In my setup, I currently have 3 meshes named cube(a), tempSphere(b), and m_mesh(c). Mesh a and b are grouped together with a as the parent mesh.
I have managed to update the location, rotation, and position of the group, so that meshes a and b automatically adjust themselves. Now, I am facing an issue where I want to set c to the current position and rotation of b. Below is my attempt which is not working as expected:
const cube: Mesh = this.createCube(size, objectColor);
group.add(cube);
const homePos: THREE.Vector3 = this.getHomePosition(size, homePosition);
const tempSphere = this.createHomePosition(cube, homePosition);
group.add(tempSphere);
// Set the local position of the group
group.position.x = meshPosition.x;
group.position.y = meshPosition.y;
group.position.z = meshPosition.z;
// Set the local rotation of the group
const rad = rotationZ * Math.PI / 180;
group.rotation.z = rad;
// Try to update the world matrix of the group and tempSphere
group.updateMatrixWorld(true);
tempSphere.updateMatrix();
tempSphere.updateMatrixWorld(true);
tempSphere.updateWorldMatrix(true, true);
// Retrieve the world matrix of tempSphere
let worldRotQuat: THREE.Quaternion;
let worldPos: THREE.Vector3;
tempSphere.getWorldQuaternion(worldRotQuat);
tempSphere.getWorldPosition(worldPos);
// Set the world matrix of tempSphere to another external mesh
if (this.transScaleTool.m_mesh !== null) {
this.transScaleTool.m_mesh.matrixWorld.setRotationFromQuaternion(worldRotQuat);
this.transScaleTool.m_mesh.matrixWorld.setPosition(worldPos);
}