Browse Source

Fixed morph target count inconsistency when used in multiple primitives, fixes #208 and #281

vpenades 5 months ago
parent
commit
98ec96e00e
1 changed files with 7 additions and 1 deletions
  1. 7 1
      src/SharpGLTF.Toolkit/Geometry/MorphTargetBuilder.cs

+ 7 - 1
src/SharpGLTF.Toolkit/Geometry/MorphTargetBuilder.cs

@@ -288,9 +288,15 @@ namespace SharpGLTF.Geometry
         {
         {
             _Mesh = mesh;
             _Mesh = mesh;
             _MorphTargetIndex = morphTargetIndex;
             _MorphTargetIndex = morphTargetIndex;
-
+            
             foreach (var prim in _Mesh.Primitives)
             foreach (var prim in _Mesh.Primitives)
             {
             {
+                // this is required to ensure that all primitives are aligned
+                // by having the same amount of morph targets regardless of whether
+                // they're used or not.
+                prim._UseMorphTarget(morphTargetIndex);
+
+                // create a global position table to be used for morph target keys.
                 for (int vidx = 0; vidx < prim.Vertices.Count; ++vidx)
                 for (int vidx = 0; vidx < prim.Vertices.Count; ++vidx)
                 {
                 {
                     var key = prim.Vertices[vidx].Geometry;
                     var key = prim.Vertices[vidx].Geometry;