There are a few ways to do that using babylon’s observables. The simplest way would be to add a new callback (with insertFirst set to true), and checking in this callback how often it is called. then set the state object to skip the next calls. Without testing too much, this is what I would do:
let lastCalled = new Date().getTime();
this.scene.onMeshImportedObservable.add((_, state) => {
let now = new Date().getTime();
if(now - lastCalled < 500 /* half a second */) {
// skip next calls
state.skipNextObservers = true;
} else {
lastCalled = now;
}
}, -1, true);
For example, I have a class to manages a grid! I don’t want to take care about upload the grid manually, for that reason, just I add the scene to the GridManager class, and everytime a new mesh is added or removed, I update the bounding box, … and the grid!
If add 100 meshes, it is updating any time, for that reason, I was thinking to add a Debounce, to manage that, only executes after 500 ms.
I’m trying to use the RaananW! I will keep informed!
By other hand, I love BabylonJS! And the community!! And you!!! … And the youtube channel too!!
I was trying your example, but I can not do it. I created a simple playground. I add 100 spheres, I need to know when is not adding more spheres after 500ms.