Browse Source

refactor adding types to metadata

Bert Temme 1 year ago
parent
commit
6abb95ea25

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

@@ -1257,21 +1257,123 @@ namespace SharpGLTF.Schema2
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithValueType(ELEMENTTYPE etype, DATATYPE? ctype = null, bool normalized = false, bool required = false)
+            public StructuralMetadataClassProperty WithStringType()
+            {
+                Type = ElementType.STRING;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithBooleanType()
+            {
+                Type = ElementType.BOOLEAN;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithUInt8Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.UINT8;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithInt8Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.INT8;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithUInt16Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.UINT16;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithInt16Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.INT16;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithUInt32Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.UINT32;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithInt32Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.INT32;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithUInt64Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.UINT64;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithInt64Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.INT64;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithFloat32Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.FLOAT32;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithFloat64Type()
+            {
+                Type = ELEMENTTYPE.SCALAR;
+                ComponentType = DATATYPE.FLOAT64;
+                return this;
+            }
+
+
+            public StructuralMetadataClassProperty WithVector3Type()
+            {
+                Type = ElementType.VEC3;
+                ComponentType = DataType.FLOAT32;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithMatrix4x4Type()
+            {
+                Type = ElementType.MAT4;
+                ComponentType = DataType.FLOAT32;
+                return this;
+            }
+
+            public StructuralMetadataClassProperty WithCount()
+            {
+                Type = ElementType.MAT4;
+                ComponentType = DataType.FLOAT32;
+                return this;
+            }
+
+
+            public StructuralMetadataClassProperty WithValueType(ELEMENTTYPE etype, DATATYPE? ctype = null)
             {
             {
                 Type = etype;
                 Type = etype;
                 ComponentType = ctype;
                 ComponentType = ctype;
-                Normalized = normalized;
                 Array = false;
                 Array = false;
-                Required = required;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithArrayType(ELEMENTTYPE etype, DATATYPE? ctype = null, bool normalized = false, int? count = null)
+            public StructuralMetadataClassProperty WithArrayType(ELEMENTTYPE etype, DATATYPE? ctype = null, int? count = null)
             {
             {
                 Type = etype;
                 Type = etype;
                 ComponentType = ctype;
                 ComponentType = ctype;
-                Normalized = normalized;
                 Array = true;
                 Array = true;
                 Count = count;
                 Count = count;
                 return this;
                 return this;
@@ -1299,6 +1401,13 @@ namespace SharpGLTF.Schema2
                 return this;
                 return this;
             }
             }
 
 
+            public StructuralMetadataClassProperty WithNormalized(bool normalized)
+            {
+                Normalized = normalized;
+                return this;
+            }
+
+
             #endregion
             #endregion
         }
         }
 
 

+ 36 - 24
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -78,7 +78,12 @@ namespace SharpGLTF.Schema2.Tiles3D
 
 
             var nameProperty = trianglesClass
             var nameProperty = trianglesClass
                 .UseProperty("name")
                 .UseProperty("name")
-                .WithValueType(ElementType.STRING);
+                .WithStringType();
+
+
+            var isTriangle = trianglesClass
+                .UseProperty("IsTriangle")
+                .WithBooleanType();
 
 
             var propertyTable = trianglesClass
             var propertyTable = trianglesClass
                 .AddPropertyTable(3, "PropertyTable");
                 .AddPropertyTable(3, "PropertyTable");
@@ -87,6 +92,11 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty(nameProperty)
                 .UseProperty(nameProperty)
                 .SetValues("this is featureId0", "this is featureId1", "this is featureId2");
                 .SetValues("this is featureId0", "this is featureId1", "this is featureId2");
 
 
+            propertyTable
+                .UseProperty(isTriangle)
+                .SetValues(false, true, false);
+
+
             foreach (var primitive in model.LogicalMeshes[0].Primitives)
             foreach (var primitive in model.LogicalMeshes[0].Primitives)
             {
             {
                 var triangles = primitive.EvaluateTriangles().Count();
                 var triangles = primitive.EvaluateTriangles().Count();
@@ -153,26 +163,25 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .WithDescription("Type of tree.")
                 .WithDescription("Type of tree.")
                 .WithEnumeration(speciesEnum)
                 .WithEnumeration(speciesEnum)
                 .WithRequired(true);
                 .WithRequired(true);
-            
-            speciesProperty.Required = true;
-               
+
             // age property
             // age property
             var ageProperty = treeClass
             var ageProperty = treeClass
                 .UseProperty("age")
                 .UseProperty("age")
-                .WithDescription("The age of the tree, in years");
-            ageProperty.WithValueType(ElementType.SCALAR, DataType.UINT32, required: true);
+                .WithDescription("The age of the tree, in years")
+                .WithUInt32Type()
+                .WithRequired(true);
 
 
             // Height property
             // Height property
             var heightProperty = treeClass
             var heightProperty = treeClass
                 .UseProperty("height")
                 .UseProperty("height")
                 .WithDescription("Height of tree measured from ground level, in meters");
                 .WithDescription("Height of tree measured from ground level, in meters");
-            heightProperty.WithValueType(ElementType.SCALAR, DataType.FLOAT32);
+            heightProperty.WithFloat32Type();
 
 
             // Diameter property
             // Diameter property
             var diameterProperty = treeClass
             var diameterProperty = treeClass
                 .UseProperty("diameter")
                 .UseProperty("diameter")
                 .WithDescription("Diameter at trunk base, in meters.");
                 .WithDescription("Diameter at trunk base, in meters.");
-            diameterProperty.WithValueType(ElementType.SCALAR, DataType.FLOAT32);
+            diameterProperty.WithFloat32Type();
 
 
             var propertyTable = treeClass
             var propertyTable = treeClass
                 .AddPropertyTable(features.Count, "PropertyTable");
                 .AddPropertyTable(features.Count, "PropertyTable");
@@ -257,12 +266,12 @@ namespace SharpGLTF.Schema2.Tiles3D
             var componentProp = buildingComponentsClass
             var componentProp = buildingComponentsClass
                 .UseProperty("component")
                 .UseProperty("component")
                 .WithName("Component")
                 .WithName("Component")
-                .WithValueType(ElementType.STRING);
+                .WithStringType();
 
 
             var yearProp = buildingComponentsClass
             var yearProp = buildingComponentsClass
                 .UseProperty("yearBuilt")
                 .UseProperty("yearBuilt")
                 .WithName("Year built")
                 .WithName("Year built")
-                .WithValueType(ElementType.SCALAR, DataType.INT16);            
+                .WithInt16Type();            
 
 
             var propertyTable = buildingComponentsClass
             var propertyTable = buildingComponentsClass
                 .AddPropertyTable(4, "Example property table");
                 .AddPropertyTable(4, "Example property table");
@@ -342,17 +351,18 @@ namespace SharpGLTF.Schema2.Tiles3D
             exampleMetadataClass
             exampleMetadataClass
                 .UseProperty("insideTemperature")
                 .UseProperty("insideTemperature")
                 .WithName("Inside temperature")
                 .WithName("Inside temperature")
-                .WithValueType(ElementType.SCALAR, DataType.UINT8);
+                .WithUInt8Type();
 
 
             exampleMetadataClass
             exampleMetadataClass
                 .UseProperty("outsideTemperature")
                 .UseProperty("outsideTemperature")
                 .WithName("Outside temperature")
                 .WithName("Outside temperature")
-                .WithValueType(ElementType.SCALAR, DataType.UINT8);
+                .WithUInt8Type();
 
 
             exampleMetadataClass
             exampleMetadataClass
                 .UseProperty("insulation")
                 .UseProperty("insulation")
                 .WithName("Insulation Thickness")
                 .WithName("Insulation Thickness")
-                .WithValueType(ElementType.SCALAR, DataType.UINT8, true);
+                .WithUInt8Type()
+                .WithNormalized(true);
 
 
             // define texture property
             // define texture property
 
 
@@ -416,13 +426,13 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty("example_VEC3_FLOAT32")
                 .UseProperty("example_VEC3_FLOAT32")
                 .WithName("Example VEC3 FLOAT32 property")
                 .WithName("Example VEC3 FLOAT32 property")
                 .WithDescription("An example property, with type VEC3, with component type FLOAT32")
                 .WithDescription("An example property, with type VEC3, with component type FLOAT32")
-                .WithValueType(ElementType.VEC3, DataType.FLOAT32);
+                .WithVector3Type();
 
 
             var stringProperty = exampleMetadataClass
             var stringProperty = exampleMetadataClass
                 .UseProperty("example_STRING")
                 .UseProperty("example_STRING")
                 .WithName("Example STRING property")
                 .WithName("Example STRING property")
                 .WithDescription("An example property, with type STRING")
                 .WithDescription("An example property, with type STRING")
-                .WithValueType(ElementType.STRING);
+                .WithStringType();
 
 
             // define table
             // define table
 
 
@@ -486,13 +496,13 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty("example_VEC3_FLOAT32")
                 .UseProperty("example_VEC3_FLOAT32")
                 .WithName("Example VEC3 FLOAT32 property")
                 .WithName("Example VEC3 FLOAT32 property")
                 .WithDescription("An example property, with type VEC3, with component type FLOAT32")
                 .WithDescription("An example property, with type VEC3, with component type FLOAT32")
-                .WithValueType(ElementType.VEC3, DataType.FLOAT32);
+                .WithVector3Type();
 
 
             var matrix4x4Property = exampleMetadataClass
             var matrix4x4Property = exampleMetadataClass
                 .UseProperty("example_MAT4_FLOAT32")
                 .UseProperty("example_MAT4_FLOAT32")
                 .WithName("Example MAT4 FLOAT32 property")
                 .WithName("Example MAT4 FLOAT32 property")
                 .WithDescription("An example property, with type MAT4, with component type FLOAT32")
                 .WithDescription("An example property, with type MAT4, with component type FLOAT32")
-                .WithValueType(ElementType.MAT4, DataType.FLOAT32);
+                .WithMatrix4x4Type();
 
 
             // define table
             // define table
 
 
@@ -561,13 +571,15 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty("example_variable_length_ARRAY_normalized_UINT8")
                 .UseProperty("example_variable_length_ARRAY_normalized_UINT8")
                 .WithName("Example variable-length ARRAY normalized INT8 property")
                 .WithName("Example variable-length ARRAY normalized INT8 property")
                 .WithDescription("An example property, with type ARRAY, with component type UINT8, normalized, and variable length")
                 .WithDescription("An example property, with type ARRAY, with component type UINT8, normalized, and variable length")
-                .WithArrayType(ElementType.SCALAR, DataType.UINT8, false);
+                .WithArrayType(ElementType.SCALAR, DataType.UINT8)
+                .WithNormalized(false);
 
 
             var fixedLengthBooleanProperty = exampleMetadataClass
             var fixedLengthBooleanProperty = exampleMetadataClass
                 .UseProperty("example_fixed_length_ARRAY_BOOLEAN")
                 .UseProperty("example_fixed_length_ARRAY_BOOLEAN")
                 .WithName("Example fixed-length ARRAY BOOLEAN property")
                 .WithName("Example fixed-length ARRAY BOOLEAN property")
                 .WithDescription("An example property, with type ARRAY, with component type BOOLEAN, and fixed length ")
                 .WithDescription("An example property, with type ARRAY, with component type BOOLEAN, and fixed length ")
-                .WithArrayType(ElementType.BOOLEAN, null, false, 4);
+                .WithArrayType(ElementType.BOOLEAN, null, 4)
+                .WithNormalized(false);
 
 
             var variableLengthStringArrayProperty = exampleMetadataClass
             var variableLengthStringArrayProperty = exampleMetadataClass
                 .UseProperty("example_variable_length_ARRAY_STRING")
                 .UseProperty("example_variable_length_ARRAY_STRING")
@@ -651,12 +663,12 @@ namespace SharpGLTF.Schema2.Tiles3D
             var classAp0 = classA.UseProperty("example_FLOAT32")
             var classAp0 = classA.UseProperty("example_FLOAT32")
                 .WithName("Example FLOAT32 property")
                 .WithName("Example FLOAT32 property")
                 .WithDescription("An example property, with component type FLOAT32")
                 .WithDescription("An example property, with component type FLOAT32")
-                .WithValueType(ElementType.SCALAR, DataType.FLOAT32);
+                .WithFloat32Type();
 
 
             var classAp1 = classA.UseProperty("example_INT64")
             var classAp1 = classA.UseProperty("example_INT64")
                 .WithName("Example INT64 property")
                 .WithName("Example INT64 property")
                 .WithDescription("An example property, with component type INT64")
                 .WithDescription("An example property, with component type INT64")
-                .WithValueType(ElementType.SCALAR, DataType.INT64);
+                .WithInt64Type();
 
 
             var classB = schema.UseClassMetadata("exampleMetadataClassB")
             var classB = schema.UseClassMetadata("exampleMetadataClassB")
                 .WithName("Example metadata class B")
                 .WithName("Example metadata class B")
@@ -665,12 +677,12 @@ namespace SharpGLTF.Schema2.Tiles3D
             var classBp0 = classB.UseProperty("example_UINT16")
             var classBp0 = classB.UseProperty("example_UINT16")
                 .WithName("Example UINT16 property")
                 .WithName("Example UINT16 property")
                 .WithDescription("An example property, with component type UINT16")
                 .WithDescription("An example property, with component type UINT16")
-                .WithValueType(ElementType.SCALAR, DataType.UINT16);
+                .WithUInt16Type();
 
 
             var classBp1 = classB.UseProperty("example_FLOAT64")
             var classBp1 = classB.UseProperty("example_FLOAT64")
                 .WithName("Example FLOAT64 property")
                 .WithName("Example FLOAT64 property")
                 .WithDescription("An example property, with component type FLOAT64")
                 .WithDescription("An example property, with component type FLOAT64")
-                .WithValueType(ElementType.SCALAR, DataType.FLOAT64);
+                .WithFloat64Type();
 
 
             // properties
             // properties
 
 
@@ -743,7 +755,7 @@ namespace SharpGLTF.Schema2.Tiles3D
             classA.UseProperty("intensity")
             classA.UseProperty("intensity")
                 .WithName("Example intensity property")
                 .WithName("Example intensity property")
                 .WithDescription("An example property for the intensity, with component type FLOAT32")
                 .WithDescription("An example property for the intensity, with component type FLOAT32")
-                .WithValueType(ElementType.SCALAR, DataType.FLOAT32);
+                .WithFloat32Type();
 
 
             var speciesEnum = schema.UseEnumMetadata("classificationEnumType", ("MediumVegetation", 0), ("Buildings", 1));
             var speciesEnum = schema.UseEnumMetadata("classificationEnumType", ("MediumVegetation", 0), ("Buildings", 1));