I am creating a scene using the newish fat lines feature and am having trouble finding the bounding volume for it that I use to position the camera so that the geometry fills the scene.
I understand from a previous thread that "Box3.setFromObject() will not work correctly when applied to any object whose vertices are updated on the GPU" like in this case but that "LineSegmentsGeometry.computeBoundingBox() should work, though.".
I haven’t been able to make my example work using these pointers - can someone point me in the right direction please.
I hope it’s what you are looking for. The idea is to calculate the bounding box of the pure geometry data and then use it. If your line object is transform e.g. a scaling is applied, you have to multiply the world matrix of the line object with the mentioned bounding box. I’ve done this in your code and add some comments in order to illustrate the approach.
Wonderful - thank you so much for taking the time to add comments too…
Out of curiosity, I wondered why the geometry didn’t appear to fill the viewport like it does if the geometry is a sphere so I added a sphere to the scene that had the same radius as the bounding sphere we calculate.
any thoughts why the sphere doesn’t match the viewport extents when the fudge factor is 1.0?
EDIT: I switched my dev box from macOS to Windows and same fiddle now works and sphere fits perfectly. I think it’s because I was logged into JS Fiddle in macOS and have a different panel configuration as my default.
Porting what you taught me to my experiment, I see that I am creating hundreds of THREE.Line2's and adding them to the root THREE.Object3D each time but that has no geometry::computeBoundingBox() function - I imagined that would be present and recalculate every time something was added to it.
Maybe a THREE.Group() is the right root note to use here?
Later:
For each of the few hundred THREE.Line2s I add, I grab their bounding sphere and keep a running record of the total bounds by adding them together - I use the final total to calculate the camera pos that fits properly but it feels like I’m needlessly repeating work.
THREE.Object3D and THREE.Group have no geometry property. Consider THREE.Object3D as a base class for concrete objects in 3D space like meshes, lines or point clouds. As the name implies, THREE.Group is intended to group objects in order to apply transformations to a bunch of objects at the same time.
I think this is a valid solution. Can’t think of a better one right now.