Skip to content

Commit

Permalink
feat: add BeforeNodeExport callback that allows for hierarchy and mes…
Browse files Browse the repository at this point in the history
…h modifications
  • Loading branch information
hybridherbst committed Dec 31, 2023
1 parent 66bee81 commit 20d5a38
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
18 changes: 14 additions & 4 deletions Runtime/Scripts/GLTFSceneExporter.cs
Expand Up @@ -496,15 +496,16 @@ public override int GetHashCode()
private static ProfilerMarker exportBlendShapeMarker = new ProfilerMarker("Export BlendShape");
private static ProfilerMarker exportSkinFromNodeMarker = new ProfilerMarker("Export Skin");
private static ProfilerMarker exportSparseAccessorMarker = new ProfilerMarker("Export Sparse Accessor");
private static ProfilerMarker beforeNodeExportMarker = new ProfilerMarker("Before Node Export (Callback)");
private static ProfilerMarker exportNodeMarker = new ProfilerMarker("Export Node");
private static ProfilerMarker afterNodeExportMarker = new ProfilerMarker("After Node Export (Callback)");
private static ProfilerMarker exportAnimationFromNodeMarker = new ProfilerMarker("Export Animation from Node");
private static ProfilerMarker convertClipToGLTFAnimationMarker = new ProfilerMarker("Convert Clip to GLTF Animation");
private static ProfilerMarker beforeSceneExportMarker = new ProfilerMarker("Before Scene Export (Callback)");
private static ProfilerMarker exportSceneMarker = new ProfilerMarker("Export Scene");
private static ProfilerMarker afterMaterialExportMarker = new ProfilerMarker("After Material Export (Callback)");
private static ProfilerMarker exportMaterialMarker = new ProfilerMarker("Export Material");
private static ProfilerMarker beforeMaterialExportMarker = new ProfilerMarker("Before Material Export (Callback)");
private static ProfilerMarker exportMaterialMarker = new ProfilerMarker("Export Material");
private static ProfilerMarker afterMaterialExportMarker = new ProfilerMarker("After Material Export (Callback)");
private static ProfilerMarker writeImageToDiskMarker = new ProfilerMarker("Export Image - Write to Disk");
private static ProfilerMarker afterSceneExportMarker = new ProfilerMarker("After Scene Export (Callback)");

Expand Down Expand Up @@ -1004,16 +1005,25 @@ private NodeId ExportNode(Transform nodeTransform)
return new NodeId() { Id = existingNodeId, Root = _root };

exportNodeMarker.Begin();

var node = new Node();

if (ExportNames)
{
node.Name = nodeTransform.name;
}

// TODO think more about how this callback is used – could e.g. be modifying the hierarchy,
// and we would want to prevent exporting children of this node.
// Could also be that we want to add a mesh based on some condition
// (e.g. merged childs, procedural geometry, etc.)
beforeNodeExportMarker.Begin();
foreach (var plugin in _plugins)
plugin?.BeforeNodeExport(this, _root, nodeTransform, node);
beforeNodeExportMarker.End();

#if ANIMATION_SUPPORTED
if (nodeTransform.GetComponent<UnityEngine.Animation>() || nodeTransform.GetComponent<UnityEngine.Animator>())
if (nodeTransform.GetComponent<Animation>() || nodeTransform.GetComponent<Animator>())
{
_animatedNodes.Add(nodeTransform);
}
Expand Down
1 change: 1 addition & 0 deletions Runtime/Scripts/Plugins/GltfExportPlugin.cs
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 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;
public virtual void AfterMaterialExport(GLTFSceneExporter exporter, GLTFRoot gltfRoot, Material material, GLTFMaterial materialNode) {}
Expand Down

0 comments on commit 20d5a38

Please sign in to comment.