{
"$type": "site.standard.document",
"bskyPostRef": {
"cid": "bafyreieo63saw3anjytrjhdfnwadkspgvdgqbsa3mmkvsm5biucvcexbki",
"uri": "at://did:plc:dxjzgxe7cvirxkwfjr2tjspt/app.bsky.feed.post/3mkkes4any6i2"
},
"path": "/t/adding-full-support-for-custom-materials-to-gltfloader/49444#post_7",
"publishedAt": "2026-04-28T09:07:59.000Z",
"site": "https://hub.jmonkeyengine.org",
"tags": [
"github.com/jMonkeyEngine/jmonkeyengine",
"Adding full support for custom materials to GltfLoader (#2725)",
"theMinka",
"+810\n-12",
"…"
],
"textContent": "After fixing two more bugs with the old implementation, I decided to create a pull request.\n\ngithub.com/jMonkeyEngine/jmonkeyengine\n\n#### Adding full support for custom materials to GltfLoader (#2725)\n\n`master` ← `theMinka:theMinka_Custom-material-support-in-GltfLoader`\n\nopened 09:05AM - 28 Apr 26 UTC\n\n\n\n theMinka\n \n\n\n+810\n-12\n\n\nReworked 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`",
"title": "Adding full support for custom materials to GltfLoader"
}