Browse Source

add checks for textures

Bert Temme 2 years ago
parent
commit
3dab41c1ab

+ 19 - 1
src/SharpGLTF.Cesium/Schema2/EXTStructuralMetaDataRoot.cs

@@ -64,7 +64,25 @@ OneOf<StructuralMetadataSchema, Uri> schema)
                 }
                 }
                 );
                 );
 
 
-            // todo add check propertyTexture 
+            foreach(var propertyTexture in propertyTextures)
+            {
+                foreach(var propertyTextureProperty in propertyTexture.Properties)
+                {
+                    var texCoord = propertyTextureProperty.Value.TextureCoordinate;
+                    var channels = propertyTextureProperty.Value.Channels;
+                    var index = propertyTextureProperty.Value._LogicalTextureIndex;
+                    Guard.MustBeGreaterThanOrEqualTo(texCoord, 0, nameof(texCoord));
+                    Guard.IsTrue(channels.Count > 0, nameof(channels), "Channels must be defined");
+                    try
+                    {
+                        var texture = modelRoot.LogicalTextures[index];
+                    }
+                    catch (ArgumentOutOfRangeException)
+                    {
+                        throw new ArgumentOutOfRangeException($"Texture index {index} does not exist");
+                    }
+                }
+            }
             var ext = modelRoot.UseExtension<EXTStructuralMetadataRoot>();
             var ext = modelRoot.UseExtension<EXTStructuralMetadataRoot>();
             ext.PropertyTextures = propertyTextures;
             ext.PropertyTextures = propertyTextures;
             ext.AddSchema(schema);
             ext.AddSchema(schema);

+ 8 - 2
src/SharpGLTF.Cesium/Schema2/MeshExtMeshFeatures.cs

@@ -160,8 +160,14 @@ namespace SharpGLTF.Schema2
                 var expectedTexCoordAttribute = $"TEXCOORD_{item.Texture.TextureCoordinate}";
                 var expectedTexCoordAttribute = $"TEXCOORD_{item.Texture.TextureCoordinate}";
                 Guard.NotNull(primitive.GetVertexAccessor(expectedTexCoordAttribute), expectedTexCoordAttribute);
                 Guard.NotNull(primitive.GetVertexAccessor(expectedTexCoordAttribute), expectedTexCoordAttribute);
 
 
-                var image = primitive.LogicalParent.LogicalParent.LogicalImages[item.Texture.Index];
-                Guard.NotNull(image, "Texture " + nameof(item.Texture.Index));
+                try
+                {
+                    var texture = primitive.LogicalParent.LogicalParent.LogicalTextures[item.Texture.Index];
+                }
+                catch (System.ArgumentOutOfRangeException)
+                {
+                    throw new System.Exception($"Texture index {item.Texture.Index} does not exist");
+                }
             }
             }
         }
         }
     }
     }