|
|
@@ -22,6 +22,54 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
Tiles3DExtensions.RegisterExtensions();
|
|
|
}
|
|
|
|
|
|
+ /*
|
|
|
+ [Test(Description = "First test with ext_structural_metadata")]
|
|
|
+ public void TriangleWithMetadataTest()
|
|
|
+ {
|
|
|
+ TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
+ var material = MaterialBuilder.CreateDefault().WithDoubleSide(true);
|
|
|
+ var mesh = new MeshBuilder<VertexPosition>("mesh");
|
|
|
+ var prim = mesh.UsePrimitive(material);
|
|
|
+
|
|
|
+ prim.AddTriangle(new VertexPosition(-10, 0, 0), new VertexPosition(10, 0, 0), new VertexPosition(0, 10, 0));
|
|
|
+
|
|
|
+ var scene = new SceneBuilder();
|
|
|
+ scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
+ var model = scene.ToGltf2();
|
|
|
+
|
|
|
+ var schema = new StructuralMetadataSchema();
|
|
|
+ schema.Id = "schema_001";
|
|
|
+ schema.Name = "schema 001";
|
|
|
+ schema.Description = "an example schema";
|
|
|
+ schema.Version = "3.5.1";
|
|
|
+ var classes = new Dictionary<string, StructuralMetadataClass>();
|
|
|
+ var treeClass = new StructuralMetadataClass();
|
|
|
+ treeClass.Name = "Tree";
|
|
|
+ treeClass.Description = "Woody, perennial plant.";
|
|
|
+ classes["tree"] = treeClass;
|
|
|
+ var ageProperty = new ClassProperty();
|
|
|
+ ageProperty.Description = "The age of the tree, in years";
|
|
|
+ ageProperty.Type = ElementType.SCALAR;
|
|
|
+ ageProperty.ComponentType = DataType.UINT32;
|
|
|
+ ageProperty.Required = true;
|
|
|
+
|
|
|
+ treeClass.Properties.Add("age", ageProperty);
|
|
|
+
|
|
|
+ schema.Classes = classes;
|
|
|
+
|
|
|
+ var propertyTable = new PropertyTable("tree", 1, "PropertyTable");
|
|
|
+ var agePropertyTableProperty = model.GetPropertyTableProperty(new List<int>() { 100 });
|
|
|
+ propertyTable.Properties.Add("age", agePropertyTableProperty);
|
|
|
+
|
|
|
+ model.SetPropertyTable(propertyTable, schema);
|
|
|
+
|
|
|
+ // create files
|
|
|
+ var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
+ model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.glb");
|
|
|
+ model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.gltf");
|
|
|
+ model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.plotly");
|
|
|
+ }*/
|
|
|
+
|
|
|
[Test(Description = "ext_structural_metadata with FeatureId Texture and Property Table")]
|
|
|
// sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/FeatureIdTextureAndPropertyTable
|
|
|
public void FeatureIdTextureAndPropertytableTest()
|
|
|
@@ -43,8 +91,7 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
.WithDoubleSide(true)
|
|
|
.WithAlpha(Materials.AlphaMode.OPAQUE)
|
|
|
.WithMetallicRoughness(0, 1)
|
|
|
- .WithMetallicRoughness(imageBuilder1)
|
|
|
- ;
|
|
|
+ .WithMetallicRoughness(imageBuilder1);
|
|
|
|
|
|
var mesh = VBTexture1.CreateCompatibleMesh("mesh");
|
|
|
var prim = mesh.UsePrimitive(material);
|
|
|
@@ -62,34 +109,44 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
- schema.Id = "FeatureIdTextureAndPropertyTableSchema";
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- var buildingComponentsClass = new StructuralMetadataClass();
|
|
|
- buildingComponentsClass.Name = "Building components";
|
|
|
- buildingComponentsClass.Properties.Add("component", new ClassProperty() { Name = "Component", Type = ElementType.STRING });
|
|
|
- buildingComponentsClass.Properties.Add("yearBuilt", new ClassProperty() { Name = "Year built", Type = ElementType.SCALAR, ComponentType = DataType.INT16 });
|
|
|
- schema.Classes.Add("buildingComponents", buildingComponentsClass);
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("FeatureIdTextureAndPropertyTableSchema");
|
|
|
|
|
|
- var propertyTable = new PropertyTable();
|
|
|
- propertyTable.Name = "Example property table";
|
|
|
- propertyTable.Class = "buildingComponents";
|
|
|
- propertyTable.Count = 4;
|
|
|
+ // define schema
|
|
|
|
|
|
- var componentProperty = model.GetPropertyTableProperty(new List<string>() { "Wall", "Door", "Roof", "Window" });
|
|
|
- var yearBuiltProperty = model.GetPropertyTableProperty(new List<Int16>() { 1960, 1996, 1985, 2002 });
|
|
|
- propertyTable.Properties.Add("component", componentProperty);
|
|
|
- propertyTable.Properties.Add("yearBuilt", yearBuiltProperty);
|
|
|
+ var buildingComponentsClass = schema
|
|
|
+ .UseClassMetadata("buildingComponents")
|
|
|
+ .WithNameAndDesc("Building components");
|
|
|
|
|
|
- model.SetPropertyTable(propertyTable, schema);
|
|
|
+ var componentProp = buildingComponentsClass
|
|
|
+ .UseProperty("component")
|
|
|
+ .WithNameAndDesc("Component")
|
|
|
+ .WithValueType(ElementType.STRING);
|
|
|
+
|
|
|
+ var yearProp = buildingComponentsClass
|
|
|
+ .UseProperty("yearBuilt")
|
|
|
+ .WithNameAndDesc("Year built")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.INT16);
|
|
|
+
|
|
|
+ var propertyTable = buildingComponentsClass
|
|
|
+ .AddPropertyTable(4, "Example property table");
|
|
|
+
|
|
|
+ propertyTable
|
|
|
+ .UseProperty(componentProp)
|
|
|
+ .SetValues1D("Wall", "Door", "Roof", "Window");
|
|
|
+
|
|
|
+ propertyTable
|
|
|
+ .UseProperty(yearProp)
|
|
|
+ .SetValues1D(1960, 1996, 1985, 2002);
|
|
|
|
|
|
// Set the FeatureIds, pointing to the red channel of the texture
|
|
|
- var texture = new MeshExtMeshFeatureIDTexture(new List<int>() { 0 }, 1, 0);
|
|
|
- var featureIdTexture = new MeshExtMeshFeatureID(4, texture: texture, propertyTable: 0);
|
|
|
- var featureIds = new List<MeshExtMeshFeatureID>() { featureIdTexture };
|
|
|
+
|
|
|
+ var featureId = new FeatureIDBuilder(propertyTable);
|
|
|
|
|
|
var primitive = model.LogicalMeshes[0].Primitives[0];
|
|
|
- primitive.SetFeatureIds(featureIds);
|
|
|
+ primitive.AddMeshFeatureIds((featureId, model.LogicalTextures[0], new[] {0}));
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
|
|
|
@@ -138,64 +195,44 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
-
|
|
|
- schema.Id = "SimplePropertyTextureSchema";
|
|
|
-
|
|
|
- var exampleMetadataClass = new StructuralMetadataClass();
|
|
|
- exampleMetadataClass.Name = "Building properties";
|
|
|
-
|
|
|
- var insideTemperatureProperty = new ClassProperty();
|
|
|
- insideTemperatureProperty.Name = "Inside temperature";
|
|
|
- insideTemperatureProperty.Type = ElementType.SCALAR;
|
|
|
- insideTemperatureProperty.ComponentType = DataType.UINT8;
|
|
|
-
|
|
|
- var outsideTemperatureProperty = new ClassProperty();
|
|
|
- outsideTemperatureProperty.Name = "Outside temperature";
|
|
|
- outsideTemperatureProperty.Type = ElementType.SCALAR;
|
|
|
- outsideTemperatureProperty.ComponentType = DataType.UINT8;
|
|
|
-
|
|
|
- var insulationProperty = new ClassProperty();
|
|
|
- insulationProperty.Name = "Insulation Thickness";
|
|
|
- insulationProperty.Type = ElementType.SCALAR;
|
|
|
- insulationProperty.ComponentType = DataType.UINT8;
|
|
|
- insulationProperty.Normalized = true;
|
|
|
-
|
|
|
- exampleMetadataClass.Properties.Add("insideTemperature", insideTemperatureProperty);
|
|
|
- exampleMetadataClass.Properties.Add("outsideTemperature", outsideTemperatureProperty);
|
|
|
- exampleMetadataClass.Properties.Add("insulation", insulationProperty);
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- schema.Classes.Add("buildingComponents", exampleMetadataClass);
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("SimplePropertyTextureSchema");
|
|
|
|
|
|
- var buildingPropertyTexture = new PropertyTexture();
|
|
|
- buildingPropertyTexture.ClassName = "buildingComponents";
|
|
|
+ // define schema
|
|
|
|
|
|
- var insideTemperatureTextureProperty = new PropertyTextureProperty();
|
|
|
- insideTemperatureTextureProperty._LogicalTextureIndex = 1;
|
|
|
- insideTemperatureTextureProperty.TextureCoordinate = 0;
|
|
|
- insideTemperatureTextureProperty.Channels = new List<int>() { 0 };
|
|
|
+ var exampleMetadataClass = schema
|
|
|
+ .UseClassMetadata("buildingComponents")
|
|
|
+ .WithNameAndDesc("Building properties");
|
|
|
|
|
|
- buildingPropertyTexture.Properties.Add("insideTemperature", insideTemperatureTextureProperty);
|
|
|
+ exampleMetadataClass
|
|
|
+ .UseProperty("insideTemperature")
|
|
|
+ .WithNameAndDesc("Inside temperature")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.UINT8);
|
|
|
|
|
|
- var outsideTemperatureTextureProperty = new PropertyTextureProperty();
|
|
|
- outsideTemperatureTextureProperty._LogicalTextureIndex = 1;
|
|
|
- outsideTemperatureTextureProperty.TextureCoordinate = 0;
|
|
|
- outsideTemperatureTextureProperty.Channels = new List<int>() { 1 };
|
|
|
+ exampleMetadataClass
|
|
|
+ .UseProperty("outsideTemperature")
|
|
|
+ .WithNameAndDesc("Outside temperature")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.UINT8);
|
|
|
|
|
|
- buildingPropertyTexture.Properties.Add("outsideTemperature", outsideTemperatureTextureProperty);
|
|
|
+ exampleMetadataClass
|
|
|
+ .UseProperty("insulation")
|
|
|
+ .WithNameAndDesc("Insulation Thickness")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.UINT8, true);
|
|
|
|
|
|
- var insulationTextureProperty = new PropertyTextureProperty();
|
|
|
- insulationTextureProperty._LogicalTextureIndex = 1;
|
|
|
- insulationTextureProperty.TextureCoordinate = 0;
|
|
|
- insulationTextureProperty.Channels = new List<int>() { 2 };
|
|
|
+ // define texture property
|
|
|
|
|
|
- buildingPropertyTexture.Properties.Add("insulation", insulationTextureProperty);
|
|
|
+ var buildingPropertyTexture = exampleMetadataClass.AddPropertyTexture();
|
|
|
+
|
|
|
+ buildingPropertyTexture.CreateProperty("insideTemperature", model.LogicalTextures[1], new int[] {0});
|
|
|
+ buildingPropertyTexture.CreateProperty("outsideTemperature", model.LogicalTextures[1], new int[] {1});
|
|
|
+ buildingPropertyTexture.CreateProperty("insulation", model.LogicalTextures[1], new int[] {2});
|
|
|
|
|
|
- model.SetPropertyTexture(buildingPropertyTexture, schema);
|
|
|
+ // assign to primitive
|
|
|
|
|
|
- var primitive = model.LogicalMeshes[0].Primitives[0];
|
|
|
- var propertyTextures = new List<int> { 0 };
|
|
|
- primitive.SetPropertyTextures(propertyTextures);
|
|
|
+ var primitive = model.LogicalMeshes[0].Primitives[0];
|
|
|
+ primitive.AddPropertyTexture(buildingPropertyTexture);
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_simple_property_texture.glb");
|
|
|
@@ -205,7 +242,7 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
|
|
|
[Test(Description = "ext_structural_metadata with Multiple Feature IDs and Properties")]
|
|
|
// sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/MultipleFeatureIdsAndProperties
|
|
|
- public void MultipleFeatureIdsandPropertiesTest()
|
|
|
+ public void MultipleFeatureIdsAndPropertiesTest()
|
|
|
{
|
|
|
TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
var material = MaterialBuilder.CreateDefault().WithDoubleSide(true);
|
|
|
@@ -230,55 +267,45 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
- schema.Id = "MultipleFeatureIdsAndPropertiesSchema";
|
|
|
-
|
|
|
- var exampleMetadataClass = new StructuralMetadataClass();
|
|
|
- exampleMetadataClass.Name = "Example metadata class";
|
|
|
- exampleMetadataClass.Description = "An example metadata class";
|
|
|
-
|
|
|
- var vector3Property = new ClassProperty();
|
|
|
- vector3Property.Name = "Example VEC3 FLOAT32 property";
|
|
|
- vector3Property.Description = "An example property, with type VEC3, with component type FLOAT32";
|
|
|
- vector3Property.Type = ElementType.VEC3;
|
|
|
- vector3Property.ComponentType = DataType.FLOAT32;
|
|
|
-
|
|
|
- exampleMetadataClass.Properties.Add("example_VEC3_FLOAT32", vector3Property);
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- var stringProperty = new ClassProperty();
|
|
|
- stringProperty.Name = "Example STRING property";
|
|
|
- stringProperty.Description = "An example property, with type STRING";
|
|
|
- stringProperty.Type = ElementType.STRING;
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("MultipleFeatureIdsAndPropertiesSchema");
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_STRING", stringProperty);
|
|
|
+ // define schema
|
|
|
|
|
|
- schema.Classes.Add("exampleMetadataClass", exampleMetadataClass);
|
|
|
+ var exampleMetadataClass = schema
|
|
|
+ .UseClassMetadata("exampleMetadataClass")
|
|
|
+ .WithNameAndDesc("Example metadata class", "An example metadata class");
|
|
|
|
|
|
- var vector3List = new List<Vector3>() {
|
|
|
- new Vector3(3, 3.0999999046325684f, 3.200000047683716f),
|
|
|
- new Vector3(103, 103.0999999046325684f, 103.200000047683716f)
|
|
|
+ var vec3Property = exampleMetadataClass
|
|
|
+ .UseProperty("example_VEC3_FLOAT32")
|
|
|
+ .WithNameAndDesc("Example VEC3 FLOAT32 property", "An example property, with type VEC3, with component type FLOAT32")
|
|
|
+ .WithValueType(ElementType.VEC3, DataType.FLOAT32);
|
|
|
|
|
|
- };
|
|
|
+ var stringProperty = exampleMetadataClass
|
|
|
+ .UseProperty("example_STRING")
|
|
|
+ .WithNameAndDesc("Example STRING property", "An example property, with type STRING")
|
|
|
+ .WithValueType(ElementType.STRING);
|
|
|
|
|
|
- var vector3PropertyTableProperty = model.GetPropertyTableProperty(vector3List);
|
|
|
+ // define table
|
|
|
|
|
|
- var examplePropertyTable = new PropertyTable("exampleMetadataClass", 2, "Example property table");
|
|
|
+ var examplePropertyTable = exampleMetadataClass.AddPropertyTable(2, "Example property table");
|
|
|
|
|
|
- examplePropertyTable.Properties.Add("example_VEC3_FLOAT32", vector3PropertyTableProperty);
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(vec3Property)
|
|
|
+ .SetValues1D(new Vector3(3, 3.0999999046325684f, 3.200000047683716f), new Vector3(103, 103.0999999046325684f, 103.200000047683716f));
|
|
|
|
|
|
- var stringList = new List<string>() { "Rain 🌧", "Thunder ⛈" };
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(stringProperty)
|
|
|
+ .SetValues1D("Rain 🌧", "Thunder ⛈");
|
|
|
|
|
|
- var stringPropertyTableProperty = model.GetPropertyTableProperty(stringList);
|
|
|
+ // assign to primitive
|
|
|
|
|
|
- examplePropertyTable.Properties.Add("example_STRING", stringPropertyTableProperty);
|
|
|
+ var featureId0 = new FeatureIDBuilder(examplePropertyTable, 0);
|
|
|
+ var featureId1 = new FeatureIDBuilder(examplePropertyTable, 1);
|
|
|
|
|
|
- model.SetPropertyTable(examplePropertyTable, schema);
|
|
|
-
|
|
|
- var featureId0 = new MeshExtMeshFeatureID(2, 0, 0);
|
|
|
- var featureId1 = new MeshExtMeshFeatureID(2, 1, 0);
|
|
|
- var featureIds = new List<MeshExtMeshFeatureID>() { featureId0, featureId1 };
|
|
|
-
|
|
|
- model.LogicalMeshes[0].Primitives[0].SetFeatureIds(featureIds);
|
|
|
+ model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds( (featureId0, null, null), (featureId1, null, null) );
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_attribute_and_property_table.glb");
|
|
|
@@ -286,8 +313,8 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_featureid_attribute_and_property_table.plotly");
|
|
|
}
|
|
|
|
|
|
- [Test(Description = "ext_structural_metadata with FeatureIdAttributeAndPropertyTable")]
|
|
|
// sample see https://github.com/CesiumGS/3d-tiles-samples/tree/main/glTF/EXT_structural_metadata/FeatureIdAttributeAndPropertyTable
|
|
|
+ [Test(Description = "ext_structural_metadata with FeatureIdAttributeAndPropertyTable")]
|
|
|
public void FeatureIdAndPropertyTableTest()
|
|
|
{
|
|
|
TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
@@ -307,49 +334,44 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
- schema.Id = "FeatureIdAttributeAndPropertyTableSchema";
|
|
|
-
|
|
|
- var exampleMetadataClass = new StructuralMetadataClass();
|
|
|
- exampleMetadataClass.Name = "Example metadata class";
|
|
|
- exampleMetadataClass.Description = "An example metadata class";
|
|
|
-
|
|
|
- var vector3Property = new ClassProperty();
|
|
|
- vector3Property.Name = "Example VEC3 FLOAT32 property";
|
|
|
- vector3Property.Description = "An example property, with type VEC3, with component type FLOAT32";
|
|
|
- vector3Property.Type = ElementType.VEC3;
|
|
|
- vector3Property.ComponentType = DataType.FLOAT32;
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_VEC3_FLOAT32", vector3Property);
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("FeatureIdAttributeAndPropertyTableSchema");
|
|
|
|
|
|
- var matrix4x4Property = new ClassProperty();
|
|
|
- matrix4x4Property.Name = "Example MAT4 FLOAT32 property";
|
|
|
- matrix4x4Property.Description = "An example property, with type MAT4, with component type FLOAT32";
|
|
|
- matrix4x4Property.Type = ElementType.MAT4;
|
|
|
- matrix4x4Property.ComponentType = DataType.FLOAT32;
|
|
|
+ // define schema
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_MAT4_FLOAT32", matrix4x4Property);
|
|
|
+ var exampleMetadataClass = schema
|
|
|
+ .UseClassMetadata("exampleMetadataClass")
|
|
|
+ .WithNameAndDesc("Example metadata class", "An example metadata class");
|
|
|
|
|
|
- schema.Classes.Add("exampleMetadataClass", exampleMetadataClass);
|
|
|
+ var vector3Property = exampleMetadataClass
|
|
|
+ .UseProperty("example_VEC3_FLOAT32")
|
|
|
+ .WithNameAndDesc("Example VEC3 FLOAT32 property", "An example property, with type VEC3, with component type FLOAT32")
|
|
|
+ .WithValueType(ElementType.VEC3, DataType.FLOAT32);
|
|
|
|
|
|
- var vector3List = new List<Vector3>() { new Vector3(3, 3.0999999046325684f, 3.200000047683716f) };
|
|
|
+ var matrix4x4Property = exampleMetadataClass
|
|
|
+ .UseProperty("example_MAT4_FLOAT32")
|
|
|
+ .WithNameAndDesc("Example MAT4 FLOAT32 property", "An example property, with type MAT4, with component type FLOAT32")
|
|
|
+ .WithValueType(ElementType.MAT4, DataType.FLOAT32);
|
|
|
|
|
|
- var vector3PropertyTableProperty = model.GetPropertyTableProperty(vector3List);
|
|
|
+ // define table
|
|
|
|
|
|
- var examplePropertyTable = new PropertyTable("exampleMetadataClass", 1, "Example property table");
|
|
|
+ var examplePropertyTable = exampleMetadataClass.AddPropertyTable(1, "Example property table");
|
|
|
|
|
|
- examplePropertyTable.Properties.Add("example_VEC3_FLOAT32", vector3PropertyTableProperty);
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(vector3Property)
|
|
|
+ .SetValues1D(new Vector3(3, 3.0999999046325684f, 3.200000047683716f));
|
|
|
|
|
|
- var matrix4x4List = new List<Matrix4x4>() { Matrix4x4.Identity };
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(matrix4x4Property)
|
|
|
+ .SetValues1D(Matrix4x4.Identity);
|
|
|
|
|
|
- var matrix4x4PropertyTableProperty = model.GetPropertyTableProperty(matrix4x4List);
|
|
|
+ // assign to primitive
|
|
|
|
|
|
- examplePropertyTable.Properties.Add("example_MAT4_FLOAT32", matrix4x4PropertyTableProperty);
|
|
|
+ var featureId = new FeatureIDBuilder(examplePropertyTable, 0);
|
|
|
|
|
|
- model.SetPropertyTable(examplePropertyTable, schema);
|
|
|
-
|
|
|
- var featureId = new MeshExtMeshFeatureID(1, 0, 0);
|
|
|
- model.LogicalMeshes[0].Primitives[0].SetFeatureId(featureId);
|
|
|
+ model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds((featureId, null, null));
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_featureids_and_properties.glb");
|
|
|
@@ -357,8 +379,8 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_featureids_and_properties.plotly");
|
|
|
}
|
|
|
|
|
|
- [Test(Description = "ext_structural_metadata with complex types")]
|
|
|
// sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/ComplexTypes/
|
|
|
+ [Test(Description = "ext_structural_metadata with complex types")]
|
|
|
public void ComplexTypesTest()
|
|
|
{
|
|
|
TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
@@ -378,98 +400,70 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
-
|
|
|
- var exampleMetadataClass = new StructuralMetadataClass();
|
|
|
- exampleMetadataClass.Name = "Example metadata class A";
|
|
|
- exampleMetadataClass.Description = "First example metadata class";
|
|
|
-
|
|
|
- // class properties
|
|
|
-
|
|
|
- var uint8ArrayProperty = new ClassProperty();
|
|
|
- uint8ArrayProperty.Name = "Example variable-length ARRAY normalized INT8 property";
|
|
|
- uint8ArrayProperty.Description = "An example property, with type ARRAY, with component type UINT8, normalized, and variable length";
|
|
|
- uint8ArrayProperty.Type = ElementType.SCALAR;
|
|
|
- uint8ArrayProperty.ComponentType = DataType.UINT8;
|
|
|
- uint8ArrayProperty.Normalized = false;
|
|
|
- uint8ArrayProperty.Array = true;
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_variable_length_ARRAY_normalized_UINT8", uint8ArrayProperty);
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("FeatureIdAttributeAndPropertyTableSchema");
|
|
|
|
|
|
- var fixedLengthBooleanProperty = new ClassProperty();
|
|
|
- fixedLengthBooleanProperty.Name = "Example fixed-length ARRAY BOOLEAN property";
|
|
|
- fixedLengthBooleanProperty.Description = "An example property, with type ARRAY, with component type BOOLEAN, and fixed length ";
|
|
|
- fixedLengthBooleanProperty.Type = ElementType.BOOLEAN;
|
|
|
- fixedLengthBooleanProperty.Array = true;
|
|
|
- fixedLengthBooleanProperty.Count = 4;
|
|
|
+ // define schema
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_fixed_length_ARRAY_BOOLEAN", fixedLengthBooleanProperty);
|
|
|
+ var exampleMetadataClass = schema
|
|
|
+ .UseClassMetadata("exampleMetadataClass")
|
|
|
+ .WithNameAndDesc("Example metadata class A", "First example metadata class");
|
|
|
|
|
|
- var variableLengthStringArrayProperty = new ClassProperty();
|
|
|
- variableLengthStringArrayProperty.Name = "Example variable-length ARRAY STRING property";
|
|
|
- variableLengthStringArrayProperty.Description = "An example property, with type ARRAY, with component type STRING, and variable length";
|
|
|
- variableLengthStringArrayProperty.Type = ElementType.STRING;
|
|
|
- variableLengthStringArrayProperty.Array = true;
|
|
|
- exampleMetadataClass.Properties.Add("example_variable_length_ARRAY_STRING", variableLengthStringArrayProperty);
|
|
|
+ // enums
|
|
|
|
|
|
- var fixed_length_ARRAY_ENUM = new ClassProperty();
|
|
|
- fixed_length_ARRAY_ENUM.Name = "Example fixed-length ARRAY ENUM property";
|
|
|
- fixed_length_ARRAY_ENUM.Description = "An example property, with type ARRAY, with component type ENUM, and fixed length";
|
|
|
- fixed_length_ARRAY_ENUM.Type = ElementType.ENUM;
|
|
|
- fixed_length_ARRAY_ENUM.Array = true;
|
|
|
- fixed_length_ARRAY_ENUM.Count = 2;
|
|
|
- fixed_length_ARRAY_ENUM.EnumType = "exampleEnumType";
|
|
|
+ var exampleEnum = schema.UseEnumMetadata("exampleEnumType", ("ExampleEnumValueA", 0), ("ExampleEnumValueB", 1), ("ExampleEnumValueC", 2));
|
|
|
|
|
|
- exampleMetadataClass.Properties.Add("example_fixed_length_ARRAY_ENUM", fixed_length_ARRAY_ENUM);
|
|
|
+ // class properties
|
|
|
|
|
|
- schema.Classes.Add("exampleMetadataClass", exampleMetadataClass);
|
|
|
+ var uint8ArrayProperty = exampleMetadataClass
|
|
|
+ .UseProperty("example_variable_length_ARRAY_normalized_UINT8")
|
|
|
+ .WithNameAndDesc("Example variable-length ARRAY normalized INT8 property","An example property, with type ARRAY, with component type UINT8, normalized, and variable length")
|
|
|
+ .WithArrayType(ElementType.SCALAR,DataType.UINT8,false);
|
|
|
|
|
|
- // enums
|
|
|
+ var fixedLengthBooleanProperty = exampleMetadataClass
|
|
|
+ .UseProperty("example_fixed_length_ARRAY_BOOLEAN")
|
|
|
+ .WithNameAndDesc("Example fixed-length ARRAY BOOLEAN property", "An example property, with type ARRAY, with component type BOOLEAN, and fixed length ")
|
|
|
+ .WithArrayType(ElementType.BOOLEAN, null, false, 4);
|
|
|
|
|
|
- var exampleEnum = new StructuralMetadataEnum();
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueA", Value = 0 });
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueB", Value = 1 });
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueC", Value = 2 });
|
|
|
+ var variableLengthStringArrayProperty = exampleMetadataClass
|
|
|
+ .UseProperty("example_variable_length_ARRAY_STRING")
|
|
|
+ .WithNameAndDesc("Example variable-length ARRAY STRING property", "An example property, with type ARRAY, with component type STRING, and variable length")
|
|
|
+ .WithArrayType(ElementType.STRING);
|
|
|
|
|
|
- schema.Enums.Add("exampleEnumType", exampleEnum);
|
|
|
+ var fixed_length_ARRAY_ENUM = exampleMetadataClass
|
|
|
+ .UseProperty("example_fixed_length_ARRAY_ENUM")
|
|
|
+ .WithNameAndDesc("Example fixed-length ARRAY ENUM property", "An example property, with type ARRAY, with component type ENUM, and fixed length")
|
|
|
+ .WithEnumArrayType(exampleEnum, 2);
|
|
|
|
|
|
// property tables
|
|
|
|
|
|
- var examplePropertyTable = new PropertyTable("exampleMetadataClass", 1, "Example property table");
|
|
|
- var list2 = new List<List<byte>>() {
|
|
|
- new() { 0, 1, 2, 3, 4, 5, 6, 7 }
|
|
|
- };
|
|
|
-
|
|
|
- var property = model.GetArrayPropertyTableProperty(list2);
|
|
|
- examplePropertyTable.Properties.Add("example_variable_length_ARRAY_normalized_UINT8", property);
|
|
|
+ var examplePropertyTable = exampleMetadataClass.AddPropertyTable(1, "Example property table");
|
|
|
|
|
|
- var booleansList = new List<List<bool>>()
|
|
|
- {
|
|
|
- new() { true, false, true, false }
|
|
|
- };
|
|
|
- var propertyBooleansList = model.GetArrayPropertyTableProperty(booleansList, false);
|
|
|
- examplePropertyTable.Properties.Add("example_fixed_length_ARRAY_BOOLEAN", propertyBooleansList);
|
|
|
+ // Question: The table declares a feature count of 1, but then, these properties define different number of items
|
|
|
+
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(uint8ArrayProperty)
|
|
|
+ .SetValues1D<byte>(0, 1, 2, 3, 4, 5, 6, 7);
|
|
|
|
|
|
- var stringsList = new List<List<string>>()
|
|
|
- {
|
|
|
- new() { "Example string 1", "Example string 2", "Example string 3" }
|
|
|
- };
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(fixedLengthBooleanProperty)
|
|
|
+ .SetValues1D<Boolean>(true, false, true, false);
|
|
|
|
|
|
- var propertyStringsList = model.GetArrayPropertyTableProperty(stringsList);
|
|
|
- examplePropertyTable.Properties.Add("example_variable_length_ARRAY_STRING", propertyStringsList);
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(variableLengthStringArrayProperty)
|
|
|
+ .SetValues1D("Example string 1", "Example string 2", "Example string 3");
|
|
|
|
|
|
- var enumsList = new List<List<int>>()
|
|
|
- {
|
|
|
- new() { 0, 1 }
|
|
|
- };
|
|
|
+ examplePropertyTable
|
|
|
+ .UseProperty(fixed_length_ARRAY_ENUM)
|
|
|
+ .SetValues1D<int>(0, 1);
|
|
|
|
|
|
- var enumsProperty = model.GetArrayPropertyTableProperty(enumsList, false);
|
|
|
- examplePropertyTable.Properties.Add("example_fixed_length_ARRAY_ENUM", enumsProperty);
|
|
|
+ // add to primitive
|
|
|
|
|
|
- model.SetPropertyTable(examplePropertyTable, schema);
|
|
|
+ var featureId = new FeatureIDBuilder(examplePropertyTable, 0);
|
|
|
|
|
|
- var featureId = new MeshExtMeshFeatureID(1, 0, 0);
|
|
|
- model.LogicalMeshes[0].Primitives[0].SetFeatureId(featureId);
|
|
|
+ model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds((featureId, null, null));
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_complex_types.glb");
|
|
|
@@ -477,8 +471,8 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_complex_types.plotly");
|
|
|
}
|
|
|
|
|
|
- [Test(Description = "ext_structural_metadata with multiple classes")]
|
|
|
// Sample see https://github.com/CesiumGS/3d-tiles-samples/blob/main/glTF/EXT_structural_metadata/MultipleClasses/
|
|
|
+ [Test(Description = "ext_structural_metadata with multiple classes")]
|
|
|
public void MultipleClassesTest()
|
|
|
{
|
|
|
var material = MaterialBuilder.CreateDefault().WithDoubleSide(true);
|
|
|
@@ -496,36 +490,54 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
var model = scene.ToGltf2();
|
|
|
|
|
|
- // FeatureID 0: featureCount=1, attribute=0, porpertyTable=0
|
|
|
- var featureId0Attribute = new MeshExtMeshFeatureID(1, 0, 0);
|
|
|
- // FeatureID 1: featureCount=1, attribute=1, porpertyTable=1
|
|
|
- var featureId1Attribute = new MeshExtMeshFeatureID(1, 1, 1);
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
- // Set the FeatureIds
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("MultipleClassesSchema");
|
|
|
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
- schema.Id = "MultipleClassesSchema";
|
|
|
+ // classes
|
|
|
|
|
|
- var classes = new Dictionary<string, StructuralMetadataClass>();
|
|
|
- classes["exampleMetadataClassA"] = GetExampleClassA();
|
|
|
- classes["exampleMetadataClassB"] = GetExampleClassB();
|
|
|
+ var classA = schema
|
|
|
+ .UseClassMetadata("exampleMetadataClassA")
|
|
|
+ .WithNameAndDesc("Example metadata class A","First example metadata class");
|
|
|
|
|
|
- schema.Classes = classes;
|
|
|
- var exampleEnum = new StructuralMetadataEnum();
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueA", Value = 0 });
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueB", Value = 1 });
|
|
|
- exampleEnum.Values.Add(new EnumValue() { Name = "ExampleEnumValueC", Value = 2 });
|
|
|
+ var classAp0 = classA.UseProperty("example_FLOAT32")
|
|
|
+ .WithNameAndDesc("Example FLOAT32 property", "An example property, with component type FLOAT32")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.FLOAT32);
|
|
|
+
|
|
|
+ var classAp1 = classA.UseProperty("example_INT64")
|
|
|
+ .WithNameAndDesc("Example INT64 property", "An example property, with component type INT64")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.INT64);
|
|
|
+
|
|
|
+ var classB = schema.UseClassMetadata("exampleMetadataClassB")
|
|
|
+ .WithNameAndDesc("Example metadata class B", "Second example metadata class");
|
|
|
+
|
|
|
+ var classBp0 = classB.UseProperty("example_UINT16")
|
|
|
+ .WithNameAndDesc("Example UINT16 property", "An example property, with component type UINT16")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.UINT16);
|
|
|
|
|
|
- schema.Enums.Add("exampleEnumType", exampleEnum);
|
|
|
+ var classBp1 = classB.UseProperty("example_FLOAT64")
|
|
|
+ .WithNameAndDesc("Example FLOAT64 property", "An example property, with component type FLOAT64")
|
|
|
+ .WithValueType(ElementType.SCALAR, DataType.FLOAT64);
|
|
|
|
|
|
- var firstPropertyTable = GetFirstPropertyTable(model);
|
|
|
- var secondPropertyTable = GetSecondPropertyTable(model);
|
|
|
+ // properties
|
|
|
|
|
|
- var propertyTables = new List<PropertyTable>() { firstPropertyTable, secondPropertyTable };
|
|
|
- model.SetPropertyTables(propertyTables, schema);
|
|
|
+ var firstPropertyTable = classA.AddPropertyTable(1, "First example property table");
|
|
|
+ firstPropertyTable.UseProperty(classAp0).SetValues1D<float>(100);
|
|
|
+ firstPropertyTable.UseProperty(classAp1).SetValues1D<long>(101);
|
|
|
|
|
|
- var featureIds = new List<MeshExtMeshFeatureID>() { featureId0Attribute, featureId1Attribute };
|
|
|
- model.LogicalMeshes[0].Primitives[0].SetFeatureIds(featureIds);
|
|
|
+ var secondPropertyTable = classB.AddPropertyTable(1, "Second example property table");
|
|
|
+ secondPropertyTable.UseProperty(classBp0).SetValues1D<ushort>(102);
|
|
|
+ secondPropertyTable.UseProperty(classBp1).SetValues1D<double>(103);
|
|
|
+
|
|
|
+ // features
|
|
|
+
|
|
|
+ // FeatureID 0: featureCount=1, attribute=0, porpertyTable=0
|
|
|
+ var featureId0 = new FeatureIDBuilder(firstPropertyTable, 0);
|
|
|
+ // FeatureID 1: featureCount=1, attribute=1, porpertyTable=1
|
|
|
+ var featureId1 = new FeatureIDBuilder(secondPropertyTable, 1);
|
|
|
+
|
|
|
+ model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds((featureId0, null,null), (featureId1,null,null));
|
|
|
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.glb");
|
|
|
@@ -533,9 +545,9 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
model.AttachToCurrentTest("cesium_ext_structural_metadata_multiple_classes.plotly");
|
|
|
}
|
|
|
|
|
|
- [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/
|
|
|
-
|
|
|
+ [Test(Description = "ext_structural_metadata with pointcloud and custom attributes")]
|
|
|
public void CreatePointCloudWithCustomAttributesTest()
|
|
|
{
|
|
|
var material = new MaterialBuilder("material1").WithUnlitShader();
|
|
|
@@ -564,138 +576,34 @@ namespace SharpGLTF.Schema2.Tiles3D
|
|
|
model.UseScene("Default")
|
|
|
.CreateNode().WithMesh(model.LogicalMeshes[0]);
|
|
|
|
|
|
- var propertyAttribute = new Schema2.PropertyAttribute();
|
|
|
- propertyAttribute.Class = "exampleMetadataClass";
|
|
|
- var intensityProperty = new PropertyAttributeProperty();
|
|
|
- intensityProperty.Attribute = "_INTENSITY";
|
|
|
- var classificationProperty = new PropertyAttributeProperty();
|
|
|
- classificationProperty.Attribute = "_CLASSIFICATION";
|
|
|
- propertyAttribute.Properties["intensity"] = intensityProperty;
|
|
|
- propertyAttribute.Properties["classification"] = classificationProperty;
|
|
|
-
|
|
|
- var schemaUri = new Uri("MetadataSchema.json", UriKind.Relative);
|
|
|
- model.SetPropertyAttribute(propertyAttribute, schemaUri);
|
|
|
- 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");
|
|
|
- }
|
|
|
+ // --------------------------------------------------------------
|
|
|
|
|
|
+ var rootMetadata = model.UseStructuralMetadata();
|
|
|
|
|
|
- private static PropertyTable GetFirstPropertyTable(ModelRoot model)
|
|
|
- {
|
|
|
- var firstPropertyTable = new PropertyTable("exampleMetadataClassA", 1, "First example property table");
|
|
|
- var float32Property = model.GetPropertyTableProperty(new List<float>() { 100 });
|
|
|
- firstPropertyTable.Properties.Add("example_FLOAT32", float32Property);
|
|
|
- var int64Property = model.GetPropertyTableProperty(new List<long>() { 101 });
|
|
|
- firstPropertyTable.Properties.Add("example_INT64", int64Property);
|
|
|
- return firstPropertyTable;
|
|
|
- }
|
|
|
+ // 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.
|
|
|
|
|
|
- private static PropertyTable GetSecondPropertyTable(ModelRoot model)
|
|
|
- {
|
|
|
- var secondPropertyTable = new PropertyTable("exampleMetadataClassB", 1, "First example property table");
|
|
|
- var uint16Property = model.GetPropertyTableProperty(new List<ushort>() { 102 });
|
|
|
- secondPropertyTable.Properties.Add("example_UINT16", uint16Property);
|
|
|
- var float64Property = model.GetPropertyTableProperty(new List<double>() { 103 });
|
|
|
- secondPropertyTable.Properties.Add("example_FLOAT64", float64Property);
|
|
|
- return secondPropertyTable;
|
|
|
- }
|
|
|
+ // var schemaUri = new Uri("MetadataSchema.json", UriKind.Relative);
|
|
|
+ // var schemaProxy = rootMetadata.UseExternalSchema(schemaUri);
|
|
|
|
|
|
- private static StructuralMetadataClass GetExampleClassB()
|
|
|
- {
|
|
|
- var classB = new StructuralMetadataClass();
|
|
|
- classB.Name = "Example metadata class B";
|
|
|
- classB.Description = "Second example metadata class";
|
|
|
-
|
|
|
- var uint16Property = new ClassProperty();
|
|
|
- uint16Property.Name = "Example UINT16 property";
|
|
|
- uint16Property.Description = "An example property, with component type UINT16";
|
|
|
- uint16Property.Type = ElementType.SCALAR;
|
|
|
- uint16Property.ComponentType = DataType.UINT16;
|
|
|
-
|
|
|
- classB.Properties.Add("example_UINT16", uint16Property);
|
|
|
-
|
|
|
- var float64Property = new ClassProperty();
|
|
|
- float64Property.Name = "Example FLOAT64 property";
|
|
|
- float64Property.Description = "An example property, with component type FLOAT64";
|
|
|
- float64Property.Type = ElementType.SCALAR;
|
|
|
- float64Property.ComponentType = DataType.FLOAT64;
|
|
|
-
|
|
|
- classB.Properties.Add("example_FLOAT64", float64Property);
|
|
|
- return classB;
|
|
|
- }
|
|
|
+ var schema = rootMetadata.UseEmbeddedSchema("externalSchema");
|
|
|
|
|
|
+ var externalClass = schema.UseClassMetadata("exampleMetadataClass");
|
|
|
|
|
|
- private static StructuralMetadataClass GetExampleClassA()
|
|
|
- {
|
|
|
- var classA = new StructuralMetadataClass();
|
|
|
- classA.Name = "Example metadata class A";
|
|
|
- classA.Description = "First example metadata class";
|
|
|
-
|
|
|
- var float32Property = new ClassProperty();
|
|
|
- float32Property.Name = "Example FLOAT32 property";
|
|
|
- float32Property.Description = "An example property, with component type FLOAT32";
|
|
|
- float32Property.Type = ElementType.SCALAR;
|
|
|
- float32Property.ComponentType = DataType.FLOAT32;
|
|
|
-
|
|
|
- classA.Properties.Add("example_FLOAT32", float32Property);
|
|
|
-
|
|
|
- var int64Property = new ClassProperty();
|
|
|
- int64Property.Name = "Example INT64 property";
|
|
|
- int64Property.Description = "An example property, with component type INT64";
|
|
|
- int64Property.Type = ElementType.SCALAR;
|
|
|
- int64Property.ComponentType = DataType.INT64;
|
|
|
-
|
|
|
- classA.Properties.Add("example_INT64", int64Property);
|
|
|
- return classA;
|
|
|
- }
|
|
|
+ var propertyAttribute = rootMetadata.AddPropertyAttribute(externalClass);
|
|
|
|
|
|
- [Test(Description = "First test with ext_structural_metadata")]
|
|
|
- public void TriangleWithMetadataTest()
|
|
|
- {
|
|
|
- TestContext.CurrentContext.AttachGltfValidatorLinks();
|
|
|
- var material = MaterialBuilder.CreateDefault().WithDoubleSide(true);
|
|
|
- var mesh = new MeshBuilder<VertexPosition>("mesh");
|
|
|
- var prim = mesh.UsePrimitive(material);
|
|
|
-
|
|
|
- prim.AddTriangle(new VertexPosition(-10, 0, 0), new VertexPosition(10, 0, 0), new VertexPosition(0, 10, 0));
|
|
|
-
|
|
|
- var scene = new SceneBuilder();
|
|
|
- scene.AddRigidMesh(mesh, Matrix4x4.Identity);
|
|
|
- var model = scene.ToGltf2();
|
|
|
-
|
|
|
- var schema = new StructuralMetadataSchema();
|
|
|
- schema.Id = "schema_001";
|
|
|
- schema.Name = "schema 001";
|
|
|
- schema.Description = "an example schema";
|
|
|
- schema.Version = "3.5.1";
|
|
|
- var classes = new Dictionary<string, StructuralMetadataClass>();
|
|
|
- var treeClass = new StructuralMetadataClass();
|
|
|
- treeClass.Name = "Tree";
|
|
|
- treeClass.Description = "Woody, perennial plant.";
|
|
|
- classes["tree"] = treeClass;
|
|
|
- var ageProperty = new ClassProperty();
|
|
|
- ageProperty.Description = "The age of the tree, in years";
|
|
|
- ageProperty.Type = ElementType.SCALAR;
|
|
|
- ageProperty.ComponentType = DataType.UINT32;
|
|
|
- ageProperty.Required = true;
|
|
|
-
|
|
|
- treeClass.Properties.Add("age", ageProperty);
|
|
|
-
|
|
|
- schema.Classes = classes;
|
|
|
-
|
|
|
- var propertyTable = new PropertyTable("tree", 1, "PropertyTable");
|
|
|
- var agePropertyTableProperty = model.GetPropertyTableProperty(new List<int>() { 100 });
|
|
|
- propertyTable.Properties.Add("age", agePropertyTableProperty);
|
|
|
+ var intensityProperty = propertyAttribute.CreateProperty("intensity");
|
|
|
+ intensityProperty.Attribute = "_INTENSITY";
|
|
|
|
|
|
- model.SetPropertyTable(propertyTable, schema);
|
|
|
+ var classificationProperty = propertyAttribute.CreateProperty("classification");
|
|
|
+ classificationProperty.Attribute = "_CLASSIFICATION";
|
|
|
|
|
|
- // create files
|
|
|
var ctx = new ValidationResult(model, ValidationMode.Strict, true);
|
|
|
- model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.glb");
|
|
|
- model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.gltf");
|
|
|
- model.AttachToCurrentTest("cesium_ext_structural_metadata_basic_triangle.plotly");
|
|
|
+ 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");
|
|
|
}
|
|
|
}
|
|
|
}
|