@@ -69,8 +69,8 @@ def load_font(font_path):
69
69
'resolution_x' : 1920 ,
70
70
'resolution_y' : 1080 ,
71
71
'resolution_percentage' : 100 ,
72
- 'start_frame' : 20 ,
73
- 'end_frame' : 25 ,
72
+ 'start_frame' : 1 ,
73
+ 'end_frame' : 300 ,
74
74
'animation' : True ,
75
75
}
76
76
@@ -81,14 +81,6 @@ def load_font(font_path):
81
81
# that defines this template in OpenShot.
82
82
# ----------------------------------------------------------------------------
83
83
84
- # TITLE 1 - Modify Text / Curve settings
85
- text_object1 = bpy .data .curves ["Title1" ]
86
- text_object1 .extrude = params ["extrude" ]
87
- text_object1 .bevel_depth = params ["bevel_depth" ]
88
- text_object1 .body = params ["title1" ]
89
- text_object1 .align_x = params ["spacemode" ]
90
- text_object1 .size = params ["text_size" ]
91
- text_object1 .space_character = params ["width" ]
92
84
# Get font object
93
85
font = None
94
86
if params ["fontname" ] != "Bfont" :
@@ -97,50 +89,43 @@ def load_font(font_path):
97
89
else :
98
90
# Get default font
99
91
font = bpy .data .fonts ["Bfont" ]
100
- text_object1 .font = font
92
+
93
+ # TITLE 1 - Modify Text / Curve settings
94
+ text_object1 = bpy .data .curves ["Title1" ]
95
+ text_object1 .body = params ["title1" ]
101
96
102
97
# TITLE 2 - Modify Text / Curve settings
103
98
text_object2 = bpy .data .curves ["Title2" ]
104
- text_object2 .extrude = params ["extrude" ]
105
- text_object2 .bevel_depth = params ["bevel_depth" ]
106
99
text_object2 .body = params ["title2" ]
107
- text_object2 .align_x = params ["spacemode" ]
108
- text_object2 .size = params ["text_size" ]
109
- text_object2 .space_character = params ["width" ]
110
- text_object2 .font = font
111
100
112
101
# TITLE 3 - Modify Text / Curve settings
113
102
text_object3 = bpy .data .curves ["Title3" ]
114
- text_object3 .extrude = params ["extrude" ]
115
- text_object3 .bevel_depth = params ["bevel_depth" ]
116
103
text_object3 .body = params ["title3" ]
117
- text_object3 .align_x = params ["spacemode" ]
118
- text_object3 .size = params ["text_size" ]
119
- text_object3 .space_character = params ["width" ]
120
- text_object3 .font = font
121
-
122
- # TITLE 1 - Change the material settings (color, alpha, etc...)
123
- material_object1 = bpy .data .materials ["Title1.Material" ]
124
- material_object1 .diffuse_color = params ["diffuse_color" ]
125
- material_object1 .specular_color = params ["specular_color" ]
126
- material_object1 .specular_intensity = params ["specular_intensity" ]
127
-
128
- # TITLE 2 - Change the material settings (color, alpha, etc...)
129
- material_object2 = bpy .data .materials ["Title2.Material" ]
130
- material_object2 .diffuse_color = params ["diffuse_color" ]
131
- material_object2 .specular_color = params ["specular_color" ]
132
- material_object2 .specular_intensity = params ["specular_intensity" ]
133
-
134
- # TITLE 3 - Change the material settings (color, alpha, etc...)
135
- material_object3 = bpy .data .materials ["Title3.Material" ]
136
- material_object3 .diffuse_color = params ["diffuse_color" ]
137
- material_object3 .specular_color = params ["specular_color" ]
138
- material_object3 .specular_intensity = params ["specular_intensity" ]
104
+
105
+ # Set common text properties
106
+ for ob in [text_object1 , text_object2 , text_object3 ]:
107
+ ob .extrude = params ["extrude" ]
108
+ ob .bevel_depth = params ["bevel_depth" ]
109
+ ob .align_x = params ["spacemode" ]
110
+ ob .size = params ["text_size" ]
111
+ ob .space_character = params ["width" ]
112
+ ob .font = font
113
+
114
+ # Change the title material settings (color, alpha, etc...)
115
+ for mat in [
116
+ "Title1.Material" ,
117
+ "Title2.Material" ,
118
+ "Title3.Material" ,
119
+ ]:
120
+ ob = bpy .data .materials [mat ]
121
+ ob .diffuse_color = params ["diffuse_color" ]
122
+ ob .specular_color = params ["specular_color" ]
123
+ ob .specular_intensity = params ["specular_intensity" ]
139
124
140
125
# BACKGROUND - Change the material settings (color, alpha, etc...)
141
- material_object4 = bpy .data .materials ["Background.Material" ]
142
- material_object4 .specular_color = params ["specular_color_bg" ]
143
- material_object4 .specular_intensity = params ["specular_intensity_bg" ]
126
+ bg_mat = bpy .data .materials ["Background.Material" ]
127
+ bg_mat .specular_color = params ["specular_color_bg" ]
128
+ bg_mat .specular_intensity = params ["specular_intensity_bg" ]
144
129
145
130
# Shadeless Background
146
131
# TODO: Unsupported in Blender 2.8 (not sure of workaround yet)
@@ -149,116 +134,60 @@ def load_font(font_path):
149
134
# else:
150
135
# material_object4.use_shadeless = False
151
136
152
- # BACKGROUND COLORS (KEYFRAMES) ----------------------
153
- # TILE 1
154
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [0 ].co = (1.0 , params ["diffuse_color_t1" ][0 ])
155
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [0 ].handle_left .y = params ["diffuse_color_t1" ][0 ]
156
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [0 ].handle_right .y = params ["diffuse_color_t1" ][0 ]
157
-
158
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [0 ].co = (1.0 , params ["diffuse_color_t1" ][1 ])
159
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [0 ].handle_left .y = params ["diffuse_color_t1" ][1 ]
160
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [0 ].handle_right .y = params ["diffuse_color_t1" ][1 ]
161
-
162
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [0 ].co = (1.0 , params ["diffuse_color_t1" ][2 ])
163
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [0 ].handle_left .y = params ["diffuse_color_t1" ][2 ]
164
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [0 ].handle_right .y = params ["diffuse_color_t1" ][2 ]
165
-
166
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [1 ].co = (70.0 , params ["diffuse_color_t1" ][0 ])
167
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [1 ].handle_left .y = params ["diffuse_color_t1" ][0 ]
168
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [1 ].handle_right .y = params ["diffuse_color_t1" ][0 ]
169
137
170
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [1 ].co = (70.0 , params ["diffuse_color_t1" ][1 ])
171
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [1 ].handle_left .y = params ["diffuse_color_t1" ][1 ]
172
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [1 ].handle_right .y = params ["diffuse_color_t1" ][1 ]
138
+ def update_keyframe (point , coord ):
139
+ point .co = coord
140
+ point .handle_left .y = coord [1 ]
141
+ point .handle_right .y = coord [1 ]
173
142
174
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [1 ].co = (70.0 , params ["diffuse_color_t1" ][2 ])
175
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [1 ].handle_left .y = params ["diffuse_color_t1" ][2 ]
176
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [1 ].handle_right .y = params ["diffuse_color_t1" ][2 ]
177
143
178
- # TILE 2
179
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [2 ].co = (120.0 , params ["diffuse_color_t2" ][0 ])
180
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [2 ].handle_left .y = params ["diffuse_color_t2" ][0 ]
181
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [2 ].handle_right .y = params ["diffuse_color_t2" ][0 ]
182
-
183
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [2 ].co = (120.0 , params ["diffuse_color_t2" ][1 ])
184
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [2 ].handle_left .y = params ["diffuse_color_t2" ][1 ]
185
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [2 ].handle_right .y = params ["diffuse_color_t2" ][1 ]
144
+ def update_curves (action , point , frame , color ):
145
+ for i in range (0 , 3 ):
146
+ coord = (frame , color [i ])
147
+ update_keyframe (
148
+ action .fcurves [i ].keyframe_points [point ],
149
+ coord )
186
150
187
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [2 ].co = (120.0 , params ["diffuse_color_t2" ][2 ])
188
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [2 ].handle_left .y = params ["diffuse_color_t2" ][2 ]
189
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [2 ].handle_right .y = params ["diffuse_color_t2" ][2 ]
190
151
191
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [3 ].co = (160.0 , params ["diffuse_color_t2" ][0 ])
192
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [3 ].handle_left .y = params ["diffuse_color_t2" ][0 ]
193
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [3 ].handle_right .y = params ["diffuse_color_t2" ][0 ]
152
+ # BACKGROUND COLORS (KEYFRAMES) ----------------------
153
+ action = bpy .data .actions ["Background.MaterialAc" ]
194
154
195
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 1 ]. keyframe_points [ 3 ]. co = ( 160.0 , params [ "diffuse_color_t2" ][ 1 ])
196
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 1 ]. keyframe_points [ 3 ]. handle_left . y = params ["diffuse_color_t2" ][ 1 ]
197
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 1 ]. keyframe_points [ 3 ]. handle_right . y = params ["diffuse_color_t2" ][ 1 ]
155
+ # TILE 1
156
+ update_curves ( action , 0 , 1.0 , params ["diffuse_color_t1" ])
157
+ update_curves ( action , 1 , 70.0 , params ["diffuse_color_t1" ])
198
158
199
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 2 ]. keyframe_points [ 3 ]. co = ( 160.0 , params [ "diffuse_color_t2" ][ 2 ])
200
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 2 ]. keyframe_points [ 3 ]. handle_left . y = params ["diffuse_color_t2" ][ 2 ]
201
- bpy . data . actions [ "Background.MaterialAc" ]. fcurves [ 2 ]. keyframe_points [ 3 ]. handle_right . y = params ["diffuse_color_t2" ][ 2 ]
159
+ # TILE 2
160
+ update_curves ( action , 2 , 120.0 , params ["diffuse_color_t2" ])
161
+ update_curves ( action , 3 , 160.0 , params ["diffuse_color_t2" ])
202
162
203
163
# TILE 3
204
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [4 ].co = (200.0 , params ["diffuse_color_t3" ][0 ])
205
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [4 ].handle_left .y = params ["diffuse_color_t3" ][0 ]
206
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [4 ].handle_right .y = params ["diffuse_color_t3" ][0 ]
207
-
208
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [4 ].co = (200.0 , params ["diffuse_color_t3" ][1 ])
209
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [4 ].handle_left .y = params ["diffuse_color_t3" ][1 ]
210
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [4 ].handle_right .y = params ["diffuse_color_t3" ][1 ]
211
-
212
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [4 ].co = (200.0 , params ["diffuse_color_t3" ][2 ])
213
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [4 ].handle_left .y = params ["diffuse_color_t3" ][2 ]
214
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [4 ].handle_right .y = params ["diffuse_color_t3" ][2 ]
215
-
216
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [5 ].co = (240.0 , params ["diffuse_color_t3" ][0 ])
217
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [5 ].handle_left .y = params ["diffuse_color_t3" ][0 ]
218
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [5 ].handle_right .y = params ["diffuse_color_t3" ][0 ]
219
-
220
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [5 ].co = (240.0 , params ["diffuse_color_t3" ][1 ])
221
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [5 ].handle_left .y = params ["diffuse_color_t3" ][1 ]
222
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [5 ].handle_right .y = params ["diffuse_color_t3" ][1 ]
223
-
224
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [5 ].co = (240.0 , params ["diffuse_color_t3" ][2 ])
225
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [5 ].handle_left .y = params ["diffuse_color_t3" ][2 ]
226
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [5 ].handle_right .y = params ["diffuse_color_t3" ][2 ]
164
+ update_curves (action , 4 , 200.0 , params ["diffuse_color_t3" ])
165
+ update_curves (action , 5 , 240.0 , params ["diffuse_color_t3" ])
227
166
228
167
# TILE 4
229
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [6 ].co = (300.0 , params ["diffuse_color_t4" ][0 ])
230
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [6 ].handle_left .y = params ["diffuse_color_t4" ][0 ]
231
- bpy .data .actions ["Background.MaterialAc" ].fcurves [0 ].keyframe_points [6 ].handle_right .y = params ["diffuse_color_t4" ][0 ]
232
-
233
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [6 ].co = (300.0 , params ["diffuse_color_t4" ][1 ])
234
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [6 ].handle_left .y = params ["diffuse_color_t4" ][1 ]
235
- bpy .data .actions ["Background.MaterialAc" ].fcurves [1 ].keyframe_points [6 ].handle_right .y = params ["diffuse_color_t4" ][1 ]
236
-
237
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [6 ].co = (300.0 , params ["diffuse_color_t4" ][2 ])
238
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [6 ].handle_left .y = params ["diffuse_color_t4" ][2 ]
239
- bpy .data .actions ["Background.MaterialAc" ].fcurves [2 ].keyframe_points [6 ].handle_right .y = params ["diffuse_color_t4" ][2 ]
240
-
168
+ update_curves (action , 6 , 300.0 , params ["diffuse_color_t4" ])
241
169
242
170
# Set the render options. It is important that these are set
243
171
# to the same values as the current OpenShot project. These
244
172
# params are automatically set by OpenShot
245
- bpy .context .scene .render .filepath = params ["output_path" ]
246
- bpy .context .scene .render .fps = params ["fps" ]
173
+ render = bpy .context .scene .render
174
+ render .filepath = params ["output_path" ]
175
+ render .fps = params ["fps" ]
247
176
if "fps_base" in params :
248
- bpy . context . scene . render .fps_base = params ["fps_base" ]
249
- bpy . context . scene . render .image_settings .file_format = params ["file_format" ]
250
- bpy . context . scene . render .image_settings .color_mode = params ["color_mode" ]
251
- bpy . context . scene . render .film_transparent = params ["alpha_mode" ]
177
+ render .fps_base = params ["fps_base" ]
178
+ render .image_settings .file_format = params ["file_format" ]
179
+ render .image_settings .color_mode = params ["color_mode" ]
180
+ render .film_transparent = params ["alpha_mode" ]
252
181
bpy .data .worlds [0 ].color = params ["horizon_color" ]
253
- bpy . context . scene . render .resolution_x = params ["resolution_x" ]
254
- bpy . context . scene . render .resolution_y = params ["resolution_y" ]
255
- bpy . context . scene . render .resolution_percentage = params ["resolution_percentage" ]
182
+ render .resolution_x = params ["resolution_x" ]
183
+ render .resolution_y = params ["resolution_y" ]
184
+ render .resolution_percentage = params ["resolution_percentage" ]
256
185
257
186
# Animation Speed (use Blender's time remapping to slow or speed up animation)
258
187
length_multiplier = int (params ["length_multiplier" ]) # time remapping multiplier
259
188
new_length = int (params ["end_frame" ]) * length_multiplier # new length (in frames)
260
- bpy . context . scene . render .frame_map_old = 1
261
- bpy . context . scene . render .frame_map_new = length_multiplier
189
+ render .frame_map_old = 1
190
+ render .frame_map_new = length_multiplier
262
191
263
192
# Set render length/position
264
193
bpy .context .scene .frame_start = params ["start_frame" ]
0 commit comments