Bladeren bron

Added unit tests to fix invalid tangents commonly exported by Sketchfab auto exporter.

Vicente Penades 5 jaren geleden
bovenliggende
commit
439e161873

+ 1 - 0
src/Shared/_Extensions.cs

@@ -153,6 +153,7 @@ namespace SharpGLTF
 
         internal static Vector3 SanitizeNormal(this Vector3 normal)
         {
+            if (normal == Vector3.Zero) return Vector3.UnitX;
             return normal.IsNormalized() ? normal : Vector3.Normalize(normal);
         }
 

BIN
tests/Assets/SpecialCases/SketchfabExport-WhatIsPBR.glb


+ 15 - 0
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadSpecialModelsTest.cs

@@ -156,6 +156,21 @@ namespace SharpGLTF.Schema2.LoadAndSave
             model.AttachToCurrentTest("mouse_01.obj", model.LogicalAnimations[1], 1f);
         }
 
+        [TestCase("SketchfabExport-WhatIsPBR.glb")] // model has exported tangents in the form <0,0,0,1>
+        public void LoadSketchfabModels(string path)
+        {
+            // this model has several nodes with curve animations containing a single animation key,
+            // which is causing some problems to the interpolator.
+
+            TestContext.CurrentContext.AttachShowDirLink();
+
+            path = System.IO.Path.Combine(TestContext.CurrentContext.TestDirectory, $"Assets\\SpecialCases\\{path}");
+
+            var model = ModelRoot.Load(path, Validation.ValidationMode.TryFix);
+
+            model.AttachToCurrentTest("output.glb");            
+        }
+
         // these models show normal mapping but lack tangents, which are expected to be
         // generated at runtime; These tests generate the tangents and check them against the baseline.
         [TestCase("NormalTangentTest.glb")]