Browse Source

add default property

Bert Temme 1 year ago
parent
commit
bc0f15a028

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

@@ -14,6 +14,7 @@ namespace SharpGLTF.Schema2
     using Tiles3D;
     using Tiles3D;
     using System.Numerics;
     using System.Numerics;
     using System.Text.Json.Nodes;
     using System.Text.Json.Nodes;
+    using System.ComponentModel;
 
 
     partial class Tiles3DExtensions
     partial class Tiles3DExtensions
     {
     {
@@ -1341,10 +1342,11 @@ namespace SharpGLTF.Schema2
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithStringType(string noData = null)
+            public StructuralMetadataClassProperty WithStringType(string noData = null, string defaultValue = null)
             {
             {
                 Type = ElementType.STRING;
                 Type = ElementType.STRING;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if(defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
@@ -1354,88 +1356,98 @@ namespace SharpGLTF.Schema2
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithUInt8Type(byte? noData = null)
+            public StructuralMetadataClassProperty WithUInt8Type(byte? noData = null, byte? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.UINT8;
                 ComponentType = DATATYPE.UINT8;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithInt8Type(sbyte? noData = null)
+            public StructuralMetadataClassProperty WithInt8Type(sbyte? noData = null, sbyte? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.INT8;
                 ComponentType = DATATYPE.INT8;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithUInt16Type(ushort? noData = null)
+            public StructuralMetadataClassProperty WithUInt16Type(ushort? noData = null, ushort? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.UINT16;
                 ComponentType = DATATYPE.UINT16;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithInt16Type(short? noData = null)
+            public StructuralMetadataClassProperty WithInt16Type(short? noData = null, short? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.INT16;
                 ComponentType = DATATYPE.INT16;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithUInt32Type(uint? noData = null)
+            public StructuralMetadataClassProperty WithUInt32Type(uint? noData = null, uint? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.UINT32;
                 ComponentType = DATATYPE.UINT32;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithInt32Type(int? noData = null)
+            public StructuralMetadataClassProperty WithInt32Type(int? noData = null, int? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.INT32;
                 ComponentType = DATATYPE.INT32;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithUInt64Type(ulong? noData = null)
+            public StructuralMetadataClassProperty WithUInt64Type(ulong? noData = null, ulong? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.UINT64;
                 ComponentType = DATATYPE.UINT64;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithInt64Type(long? noData = null)
+            public StructuralMetadataClassProperty WithInt64Type(long? noData = null, long? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.INT64;
                 ComponentType = DATATYPE.INT64;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithFloat32Type(float? noData = null)
+            public StructuralMetadataClassProperty WithFloat32Type(float? noData = null, float? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.FLOAT32;
                 ComponentType = DATATYPE.FLOAT32;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithFloat64Type(double? noData = null)
+            public StructuralMetadataClassProperty WithFloat64Type(double? noData = null, double? defaultValue = null)
             {
             {
                 Type = ELEMENTTYPE.SCALAR;
                 Type = ELEMENTTYPE.SCALAR;
                 ComponentType = DATATYPE.FLOAT64;
                 ComponentType = DATATYPE.FLOAT64;
                 if (noData != null) _noData = noData;
                 if (noData != null) _noData = noData;
+                if (defaultValue != null) _default = defaultValue;
                 return this;
                 return this;
             }
             }
 
 
 
 
-            public StructuralMetadataClassProperty WithVector3Type(Vector3? noData = null)
+            public StructuralMetadataClassProperty WithVector3Type(Vector3? noData = null, Vector3? defaultValue = null)
             {
             {
                 Type = ElementType.VEC3;
                 Type = ElementType.VEC3;
                 ComponentType = DataType.FLOAT32;
                 ComponentType = DataType.FLOAT32;
@@ -1444,10 +1456,15 @@ namespace SharpGLTF.Schema2
                 {
                 {
                     _noData = new JsonArray(noData.Value.X, noData.Value.Y, noData.Value.Z);
                     _noData = new JsonArray(noData.Value.X, noData.Value.Y, noData.Value.Z);
                 }
                 }
+                if (defaultValue != null)
+                {
+                    _default = new JsonArray(defaultValue.Value.X, defaultValue.Value.Y, defaultValue.Value.Z);
+                }
+
                 return this;
                 return this;
             }
             }
 
 
-            public StructuralMetadataClassProperty WithMatrix4x4Type(Matrix4x4? noData = null)
+            public StructuralMetadataClassProperty WithMatrix4x4Type(Matrix4x4? noData = null, Matrix4x4? defaultValue = null)
             {
             {
                 Type = ElementType.MAT4;
                 Type = ElementType.MAT4;
                 ComponentType = DataType.FLOAT32;
                 ComponentType = DataType.FLOAT32;
@@ -1462,6 +1479,16 @@ namespace SharpGLTF.Schema2
                         m4.M41, m4.M42, m4.M43, m4.M44);
                         m4.M41, m4.M42, m4.M43, m4.M44);
                 }
                 }
 
 
+                if (defaultValue != null)
+                {
+                    var m4 = defaultValue.Value;
+                    _default = new JsonArray(
+                        m4.M11, m4.M12, m4.M13, m4.M14,
+                        m4.M21, m4.M22, m4.M23, m4.M24,
+                        m4.M31, m4.M32, m4.M33, m4.M34,
+                        m4.M41, m4.M42, m4.M43, m4.M44);
+                }
+
                 return this;
                 return this;
             }
             }
 
 
@@ -1598,37 +1625,6 @@ namespace SharpGLTF.Schema2
                 return this;
                 return this;
             }
             }
 
 
-            /**
-            private static JsonArray ToJsonArray(Vector3 vector3)
-            {
-                var floats = new float[] { vector3.X, vector3.Y, vector3.Z };
-                var  jsonNode = ToJsonArray(floats);
-                return jsonNode;
-            }
-
-            private static JsonArray ToJsonArray(Matrix4x4 matrix4x4)
-            {
-                var floats = new float[] {
-                    matrix4x4.M11, matrix4x4.M12, matrix4x4.M13, matrix4x4.M14,
-                    matrix4x4.M21, matrix4x4.M22, matrix4x4.M23, matrix4x4.M24,
-                    matrix4x4.M31, matrix4x4.M32, matrix4x4.M33, matrix4x4.M34,
-                    matrix4x4.M41, matrix4x4.M42, matrix4x4.M43, matrix4x4.M44
-                };
-
-                var jsonNode = ToJsonArray(floats);
-                return jsonNode;
-            }
-
-            private static JsonArray ToJsonArray(float[] floats)
-            {
-                var jsonNode = new JsonArray();
-                foreach (var f in floats)
-                {
-                    jsonNode.Add(f);
-                }
-
-                return jsonNode;
-            }*/
 
 
             #endregion
             #endregion
         }
         }

+ 5 - 2
tests/SharpGLTF.Ext.3DTiles.Tests/ExtStructuralMetadataTests.cs

@@ -120,9 +120,11 @@ namespace SharpGLTF.Schema2.Tiles3D
                     .UseProperty("description")
                     .UseProperty("description")
                     .WithStringType();
                     .WithStringType();
 
 
+            // for this property, the default value (byte.MaxValue) should be shown in the client when the actual value is 
+            // equal to the noData value (byte.MinValue)
             var uint8Property = schemaClass
             var uint8Property = schemaClass
                 .UseProperty("uint8")
                 .UseProperty("uint8")
-                .WithUInt8Type(byte.MinValue);
+                .WithUInt8Type(byte.MinValue, byte.MaxValue);
 
 
             var int8Property = schemaClass
             var int8Property = schemaClass
                 .UseProperty("int8")
                 .UseProperty("int8")
@@ -164,7 +166,7 @@ namespace SharpGLTF.Schema2.Tiles3D
 
 
             var stringProperty = schemaClass
             var stringProperty = schemaClass
                 .UseProperty("string")
                 .UseProperty("string")
-                .WithStringType("noData");
+                .WithStringType("noData", "-");
 
 
             var speciesProperty = schemaClass
             var speciesProperty = schemaClass
                 .UseProperty("species")
                 .UseProperty("species")
@@ -251,6 +253,7 @@ namespace SharpGLTF.Schema2.Tiles3D
                 primitive.AddMeshFeatureIds(featureIdAttribute);
                 primitive.AddMeshFeatureIds(featureIdAttribute);
             }
             }
 
 
+            model.SaveGLTF(@"D:\dev\github.com\bertt\cesium_issues\vector3_float32_nodata\vector3_float32_nodata.gltf");
             // create files
             // create files
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
             var ctx = new ValidationResult(model, ValidationMode.Strict, true);
             model.AttachToCurrentTest("cesium_ext_structural_minimal_metadata_sample.glb");
             model.AttachToCurrentTest("cesium_ext_structural_minimal_metadata_sample.glb");