فهرست منبع

Updated nugets
Small code fixes.

Vicente Penades 5 سال پیش
والد
کامیت
0fb914259d

+ 1 - 1
build/SharpGLTF.CodeGen/SharpGLTF.CodeGen.csproj

@@ -8,7 +8,7 @@
 
 
   <ItemGroup>
   <ItemGroup>
     <PackageReference Include="LibGit2Sharp" Version="0.26.2" />    
     <PackageReference Include="LibGit2Sharp" Version="0.26.2" />    
-    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.1.18" />
+    <PackageReference Include="NJsonSchema.CodeGeneration.CSharp" Version="10.1.21" />
   </ItemGroup>
   </ItemGroup>
 
 
 </Project>
 </Project>

+ 1 - 1
src/Shared/Guard.cs

@@ -109,7 +109,7 @@ namespace SharpGLTF
         {
         {
             if (value.CompareTo(expected) == 0) return;
             if (value.CompareTo(expected) == 0) return;
 
 
-            throw new ArgumentOutOfRangeException(parameterName, $"{parameterName} {value} must be equal to {expected}.");
+            throw new ArgumentException(parameterName, $"{parameterName} {value} must be equal to {expected}.");
         }
         }
 
 
         public static void MustBePositiveAndMultipleOf(int value, int padding, string parameterName, string message = "")
         public static void MustBePositiveAndMultipleOf(int value, int padding, string parameterName, string message = "")

+ 2 - 1
src/Shared/_Extensions.cs

@@ -177,11 +177,12 @@ namespace SharpGLTF
             return dst;
             return dst;
         }
         }
 
 
-        internal static bool IsValid(this in Matrix4x4 matrix, bool mustDecompose = true, bool mustInvert = true)
+        internal static bool IsValid(this in Matrix4x4 matrix, bool mustDecompose = true, bool mustInvert = true, bool mustPositiveDeterminant = false)
         {
         {
             if (!matrix._IsFinite()) return false;
             if (!matrix._IsFinite()) return false;
             if (mustDecompose && !Matrix4x4.Decompose(matrix, out _, out _, out _)) return false;
             if (mustDecompose && !Matrix4x4.Decompose(matrix, out _, out _, out _)) return false;
             if (mustInvert && !Matrix4x4.Invert(matrix, out _)) return false;
             if (mustInvert && !Matrix4x4.Invert(matrix, out _)) return false;
+            if (mustPositiveDeterminant && matrix.GetDeterminant() < 0) return false;
 
 
             return true;
             return true;
         }
         }

+ 1 - 1
src/SharpGLTF.Core/Debug/DebugViews.cs

@@ -55,7 +55,7 @@ namespace SharpGLTF.Debug
 
 
         public Schema2.BufferView Source => _Value.SourceBufferView;
         public Schema2.BufferView Source => _Value.SourceBufferView;
 
 
-        public (Schema2.DimensionType, Schema2.EncodingType, bool) Format => (_Value.Dimensions, _Value.Encoding, _Value.Normalized);
+        public (Schema2.DimensionType Dimensions, Schema2.EncodingType Encoding, bool Normalized) Format => (_Value.Dimensions, _Value.Encoding, _Value.Normalized);
 
 
         public Object[] Items
         public Object[] Items
         {
         {

+ 21 - 14
src/SharpGLTF.Core/Schema2/gltf.MeshPrimitive.cs

@@ -321,24 +321,31 @@ namespace SharpGLTF.Schema2
 
 
             foreach (var group in this.VertexAccessors.Values.GroupBy(item => item.SourceBufferView))
             foreach (var group in this.VertexAccessors.Values.GroupBy(item => item.SourceBufferView))
             {
             {
-                if (group.Skip(1).Any())
-                {
-                    // if more than one accessor shares a BufferView, it must define a ByteStride
+                if (!group.Skip(1).Any()) continue;
 
 
-                    validate.IsGreater("ByteStride", group.Key.ByteStride, 0); // " must be defined when two or more accessors use the same BufferView."
+                // if more than one accessor shares a BufferView, it must define a ByteStride
 
 
-                    // now, there's two possible outcomes:
-                    // - 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
+                validate.IsGreater("ByteStride", group.Key.ByteStride, 0); // " must be defined when two or more accessors use the same BufferView."
 
 
-                    bool isSequential = group.All(item => item.Format.ByteSizePadded == group.Key.ByteStride);
-                    bool isStrided    = group.Sum(item => item.Format.ByteSizePadded) == group.Key.ByteStride;
+                // determine if we're sequential or strided by checking if the memory buffers overlap
+                var memories = group.Select(item => item._GetMemoryAccessor());
+                var overlap = Memory.MemoryAccessor.HaveOverlappingBuffers(memories);
 
 
-                    if (!(isSequential || isStrided))
-                    {
-                        var accessors = string.Join(" ", group.Select(item => item.LogicalIndex));
-                        validate._LinkThrow("Attributes", $"Inconsistent accessors configuration: {accessors}");
-                    }
+                bool ok = false;
+
+                if (overlap) // strided buffer detected
+                {
+                    ok = group.Sum(item => item.Format.ByteSizePadded) == group.Key.ByteStride;
+                }
+                else // sequential buffer detected
+                {
+                    ok = group.All(item => item.Format.ByteSizePadded <= group.Key.ByteStride);
+                }
+
+                if (!ok)
+                {
+                    var accessors = string.Join(" ", group.Select(item => item.LogicalIndex));
+                    validate._LinkThrow("Attributes", $"Inconsistent accessors configuration: {accessors}");
                 }
                 }
             }
             }
 
 

+ 11 - 5
tests/SharpGLTF.NUnit/NUnitGltfUtils.cs

@@ -6,6 +6,8 @@ using System.Text;
 
 
 using NUnit.Framework;
 using NUnit.Framework;
 
 
+using SharpGLTF.Schema2;
+
 namespace SharpGLTF
 namespace SharpGLTF
 {
 {
     public static class NUnitGltfUtils
     public static class NUnitGltfUtils
@@ -53,18 +55,20 @@ namespace SharpGLTF
             gl2model.AttachToCurrentTest(fileName);
             gl2model.AttachToCurrentTest(fileName);
         }
         }
 
 
-        public static void AttachToCurrentTest(this Schema2.ModelRoot model, string fileName)
+        public static string AttachToCurrentTest(this Schema2.ModelRoot model, string fileName, WriteSettings settings = null)
         {
         {
             // find the output path for the current test
             // find the output path for the current test
             fileName = TestContext.CurrentContext.GetAttachmentPath(fileName, true);
             fileName = TestContext.CurrentContext.GetAttachmentPath(fileName, true);
 
 
             if (fileName.ToLower().EndsWith(".glb"))
             if (fileName.ToLower().EndsWith(".glb"))
             {
             {
-                model.SaveGLB(fileName);
+                model.SaveGLB(fileName, settings);
             }
             }
             else if (fileName.ToLower().EndsWith(".gltf"))
             else if (fileName.ToLower().EndsWith(".gltf"))
             {
             {
-                model.Save(fileName, new Schema2.WriteSettings { JsonIndented = true });
+                if (settings == null) settings = new WriteSettings { JsonIndented = true };
+
+                model.Save(fileName, settings);
             }
             }
             else if (fileName.ToLower().EndsWith(".obj"))
             else if (fileName.ToLower().EndsWith(".obj"))
             {
             {
@@ -75,10 +79,10 @@ namespace SharpGLTF
             // Attach the saved file to the current test
             // Attach the saved file to the current test
             TestContext.AddTestAttachment(fileName);
             TestContext.AddTestAttachment(fileName);
 
 
-            if (fileName.ToLower().EndsWith(".obj")) return;
+            if (fileName.ToLower().EndsWith(".obj")) return fileName;
 
 
             var report = gltf_validator.ValidateFile(fileName);
             var report = gltf_validator.ValidateFile(fileName);
-            if (report == null) return;
+            if (report == null) return fileName;
 
 
             if (report.HasErrors || report.HasWarnings)
             if (report.HasErrors || report.HasWarnings)
             {
             {
@@ -86,6 +90,8 @@ namespace SharpGLTF
             }
             }
 
 
             Assert.IsFalse(report.HasErrors);
             Assert.IsFalse(report.HasErrors);
+
+            return fileName;
         }
         }
     }
     }
 
 

+ 11 - 0
tests/SharpGLTF.NUnit/NUnitUtils.cs

@@ -64,5 +64,16 @@ namespace SharpGLTF
 
 
             TestContext.AddTestAttachment(linkPath);
             TestContext.AddTestAttachment(linkPath);
         }
         }
+
+        public static string AttachToCurrentTest(this Byte[] data, string fileName)
+        {
+            fileName = TestContext.CurrentContext.GetAttachmentPath(fileName, true);
+
+            System.IO.File.WriteAllBytes(fileName, data);
+
+            TestContext.AddTestAttachment(fileName);
+
+            return fileName;
+        }
     }
     }
 }
 }

+ 1 - 0
tests/SharpGLTF.NUnit/TestFiles.cs

@@ -197,6 +197,7 @@ namespace SharpGLTF
                 .OrderBy(item => item)
                 .OrderBy(item => item)
                 .Where(item => !item.Contains("\\AssetGenerator\\0.6\\"))
                 .Where(item => !item.Contains("\\AssetGenerator\\0.6\\"))
                 .Where(item => !item.Contains("\\Sheen\\"))
                 .Where(item => !item.Contains("\\Sheen\\"))
+                .Where(item => !item.Contains("\\Demos\\retargeting\\riggedMesh.glb"))
                 .Where(item => !_BabylonJsInvalidFiles.Any(ff => item.EndsWith(ff)))                
                 .Where(item => !_BabylonJsInvalidFiles.Any(ff => item.EndsWith(ff)))                
                 .ToList();
                 .ToList();
         }
         }