Browse Source

breaks again?

Bert Temme 1 year ago
parent
commit
2743b28635

+ 17 - 2
src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs

@@ -1579,10 +1579,25 @@ namespace SharpGLTF.Schema2
                 return WithArrayType(ELEMENTTYPE.MAT4, DATATYPE.FLOAT32, count);
                 return WithArrayType(ELEMENTTYPE.MAT4, DATATYPE.FLOAT32, count);
             }
             }
 
 
-            public StructuralMetadataClassProperty WithStringArrayType(int? count = null, string noData = null)
+            public StructuralMetadataClassProperty WithStringArrayType(int? count = null, List<string> noData = null, List<string> defaultValue = null)
             {
             {
                 var property = WithArrayType(ELEMENTTYPE.STRING, null, count);
                 var property = WithArrayType(ELEMENTTYPE.STRING, null, count);
-                if (noData != null) property._noData = noData;
+                if (noData != null)
+                {
+                    var arr = noData.ToArray();
+                    var jsonNodes = new List<JsonNode>();
+                    foreach(var item in arr)
+                    {
+                        jsonNodes.Add(item);
+                    }
+                    var jsonArray = new JsonArray(jsonNodes.ToArray());
+
+                    property._noData = jsonArray;
+                }
+                if (noData != null)
+                {
+                    property._default = new JsonArray(defaultValue[0]);
+                }
                 return property;
                 return property;
             }
             }
 
 

+ 11 - 0
tests/SharpGLTF.Ext.3DTiles.Tests/ExtStructuralMetadataTests.cs

@@ -182,6 +182,10 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty("matrix4x4")
                 .UseProperty("matrix4x4")
                 .WithMatrix4x4Type(Matrix4x4.Identity * -10);
                 .WithMatrix4x4Type(Matrix4x4.Identity * -10);
 
 
+            var stringArrayProperty = schemaClass
+                .UseProperty("stringArray")
+                .WithStringArrayType(noData: ["test0", "test1"], defaultValue: ["nothing"]);
+
             // todo add array types
             // todo add array types
 
 
             var propertyTable = schemaClass.AddPropertyTable(1);
             var propertyTable = schemaClass.AddPropertyTable(1);
@@ -247,6 +251,13 @@ namespace SharpGLTF.Schema2.Tiles3D
                 .UseProperty(matrix4x4Property)
                 .UseProperty(matrix4x4Property)
                 .SetValues(m4);
                 .SetValues(m4);
 
 
+            var strings = new List<List<string>>();
+            strings.Add(["test0", "test1"]);
+
+            propertyTable
+                .UseProperty(stringArrayProperty)
+                .SetArrayValues(strings);
+
             foreach (var primitive in model.LogicalMeshes[0].Primitives)
             foreach (var primitive in model.LogicalMeshes[0].Primitives)
             {
             {
                 var featureIdAttribute = new FeatureIDBuilder(1, 0, propertyTable);
                 var featureIdAttribute = new FeatureIDBuilder(1, 0, propertyTable);