-
Notifications
You must be signed in to change notification settings - Fork 492
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
Export Unity animation clips and skeleton to GLTF #561
base: main
Are you sure you want to change the base?
Conversation
…rt GLTF file with animation clips and skeleton throght "GLTF -> Export ***" menu now.
@owilliamailliwo couple questions to judge this vs my PR and which pieces to take from which:
|
Hi @soraryu , I will create a new pull request recently, which will support the compression of animation data and geometry properties. |
That's great to hear! I'll look into any differences that there may be between mine and yours and notice here. About compatibility: note that the rest of Khronos' Unity code (currently) itself isn't fully spec compatible in some places unfortunately, and there are big differences in gltf support between babylon, three, filament, scene viewer try etc. Please try in as many as you can. |
foreach (var prim in primitives) | ||
{ | ||
var smr = prim.GetComponent<SkinnedMeshRenderer>(); | ||
if (_existedSkins.TryGetValue(smr.rootBone.GetInstanceID(), out SkinId skinId)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't use the smr.rootbone's instanceid as the key, different skinnmeshrender' may have same rootBone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have fixed this problem, I will commit it later. Thank you!
|
||
node.Mesh = ExportMesh(prim.name, new GameObject[] { prim }); | ||
|
||
_existedSkins.Add(smr.rootBone.GetInstanceID(), skinId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here
var boneNode = new Node | ||
{ | ||
Name = bone.gameObject.name, | ||
Translation = new GLTF.Math.Vector3(translation.x, translation.y, translation.z), | ||
Rotation = new GLTF.Math.Quaternion(rotation.x, rotation.y, rotation.z, rotation.w), | ||
Scale = new GLTF.Math.Vector3(scale.x, scale.y, scale.z), | ||
}; | ||
|
||
if (bone.childCount > 0) | ||
{ | ||
boneNode.Children = new List<NodeId>(); | ||
for (var i = 0; i < bone.childCount; ++i) | ||
{ | ||
var childIndex = Array.IndexOf(smr.bones, bone.GetChild(i)); | ||
if (-1 == childIndex) | ||
{ | ||
continue; | ||
} | ||
boneNode.Children.Add( | ||
new NodeId | ||
{ | ||
Id = childIndex + baseId, | ||
Root = _root | ||
} | ||
); | ||
} | ||
} | ||
|
||
nodeId = new NodeId | ||
{ | ||
Id = _root.Nodes.Count, | ||
Root = _root | ||
}; | ||
|
||
_root.Nodes.Add(boneNode); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generate GLTF nodes is not add to existedNode dict and the _root.Nodes. Would cause duplicated nodes when add gameobject.
It would be more clear to generate GLTF nodes for every gameobject first, then parse components like mesh/skin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be more clear to generate GLTF nodes for every gameobject first, then parse components like mesh/skin
Hi, thanks very much! I've fixed the problems you found. I couldn't agree more with your suggestion, but I don't want to make sweeping changes to the current code structure.
NodeId rootBoneId = null; | ||
if (!_existedNodes.TryGetValue(smr.rootBone.GetInstanceID(), out rootBoneId)) | ||
{ | ||
rootBoneId = new NodeId | ||
{ | ||
Id = baseId, | ||
Root = _root | ||
}; | ||
} | ||
|
||
skin.Skeleton = rootBoneId; | ||
|
||
skinId = new SkinId | ||
{ | ||
Id = _root.Skins.Count, | ||
Root = _root | ||
}; | ||
|
||
_root.Skins.Add(skin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same problem
This will not work for runtime export 'cause AnimationUtility was called, and disregard legacy Animation system. |
@tufeixp that's correct; as outlined above a good improvement here would be the ability to record via a timeline clip (which would also work at runtime). Similar to how Unity-USD does that. |
Add exporting Unity animation clips and skeleton to GLTF. We can export GLTF file with animation clips and skeleton throght "GLTF -> Export ***" menu now.