Browse Source

Improved primitives morph target validation, which exposes some reported issues

vpenades 5 months ago
parent
commit
2da1b64cde
1 changed files with 13 additions and 5 deletions
  1. 13 5
      src/SharpGLTF.Core/Schema2/gltf.Mesh.cs

+ 13 - 5
src/SharpGLTF.Core/Schema2/gltf.Mesh.cs

@@ -97,14 +97,22 @@ namespace SharpGLTF.Schema2
 
 
         protected override void OnValidateContent(Validation.ValidationContext validate)
         protected override void OnValidateContent(Validation.ValidationContext validate)
         {
         {
-            if (_weights.Count > 0)
+            // https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#morph-targets
+
+            int morphsCount = -1;
+
+            foreach (var p in this.Primitives)
             {
             {
-                foreach (var p in this.Primitives)
-                {
-                    validate.GetContext(p).AreEqual("MorphTargetsCount", p.MorphTargetsCount, _weights.Count);
-                }
+                if (morphsCount < 0) morphsCount = p.MorphTargetsCount;
+
+                validate.GetContext(p).AreEqual("MorphTargets.Count", p.MorphTargetsCount, morphsCount);
             }
             }
 
 
+            if (_weights.Count > 0)
+            {
+                validate.AreEqual("Weights", morphsCount, _weights.Count);
+            }            
+
             base.OnValidateContent(validate);
             base.OnValidateContent(validate);
         }
         }