mkkellogg / GaussianSplats3D

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

Questions about dynamically loading data #273

Open Linkersem opened 3 days ago

Linkersem commented 3 days ago

Hello, thank you for your excellent work, I have 5 ply data (A, B, C, D, E), I load three ply at once, when my camera moves to scene C, I want to be able to load the ply of scene D and delete the data of scene A, what should I do?

mkkellogg commented 3 days ago

You can use Viewer.removeSplatScene(<scene index>) , which returns a promise, to remove a splat scene and when that call completes you can load a different splat scene using Viewer.addSplatScene()

Linkersem commented 3 days ago

thx for your reply! i will try it and give a response.

Linkersem commented 2 days ago

Hi, @mkkellogg I tried what you said, he can delete the scene I don't need when rendering, but the whole page will turn black when deleting, is this normal? What should I do so that when I delete scene data, the entire page does not go black? For example, when I'm in scene C, I want to delete scene A, but it shouldn't affect what I'm looking at at scene C at that moment. Thx for your greate work!

Linkersem commented 2 days ago

And i also want to ask how to delete multiple scenes ?

mkkellogg commented 2 days ago

Well most likely you're still rendering while the scene removal or scene addition is in process. If you post your code I can help fix it, but you need to make sure not to render until the promises returned by Viewer.removeSplatScene(<scene index>) or Viewer.addSplatScene() complete.

As for deleting multiple scenes, there is not a great way to do that unfortunately. The only way is to make multiple calls to removeSplatScene() (one at a time of course).

mkkellogg commented 2 days ago

I will try to add a removeSplatScenes() function to the next release to remove multiple splat scenes at once.

Linkersem commented 2 days ago

Ohhh,thx for your reply! Regarding the black screen issue after deleting scenes, I may be able to provide some useful code snippets this week, regarding the case of deleting multiple scenes, I am calling this function multiple times now, looking forward to your update. But I have some confusion. For example, when I delete scene A, I do not delete scene C. So theoretically, scene C should still be rendering. Therefore, I do not understand your statement, "you're still rendering while the scene removal or scene addition is in process."

mkkellogg commented 2 days ago

Well Viewer.addSplatScene() actually works by removing all of the scenes, clearing out all of the viewer's resources, and then adding the scenes you want to keep back in. That's why you see black for a small amount of time if you keep rendering while that function is executing.

Linkersem commented 2 days ago

Hahaha, then what should I do to achieve the purpose I am talking about? Thank you again for your patient reply!

mkkellogg commented 1 day ago

Well during the call to removeSplatScene(), you need to make not to call the render() function of whatever three.js renderer you are using.

Here's an example of how it might work, where a function removeScene() could be called to remove a scene:

// main animation loop
let renderPause = false;
requestAnimationFrame(update);
function update() {
  requestAnimationFrame(update);
  if (!renderPause) {
    // renderer = three.js WebGLRenderer
    // threeScene is the three.js Scene instance
    renderer.render(threeScene, camera);
  }
}

const removeScene = () => {
  renderPause = true;
  viewer.removeSplatScene(0).then(() => {
    renderPause = false;
  });
);
lucylucy27 commented 20 hours ago

Hi All, I encountered the same black screen issue. It seems that the renderPause was not able to avoid this black screen problem. My code logic is:

  1. add blk0 and blk1, then stay at the position of blk0.
  2. After waiting for a mouse event, trigger the removal of blk1 and the addition of blk2, and set renderPause to true.
  3. After another 15 seconds, set renderPause to false. During this period, remain at the position of blk0. I noticed that the screen suddenly changed to black after a period of time(15s after loding blk2 finished in my experiment), and then gradually recovered to normal. It seems that this black screen is something that the upper-level code cannot avoid. It would mean so much if a solution could be found., the user experience will be much better. :)

Thx for your pacience!

lucylucy27 commented 20 hours ago

sample.txt

Here attached my sample.

mkkellogg commented 8 hours ago

Would you both be able to post your full source code for me to debug? @lucylucy27 The code you posted is incomplete and cannot be run.