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
.