Browse Source

fix pointcloud test

Bert Temme 1 year ago
parent
commit
ce98568665

+ 10 - 3
src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs

@@ -95,9 +95,16 @@ namespace SharpGLTF.Schema2
                 return schema;
             }
 
+            // Sets the schema to use an external schema, returns an empty schema to used for adding schema properties
+            public StructuralMetadataSchema UseExternalSchema(Uri uri)
+            {
+                SchemaUri = uri.ToString();
+                return new StructuralMetadataSchema();
+            }
+
             public StructuralMetadataSchema UseEmbeddedSchema()
             {
-                this.SchemaUri = null;
+                SchemaUri = null;
 
                 if (_schema == null) GetChildSetter(this).SetProperty(ref _schema, new StructuralMetadataSchema());
 
@@ -764,7 +771,7 @@ namespace SharpGLTF.Schema2
 
             void IChildOf<EXTStructuralMetadataRoot>.SetLogicalParent(EXTStructuralMetadataRoot parent)
             {
-                LogicalParent = parent;                
+                LogicalParent = parent;
             }
 
             #endregion
@@ -814,7 +821,7 @@ namespace SharpGLTF.Schema2
             public StructuralMetadataEnum UseEnumMetadata(string key, params (string name, int value)[] enumValues)
             {
                 var enumType = UseEnumMetadata(key);
-                foreach(var (name, value) in enumValues)
+                foreach (var (name, value) in enumValues)
                 {
                     enumType.AddEnum(name, value);
                 }

+ 6 - 15
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -277,7 +277,7 @@ namespace SharpGLTF.Schema2.Tiles3D
             // assign to primitive
 
             var primitive = model.LogicalMeshes[0].Primitives[0];            
-            primitive.AddPropertyTexture(buildingPropertyTexture);            
+            primitive.AddPropertyTexture(buildingPropertyTexture);
 
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
             model.AttachToCurrentTest("cesium_ext_structural_metadata_simple_property_texture.glb");
@@ -590,13 +590,12 @@ namespace SharpGLTF.Schema2.Tiles3D
 
             // features
 
-            // FeatureID 0: featureCount=1, attribute=0, porpertyTable=0 
+            // FeatureID 0: featureCount=1, attribute=0, propertyTable=0 
             var featureId0 = new FeatureIDBuilder(firstPropertyTable, 0);
-            // FeatureID 1: featureCount=1, attribute=1, porpertyTable=1
+            // FeatureID 1: featureCount=1, attribute=1, prorpertyTable=1
             var featureId1 = new FeatureIDBuilder(secondPropertyTable, 1);
             
             model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds(featureId0, featureId1);
-
             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");
@@ -637,17 +636,8 @@ namespace SharpGLTF.Schema2.Tiles3D
             // --------------------------------------------------------------
 
             var rootMetadata = model.UseStructuralMetadata();
-
-            // external references are problematic because the idea behind SharpGLTF is that all files are loaded into memory, so you don't
-            // need to track resources in disk while working with models. The whole mechanism is too complex to be worth the pain of implementing it.
-            // so my idea is that the UseExternalSchema returns a ISchemaProxy interface or something like that, that has pretty much the same methods
-            // of an actual schema, so the API usage remains the same for both an embedded and an external schema.
-
-            // var schemaUri = new Uri("MetadataSchema.json", UriKind.Relative);            
-            // var schemaProxy = rootMetadata.UseExternalSchema(schemaUri);
-
-            var schema = rootMetadata.UseEmbeddedSchema("externalSchema");
-
+            var schemaUri = new Uri("MetadataSchema.json", UriKind.Relative);            
+            var schema = rootMetadata.UseExternalSchema(schemaUri);
             var externalClass = schema.UseClassMetadata("exampleMetadataClass");
 
             var propertyAttribute = rootMetadata.AddPropertyAttribute(externalClass);
@@ -659,6 +649,7 @@ namespace SharpGLTF.Schema2.Tiles3D
             classificationProperty.Attribute = "_CLASSIFICATION";
 
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
+
             model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.glb");
             model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.gltf");
             model.AttachToCurrentTest("cesium_ext_structural_metadata_with_pointcloud_attributes.plotly");