For quite some time, I've had an issue in three.js where when putting any HTML element updates in my animation loop, my PointerLockControls always have a strange stutter. For example:
function animate() {
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
Works completely normal. PointerLockControls feel smooth, responsive, and my framerate is normal.
But if I do this:
function animate() {
document.querySelector("#some-element").textContent = "foobar";
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
Suddenly, the PointerLockControls have a strange stutter effect, whereas if I point my cursor up slowly, the controls are stuck, but if I point my cursor up slightly faster, the controls completely jerk to the top of the screen.
Strangely enough, the framerate is not affected by this. It is just the PointerLockControls, nothing else.
Why does this issue happen, and how can I fix it? Also, I need to constantly update the element's textContent, so "updating it only when I need to" doesn't work.