GLB Texture Tools - Lightmapping, Batch Image Scale, Quick Export

Just checked console in blender.
There are many errors like this:

location: :-1
Python: Traceback (most recent call last):
File “C:\Users\Andrey\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\GLBTextureTools\Panels\panel.py”, line 77, in draw
box.prop(scene.world.node_tree.nodes[“Background”].inputs[1],‘default_value’,text=“World Influence”)
KeyError: ‘bpy_prop_collection[key]: key “Background” not found’

location: :-1
Python: Traceback (most recent call last):
File “C:\Users\Andrey\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\GLBTextureTools\Panels\panel.py”, line 77, in draw
box.prop(scene.world.node_tree.nodes[“Background”].inputs[1],‘default_value’,text=“World Influence”)
KeyError: ‘bpy_prop_collection[key]: key “Background” not found’

location: :-1
Python: Traceback (most recent call last):
File “C:\Users\Andrey\AppData\Roaming\Blender Foundation\Blender\2.93\scripts\addons\GLBTextureTools\Panels\panel.py”, line 77, in draw
box.prop(scene.world.node_tree.nodes[“Background”].inputs[1],‘default_value’,text=“World Influence”)
KeyError: ‘bpy_prop_collection[key]: key “Background” not found’

location: :-1

Do you have a world in your Scene? Could open up the node editor / Shader editor and where it says, object select world. If there is none create a new one but there should be a default world when blender starts

Maybe you could try to delete the Addons in the app data / blender folder and reinstall it.

Btw. Why don’t you install via console and not within the preferences?

Yes, I reinstalled addon via Preferences → Addons yesterday. Result is the same.
Will try to check for World. I’m novice to Blender. Just wanted to convert one existing blender scene to GLB…

Are you sure the problem is in world node ?
box.prop(scene.world.node_tree.nodes[“Background”].inputs[1],‘default_value’,text=“World Influence”)
KeyError: ‘bpy_prop_collection[key]: key “Background” not found’

It doesn’t say world is undeclared. It says Background key is not existing.
What should I modify in my scene to add this node ?

Normally every default world has a background node.

Ok, I added Background node in shader nodes editor. And now Lightmap dialog is properly presented.
But it looks kinda strange, because this node is not connected to anything ))

The whole idea behind that is that you can control how much influence the light of the world has to the baking process. Also when you want to save lightmaps to glb, it’s not natively supported. I use a little workaround to save it to emission and later move it to the Lightmap channel in three js. Where do you want to use your glb file? Maybe if you wan’t we can have a quick zoom call today.

Nice house by the way.

I made this once :

I modified world shader node by adding Background to the end of graph like on your screen.
Thank you very much for your help.
Very appreciated!

P.S. The house was modelled not by me )) I bought it at CGTrade.
But it is nice. Agree. Has animated doors / windows, furnished, and lot of details.

Checked your house. Really well done!
Great work!

Maybe you want to try our free online presentation tool, that’s where I made the other house demo, and lightmaps are handled well.

I have a question about AO baking. It has R and G channels variations inside the texture. B channel seems always 1.
Is R + G somehow represent bent normal ? Or someting different ?

Another strange thing. When I baked PBR + AO + Lightmap, then AO and metallic-Roughness are bound to the same slot in GLB. So no separate roughness-map anymore.

Do you mean in Blender after baking? My images have the same values in all channels but it might be different inside the GLB because the GLTF Exporter joins Roughness, Metallic and AO in a combined image to save space:

GlTF stores occlusion in the red (R) channel, allowing it to optionally share the same image with the roughness and metallic channels.

You might wanna have a look here: https://docs.blender.org/manual/en/2.80/addons/io_scene_gltf2.html

Unfortunately I was not able to generate lightmap for my scene in 2 days.
There are many objects in the scene. So I splitted them by lightmap groups.

When I generate first group - some objects become black. So Lightmap generation for some reason produces black pixels, though the objects are bright in outdoor area.
Then I try to regenerate lightmap for this wrong objects (giving different lightmap name). After regeneration it becomes even worse. Selected objects lightmap is not fixed and additionally It affects also objects which wasn’t selected. They become partially black as well. Result is absolutely unpredictable. i don’t know which objects wil lbe properly generated which will be broken after I press “Bake Textures” button. I tried GPU and CPU generation - the same result. Experimenting is very time consuming because one bake iteration takes several hours.

Those wooden planks. LM Gen 100% always produces wrong black pixels.
Do you have any idea why?

Really looks like it uses wrong uv coordinates for LM on planks.
Just checked… this planks use 3 geometry modifiers. maybe this is related…
One more thing: Array modifier is the reason. there are lot of objects in scene with array geometry modifiers. In this objects only first piece of geometry in array showed right. Other pieces have texture coordinate problems.
Update: Found one workaround - convert to mesh which prebakes modifiers.
But this seems like very buggy in Blender. So have to do for each object manually.

Another problem - on couch pillows. There are blocky LM artefacts. Like it uses face normals instead of smooth vertex normals.

Ok so array modifiers are problematic because they don’t have unwrapped UV’s until you apply the modifier, as you figured. But you can select multiple objects and press alt+C to apply the modifiers of all selected objects. But make a copy of the objects before you do that. I have a script that generates instances out of arrays after you apply the modifiers to optimize performance but that won’t work for Lightmaps because each instance will receive a different lighting and therefore needs a unique UV.

When it comes to the artefact try disabling Denoiser and bake again. I also recommend just baking with a low sample count to get a preview. Also up the bake margin because your UV’s are to close and pixels might be overridden. The unwrap I use by default is smart uv but there are way better unwraps like xatlas and ways to pack the ( UV packmaster) to get the most texture space. If you’re doing this in a professional way you could also have a look at instalod or simplygone but they can get really expensive.

For the pillows and couch I would need to see them to really know what’s the problem. Is there a sub division surface modifier? Are there custom normals, is auto smooth turned on or is there an edge split modifier?

As I said we could have a look at it together but baking Lightmaps is not a one-click thing and usually you would need to optimise your scene first for web, like you do for a game Engine.

Modifiers can be work-arounded by prebaking them. It works quite well using several steps.
But biggest problem of the Lightmap Generatpr - is supporting of shared meshes.
Not sure why it shares meshes if they have differend unwrapped second UV set?
You remember I said that generating additional LM atlas breakes objects which wasn’t selected (wasn’t included in current LM atlas)?
Now I realized. This happens because it doesn’t try to unshare instances of the same mesh.
My scene contains huge number of instances of the same mesh. When I generate LM atlas those instances can be even in different atlases. But since they not unsharing based on second UV after generating - atlasses and LM in general - just messed up.

Look at this screeen. Objects marked in red - assigned LM1 lightmap. But they became black after I generated LM2 for different object sets.
Also look at couch. They are mirrored. But LM on them are absolutely similar. Because different instances of couch have the same shared mesh.

Just found how to unshare mesh manually. When i select active mesh - it shows how many users this mesh has. Here I can press the button which copies and creates single user mesh.
But as I said the scene contains huge number of instances. I need kind of batch process to unshare all meshes in the scene if LM generator not doing this automatically during mapping second UV set to the atlas…

press U. to unlink the selection’s datas.
image

@LdelMar : really handy addon.