[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2885] trunk/py/scripts/addons/ io_export_after_effects.py: Last changes were accidentaly reverted.

Bartek Skorupa bartekskorupa at bartekskorupa.com
Wed Jan 11 15:12:42 CET 2012


Revision: 2885
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2885
Author:   bartekskorupa
Date:     2012-01-11 14:12:41 +0000 (Wed, 11 Jan 2012)
Log Message:
-----------
Last changes were accidentaly reverted. Bringing them back.

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-01-11 13:56:48 UTC (rev 2884)
+++ trunk/py/scripts/addons/io_export_after_effects.py	2012-01-11 14:12:41 UTC (rev 2885)
@@ -62,7 +62,7 @@
 
 # create managable list of selected objects
 # (only selected objects will be analyzed and exported)
-def get_selected(context, prefix):
+def get_selected(context):
     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)
@@ -72,11 +72,17 @@
     for ob in obs:
         if ob.type == 'CAMERA':
             cameras.append(ob)
-            cams_names.append(convert_name(False, ob, prefix))
+            cams_names.append(convert_name(False, ob))
         else:
             nulls.append(ob)
-            nulls_names.append(convert_name(False, ob, prefix))
-
+            nulls_names.append(convert_name(False, ob))
+    # If no camera is selected - export at least scene's camera if exists
+    if not cameras:
+        cam = context.scene.camera
+        if cam:
+            cameras.append(cam)
+            cams_names.append(convert_name(False, cam))
+    
     selection = {
         'cameras': cameras,
         'cams_names': cams_names,
@@ -87,13 +93,13 @@
     return selection
 
 
-# convert names of objects to avoid errors in AE. Add user specified prefix
-def convert_name(is_comp, ob, prefix):
+# convert names of objects to avoid errors in AE.
+def convert_name(is_comp, ob):
     if is_comp:
-        ob_name = prefix + ob
+        ob_name = ob
         ob_name = ob_name.replace('"', "_")
     else:
-        ob_name = prefix + "_" + ob.name
+        ob_name = "_" + ob.name
 
         if ob_name[0].isdigit():
             ob_name = "_" + ob_name
@@ -106,11 +112,12 @@
 
 # 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_matrix(matrix, width, height, aspect, x_rot_correction=False):
+def convert_transform_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()
     b_rot_x, b_rot_y, b_rot_z = matrix.to_euler()
+    b_scale_x, b_scale_y, b_scale_z = matrix.to_scale()
 
     # get blender rotation for ob
     if x_rot_correction:
@@ -125,17 +132,20 @@
     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
-    # Using AE's rotation combined with AE's orientation allows to compensate for different euler rotation order.
+    sx = b_scale_x * 100.0
+    sy = b_scale_z * 100.0
+    sz = b_scale_y * 100.0
 
-    return x, y, z, rx, ry, rz
+    return x, y, z, rx, ry, rz, sx, sy, sz
 
 
-def convert_pos_rot(obj, width, height, aspect, x_rot_correction=False):
+def convert_transform(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)
+    return convert_transform_matrix(matrix, width, height, aspect, x_rot_correction)
 
 
 # get camera's lens and convert to AE's "zoom" value in pixels
@@ -184,15 +194,11 @@
 #    zoom = lens * dimension / sensor * aspect
 #
 def convert_lens(camera, width, height, aspect):
-    if hasattr(camera.data, "sensor_width"):  # Preserve compatibility with versions not supporting camera sensor.
-        if camera.data.sensor_fit == 'VERTICAL':
-            sensor = camera.data.sensor_height
-            dimension = height
-        else:
-            sensor = camera.data.sensor_width
-            dimension = width
+    if camera.data.sensor_fit == 'VERTICAL':
+        sensor = camera.data.sensor_height
+        dimension = height
     else:
-        sensor = 32  # standard blender's sensor size
+        sensor = camera.data.sensor_width
         dimension = width
     
     zoom = camera.data.lens * dimension / sensor * aspect
@@ -201,7 +207,7 @@
 
 
 # jsx script for AE creation
-def write_jsx_file(file, data, selection, export_bundles, comp_name, prefix):
+def write_jsx_file(file, data, selection, export_bundles, include_rotation, include_scale):
     from mathutils import Matrix
 
     print("\n---------------------------\n- Export to After Effects -\n---------------------------")
@@ -232,6 +238,7 @@
             'position': '',
             'orientation': '',
             'rotationX': '',
+            'scale': '',
             }
 
     # get all keyframes for each objects and store into dico
@@ -247,14 +254,14 @@
             #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_transform = convert_transform(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['height'], data['aspect'])
             #store all the value into dico
-            js_data['cameras'][name_ae]['position'] += '[%f,%f,%f],' % (ae_pos_rot[0], ae_pos_rot[1], ae_pos_rot[2])
-            js_data['cameras'][name_ae]['pointOfInterest'] += '[%f,%f,%f],' % (ae_pos_rot[0], ae_pos_rot[1], ae_pos_rot[2])
-            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]['position'] += '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
+            js_data['cameras'][name_ae]['pointOfInterest'] += '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
+            js_data['cameras'][name_ae]['orientation'] += '[%f,%f,%f],' % (0, ae_transform[4], ae_transform[5])
+            js_data['cameras'][name_ae]['rotationX'] += '%f ,' % (ae_transform[3])
             js_data['cameras'][name_ae]['zoom'] += '[%f],' % (zoom)
 
         #keyframes for all nulls
@@ -262,11 +269,14 @@
             #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)
+            ae_transform = convert_transform(ob, data['width'], data['height'], data['aspect'], x_rot_correction=False)
             #store all datas into dico
-            js_data['objects'][name_ae]['position'] += '[%f,%f,%f],' % (ae_pos_rot[0], ae_pos_rot[1], ae_pos_rot[2])
-            js_data['objects'][name_ae]['orientation'] += '[%f,%f,%f],' % (0, ae_pos_rot[4], ae_pos_rot[5])
-            js_data['objects'][name_ae]['rotationX'] += '%f ,' % (ae_pos_rot[3])
+            js_data['objects'][name_ae]['position'] += '[%f,%f,%f],' % (ae_transform[0], ae_transform[1], ae_transform[2])
+            if include_rotation:
+                js_data['objects'][name_ae]['orientation'] += '[%f,%f,%f],' % (0, ae_transform[4], ae_transform[5])
+                js_data['objects'][name_ae]['rotationX'] += '%f ,' % (ae_transform[3])
+            if include_scale:
+                js_data['objects'][name_ae]['scale'] += '[%f,%f,%f],' % (ae_transform[6], ae_transform[7], ae_transform[8])
 
     # ---- write JSX file
     jsx_file = open(file, 'w')
@@ -285,7 +295,8 @@
     #wrap in function
     jsx_file.write("function compFromBlender(){\n")
     # create new comp
-    jsx_file.write('\nvar compName = "%s";' % (comp_name))
+    jsx_file.write('\nvar compName = prompt("Blender Comp\'s Name \\nEnter Name of newly created Composition","BlendComp","Composition\'s Name");')
+    jsx_file.write('if (compName){')
     jsx_file.write('\nvar newComp = app.project.items.addComp(compName, %i, %i, %f, %f, %i);\n\n\n' %
                    (data['width'], data['height'], data['aspect'], data['duration'], data['fps']))
 
@@ -314,6 +325,7 @@
         jsx_file.write('%s.property("rotationX").setValuesAtTimes([%s],[%s]);\n' % (name_ae, js_data['times'], js_data['objects'][obj]['rotationX']))
         jsx_file.write('%s.property("rotationY").setValue(0);\n' % name_ae)
         jsx_file.write('%s.property("rotationZ").setValue(0);\n\n\n' % name_ae)
+        jsx_file.write('%s.property("scale").setValuesAtTimes([%s],[%s]);\n' % (name_ae, js_data['times'], js_data['objects'][obj]['scale']))
 
     # create Bundles
     if export_bundles:
@@ -335,22 +347,22 @@
                     else:
                         mc = constrain.clip
 
-                    #go throuhg each tracking point
+                    #go through each tracking point
                     for track in mc.tracking.tracks:
                         #is this tracking point has a Bundles (does it's 3D position has been solved)
                         if track.has_bundle:
                             # bundle are in camera space, so transpose it to world space
                             matrix = Matrix.Translation(cam.matrix_basis * track.bundle)
                             #convert the position into AE space
-                            ae_pos_rot = convert_pos_rot_matrix(matrix, data['width'], data['height'], data['aspect'], x_rot_correction=False)
+                            ae_transform = convert_transform_matrix(matrix, data['width'], data['height'], data['aspect'], x_rot_correction=False)
                             #get the name of the tracker
-                            name_ae = convert_name(False, track, prefix)
+                            name_ae = convert_name(False, track)

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list