Hi,
I am new to ThreeJS.
My issue is the following: I am loading an object( using the FBX loader), that has the geometry displaced by a locator.
I am trying to bring the geometry to the centre of my viewport but what I am currently doing is bringing the centre of a bounding box of the geometry but offset by the transformations of the locator.
I want to know how to calculate the true world space of the geometry, basically I want to find out the offset between the locator and the geometry.
In Maya or other 3D applications I would go up the hierarchy and calculate the world transforms based on the object local transforms and its parents transforms. I don’t know how to work my way up the hierarchy here(that’s one problem), when I try to access the geometry’s parents I don’t seem to be able to get their transformations.
When geometries are not displace I use the following to centre the geometry:
// Compute object dimensions
const matrix = new three.Vector3();
child.geometry.computeBoundingBox();
const offset = child.geometry.boundingBox.getCenter(matrix);
child.geometry.applyMatrix(
new three.Matrix4().makeTranslation(
-offset.x,
-offset.y,
-offset.z,
),
);
child.geometry.computeBoundingBox();
const box = new three.Box3().setFromObject(object);
objectDimension = box.getSize(new three.Vector3()).length();
objectPosition = box.getCenter(new three.Vector3());
object.position.x += object.position.x - objectPosition.x;
object.position.y += object.position.y - objectPosition.y;
object.position.z += object.position.z - objectPosition.z;
// Adding loaded model to the scene object
scene.add(object);
I tried getting the world position using this method ’ getWorldPosition’ but I still get the world position of the locator, so not helpful at all.
Going back to the 3D package and altering the model is not an option, I need to figure out how to find all the information I need while in ThreeJS.
Thanks!