My scenario involves having a scene
, multiple meshes
, and a target object
.
After setting up the scene, I use the code snippet below to make a mesh (referred to as mesh) face the target object:
mesh.lookAt(object)
This action successfully aligns the mesh with the object.
Now, I am trying to figure out how to replicate this rotation of the first mesh on another mesh so that it faces the same direction (not necessarily towards the same object but with the same orientation).
Is there a way to obtain the rotation coordinates of the initial mesh?
Furthermore, is there a method to calculate these coordinates without creating a new mesh or using the mesh.lookAt(object)
function?
UPDATE:
The best solution I found is to create a new THREE.Object3D()
and utilize object.lookAt(target)
. Subsequently, you can repeat this rotation for all subsequently loaded objects using:
new_object.rotation.set(object.rotation.x, object.rotation.y, object.rotation.z)
.
By implementing this approach, you only need to create one Object instead of generating numerous unnecessary Vector3-s.
Please avoid using
new_object.rotation = object.rotation
as it results in connected variables. Any changes made to the object
's rotation will automatically update the new_object.rotation
as well due to renderer updates occurring every frame.