I’ve got a Radeon RX 560 (reasonably modern) and am rendering the simple green cube from the main example docs along with stats.js and OrbitControls in up-to-date Chrome on Linux. The very simple full JS is at the bottom.
I’ve noticed something strange: When animate() is enabled, I can use the controls (rotate, zoom) and everything is silky smooth (triple-digit FPS). When I turn animate() off, my controls become very jumpy and the frame rate drops to single digits for a second or two when I do the same thing.
Why would this be the case? Any ideas?
(More generally, I’m investigating performance bottlenecks with a larger application and seeking to understand, more thoroughly, how all of this works and what I should reasonably expect.)
var scene;
var camera;
var renderer;
var controls;
var geometry;
var material;
var cube;
var stats;
var mouse;
function createStats() {
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = 'absolute';
stats.domElement.style.left = '0';
stats.domElement.style.top = '0';
return stats;
}
function render() {
renderer.render(scene, camera);
stats.update();
}
const animate = function() {
requestAnimationFrame(animate);
cube.rotation.x += 0.01;
cube.rotation.y += 0.01;
render();
};
function onMouseMove(event) {
mouse.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse.y = - (event.clientY / window.innerHeight) * 2 + 1;
render();
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
render();
}
$(document).ready(function() {
mouse = new THREE.Vector2();
renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera(75, window.innerWidth
/ window.innerHeight, 0.1, 1000);
controls = new THREE.OrbitControls(camera, renderer.domElement);
controls.update();
geometry = new THREE.BoxGeometry();
material = new THREE.MeshBasicMaterial({ color: 0x00ff00 });
cube = new THREE.Mesh(geometry, material);
scene.add(cube);
camera.position.z = 5;
stats = createStats();
document.body.appendChild(stats.domElement);
render();
window.addEventListener('resize', onWindowResize, false);
window.addEventListener('mousemove', onMouseMove, false);
// animate();
});