vpenades / SharpGLTF

glTF reader and writer for .NET Standard
MIT License
458 stars 72 forks source link

Morph target animation using MorphTargetBuilder #127

Closed vermadas closed 2 years ago

vermadas commented 2 years ago

Hi there,

I'm trying to understand how to set up a morph target animation. Looking at this test: https://github.com/vpenades/SharpGLTF/blob/f6e5ebd1f3edb5ab47dbac6e6f7042dedb7f8980/tests/SharpGLTF.Toolkit.Tests/Scenes/SceneBuilderTests.cs#L443

Looking at the code, I believe the result should show the second pink cube moving up 1 meter and then back down. However, when I run the test the result does not have any animation.

It's quite possible I'm missing something. Thanks for your time.

vpenades commented 2 years ago

I've checked the test and it's indeed broken, there's been a slight change in functionality due to adding mesh instancing a while ago.

I will correct the test to adjust to the new funcionality, in the meantime, in order the make it work, instead of adding the mesh like this:

            var inst2 = scene.AddRigidMesh(mesh2, Matrix4x4.CreateTranslation(2, 0, 0)); 

you must add it like this:

            var armature = new NodeBuilder();
            armature.LocalTransform = Matrix4x4.CreateTranslation(2, 0, 0);
            var inst2 = scene.AddRigidMesh(mesh2, armature); 

At first sight the difference seems irrelevant, but the former uses now a "fast path" that prevents morphing from working. The later uses the "full stack" which does support morphing.

vermadas commented 2 years ago

Excellent, that fixed the issue for me. Thanks!