After detaching child from parent mesh, child's position is the one of parent


I have the following issue: from the GLB file I import to the scene mesh which is one parent (table) with 3 children (chairs) as seen on the picture.

After I take each child and attach it to the scene since I want to create 4 fully independent mesh objects I am noticing that the position of each one of children is still the position of the parent.

My question is : how to actally make those children meshes fully ‘independent’ meaning that their own geometry center is not in the center of the table and that theri position on the scene is not the position of the table since they are not in the parent-children relation now?

Screenshot 2022-01-12 at 10.55.04

Many thanks!

I think chairs have local offseted positions (pivot). In three.js need to translate their vertices positions to center and then to floor.



I’ve resolved it with this:

let box = new THREE.Box3().setFromObject(newchild);
    let offset = box.getCenter();
    newchild.geometry = existingchild.geometry;;

    newchild.position.x = offset.x;
    newchild.position.y = offset.y;
    newchild.position.z = offset.z;
    newchild.rotation.z = rotation;

(newchild is actually the mesh child)

Hope it helps someone.