@@ -49,11 +49,14 @@ def load_font(font_path):
49
49
# @param
50
50
# @return
51
51
#
52
- def createDissolveText (title , extrude , bevel_depth , spacemode , textsize , width , font ):
52
+ def createDissolveText (title , extrude , bevel_depth , spacemode , textsize , width , font , frame_count ):
53
53
""" Create aned animate the exploding texte """
54
54
55
55
# create text
56
- bpy .ops .object .text_add (radius = 1.0 , enter_editmode = False , align = 'WORLD' , location = (0.0 , 0.0 , 0.0 ), rotation = (0.0 , 0.0 , 0.0 ))
56
+ bpy .ops .object .text_add (
57
+ radius = 1.0 , enter_editmode = False , align = 'WORLD' ,
58
+ location = (0.0 , 0.0 , 0.0 ), rotation = (0.0 , 0.0 , 0.0 )
59
+ )
57
60
ActiveObjectText = bpy .context .view_layer .objects .active
58
61
59
62
# naming/renaming the text element
@@ -112,8 +115,8 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
112
115
# Particle parameters
113
116
ActiveObjectText .particle_systems [0 ].settings .count = NbQuads
114
117
ActiveObjectText .particle_systems [0 ].settings .frame_start = 10
115
- ActiveObjectText .particle_systems [0 ].settings .frame_end = 60
116
- ActiveObjectText .particle_systems [0 ].settings .lifetime = 120
118
+ ActiveObjectText .particle_systems [0 ].settings .frame_end = int ( frame_count * 0.75 - 10 )
119
+ ActiveObjectText .particle_systems [0 ].settings .lifetime = int ( frame_count * 0.25 + 10 )
117
120
ActiveObjectText .particle_systems [0 ].point_cache .frame_step = 1
118
121
ActiveObjectText .particle_systems [0 ].settings .normal_factor = 0.0
119
122
# not useful
@@ -126,7 +129,10 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
126
129
ActiveObjectText .particle_systems [0 ].settings .courant_target = 0.2
127
130
128
131
# Adding Wind force field on center and rotate it -90 on Y
129
- bpy .ops .object .effector_add (type = 'WIND' , radius = 1.0 , enter_editmode = False , align = 'WORLD' , location = (0.0 , 0.0 , 0.0 ), rotation = (0 , - pi / 2 , 0 ))
132
+ bpy .ops .object .effector_add (
133
+ type = 'WIND' , radius = 1.0 , enter_editmode = False , align = 'WORLD' ,
134
+ location = (0.0 , 0.0 , 0.0 ), rotation = (0 , - pi / 2 , 0 )
135
+ )
130
136
ActiveObjectWindField = bpy .context .view_layer .objects .active
131
137
ActiveObjectWindField .name = 'WindField'
132
138
# settings
@@ -139,7 +145,10 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
139
145
ActiveObjectWindField .field .use_absorption = False
140
146
141
147
# Adding Turbulence Force Field
142
- bpy .ops .object .effector_add (type = 'TURBULENCE' , radius = 1.0 , enter_editmode = False , align = 'WORLD' , location = (0.0 , 0.0 , 0.0 ), rotation = (0 , 0 , 0 ))
148
+ bpy .ops .object .effector_add (
149
+ type = 'TURBULENCE' , radius = 1.0 , enter_editmode = False , align = 'WORLD' ,
150
+ location = (0.0 , 0.0 , 0.0 ), rotation = (0 , 0 , 0 )
151
+ )
143
152
ActiveObjectTurbulenceField = bpy .context .view_layer .objects .active
144
153
ActiveObjectTurbulenceField .name = 'TurbulenceField'
145
154
# settings
@@ -164,24 +173,23 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
164
173
165
174
TexSlot = ActiveObjectText .particle_systems [0 ].settings .texture_slots .add ()
166
175
TexSlot .texture = sTex
176
+ TexSlot .use_map_time = True
167
177
168
178
bpy .ops .object .select_all (action = 'DESELECT' )
169
179
170
180
# Create plane for controlling action of particle system (based on time)
171
181
# if text is created on the fly 'Wipe' texture does not work! don't know really why!
172
182
# so use of an existing plane, and resize it to the text x dimension
173
- bpy .ops .mesh .primitive_plane_add (size = 2.0 , calc_uvs = True , enter_editmode = False , align = 'WORLD' , location = (0.0 , 0.0 , 0.0 ), rotation = (pi / 2 , 0 , 0 ))
183
+ bpy .ops .mesh .primitive_plane_add (
184
+ size = 2.0 , calc_uvs = True , enter_editmode = False , align = 'WORLD' ,
185
+ location = (0.0 , 0.0 , 0.0 ), rotation = (pi / 2 , 0 , 0 )
186
+ )
174
187
ActiveObjectPlane = bpy .context .view_layer .objects .active
175
188
ActiveObjectPlane .name = 'Plane'
176
189
# Change dimensions
177
190
ActiveObjectPlane .dimensions = ((ActiveObjectText .dimensions [0 ] * 1.2 ), (ActiveObjectText .dimensions [1 ] * 1.2 ), 0 )
178
191
# hide plane for render
179
192
ActiveObjectPlane .hide_render = True
180
- # show as wire in 3D
181
- # TODO: Not sure how to convert draw_type = 'WIRE'. Some ideas below.
182
- #ActiveObjectPlane.render_type = 'LINE'
183
- #ActiveObjectPlane.display_type = 'WIRE'
184
- #ActiveObjectPlane.show_wire = True
185
193
186
194
bpy .ops .object .select_all (action = 'DESELECT' )
187
195
@@ -197,6 +205,7 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
197
205
bpy .ops .object .modifier_add (type = 'EXPLODE' )
198
206
bpy .ops .mesh .uv_texture_add () # name UVMap by default
199
207
ActiveObjectText .modifiers ['Explode' ].particle_uv = 'UVMap'
208
+ ActiveObjectText .modifiers ['Explode' ].show_dead = False
200
209
ActiveObjectText .data .update ()
201
210
202
211
# Don't forget to deselect before select!
@@ -264,41 +273,47 @@ def createDissolveText(title, extrude, bevel_depth, spacemode, textsize, width,
264
273
# Get default font
265
274
font = bpy .data .fonts ["Bfont" ]
266
275
276
+ # Compute animation length
277
+ length_multiplier = int (params ["length_multiplier" ]) # time remapping multiplier
278
+ frame_count = int (params ["end_frame" ]) * length_multiplier # new length (in frames)
279
+
267
280
# Create dissolve text changes (slow)
268
- createDissolveText (params ["title" ], params ["extrude" ], params ["bevel_depth" ], params ["spacemode" ], params ["text_size" ], params ["width" ], font )
281
+ createDissolveText (
282
+ params ["title" ], params ["extrude" ], params ["bevel_depth" ],
283
+ params ["spacemode" ], params ["text_size" ], params ["width" ], font , frame_count
284
+ )
269
285
270
286
# Change the material settings (color, alpha, etc...)
271
287
material_object = bpy .data .materials ["DissolveMaterial" ]
272
- print (material_object )
273
288
material_object .node_tree .nodes [1 ].inputs [17 ].default_value = params ["diffuse_color" ]
274
289
material_object = bpy .data .materials ["TextMaterial" ]
275
- print (material_object )
276
290
material_object .node_tree .nodes [1 ].inputs [17 ].default_value = params ["diffuse_color" ]
277
291
278
292
# Set the render options. It is important that these are set
279
293
# to the same values as the current OpenShot project. These
280
294
# params are automatically set by OpenShot
281
295
bpy .context .scene .render .filepath = params ["output_path" ]
282
296
bpy .context .scene .render .fps = params ["fps" ]
297
+ if "fps_base" in params :
298
+ bpy .context .scene .render .fps_base = params ["fps_base" ]
283
299
bpy .context .scene .render .image_settings .file_format = params ["file_format" ]
284
300
bpy .context .scene .render .image_settings .color_mode = params ["color_mode" ]
285
301
bpy .context .scene .render .film_transparent = params ["alpha_mode" ]
286
302
bpy .data .worlds [0 ].color = params ["horizon_color" ]
287
303
bpy .context .scene .render .resolution_x = params ["resolution_x" ]
288
304
bpy .context .scene .render .resolution_y = params ["resolution_y" ]
289
305
bpy .context .scene .render .resolution_percentage = params ["resolution_percentage" ]
290
- bpy .context .scene .frame_start = params ["start_frame" ]
291
- bpy .context .scene .frame_end = params ["end_frame" ]
292
306
293
- # Animation Speed (use Blender's time remapping to slow or speed up animation)
294
- length_multiplier = int (params ["length_multiplier" ]) # time remapping multiplier
295
- new_length = int (params ["end_frame" ]) * length_multiplier # new length (in frames)
296
- bpy .context .scene .frame_end = new_length
297
- bpy .context .scene .render .frame_map_old = 1
298
- bpy .context .scene .render .frame_map_new = length_multiplier
299
- if params ["start_frame" ] == params ["end_frame" ]:
300
- bpy .context .scene .frame_start = params ["end_frame" ]
301
- bpy .context .scene .frame_end = params ["end_frame" ]
307
+ # Unbake particle cache
308
+ bpy .ops .ptcache .free_bake_all ()
309
+
310
+ # Set render length/position
311
+ if "preview_frame" in params :
312
+ bpy .context .scene .frame_start = params ["preview_frame" ]
313
+ bpy .context .scene .frame_end = params ["preview_frame" ]
314
+ else :
315
+ bpy .context .scene .frame_start = params ["start_frame" ]
316
+ bpy .context .scene .frame_end = frame_count
302
317
303
318
# Render the current animation to the params["output_path"] folder
304
319
bpy .ops .render .render (animation = params ["animation" ])
0 commit comments