Browse Source

refactored IVertexSkinning properties and methods to avoid name collision.

Vicente Penades 6 years ago
parent
commit
f9c83715a3

+ 1 - 1
src/SharpGLTF.Toolkit/Geometry/Vertex.cs

@@ -34,7 +34,7 @@ namespace SharpGLTF.Geometry
     /// <see cref="VertexJoints16x4"/>,
     /// <see cref="VertexJoints16x4"/>,
     /// <see cref="VertexJoints16x8"/>.
     /// <see cref="VertexJoints16x8"/>.
     /// </typeparam>
     /// </typeparam>
-    [System.Diagnostics.DebuggerDisplay("Primitive {_Material}")]
+    [System.Diagnostics.DebuggerDisplay("Vertex {Geometry} {Material} {Skinning}")]
     public struct Vertex<TvP, TvM, TvS>
     public struct Vertex<TvP, TvM, TvS>
         where TvP : struct, IVertexGeometry
         where TvP : struct, IVertexGeometry
         where TvM : struct, IVertexMaterial
         where TvM : struct, IVertexMaterial

+ 8 - 8
src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexColumns.cs

@@ -83,10 +83,10 @@ namespace SharpGLTF.Geometry.VertexTypes
                 var j = Joints0[index];
                 var j = Joints0[index];
                 var w = Weights0[index];
                 var w = Weights0[index];
 
 
-                jjjj.SetJoint(0, (int)j.X, w.X);
-                jjjj.SetJoint(1, (int)j.Y, w.Y);
-                jjjj.SetJoint(2, (int)j.Z, w.Z);
-                jjjj.SetJoint(3, (int)j.W, w.W);
+                jjjj.SetBinding(0, (int)j.X, w.X);
+                jjjj.SetBinding(1, (int)j.Y, w.Y);
+                jjjj.SetBinding(2, (int)j.Z, w.Z);
+                jjjj.SetBinding(3, (int)j.W, w.W);
             }
             }
 
 
             if (Joints1 != null && Weights1 != null)
             if (Joints1 != null && Weights1 != null)
@@ -94,10 +94,10 @@ namespace SharpGLTF.Geometry.VertexTypes
                 var j = Joints1[index];
                 var j = Joints1[index];
                 var w = Weights1[index];
                 var w = Weights1[index];
 
 
-                jjjj.SetJoint(4, (int)j.X, w.X);
-                jjjj.SetJoint(5, (int)j.Y, w.Y);
-                jjjj.SetJoint(6, (int)j.Z, w.Z);
-                jjjj.SetJoint(7, (int)j.W, w.W);
+                jjjj.SetBinding(4, (int)j.X, w.X);
+                jjjj.SetBinding(5, (int)j.Y, w.Y);
+                jjjj.SetBinding(6, (int)j.Z, w.Z);
+                jjjj.SetBinding(7, (int)j.W, w.W);
             }
             }
 
 
             return jjjj;
             return jjjj;

+ 4 - 4
src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexEmpty.cs

@@ -11,7 +11,7 @@ namespace SharpGLTF.Geometry.VertexTypes
     {
     {
         public void Validate() { }
         public void Validate() { }
 
 
-        public int MaxJoints => 0;
+        public int MaxBindings => 0;
 
 
         public int MaxColors => 0;
         public int MaxColors => 0;
 
 
@@ -25,10 +25,10 @@ namespace SharpGLTF.Geometry.VertexTypes
 
 
         Vector2 IVertexMaterial.GetTexCoord(int index) { throw new NotSupportedException(); }
         Vector2 IVertexMaterial.GetTexCoord(int index) { throw new NotSupportedException(); }
 
 
-        void IVertexSkinning.SetJoint(int index, int joint, float weight) { }
+        void IVertexSkinning.SetBinding(int index, int joint, float weight) { }
 
 
-        JointWeightPair IVertexSkinning.GetJoint(int index) { throw new NotSupportedException(); }
+        JointWeightPair IVertexSkinning.GetBinding(int index) { throw new NotSupportedException(); }
 
 
-        public IEnumerable<JointWeightPair> Joints => Enumerable.Empty<JointWeightPair>();
+        public IEnumerable<JointWeightPair> Bindings => Enumerable.Empty<JointWeightPair>();
     }
     }
 }
 }

+ 22 - 22
src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexSkinning.cs

@@ -80,9 +80,9 @@ namespace SharpGLTF.Geometry.VertexTypes
 
 
         public static IEnumerable<JointWeightPair> GetJoints(IVertexSkinning vs)
         public static IEnumerable<JointWeightPair> GetJoints(IVertexSkinning vs)
         {
         {
-            for (int i = 0; i < vs.MaxJoints; ++i)
+            for (int i = 0; i < vs.MaxBindings; ++i)
             {
             {
-                var jw = vs.GetJoint(i);
+                var jw = vs.GetBinding(i);
                 if (jw.Weight != 0) yield return jw;
                 if (jw.Weight != 0) yield return jw;
             }
             }
         }
         }
@@ -90,7 +90,7 @@ namespace SharpGLTF.Geometry.VertexTypes
 
 
     public interface IVertexSkinning
     public interface IVertexSkinning
     {
     {
-        int MaxJoints { get; }
+        int MaxBindings { get; }
 
 
         // TODO: validation must ensure that:
         // TODO: validation must ensure that:
         // - there's some positive weight
         // - there's some positive weight
@@ -99,11 +99,11 @@ namespace SharpGLTF.Geometry.VertexTypes
         // - 0 weight joints point to joint 0
         // - 0 weight joints point to joint 0
         void Validate();
         void Validate();
 
 
-        JointWeightPair GetJoint(int index);
+        JointWeightPair GetBinding(int index);
 
 
-        void SetJoint(int index, int joint, float weight);
+        void SetBinding(int index, int joint, float weight);
 
 
-        IEnumerable<JointWeightPair> Joints { get; }
+        IEnumerable<JointWeightPair> Bindings { get; }
     }
     }
 
 
     /// <summary>
     /// <summary>
@@ -153,7 +153,7 @@ namespace SharpGLTF.Geometry.VertexTypes
         [VertexAttribute("WEIGHTS_0", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         [VertexAttribute("WEIGHTS_0", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         public Vector4 Weights;
         public Vector4 Weights;
 
 
-        public int MaxJoints => 4;
+        public int MaxBindings => 4;
 
 
         #endregion
         #endregion
 
 
@@ -167,7 +167,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             if (!Weights._IsReal()) throw new NotFiniteNumberException(nameof(Weights));
             if (!Weights._IsReal()) throw new NotFiniteNumberException(nameof(Weights));
         }
         }
 
 
-        public JointWeightPair GetJoint(int index)
+        public JointWeightPair GetBinding(int index)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -179,7 +179,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        public void SetJoint(int index, int joint, float weight)
+        public void SetBinding(int index, int joint, float weight)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -206,7 +206,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             Weights = new Vector4(pairs[0].Weight, pairs[1].Weight, pairs[2].Weight, pairs[3].Weight);
             Weights = new Vector4(pairs[0].Weight, pairs[1].Weight, pairs[2].Weight, pairs[3].Weight);
         }
         }
 
 
-        IEnumerable<JointWeightPair> IVertexSkinning.Joints => JointWeightPair.GetJoints(this);
+        public IEnumerable<JointWeightPair> Bindings => JointWeightPair.GetJoints(this);
 
 
         #endregion
         #endregion
     }
     }
@@ -258,7 +258,7 @@ namespace SharpGLTF.Geometry.VertexTypes
         [VertexAttribute("WEIGHTS_0", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         [VertexAttribute("WEIGHTS_0", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         public Vector4 Weights;
         public Vector4 Weights;
 
 
-        public int MaxJoints => 4;
+        public int MaxBindings => 4;
 
 
         #endregion
         #endregion
 
 
@@ -272,7 +272,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             if (!Weights._IsReal()) throw new NotFiniteNumberException(nameof(Weights));
             if (!Weights._IsReal()) throw new NotFiniteNumberException(nameof(Weights));
         }
         }
 
 
-        public JointWeightPair GetJoint(int index)
+        public JointWeightPair GetBinding(int index)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -284,7 +284,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        public void SetJoint(int index, int joint, float weight)
+        public void SetBinding(int index, int joint, float weight)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -311,7 +311,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             Weights = new Vector4(pairs[0].Weight, pairs[1].Weight, pairs[2].Weight, pairs[3].Weight);
             Weights = new Vector4(pairs[0].Weight, pairs[1].Weight, pairs[2].Weight, pairs[3].Weight);
         }
         }
 
 
-        IEnumerable<JointWeightPair> IVertexSkinning.Joints => JointWeightPair.GetJoints(this);
+        public IEnumerable<JointWeightPair> Bindings => JointWeightPair.GetJoints(this);
 
 
         #endregion
         #endregion
     }
     }
@@ -355,7 +355,7 @@ namespace SharpGLTF.Geometry.VertexTypes
         [VertexAttribute("WEIGHTS_1", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         [VertexAttribute("WEIGHTS_1", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         public Vector4 Weights1;
         public Vector4 Weights1;
 
 
-        public int MaxJoints => 8;
+        public int MaxBindings => 8;
 
 
         #endregion
         #endregion
 
 
@@ -373,7 +373,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             if (!Weights1._IsReal()) throw new NotFiniteNumberException(nameof(Weights1));
             if (!Weights1._IsReal()) throw new NotFiniteNumberException(nameof(Weights1));
         }
         }
 
 
-        public JointWeightPair GetJoint(int index)
+        public JointWeightPair GetBinding(int index)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -389,7 +389,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        public void SetJoint(int index, int joint, float weight)
+        public void SetBinding(int index, int joint, float weight)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -405,7 +405,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        IEnumerable<JointWeightPair> IVertexSkinning.Joints => JointWeightPair.GetJoints(this);
+        public IEnumerable<JointWeightPair> Bindings => JointWeightPair.GetJoints(this);
 
 
         #endregion
         #endregion
     }
     }
@@ -449,7 +449,7 @@ namespace SharpGLTF.Geometry.VertexTypes
         [VertexAttribute("WEIGHTS_1", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         [VertexAttribute("WEIGHTS_1", Schema2.EncodingType.UNSIGNED_BYTE, true)]
         public Vector4 Weights1;
         public Vector4 Weights1;
 
 
-        public int MaxJoints => 8;
+        public int MaxBindings => 8;
 
 
         #endregion
         #endregion
 
 
@@ -467,7 +467,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             if (!Weights1._IsReal()) throw new NotFiniteNumberException(nameof(Weights1));
             if (!Weights1._IsReal()) throw new NotFiniteNumberException(nameof(Weights1));
         }
         }
 
 
-        public JointWeightPair GetJoint(int index)
+        public JointWeightPair GetBinding(int index)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -483,7 +483,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        public void SetJoint(int index, int joint, float weight)
+        public void SetBinding(int index, int joint, float weight)
         {
         {
             switch (index)
             switch (index)
             {
             {
@@ -499,7 +499,7 @@ namespace SharpGLTF.Geometry.VertexTypes
             }
             }
         }
         }
 
 
-        IEnumerable<JointWeightPair> IVertexSkinning.Joints => JointWeightPair.GetJoints(this);
+        public IEnumerable<JointWeightPair> Bindings => JointWeightPair.GetJoints(this);
 
 
         #endregion
         #endregion
     }
     }

+ 10 - 10
src/SharpGLTF.Toolkit/Geometry/VertexTypes/VertexUtils.cs

@@ -268,13 +268,13 @@ namespace SharpGLTF.Geometry.VertexTypes
 
 
             var dst = default(TvS);
             var dst = default(TvS);
 
 
-            if (dst.MaxJoints >= src.MaxJoints)
+            if (dst.MaxBindings >= src.MaxBindings)
             {
             {
-                for (int i = 0; i < src.MaxJoints; ++i)
+                for (int i = 0; i < src.MaxBindings; ++i)
                 {
                 {
-                    var jw = src.GetJoint(i);
+                    var jw = src.GetBinding(i);
 
 
-                    dst.SetJoint(i, jw.Joint, jw.Weight);
+                    dst.SetBinding(i, jw.Joint, jw.Weight);
                 }
                 }
 
 
                 return dst;
                 return dst;
@@ -282,20 +282,20 @@ namespace SharpGLTF.Geometry.VertexTypes
 
 
             // if there's more source joints than destination joints, transfer with scale
             // if there's more source joints than destination joints, transfer with scale
 
 
-            Span<JointWeightPair> srcjw = stackalloc JointWeightPair[src.MaxJoints];
+            Span<JointWeightPair> srcjw = stackalloc JointWeightPair[src.MaxBindings];
 
 
-            for (int i = 0; i < src.MaxJoints; ++i)
+            for (int i = 0; i < src.MaxBindings; ++i)
             {
             {
-                srcjw[i] = src.GetJoint(i);
+                srcjw[i] = src.GetBinding(i);
             }
             }
 
 
             JointWeightPair.InPlaceReverseBubbleSort(srcjw);
             JointWeightPair.InPlaceReverseBubbleSort(srcjw);
 
 
-            var w = JointWeightPair.CalculateScaleFor(srcjw, dst.MaxJoints);
+            var w = JointWeightPair.CalculateScaleFor(srcjw, dst.MaxBindings);
 
 
-            for (int i = 0; i < dst.MaxJoints; ++i)
+            for (int i = 0; i < dst.MaxBindings; ++i)
             {
             {
-                dst.SetJoint(i, srcjw[i].Joint, srcjw[i].Weight * w);
+                dst.SetBinding(i, srcjw[i].Joint, srcjw[i].Weight * w);
             }
             }
 
 
             return dst;
             return dst;

+ 13 - 13
tests/SharpGLTF.Tests/Geometry/VertexTypes/VertexSkinningTests.cs

@@ -14,23 +14,23 @@ namespace SharpGLTF.Geometry.VertexTypes
         public void TestCloneAs()
         public void TestCloneAs()
         {
         {
             var v8 = new VertexJoints8x8();
             var v8 = new VertexJoints8x8();
-            v8.SetJoint(0, 1, 0.2f);
-            v8.SetJoint(1, 2, 0.15f);
-            v8.SetJoint(2, 3, 0.25f);
-            v8.SetJoint(3, 4, 0.10f);
-            v8.SetJoint(4, 5, 0.30f);
+            v8.SetBinding(0, 1, 0.2f);
+            v8.SetBinding(1, 2, 0.15f);
+            v8.SetBinding(2, 3, 0.25f);
+            v8.SetBinding(3, 4, 0.10f);
+            v8.SetBinding(4, 5, 0.30f);
 
 
             var v4 = v8.CloneAs<VertexJoints8x4>();
             var v4 = v8.CloneAs<VertexJoints8x4>();
 
 
-            Assert.AreEqual(5, v4.GetJoint(0).Joint);
-            Assert.AreEqual(3, v4.GetJoint(1).Joint);
-            Assert.AreEqual(1, v4.GetJoint(2).Joint);
-            Assert.AreEqual(2, v4.GetJoint(3).Joint);
+            Assert.AreEqual(5, v4.GetBinding(0).Joint);
+            Assert.AreEqual(3, v4.GetBinding(1).Joint);
+            Assert.AreEqual(1, v4.GetBinding(2).Joint);
+            Assert.AreEqual(2, v4.GetBinding(3).Joint);
 
 
-            Assert.AreEqual(0.333333f, v4.GetJoint(0).Weight, 0.01f);
-            Assert.AreEqual(0.277777f, v4.GetJoint(1).Weight, 0.01f);
-            Assert.AreEqual(0.222222f, v4.GetJoint(2).Weight, 0.01f);
-            Assert.AreEqual(0.166666f, v4.GetJoint(3).Weight, 0.01f);
+            Assert.AreEqual(0.333333f, v4.GetBinding(0).Weight, 0.01f);
+            Assert.AreEqual(0.277777f, v4.GetBinding(1).Weight, 0.01f);
+            Assert.AreEqual(0.222222f, v4.GetBinding(2).Weight, 0.01f);
+            Assert.AreEqual(0.166666f, v4.GetBinding(3).Weight, 0.01f);
         }
         }
     }
     }
 }
 }