I have a curve, along which at various points I need to place a cross beam (box geometry) whose up vector points in the direction of the curve’s tangent vector. As the camera moves, I need the cross beam to rotate around its up vector such that it always faces the camera, By this, I mean that the beam should remain oriented left to right on the screen (though on a diagonal as it must be perpendicular to the curve where it crosses it).
How it should look from the sides:
How it should look from above:
Here’s a fiddle containing a minimal working example: Quaternion hell - JSFiddle - Code Playground. Note that in my real application, there are many beams (implemented as an instanced mesh) that cross the curve at different points, so each beam has a different up vector it rotates around.
The challenge is essentially to calculate a rotation about the beam’s up axis based on the current rotation of the camera. This is where I’m getting stuck. I can manually add in a rotation to make the beam face the direction I want - as I have done so that it is oriented approximately correctly for the camera’s initial position (see Option 3 at end of the jsfiddle code), but I don’t know how to calculate this angle dynamically based on the rotation of the camera.
Note: this is similar to what I’m trying to achieve: InstancedMesh + implement billboard. The main difference is that I need the mesh that I’m billboarding to rotate around a Y axis that is tangent to a point on a curve rather than a Y axis that is vertical.
I’ve been stuck on this for quite some time now and I’ve hit the limits of my current skills. Any help would be greatly appreciated!






