[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2933] trunk/py/scripts/addons/ io_export_after_effects.py: 1. Fix for active camera export - when cameras bound to markers - option to export as one camera .

Bartek Skorupa bartekskorupa at bartekskorupa.com
Mon Jan 23 11:50:59 CET 2012


Revision: 2933
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2933
Author:   bartekskorupa
Date:     2012-01-23 10:50:54 +0000 (Mon, 23 Jan 2012)
Log Message:
-----------
1. Fix for active camera export - when cameras bound to markers - option to export as one camera.    2. poll fix - changed from active object to active camera or selected objects    3. Export of active camera is now optional    4. Export of selected cameras is now optional    5. Naming fix - Changed tracking data export naming for user from BUNDLES to 3D MARKERS    6. Toolbar fix - wrapped in box, options added    7. Code cleanup - Prepared structure for future options of exporting lamps as AE lights, planes as AE solids and object tracking bundles, additional conditions added to avoid AE errors in some rare cases

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-23 08:10:31 UTC (rev 2932)
+++ trunk/py/scripts/addons/io_export_after_effects.py	2012-01-23 10:50:54 UTC (rev 2933)
@@ -19,9 +19,9 @@
 #
 bl_info = {
     'name': 'Export: Adobe After Effects (.jsx)',
-    'description': 'Export selected cameras, objects & bundles to Adobe After Effects CS3 and above',
+    'description': 'Export cameras, selected objects & camera solution 3D Markers to Adobe After Effects CS3 and above',
     'author': 'Bartek Skorupa',
-    'version': (0, 5, 9),
+    'version': (0, 6, 0),
     'blender': (2, 6, 1),
     'location': 'File > Export > Adobe After Effects (.jsx)',
     "warning": "",
@@ -33,9 +33,10 @@
     }
 
 
-from math import pi
 import bpy
 import datetime
+from math import pi
+from mathutils import Matrix
 
 
 # create list of static blender's data
@@ -44,6 +45,9 @@
     aspect_x = scene.render.pixel_aspect_x
     aspect_y = scene.render.pixel_aspect_y
     aspect = aspect_x / aspect_y
+    start = scene.frame_start
+    end = scene.frame_end
+    active_cam_frames = get_active_cam_for_each_frame(scene, start, end)
     fps = scene.render.fps
 
     return {
@@ -52,64 +56,94 @@
         'height': scene.render.resolution_y,
         'aspect': aspect,
         'fps': fps,
-        'start': scene.frame_start,
-        'end': scene.frame_end,
-        'duration': (scene.frame_end - scene.frame_start + 1.0) / fps,
+        'start': start,
+        'end': end,
+        'duration': (end - start + 1.0) / fps,
+        'active_cam_frames': active_cam_frames,
         'curframe': scene.frame_current,
         }
 
+# create list of active camera for each frame in case active camera is set by markers
+def get_active_cam_for_each_frame(scene, start, end):
+    active_cam_frames = []
+    sorted_markers = []
+    markers = scene.timeline_markers
+    if markers:
+        for marker in markers:
+            if marker.camera:
+                sorted_markers.append([marker.frame, marker])
+        sorted_markers = sorted(sorted_markers)
+        
+        for i, marker in enumerate (sorted_markers):
+            cam = marker[1].camera
+            if i is 0 and marker[0] > start:
+                start_range = start
+            else:
+                start_range = sorted_markers[i][0]
+            if len(sorted_markers) > i + 1:
+                end_range = sorted_markers[i+1][0] - 1
+            else:
+                end_range = end
+            for i in range(start_range, end_range + 1):
+                active_cam_frames.append(cam)
+    if not active_cam_frames:
+        if scene.camera:
+            # in this case active_cam_frames array will have legth of 1. This will indicate that there is only one active cam in all frames
+            active_cam_frames.append(scene.camera)
 
+    return(active_cam_frames)    
+
 # create managable list of selected objects
-# (only selected objects will be analyzed and exported)
 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)
+    solids = []  # list of all selected meshes that can be exported as AE's solids
+    lights = []  # list of all selected lamps that can be exported as AE's lights
     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 = context.selected_objects
 
     for ob in obs:
         if ob.type == 'CAMERA':
-            cameras.append(ob)
-            cams_names.append(convert_name(False, ob))
+            cameras.append([ob, convert_name(ob.name)])
+
+        elif is_plane(ob):
+            # not ready yet. is_plane(object) returns False in all cases. This is temporary
+            solids.append([ob, convert_name(ob.name)])
+            
+        elif ob.type == 'LAMP':
+            # not ready yet. Lamps will be exported as nulls. This is temporary
+            nulls.append([ob, convert_name(ob.name)])
+
         else:
-            nulls.append(ob)
-            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))
-    
+            nulls.append([ob, convert_name(ob.name)])
+
     selection = {
         'cameras': cameras,
-        'cams_names': cams_names,
+        'solids': solids,
+        'lights': lights,
         'nulls': nulls,
-        'nulls_names': nulls_names,
         }
 
     return selection
 
+# check if object is plane and can be exported as AE's solid
+def is_plane(object):
+    # work in progress. Not ready yet
+    return False
 
 # convert names of objects to avoid errors in AE.
-def convert_name(is_comp, ob):
-    if is_comp:
-        ob_name = ob
-        ob_name = ob_name.replace('"', "_")
-    else:
-        ob_name = "_" + ob.name
+def convert_name(name):
+    name = "_" + name
 
-        if ob_name[0].isdigit():
-            ob_name = "_" + ob_name
-            
-        ob_name = bpy.path.clean_name(ob_name)
-        ob_name = ob_name.replace("-", "_")
+    if name[0].isdigit():
+        name = "_" + name
+        
+    name = bpy.path.clean_name(name)
+    name = name.replace("-", "_")
 
-    return ob_name
+    return name
 
 
-# get object's blender's location and rotation and return AE's Position and Rotation/Orientation
+# 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):
 
@@ -126,7 +160,7 @@
     b_rot_y = b_rot_y / pi * 180.0
     b_rot_z = b_rot_z / pi * 180.0
 
-    # convert to AE Position and Rotation
+    # 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
@@ -135,18 +169,12 @@
     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
-    sy = b_scale_z * 100.0
-    sz = b_scale_y * 100.0
+    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
 
-
-def convert_transform(obj, width, height, aspect, x_rot_correction=False):
-    matrix = obj.matrix_world.copy()
-    return convert_transform_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
 #
@@ -204,10 +232,14 @@
 
     return zoom
 
+# convert object bundle's matrix. Not ready yet. Temporarily not active
+#def get_ob_bundle_matrix_world(cam_matrix_world, bundle_matrix):
+#    matrix = cam_matrix_basis
+#    return matrix
 
+
 # jsx script for AE creation
-def write_jsx_file(file, data, selection, export_bundles, include_rotation, include_scale):
-    from mathutils import Matrix
+def write_jsx_file(file, data, selection, include_active_cam, include_selected_cams, include_selected_objects, include_cam_bundles, include_rotation, include_scale):
 
     print("\n---------------------------\n- Export to After Effects -\n---------------------------")
     #store the current frame to restore it at the enf of export
@@ -216,12 +248,22 @@
     js_data = {
         'times': '',
         'cameras': {},
-        'objects': {},
+        'solids': {},
+        'lights': {},
+        'nulls': {},
+        'bundles_cam': {},
+        'bundles_ob': {},  # not ready yet
         }
 
-    # create camera structure
-    for i, cam in enumerate(selection['cameras']):  # more than one camera can be selected
-        name_ae = selection['cams_names'][i]
+    # create structure for active camera/cameras
+    active_cam_name = ''
+    if include_active_cam and data['active_cam_frames'] != []:
+        # check if more that one active cam exist (true if active cams set by markers)
+        if len(data['active_cam_frames']) is 1:
+            name_ae = convert_name(data['active_cam_frames'][0].name)  # take name of the only active camera in scene
+        else:
+            name_ae = 'Active_Camera'
+        active_cam_name = name_ae  # store name to be used when creating keyframes for active cam.
         js_data['cameras'][name_ae] = {
             'position': '',
             'pointOfInterest': '',
@@ -230,53 +272,171 @@
             'zoom': '',
             }
 
-    # create object structure
-    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': '',
-            'scale': '',
-            }
+    # create camera structure for selected cameras
+    if include_selected_cams:
+        for i, cam in enumerate(selection['cameras']):  # more than one camera can be selected
+            if cam[1] != active_cam_name:
+                name_ae = selection['cameras'][i][1]
+                js_data['cameras'][name_ae] = {
+                    'position': '',
+                    'pointOfInterest': '',
+                    'orientation': '',
+                    'rotationX': '',
+                    'zoom': '',
+                    }
+    
+    # create structure for solids. Not ready yet. Temporarily not active
+#    for i, obj in enumerate(selection['solids']):
+#        name_ae = selection['solids'][i][1]
+#        js_data['solids'][name_ae] = {
+#            'position': '',
+#            'orientation': '',
+#            'rotationX': '',

@@ Diff output truncated at 10240 characters. @@


More information about the Bf-extensions-cvs mailing list