Textured floor planes appear mirrored/flipped every frame when animating camera.position with OrbitControls (polar angle locked)

SETUP

I’m building a multi-floor building viewer with Three.js (Vue 3 + TypeScript). Each floor is a PlaneGeometry with a 2D blueprint texture, rotated flat with plane.rotation.x = -Math.PI / 2, stacked 10 units apart on the Y axis. Each floor also has a transparent BoxGeometry volume, and sphere markers for devices placed using normalized coordinates (0..1, top-left origin).

OrbitControls is configured with the polar angle locked and all user interaction mostly disabled:

controls.enableDamping = false
controls.enablePan = false
controls.enableZoom = false
controls.minPolarAngle = Math.PI / 3
controls.maxPolarAngle = Math.PI / 3

I animate the camera programmatically with my own controller, using spherical to Cartesian conversion and then calling controls.update() every frame:

function applyState(state) {
  controls.target.set(state.target.x, state.target.y, state.target.z)

  const x = state.distance * Math.sin(state.elevation) * Math.sin(state.azimuth)
  const y = state.distance * Math.cos(state.elevation)
  const z = state.distance * Math.sin(state.elevation) * Math.cos(state.azimuth)

  camera.position.set(state.target.x + x, state.target.y + y, state.target.z + z)
  controls.update()
}

PROBLEM

While the camera animates, the floor plan looks like it keeps mirroring or rotating on every frame, and device markers appear to swap positions relative to the floor image. The effect shows up even when only elevation is animated and the other values are held constant.

  • The spherical to Cartesian math is the exact inverse of the read function, and Vector3.setFromSpherical(new Spherical(d, elevation, azimuth)) gives identical positions.
  • Switching the material from DoubleSide to FrontSide does not change the behavior, and the camera never goes below the planes.
  • Moving the rotation into the geometry (geometry.rotateX(-Math.PI / 2)) makes no difference.
  • Commenting out the camera.position.set(...) line makes the symptom disappear (the camera obviously doesn’t move then).

QUESTION

Is there a known issue with writing camera.position manually every frame while OrbitControls has a locked polar angle and controls.update() is called right after? What is the correct way to animate camera azimuth/elevation/distance around a target without the scene appearing to flip or rotate unexpectedly? Should I drive the camera through OrbitControls internals (Spherical, setPolarAngle/setAzimuthalAngle, or a tween on controls) instead of setting camera.position directly?

Live demo: https://heimdall-prototype.vercel.app/ (click the “Test Camera” button at the bottom right to run the programmatic camera animation and see the floor plans flip).

There are a few issues in your demo.

One is z-fighting between the textured floor planes.

Re the animation:

When you move the camera programatically.. you need to do it at a specific time during the animation loop… not based on a setInterval or setTimeout, since those can occur at arbitrary times during the frame.

You want to update your camera right before:
controls.update()
renderer.render( scene, camera);

let me know if you need more clarification.

Thanks for the advice. I fixed the z-fighting issue by adding a micro-offset (+0.01) to the plane positions. Quick question: is my render loop setup using requestAnimationFrame correct and optimal? (I’m using a single persistent renderer while swapping out the active scene dynamically).
const animate = () => {
animationFrame = requestAnimationFrame(animate)
controls.update()
if (currentScene) {
renderer.render(currentScene, camera)
}
}

Yeah that looks fine.

There is a better form for it though:

renderer.setAnimationLoop( ()=>{
    controls.update()
    currentScene && renderer.render(currentScene, camera)
})

This lets threejs manage the render loop which becomes important if you want to do VR/XR, so the threejs engine can call your render for each eye… but your form is fine if that’s not in the cards. (if you use this make sure you don’t include the requestAnimationFrame also, since that is what it’s wrapping.)

Thanks for the tip! Switching it to renderer.setAnimationLoop worked great and actually helped smooth out the timing for my programmatic movements. Plus, letting Three.js manage the loop makes disposal and cleanup much cleaner, avoiding any manual requestAnimationFrame overhead or potential memory leaks.

Really appreciate the insight!