2

I'm using this for a 360 image and I need the camera to stay fixed at (0,0,0)

If I update the camera position the controls stop working.

I've seen this post https://codeworkshop.dev/blog/2020-04-03-adding-orbit-controls-to-react-three-fiber/ which kind of has a fix but seems out of date, the extend functionality doesn't make orbitControls available.

I've tried various combinations of

  const onChange = () => {
    camera.position.set(0, 0, 0);
    ref.current.update();
  };

Or

  useEffect(() => {
    if (ref.current && scene.projection === SceneProjection['3603D']) {
      camera.position.set(0, 0, 0);
      ref.current.update();
    }
  }, [ref, scene]);

Is there a simple way to lock the camera position with OrbitControls and just rotate the camera?

beek
  • 3,522
  • 8
  • 33
  • 86
  • 1
    I think you might be able to set .maxDistance to 0. That way it only rotates around its origin. https://threejs.org/docs/index.html?#examples/en/controls/OrbitControls.maxDistance – M - Apr 28 '22 at 00:18
  • Great answer thanks. Setting it to 0 breaks the OrbitControls but setting to 0.1 works great. Thank you! – beek Apr 28 '22 at 01:19
  • @Marquizzo if you make that an answer I'll mark it correct – beek Apr 28 '22 at 01:20

1 Answers1

1

I think you might be able to set controls.maxDistance to something really small, like 0.01. That way it only rotates around its origin by an imperceptible amount.

You can read more about the .maxDistance attribute in the docs](https://threejs.org/docs/index.html?#examples/en/controls/OrbitControls.maxDistance)

M -
  • 26,908
  • 11
  • 49
  • 81