Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function rotate($solid: Solid, animate = true, speed = 1) {
// TODO Damping after mouse movement
// TODO Better mouse-to-point mapping
// Only Chrome is fast enough to support auto-rotation.
const autoRotate = animate && Browser.isChrome && !Browser.isMobile;
let dragging = false;
let visible = false;
function frame() {
if (visible && autoRotate) requestAnimationFrame(frame);
$solid.scene.draw();
if (!dragging) $solid.object.rotation.y += speed * 0.012;
}
if (autoRotate) {
$solid.scene.$canvas.on('enterViewport', () => { visible = true; frame(); });
$solid.scene.$canvas.on('exitViewport', () => { visible = false; });
} else {
setTimeout(frame);
}