Box3 expandByObject fails if attribute.itemSize is 2.
See original GitHub issueBox3
’s expandByObject
fails for buffer geometry whose itemSize !== 3
.
If you call expandByObject(obj)
where obj
has a child with (for example) a TextGeometry
, this line will attempt to read past the end of an array, then call applyMatrix4
so that v1
is {x:NaN, y:NaN, z:NaN}
:
https://github.com/mrdoob/three.js/blob/master/src/math/Box3.js#L255
This means that the box’s min
and max
both become NaN, NaN, NaN
.
One (obviously not optimized) solution is to replace that line with:
if (attribute.itemSize === 2) {
var v2 = new Vector2();
v2.fromBufferAttribute(attribute, i);
v1.x = v2.x;
v1.y = v2.y;
v1.z = 0;
} else {
v1.fromBufferAttribute(attribute, i);
}
v1.applyMatrix4(node.matrixWorld);
Of course, this would fail if attribute.itemSize === 4
. (I’m not sure ever happens in practice.) You can fix that by checking if itemSize ===3
before reading from it with a Vector3
.
This is not a problem with setFromBufferAttribute
because that does not rely on Math.min
or Math.max
, which favor NaN
over any numbers. (Instead it uses <
and >
which favor numbers over NaN
.)
Three.js version
- Dev
- r93
- …
Browser
- All of them
- Chrome
- Firefox
- Internet Explorer
OS
- All of them
- Windows
- macOS
- Linux
- Android
- iOS
Hardware Requirements (graphics card, VR Device, …)
Issue Analytics
- State:
- Created 5 years ago
- Comments:9 (5 by maintainers)
Top GitHub Comments
In this case I vote to clarify the documentation. Users have to ensure their geometry data is expressed in 3D space when using
Box3
.I see. So WebGL renderer makes that assumption. Okay, I won’t argue further.