Aligning an object normal

This is about a project that I am working on. I am trying to abstract the details as much as possible.

There are two objects in ThreeJS context. One of the object is a simple triangle (2D geometry). This triangle moves and rotates as per the coordinates given by an external library.
There is another 3D object whose orientation(orientation) is to be kept in sync with this triangle.

For this purpose I did something like this:

.... v1, v2, v3 are Vector3 objects created with the coordinates given by an external library
triangle.geometry.vertices[0].copy(v1);
triangle.geometry.vertices[1].copy(v2);
triangle.geometry.vertices[2].copy(v3);

//Re-calculating new face normals
triangle.geometry.elementsNeedUpdate = true;
triangle.geometry.verticesNeedUpdate = true;
triangle.geometry.computeFaceNormals();

//Cloning the new normal
const normal = triangle.geometry.faces[0].normal.clone();

//Making the other Object to look at the normal thus cloned
obj.lookAt(normal);

The problem with this is that this works fine when the object obj is kept at Origin (0, 0, 0) and not when kept at any other position.
After browsing through the internet for this issue, I could find that there is this function transformDirection that can probably be used here, but I am not really sure how.
Appreciate any help or suggestion here. :pleading_face:

Hi!

So, take in count obj's position. Something like this:

var la = new THREE.Vector3().addVectors(obj.position, normal);
obj.lookAt(la);
2 Likes

@prisoner849 appreciate the quick response.
It worked ! Thanks a ton !

1 Like