Version: git master (d4c5968)
Engine: WebGL2
Background:
I’m making a material plugin and do not want it to be serialized, since it is designed to be attached at runtime by code.
In Material#_serializePlugins
, which is called every time a material being serialized, it just serialize every plugin in _plugins
.
Proposal:
Add a public doNotSerialize
to MaterialPluginBase
, and skip serialization when it’s true. Existing material plugins would implicitly have this field as they extends MaterialPluginBase
.
protected _serializePlugins(serializationObject: any) {
serializationObject.plugins = {};
if (this.pluginManager) {
for (const plugin of this.pluginManager._plugins) {
if (!plugin.doNotSerialize) // the proposed change
serializationObject.plugins[plugin.getClassName()] = plugin.serialize();
}
}
}
Risks:
Material plugins that does not extend MaterialPluginBase
will not have a doNotSerialize
after this, but when using if to check, it would have the same result as false
, which should be the default value, so backward compatibility for js projects would not be broken after this.
In typescript projects, type checking ensures that plugins extending MaterialPluginBase
.
Alternatives
Users can iterate the serialized json for material plugin and remove what they do not want, but it’s complex to do that.
Js users can patch Material#_serializePlugins
in prototype and make the change without upstreaming it.