Quellcode durchsuchen

Small code cleanup

Vicente Penades vor 5 Jahren
Ursprung
Commit
8f1f16354b

+ 7 - 12
src/SharpGLTF.Core/Schema2/gltf.MeshPrimitive.cs

@@ -317,7 +317,7 @@ namespace SharpGLTF.Schema2
                 }
             }
 
-            // check vertex attributes accessors
+            // check vertex attributes accessors ByteStride
 
             foreach (var group in this.VertexAccessors.Values.GroupBy(item => item.SourceBufferView))
             {
@@ -331,15 +331,10 @@ namespace SharpGLTF.Schema2
                     // - sequential accessors: all accessors's ElementByteStride should be EQUAL to BufferView's ByteStride
                     // - strided accessors: all accessors's ElementByteStride should SUM to BufferView's ByteStride
 
-                    if (group.All(item => item.ElementByteSize.WordPadded() == group.Key.ByteStride))
-                    {
-                        // sequential format.
-                    }
-                    else if (group.Sum(item => item.ElementByteSize.WordPadded()) == group.Key.ByteStride)
-                    {
-                        // strided format.
-                    }
-                    else
+                    bool isSequential = group.All(item => item.Format.ByteSizePadded == group.Key.ByteStride);
+                    bool isStrided    = group.Sum(item => item.Format.ByteSizePadded) == group.Key.ByteStride;
+
+                    if (!(isSequential || isStrided))
                     {
                         var accessors = string.Join(" ", group.Select(item => item.LogicalIndex));
                         validate._LinkThrow("Attributes", $"Inconsistent accessors configuration: {accessors}");
@@ -352,8 +347,8 @@ namespace SharpGLTF.Schema2
             if (validate.TryFix)
             {
                 var vattributes = this.VertexAccessors
-                .Select(item => item.Value._GetMemoryAccessor(item.Key))
-                .ToArray();
+                    .Select(item => item.Value._GetMemoryAccessor(item.Key))
+                    .ToArray();
 
                 Memory.MemoryAccessor.SanitizeVertexAttributes(vattributes);
             }

+ 3 - 3
src/SharpGLTF.Core/Schema2/gltf.Node.cs

@@ -454,9 +454,9 @@ namespace SharpGLTF.Schema2
             }
 
             validate
-                .IsNullOrPosition("Scale", _scale)
-                .IsNullOrRotation("Rotation", _rotation)
-                .IsNullOrPosition("Translation", _translation)
+                .IsPosition("Scale", _scale.AsValue(Vector3.One))
+                .IsRotation("Rotation", _rotation.AsValue(Quaternion.Identity))
+                .IsPosition("Translation", _translation.AsValue(Vector3.Zero))
                 .IsNullOrMatrix("Rotation", _matrix);
         }
 

+ 1 - 27
src/SharpGLTF.Core/Validation/ValidationContext.Guards.cs

@@ -221,7 +221,7 @@ namespace SharpGLTF.Validation
         #region data
 
         [System.Diagnostics.DebuggerStepThrough]
-        internal void _DataThrow(PARAMNAME pname, string msg) { throw new DataException(_Current, $"{pname}: {msg}"); }
+        private void _DataThrow(PARAMNAME pname, string msg) { throw new DataException(_Current, $"{pname}: {msg}"); }
 
         public OUTTYPE IsInRange<T>(PARAMNAME pname, T value, T minInclusive, T maxInclusive)
             where T : IComparable<T>
@@ -231,26 +231,6 @@ namespace SharpGLTF.Validation
             return this;
         }
 
-        public OUTTYPE IsInRange(PARAMNAME pname, double? value, double minInclusive, double maxInclusive)
-        {
-            if (!value.HasValue) return this;
-            if (value.Value < minInclusive) _DataThrow(pname, $"is below minimum {minInclusive} value: {value}");
-            if (value.Value > maxInclusive) _DataThrow(pname, $"is above maximum {maxInclusive} value: {value}");
-            return this;
-        }
-
-        public OUTTYPE IsNullOrPosition(PARAMNAME pname, System.Numerics.Vector3? position)
-        {
-            if (!position.HasValue) return this;
-            return IsPosition(pname, position.Value);
-        }
-
-        public OUTTYPE IsNullOrRotation(PARAMNAME pname, System.Numerics.Quaternion? rotation)
-        {
-            if (!rotation.HasValue) return this;
-            return IsRotation(pname, rotation.Value);
-        }
-
         public OUTTYPE IsNullOrMatrix(PARAMNAME pname, System.Numerics.Matrix4x4? matrix)
         {
             if (!matrix.HasValue) return this;
@@ -275,12 +255,6 @@ namespace SharpGLTF.Validation
             return this;
         }
 
-        public OUTTYPE IsNormal(PARAMNAME pname, in System.Numerics.Vector4 tangent)
-        {
-            if (!tangent.IsValidTangent()) _DataThrow(pname, "Invalid Tangent");
-            return this;
-        }
-
         public OUTTYPE IsMatrix(PARAMNAME pname, in System.Numerics.Matrix4x4 matrix)
         {
             if (!matrix.IsValid()) _DataThrow(pname, "Invalid Matrix");