Jump to content

Test GLTF Animations


MackeyK24
 Share

Recommended Posts

Hi guys... Im working on encoding GLTF Skeletal Animations. It looks like the skeleton is there, the bones are there, the animations are on the bones...

But for some reason, it does not Animate.

Yo @Deltakosh  or @bghgary or ANYBODY who know ANYTHING about GLTF Animations ... C an you please take a look at this playground: https://playground.babylonjs.com/#I42JEZ

Maybe you can tell WTF is going on the GLTF Animations i hav encoded... Am i missing something in the GLTF File or what.... Is the the Bone Weights ???

Shit... This is so frustrating because there is not that much to go on BESIDES the Khronos and Sketchfab UnityGLTF Exporters... WHICH BOTH SUCK FOR ANIMATIONS... So now i gotta go re-write that shit too :(

 

Link to comment
Share on other sites

Looks like im gonna have to implement GLTF Animations from scratch in UnityGLTF. Khronos does not support animations in the UnityGLTF Exporter and the Sketchfab has too many tweaks made especially for sketchfab viewer... Plus only the TRS animations worked... Kind of... So it looks like i am going to have to either study up on the GLTF Animation Format or serialized native Unity Animation Meta Data and handle that Animation Meta Data in the Parser... Bummer :(

 

Link to comment
Share on other sites

Yo @bghgary are you sure that code is supposed to work... I fork that guys UnityGLTF... But when i try to export with animations... I get this error:

 

ArgumentException: The requested value 'localEulerAnglesRaw' was not found.


System.Enum.Parse (System.Type enumType, System.String value, Boolean ignoreCase) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:692)
System.Enum.Parse (System.Type enumType, System.String value) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System/Enum.cs:547)
UnityGLTF.GLTFSceneExporter.ExportAnimation (UnityEngine.GameObject gameObject, UnityEngine.AnimationClip unityAnimationClip) (at Assets/Canvas/Build/Sources/Extensions/GLTFSceneExporter.Animation.cs:88)

Is crapping out here:

                    Property property = (Property)Enum.Parse(typeof(Property), pairProperty.Key);

So he is try to use a name that does now exist in the enum... I can only imagine :(

 

Link to comment
Share on other sites

10 hours ago, bghgary said:

@MackeyK24 There is a PR in the UnityGLTF repo that adds animation export support: https://github.com/KhronosGroup/UnityGLTF/pull/160. This was a port from my repo which already supports animation export. Let me know if this works for you.

Yo @bghgary

How long ago was the animation support added... Apparently, Unity uses localEulerAnglesRaw and NOT m_LocalRotation... How do i handle that ??? 

Link to comment
Share on other sites

Man i dont know about that one... Its not taking into account ALL the ofer rotation type... And the way hey is baking the clip... i have no idea when it the best time in his code to convert that Euler values to Quaternion...

I think the localEuler stuff has been around since 5.3... 

So i i am wonder how this EVER worked ONLY using m_LocalRotation ???

 

We should be doing Something like this to get ALL rotation types:

 

				TargetCurveSet current = targetCurves[binding.path];
				if (binding.propertyName.Contains("m_LocalPosition"))
				{
					if (binding.propertyName.Contains(".x"))
						current.translationCurves[0] = curve;
					else if (binding.propertyName.Contains(".y"))
						current.translationCurves[1] = curve;
					else if (binding.propertyName.Contains(".z"))
						current.translationCurves[2] = curve;
				}
				else if (binding.propertyName.Contains("m_LocalScale"))
				{
					if (binding.propertyName.Contains(".x"))
						current.scaleCurves[0] = curve;
					else if (binding.propertyName.Contains(".y"))
						current.scaleCurves[1] = curve;
					else if (binding.propertyName.Contains(".z"))
						current.scaleCurves[2] = curve;
				}
				else if (binding.propertyName.ToLower().Contains("localrotation"))
				{
					current.rotationType = ROTATION_TYPE.QUATERNION;
					if (binding.propertyName.Contains(".x"))
						current.rotationCurves[0] = curve;
					else if (binding.propertyName.Contains(".y"))
						current.rotationCurves[1] = curve;
					else if (binding.propertyName.Contains(".z"))
						current.rotationCurves[2] = curve;
					else if (binding.propertyName.Contains(".w"))
						current.rotationCurves[3] = curve;
				}
				// Takes into account 'localEuler', 'localEulerAnglesBaked' and 'localEulerAnglesRaw'
				else if (binding.propertyName.ToLower().Contains("localeuler"))
				{
					current.rotationType = ROTATION_TYPE.EULER;
					if (binding.propertyName.Contains(".x"))
						current.rotationCurves[0] = curve;
					else if (binding.propertyName.Contains(".y"))
						current.rotationCurves[1] = curve;
					else if (binding.propertyName.Contains(".z"))
						current.rotationCurves[2] = curve;
				}
				targetCurves[binding.path] = current;

 

Then when Evaluating, Convert Eulers to Quaternion

if (curveSet.rotationType == ROTATION_TYPE.EULER)
{
	Quaternion eulerToQuat = Quaternion.Euler(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime));
	rotations[i] = new Vector4(eulerToQuat.x, eulerToQuat.y, eulerToQuat.z, eulerToQuat.w);
}
else
{
	rotations[i] = new Vector4(curveSet.rotationCurves[0].Evaluate(currentTime), curveSet.rotationCurves[1].Evaluate(currentTime), curveSet.rotationCurves[2].Evaluate(currentTime), curveSet.rotationCurves[3].Evaluate(currentTime));
}

 

But Again... I can tell what is Going On In the GLTFSceneExporter.Animation.cs wih this function:

private AnimationSampler ExportAnimationSamplerRotation(AnimationCurve curveX, AnimationCurve curveY, AnimationCurve curveZ, AnimationCurve curveW)
{
	return ExportAnimationSampler(
		new AnimationCurve[] { curveX, curveY, curveZ, curveW },
		keyIndex => GetRightHandedQuaternion(new Quaternion(curveX.keys[keyIndex].inTangent, curveY.keys[keyIndex].inTangent, curveZ.keys[keyIndex].inTangent, curveW.keys[keyIndex].inTangent)),
		keyIndex => GetRightHandedQuaternion(CreateNormalizedQuaternion(curveX.keys[keyIndex].value, curveY.keys[keyIndex].value, curveZ.keys[keyIndex].value, curveW.keys[keyIndex].value)),
		keyIndex => GetRightHandedQuaternion(new Quaternion(curveX.keys[keyIndex].outTangent, curveY.keys[keyIndex].outTangent, curveZ.keys[keyIndex].outTangent, curveW.keys[keyIndex].outTangent)),
		time => GetRightHandedQuaternion(CreateNormalizedQuaternion(curveX.Evaluate(time), curveY.Evaluate(time), curveZ.Evaluate(time), curveW.Evaluate(time))),
		values => GLTF.DataExporter.ExportData(values.Select(value => value.ToGltfQuaternionConvert()), _bufferId, _root, _bufferWriter));
}

How i can make another function like this that converts the Euler curves then feed them into ExportAnimationSamplerRotation... I guess...

Thats why i ask how old is this code ???

 

Link to comment
Share on other sites

I just end up porting the SketchFab Version and removing some of the ambient occlusion packing stuff.

But is does support skinned meshes.. so it exports JOINTS and WEIGHTS... Is does support Animations... Although it combines all animations as 1 long Take001 animation track... dunno how they plan to track when one animation clip stops and another another start WITHOUT keeping some king of start frame and stop frame  Ranges ... But at least is does work.

Note... No implementation at all... not a single one (C# Unity Based) that i can find... exports skeletal animations... Dunno why that seems to be missing in everyones C# implementation of GLTF  Exportation :(

 

Link to comment
Share on other sites

 

11 hours ago, MackeyK24 said:

how old is this code ???

The code is just a port of my code from my repo. I didn't take everything into account since I did it just to prove out the spec. Euler rotations are not supported in the code I wrote. I wrote this code about more than a year ago. glTF only supports Quaternion rotations. I will need to spend some time thinking about how to convert from Euler rotations to Quaternion rotations.

4 hours ago, MackeyK24 said:

No implementation at all... not a single one (C# Unity Based) that i can find... exports skeletal animations...

I'm a bit confused by this statement. The Sketchfab version you mentioned does support skeletal animations and it sounds like you are saying it works. My repo also has skeletal animation support.

Link to comment
Share on other sites

Sketchfab exports the skin... not the actual bone animations... it also packs all clips into one single channel set ... merged into one long animation called Take001

i have seen glTF with skeleton animation... just not one in unity ... so I dont know how to encode them into channel sets... I can bake out the animations easy... I already do that for Babylon ... 

I am using Sketchfab as gospel... cause I don’t know any better and that is what I am using to learn the inner workings of the export 

 

Link to comment
Share on other sites

Btw... I did manage to get a few things added to my Sketchfab port...

added GLB support with internal buffers

added all my material fallbacks so any non pbr material gets converted to pbr spec with black and zero glossiness to give a legacy diffuse type fallback

not to mention all my unity metadata that I use to make Babylon Toolkit ... including components and scripts... my PlayCanvas glTF importer is parsing out great so far... also including components and scripts... that part is beautiful 

my my problem is lack of knowledge of glTF animation ... both regular transform and skeletal... I can’t get all my mechanim styles animations I have baked into glTF format ... but I will keep trying ?

Link to comment
Share on other sites

12 minutes ago, MackeyK24 said:

Sketchfab exports the skin... not the actual bone animations...

That has not been my experience. I have used the exporter and it worked for me. In Unity, the bone hierarchy is part of the node hierarchy, just like glTF (though we have discussed separating them in future versions). There isn't a separate export for bone animations. The export for node animations are also for the bone animations. Perhaps there is a misunderstanding here?

Link to comment
Share on other sites

4 minutes ago, MackeyK24 said:

I can’t get all my mechanim styles animations I have baked into glTF format

glTF does not support Unity Animator (mechanim) components. glTF only support Unity animation clips. Unity Animator is basically a state machine that can blend animations between states. This does not exist in core glTF and I am not aware of an extension that does this.

Link to comment
Share on other sites

According to an email from Sketchfab 

Hello,

Skeletal / humanoid / avatar animations are not currently supported in the Unity Exporter. We hope to improve this in the future.

I'll add your '+1' to this feature request and follow up with any news.

James

James Green
Product Specialist
Sketchfab

Plans | Store

Link to comment
Share on other sites

1 minute ago, bghgary said:

glTF does not support Unity Animator (mechanim) components. glTF only support Unity animation clips. Unity Animator is basically a state machine that can blend animations between states. This does not exist in core glTF and I am not aware of an extension that does this.

I know, but I bake out regular TRS info for each bone and encode the key frames ... I can encode the seperate T R S or like for Babylon I compose into a matrix and serialize a key frames with a path of _matrix

This is how I currently export out unity state machines ... with states, transitions, blend trees, avatar masks. .., the whole animator state machine... there are a few of my animation state machine stuff on playground... I also export regular animation clips curves... it all come down to a time and a value ... just like your glTF anim port... I just need to see some code on encoding bone anim into glTF ... I’m afraid I don’t quite understand all ins and outs and accessors enough to pack that stuff into. GlTF animation the same way I did for Babylon Toolkit

Link to comment
Share on other sites

23 minutes ago, MackeyK24 said:

Have you seen any of my Babylon Toolkit stuff ??? 

I haven't looked at it carefully, but I know about the extras stuff you are adding. I thought you were trying to get the animator stuff into core spec.

27 minutes ago, MackeyK24 said:

I’m afraid I don’t quite understand all ins and outs and accessors enough to pack that stuff into.

I'm hoping my code can help with this, but if not, let me know how I can help.

Link to comment
Share on other sites

1 hour ago, bghgary said:

I haven't looked at it carefully, but I know about the extras stuff you are adding. I thought you were trying to get the animator stuff into core spec.

I'm hoping my code can help with this, but if not, let me know how I can help.

Nope... just trying to get the UNDERLYING Skeletal Animation into GLTF Format

Link to comment
Share on other sites

23 hours ago, MackeyK24 said:

just trying to get the UNDERLYING Skeletal Animation into GLTF Format

I watched the video you posted in the other thread (looks interesting btw), but I am still not sure how to help you with this. Do you need to learn more about the glTF format to be able to do your work? If so, maybe the skinning section of the glTF tutorial helps?

Link to comment
Share on other sites

It would be great to see some code on how to build the animation and assign to bone or joint. As you saw I can bake key frames... I see how Sketchfab is doing a regular transform animation... but how do iterate the bones making glTF animations with my bone info...

if I can see some code actually building the animation... I can probably figure out how to use my animation data using that sample as a guide

Link to comment
Share on other sites

The code that I sent is all you need to do to export a skin and its joints/bones. The code that exports the animation for nodes is the same code that is necessary to export animation of joints/bones since Unity treats them the same (just like in glTF). I'm not sure what is the missing piece.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...