Skip to content

Commit 64195e9

Browse files
robertdorn83marwie
authored andcommitted
added animation support for KHR_node_visibility
1 parent a627dec commit 64195e9

2 files changed

Lines changed: 51 additions & 0 deletions

File tree

Runtime/Scripts/SceneExporter/ExporterAnimationPointer.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,36 @@ public void AddAnimationData(Object animatedObject, string propertyName, GLTFAni
113113

114114
switch (animatedObject)
115115
{
116+
case GameObject gameObject:
117+
if (propertyName == "activeSelf")
118+
{
119+
if (!UseAnimationPointer)
120+
{
121+
Debug.LogWarning(null, $"GLTFExporter error: Cannot export GameObject.activeSelf animation without KHR_animation_pointer. Skipping", animatedObject);
122+
return;
123+
}
124+
125+
var transformIndex = GetTransformIndex(gameObject.transform);
126+
if (transformIndex == -1)
127+
{
128+
Debug.LogError(null, $"GLTFExporter error: Could not find transform for animated GameObject \"{gameObject}\". Skipping", animatedObject);
129+
return;
130+
}
131+
132+
var node = _root.Nodes[transformIndex];
133+
if (node.Extensions == null || !node.Extensions.ContainsKey(KHR_node_visibility_Factory.EXTENSION_NAME))
134+
{
135+
var newExtension = new KHR_node_visibility();
136+
newExtension.visible = true;
137+
138+
node.AddExtension(KHR_node_visibility_Factory.EXTENSION_NAME, newExtension);
139+
DeclareExtensionUsage(KHR_node_visibility_Factory.EXTENSION_NAME, false);
140+
}
141+
142+
propertyName = $"extensions/{KHR_node_visibility_Factory.EXTENSION_NAME}/{nameof(KHR_node_visibility.visible)}";
143+
extensionName = KHR_node_visibility_Factory.EXTENSION_NAME;
144+
}
145+
break;
116146
case Material material:
117147
// Debug.Log("material: " + material + ", propertyName: " + propertyName);
118148
// mapping from known Unity property names to glTF property names

Runtime/Scripts/SceneImporter/ImporterAnimation.cs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,27 @@ AttributeAccessor FindSecondaryChannel(string animationPointerPath)
358358
switch (rootType)
359359
{
360360
case "nodes":
361+
var nodeExtension = pointerHierarchy.FindNext(PointerPath.PathElement.Extension);
362+
if (nodeExtension != null)
363+
{
364+
var extensionPath = nodeExtension.ExtractPath();
365+
if (extensionPath == "extensions/KHR_node_visibility/visible")
366+
{
367+
pointerData = new AnimationPointerData();
368+
pointerData.targetNodeIds = new int[] {rootIndex.index};
369+
nodeIds = pointerData.targetNodeIds;
370+
pointerData.unityPropertyNames = new string[1] { "m_IsActive" };
371+
pointerData.targetType = typeof(GameObject);
372+
pointerData.primaryData = samplerCache.Output;
373+
pointerData.importAccessorContentConversion = (data, frame) =>
374+
{
375+
var v = data.primaryData.AccessorContent.AsFloats[frame];
376+
return new float[] { v };
377+
};
378+
break;
379+
}
380+
}
381+
361382
var pointerPropertyElement = pointerHierarchy.FindNext(PointerPath.PathElement.Property);
362383
if (pointerPropertyElement == null)
363384
continue;

0 commit comments

Comments
 (0)