Although I am still new to both the 3D and three JS worlds, I have managed to grasp most concepts. However, when it comes to matrices, I always find myself getting confused.
My goal is to drag a small object on top of other objects in such a way that the small object faces the same direction as the main object (similar to hanging a wall clock on the wall).
Initially, I tried placing an axis helper on top of a rotating cube and implemented a simple logic where the intersecting point provides the position for the small object placement and the face normal of the intersecting object gives the direction for the small object to look at. While this approach worked to some extent, it wasn't entirely effective.
After doing some calculations and researching code snippets for similar tasks, I eventually found success. However, I still don't fully comprehend the underlying logic behind why we perform these specific actions.
this.normalMatrix.getNormalMatrix(intersects[i].object.matrixWorld);
this.worldNormal.copy(intersects[i].face.normal).applyMatrix3(this.normalMatrix).normalize();
this.object.position.addVectors(intersects[i].point, this.worldNormal);
this.lookAtVec.addVectors(this.object.position,this.worldNormal.multiplyScalar(15));
this.object.lookAt(this.lookAtVec);
Another individual successfully created a wall and positioned a small object on top by modifying this line:
this.object.position.addVectors(intersects[i].point, this.worldNormal);
to
this.object.position.copy(intersects[i].point);
This adjustment worked for him, but unfortunately, the same modification did not yield the desired results with my axis helper.