[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2527] contrib/py/scripts/addons/ io_export_after_effects.py: - remove temp empty creation, just pass a matrix
Campbell Barton
ideasman42 at gmail.com
Wed Oct 26 01:35:06 CEST 2011
Revision: 2527
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2527
Author: campbellbarton
Date: 2011-10-25 23:35:05 +0000 (Tue, 25 Oct 2011)
Log Message:
-----------
- remove temp empty creation, just pass a matrix
- made pep8 compliant
Modified Paths:
--------------
contrib/py/scripts/addons/io_export_after_effects.py
Modified: contrib/py/scripts/addons/io_export_after_effects.py
===================================================================
--- contrib/py/scripts/addons/io_export_after_effects.py 2011-10-25 16:04:46 UTC (rev 2526)
+++ contrib/py/scripts/addons/io_export_after_effects.py 2011-10-25 23:35:05 UTC (rev 2527)
@@ -43,61 +43,58 @@
aspect = aspect_x / aspect_y
fps = bpy.context.scene.render.fps
- comp_data = {
- 'scn': bpy.context.scene,
- 'width': bpy.context.scene.render.resolution_x,
- 'height': bpy.context.scene.render.resolution_y,
- 'aspect': aspect,
- 'fps': fps,
- 'start': bpy.context.scene.frame_start,
- 'end': bpy.context.scene.frame_end,
- 'duration': (bpy.context.scene.frame_end-bpy.context.scene.frame_start + 1) / fps,
- 'curframe': bpy.context.scene.frame_current,
- }
+ return {
+ 'scn': bpy.context.scene,
+ 'width': bpy.context.scene.render.resolution_x,
+ 'height': bpy.context.scene.render.resolution_y,
+ 'aspect': aspect,
+ 'fps': fps,
+ 'start': bpy.context.scene.frame_start,
+ 'end': bpy.context.scene.frame_end,
+ 'duration': (bpy.context.scene.frame_end - bpy.context.scene.frame_start + 1.0) / fps,
+ 'curframe': bpy.context.scene.frame_current,
+ }
- return comp_data
-
# create managable list of selected objects
# (only selected objects will be analyzed and exported)
def get_selected(prefix):
cameras = [] # list of selected cameras
cams_names = [] # list of selected cameras' names (prevent from calling "ConvertName(ob)" function too many times)
- nulls = [] # list of all selected objects exept cameras (will be used to create nulls in AE)
+ nulls = [] # list of all selected objects exept cameras (will be used to create nulls in AE)
nulls_names = [] # list of above objects names (prevent from calling "ConvertName(ob)" function too many times)
obs = bpy.context.selected_objects
for ob in obs:
if ob.type == 'CAMERA':
cameras.append(ob)
- cams_names.append(convert_name(ob,prefix))
+ cams_names.append(convert_name(ob, prefix))
else:
nulls.append(ob)
- nulls_names.append(convert_name(ob,prefix))
+ nulls_names.append(convert_name(ob, prefix))
selection = {
- 'cameras': cameras,
- 'cams_names': cams_names,
- 'nulls': nulls,
- 'nulls_names': nulls_names,
- }
+ 'cameras': cameras,
+ 'cams_names': cams_names,
+ 'nulls': nulls,
+ 'nulls_names': nulls_names,
+ }
- return selection
+ return selection
# convert names of objects to avoid errors in AE. Add user specified prefix
def convert_name(ob, prefix):
ob_name = ob.name
- for c in [" ",".",",","-","=","+","*"]:
+ for c in (" ", ".", ",", "-", "=", "+", "*"):
ob_name = ob_name.replace(c, "_")
-
+
return prefix + ob_name
# get object's blender's location and rotation and return AE's Position and Rotation/Orientation
# this function will be called for every object for every frame
-def convert_pos_rot(obs, width, height, aspect, x_rot_correction = False):
- matrix = obs.matrix_world
+def convert_pos_rot_matrix(matrix, width, height, aspect, x_rot_correction=False):
# get blender location for ob
b_loc_x, b_loc_y, b_loc_z = matrix.to_translation()
@@ -105,26 +102,30 @@
# get blender rotation for ob
if x_rot_correction:
- b_rot_x = b_rot_x / pi * 180 - 90
+ b_rot_x = b_rot_x / pi * 180.0 - 90.0
else:
- b_rot_x = b_rot_x / pi * 180
- b_rot_y = b_rot_y / pi * 180
- b_rot_z = b_rot_z / pi * 180
+ b_rot_x = b_rot_x / pi * 180.0
+ b_rot_y = b_rot_y / pi * 180.0
+ b_rot_z = b_rot_z / pi * 180.0
# convert to AE Position and Rotation
# Axes in AE are different. AE's X is blender's X, AE's Y is negative Blender's Z, AE's Z is Blender's Y
- x = (b_loc_x * 100) / aspect + width / 2 #calculate AE's X position
- y = (-b_loc_z * 100) + (height / 2) #calculate AE's Y position
- z = b_loc_y * 100 #calculate AE's Z position
- rx = b_rot_x #calculate AE's X rotation. Will become AE's RotationX property
- ry = -b_rot_z #calculate AE's Y rotation. Will become AE's OrientationY property
- rz = b_rot_y #calculate AE's Z rotation. Will become AE's OrentationZ property
+ x = (b_loc_x * 100.0) / aspect + width / 2.0 # calculate AE's X position
+ y = (-b_loc_z * 100.0) + (height / 2.0) # calculate AE's Y position
+ z = b_loc_y * 100.0 # calculate AE's Z position
+ rx = b_rot_x # calculate AE's X rotation. Will become AE's RotationX property
+ ry = -b_rot_z # calculate AE's Y rotation. Will become AE's OrientationY property
+ rz = b_rot_y # calculate AE's Z rotation. Will become AE's OrentationZ property
# Using AE's rotation combined with AE's orientation allows to compensate for different euler rotation order.
- ae_pos_rot = [x, y, z, rx, ry, rz]
- return ae_pos_rot
+ return x, y, z, rx, ry, rz
+def convert_pos_rot(obj, width, height, aspect, x_rot_correction=False):
+ matrix = obj.matrix_world.copy()
+ return convert_pos_rot_matrix(matrix, width, height, aspect, x_rot_correction)
+
+
# get camera's lens and convert to AE's "zoom" value in pixels
# this function will be called for every camera for every frame
#
@@ -153,73 +154,75 @@
# | | \ |
# | | \ |
# | | |
-# lens | zoom
+# lens | zoom
#
# zoom/width = lens/sensor =>
# zoom = lens/sensor*width = lens*width * (1/sensor)
# sensor - sensor_width will be taken into account if version of blender supports it. If not - standard blender's 32mm will be caclulated.
-#
-#
+#
+#
# above is true if square pixels are used. If not - aspect compensation is needed, so final formula is:
# zoom = lens * width * (1/sensor) * aspect
#
def convert_lens(camera, width, aspect):
# wrap camera.data.sensor_width in 'try' to maintain compatibility with blender version not supporting camera.data.sensor_width
try:
- sensor = camera.data.sensor_width #if camera.data.sensor_width is supported - it will be taken into account
+ sensor = camera.data.sensor_width # if camera.data.sensor_width is supported - it will be taken into account
except:
- sensor = 32 #if version of blender doesn't yet support sensor_width - default blender's 32mm will be taken.
- zoom = camera.data.lens * width * (1/sensor) * aspect
+ sensor = 32 # if version of blender doesn't yet support sensor_width - default blender's 32mm will be taken.
+ zoom = camera.data.lens * width * (1.0 / sensor) * aspect
return zoom
# jsx script for AE creation
def write_jsx_file(file, data, selection, export_bundles, comp_name, prefix):
+ from mathutils import Matrix
+
print("\n---------------------------\n- Export to After Effects -\n---------------------------")
#store the current frame to restore it at the enf of export
curframe = data['curframe']
#create array which will contain all keyframes values
js_data = {
- 'times': '',
- 'cameras': {},
- 'objects': {},
- }
+ 'times': '',
+ 'cameras': {},
+ 'objects': {},
+ }
# create camera structure
- for i, cam in enumerate (selection['cameras']): #more than one camera can be selected
+ for i, cam in enumerate(selection['cameras']): # more than one camera can be selected
name_ae = selection['cams_names'][i]
js_data['cameras'][name_ae] = {
- 'position': '',
- 'pointOfInterest': '',
- 'orientation': '',
- 'rotationX': '',
- 'zoom': '',
- }
-
+ 'position': '',
+ 'pointOfInterest': '',
+ 'orientation': '',
+ 'rotationX': '',
+ 'zoom': '',
+ }
+
# create object structure
- for i, obj in enumerate (selection['nulls']): #nulls representing blender's obs except cameras
+ for i, obj in enumerate(selection['nulls']): # nulls representing blender's obs except cameras
name_ae = selection['nulls_names'][i]
js_data['objects'][name_ae] = {
- 'position': '',
- 'orientation': '',
- 'rotationX': '',
- }
+ 'position': '',
+ 'orientation': '',
+ 'rotationX': '',
+ }
# get all keyframes for each objects and store into dico
- for frame in range(data['start'],data['end'] + 1):
+ for frame in range(data['start'], data['end'] + 1):
print("working on frame: " + str(frame))
data['scn'].frame_set(frame)
-
+
#get time for this loop
- js_data['times'] += '%f ,' % float((frame-data['start']) / (data['fps']));
+ js_data['times'] += '%f ,' % ((frame - data['start']) / data['fps'])
# keyframes for all cameras
- for i, cam in enumerate (selection['cameras']):
+ for i, cam in enumerate(selection['cameras']):
#get cam name
name_ae = selection['cams_names'][i]
#convert cam position to AE space
- ae_pos_rot = convert_pos_rot(cam, data['width'], data['height'], data['aspect'], x_rot_correction = True)
+ ae_pos_rot = convert_pos_rot(cam, data['width'], data['height'], data['aspect'], x_rot_correction=True)
#convert Blender's cam zoom to AE's
zoom = convert_lens(cam, data['width'], data['aspect'])
#store all the value into dico
@@ -228,22 +231,21 @@
js_data['cameras'][name_ae]['orientation'] += '[%f,%f,%f],' % (0, ae_pos_rot[4], ae_pos_rot[5])
js_data['cameras'][name_ae]['rotationX'] += '%f ,' % (ae_pos_rot[3])
js_data['cameras'][name_ae]['zoom'] += '[%f],' % (zoom)
-
+
#keyframes for all nulls
- for i, ob in enumerate (selection['nulls']):
+ for i, ob in enumerate(selection['nulls']):
#get object name
name_ae = selection['nulls_names'][i]
#convert ob position to AE space
- ae_pos_rot = convert_pos_rot(ob, data['width'], data['height'], data['aspect'], x_rot_correction = False)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list