diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-08-24 13:48:00 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-08-24 13:48:00 +0300 |
commit | 7cde1c98a02c78c26154edf3cef2ef9fd8936ad1 (patch) | |
tree | 0a3ada798c102579a7251ae1b17d603ce83e72f4 | |
parent | 30e801eb06e47591b658a3faf6e3545b542ddf0d (diff) |
Fix T45879: Object Animated Render Baker options not showing up in Render->Bake, with Cycles engine
Take Two. Not really happy with our current baking API tbh, there are many things that look messy
(even inside Blender code, how can a func named 'ED_object_get_active_image' can be reserved to new shading system???),
but this should do it for now. Just avoid too much exotic node systems with Cycles and this addon,
and/or clearly select/activate the image tex node containing the picture you want to use as target.
Based on a patch by Edward Gabriel Rowlett-Barbu (Zadirion), many thanks.
-rw-r--r-- | object_animrenderbake.py | 58 |
1 files changed, 48 insertions, 10 deletions
diff --git a/object_animrenderbake.py b/object_animrenderbake.py index ce04f602..552ac80c 100644 --- a/object_animrenderbake.py +++ b/object_animrenderbake.py @@ -19,8 +19,8 @@ bl_info = { "name": "Animated Render Baker", "author": "Janne Karhu (jahka)", - "version": (1, 0), - "blender": (2, 65, 0), + "version": (2, 0), + "blender": (2, 75, 0), "location": "Properties > Render > Bake Panel", "description": "Renderbakes a series of frames", "category": "Object", @@ -48,9 +48,10 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator): def invoke(self, context, event): import shutil - + is_cycles = (context.scene.render.engine == 'CYCLES') + scene = context.scene - + start = scene.animrenderbake_start end = scene.animrenderbake_end @@ -82,12 +83,46 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator): # find the image that's used for rendering # TODO: support multiple images per bake - for uvtex in context.active_object.data.uv_textures: - if uvtex.active_render == True: - for uvdata in uvtex.data: - if uvdata.image is not None: - img = uvdata.image + if is_cycles: + # XXX This tries to mimic nodeGetActiveTexture(), but we have no access to 'texture_active' state from RNA... + # IMHO, this should be a func in RNA nodetree struct anyway? + inactive = None + selected = None + for mat_slot in context.active_object.material_slots: + mat = mat_slot.material + if not mat or not mat.node_tree: + continue + trees = [mat.node_tree] + while trees and not img: + tree = trees.pop() + node = tree.nodes.active + if node.type in {'TEX_IMAGE', 'TEX_ENVIRONMENT'}: + img = node.image break + for node in tree.nodes: + if node.type in {'TEX_IMAGE', 'TEX_ENVIRONMENT'} and node.image: + if node.select: + if not selected: + selected = node + else: + if not inactive: + inactive = node + elif node.type == 'GROUP': + trees.add(node.node_tree) + if img: + break + if not img: + if selected: + img = selected.image + elif inactive: + img = inactive.image + else: + for uvtex in context.active_object.data.uv_textures: + if uvtex.active_render == True: + for uvdata in uvtex.data: + if uvdata.image is not None: + img = uvdata.image + break if img is None: self.report({'ERROR'}, "No valid image found to bake to") @@ -111,7 +146,10 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator): # update scene to new frame and bake to template image scene.frame_set(cfra) - ret = bpy.ops.object.bake_image() + if is_cycles: + ret = bpy.ops.object.bake() + else: + ret = bpy.ops.object.bake_image() if 'CANCELLED' in ret: return {'CANCELLED'} |