I want to make the mesh representing the height of the model to always face the camera whenever user rotates the model.
I have tried using mesh.lookAt(camera.position);
the mesh is facing the camera but somehow the mesh is rotated along x axis.
const step = 2 * delta;
rotationMatrix.lookAt(camera.position, widthMesh.position, widthMesh.up);
targetQuaternion.setFromRotationMatrix(rotationMatrix);
widthMesh.quaternion.rotateTowards(targetQuaternion, step);
I have also tried this. But getting the same result
Be sure no rotation is applied to the mesh besides it looking at the same - otherwise you’ll be multiplying the rotations and see weird effects.
Put the Mesh inside a Group. Add said Group to the Scene.
Apply any transforms to the Mesh directly (except the .lookAt camera.)
Make Group .lookAt camera on every frame.
1 Like
@mjurczyk I have grouped the meshes and applied lookAt to the group. Now the mesh is not at all visible.
The following demo might help (or not), depending on the structure of your model and labels:
https://codepen.io/boytchev/pen/abQKpLX
The full discussion is here:
I create points based on the fibonacci sphere, then using TextGeometry I create a virtual sphere from the resulting positions.How i can rotate this virtual sphere with no effect on text nodes?
function fibonacciSphere(numPoints, point) {
const rnd = 1;
const offset = 2 / numPoints;
const increment = Math.PI * (3 - Math.sqrt(5));
const y = point * offset - 1 + offset / 2;
const r = Math.sqrt(1 - Math.pow(y, 2));
const phi = ((point + rnd) % numPoints) * increment;
const x = Math…
@PavelBoytchev for some reason the mesh is moving from it’s actual place.
https://codesandbox.io/p/sandbox/three-js-load-models-forked-zmjsx7?file=%2Fsrc%2Findex.js
This is the sandbox. I am new to three js. Can you please take a look?.
I want to make the meshes with names Width, Height and Depth always look at the camera.
FYI: The sandbox does not show up well on my machine (there is an error message with the GLTF, the machine becomes unresponsive).
Could make some minimal demo that shows the issue with the meshes? A demo without all unrelated stuff (like GLTF animations).
What is the final state of your issue? If the meshes look towards the camera, but do not keep their positions, a possible reason might be their coordinates. Rotation happens in respect to the local (0,0,0) of the mesh. If the origin of the mesh is in its center, it will rotate well. If it is somewhere far away, the mesh will move.
In the following illustration the blue dot is the origin (0,0,0) of the label.
After applying
group.add(object)
the is moving upward from it’s actual position.