Adding full support for custom materials to GltfLoader
After fixing two more bugs with the old implementation, I decided to create a pull request.
github.com/jMonkeyEngine/jmonkeyengine
Adding full support for custom materials to GltfLoader (#2725)
master ← theMinka:theMinka_Custom-material-support-in-GltfLoader
opened 09:05AM - 28 Apr 26 UTC
theMinka
+810 -12
Reworked the material creation process in GltfLoader, to allow for custom mate…rials to be created. ### Supporting a custom material definition To support a new material definition, one simply needs to implement a new GltfMaterialFactory and register it with the GltfLoader. It is important to consider the overall order of all registered material factories, because only the first factory that accepts a given material data instance will be used. By default, there are already two material factories: one for the PBRLighting material and one for the Unshaded material. One special use case would be when someone creates a copy of the standard PBRLighting material to add additional functionality. If none of the original material parameters have been changed (adding new ones is not a problem), one can simply extend PBRLightingMaterialFactory and modify the material definition path returned by the getMaterialDefPath() method. Finally, the original PBRLightingMaterialFactory just needs to be replaced in the GltfLoader with the custom one. This way, all loaded models will use the extended PBRLighting material. ### Backward compatibility As mentioned earlier, my new system is not backward compatible with regard to custom MaterialAdapters. Therefore, I have kept the old implementation but disabled it. To reactivate it, a specific flag must be set in the GltfModelKey. This will fully switch back to the old material creation process when loading the corresponding 3D model. However, I believe that keeping the old MaterialAdapter system in the engine is not a good long-term solution. I suggest removing it in one or two future releases. To reflect this, I have already marked most classes, methods, and fields related to the old process as deprecated. Forum discussion: https://hub.jmonkeyengine.org/t/adding-full-support-for-custom-materials-to-gltfloader/49444 Also fixed some related bugs: * CustomContentManager can now handle multiple GLTF extensions per element * Wrong material parameter was set on unlit materials with vertex colors (UseVertexColor instead of VertexColor) * Materials using BlendMode.AlphaAdditive are now added to QueueBucket.Transparent
Discussion in the ATmosphere