* The Reoriented Normal Mapping method is used to blend normals.
* Details of the algorithm can be found here: https://blog.selfshadow.com/publications/blending-in-detail/
*/
public static readonly MATERIAL_NORMALBLENDMETHOD_RNM = 1;
/**
* Event observable which raises global events common to all materials (like MaterialPluginEvent.Created)
*/
public static OnEventObservable = new Observable<Material>();
static {
EngineStore.OnEnginesDisposedObservable.addOnce(() => {
Material.OnEventObservable.clear();
});
}
/**
* Custom callback helping to override the default shader used in the material.
*/
public customShaderNameResolve: (
shaderName: string,
OnEventObserver added in function RegisterMaterialPlugin
is cleared in these lines so when I open an engine after disposing another engine, material plugins are not able to register.
That’s expected, as there are no more active engines, some cleanups are performed.
A workaround is to create the new engine before releasing the existing one. That way, this code won’t trigger in the dispose method:
};
}
}
/**
* Type for plugin material factories.
*/
export type PluginMaterialFactory = (material: Material) => Nullable<MaterialPluginBase>;
const plugins: Array<[string, PluginMaterialFactory]> = [];
let inited = false;
let observer: Nullable<Observer<Material>> = null;
/**
* Registers a new material plugin through a factory, or updates it. This makes the plugin available to all materials instantiated after its registration.
* @param pluginName The plugin name
* @param factory The factory function which allows to create the plugin
*/
// eslint-disable-next-line @typescript-eslint/naming-convention
export function RegisterMaterialPlugin(pluginName: string, factory: PluginMaterialFactory): void {
if (!inited) {
As far as I am concerned, inited
here should be set to false again when all engines disposed? So I can register material plugins again when opening the second engine. It is really strange for me that I have to keep an engine all the time to keep the plugins.
I think this one is a bug, here’s the fix:
BabylonJS:master
← Popov72:fix-materialplugin-dispose
opened 11:28AM - 16 May 23 UTC
See https://forum.babylonjs.com/t/material-oneventobservable-clear-cause-materia… l-plugins-not-work/40838/3
2 Likes