1

I have three cube meshes (A, B, C) each within a group. Then I parented the groups into a hierarchy.

Group A -> Group B -> Group C

I need to rotate group B around a world axis and the find the position of mesh C.

For rotation around a world axis I used the code given here

I have a small rotate_cubes function to perform the rotation. After rotation it logs the result of getWorldPosition(). But I do not get the updated position. I get the old position of the cube C.

function rotate_cubes(group) {
 group.rotateAroundWorldAxis(make_vector3(), make_vector3(1, 0, 0), 15 * THREE.Math.DEG2RAD)

  let pos = make_vector3()
  cube3.getWorldPosition(pos)
  console.log(pos)
}

How can I calculate its position after rotation?

Thanks for the help.

GaryTheBaddy
  • 123
  • 1
  • 8
  • 2
    Can you please try to update the world matrix of Group B via `updateMatrixWorld()` after applying the rotation? In the next step, try to retrieve the world position of mesh C. – Mugen87 Jun 11 '19 at 09:09
  • Thank you very much @Mugen87! It works now. I made the incorrect assumption that the matrix gets updated automatically. – GaryTheBaddy Jun 12 '19 at 02:58
  • 1
    Also please add this as an answer so I can mark it as the answer. Will be easier for others to find. – GaryTheBaddy Jun 12 '19 at 02:59

1 Answers1

1

Try to update the world matrix of Group B via Object3D.updateMatrixWorld() after applying the rotation. In the next step, try to retrieve the world position of mesh C.

three.js R105

Mugen87
  • 28,829
  • 4
  • 27
  • 50