i have clothe object where user can rotation the cloth, i am using orbit control to rotation the object here, and the interface, user can change the color of clothe, there is a button to see the back of clothe, so i want to make sure when user click it it gonna show the back on cloth
here is how i animate is with anime js
this is how i init 3D and call function doSmething
for show the back of cloth object
let _scene;
let _camera;
let _control;
function init3D() {
_scene = new THREE.Scene();
_camera = new THREE.PerspectiveCamera(75, container.value.clientWidth / container.value.clientHeight, 0.1, 1000);
_control = new OrbitControls(_camera, container.value);
}
init3D()
function doSometing() {
gltfloader.load(
url,
(gltfModelOnLoad) => {
_scene.add(gltfModelOnLoad.scene);
anime({
targets: _scene.rotation,
y: _scene.rotation.y - Math.PI,
duration: 2000,
easing: 'easeInOutQuad',
update: () => {
renderSceneAndCamera();
}
});
},
undefined,
undefined
)}
}
const renderSceneAndCamera = () => {
_renderer.render(_scene, _camera);
}
anime({
targets: _scene.rotation,
y: _scene.rotation.y - Math.PI,
duration: 2000,
easing: 'easeInOutQuad',
update: () => {
renderSceneAndCamera();
}
});
when i do this _scene.rotation.y - Math.PI
it is not always rotation the back of clothe, also when i am on position 180 degree already, the scene becomes rotation the front of cloth ,
is that any way to make always the object rotation 180 degree what ever the rotation y changed ?
2
Answers
You should rotate the camera instead of the model. First, get the position of the camera after it rotates to the back of the clothes, save it to a constant, and then use anime to transition the camera position when you need to rotate to the back of the clothes.
In general, the solution to this problem is not as simple as it may seem… Interfering with the
camera
with the transformations that @rookie proposes will cause a 180 degree rotation every time, not respecting the user’s input viaOrbitControls
. The solution below is not perfect but it may give you the direction of the output. I assume that the red face of the cube is the front of the shirt. I transformed thecamera
position tospherical
coordinates by blocking the x-axis, because as I understood from your question, you will simply rotate the shirt, something like a 3D gallery, so activating the entire transformation is probably not the best approach. As for the animation itself, always showing the front of the shirt, you can use a quaternion, which will rotate the shirt so that its front (which by default is directed towards the Z axis, example(0, 0, 1)
) points towards thecamera
.