Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "ShouldNodeExport" hook #767

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,8 @@ private SceneId ExportScene(string name, Transform[] rootObjTransforms)
Debug.LogWarning("GLTFSceneExporter", $"Skipping empty transform in root transforms provided for scene export for {name}", transform);
continue;
}
scene.Nodes.Add(ExportNode(transform));
var node = ExportNode(transform);
if (node != null) scene.Nodes.Add(node);
}

_root.Scenes.Add(scene);
Expand All @@ -1028,6 +1029,9 @@ private NodeId ExportNode(Transform nodeTransform)
if (_exportedTransforms.TryGetValue(nodeTransform.GetInstanceID(), out var existingNodeId))
return new NodeId() { Id = existingNodeId, Root = _root };

foreach (var plugin in _plugins)
if (!(plugin?.ShouldNodeExport(this, _root, nodeTransform) ?? true)) return null;

exportNodeMarker.Begin();

var node = new Node();
Expand Down Expand Up @@ -1168,7 +1172,8 @@ private NodeId ExportNode(Transform nodeTransform)
foreach (var child in nonPrimitives)
{
if (!ShouldExportTransform(child.transform)) continue;
parentOfChilds.Children.Add(ExportNode(child.transform));
var childNode = ExportNode(child.transform);
if (childNode != null) parentOfChilds.Children.Add(childNode);
}
}

Expand Down
1 change: 1 addition & 0 deletions Runtime/Scripts/Plugins/Core/GltfExportPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public abstract class GLTFExportPluginContext
{
public virtual void BeforeSceneExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot) {}
public virtual void AfterSceneExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot) {}
public virtual bool ShouldNodeExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Transform transform) => true;
public virtual void BeforeNodeExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Transform transform, Node node) {}
public virtual void AfterNodeExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Transform transform, Node node) {}
public virtual bool BeforeMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode) => false;
Expand Down
4 changes: 3 additions & 1 deletion Runtime/Scripts/Plugins/LodsExport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ public override void AfterNodeExport(GLTFSceneExporter exporter, GLTFRoot gltfro
return;
}

nodeIds[index] = exporter.ExportNode(lod.renderers[0].gameObject).Id;
var lodNode = exporter.ExportNode(lod.renderers[0].gameObject);
if (lodNode != null) nodeIds[index] = lodNode.Id;

coverages[index] = lod.screenRelativeTransitionHeight;
}
// if (usesCulling) coverages[coverages.Length - 1] = 0;
Expand Down