Browse Source

fix the complex types test

Bert Temme 1 year ago
parent
commit
0259ff405e

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

@@ -679,25 +679,26 @@ namespace SharpGLTF.Schema2
 
             private ModelRoot _GetModelRoot() => LogicalParent.LogicalParent.LogicalParent;
 
-            public void SetValues2D<T>(List<List<T>> values, bool CreateArrayOffsets = true)
+            public void SetValues2D<T>(List<List<T>> values, bool HasVariableLength = true)
             {
                 var root = _GetModelRoot();
                 
                 int logicalIndex = GetBufferView(root, values);
-                this.Values = logicalIndex;
+                Values = logicalIndex;
 
-                if (CreateArrayOffsets)
+                if (HasVariableLength)
                 {
+                    // if the array has items of variable length, create arraysOffsets bufferview
                     var arrayOffsets = BinaryTable.GetArrayOffsets(values);
                     int logicalIndexOffsets = GetBufferView(root, arrayOffsets);
-                    this.ArrayOffsets = logicalIndexOffsets;
+                    ArrayOffsets = logicalIndexOffsets;
 
                     if (typeof(T) == typeof(string))
                     {
                         var stringValues = values.ConvertAll(x => x.ConvertAll(y => (string)Convert.ChangeType(y, typeof(string), CultureInfo.InvariantCulture)));
                         var stringOffsets = BinaryTable.GetStringOffsets(stringValues);
                         int offsets = GetBufferView(root, stringOffsets);
-                        this.StringOffsets = offsets;
+                        StringOffsets = offsets;
                     }
                 }                
             }

+ 16 - 9
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -5,6 +5,7 @@ using SharpGLTF.Materials;
 using SharpGLTF.Scenes;
 using SharpGLTF.Validation;
 using System;
+using System.Collections.Generic;
 using System.Numerics;
 
 namespace SharpGLTF.Schema2.Tiles3D
@@ -467,13 +468,13 @@ namespace SharpGLTF.Schema2.Tiles3D
 
             var exampleEnum = schema.UseEnumMetadata("exampleEnumType", ("ExampleEnumValueA", 0), ("ExampleEnumValueB", 1), ("ExampleEnumValueC", 2));
 
-            // class properties
+            //// class properties
 
             var uint8ArrayProperty = exampleMetadataClass
                 .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, false);
 
             var fixedLengthBooleanProperty = exampleMetadataClass
                 .UseProperty("example_fixed_length_ARRAY_BOOLEAN")
@@ -495,26 +496,32 @@ namespace SharpGLTF.Schema2.Tiles3D
 
             var examplePropertyTable = exampleMetadataClass.AddPropertyTable(1, "Example property table");
 
-            // Question: The table declares a feature count of 1, but then, these properties define different number of items
-            
+            var bytes = new List<List<byte>>();
+            bytes.Add(new List<byte>() { 0, 1, 2, 3, 4, 5, 6, 7 });
             examplePropertyTable
                 .UseProperty(uint8ArrayProperty)
-                .SetValues<byte>(0, 1, 2, 3, 4, 5, 6, 7);
+                .SetValues2D(bytes);
 
+            var bools = new List<List<bool>>();
+            bools.Add(new List<bool>() { true, false, true, false });
             examplePropertyTable
                 .UseProperty(fixedLengthBooleanProperty)
-                .SetValues<Boolean>(true, false, true, false);
+                .SetValues2D(bools, false);
 
+            var strings = new List<List<string>>();
+            strings.Add(new List<string>() { "Example string 1", "Example string 2", "Example string 3" });
             examplePropertyTable
                 .UseProperty(variableLengthStringArrayProperty)
-                .SetValues("Example string 1", "Example string 2", "Example string 3");
+                .SetValues2D(strings);
 
+            // Fill property table with enum values
+            var ints = new List<List<int>>();
+            ints.Add(new List<int>() { 0, 1 });
             examplePropertyTable
                 .UseProperty(fixed_length_ARRAY_ENUM)
-                .SetValues<int>(0, 1);
+                .SetValues2D(ints, false);
 
             // add to primitive            
-
             var featureId = new FeatureIDBuilder(examplePropertyTable, 0);
 
             model.LogicalMeshes[0].Primitives[0].AddMeshFeatureIds(featureId);