Browse Source

add StructuralMetadataSchema

Bert Temme 2 years ago
parent
commit
22c9b41bb6

+ 155 - 3
src/SharpGLTF.Cesium/Schema2/EXTStructuralMetaDataRoot.cs

@@ -19,18 +19,168 @@ namespace SharpGLTF.Schema2
             set { _propertyTables = value; }
         }
 
+        public StructuralMetadataSchema Schema
+        {
+            get { return _schema; }
+            set { _schema = value; }
+        }
+
+
         protected override void OnValidateContent(ValidationContext validate)
         {
         }
     }
 
+    public partial class StructuralMetadataSchema
+    {
+        public StructuralMetadataSchema()
+        {
+            _classes = new Dictionary<string, StructuralMetadataClass>();
+            _enums = new Dictionary<string, StructuralMetadataEnum>();
+        }
+
+        public Dictionary<string, StructuralMetadataClass> Classes
+        {
+            get { return _classes; }
+            set { _classes = value; }
+        }
+
+        public string Id
+        {
+            get { return _id; }
+            set { _id = value; }
+        }
+
+        public string Version
+        {
+            get { return _version; }
+            set { _version = value; }
+        }
+
+        public string Name
+        {
+            get { return _name; }
+            set { _name = value; }
+        }
+
+        public string Description
+        {
+            get { return _description; }
+            set { _description = value; }
+        }
+
+        public Dictionary<string, StructuralMetadataEnum> Enums
+        {
+            get { return _enums; }
+            set { _enums = value; }
+        }
+    }
+
+    public partial class StructuralMetadataEnum
+    {
+        public StructuralMetadataEnum()
+        {
+            _values = new List<EnumValue>();
+        }
+        public string Name
+        {
+            get { return _name; }
+            set { _name = value; }
+        }
+        public string Description
+        {
+            get { return _description; }
+            set { _description = value; }
+        }
+        public List<EnumValue> Values
+        {
+            get { return _values; }
+            set { _values = value; }
+        }
+    }
+
+    public partial class EnumValue
+    {
+        public string Name
+        {
+            get { return _name; }
+            set { _name = value; }
+        }
+        public int Value
+        {
+            get { return _value; }
+            set { _value = value; }
+        }
+    }
+
+    public partial class StructuralMetadataClass
+    {
+        public StructuralMetadataClass()
+        {
+            _properties = new Dictionary<string, ClassProperty>();
+        }
+
+        public Dictionary<string, ClassProperty> Properties
+        {
+            get { return _properties; }
+            set { _properties = value; }
+        }
+
+        public string Name
+        {
+            get { return _name; }
+            set { _name = value; }
+        }
+
+        public string Description
+        {
+            get { return _description; }
+            set { _description = value; }
+        }
+
+    }
+
+    public partial class ClassProperty
+    {
+        public string Description
+        {
+            get { return _description; }
+            set { _description = value; }
+        }
+
+        public ElementType Type
+        {
+            get { return _type; }
+            set { _type = value; }
+        }
+
+        public string EnumType
+        {
+            get { return _enumType; }
+            set { _enumType = value; }
+        }
+
+        public DataType? ComponentType
+        {
+            get { return _componentType; }
+            set { _componentType = value; }
+        }
+
+        // required property
+        public bool? Required
+        {
+            get { return _required; }
+            set { _required = value; }
+        }
+    }
+
     public partial class PropertyTable
     {
         public PropertyTable()
         {
             _properties = new Dictionary<string, PropertyTableProperty>();
         }
-        public PropertyTable(string PropertyTableName, int NumberOfFeatures): this()
+        public PropertyTable(string PropertyTableName, int NumberOfFeatures) : this()
         {
             _class = PropertyTableName;
             _count = NumberOfFeatures;
@@ -57,9 +207,11 @@ namespace SharpGLTF.Schema2
 
     public partial class PropertyTableProperty
     {
-        public int Values {
+        public int Values
+        {
             get { return _values; }
             set { _values = value; }
         }
     }
-}
+}
+

+ 39 - 0
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -46,6 +46,45 @@ namespace SharpGLTF.Cesium
             propertyTable.Properties["id1"] = propertyTableProperty;
             ext.PropertyTables.Add( propertyTable);
 
+            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();
+            classes["tree"] = treeClass;
+            treeClass.Name = "Tree";
+            treeClass.Description = "Woody, perennial plant.";
+
+            var speciesProperty = new ClassProperty();
+            speciesProperty.Description = "Type of tree";
+            speciesProperty.Type = ElementType.ENUM;
+            speciesProperty.EnumType = "speciesEnum";
+            speciesProperty.Required = true;
+
+            treeClass.Properties.Add("species", speciesProperty);
+
+            var ageProperty = new ClassProperty();
+            ageProperty.Description = "The age of the tree, in years";
+            ageProperty.Type = ElementType.SCALAR;
+            ageProperty.ComponentType = DataType.UINT8;
+            ageProperty.Required = true;
+
+            treeClass.Properties.Add("age", ageProperty);
+
+            var speciesEnum = new StructuralMetadataEnum();
+            schema.Enums["speciesEnum"] = speciesEnum;
+            speciesEnum.Name = "Species";
+            speciesEnum.Description = "An example enum for tree species.";
+            speciesEnum.Values.Add(new EnumValue() { Name = "Unpsecified", Value = 0 });
+            speciesEnum.Values.Add(new EnumValue() { Name = "Oak", Value = 1 });
+            speciesEnum.Values.Add(new EnumValue() { Name = "Pine", Value = 2 });
+            speciesEnum.Values.Add(new EnumValue() { Name = "Maple", Value = 3 });
+
+            schema.Classes = classes;
+            ext.Schema = schema;
+
             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");