Selaa lähdekoodia

Added more skin validations

Vicente Penades 6 vuotta sitten
vanhempi
sitoutus
07159618f2
1 muutettua tiedostoa jossa 17 lisäystä ja 5 poistoa
  1. 17 5
      src/SharpGLTF.Core/Schema2/gltf.Skin.cs

+ 17 - 5
src/SharpGLTF.Core/Schema2/gltf.Skin.cs

@@ -224,11 +224,6 @@ namespace SharpGLTF.Schema2
 
 
             var logicalNodeCount = this.LogicalParent.LogicalNodes.Count;
             var logicalNodeCount = this.LogicalParent.LogicalNodes.Count;
 
 
-            if (_skeleton.HasValue)
-            {
-                if (_skeleton.Value < 0 || _skeleton.Value >= logicalNodeCount) result.AddError(this, $"Skeleton Node index reference is out of bounds.");
-            }
-
             if (_joints == null || _joints.Count < _jointsMinItems)
             if (_joints == null || _joints.Count < _jointsMinItems)
             {
             {
                 result.AddError(this, $"Expected at least {_jointsMinItems} Joints");
                 result.AddError(this, $"Expected at least {_jointsMinItems} Joints");
@@ -247,6 +242,23 @@ namespace SharpGLTF.Schema2
                     catch { result.AddError(this, $"Joint {i} has invalid bind matrix"); }
                     catch { result.AddError(this, $"Joint {i} has invalid bind matrix"); }
                 }
                 }
             }
             }
+
+            if (_skeleton.HasValue)
+            {
+                if (_skeleton.Value < 0 || _skeleton.Value >= logicalNodeCount) result.AddError(this, $"Skeleton Node index reference is out of bounds.");
+
+                var skeletonNode = this.Skeleton;
+
+                for (int i = 0; i < this.JointsCount; ++i)
+                {
+                    var jointNode = GetJoint(i).Key;
+
+                    if (skeletonNode == jointNode) continue;
+                    if (skeletonNode._ContainsVisualNode(jointNode, true)) continue;
+
+                    result.AddError(this, $"Skeleton node is not a common ancestor of Joint[{i}]");
+                }
+            }
         }
         }
 
 
         #endregion
         #endregion