Browse Source

start multiple classes test

Bert Temme 2 years ago
parent
commit
98b56c4955

+ 7 - 2
src/SharpGLTF.Cesium/Schema2/EXTStructuralMetaDataRoot.cs

@@ -49,7 +49,7 @@ namespace SharpGLTF.Schema2
 
 
             var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
             var ext = modelRoot.UseExtension<EXTStructuralMetaDataRoot>();
             ext.PropertyTables.Clear();
             ext.PropertyTables.Clear();
-            ext.PropertyTables.Add(GetPropertyTable(modelRoot, attributes, name));
+            ext.PropertyTables.Add(GetPropertyTable(modelRoot, attributes, name, schema));
             ext.AddSchema(schema, schemaUri);
             ext.AddSchema(schema, schemaUri);
         }
         }
 
 
@@ -141,8 +141,13 @@ namespace SharpGLTF.Schema2
             set { _propertyTextures = value; }
             set { _propertyTextures = value; }
         }
         }
 
 
-        protected override void OnValidateContent(ValidationContext validate)
+        protected override void OnValidateContent(ValidationContext result)
         {
         {
+            // Schema or SchemaUri must be defined
+            Guard.IsTrue(Schema != null || SchemaUri != null, "Schema/SchemaUri", "Schema or SchemaUri must be defined");
+
+            base.OnValidateContent(result);
+
         }
         }
     }
     }
 
 

+ 29 - 1
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -20,8 +20,36 @@ namespace SharpGLTF.Cesium
             CesiumExtensions.RegisterExtensions();
             CesiumExtensions.RegisterExtensions();
         }
         }
 
 
+        [Test(Description = "ext_structural_metadata with multiple classes")]
+        // Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/MultipleClasses/MultipleClasses.gltf
+        public void MultipleClassesTest()
+        {
+            var material = MaterialBuilder.CreateDefault().WithDoubleSide(true);
+
+            var mesh = new MeshBuilder<VertexPositionNormal, VertexWithFeatureIds, VertexEmpty>("mesh");
+            var prim = mesh.UsePrimitive(material);
+
+            // All the vertices in the triangle have the same feature ID
+            var vt0 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(-10, 0, 0), new Vector3(0, 0, 1), 0, 100);
+            var vt1 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(10, 0, 0), new Vector3(0, 0, 1), 0, 100);
+            var vt2 = VertexBuilder.GetVertexWithFeatureIds(new Vector3(0, 10, 0), new Vector3(0, 0, 1), 0, 100);
+
+            prim.AddTriangle(vt0, vt1, vt2);
+            var scene = new SceneBuilder();
+            scene.AddRigidMesh(mesh, Matrix4x4.Identity);
+            var model = scene.ToGltf2();
+
+            // todo: add metadata
+
+            var ctx = new ValidationResult(model, ValidationMode.Strict, true);
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.glb");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.gltf");
+            model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.plotly");
+        }
+
+
         [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")]
         [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")]
-        /// Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/PropertyAttributesPointCloudHouse.gltf
+        // Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/PropertyAttributesPointCloud/PropertyAttributesPointCloudHouse.gltf
 
 
         public void CreatePointCloudWithCustomAttributesTest()
         public void CreatePointCloudWithCustomAttributesTest()
         {
         {

+ 9 - 0
tests/SharpGLTF.Cesium.Tests/VertexBuilder.cs

@@ -6,6 +6,15 @@ namespace SharpGLTF
 {
 {
     public static class VertexBuilder
     public static class VertexBuilder
     {
     {
+        internal static VertexBuilder<VertexPositionNormal, VertexWithFeatureIds, VertexEmpty> GetVertexWithFeatureIds(Vector3 position, Vector3 normal, int featureId0, int featureId1)
+        {
+            var vertexWithFeatureIds = new VertexWithFeatureIds(featureId0, featureId1);
+
+            var vp0 = new VertexPositionNormal(position, normal);
+            var vb0 = new VertexBuilder<VertexPositionNormal, VertexWithFeatureIds, VertexEmpty>(vp0, vertexWithFeatureIds);
+            return vb0;
+        }
+
         internal static VertexBuilder<VertexPositionNormal, VertexWithFeatureId, VertexEmpty> GetVertexWithFeatureId(Vector3 position, Vector3 normal, int featureid)
         internal static VertexBuilder<VertexPositionNormal, VertexWithFeatureId, VertexEmpty> GetVertexWithFeatureId(Vector3 position, Vector3 normal, int featureid)
         {
         {
             var vp0 = new VertexPositionNormal(position, normal);
             var vp0 = new VertexPositionNormal(position, normal);

+ 81 - 0
tests/SharpGLTF.Cesium.Tests/VertexWithFeatureIds.cs

@@ -0,0 +1,81 @@
+using System;
+using System.Collections.Generic;
+using System.Numerics;
+
+using SharpGLTF.Geometry.VertexTypes;
+using SharpGLTF.Schema2;
+
+namespace SharpGLTF
+{
+    [System.Diagnostics.DebuggerDisplay("𝐂:{Color} 𝐔𝐕:{TexCoord}")]
+    public struct VertexWithFeatureIds : IVertexCustom
+    {
+        public VertexWithFeatureIds(float featureId0, float featureId1)
+        {
+            FeatureId0 = featureId0;
+            FeatureId1 = featureId1;
+        }
+
+        public const string FEATUREID0ATTRIBUTENAME = "_FEATURE_ID_0";
+        public const string FEATUREID1ATTRIBUTENAME = "_FEATURE_ID_1";
+
+        [VertexAttribute(FEATUREID0ATTRIBUTENAME, EncodingType.FLOAT, false)]
+        public float FeatureId0;
+
+        [VertexAttribute(FEATUREID1ATTRIBUTENAME, EncodingType.FLOAT, false)]
+        public float FeatureId1;
+
+        public int MaxColors => 0;
+
+        public int MaxTextCoords => 0;
+
+        public IEnumerable<string> CustomAttributes => throw new NotImplementedException();
+
+        public void SetColor(int setIndex, Vector4 color) { }
+
+        public void SetTexCoord(int setIndex, Vector2 coord) { }
+
+        public Vector4 GetColor(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
+
+        public Vector2 GetTexCoord(int index) { throw new ArgumentOutOfRangeException(nameof(index)); }
+
+        public void Validate() { }
+
+        public object GetCustomAttribute(string attributeName)
+        {
+            throw new NotImplementedException();
+        }
+
+        public bool TryGetCustomAttribute(string attribute, out object value)
+        {
+            if (attribute == FEATUREID0ATTRIBUTENAME)
+            {
+                value = FeatureId0; return true;
+            }
+            else if (attribute == FEATUREID1ATTRIBUTENAME)
+            {
+                value = FeatureId1; return true;
+            }
+            else
+            {
+                value = null; return false;
+            }
+
+        }
+
+        public void SetCustomAttribute(string attributeName, object value)
+        {
+            throw new NotImplementedException();
+        }
+
+        public VertexMaterialDelta Subtract(IVertexMaterial baseValue)
+        {
+            throw new NotImplementedException();
+        }
+
+        public void Add(in VertexMaterialDelta delta)
+        {
+            throw new NotImplementedException();
+        }
+    }
+}