Need some observables to listen Scene/AbstractMesh/Material objects creation event

Our team write a mixin library to improve and extend babylon builtin Class functions, such as Scene/AbstractMesh/Material, because wirting extension for builtin Class used XXX.prototype is so tedius.

the mixin is used as follows:

RegisterMixin(AbstractMesh, class extends AbstractMesh {
     private _castShadow = false;
     public get castShadow() {
          return this._castShadow;
     public set castShadow(v: boolean) {
          this._castShadow = v;
          // xxxx

But, the implementation of mixin library need to observe builtin type object creation, to copy property descriptors.

Now, we are using apis Engine.onNewSceneAddedObservable, Scene.onNewMeshAddedObservable, Material.OnEventObservable to achieve the goal. But these apis are not perfect:

Engine.onNewSceneAddedObservable can not be used observing non-virtual scene creation, so we hacked engine._virtualScenes to listen the calling of engine._virtualScenes.push.

Scene.onNewMeshAddedObservable can not be used observing abstract mesh creation when importing gltf file, because babylon need to create and collect all entities from gltf first, and then add them into current scene.

Material.OnEventObservable is closed to perfect, but only emit one event MaterialPluginEvent.Created. Name of th event is not perfect.

So, we want some perfect observables to exactly observe Scene/AbstractMesh/Material objects creation, like Material.OnEventObservable, but has more appropriate event name.

for example

Scene.OnEventObservable.add(() =>, Scene.Created);

AbstractMesh.OnEventObservable.add(() =>, AbstractMesh.Created);

Material.OnEventObservable.add(() =>, Material.Created);

It would be nice if there were other observables to notify other type objects creation, such as PBRMaterial, Mesh, InstancedMesh.

1 Like

As long as there is no performance degradation, we are fine with adding observables to the scene or any other class!

We are on course to release 7.0, so merging such a feature won’t happen very soon, but if you want to submit a PR as a suggestion for what you mean, we will be happy to review it! Otherwise, feel free to add an issue to the core github repository, and we will review it and see when we decide to implement it.

1 Like

@RaananW hey,the issue is here, but it is closed, could you reopen it.

1 Like