~ubuntu-branches/ubuntu/saucy/blender/saucy-proposed

« back to all changes in this revision

Viewing changes to release/scripts/addons/object_animrenderbake.py

  • Committer: Package Import Robot
  • Author(s): Jeremy Bicha
  • Date: 2013-03-06 12:08:47 UTC
  • mfrom: (1.5.1) (14.1.8 experimental)
  • Revision ID: package-import@ubuntu.com-20130306120847-frjfaryb2zrotwcg
Tags: 2.66a-1ubuntu1
* Resynchronize with Debian (LP: #1076930, #1089256, #1052743, #999024,
  #1122888, #1147084)
* debian/control:
  - Lower build-depends on libavcodec-dev since we're not
    doing the libav9 transition in Ubuntu yet

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
    "name": "Animated Render Baker",
21
21
    "author": "Janne Karhu (jahka)",
22
22
    "version": (1, 0),
23
 
    "blender": (2, 5, 8),
 
23
    "blender": (2, 65, 0),
24
24
    "location": "Properties > Render > Bake Panel",
25
25
    "description": "Renderbakes a series of frames",
26
26
    "category": "Object",
27
 
    'wiki_url': 'http://wiki.blender.org/index.php/Extensions:2.5/Py/' \
28
 
        'Scripts/Object/Animated_Render_Baker',
29
 
    'tracker_url': 'https://projects.blender.org/tracker/index.php?'\
30
 
        'func=detail&aid=24836'}
 
27
    "wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
 
28
                "Scripts/Object/Animated_Render_Baker",
 
29
    "tracker_url": "https://projects.blender.org/tracker/index.php?"
 
30
                   "func=detail&aid=24836"}
31
31
 
32
32
import bpy
33
 
from bpy.props import *
 
33
from bpy.props import IntProperty
34
34
 
35
35
class OBJECT_OT_animrenderbake(bpy.types.Operator):
36
36
    bl_label = "Animated Render Bake"
38
38
    bl_idname = "object.anim_bake_image"
39
39
    bl_register = True
40
40
 
41
 
    def framefile(self, orig, frame):
42
 
        '''
 
41
    def framefile(self, filepath, frame):
 
42
        """
43
43
        Set frame number to file name image.png -> image0013.png
44
 
        '''
45
 
        dot = orig.rfind(".")
46
 
        return orig[:dot] + ('%04d' % frame) + orig[dot:]
47
 
    
 
44
        """
 
45
        import os
 
46
        fn, ext = os.path.splitext(filepath)
 
47
        return "%s%04d%s" % (fn, frame, ext)
 
48
 
48
49
    def invoke(self, context, event):
49
 
        import bpy
50
50
        import shutil
51
51
        
52
52
        scene = context.scene
74
74
            self.report({'ERROR'}, "The baked object must be a mesh object")
75
75
            return {'CANCELLED'}
76
76
 
 
77
        if context.active_object.mode == 'EDIT':
 
78
            self.report({'ERROR'}, "Can't bake in edit-mode")
 
79
            return {'CANCELLED'}
 
80
 
77
81
        img = None
78
82
 
79
 
        #find the image that's used for rendering
 
83
        # find the image that's used for rendering
 
84
        # TODO: support multiple images per bake
80
85
        for uvtex in context.active_object.data.uv_textures:
81
86
            if uvtex.active_render == True:
82
87
                for uvdata in uvtex.data:
83
 
                    if uvdata.image != None:
 
88
                    if uvdata.image is not None:
84
89
                        img = uvdata.image
85
90
                        break
86
91
 
92
97
            self.report({'ERROR'}, "Save the image that's used for baking before use")
93
98
            return {'CANCELLED'}
94
99
 
 
100
        if img.packed_file is not None:
 
101
            self.report({'ERROR'}, "Can't animation-bake packed file")
 
102
            return {'CANCELLED'}
 
103
 
95
104
        # make sure we have an absolute path so that copying works for sure
96
 
        absp = bpy.path.abspath(img.filepath, library=img.library)
97
 
 
98
 
        print("Animated baking for frames " + str(start) + " - " + str(end))
99
 
 
100
 
        for cfra in range(start, end+1):
101
 
            print("Baking frame " + str(cfra))
 
105
        img_filepath_abs = bpy.path.abspath(img.filepath, library=img.library)
 
106
 
 
107
        print("Animated baking for frames (%d - %d)" % (start, end))
 
108
 
 
109
        for cfra in range(start, end + 1):
 
110
            print("Baking frame %d" % cfra)
102
111
 
103
112
            # update scene to new frame and bake to template image
104
113
            scene.frame_set(cfra)
106
115
            if 'CANCELLED' in ret:
107
116
                return {'CANCELLED'}
108
117
 
109
 
            #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
 
118
            # Currently the api doesn't allow img.save_as()
 
119
            # so just save the template image as usual for
 
120
            # every frame and copy to a file with frame specific filename
110
121
            img.save()
111
 
            shutil.copyfile(absp, self.framefile(absp, cfra))
 
122
            img_filepath_new = self.framefile(img_filepath_abs, cfra)
 
123
            shutil.copyfile(img_filepath_abs, img_filepath_new)
 
124
            print("Saved %r" % img_filepath_new)
112
125
 
113
 
            print("Saved " + self.framefile(absp, cfra))
114
126
        print("Baking done!")
115
127
 
116
128
        return{'FINISHED'}
117
129
 
118
 
# modified copy of original bake panel draw function
119
 
def draw_animrenderbake(self, context):
 
130
 
 
131
def draw(self, context):
120
132
    layout = self.layout
121
133
 
122
 
    rd = context.scene.render
 
134
    scene = context.scene
123
135
 
124
136
    row = layout.row()
125
 
    row.operator("object.bake_image", icon='RENDER_STILL')
126
 
    
127
 
    #----------- beginning of modifications ----------------
128
137
    row.operator("object.anim_bake_image", text="Animated Bake", icon="RENDER_ANIMATION")
129
 
    row = layout.row(align=True)
130
 
    row.prop(context.scene, "animrenderbake_start")
131
 
    row.prop(context.scene, "animrenderbake_end")
132
 
    #-------------- end of modifications ---------------------
133
 
 
134
 
    layout.prop(rd, "bake_type")
135
 
 
136
 
    multires_bake = False
137
 
    if rd.bake_type in ['NORMALS', 'DISPLACEMENT']:
138
 
        layout.prop(rd, 'use_bake_multires')
139
 
        multires_bake = rd.use_bake_multires
140
 
 
141
 
    if not multires_bake:
142
 
        if rd.bake_type == 'NORMALS':
143
 
            layout.prop(rd, "bake_normal_space")
144
 
        elif rd.bake_type in {'DISPLACEMENT', 'AO'}:
145
 
            layout.prop(rd, "use_bake_normalize")
146
 
 
147
 
        # col.prop(rd, "bake_aa_mode")
148
 
        # col.prop(rd, "use_bake_antialiasing")
149
 
 
150
 
        layout.separator()
151
 
 
152
 
        split = layout.split()
153
 
 
154
 
        col = split.column()
155
 
        col.prop(rd, "use_bake_clear")
156
 
        col.prop(rd, "bake_margin")
157
 
        col.prop(rd, "bake_quad_split", text="Split")
158
 
 
159
 
        col = split.column()
160
 
        col.prop(rd, "use_bake_selected_to_active")
161
 
        sub = col.column()
162
 
        sub.active = rd.use_bake_selected_to_active
163
 
        sub.prop(rd, "bake_distance")
164
 
        sub.prop(rd, "bake_bias")
165
 
    else:
166
 
        if rd.bake_type == 'DISPLACEMENT':
167
 
            layout.prop(rd, "use_bake_lores_mesh")
168
 
 
169
 
        layout.prop(rd, "use_bake_clear")
170
 
        layout.prop(rd, "bake_margin")
 
138
    rowsub = row.row(align=True)
 
139
    rowsub.prop(scene, "animrenderbake_start")
 
140
    rowsub.prop(scene, "animrenderbake_end")
 
141
 
171
142
 
172
143
def register():
173
144
    bpy.utils.register_module(__name__)
174
145
 
175
146
    bpy.types.Scene.animrenderbake_start = IntProperty(
176
 
        name="Start",
177
 
        description="Start frame of the animated bake",
178
 
        default=1)
 
147
            name="Start",
 
148
            description="Start frame of the animated bake",
 
149
            default=1)
179
150
 
180
151
    bpy.types.Scene.animrenderbake_end = IntProperty(
181
 
        name="End",
182
 
        description="End frame of the animated bake",
183
 
        default=250)
184
 
 
185
 
    # replace original panel draw function with modified one
186
 
    panel = bpy.types.RENDER_PT_bake
187
 
    panel.old_draw = panel.draw
188
 
    panel.draw = draw_animrenderbake
 
152
            name="End",
 
153
            description="End frame of the animated bake",
 
154
            default=250)
 
155
 
 
156
    bpy.types.RENDER_PT_bake.prepend(draw)
 
157
 
189
158
 
190
159
def unregister():
191
160
    bpy.utils.unregister_module(__name__)
192
161
 
193
162
    # restore original panel draw function
194
 
    bpy.types.RENDER_PT_bake.draw = bpy.types.RENDER_PT_bake.old_draw
195
 
    del bpy.types.RENDER_PT_bake.old_draw
196
163
    del bpy.types.Scene.animrenderbake_start
197
164
    del bpy.types.Scene.animrenderbake_end
198
165
 
 
166
    bpy.types.RENDER_PT_bake.remove(draw)
 
167
 
 
168
 
199
169
if __name__ == "__main__":
200
170
    register()