Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using external controls with useBuiltInControls: false. For example: FirstPersonControls #211

Closed
RigoTamas opened this issue Apr 22, 2024 · 2 comments

Comments

@RigoTamas
Copy link

Hi, I'm trying to use a different control than the built in OrbitControls. My code is something like this:

import { FirstPersonControls } from 'three/examples/jsm/controls/FirstPersonControls.js';

viewer = new GaussianSplats3D.Viewer({
  rootElement: rootElement,
  selfDrivenMode: true,
  useBuiltInControls: false,
  dynamicScene: true,
  sharedMemoryForWorkers: false,
});

viewer.controls = new FirstPersonControls(viewer.camera, viewer.renderer.domElement);

viewer
  .addSplatScenes(
    [
      {
        path: '/path-to-my-splat-file',
        splatAlphaRemovalThreshold: 10,
      },
    ],
    true
  )
  .then(() => {
    viewer.start();
  });

When I run this code, I see nothing but a black screen with no error messages in the console. Running the same code, but using the OrbitControls instead of the FirstPersonControls works however:

...
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';

viewer.controls = new OrbitControls(viewer.camera, viewer.renderer.domElement);
...

How can I any other control than OrbitControls?

@mkkellogg
Copy link
Owner

My first suggestion would not be to assign the controls to the controls property on the viewer object. Just make an external variable. Next, you need to be calling the update() function on the controls with a time delta parameter. Try something like:

let controls;
const clock = new THREE.Clock();
viewer.addSplatScene(path)
.then(() => {
    viewer.start();
    requestAnimationFrame(update);
    controls = new GaussianSplats3D.FirstPersonControls(viewer.camera, viewer.renderer.domElement);
});

function update() {
  requestAnimationFrame(update);
  const delta = clock.getDelta();
  controls.update(delta);
}

@RigoTamas
Copy link
Author

Thanks for the quick answer, it's working this way 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants