1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
|
# OpenShot Video Editor is a program that creates, modifies, and edits video files.
# Copyright (C) 2009 Jonathan Thomas
#
# This file is part of OpenShot Video Editor (http://launchpad.net/openshot/).
#
# OpenShot Video Editor is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# OpenShot Video Editor is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with OpenShot Video Editor. If not, see <http://www.gnu.org/licenses/>.
# Import Blender's python API. This only works when the script is being
# run from the context of Blender. Blender contains it's own version of Python
# with this library pre-installed.
import bpy
# Debug Info:
# ./blender -b test.blend -P demo.py
# -b = background mode
# -P = run a Python script within the context of the project file
# Init all of the variables needed by this script. Because Blender executes
# this script, OpenShot will inject a dictionary of the required parameters
# before this script is executed.
params = {
'title' : 'Oh Yeah! OpenShot!',
'extrude' : 0.1,
'bevel_depth' : 0.02,
'spacemode' : 'CENTER',
'text_size' : 1.5,
'width' : 1.0,
'fontname' : 'Bfont',
'color' : [0.8,0.8,0.8],
'alpha' : 1.0,
'alpha_mode' : 'TRANSPARENT',
'output_path' : '/tmp/',
'fps' : 24,
'quality' : 90,
'file_format' : 'PNG',
'color_mode' : 'RGBA',
'horizon_color' : [0.57, 0.57, 0.57],
'resolution_x' : 1920,
'resolution_y' : 1080,
'resolution_percentage' : 100,
'start_frame' : 20,
'end_frame' : 25,
'animation' : True,
}
#INJECT_PARAMS_HERE
# The remainder of this script will modify the current Blender .blend project
# file, and adjust the settings. The .blend file is specified in the XML file
# that defines this template in OpenShot.
#----------------------------------------------------------------------------
# Modify the Location of the Wand
sphere_object = bpy.data.objects["Sphere"]
sphere_object.location = [params["start_x"], params["start_y"], params["start_z"]]
# Modify the Start and End keyframes
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[0].co = (1.0, params["start_x"])
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[0].handle_left.y = params["start_x"]
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[0].handle_right.y = params["start_x"]
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[0].co = (1.0, params["start_y"])
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[0].handle_left.y = params["start_y"]
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[0].handle_right.y = params["start_y"]
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[0].co = (1.0, params["start_z"])
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[0].handle_left.y = params["start_z"]
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[0].handle_right.y = params["start_z"]
#################
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[1].co = (300.0, params["end_x"])
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[1].handle_left.y = params["end_x"]
bpy.data.actions["SphereAction"].fcurves[0].keyframe_points[1].handle_right.y = params["end_x"]
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[1].co = (300.0, params["end_y"])
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[1].handle_left.y = params["end_y"]
bpy.data.actions["SphereAction"].fcurves[1].keyframe_points[1].handle_right.y = params["end_y"]
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[1].co = (300.0, params["end_z"])
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[1].handle_left.y = params["end_z"]
bpy.data.actions["SphereAction"].fcurves[2].keyframe_points[1].handle_right.y = params["end_z"]
# Modfiy the Material Keyframe (i.e. the keyframed halo size setting)
bpy.data.actions["Material.001Action"].fcurves[0].keyframe_points[0].co = (1.0, params["start_halo_size"])
bpy.data.actions["Material.001Action"].fcurves[0].keyframe_points[1].co = (300.00, params["end_halo_size"])
# Change the material settings (color, alpha, etc...)
material_object = bpy.data.materials["Material.001"]
material_object.diffuse_color = params["diffuse_color"]
material_object.specular_color = params["specular_color"]
material_object.mirror_color = params["mirror_color"]
material_object.alpha = params["alpha"]
# Change Composite Node settings
sun_glare_node = bpy.data.scenes[0].node_tree.nodes["Glare"]
sun_glare_node.color_modulation = params["sun_glare_color"]
sun_glare_node.glare_type = params["sun_glare_type"]
sun_glare_node.streaks = params["sun_streaks"]
sun_glare_node.angle_offset = params["sun_angle_offset"]
spots_glare_node = bpy.data.scenes[0].node_tree.nodes["Glare.000"]
spots_glare_node.color_modulation = params["spots_glare_color"]
# Change Halo settings
material_object.halo.size = params["start_halo_size"]
material_object.halo.hardness = params["halo_hardness"]
if params["halo_use_lines"] == "Yes":
material_object.halo.use_lines = True
else:
material_object.halo.use_lines = False
material_object.halo.line_count = params["halo_line_count"]
if params["halo_use_ring"] == "Yes":
material_object.halo.use_ring = True
else:
material_object.halo.use_ring = False
material_object.halo.ring_count = params["halo_ring_count"]
if params["halo_use_star"] == "Yes":
material_object.halo.use_star = True
else:
material_object.halo.use_star = False
material_object.halo.star_tip_count = params["halo_star_tip_count"]
# Set the render options. It is important that these are set
# to the same values as the current OpenShot project. These
# params are automatically set by OpenShot
bpy.context.scene.render.filepath = params["output_path"]
bpy.context.scene.render.fps = params["fps"]
#bpy.context.scene.render.quality = params["quality"]
try:
bpy.context.scene.render.file_format = params["file_format"]
bpy.context.scene.render.color_mode = params["color_mode"]
except:
bpy.context.scene.render.image_settings.file_format = params["file_format"]
bpy.context.scene.render.image_settings.color_mode = params["color_mode"]
# Set background transparency (SKY or TRANSPARENT)
try:
bpy.context.scene.render.alpha_mode = params["alpha_mode"]
except:
pass
bpy.context.scene.render.resolution_x = params["resolution_x"]
bpy.context.scene.render.resolution_y = params["resolution_y"]
bpy.context.scene.render.resolution_percentage = params["resolution_percentage"]
bpy.context.scene.frame_start = params["start_frame"]
bpy.context.scene.frame_end = params["end_frame"]
# Animation Speed (use Blender's time remapping to slow or speed up animation)
animation_speed = int(params["animation_speed"]) # time remapping multiplier
new_length = int(params["end_frame"]) * animation_speed # new length (in frames)
bpy.context.scene.frame_end = new_length
bpy.context.scene.render.frame_map_old = 1
bpy.context.scene.render.frame_map_new = animation_speed
if params["start_frame"] == params["end_frame"]:
bpy.context.scene.frame_start = params["end_frame"]
bpy.context.scene.frame_end = params["end_frame"]
# Render the current animation to the params["output_path"] folder
bpy.ops.render.render(animation=params["animation"])
|