Browse Source

add min, max, offset, scale to properties

Bert Temme 1 year ago
parent
commit
2d7000038d

+ 11 - 4
src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataPrimitive.cs

@@ -123,7 +123,6 @@ namespace SharpGLTF.Schema2
                         var expectedVertexAttribute = "TEXCOORD_" + textureCoordinate;
                         var expectedVertexAttribute = "TEXCOORD_" + textureCoordinate;
                         Guard.NotNull(meshPrimitive.GetVertexAccessor(expectedVertexAttribute), nameof(textureCoordinate), $"The primitive should have texture coordinate attribute {textureCoordinate}.");
                         Guard.NotNull(meshPrimitive.GetVertexAccessor(expectedVertexAttribute), nameof(textureCoordinate), $"The primitive should have texture coordinate attribute {textureCoordinate}.");
 
 
-
                         var texture = property.Value.Texture;
                         var texture = property.Value.Texture;
                         Guard.NotNull(texture, nameof(texture), $"The primitive should have texture {texture}.");
                         Guard.NotNull(texture, nameof(texture), $"The primitive should have texture {texture}.");
 
 
@@ -137,6 +136,11 @@ namespace SharpGLTF.Schema2
                                  $"The property '{property.Key}'  is a variable-length array, which is not supported for property textures");
                                  $"The property '{property.Key}'  is a variable-length array, which is not supported for property textures");
                         }
                         }
 
 
+                        // todo: check used values in texture against min, max (using scale and offset)
+                        // var min = schemaProperty.Min;
+                        // var max = schemaProperty.Max;
+                        // var scale = schemaProperty.Scale;
+                        // var offset = schemaProperty.Offset;
 
 
                         var channels = property.Value.Channels;
                         var channels = property.Value.Channels;
                         var elementCount = ComponentCount.ElementCountForType(schemaProperty.Type);
                         var elementCount = ComponentCount.ElementCountForType(schemaProperty.Type);
@@ -173,9 +177,12 @@ namespace SharpGLTF.Schema2
                         var expectedVertexAttribute = property.Value.Attribute;
                         var expectedVertexAttribute = property.Value.Attribute;
                         Guard.NotNull(meshPrimitive.GetVertexAccessor(expectedVertexAttribute), expectedVertexAttribute, $"The primitive should have custom vertex attribute {expectedVertexAttribute}.");
                         Guard.NotNull(meshPrimitive.GetVertexAccessor(expectedVertexAttribute), expectedVertexAttribute, $"The primitive should have custom vertex attribute {expectedVertexAttribute}.");
 
 
-                        // var min = property.Value.Min?.AsValue();
-                        //var max = property.Value.Max?.AsValue();
-                        // todo check against min and max of accessor
+                        // todo: check used values in attribute against min, max (using scale and offset)
+                        var min = property.Value.Min;
+                        var max = property.Value.Max;
+                        var scale = property.Value.Scale;
+                        var offset = property.Value.Offset;
+                        // todo read values from accessor, get min, max
                         // var acc = property.Value.Attribute;
                         // var acc = property.Value.Attribute;
                         // var vertexAccessor = meshPrimitive.GetVertexAccessor(acc);
                         // var vertexAccessor = meshPrimitive.GetVertexAccessor(acc);
                         // var a = vertexAccessor.AsScalarArray();
                         // var a = vertexAccessor.AsScalarArray();

+ 37 - 0
src/SharpGLTF.Ext.3DTiles/Schema2/Ext.StructuralMetadataRoot.cs

@@ -540,14 +540,26 @@ namespace SharpGLTF.Schema2
             public JsonNode Min
             public JsonNode Min
             {
             {
                 get => _min;
                 get => _min;
+                set => _min = value;
             }
             }
 
 
             public JsonNode Max
             public JsonNode Max
             {
             {
                 get => _max;
                 get => _max;
+                set => _max = value;
             }
             }
 
 
+            public JsonNode Scale
+            {
+                get => _scale;
+                set => _scale = value;
+            }
 
 
+            public JsonNode Offset
+            {
+                get => _offset;
+                set => _offset = value;
+            }
             #endregion
             #endregion
         }
         }
 
 
@@ -1264,6 +1276,31 @@ namespace SharpGLTF.Schema2
                 set => _count = value;
                 set => _count = value;
             }
             }
 
 
+            public JsonNode Min
+            {
+                get => _min;
+                set => _min = value;
+            }
+
+            public JsonNode Max
+            {
+                get => _max;
+                set => _max = value;
+            }
+
+            public JsonNode Scale
+            {
+                get => _scale;
+                set => _scale = value;
+            }
+
+            public JsonNode Offset
+            {
+                get => _offset;
+                set => _offset = value;
+            }
+
+
             #endregion
             #endregion
 
 
             #region API
             #region API

+ 4 - 7
tests/SharpGLTF.Cesium.Tests/ExtStructuralMetadataTests.cs

@@ -52,14 +52,8 @@ namespace SharpGLTF.Schema2.Tiles3D
                 "PropertyTexturePropertyTexturePropertyMinNotInRange.gltf",
                 "PropertyTexturePropertyTexturePropertyMinNotInRange.gltf",
             };
             };
 
 
-            // combine both lists excludedFilesWithStats and excludedFilesWithTextureInspection into a new list
-
             var excludedFiles = excludedFilesWithStats.Concat(excludedFilesWithTextureInspection);
             var excludedFiles = excludedFilesWithStats.Concat(excludedFilesWithTextureInspection);
 
 
-
-
-            // var excludedTests = excludedFilesWithStats.AddRange(excludedFilesWithTextureInspection);
-
             foreach (var file in gltffiles)
             foreach (var file in gltffiles)
             {
             {
                 var fileName = Path.GetFileName(file);
                 var fileName = Path.GetFileName(file);
@@ -69,7 +63,10 @@ namespace SharpGLTF.Schema2.Tiles3D
 
 
                     if (!fileName.StartsWith("Valid"))
                     if (!fileName.StartsWith("Valid"))
                     {
                     {
-                        Assert.That(() => ModelRoot.Load(file), Throws.Exception);
+                        //if(fileName == "PropertyTextureClassPropertyWithOffsetScaleMinNotInRange.gltf")
+                        //{
+                            Assert.That(() => ModelRoot.Load(file), Throws.Exception);
+                        //}
                     }
                     }
                     else
                     else
                     {
                     {