[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2602] trunk/py/scripts/addons/ io_export_after_effects.py: modified def convert_lens to behave correctly when camera sensor fit is set to vertical .\nPrevious version worked accurately only when 'AUTO' or 'HORIZONTAL' sensor fit was used.\nPreserved compatibility with 2. 60a not supporting camera sensor size.

Bartek Skorupa bartekskorupa at bartekskorupa.com
Sat Nov 12 00:46:06 CET 2011


Revision: 2602
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2602
Author:   bartekskorupa
Date:     2011-11-11 23:46:05 +0000 (Fri, 11 Nov 2011)
Log Message:
-----------
modified def convert_lens to behave correctly when camera sensor fit is set to vertical.\nPrevious version worked accurately only when 'AUTO' or 'HORIZONTAL' sensor fit was used.\nPreserved compatibility with 2.60a not supporting camera sensor size.

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	2011-11-11 03:16:01 UTC (rev 2601)
+++ trunk/py/scripts/addons/io_export_after_effects.py	2011-11-11 23:46:05 UTC (rev 2602)
@@ -21,9 +21,9 @@
     'name': 'Export: Adobe After Effects (.jsx)',
     'description': 'Export selected cameras, objects & bundles to Adobe After Effects CS3 and above',
     'author': 'Bartek Skorupa',
-    'version': (0, 56),
+    'version': (0, 57),
     'blender': (2, 6, 0),
-    'api': 41098,
+    'api': 41760,
     'location': 'File > Export > Adobe After Effects (.jsx)',
     'category': 'Import-Export',
     "warning": "",
@@ -140,46 +140,59 @@
 #
 #
 # AE's lens is defined by "zoom" in pixels. Zoom determines focal angle or focal length.
-# AE's camera's focal length is calculated basing on zoom value.
 #
-# Known values:
-#     - sensor (blender's sensor is 32mm)
+# ZOOM VALUE CALCULATIONS:
+#
+# Given values:
+#     - sensor width (camera.data.sensor_width)
+#     - sensor height (camera.data.sensor_height)
+#     - sensor fit (camera.data.sensor_fit)
 #     - lens (blender's lens in mm)
 #     - width (witdh of the composition/scene in pixels)
+#     - height (height of the composition/scene in pixels)
+#     - PAR (pixel aspect ratio)
 #
-# zoom can be calculated from simple proportions.
+# Calculations are made using sensor's size and scene/comp dimention (width or height).
+# If camera.sensor_fit is set to 'AUTO' or 'HORIZONTAL' - sensor = camera.data.sensor_width, dimention = width.
+# If camera.sensor_fit is set to 'VERTICAL' - sensor = camera.data.sensor_height, dimention = height
 #
+# zoom can be calculated using simple proportions.
+#
 #                             |
 #                           / |
 #                         /   |
-#                       /     | w
+#                       /     | d
 #       s  |\         /       | i
-#       e  |  \     /         | d
-#       n  |    \ /           | t
-#       s  |    / \           | h
-#       o  |  /     \         |
-#       r  |/         \       |
-#                       \     |
-#          |     |        \   |
+#       e  |  \     /         | m
+#       n  |    \ /           | e
+#       s  |    / \           | n
+#       o  |  /     \         | t
+#       r  |/         \       | i
+#                       \     | o
+#          |     |        \   | n
 #          |     |          \ |
 #          |     |            |
 #           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.
+#    zoom / dimention = lens / sensor   =>
+#    zoom = lens * dimention / sensor
 #
-#
 #    above is true if square pixels are used. If not - aspect compensation is needed, so final formula is:
-#    zoom = lens * width * (1/sensor) * aspect
+#    zoom = lens * dimention / 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
+def convert_lens(camera, width, height, aspect):
+    try:  # wrap in "try" to preserve compatibility with older versions not supporting camera sensor size.
+        if camera.data.sensor_fit == 'VERTICAL':
+            sensor = camera.data.sensor_height
+            dimention = height
+        else:
+            sensor = camera.data.sensor_width
+            dimention = width
     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.0 / sensor) * aspect
+        sensor = 32  # standard blender's sensor size
+        dimention = width
+    
+    zoom = camera.data.lens * dimention / sensor * aspect
 
     return zoom
 
@@ -233,7 +246,7 @@
             #convert cam position to AE space
             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'])
+            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])



More information about the Bf-extensions-cvs mailing list