Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InstancedMesh bounding volume issue #25610

Closed
ycw opened this issue Mar 3, 2023 · 8 comments
Closed

InstancedMesh bounding volume issue #25610

ycw opened this issue Mar 3, 2023 · 8 comments

Comments

@ycw
Copy link
Contributor

ycw commented Mar 3, 2023

Description

related #25591, its not guaranteed that the volume is the smallest, bc instancedmesh's matrixworld is ignored during union.

could computeBounding*() offers "precise" like this -> https://threejs.org/docs/index.html#api/en/math/Box3.setFromObject
??

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 3, 2023

its not guaranteed that the volume is the smallest,

That's true but since these volumes are recomputed often, it's not required to have the best-fit volume. The performance of the computation is also important.

bc instancedmesh's matrixworld is ignored during union

Do you mind explaining in more detail what you mean? The bounding volumes should be in local space.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 3, 2023

could computeBounding*() offers "precise" like this

TBH, I don't think that best-fit bounding volumes which are more expensive to compute are necessary for view frustum culling and ray casting. You can always compute best-fit bounding volumes on app level if you need them.

That said, it's sounds fine if you want to add "precise" support for InstancedMesh to Box3.expandByObject().

@ycw
Copy link
Contributor Author

ycw commented Mar 3, 2023

more expensive to compute

yes, so I wasn't requesting compute precise volume by defaults, but requesting an option as if box3.setfromobject which defaults to false

sounds fine if you want to add support for InstancedMesh to Box3.expandByObject()

nah, this will break codes; instancedmesh is-a object3d, behaviors had been defined in those apis

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 3, 2023

nah, this will break codes; instancedmesh is-a object3d, behaviors had been defined in those apis

It should work if you rewrite this section:

three.js/src/math/Box3.js

Lines 162 to 175 in fbd3ef9

if ( object.boundingBox !== undefined ) {
if ( object.boundingBox === null ) {
object.computeBoundingBox();
}
_box.copy( object.boundingBox );
_box.applyMatrix4( object.matrixWorld );
this.union( _box );
} else {

to something like:

if ( object.boundingBox !== undefined ) {

	if ( precise === true ) {

		// best-fit AABB code goes here

	} else {

		if ( object.boundingBox === null ) {

			object.computeBoundingBox();
	
		}
	
		_box.copy( object.boundingBox );
		_box.applyMatrix4( object.matrixWorld );
	
		this.union( _box );

	}

} else {

@ycw
Copy link
Contributor Author

ycw commented Mar 3, 2023

wait, seems a breaking change already; .expandByObject(instancedmesh) computed the bbox of instancedmesh.geometry before #25591; but then, it changes to compute a bbox enclosing all instances after #25591 :O

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 3, 2023

I don't think this a breaking change. The behavior wasn't right from the beginning.

@ycw
Copy link
Contributor Author

ycw commented Mar 3, 2023

breaking change: from wrong to right.

@ycw
Copy link
Contributor Author

ycw commented Mar 3, 2023

To sum up, there's still no out-of-box API computes the smallest bounding volume enclosing all instances, we've to impl on app level. Here's a good starting point (just appends .applyMatrix4(this.matrixWorld) in L64, and martixWorld must be updated beforehand). Thanks.

@ycw ycw closed this as completed Mar 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants