Hi
I want to rotate my model but because of some axes problems(I have 3d model and some other decal geometries in my scene). I decided to rotate the orbit and it worked better.
Now I need help in stopping orbitcontrol rotation.
I called this function in 3 place sometimes I send true and sometimes false.But When first time is true animate will be in unstoppable loop and just rotate unlimited even I try to stop it it did not work.
function rotateModel(model, rotationComplete) {
const rotationSpeed = 0.006; // Adjust rotation speed as needed
let isRotating = false; // Global state to track if rotation is ongoing
let animationId = null;
function animate(time) {
if (isRotating) {
console.log('rotatemodel animate');
controls.current.autoRotate = true;
controls.current.autoRotateSpeed = 1;
controls.current.update();
} else {
controls.current.autoRotate = false;
}
renderer.current.render(scene.current, camera.current);
}
if (rotationComplete) {
if (!isRotating) {
isRotating = true; // Set the rotation state to true
renderer.current.setAnimationLoop(animate); // Start the animation loop
}
} else {
if (isRotating) {
isRotating = false; // Set the rotation state to false to stop the animation
renderer.current.setAnimationLoop(null); // Stop the animation loop
}
}
}