Skip to content
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

Skinned animation and node animation coordinate space bugfixes #146

Merged
merged 18 commits into from
Mar 17, 2018

Conversation

jm991
Copy link
Contributor

@jm991 jm991 commented Mar 15, 2018

Adding support for skinned mesh animation, as well as bugfixing some issues in the animation construction code around coordinate space conversions

Copy link

@blgrossMS blgrossMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great change John! Just left a couple of comments.

return "WEIGHTS_" + index;
}

public static string Joint(int index)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs comment

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

string primitiveObjPath = relativePath + "/Primitive" + primitiveIndex;
for (int targetIndex = 0; targetIndex < targetCount; targetIndex++)
{
//clip.SetCurve(primitiveObjPath, typeof(SkinnedMeshRenderer), "blendShape." + targetIndex, curves[targetIndex]);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove, leave comment, or reactivate

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a TODO to add blend shapes/morph targets. I 'm going to do that in a separate PR since blendshapes have more than 4 curves and will need some re-jiggering of the animation construction code

animation.AddClip(clip, clip.name);
if (i == 0)
{
animation.clip = clip;
}
//animation.Play();

animation.Play();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would remove this line

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

return primitive.Targets != null;
}

void SetupBones(Skin skin, MeshPrimitive primitive, SkinnedMeshRenderer renderer, GameObject primitiveObj, UnityEngine.Mesh curMesh)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

access modifier

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for the above as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done (for all methods, they are private)


GLTFHelpers.BuildBindPoseSamplers(ref attributeAccessor);

GLTF.Math.Matrix4x4[] gltfBindPoses = attributeAccessor.AccessorContent.AsMatrix4x4s;//.ToUnityMatrix4x4sConvert();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what is commented out at the end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops - I moved that to the for loop below it and forgot to remove it. It's gone now

return boneWeights;
}

void MakeSureWeightsAddToOne(Vector4[] weights)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better name? WeightNormalize?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some comments here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah the normalize name you suggested is better!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

{
var skinnedMeshRenderer = primitiveObj.AddComponent<SkinnedMeshRenderer>();
skinnedMeshRenderer.material = material;
skinnedMeshRenderer.quality = SkinQuality.Bone4;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be a modifiable property on the script?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean that adding the skinnedmeshrenderer should be modifiable? I think it's correct to only add it if the mesh has a skin. We don't have switches for other things like whether we add a material or not, so I think this is a similar situation

I did realize after you pointed out this code that the mesh filter is only added to the static objects, so I've fixed that :)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No meant whether the skinquality should be

skinnedMeshRenderer.material = material;
skinnedMeshRenderer.quality = SkinQuality.Bone4;
/*
if (HasBlendShapes(primitive))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add comment or remove

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I put a TODO to add blend shapes/morph targets. I 'm going to do that in a separate PR since blendshapes have more than 4 curves and will need some re-jiggering of the animation construction code

SetupBlendShapes(primitive);
*/
if (HasBones(skin))
SetupBones(skin, primitive, skinnedMeshRenderer, primitiveObj, curMesh);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yield after

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to yield to the call and yield properly in SetupBones

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to coroutine as suggested

@jm991
Copy link
Contributor Author

jm991 commented Mar 16, 2018

Alright! All PR feedback addressed

@blgrossMS blgrossMS merged commit b63e529 into KhronosGroup:master Mar 17, 2018
github-actions bot pushed a commit to Rhinox-Training/UnityGLTF that referenced this pull request Nov 9, 2022
…osGroup#146)

* First attempt at getting animation working

Doesn't compile quite yet
Porting from this PR:
https://github.com/KhronosGroup/UnityGLTF/pull/43/files

* Little more progress

* Bind pose access is functional!

* First end-to-end loading of animations and bindpose

Coordinate spaces are a mess though

* ConstructUnityMesh isn't populating mesh.boneWeights yet...

* Still not working...

* Trying some ideas from a different PR

* Revert "Trying some ideas from a different PR"

This reverts commit 4ad9af2.

* First working skinning!

* Fixed inverted transforms in animation

* Fixing issue where too many bones were named GLTFNode and caused naming conflicts

* Code cleanup

* More code cleanup

* Defaulting animation to play

* Clips loop by default

* Reverting files before checkin

* Reverting files before checkin

* Addressing PR feedback
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants