Skip to content

Commit

Permalink
Added option to set AE Comp size.
Browse files Browse the repository at this point in the history
  • Loading branch information
BartekSkorupa committed Feb 23, 2018
1 parent 6184673 commit 31e5c6b
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions io_export_after_effects.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
"description": "Export cameras, selected objects & camera solution "
"3D Markers to Adobe After Effects CS3 and above",
"author": "Bartek Skorupa",
"version": (0, 64),
"blender": (2, 69, 0),
"version": (0, 65),
"blender": (2, 79, 0),
"location": "File > Export > Adobe After Effects (.jsx)",
"warning": "",
"wiki_url": "http://wiki.blender.org/index.php/Extensions:2.6/Py/"
Expand Down Expand Up @@ -150,7 +150,7 @@ def convert_name(name):

# get object's blender's location rotation and scale and return AE's Position, Rotation/Orientation and scale
# this function will be called for every object for every frame
def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=False):
def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=False, ae_size=100.0):

# get blender transform data for ob
b_loc = matrix.to_translation()
Expand All @@ -159,9 +159,9 @@ def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=Fal

# convert to AE Position Rotation and Scale
# 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.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
x = (b_loc.x * ae_size) / aspect + width / 2.0 # calculate AE's X position
y = (-b_loc.z * ae_size) + (height / 2.0) # calculate AE's Y position
z = b_loc.y * ae_size # calculate AE's Z position
# Convert rotations to match AE's orientation.
rx = degrees(b_rot.x) # if not x_rot_correction - AE's X orientation = blender's X rotation if 'ZYX' euler.
ry = -degrees(b_rot.y) # AE's Y orientation is negative blender's Y rotation if 'ZYX' euler
Expand Down Expand Up @@ -240,7 +240,7 @@ def convert_lens(camera, width, height, aspect):


# jsx script for AE creation
def write_jsx_file(file, data, selection, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles):
def write_jsx_file(file, data, selection, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles, ae_size):

print("\n---------------------------\n- Export to After Effects -\n---------------------------")
# store the current frame to restore it at the end of export
Expand Down Expand Up @@ -382,7 +382,7 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
# bundles are in camera space. Transpose to world space
matrix = Matrix.Translation(cam.matrix_basis.copy() * track.bundle)
# convert the position into AE space
ae_transform = convert_transform_matrix(matrix, data['width'], data['height'], data['aspect'], x_rot_correction=False)
ae_transform = convert_transform_matrix(matrix, data['width'], data['height'], data['aspect'], False, ae_size)
js_data['bundles_cam'][name_ae]['position'] += '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])

# get all keyframes for each object and store in dico
Expand All @@ -407,7 +407,7 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
# get cam name
name_ae = active_cam_name
# convert cam transform properties to AE space
ae_transform = convert_transform_matrix(active_cam.matrix_world.copy(), data['width'], data['height'], data['aspect'], x_rot_correction=True)
ae_transform = convert_transform_matrix(active_cam.matrix_world.copy(), data['width'], data['height'], data['aspect'], True, ae_size)
# convert Blender's lens to AE's zoom in pixels
zoom = convert_lens(active_cam, data['width'], data['height'], data['aspect'])
# store all values in dico
Expand Down Expand Up @@ -437,7 +437,7 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
# get cam name
name_ae = selection['cameras'][i][1]
# convert cam transform properties to AE space
ae_transform = convert_transform_matrix(cam[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], x_rot_correction=True)
ae_transform = convert_transform_matrix(cam[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], True, ae_size)
# convert Blender's lens to AE's zoom in pixels
zoom = convert_lens(cam[0], data['width'], data['height'], data['aspect'])
# store all values in dico
Expand Down Expand Up @@ -475,7 +475,7 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
name_ae = selection['lights'][i][1]
type = selection['lights'][i][0].data.type
# convert ob transform properties to AE space
ae_transform = convert_transform_matrix(ob[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], x_rot_correction=True)
ae_transform = convert_transform_matrix(ob[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], True, ae_size)
color = ob[0].data.color
# store all values in dico
position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
Expand Down Expand Up @@ -522,7 +522,7 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
# get object name
name_ae = selection['nulls'][i][1]
# convert ob transform properties to AE space
ae_transform = convert_transform_matrix(ob[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], x_rot_correction=True)
ae_transform = convert_transform_matrix(ob[0].matrix_world.copy(), data['width'], data['height'], data['aspect'], True, ae_size)
# store all values in dico
position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4], ae_transform[5])
Expand Down Expand Up @@ -676,10 +676,10 @@ def write_jsx_file(file, data, selection, include_animation, include_active_cam,
##########################################


def main(file, context, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles):
def main(file, context, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles, ae_size):
data = get_comp_data(context)
selection = get_selected(context)
write_jsx_file(file, data, selection, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles)
write_jsx_file(file, data, selection, include_animation, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles, ae_size)
print ("\nExport to After Effects Completed")
return {'FINISHED'}

Expand All @@ -688,7 +688,7 @@ def main(file, context, include_animation, include_active_cam, include_selected_
##########################################

from bpy_extras.io_utils import ExportHelper
from bpy.props import StringProperty, BoolProperty
from bpy.props import StringProperty, BoolProperty, FloatProperty


class ExportJsx(bpy.types.Operator, ExportHelper):
Expand Down Expand Up @@ -728,11 +728,18 @@ class ExportJsx(bpy.types.Operator, ExportHelper):
# description="Include 3D Markers of Object Motion Solution for selected cameras",
# default=True,
# )
ae_size = FloatProperty(
name="AE Size",
description="Size of AE Composition (pixels per 1BU)",
default=100.0,
)

def draw(self, context):
layout = self.layout

box = layout.box()
box.label('Size fo AE Comp (pixels per 1 BU)')
box.prop(self, 'ae_size')
box.label('Animation:')
box.prop(self, 'include_animation')
box.label('Include Cameras and Objects:')
Expand All @@ -752,7 +759,7 @@ def poll(cls, context):
return ok

def execute(self, context):
return main(self.filepath, context, self.include_animation, self.include_active_cam, self.include_selected_cams, self.include_selected_objects, self.include_cam_bundles)
return main(self.filepath, context, self.include_animation, self.include_active_cam, self.include_selected_cams, self.include_selected_objects, self.include_cam_bundles, self.ae_size)


def menu_func(self, context):
Expand Down

0 comments on commit 31e5c6b

Please sign in to comment.