[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [4167] trunk/py/scripts/addons/ object_animrenderbake.py: add error for animation baking a packed image.

Campbell Barton ideasman42 at gmail.com
Tue Jan 15 05:51:43 CET 2013


Revision: 4167
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=4167
Author:   campbellbarton
Date:     2013-01-15 04:51:36 +0000 (Tue, 15 Jan 2013)
Log Message:
-----------
add error for animation baking a packed image.

Modified Paths:
--------------
    trunk/py/scripts/addons/object_animrenderbake.py

Modified: trunk/py/scripts/addons/object_animrenderbake.py
===================================================================
--- trunk/py/scripts/addons/object_animrenderbake.py	2013-01-15 04:14:18 UTC (rev 4166)
+++ trunk/py/scripts/addons/object_animrenderbake.py	2013-01-15 04:51:36 UTC (rev 4167)
@@ -20,17 +20,17 @@
     "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 @@
     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 @@
 
         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 @@
             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 @@
             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 @@
 
         return{'FINISHED'}
 
-# modified copy of original bake panel draw function
+
 def draw(self, context):
     layout = self.layout
 
@@ -133,14 +140,14 @@
     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)
 



More information about the Bf-extensions-cvs mailing list