瀏覽代碼

Fixed compatibility with KHR_mesh_quantized
Upadted nuget packages

Vicente Penades 5 年之前
父節點
當前提交
9145530450

+ 2 - 2
SharpGLTF.sln

@@ -6,7 +6,7 @@ MinimumVisualStudioVersion = 10.0.40219.1
 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{29566B60-311D-42A0-9E8D-C48DECDD587F}"
 	ProjectSection(SolutionItems) = preProject
 		.editorconfig = .editorconfig
-		Analyzers.targets = Analyzers.targets
+		src\Analyzers.props = src\Analyzers.props
 		README.md = README.md
 		SharpGLTF.ruleset = SharpGLTF.ruleset
 	EndProjectSection
@@ -43,7 +43,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Core.Tests", "tes
 EndProject
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Toolkit.Tests", "tests\SharpGLTF.Toolkit.Tests\SharpGLTF.Toolkit.Tests.csproj", "{7FEFC259-51D6-4409-8724-8DE0EA8D5CD9}"
 EndProject
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpGLTF.Plotly", "examples\SharpGLTF.Plotly\SharpGLTF.Plotly.csproj", "{A63C2A2D-950F-4C76-9299-2B2D325A8653}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SharpGLTF.Plotly", "examples\SharpGLTF.Plotly\SharpGLTF.Plotly.csproj", "{A63C2A2D-950F-4C76-9299-2B2D325A8653}"
 EndProject
 Global
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution

+ 1 - 1
examples/MonoGameScene/MonoGameScene.csproj

@@ -8,7 +8,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1375-develop" />
+    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />
   </ItemGroup>
 
   <ItemGroup>

+ 1 - 1
examples/SharpGLTF.Runtime.MonoGame/SharpGLTF.Runtime.MonoGame.csproj

@@ -8,7 +8,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1375-develop" />    
+    <PackageReference Include="MonoGame.Framework.DesktopGL" Version="3.8.0.1641" />    
   </ItemGroup>
 
   <ItemGroup>

+ 2 - 2
src/Analyzers.props

@@ -10,8 +10,8 @@
   </ItemGroup>
 
   <ItemGroup>    
-    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.0.0" PrivateAssets="all" />
-    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.0.0" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="3.3.0" PrivateAssets="all" />
+    <PackageReference Include="Microsoft.CodeQuality.Analyzers" Version="3.3.0" PrivateAssets="all" />
     <PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="all" />
   </ItemGroup>
 	

+ 32 - 27
src/SharpGLTF.Core/IO/ReadContext.cs

@@ -254,43 +254,47 @@ namespace SharpGLTF.IO
             var root = new SCHEMA2();
             var vcontext = new Validation.ValidationResult(root, this.Validation);
 
-            try
-            {
-                if (jsonUtf8Bytes.IsEmpty) throw new System.Text.Json.JsonException("JSon is empty.");
+            #if !SUPRESSTRYCATCH
+            try {
+            #endif
 
-                var reader = new Utf8JsonReader(jsonUtf8Bytes.Span);
+            if (jsonUtf8Bytes.IsEmpty) throw new System.Text.Json.JsonException("JSon is empty.");
 
-                if (!reader.Read())
-                {
-                    vcontext.SetError(new Validation.SchemaException(root, "Json is empty"));
-                    return (null, vcontext);
-                }
+            var reader = new Utf8JsonReader(jsonUtf8Bytes.Span);
 
-                root.Deserialize(ref reader);
-                root.OnDeserializationCompleted();
+            if (!reader.Read())
+            {
+                vcontext.SetError(new Validation.SchemaException(root, "Json is empty"));
+                return (null, vcontext);
+            }
 
-                // binary chunk check
+            root.Deserialize(ref reader);
+            root.OnDeserializationCompleted();
 
-                foreach (var b in root.LogicalBuffers) b.OnValidateBinaryChunk(vcontext.GetContext(), this._BinaryChunk);
+            // binary chunk check
 
-                // schema validation
+            foreach (var b in root.LogicalBuffers) b.OnValidateBinaryChunk(vcontext.GetContext(), this._BinaryChunk);
 
-                root.ValidateReferences(vcontext.GetContext());
-                var ex = vcontext.Errors.FirstOrDefault();
-                if (ex != null) return (null, vcontext);
+            // schema validation
 
-                // resolve external dependencies
+            root.ValidateReferences(vcontext.GetContext());
+            var ex = vcontext.Errors.FirstOrDefault();
+            if (ex != null) return (null, vcontext);
 
-                root._ResolveSatelliteDependencies(this);
+            // resolve external dependencies
 
-                // full validation
+            root._ResolveSatelliteDependencies(this);
 
-                if (this.Validation != VALIDATIONMODE.Skip)
-                {
-                    root.ValidateContent(vcontext.GetContext());
-                    ex = vcontext.Errors.FirstOrDefault();
-                    if (ex != null) return (null, vcontext);
-                }
+            // full validation
+
+            if (this.Validation != VALIDATIONMODE.Skip)
+            {
+                root.ValidateContent(vcontext.GetContext());
+                ex = vcontext.Errors.FirstOrDefault();
+                if (ex != null) return (null, vcontext);
+            }
+
+            #if !SUPRESSTRYCATCH
             }
             catch (JsonException rex)
             {
@@ -312,6 +316,7 @@ namespace SharpGLTF.IO
                 vcontext.SetError(mex);
                 return (null, vcontext);
             }
+            #endif
 
             return (root, vcontext);
         }
@@ -355,6 +360,6 @@ namespace SharpGLTF.IO
             return stream.ReadBytesToEnd();
         }
 
-        #endregion
+#endregion
     }
 }

+ 13 - 5
src/SharpGLTF.Core/Schema2/gltf.ExtensionsFactory.cs

@@ -40,7 +40,9 @@ namespace SharpGLTF.Schema2
 
         #region API
 
-        public static IEnumerable<string> SupportedExtensions => _Extensions.Select(item => item.Name);
+        public static IEnumerable<string> SupportedExtensions => _Extensions
+            .Select(item => item.Name)
+            .Concat(new[] { "KHR_mesh_quantization" });
 
         public static void RegisterExtension<TParent, TExtension>(string persistentName)
             where TParent : JsonSerializable
@@ -93,7 +95,8 @@ namespace SharpGLTF.Schema2
         #region API
 
         /// <summary>
-        /// Immediatelly called after deserialization, it assigns
+        /// Immediatelly called after deserialization, it enables <see cref="MeshQuantizationAllowed"/>
+        /// to prevent validators to throw errors
         /// </summary>
         private void _FindMeshQuantizationExtension()
         {
@@ -113,10 +116,15 @@ namespace SharpGLTF.Schema2
 
         private void _SetRequiredExtension(string extension, bool enabled)
         {
-            if (!enabled) { this._extensionsRequired.Remove(extension); return; }
+            if (!enabled)
+            {
+                this._extensionsUsed.Remove(extension);
+                this._extensionsRequired.Remove(extension);
+                return;
+            }
 
-            if (this._extensionsRequired.Contains(extension)) return;
-            this._extensionsRequired.Add(extension);
+            if (!this._extensionsUsed.Contains(extension)) this._extensionsUsed.Add(extension);
+            if (!this._extensionsRequired.Contains(extension)) this._extensionsRequired.Add(extension);
         }
 
         internal IEnumerable<ExtraProperties> GetLogicalChildrenFlattened()

+ 12 - 1
tests/SharpGLTF.Tests/Schema2/LoadAndSave/LoadSampleTests.cs

@@ -148,7 +148,18 @@ namespace SharpGLTF.Schema2.LoadAndSave
 
         [TestCase("SpecGlossVsMetalRough.gltf")]
         [TestCase(@"TextureTransformTest.gltf")]
-        [TestCase(@"UnlitTest\glTF-Binary\UnlitTest.glb")]        
+        [TestCase(@"UnlitTest\glTF-Binary\UnlitTest.glb")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\Avocado.gltf")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\BarramundiFish.gltf")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\BoomBox.gltf")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\Corset.gltf")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\Lantern.gltf")]
+        [TestCase(@"glTF-pbrSpecularGlossiness\WaterBottle.gltf")]
+        [TestCase(@"glTF-Quantized\Avocado.gltf")]
+        [TestCase(@"glTF-Quantized\AnimatedMorphCube.gltf")]
+        [TestCase(@"glTF-Quantized\AnimatedMorphCube.gltf")]
+        [TestCase(@"glTF-Quantized\Duck.gltf")]
+        [TestCase(@"glTF-Quantized\Lantern.gltf")]
         public void LoadModelsWithExtensions(string filePath)
         {
             TestContext.CurrentContext.AttachShowDirLink();

+ 1 - 1
tests/SharpGLTF.Tests/SharpGLTF.Core.Tests.csproj

@@ -26,7 +26,7 @@
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
   </ItemGroup>  
 
 </Project>

+ 1 - 1
tests/SharpGLTF.Toolkit.Tests/SharpGLTF.Toolkit.Tests.csproj

@@ -26,7 +26,7 @@
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
     </PackageReference>
-    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
+    <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.0" />
   </ItemGroup>  
 
 </Project>