LOD switching and pivots

Hi all,
quite new to THREE.js (coming from another library)
I played a bit with THREE.LOD and with basic samples everything works as expeced (levels, ranges, etc.) until I tried some imported meshes (glTF) with pivot far outside the mesh itself (this happens a lot with photogrammetric blocks).

After several tries, I figured out it looks like the computation of distance switch (thus the level) is made from local origin and NOT from object3D boundingbox center (as I’d expect). Is that correct?

Is there some way to set some flag to allow the LOD to switch depending on object bb center?
How is this addressed in general? Forcing offsets to my meshes looks a bad idea…

Yes, it uses the position of the object in world space which is not necessarily the center of its bounding box.

THREE.LOD does not provide the feature you are looking for. You have to indeed centering the object by yourself. Example code:

const aabb = new THREE.Box3();
aabb.setFromObject(object);

const center = new THREE.Vector3();
aabb.getCenter(center);

object.position.x += (object.position.x - center.x);
object.position.y += (object.position.y - center.y);
object.position.z += (object.position.z - center.z);

Thanks
I was able to switch correctly applying local offset to blocks, then re-transform the above LOD, like this:

himodel.position.set(-center.x,-center.y,-center.z)
lomodel.position.set(-center.x,-center.y,-center.z)

lod.addLevel( himodel, 0.0)
lod.addLevel( lomodel, 20.0)

lod.position.set(center.x,center.y,center.z);

The final LOD translate is needed to restore the block to its original position.
Looks a bit dirty, but it’s working… maybe there are cleaner approaches?

1 Like

You could patch or extend the LOD class to do this calculation automatically, without actually moving the object (just make sure to only calculate the AABB one time).