Skip to content

Commit

Permalink
Merge branch 'feature/configurable-extensions' of https://github.com/…
Browse files Browse the repository at this point in the history
…prefrontalcortex/UnityGLTF into feature/configurable-extensions
  • Loading branch information
hybridherbst committed Jan 2, 2024
2 parents 926d9ee + 16c83c3 commit 9bd7e71
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
18 changes: 14 additions & 4 deletions Runtime/Scripts/GLTFSceneExporter.cs
Original file line number Diff line number Diff line change
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
7 changes: 6 additions & 1 deletion Runtime/Scripts/GLTFSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,14 @@ private static void RegisterPlugins(GLTFSettings settings)
{
var newInstance = CreateInstance(pluginType) as T;
if (!newInstance) continue;


newInstance.name = pluginType.Name;
newInstance.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
newInstance.Enabled = newInstance.EnabledByDefault;

plugins.Add(newInstance);
if (AssetDatabase.Contains(settings))
AssetDatabase.AddObjectToAsset(newInstance, settings);
EditorUtility.SetDirty(settings);
}
}
Expand Down
1 change: 1 addition & 0 deletions Runtime/Scripts/Plugins/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 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
1 change: 1 addition & 0 deletions Runtime/Scripts/SceneImporter/ImporterMeshes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using UnityGLTF.Extensions;
#if HAVE_DRACO
using Draco;
using UnityGLTF.Plugins;
#endif

namespace UnityGLTF
Expand Down

0 comments on commit 9bd7e71

Please sign in to comment.