huggingface / gsplat.js

JavaScript Gaussian Splatting library.
MIT License
1.26k stars 77 forks source link

Automatic Rotation = High CPU use? #101

Open nicholasvadasz opened 3 weeks ago

nicholasvadasz commented 3 weeks ago

Currently trying to implement automatic scene rotation in a react project.

My current approach is something like:

const loadAndRender = async () => {
  const url = "example.splat";
  await SPLAT.Loader.LoadAsync(url, scene, () => {});

  const animate = () => {
    for (let i = 0; i < scene.objects.length; i++) {
      scene.objects[i].rotation = <incremented_rotation>;
      scene.objects[i].update();
    }

    camera.update();
    renderer.render(scene, camera);
    requestAnimationFrame(animate);
  };

  animate();
};

loadAndRender();

But this seems to take an unyieldy amount of CPU. I imagine it would be more principled to use OrbitControls and increment the alpha/beta over time, but this doesn't seem to be a supported approach.

Is there a more standard way of doing this that I am not seeing? I found some old PRs/issues, but doesn't seem anything ever came of them.

TravisThomp commented 3 weeks ago

Don't call scene.objects[i].update();

The update function applies the rotation, position, and scale to each gaussian on the CPU, which is useful for if you need to export a model with these transformations applied. For live animations just remove that line and your CPU usage will decrease significantly.