2
0
Эх сурвалжийг харах

add failing test for loading model with bufferView defined in extension, not in accessor

Bert Temme 6 сар өмнө
parent
commit
23d4ed15ac

+ 20 - 0
tests/SharpGLTF.ThirdParty.Tests/AccessorBufferViewMissingTest.cs

@@ -0,0 +1,20 @@
+using NUnit.Framework;
+using SharpGLTF.Schema2;
+
+namespace SharpGLTF.ThirdParty
+{
+    public class AccessorBufferViewMissing
+    {
+        [Test]
+        public void ModelLoadFailsWhenAccessorBufferViewMissing()
+        {
+            ExtensionsFactory.RegisterExtension<MeshPrimitive, SpzGaussianSplatsCompression>("KHR_spz_gaussian_splats_compression", p => new SpzGaussianSplatsCompression(p));
+
+            // Currently, the model loading fails with SharpGLTF.Validation.SchemaException: 'Accessor[0] _bufferView: must be defined.Model'
+            // This is because the accessor does not have a bufferView defined,
+            // the bufferView is defined in the Splat extension.
+            var modelRoot = ModelRoot.Load("./TestFixtures/tower.glb");
+        }
+
+    }
+}

+ 90 - 0
tests/SharpGLTF.ThirdParty.Tests/GaussianSplatExtension.cs

@@ -0,0 +1,90 @@
+using System;
+using System.Collections.Generic;
+
+using JSONREADER = System.Text.Json.Utf8JsonReader;
+using JSONWRITER = System.Text.Json.Utf8JsonWriter;
+using FIELDINFO = SharpGLTF.Reflection.FieldInfo;
+using SharpGLTF.Schema2;
+
+namespace SharpGLTF.ThirdParty
+{
+    partial class SpzGaussianSplatsCompression
+    {
+        private MeshPrimitive meshPrimitive;
+
+        internal SpzGaussianSplatsCompression(MeshPrimitive meshPrimitive)
+        {
+            this.meshPrimitive = meshPrimitive;
+        }
+
+        public int BufferViewIndex
+        {
+            get => _bufferView;
+            set
+            {
+                _bufferView = value;
+            }
+        }
+    }
+
+
+
+
+    /// <summary>
+    /// Compressed data for SPZ primitive.
+    /// </summary>
+#if NET6_0_OR_GREATER
+	[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.NonPublicConstructors | System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicConstructors)]
+#endif
+    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("SharpGLTF.CodeGen", "1.0.0.0")]
+    partial class SpzGaussianSplatsCompression : ExtraProperties
+    {
+
+        #region reflection
+
+        public new const string SCHEMANAME = "KHR_spz_gaussian_splats_compression";
+        protected override string GetSchemaName() => SCHEMANAME;
+
+        protected override IEnumerable<string> ReflectFieldsNames()
+        {
+            yield return "bufferView";
+            foreach (var f in base.ReflectFieldsNames()) yield return f;
+        }
+        protected override bool TryReflectField(string name, out FIELDINFO value)
+        {
+            switch (name)
+            {
+                case "bufferView": value = FIELDINFO.From("bufferView", this, instance => instance._bufferView); return true;
+                default: return base.TryReflectField(name, out value);
+            }
+        }
+
+        #endregion
+
+        #region data
+
+        private Int32 _bufferView;
+
+        #endregion
+
+        #region serialization
+
+        protected override void SerializeProperties(JSONWRITER writer)
+        {
+            base.SerializeProperties(writer);
+            SerializeProperty(writer, "bufferView", _bufferView);
+        }
+
+        protected override void DeserializeProperty(string jsonPropertyName, ref JSONREADER reader)
+        {
+            switch (jsonPropertyName)
+            {
+                case "bufferView": DeserializePropertyValue<SpzGaussianSplatsCompression, Int32>(ref reader, this, out _bufferView); break;
+                default: base.DeserializeProperty(jsonPropertyName, ref reader); break;
+            }
+        }
+
+        #endregion
+
+    }
+}

+ 6 - 0
tests/SharpGLTF.ThirdParty.Tests/SharpGLTF.ThirdParty.Tests.csproj

@@ -29,4 +29,10 @@
     <ProjectReference Include="..\SharpGLTF.NUnit\SharpGLTF.NUnit.csproj" />
     <ProjectReference Include="..\SharpGLTF.NUnit\SharpGLTF.NUnit.csproj" />
   </ItemGroup>
   </ItemGroup>
 
 
+  <ItemGroup>
+    <None Update="TestFixtures\tower.glb">
+      <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+    </None>
+  </ItemGroup>
+
 </Project>
 </Project>

BIN
tests/SharpGLTF.ThirdParty.Tests/TestFixtures/tower.glb