question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Box3 expandByObject fails if attribute.itemSize is 2.

See original GitHub issue
Box3’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:closed
  • Created 5 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Mugen87commented, Jun 26, 2018

In this case I vote to clarify the documentation. Users have to ensure their geometry data is expressed in 3D space when using Box3.

0reactions
Usnulcommented, Jul 11, 2018

I see. So WebGL renderer makes that assumption. Okay, I won’t argue further.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix AttributeError: 'Series' object has no attribute ' ...
Itemsize attribute is used to return the size of elements in a series. However, in newer versions, they have removed the Itemsize as...
Read more >
Box3 – three.js docs
box - Box to compare with this one. Returns true if this box and box share the same lower and upper bounds. #...
Read more >
three.js
EPSILON = Math.pow( 2, - 52 ); } if ( Number. ... case 1: return this.y; default: throw new Error( 'index is out...
Read more >
Team:Munich/Hardware/threeJS
// We compute the minimum and maximum dot product values. If those values // are on the same side (back or front) of...
Read more >
UNPKG - @google/model-viewer
__pendingValue = undefined;\n if (strings.length !== 2 || strings[0] !== '' || strings[1] !== '') {\n throw new Error('Boolean attributes can only contain...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found