Skip to content

Commit dc19976

Browse files
committed
Removed normalization when checking accesor bounds. Fixes vpenades#231
1 parent 56e9245 commit dc19976

File tree

3 files changed

+160
-2
lines changed

3 files changed

+160
-2
lines changed

src/SharpGLTF.Core/Memory/MemoryAccessor.Validation.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,13 @@ public static void VerifyAccessorBounds(MemoryAccessor memory, IReadOnlyList<dou
286286
xinfo.Dimensions = DIMENSIONS.SCALAR;
287287
memory = new MemoryAccessor(memory.Data, xinfo);
288288

289-
var array = new MultiArray(memory.Data, memory.Attribute.ByteOffset, memory.Attribute.ItemsCount, memory.Attribute.ByteStride, dimensions, memory.Attribute.Encoding, memory.Attribute.Normalized);
289+
var array = new MultiArray(
290+
memory.Data,
291+
memory.Attribute.ByteOffset,
292+
memory.Attribute.ItemsCount,
293+
memory.Attribute.ByteStride,
294+
dimensions, memory.Attribute.Encoding,
295+
false); // bounds checks are done without normalization; https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_accessor_max
290296

291297
var current = new float[dimensions];
292298

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
{
2+
"accessors": [
3+
{
4+
"bufferView": 0,
5+
"componentType": 5126,
6+
"count": 12,
7+
"max": [
8+
-29.78723471088616,
9+
12.917932088251836,
10+
40.0
11+
],
12+
"min": [
13+
-96.04862708143158,
14+
-33.586632227100864,
15+
-40.0
16+
],
17+
"type": "VEC3"
18+
},
19+
{
20+
"bufferView": 1,
21+
"componentType": 5121,
22+
"count": 60,
23+
"type": "SCALAR"
24+
},
25+
{
26+
"bufferView": 2,
27+
"componentType": 5121,
28+
"count": 12,
29+
"max": [
30+
255,
31+
0,
32+
255,
33+
255
34+
],
35+
"min": [
36+
0,
37+
0,
38+
0,
39+
255
40+
],
41+
"normalized": true,
42+
"type": "VEC4"
43+
}
44+
],
45+
"asset": {
46+
"generator": "",
47+
"version": "2.0"
48+
},
49+
"bufferViews": [
50+
{
51+
"buffer": 0,
52+
"byteLength": 144,
53+
"byteStride": 12,
54+
"target": 34962
55+
},
56+
{
57+
"buffer": 0,
58+
"byteLength": 60,
59+
"byteOffset": 144,
60+
"target": 34963
61+
},
62+
{
63+
"buffer": 0,
64+
"byteLength": 48,
65+
"byteOffset": 204,
66+
"byteStride": 4,
67+
"target": 34962
68+
}
69+
],
70+
"buffers": [
71+
{
72+
"byteLength": 252,
73+
"uri": "data:application/octet-stream;base64,5hjAwtqvTkEAACBC5hjAwrZYBsIAAAAA5hjAwtqvTkEAAAAA5hjAwrZYBsIAACBCQkzuwdqvTkEAACBC5hjAwtqvTkEAACDCQkzuwbZYBsIAAAAA5hjAwrZYBsIAACDCQkzuwdqvTkEAAAAAQkzuwdqvTkEAACDCQkzuwbZYBsIAACBCQkzuwbZYBsIAACDCAAQDBAoDBwkFBwsJCQsICAsGCAYKCwcGBAgKCgYDAgkIBQkCAggEBgcBBwUBBgEDAQUCAAIEAwEAAQIAAAD//wAA//8AAP//AAD///8AAP8AAP///wAA/wAA////AAD//wAA//8AAP//AAD/"
74+
}
75+
],
76+
"materials": [
77+
{
78+
"doubleSided": true,
79+
"pbrMetallicRoughness": {
80+
"baseColorFactor": [
81+
0.5,
82+
0.5,
83+
0.0,
84+
1.0
85+
]
86+
}
87+
}
88+
],
89+
"meshes": [
90+
{
91+
"primitives": [
92+
{
93+
"attributes": {
94+
"COLOR_0": 2,
95+
"POSITION": 0
96+
},
97+
"indices": 1,
98+
"material": 0,
99+
"mode": 4
100+
}
101+
]
102+
}
103+
],
104+
"nodes": [
105+
{
106+
"mesh": 0,
107+
"name": "entity_1"
108+
},
109+
{
110+
"children": [
111+
0
112+
],
113+
"matrix": [
114+
-1.0,
115+
0.0,
116+
0.0,
117+
0.0,
118+
0.0,
119+
0.0,
120+
1.0,
121+
0.0,
122+
0.0,
123+
1.0,
124+
0.0,
125+
0.0,
126+
0.0,
127+
0.0,
128+
0.0,
129+
1.0
130+
],
131+
"name": "0"
132+
}
133+
],
134+
"scene": 0,
135+
"scenes": [
136+
{
137+
"nodes": [
138+
1
139+
]
140+
}
141+
]
142+
}

tests/SharpGLTF.Core.Tests/Schema2/LoadAndSave/RegressionTests.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace SharpGLTF.Schema2.LoadAndSave
1212
{
13-
[AttachmentPathFormat("*/TestResults/LoadAndSave/?", true)]
13+
[AttachmentPathFormat("*/TestResults/Regressions/?", true)]
1414
internal class RegressionTests
1515
{
1616
[Test]
@@ -102,5 +102,15 @@ public void LoadBinaryWithLimitedStream()
102102
Assert.That(model, Is.Not.Null);
103103
}
104104
}
105+
106+
[Test]
107+
public void LoadMinMaxBoundsOnByteAccessor()
108+
{
109+
// https://github.com/vpenades/SharpGLTF/issues/231
110+
// https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#_accessor_max
111+
112+
var gltf = ModelRoot.Load(ResourceInfo.From("cube-integer-min-max-bounds.gltf"));
113+
Assert.That(gltf, Is.Not.Null);
114+
}
105115
}
106116
}

0 commit comments

Comments
 (0)