[Durian-svn] [3579] update to physics baking script, basically works now :)
campbell
institute at blender.org
Wed May 19 13:39:52 CEST 2010
Revision: 3579
https://blenderinstitute.dyndns.org/durian-svn/?do=log&project=durian&path=/&rev=3579
Author: campbell
Date: 2010-05-19 13:39:52 +0200 (Wed, 19 May 2010)
Log Message:
-----------
update to physics baking script, basically works now :)
Modified Paths:
--------------
pro/scripts/utilities/batch_bake.py
Modified: pro/scripts/utilities/batch_bake.py
===================================================================
--- pro/scripts/utilities/batch_bake.py 2010-05-19 11:37:31 UTC (rev 3578)
+++ pro/scripts/utilities/batch_bake.py 2010-05-19 11:39:52 UTC (rev 3579)
@@ -1,23 +1,85 @@
# replace
+
+# python /d/pro/scripts/utilities/batch_bake.py # build list
+# ./B -b /d/pro/scenes/05.8_ambushfight/05.8b_comp.blend -P /d/pro/scripts/utilities/batch_bake.py
+# ./B bzz /d/pro/scenes/05.8_ambushfight/05.8b_comp.blend -P /d/pro/scripts/utilities/batch_bake.py
+
+
+print("running", __file__)
import os
+import sys
def text_replace(text_block, from_text, to_text):
st = text_block.as_string()
- st = text_block.replace(from_text, to_text)
+ st = st.replace(from_text, to_text)
text_block.from_string(st)
-def main():
- import finals_config
+def get_group_instance(obj_in_group):
+ groups = []
+ for grp in bpy.data.groups:
+ for obj in grp.objects:
+ if obj_in_group == obj:
+ groups.append(grp)
+ break
+
+ print(groups)
+
+ objects = []
+
+ if not groups:
+ return objects
+
+ scenes = [bpy.context.scene]
+
+ while scenes[-1].set:
+ scenes.append(scenes[-1].set)
+
+ for scene in scenes:
+ for base in scene.bases:
+ obj = base.object
+ if obj.type == 'EMPTY':
+ dupli_group = obj.dupli_group
+ if dupli_group and dupli_group in groups:
+ objects.append(base)
+
+ return objects
+
+
+def get_object_layers(objects):
+ lay = [False] * 20
+ for base_inst in objects:
+ lay_obj = base_inst.layers[:]
+ print("Whee:", lay_obj)
+ lay[:] = [lay_obj[i] | val for i, val in enumerate(lay)]
+
+ return lay
+
+def check_init():
+ if "durian_init.py" not in bpy.data.texts:
+ print("durian_init.py not found: Exiting!")
+ sys.exit(0)
+
+def blender_bg_bake():
# start
init_script = bpy.data.texts.get("durian_init.py")
if init_script:
text_replace(init_script, "baked=True", "baked=False")
# run script
- reload(__import__("durian_init"))
+ check_init()
+ # HACK, short frame range to test
+ bpy.context.scene.frame_end = bpy.context.scene.frame_start + 12
+
+
+
+ import durian_init
+ reload(durian_init)
+
+ finals_config = durian_init.finals_config
+
# start bake
bpy.ops.ptcache.free_bake_all()
@@ -27,14 +89,111 @@
bpy.ops.ptcache.bake({"point_cache": point_cache}, bake=True)
'''
+
+ object_items = bpy.data.objects.items()
+
+ base_context = {
+ "scene": bpy.context.scene,
+ "main": bpy.context.main,
+ "active_object": None,
+ "object": None
+ }
+
# hair
- obj, psys = get_pointcache_sintel_hair()
- bpy.ops.ptcache.bake({"point_cache": psys.point_cache}, bake=True)
-
- for cmd in pointcache_commands():
- os.system(cmd)
+ for obj in [obj for obj_name, obj in object_items if obj_name == "GEO-sintel_hair_emit"]:
+ obj, psys = finals_config.get_pointcache_sintel_hair(obj)
+ context = base_context.copy()
+
+ context["point_cache"] = psys.point_cache
+
+ lay = get_object_layers(get_group_instance(obj))
+ bpy.context.scene.layers = lay
+ if True not in lay:
+ print("Skipping", obj, "no instance")
+ continue
+
+ print("layers:", lay)
+
+ bpy.ops.ptcache.free_bake(context)
+ reload(durian_init) # <--- why is this needed?
+ bpy.ops.ptcache.bake(context, bake=True)
+
+ for cmd in finals_config.pointcache_commands(psys.point_cache):
+ os.system(cmd)
+
+
+ # import code
+ # code.interact()
+
# end script, should we save?
if init_script:
text_replace(init_script, "baked=False", "baked=True")
+
+ # save so on open this renders quick
+ bpy.ops.wm.save_mainfile(check_existing=False, path=bpy.data.filename)
+
+
+def blender_fg_render():
+ # render
+ check_init()
+
+ bpy.context.scene.render.resolution_percentage = 50
+ bpy.context.scene.render.resolution_x = 2048
+ bpy.context.scene.render.resolution_y = 872
+ bpy.context.scene.render.file_format = 'AVI_JPEG'
+ bpy.context.scene.render.file_quality = 95
+
+
+ image_dir = "/tmp/hair/"
+ filename = bpy.data.filename.replace(".blend", ".avi")
+ bpy.context.scene.render.output_path = os.path.join(image_dir, os.path.basename(filename))
+
+ # quick fix
+ # freakin give me a 3d view!!! - make them ALL 3d camera views.
+ print(bpy.context.scene.objects.active)
+
+ for ar in bpy.context.window.screen.areas:
+ ar.type = 'VIEW_3D'
+ for sp in ar.spaces:
+ if sp.type == 'VIEW_3D': # rna_Scene_active_object_get
+ sp.display_render_override = True
+ sp.lock_camera_and_layers = True
+ sp.viewport_shading = 'SOLID'
+ sp.region_3d.perspective = 'CAMERA'
+ bpy.context.scene.update()
+
+ bpy.ops.render.opengl({}, animation=True)
+
+ sys.exit()
+
+def noblender_print_tasks():
+
+ BIN = "/b/B"
+
+ os.system("find /media/data/durian/ -name '*_comp.blend' > /tmp/foo.txt")
+ lines = open("/tmp/foo.txt", 'r').read().split("\n")
+ lines.sort()
+ for f in lines:
+ print(" ".join(["DISPLAY=:1", BIN, "-b", f, "-P", __file__])) # bake
+ print(" ".join(["DISPLAY=:1", BIN, f, "-P", __file__])) # render
+
+ os.system("rm /tmp/foo.txt")
+
+
+if __name__ == "__main__":
+ try:
+ import bpy
+ except:
+ bpy = None
+
+ # OUTSIDE OF BLENDER
+ if bpy is None:
+ noblender_print_tasks()
+
+ elif bpy.app.background:
+ blender_bg_bake()
+
+ else:
+ blender_fg_render()
More information about the Durian-svn
mailing list