Operator to automatically bake lightmaps for selected objects.#281
Operator to automatically bake lightmaps for selected objects.#281GottfriedHofmann wants to merge 45 commits intoHubs-Foundation:masterfrom
Conversation
Exairnous
left a comment
There was a problem hiding this comment.
Thank you for the PR and apologies for the delay in reviewing it. I think it will provide some good functionality, but I think it's scope should be modified slightly. I think your PR is great for baking light maps for objects that don't have them yet, but your PR doesn't address all the intricacies that can arise when attempting to rebake already set up light maps. PR #48 does this very well and has a lot of error checking already in place, so I'm thinking it makes the more sense to have your PR to bake an initial light map for objects and let the other PR handle any rebaking.
With that in mind, I'm thinking that a check should be added to this PR to avoid baking light maps when they are already present on an object.
PR #48 also adds a panel in the render settings, so I'm thinking that maybe it would be better to add the operator there once that's in, rather than to a new panel in the object properties.
I believe calling bake via execute instead of invoke causes the UI to block with no feedback to the user. I think it would be better to use the non-blocking version and reset all the settings after the bake has completed via a handler (like what is done with reflection probes). The overridden settings can be stored and restored as with reflection probes in reflection_probe.py lines 362-379 and lines 334-337
bpy.app.handlers.object_bake_complete is probably the needed handler.
At some point in the Blender 4 series linear was separated out into a bunch of different versions, Linear Rec.709 is what we have used when importing HDRs and seems to be the new default. This code should make it work for all Blender versions Co-authored-by: Exairnous <mythologylover75@gmail.com>
…y the auto baker.
|
I have created this addon with PR #48 in mind. |
…g, uses the space better for multiple objects and materials but is prone to overlaps in some corner cases.
…rectly now. The UV map in the last slow now gets the correct name as well
… when in EDIT mode or when no MESH object is selected.
…triggered. This commit catches this corner case during polling.
|
Here is the Hubs Blender addon with the autobaker included: |
| if bpy.app.version < (4, 0, 0): | ||
| lightmap_texture_node.image.colorspace_settings.name = "Linear" | ||
| else: | ||
| lightmap_texture_node.image.colorspace_settings.name = "Linear Rec.709" |
There was a problem hiding this comment.
I don't see any errors reported, but this also doesn't seem to fully work as the colorspace is displayed as sRGB when I go to check the image after baking for both HDR and JPEG. If I watch closely it looks like it is initially set to Linear, but then it gets changed to sRGB when the bake finishes.
There was a problem hiding this comment.
Wow, there is actually a whole can of worms behind this one. The problem seems to have been introduced with the switch to non-blocking with a modal operator. Here are the issues I have encountered when investigating this:
- The packed images seem not to get saved, you have to prompt the save yourself. Blender will ask you about that when closing or loading another file but many users will probably just click it away, losing their bake.
- The images get saved to disk, but are completely black with all pixel values at 0.0. The image datablock loaded in Blender still has the color information, though.
- As mentioned the color space gets set to SRGB at the end.
Co-authored-by: Exairnous <mythologylover75@gmail.com>
If you use the names as the identifiers, you can access them directly, e.g. self.image_name will return either HDR or JPEG. Co-authored-by: Exairnous <mythologylover75@gmail.com>
…rror message in the tooltip.
Added an operator that bakes lightmaps using Cycles for all selected objects that have at least one material. It uses UV slot 1 for the lightmap and creates the slot if not present already. It also automatically creates the required MOZ_Lightmap nodes and wires them correctly. If a MOZ_Lightmap node is present, the addon assumes that the user has taken care of the correct setup and bakes directly.

Baking happens using the Cycles render engine. The created lightmaps are saved as .hdr to Blender's temporary directory, packed and then removed to keep the user's system clean.
The new operator can be found in the Object Properties Editor in a new Panel "Hubs Lightmap Baker"