mkkellogg / GaussianSplats3D

Three.js-based implementation of 3D Gaussian splatting
MIT License
1.09k stars 134 forks source link

How to set camera rotation ? #261

Closed ericn0ra closed 3 days ago

ericn0ra commented 1 week ago

Hello,

I would like to be able to manipulate the rotation of the camera (from my own scenes).

I first started by completing the onKeyDown function in Viewer.js, adding a key to reset the camera rotation to (0,0,0,1):

case 'KeyR':
      if (this.camera) 
          {
              this.camera.quaternion.set(0, 0, 0, 1);
          }
      break;

But it doesn't work (I modified the code to display the rotation on InfoPanel, but the rotation coordinates do not change at all). I don’t know how to proceed, as I am not very familiar with Three.js.

Is there a way for the user to access to these coordinates ?

Thank you in advance.

mkkellogg commented 1 week ago

Setting the camera's orientation can be tricky because the camera is controlled by an instance of OrbitControls. You can't just directly modify the camera's quaternion property because that will get overwritten by the controls. What you can do is change the camera's lookAt on the camera and in the controls:

 this.camera.lookAt(newTarget);
 this.controls.target.copy(newTarget);

Where newTarget is a three.js Vector3 representing the 3D point you want the camera to face. If you want, you can change the camera's up vector to alter the camera's orbital plane:

 this.camera.up.set(0, 0, 1);
 this.camera.lookAt(newTarget);
 this.controls.target.copy(newTarget);
ericn0ra commented 3 days ago

I was able to solve my problem thanks to the .copy method, thank you very much for your response ! And thank you for your great work with this project!

mkkellogg commented 3 days ago

Glad that fixed it for you!