소스 검색

refactor adding types to metadata

Bert Temme 1 년 전
부모
커밋
6abb95ea25
2개의 변경된 파일150개의 추가작업 그리고 29개의 파일을 삭제
  1. 114 5
      src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs
  2. 36 24
      tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

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

@@ -1257,21 +1257,123 @@ namespace SharpGLTF.Schema2
                 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;
                 ComponentType = ctype;
-                Normalized = normalized;
                 Array = false;
-                Required = required;
                 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;
                 ComponentType = ctype;
-                Normalized = normalized;
                 Array = true;
                 Count = count;
                 return this;
@@ -1299,6 +1401,13 @@ namespace SharpGLTF.Schema2
                 return this;
             }
 
+            public StructuralMetadataClassProperty WithNormalized(bool normalized)
+            {
+                Normalized = normalized;
+                return this;
+            }
+
+
             #endregion
         }
 

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

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