Based on your code, it seems like you are exporting your lightmap correctly from Blender. The only thing I can think of is that the UVs for your lightmap are not wrapping correctly. To check this, you can try enabling UV visualization in Blender. If you see that the UVs for your lightmap are not wrapping around the model correctly, then you will need to adjust them.
Another possibility is that your lightmap is not loading correctly in three.js. To check this, you can try printing the lightmap to the console. If you see that the lightmap is not loaded correctly, then you can try reloading it or using a different loader.
Here is an example of how to print the lightmap to the console:
const loaderTexture = new THREE.TextureLoader();
const lightmapT = loaderTexture.load("3d/textures2/bakedtx.png");
loaderT.load("3d/test 2.glb", function (gltf) {
scene.add(gltf.scene);
gltf.scene.scale.set(1, 1, 1);
gltf.scene.traverse(function (child) {
console.log(child.name, "test");
if (child.material) {
child.material.lightMap = lightmapT;
child.material.lightMapIntensity = 2;
// Print the lightmap to the console
console.log(child.material.lightMap);
}
});
});
If you are still having trouble getting your lightmap to work, then you can try posting a question on the three.js forum.
Example
Here is an example of how to enable UV visualization in Blender:
- Go to the Window menu and select Toggle System Console .
- In the system console, type the following command and press Enter:
bpy.ops.object.editmode_toggle() bpy.ops.uv.view_show()
- You should now see the UVs for your model in the viewport.
To check if the UVs for your lightmap are wrapping correctly, select the lightmap texture in the UV Editor and look at the UVs. The UVs should wrap around the model without any gaps or overlaps.
If the UVs for your lightmap are not wrapping correctly, you can adjust them by dragging them around in the UV Editor . You can also use the following tools to help you adjust the UVs:
- Unwrap: This tool unwraps the UVs for your model and spreads them out onto a flat plane.
- Project From View: This tool projects the UVs for your model from the current viewport view.
- Scale: This tool scales the UVs for your model.
- Rotate: This tool rotates the UVs for your model.
Once you are satisfied with the UVs for your lightmap, you can exit edit mode and save your fil