Page MenuHome

Allow external baking, bugfix (external pathname) and don't require dummy image node
Needs ReviewPublic

Authored by Miguel (mo_brainstorm) on Jan 3 2019, 3:01 PM.



Hello, everyone.

I created a patch that enables external baking, in a proper way:

  • Allows to bake to external textures through the python API (as described in the docs)
  • Creates its own image buffer (and frees it) so the designer doesn't need to create an image node for each material. yay! :)
  • Fixes a bug: if we set the path to manual instead of automatic, the path parameter was discarded

This patch is meaningful for the following workflow:

  • We want to bake a scene with lots of objects
  • These objects share materials between themselves
  • We want to export the baked result to an OBJ, with a single texture for the whole object.
  • The designer is lazy and wants something like 3D Max or Cinema4D: just click and bake. No creating nodes, additional buffers, etc. by hand
  • This patch is the first step to automating the above steps through a simple Python script.

I've developed it on Blender 2.79, but rebased it to the latest 2.8 git.

Related to T57143 and T60097. I've been discussing this with Dalai Felinto on that thread.

To test:

  • Go to Cycles mode
  • Select the default cube, use nodes, create a material for each face with a different color
  • UV Unwrap the cube
  • No need to create image buffers o image nodes pointing to them.
  • With the cube selected in object mode, execute:
bpy.ops.object.bake(type='COMBINED', save_mode='EXTERNAL', filepath=r'/tmp/cube_baked.png', use_automatic_name=False, width=512, height=512)

As you can see, it doesn't require a dummy node, making it transparent for the graphic designer. We could script a batch export for the scene with minimal effort.

About the implementation: The bake code just requires an image buffer, but doesn't seem to do anything useful with it when baking to external textures. Since I don't know the code, I applied the least intrusive method instead of branching the render code (tried that and didn't go well).

This is my first contribution to an open source project, please go easy on me :)

There may be faults, please look at the malloc() I used and more other things, I don't know if you use some wrappers above it.


Diff Detail

rB Blender

Event Timeline

Hello again, after some months we're using this patch (and additional script) to bake whole scenes and integrate them with our render engine, pretty quick and easily.
This is an example with the Classroom scene from Blender's demo page.