GLTF Extensions

Hi, I don’t have a playground set up yet, but I’m having trouble understanding how the extensions work when applying materials. Let’s say in my GLTF file I add a custom extension, call it “FOO”,

    "extensions": [
        "FOO" : {
              "emissiveColor": [1, 0, 0]
         }
    ]

and I apply that extension to a material in the materials array of the GLTF. Then I register my extension reader in Babylon. I’m trying to turn the emissive color red.

Questions:

  1. Should it pick up only those material nodes (not automatically change the color, but only return those material nodes with that extension)?
  2. In the material loader handler (as per this article) I see the GLTF material and the Babylon material, but even if I change properties to the Babylon material, such as babylonMaterial.albedoColor = Color3(1, 0, 0) it doesn’t display. Is this because those properties are being set by Babylon AFTER my extension runs?
1 Like

Pinging @bghgary

It depends on which method you are overriding. If you are overriding loadMaterialPropertiesAsync as in the article, returning anything other than null will override the default behavior. If you want the default behavior but add / change something afterwards, you can call the default behavior on the loader (i.e. loader.loadMaterialPropertiesAsync).

Like this: https://www.babylonjs-playground.com/#20XT9A#7

If you only want to override the behavior when an extension is present, you can check for the existence of the extension and return null if it’s not present. You can also use loadExtensionAsync to help if you want.

It’s hard to tell what you are doing without a playground, but perhaps you are not setting the color correctly? babylonMaterial.albedoColor = new BABYLON.Color3(1, 0, 0)

Thanks, I think the thing I was doing wrong was returning a value instead of null. I’m looking at one of the KHR extensions and it’s making more sense. Thanks!

1 Like