[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [2724] contrib/py/scripts/addons:

Michael Krupa kroopson at wp.pl
Mon Dec 5 16:10:40 CET 2011


Revision: 2724
          http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=2724
Author:   kroopson
Date:     2011-12-05 15:10:39 +0000 (Mon, 05 Dec 2011)
Log Message:
-----------


Modified Paths:
--------------
    contrib/py/scripts/addons/io_export_chan.py
    contrib/py/scripts/addons/io_import_chan.py

Modified: contrib/py/scripts/addons/io_export_chan.py
===================================================================
--- contrib/py/scripts/addons/io_export_chan.py	2011-12-05 15:09:57 UTC (rev 2723)
+++ contrib/py/scripts/addons/io_export_chan.py	2011-12-05 15:10:39 UTC (rev 2724)
@@ -40,11 +40,12 @@
 from math import radians
 from math import degrees
 from math import atan
+from math import atan2
 from math import tan
 
 
 def save_chan(context, filepath, y_up, rot_ord):
-    #check if we have anything selected, if not, finish without doing anything.
+    #check if we have anything selected, if not, end with no action
     if not bpy.context.active_object:
         return {'FINISHED'}
 
@@ -97,7 +98,19 @@
 
         #if we have a camera, add the focal length
         if obj.type == 'CAMERA':
-            vfov = degrees(2 * atan(tan((obj.data.angle / 2.0) * res_ratio)))
+            #I've found via the experiments that this is a blenders 
+            #default sensor size (in mm)
+            sensor_x = 32.0
+            #the vertical sensor size we get by multiplying the sensor_x by
+            #resolution ratio
+            sensor_y = sensor_x * res_ratio
+            cam_lens = obj.data.lens
+            #calculate the vertical field of view
+            #we know the vertical size of (virtual) sensor, the focal length
+            #of the camera so all we need to do is to feed this data to
+            #atan2 function whitch returns the degree (in radians) of 
+            #an angle formed by a triangle with two legs of a given lengths
+            vfov = degrees(atan2(sensor_y / 2, cam_lens))*2
             export_string.append("%f\n" % vfov)
 
         #when all is set and done write the new line

Modified: contrib/py/scripts/addons/io_import_chan.py
===================================================================
--- contrib/py/scripts/addons/io_import_chan.py	2011-12-05 15:09:57 UTC (rev 2723)
+++ contrib/py/scripts/addons/io_import_chan.py	2011-12-05 15:10:39 UTC (rev 2724)
@@ -42,7 +42,7 @@
 from math import tan
 
 
-def read_chan(context, filepath, Zup, rot_ord):
+def read_chan(context, filepath, z_up, rot_ord):
     #check if we have anything selected, if not, finish without doing anything.
     if not bpy.context.active_object:
         return {'FINISHED'}
@@ -99,7 +99,7 @@
 
             #correct the world space
             #(nuke's and blenders scene spaces are different)
-            if Zup:
+            if z_up:
                 m_trans_mat = rot_mat * m_trans_mat
 
             #break the matrix into a set of the coordinates
@@ -118,16 +118,14 @@
                 obj.rotation_euler = trns[1]
                 obj.keyframe_insert('rotation_quaternion')
 
-            #if the target object is camera test for the vfov data. If present,
-            #calculate the horizontal angle and set the keyframe on camera lens
-            if obj.data.type == "PERSP":
-                if len(data) > 7:
-                    v_fov = float(data[7])
-                    lenslen = (res_ratio/2)  / (tan(radians(v_fov/2)))
-                    h_fov = (atan( .5 / lenslen ) * 2)
-                    print(h_fov)
-                    obj.data.angle = h_fov
-                    obj.data.keyframe_insert('lens')
+            #check if the object is camera and fov data is present
+            if obj.type == "CAMERA" and len(data) > 7:
+                v_fov = float(data[7])
+                sensor_v = 32.0
+                sensor_h = sensor_v * res_ratio
+                lenslen = ((sensor_h/2) / tan(radians(v_fov / 2)))
+                obj.data.lens = lenslen
+                obj.data.keyframe_insert('lens')
     f.close()
 
     return {'FINISHED'}
@@ -147,7 +145,7 @@
 
     filter_glob = StringProperty(default="*.chan", options={'HIDDEN'})
 
-    Zup = BoolProperty(name="Make Z up",
+    z_up = BoolProperty(name="Make Z up",
                         description="Switch the Y and Z axis",
                         default=True)
     rot_ord = EnumProperty(items=(('XYZ', "XYZ", "XYZ"),
@@ -167,7 +165,7 @@
         return context.active_object != None
 
     def execute(self, context):
-        return read_chan(context, self.filepath, self.Zup, self.rot_ord)
+        return read_chan(context, self.filepath, self.z_up, self.rot_ord)
 
 
 def menu_func_import(self, context):



More information about the Bf-extensions-cvs mailing list