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

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

Open
Starryi opened this issue Mar 24, 2024 · 4 comments
Assignees
Milestone

Comments

@Starryi
Copy link
Contributor

Starryi commented Mar 24, 2024

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.

@thomlucc
Copy link
Member

@Starryi - Let's discuss on the Forum first, please.

@Starryi
Copy link
Contributor Author

Starryi commented Mar 27, 2024

@RaananW RaananW reopened this Mar 27, 2024
Copy link

This issue has been automatically staled because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added the stale label Apr 25, 2024
@bghgary bghgary added enhancement and removed stale labels Apr 29, 2024
@bghgary bghgary added this to the 8.0 milestone Apr 29, 2024
Copy link

This issue has been automatically staled because it has been inactive for more than 14 days. Please update to "unstale".

@github-actions github-actions bot added the stale label May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants