[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3091] trunk/py/scripts/addons/ io_export_after_effects.py: Version 0.6.3: Changed the way of transfering rotations.

Bartek Skorupa bartekskorupa at bartekskorupa.com
Mon Mar 12 23:12:59 CET 2012


Revision: 3091
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3091
Author:   bartekskorupa
Date:     2012-03-12 22:12:47 +0000 (Mon, 12 Mar 2012)
Log Message:
-----------
Version 0.6.3: Changed the way of transfering rotations. Now Blender's rotation is represented by After Effects Orientation only by using ZYX euler rotation order. Not necessary to use AE's Rotation X property anymore

Modified Paths:
--------------
    trunk/py/scripts/addons/io_export_after_effects.py

Modified: trunk/py/scripts/addons/io_export_after_effects.py
===================================================================
--- trunk/py/scripts/addons/io_export_after_effects.py	2012-03-12 16:04:00 UTC (rev 3090)
+++ trunk/py/scripts/addons/io_export_after_effects.py	2012-03-12 22:12:47 UTC (rev 3091)
@@ -22,7 +22,7 @@
     'name': 'Export: Adobe After Effects (.jsx)',
     'description': 'Export cameras, selected objects & camera solution 3D Markers to Adobe After Effects CS3 and above',
     'author': 'Bartek Skorupa',
-    'version': (0, 6, 2),
+    'version': (0, 6, 3),
     'blender': (2, 6, 2),
     'location': 'File > Export > Adobe After Effects (.jsx)',
     "warning": "",
@@ -36,7 +36,7 @@
 
 import bpy
 import datetime
-from math import pi
+from math import degrees
 from mathutils import Matrix
 
 
@@ -154,29 +154,25 @@
 def convert_transform_matrix(matrix, width, height, aspect, x_rot_correction=False):
 
     # get blender transform data for ob
-    b_loc_x, b_loc_y, b_loc_z = matrix.to_translation()
-    b_rot_x, b_rot_y, b_rot_z = matrix.to_euler()
-    b_scale_x, b_scale_y, b_scale_z = matrix.to_scale()
+    b_loc = matrix.to_translation()
+    b_rot = matrix.to_euler('ZYX')  # ZYX euler matches AE's orientation and allows to use x_rot_correction
+    b_scale = matrix.to_scale()
 
-    # convert radians to degrees
-    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
-    if x_rot_correction:
-        b_rot_x -= 90.0
-
     # 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
-    # Using AE's rotation combined with AE's orientation allows to compensate for different euler rotation order.
-    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
-    sx = b_scale_x * 100.0  # scale of 1.0 is 100% in AE
-    sy = b_scale_z * 100.0  # scale of 1.0 is 100% in AE
-    sz = b_scale_y * 100.0  # scale of 1.0 is 100% in AE
+    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
+    # 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
+    rz = -degrees(b_rot.z)  # AE's Z orientation is negative blender's Z rotation if 'ZYX' euler
+    if x_rot_correction:
+        rx -= 90.0  # In blender - ob of zero rotation lay on floor. In AE layer of zero orientation "stands"
+    # Convert scale to AE scale
+    sx = b_scale.x * 100.0  # scale of 1.0 is 100% in AE
+    sy = b_scale.z * 100.0  # scale of 1.0 is 100% in AE
+    sz = b_scale.y * 100.0  # scale of 1.0 is 100% in AE
 
     return x, y, z, rx, ry, rz, sx, sy, sz
 
@@ -277,9 +273,6 @@
             'orientation': '',
             'orientation_static': '',
             'orientation_anim': False,
-            'rotationX': '',
-            'rotationX_static': '',
-            'rotationX_anim': False,
             'zoom': '',
             'zoom_static': '',
             'zoom_anim': False,
@@ -297,9 +290,6 @@
                     'orientation': '',
                     'orientation_static': '',
                     'orientation_anim': False,
-                    'rotationX': '',
-                    'rotationX_static': '',
-                    'rotationX_anim': False,
                     'zoom': '',
                     'zoom_static': '',
                     'zoom_anim': False,
@@ -339,9 +329,6 @@
                 'orientation': '',
                 'orientation_static': '',
                 'orientation_anim': False,
-                'rotationX': '',
-                'rotationX_static': '',
-                'rotationX_anim': False,
                 }
 
 
@@ -356,9 +343,6 @@
                 'orientation': '',
                 'orientation_static': '',
                 'orientation_anim': False,
-                'rotationX': '',
-                'rotationX_static': '',
-                'rotationX_anim': False,
                 'scale': '',
                 'scale_static': '',
                 'scale_anim': False,
@@ -430,12 +414,10 @@
             zoom = convert_lens(active_cam, data['width'], data['height'], data['aspect'])
             # store all values in dico
             position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
-            orientation = '[%f,%f,%f],' % (0, ae_transform[4], ae_transform[5])
-            rotationX = '%f ,' % (ae_transform[3])
+            orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4], ae_transform[5])
             zoom = '%f,' % (zoom)
             js_data['cameras'][name_ae]['position'] += position
             js_data['cameras'][name_ae]['orientation'] += orientation
-            js_data['cameras'][name_ae]['rotationX'] += rotationX
             js_data['cameras'][name_ae]['zoom'] += zoom
             # Check if properties change values compared to previous frame
             # If property don't change through out the whole animation - keyframes won't be added
@@ -444,13 +426,10 @@
                     js_data['cameras'][name_ae]['position_anim'] = True
                 if orientation != js_data['cameras'][name_ae]['orientation_static']:
                     js_data['cameras'][name_ae]['orientation_anim'] = True
-                if rotationX != js_data['cameras'][name_ae]['rotationX_static']:
-                    js_data['cameras'][name_ae]['rotationX_anim'] = True
                 if zoom != js_data['cameras'][name_ae]['zoom_static']:
                     js_data['cameras'][name_ae]['zoom_anim'] = True
             js_data['cameras'][name_ae]['position_static'] = position
             js_data['cameras'][name_ae]['orientation_static'] = orientation
-            js_data['cameras'][name_ae]['rotationX_static'] = rotationX
             js_data['cameras'][name_ae]['zoom_static'] = zoom
 
         # keyframes for selected cameras
@@ -465,12 +444,10 @@
                     zoom = convert_lens(cam[0], data['width'], data['height'], data['aspect'])
                     # store all values in dico
                     position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
-                    orientation = '[%f,%f,%f],' % (0, ae_transform[4], ae_transform[5])
-                    rotationX = '%f ,' % (ae_transform[3])
+                    orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4], ae_transform[5])
                     zoom = '%f,' % (zoom)
                     js_data['cameras'][name_ae]['position'] += position
                     js_data['cameras'][name_ae]['orientation'] += orientation
-                    js_data['cameras'][name_ae]['rotationX'] += rotationX
                     js_data['cameras'][name_ae]['zoom'] += zoom
                     # Check if properties change values compared to previous frame
                     # If property don't change through out the whole animation - keyframes won't be added
@@ -479,13 +456,10 @@
                             js_data['cameras'][name_ae]['position_anim'] = True
                         if orientation != js_data['cameras'][name_ae]['orientation_static']:
                             js_data['cameras'][name_ae]['orientation_anim'] = True
-                        if rotationX != js_data['cameras'][name_ae]['rotationX_static']:
-                            js_data['cameras'][name_ae]['rotationX_anim'] = True
                         if zoom != js_data['cameras'][name_ae]['zoom_static']:
                             js_data['cameras'][name_ae]['zoom_anim'] = True
                     js_data['cameras'][name_ae]['position_static'] = position
                     js_data['cameras'][name_ae]['orientation_static'] = orientation
-                    js_data['cameras'][name_ae]['rotationX_static'] = rotationX
                     js_data['cameras'][name_ae]['zoom_static'] = zoom
     
         '''
@@ -507,13 +481,11 @@
                 color = ob[0].data.color
                 # store all values in dico
                 position = '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
-                orientation = '[%f,%f,%f],' % (0, ae_transform[4], ae_transform[5])
-                rotationX = '%f ,' % (ae_transform[3])
+                orientation = '[%f,%f,%f],' % (ae_transform[3], ae_transform[4], ae_transform[5])
                 energy = '[%f],' % (ob[0].data.energy * 100.0)
                 color = '[%f,%f,%f],' % (color[0], color[1], color[2])
                 js_data['lights'][name_ae]['position'] += position
                 js_data['lights'][name_ae]['orientation'] += orientation
-                js_data['lights'][name_ae]['rotationX'] += rotationX
                 js_data['lights'][name_ae]['energy'] += energy
                 js_data['lights'][name_ae]['color'] += color
                 # Check if properties change values compared to previous frame
@@ -523,15 +495,12 @@
                         js_data['lights'][name_ae]['position_anim'] = True
                     if orientation != js_data['lights'][name_ae]['orientation_static']:
                         js_data['lights'][name_ae]['orientation_anim'] = True
-                    if rotationX != js_data['lights'][name_ae]['rotationX_static']:
-                        js_data['lights'][name_ae]['rotationX_anim'] = True
                     if energy != js_data['lights'][name_ae]['energy_static']:
                         js_data['lights'][name_ae]['energy_anim'] = True
                     if color != js_data['lights'][name_ae]['color_static']:
                         js_data['lights'][name_ae]['color_anim'] = True
                 js_data['lights'][name_ae]['position_static'] = position

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list