1
$\begingroup$

So I am baking my smoke simulations on a headless machine. I am using the following snippet of python (bake-all.py):

import bpy

for scene in bpy.data.scenes:
    bpy.ops.ptcache.bake_all({'scene': scene,})

Together with:

/path/to/blender -b scene.blend -P bake-all.py

The smoke cache files are created properly. I then render using (for example):

/path/to/blender -b scene.blend -f 2

However, the smoke is not rendered into the scene and the smoke cache directory is empty; all cache files have been deleted.

What am I doing wrong?

$\endgroup$

1 Answer 1

4
$\begingroup$

After quite some digging around and wading through the source code, I found that upon initialising the ptcache for the smoke simulation, blender checks a flag PTCACHE_BAKED. This flag appears to be saved with the blend file. If the flag is not set, the cache directory is flushed.

To prevent this from happening, the file must be saved after baking. For this, a modified version of bake-all.py works:

import bpy

try:
    for scene in bpy.data.scenes:
        bpy.ops.ptcache.free_bake_all()
        bpy.ops.ptcache.bake_all({'scene': scene,})
finally:
    bpy.ops.wm.save_mainfile()

Two additions here:

  1. A try-finally block to save the mainfile, even if the bake is aborted with Ctrl-C.

  2. A call to free_bake_all(); this is required for re-bakes, otherwise bake_all will not do anything, for the same reason as blender will not delete the smokecache when starting (it assumes the bake is already finished).

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .