Override Material in gltf loader


I am writing my own standard shader for my gltf meshes and I want to be able to apply the shader during mesh load instead of the PBRMaterial normally used by the glTF loader.

I found this snippet inside the glTF loader for babylon:

GLTFLoader.prototype._createDefaultMaterial = function (name, babylonDrawMode) {
    var babylonMaterial = new PBRMaterial(name, this._babylonScene);
    babylonMaterial.sideOrientation = this._babylonScene.useRightHandedSystem ? Material.CounterClockWiseSideOrientation : Material.ClockWiseSideOrientation;
    babylonMaterial.fillMode = babylonDrawMode;
    babylonMaterial.enableSpecularAntiAliasing = true;
    babylonMaterial.useRadianceOverAlpha = !this._parent.transparencyAsCoverage;
    babylonMaterial.useSpecularOverAlpha = !this._parent.transparencyAsCoverage;
    babylonMaterial.transparencyMode = PBRMaterial.PBRMATERIAL_OPAQUE;
    babylonMaterial.metallic = 1;
    babylonMaterial.roughness = 1;
    return babylonMaterial;

This is a perfect point since all I need to do is override that method with something that reads the gltf material and then builds my material instead of the normal PBRMaterial.
However, I can’t figure out how to override this method after creating a GLTF file loader. Right now my code to do this looks like this:

let loader = new GLTFFileLoader();
/* Somehow override the material creation? */

If someone has some advice on how I can do this please let me know!


completely untested but did you try something like:

loader.prototype._createDefaultMaterial = ...

Hey, you can use maybe onMaterialLoaded function
but this means you let the loader to create the materials as it want, and you change or replace it after creation.
Or you can create your custom extension.
Second option I think is what are you looking for. Cheers!:beers: