Prechádzať zdrojové kódy

Fixed validation mismatch; A byte stride wider than required by the vertex attributes is not reported as an error by glTF-validator (although it should be reported as a warning due to the needless waste of memory)

Fixes #158
Vicente Penades 3 rokov pred
rodič
commit
cae46bc8b0

+ 1 - 1
src/SharpGLTF.Core/Schema2/gltf.MeshPrimitive.cs

@@ -394,7 +394,7 @@ namespace SharpGLTF.Schema2
                 // strided buffer detected
                 if (overlap)
                 {
-                    ok = group.Sum(item => item.Format.ByteSizePadded) == group.Key.ByteStride;
+                    ok = group.Sum(item => item.Format.ByteSizePadded) <= group.Key.ByteStride;
                 }
 
                 // sequential buffer detected

BIN
tests/Assets/Gotoarchi/test1.bin


+ 139 - 0
tests/Assets/Gotoarchi/test1.gltf

@@ -0,0 +1,139 @@
+{
+  "accessors": [
+    {
+      "bufferView": 0,
+      "componentType": 5126,
+      "count": 559,
+      "max": [
+        20.558862686157227,
+        20.558862686157227,
+        20.558862686157227
+      ],
+      "min": [
+        -20.558862686157227,
+        -20.558862686157227,
+        -20.558862686157227
+      ],
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 0,
+      "byteOffset": 12,
+      "componentType": 5126,
+      "count": 559,
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 1,
+      "componentType": 5125,
+      "count": 2880,
+      "type": "SCALAR"
+    }
+  ],
+  "asset": {
+    "version": "2.0"
+  },
+  "bufferViews": [
+    {
+      "buffer": 0,
+      "byteLength": 17888,
+      "byteStride": 32,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteLength": 11520,
+      "byteOffset": 17888,
+      "target": 34963
+    }
+  ],
+  "buffers": [
+    {
+      "byteLength": 29408,
+      "uri": "test1.bin"
+    }
+  ],
+  "materials": [
+    {
+      "name": "fallback Material",
+      "pbrMetallicRoughness": {
+        "baseColorFactor": [
+          0.10588235294117647,
+          0.6941176470588235,
+          0.34509803921568627,
+          1.0
+        ]
+      }
+    }
+  ],
+  "meshes": [
+    {
+      "name": "Sphere001",
+      "primitives": [
+        {
+          "attributes": {
+            "NORMAL": 1,
+            "POSITION": 0
+          },
+          "indices": 2,
+          "material": 0,
+          "mode": 4
+        }
+      ]
+    }
+  ],
+  "nodes": [
+    {
+      "matrix": [
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        1.0
+      ],
+      "mesh": 0,
+      "name": "Sphere001"
+    },
+    {
+      "children": [
+        0
+      ],
+      "matrix": [
+        1.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        -1.0,
+        0.0,
+        0.0,
+        1.0,
+        0.0,
+        0.0,
+        -0.07042326450347901,
+        0.0,
+        -0.0015650066733360292,
+        1.0
+      ]
+    }
+  ],
+  "scenes": [
+    {
+      "nodes": [
+        1
+      ]
+    }
+  ]
+}

BIN
tests/Assets/Gotoarchi/test12.bin


+ 252 - 0
tests/Assets/Gotoarchi/test12.gltf

@@ -0,0 +1,252 @@
+{
+  "accessors": [
+    {
+      "bufferView": 0,
+      "componentType": 5126,
+      "count": 559,
+      "max": [
+        20.558862686157227,
+        20.558862686157227,
+        20.558862686157227
+      ],
+      "min": [
+        -20.558862686157227,
+        -20.558862686157227,
+        -20.558862686157227
+      ],
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 0,
+      "byteOffset": 12,
+      "componentType": 5126,
+      "count": 559,
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 1,
+      "componentType": 5125,
+      "count": 2880,
+      "type": "SCALAR"
+    },
+    {
+      "bufferView": 2,
+      "componentType": 5126,
+      "count": 154,
+      "max": [
+        28.294837951660156,
+        27.86497688293457,
+        29.29737663269043
+      ],
+      "min": [
+        -28.294837951660156,
+        -27.864978790283203,
+        0.0
+      ],
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 2,
+      "byteOffset": 12,
+      "componentType": 5126,
+      "count": 154,
+      "type": "VEC3"
+    },
+    {
+      "bufferView": 3,
+      "componentType": 5125,
+      "count": 648,
+      "type": "SCALAR"
+    }
+  ],
+  "asset": {
+    "version": "2.0"
+  },
+  "bufferViews": [
+    {
+      "buffer": 0,
+      "byteLength": 17888,
+      "byteStride": 32,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteLength": 11520,
+      "byteOffset": 17888,
+      "target": 34963
+    },
+    {
+      "buffer": 0,
+      "byteLength": 4928,
+      "byteOffset": 29408,
+      "byteStride": 32,
+      "target": 34962
+    },
+    {
+      "buffer": 0,
+      "byteLength": 2592,
+      "byteOffset": 34336,
+      "target": 34963
+    }
+  ],
+  "buffers": [
+    {
+      "byteLength": 36928,
+      "uri": "test12.bin"
+    }
+  ],
+  "materials": [
+    {
+      "name": "fallback Material",
+      "pbrMetallicRoughness": {
+        "baseColorFactor": [
+          0.10588235294117647,
+          0.6941176470588235,
+          0.34509803921568627,
+          1.0
+        ]
+      }
+    },
+    {
+      "name": "fallback Material",
+      "pbrMetallicRoughness": {
+        "baseColorFactor": [
+          0.6509803921568628,
+          0.8980392156862745,
+          0.8980392156862745,
+          1.0
+        ]
+      }
+    }
+  ],
+  "meshes": [
+    {
+      "name": "Sphere001",
+      "primitives": [
+        {
+          "attributes": {
+            "NORMAL": 1,
+            "POSITION": 0
+          },
+          "indices": 2,
+          "material": 0,
+          "mode": 4
+        }
+      ]
+    },
+    {
+      "name": "Cylinder001",
+      "primitives": [
+        {
+          "attributes": {
+            "NORMAL": 4,
+            "POSITION": 3
+          },
+          "indices": 5,
+          "material": 1,
+          "mode": 4
+        }
+      ]
+    }
+  ],
+  "nodes": [
+    {
+      "matrix": [
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        1.0
+      ],
+      "mesh": 0,
+      "name": "Sphere001"
+    },
+    {
+      "children": [
+        0
+      ],
+      "matrix": [
+        1.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        -1.0,
+        0.0,
+        0.0,
+        1.0,
+        0.0,
+        0.0,
+        -0.07042326450347901,
+        0.0,
+        -0.0015650066733360292,
+        1.0
+      ]
+    },
+    {
+      "matrix": [
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.01,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        1.0
+      ],
+      "mesh": 1,
+      "name": "Cylinder001"
+    },
+    {
+      "children": [
+        2
+      ],
+      "matrix": [
+        1.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        0.0,
+        -1.0,
+        0.0,
+        0.0,
+        1.0,
+        0.0,
+        0.0,
+        0.10057971000671387,
+        0.0,
+        0.4445913696289063,
+        1.0
+      ]
+    }
+  ],
+  "scenes": [
+    {
+      "nodes": [
+        1,
+        3
+      ]
+    }
+  ]
+}

+ 38 - 0
tests/SharpGLTF.ThirdParty.Tests/SandboxTests.cs

@@ -10,6 +10,7 @@ using NUnit.Framework;
 using SharpGLTF.Geometry;
 using SharpGLTF.Geometry.VertexTypes;
 using SharpGLTF.Materials;
+using SharpGLTF.Scenes;
 using SharpGLTF.Schema2;
 using SharpGLTF.Validation;
 
@@ -145,5 +146,42 @@ namespace SharpGLTF.ThirdParty
                 .WriteObject(f => model.Save(f));
             
         }
+
+        [Test]
+        public void TestSharedMaterials()
+        {
+            var red = new MaterialBuilder()
+                .WithDoubleSide(true)
+                .WithMetallicRoughness(0.9f, 0.1f)
+                .WithMetallicRoughnessShader()
+                .WithChannelParam(KnownChannel.BaseColor, KnownProperty.RGBA, new Vector4(1, 0, 0, 1));
+
+            VBColor1 v1 = new VBColor1(new Vector3(1, 0, 0));
+            VBColor1 v2 = new VBColor1(new Vector3(0, 1, 0));
+            VBColor1 v3 = new VBColor1(new Vector3(0, 0, 1));
+
+            var mesh1 = VBColor1.CreateCompatibleMesh("some mesh 1");
+            mesh1.UsePrimitive(red).AddTriangle(v1, v2, v3);
+            mesh1.UsePrimitive(red).AddTriangle(v1, v2, v3);
+
+            var mesh2 = VBColor1.CreateCompatibleMesh("some mesh 2");
+            mesh2.UsePrimitive(red).AddTriangle(v1, v2, v3);
+
+            var scene = new SceneBuilder();
+            scene.AddRigidMesh(mesh1, Matrix4x4.Identity);
+            scene.AddRigidMesh(mesh2, Matrix4x4.CreateTranslation(10,0,0));
+
+            var gltf = scene.ToGltf2();
+        }
+
+
+        [Test]
+        public void TestLoadWideStridefile()
+        {
+            // https://github.com/vpenades/SharpGLTF/issues/158
+
+            var gltf = ModelRoot.Load(ResourceInfo.From("Gotoarchi\\test1.gltf"));
+            Assert.NotNull(gltf);
+        }
     }
 }