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.

InstancedMesh/SkinnedMesh and computeBoundingBox().

See original GitHub issue

Geometry bounding box gives a somewhat misleading result when used in an InstancedMesh.

    var count = 10000;

    var mesh = new THREE.InstancedMesh( geometry, material, count );

    var dummy = new THREE.Object3D();

    for ( var i = 0; i < count; i ++ ) {

    	dummy.position.set(
		Math.random() * 20 - 10,
		Math.random() * 20 - 10,
		Math.random() * 20 - 10
	);

	dummy.updateMatrix();

	mesh.setMatrixAt( i, dummy.matrix );

    }

Using new Box3().setFromObject(mesh) only gives you the Box3 for the single geometry, and not for the whole instance.

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:11 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
mrdoobcommented, Jan 28, 2020

SkinnedMesh case is a less visible glitch. But yes, we should solve this at some point.

2reactions
gkjohnsoncommented, Jan 9, 2020

Classes like InstancedMesh or SkinnedMesh needs to be considered in order to compute proper AABBs and bounding spheres.

I agree – there are cases even with just a mesh where being able to specify the bounding volume per-object rather than per-geometry would be beneficial. Materials can change the apparent bounds of geometry, as well, with custom vertex shaders, instancing, and displacement maps (which I also think don’t work correctly at the moment).

I still think it’s valuable to store the bounding volume on the geometry, though, to share the volume instances. Maybe the responsibility of checking for frustum intersection should shift to the objects? Should the Mesh class define an intersectsFrustum function that can be implemented by derivative classes? I think this would help with the problems mentioned here. Here’s a simple example:

Mesh.prototype.intersectsFrustum = function ( frustum ) {

  var geometry = this.geometry;
  var box = this.boundingBox || geometry.boundingBox;
  return frustum.intersectsBox( box );

}

This would allow a bounding box to optionally be set on the Mesh to account for cases where the material changes the visual bounds of the shape. Of course raycasting would also have to be updated to support custom intersections if desired but that’s already override-able.

Read more comments on GitHub >

github_iconTop Results From Across the Web

BufferGeometry#computeBoundingBox – three.js docs
BufferGeometry. A representation of mesh, line, or point geometry. Includes vertex positions, face indices, normals, colors, UVs, and custom attributes ...
Read more >
When should I call Geometry.computeBoundingBox() etc?
I always call the required compute methods just after I ended adding vertices, faces, etc and before creating the mesh with the geometry:...
Read more >
Compute bounding box — Axom documentation
The BoundingBox class represents an axis-aligned bounding box, which has two walls perpendicular to the X-axis, two perpendicular to the Y-axis, and two ......
Read more >
`compute bounding box` C++ Examples - ProgramCreek.com
const AABB& Submesh::computeBoundingBox() { Vec3f maxPos(std::numeric_limits<float>::lowest()); Vec3f minPos(std::numeric_limits<float>::max()); ...
Read more >
OpenSceneGraph: osg::Drawable Class Reference
Compute the bounding sphere around Drawables's geometry. More... virtual BoundingBox · computeBoundingBox () const. Compute the bounding box around Drawables's ...
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