Bake Wrangler - Node based baking tool set

For us it’s a pretty common case, we work with high quality high resolution assets for things like ArchViz, and also with high resolution textures for some AR experiences, so we maintain as separate as possible al lthe textures and objects.

It may not be common for normal games or baking, but for our case it’s pretty common :slight_smile:

Thanks, we will try the UV trick :slight_smile:

Oh, so you have thought about it very carefully already. Thanks.
I personally wish to make all the selected objects visible, but it is probably just me.
Perhaps more user’s voice are needed.

Yes. I wish to type the floating point value into a small textbox of a node directly! Thanks.

@3DAV It’s not that it’s difficult to achieve, it’s just that there isn’t currently any ground work to support it. I could just bake the same object multiple times, but that wouldn’t be very good. Really I would need to change things so that a single pass can result in multiple images (currently everything expects one image). Then the output needs to support saving to multiple files. For that there should really be some sort of token substitution for the names in place.

I could half ass it, add a check box somewhere, bake each object multiple times for each material and tack the material name onto the filename… But that doesn’t really add anything that you can’t already do using UV Maps.

@Bone-Studio The UV Map method should do what you want, it’s just a little extra effort to set up. Let me know if you need any help with it.

Splitting the output into files based on material is something I have to think on. There are still many features people want and I try to add what seems most popular or what people are willing to donate support towards.

@hyyou I’m just imaging you have a whole bunch of targets set and you want to bake all but one or two of them. It may be that it’s easier to just hide those you don’t want instead of editing the bake tree. You will get an error, but the other targets should still bake correctly even if a couple failed…

1 Like

Too bad, I have to agree that it is reasonable.

and I can’t wait to set my custom property, so I hacked into your baker.py :-

#within process_tree(tree_name, node_name)
...
_print(">", tag=True)
error = 0
active_scene.world["hyyou"] = 0   <== my line
for bake in bakes.keys():
    ... 
    active_scene.world["hyyou"] = active_scene.world["hyyou"] +1      <== my line
return error

Look like it will works.
Your code are easy-to-read, and saving the result .blend in a tmp folder (easy to debug) is genius. Thanks!

Edit: make post more concise

Adding a preference to ignore objects visibility is probably reasonable… I don’t want to add any more features to this version, but I think it could do with some more preferences to set stuff like default resolutions.

Because baker.py isn’t loaded until you press one of the bake buttons, you can actually edit it between bakes without having to reload the add-on or anything.

What are you controlling with the property? One thing to keep in mind is that objects are prepared for baking only the first time they are encountered. So if you wanted to change something about an object that had already been baked it probably won’t work. If it changes an object that hasn’t yet been baked then it should work fine.

Just yes. I accept that it is not so important.

The custom variable feature is irrelevant for me now, because I can edit your code directly which is the best. :relaxed:

I was surprised the first time I noticed that. It is so convenient. Thanks.

I make the custom property to be the driver of a “Value” shader node (purple in the below image).
The value effects the material used by an object X.
In the batch bake, the property is set to 0, then bake X, then set it to 1, then bake X.


The result are correct.
I am going to ignore your friendly warning, and will celebrate with delight. :watermelon: :pie:

=============================================
By the ways, sometimes, I got an error message in the popup window :-

-Loading existing file
-Mixing image channels and/or mask: Completed in 0:00:00.113026
-Creating alpha channel: Input/Output pixel count mismatch <======= !!! !!!
-Writing changes to E:\IMAno\Education\Year8Epi1\160_myGame\ver23_ogre2016again_git\Sys\pj550_wunWar\ships\blenderFile\bl_waterMelon_360_02.png

It seems to me that the message only appears when the output files already exist, but even so, my files are still overwritten correctly.

Hmm, if you get that error then the Alpha channel won’t get updated. The other channels wouldn’t be affected.

If you can find exactly what combination causes it to happen that would be useful! There are only two cases where the Alpha channel gets written: 1) You have an RGBA format and the image already existed, the Alpha channel from the original should be kept. 2) You have an RGBA format and have a input connected to the ‘A’ socket.

I’m guessing you are in case (1)? Does it happen every time the image already exists?

Yes, more likely (1).
I connected Color of Pass to Color of Output Image Path.
I didn’t connect R G B A or Value.
I will test more about it.
Edit 1&2 : In situation that it happens, I use diffuse pass. It is not related to Batch Bake node.

Edit3 : Netherby, I sent my minimal blend file as a private message to you.
I can’t reproduce bug from scratch, so I rip-ed it from a more complex scene.
Try to switch to “Bake” workspace, then press the second bake (the lower node) of Output Image Path node.

I still don’t know what causes it.
If I change the image-saving directory in your node to something not //, the symptom seems to disappear.

===================

By the way, here is the step to reproduce the rare bug “context is incorrect” :-

  • create a new cube in object-mode
  • then delete it (this will result in 0 active object)
  • try to bake using your add-on ==> get error

You can try these steps in my blend file too. It will fail.

Thanks, I will see if I can figure out what’s going on with it.

I think I’ve fixed most/all of the context bugs in my current build, I will check the deleting the only object to make sure.

I feel like I’ve pretty much got this version nailed down. I have one more build to release, which doesn’t add any new features. But it adds a bunch of preferences to set defaults and cleans up the node layouts.

Another thing I can never get it works is baking alpha.

I usually want to bake diffuse+alpha to RGBA of the output image.
Here is the “Alpha” in Shader Node that I want to bake.


Do I connect them correctly?
I can workaround by using custom driver + edit my game engine though.

You have to selected ‘RGBA’ in the ‘Color’ dropdown of the output otherwise the ‘A’ input is ignored. Otherwise your set up should work…

1 Like

Oh! Finally, it works now, thank a lot.

I have released 1.0.RC5 now. Even though it has no new features I feel like it is a pretty big improvement with the new node layouts and preferences.

I’ve also corrected some rare bugs to do with selection and editor states and the harmless pixel mismatch error when using clear option with an alpha image. Everything seems to be working pretty great and stable :smiley:

2 Likes

Thanks for the great add-on. Now I can’t live without it.

How did you learn how to code to create custom node editor (funcatio, and add event to the Bake button?
It is so hard to find a good resource/site. Do you write a blog?

When I try to bake combined I get this error:
Baking NORMALS pass: Error: Multires data baking requires multi-resolution object
I’m having a default pbr metal roughness material exported from substance.
When I bake normal or albedo or any other pass it works without problems.

After uninstalling and rebooting Blender I get now this error when baking combined:
ValueError: Converting py args to operator properties: : ‘SUBSURFACE’ not found in (‘NONE’, ‘AO’, ‘EMIT’, ‘DIRECT’, ‘INDIRECT’, ‘COLOR’, ‘DIFFUSE’, ‘GLOSSY’, ‘TRANSMISSION’)

hi, did you add the “invert cavity” ability in the 1.0.RC5 version ?

Subsurface baking is currently not supported.
I will quote the developer here :-


I think, the answer is no.
There is a cavity option though. (I don’t understand this feature, so I am not sure)


If anyone loves to add Driver into the add-on code like me (I doubt there is anyone),
beware that the for bake in bakes.keys(): means each “Pass” node, not “Output Image Path” node.

I would like to know how to create a node group. (ctrl+G not work)
I want to add image file names as input of some groups.
With 20+ objects, my bake graph becomes a mess very fast.
Perhaps, it is a hard task for developer to support it.

Edit: merge posts.

@ElinHoehler Blender 2.83 doesn’t support subsurface, I disabled the option in the nodes. But I realise now that if you are loading an old tree, the property could still be set. I will fix the issue, in the mean time the only work-around is to delete your Pass nodes and replace them…

@Anubisbis I didn’t add it yet. There are a couple of experiments I want to do with it first, but I haven’t got around to it.

@hyyou Honestly a lot of the stuff in this add-on were difficult to figure out how to do. I haven’t used Python since university, not that it’s a difficult language, but I find its documentation difficult to grok at times. There are actually a bunch of ‘errors’ in my earlier py code to do with variable scope, but it works so I’ve left it alone.
Then there is the Blender documentation, which isn’t great. It has lots of details on some things and then nothing on others. For operators you really have to look at the source code to see how they work, it would be nice if someone would document them better :stuck_out_tongue:
My main resources are the documentation, stackexchange (though people on there don’t seem to know about the more complicated things, it’s a good resource for more basic stuff), and a lot of trial and error.

As an add-on developer I’ve found the biggest frustration is there are often things you want to do, but either can’t do or have to use some ugly and or complicated hack to do something that shouldn’t be so difficult. Not being able to use your own instances of a whole lot of Blenders data structures is really annoying, though as I’ve come to understand how the ‘rna’ system works I think I could have done some of the stuff that currently uses a heap of code much more efficiently, maybe…

I don’t write a blog or anything. I’m very minimalist when it comes to online presence.

I’m not actually sure how to support node groups. I think it’s probably possible… It would complicate reading the node tree quite a bit, which is why I haven’t been keen to investigate it. I do have a few ideas for making managing large tree easier, but maybe groups should be part of it, at least to make things look less messy.

The problem of course is that node groups have no documentation about how they are supposed to work :anguished:

1 Like

Thank a lot for sharing the story!
I always thought Blender python hated me personally, because I need hacking even for a basic thing.

Recently, I tested a more risky way to use driver - to toggle Modifier + modding.

I mod-ed as :-

active_scene.world["nbw"] = 0  # <== my line (nbw=Netherby's Node Wrangler)
for bake in bakes.keys():
...
     active_scene.world["nbw"] = active_scene.world["nbw"]+1   # <== my line
return error

Here is my test blend file. ForBakeWran5_driverModifier.blend (815.1 KB)

  • There are 3 objects : source, eraser and target.
  • source has boolean modifier (difference-eraser) that is only enabled when nbw==1.
  • target’s shape is the same as source after applied the boolean modifier.
  • The step of bake batch (1) nbw=0, (2) bake, (3) nbw=1, and (4) do the final bake.
  • The result of the last baking should has both green & red.
  • I got result as plain red.

Here is my batch-bake tree. I don’t think there is anything wrong.

I looked into the file in temp folder that the add-on generated.
While the nbw value is 2 correctly, the shape of the source object is not changed to match nbw=1.

Are there any way to workaround it?

Meanwhile, I dug your code, and noticed that you applied the modifier to prepare an object.

def prep_object_for_bake(object):
  .... bpy.ops.object.modifier_apply(modifier=mod.name)

I have tried to comment out the above lines, and/or commented out if not object.bw_copy:, but I fail.

I believe I should back up SOURCE that still has un-applied modifier, but it is very complex for me.
Perhaps, the solution is near the line
selected = bpy.data.collections.new("Selected_" + active[0].name) .

If you change the first ‘if’ block in ‘prep_object_for_bake’ to always be true, that should make it work:

def prep_object_for_bake(object):
    # Create a copy of the object to modify and put it into the mesh only scene
    if not object.bw_copy:

to:

def prep_object_for_bake(object):
    # Create a copy of the object to modify and put it into the mesh only scene
    if True:

That will cause the object to get reprocessed every time, instead of just the first time. It will use up a bit more memory, but it’s the most simple change to make it work I think…