Search code examples
three.jsaframelightgltf

Aframe Load lightmap after loading GLTF - lightmap not showing


I'm trying to add a lightmap to some mesh after loading them from a GLTF file. All my objects have 2UV channel.

I'm waiting 'object3dset' and here is my code :

    const mesh = this.el.getObject3D('mesh');
    var textureLoader = new THREE.TextureLoader();

    textureLoader.load("lightmap.png", function(lmap){

        mesh.traverse((node) => {

            if (!node.isMesh) return;

            node.material.lightMap = lmap;
            lmap.flipY = node.material.map.flipY; //needed to flip the texture

            node.material.needsUpdate = true;

          });
    });

If I replace the material with a new one and set the lightmap, it's working. But I want to find a way without recreating all materials.


Solution

  • The lightmap was loaded, but not easy to see. By default metalness from Khronos Blender Exporter converted in threejs after loading GLTF result to a level 1.0. With this configuration, the lightmap is hard to see and is not corresponding to what we see in Blender.

    I hope my mistake can help someone else losing too much time.