Hello,
I have a project that is loading 3D molecules through the .pdb loader.
The 3D molecules are rotating through this line in the animate function:
requestAnimationFrame( animate );
controls.update();
const time = Date.now() * 0.0004;
root.rotation.x = time;
root.rotation.y = time * 0.7;
I would like the rotation to pause when the user clicks the mouse down. I have attempted to do that through this solution:
const isMouseDown = false;
const isMouseUP = true;
window.addEventListener('mousedown', onMouseDown);
window.addEventListener('mouseup', onMouseUp)
function onMouseDown(){
console.log("Mouse DOWN");
isMouseDown = true;
isMouseUP = false;
}
function onMouseUp(){
isMouseDown = false;
isMouseUP = true;
console.log("Mouse UP");
}
function animate() {
requestAnimationFrame( animate );
controls.update();
const time = Date.now() * 0.0004;
if(!isMouseUP){
root.rotation.x = time;
root.rotation.y = time * 0.7;
}
if(!isMouseDown){
root.rotation.x = time * 0;
root.rotation.y = time * 0;
}
render();
}
However, it doesn’t seem to be working. Any ideas anyone? Would really appreciate the help with this one.