Skip to content
Snippets Groups Projects
Commit aa2e740d authored by Campbell Barton's avatar Campbell Barton
Browse files

add error for animation baking a packed image.

parent 41021075
No related branches found
No related tags found
No related merge requests found
......@@ -20,17 +20,17 @@ bl_info = {
"name": "Animated Render Baker",
"author": "Janne Karhu (jahka)",
"version": (1, 0),
"blender": (2, 58, 0),
"blender": (2, 65, 0),
"location": "Properties > Render > Bake Panel",
"description": "Renderbakes a series of frames",
"category": "Object",
'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.6/Py/' \
'Scripts/Object/Animated_Render_Baker',
'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
'func=detail&aid=24836'}
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
"Scripts/Object/Animated_Render_Baker",
"tracker_url": "https://projects.blender.org/tracker/index.php?"
"func=detail&aid=24836"}
import bpy
from bpy.props import *
from bpy.props import IntProperty
class OBJECT_OT_animrenderbake(bpy.types.Operator):
bl_label = "Animated Render Bake"
......@@ -38,15 +38,15 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator):
bl_idname = "object.anim_bake_image"
bl_register = True
def framefile(self, orig, frame):
def framefile(self, filepath, frame):
"""
Set frame number to file name image.png -> image0013.png
"""
dot = orig.rfind(".")
return orig[:dot] + ('%04d' % frame) + orig[dot:]
import os
fn, ext = os.path.splitext(filepath)
return "%s%04d%s" % (fn, frame, ext)
def invoke(self, context, event):
import bpy
import shutil
scene = context.scene
......@@ -76,11 +76,12 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator):
img = None
#find the image that's used for rendering
# 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 != None:
if uvdata.image is not None:
img = uvdata.image
break
......@@ -92,12 +93,16 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator):
self.report({'ERROR'}, "Save the image that's used for baking before use")
return {'CANCELLED'}
if img.packed_file is not None:
self.report({'ERROR'}, "Can't animation-bake packed file")
return {'CANCELLED'}
# make sure we have an absolute path so that copying works for sure
img_filepath_abs = bpy.path.abspath(img.filepath, library=img.library)
print("Animated baking for frames (%d - %d)" % (start, end))
for cfra in range(start, end+1):
for cfra in range(start, end + 1):
print("Baking frame %d" % cfra)
# update scene to new frame and bake to template image
......@@ -106,7 +111,9 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator):
if 'CANCELLED' in ret:
return {'CANCELLED'}
#currently the api doesn't allow img.save_as(), so just save the template image as usual for every frame and copy to a file with frame specific filename
# Currently the api doesn't allow img.save_as()
# so just save the template image as usual for
# every frame and copy to a file with frame specific filename
img.save()
img_filepath_new = self.framefile(img_filepath_abs, cfra)
shutil.copyfile(img_filepath_abs, img_filepath_new)
......@@ -116,7 +123,7 @@ class OBJECT_OT_animrenderbake(bpy.types.Operator):
return{'FINISHED'}
# modified copy of original bake panel draw function
def draw(self, context):
layout = self.layout
......@@ -133,14 +140,14 @@ def register():
bpy.utils.register_module(__name__)
bpy.types.Scene.animrenderbake_start = IntProperty(
name="Start",
description="Start frame of the animated bake",
default=1)
name="Start",
description="Start frame of the animated bake",
default=1)
bpy.types.Scene.animrenderbake_end = IntProperty(
name="End",
description="End frame of the animated bake",
default=250)
name="End",
description="End frame of the animated bake",
default=250)
bpy.types.RENDER_PT_bake.prepend(draw)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment