]> git.tdb.fi Git - libs/gl.git/commitdiff
Account for render resolution when exporting camera field of view
authorMikko Rasa <tdb@tdb.fi>
Sun, 9 Oct 2022 13:34:48 +0000 (16:34 +0300)
committerMikko Rasa <tdb@tdb.fi>
Sun, 9 Oct 2022 13:34:48 +0000 (16:34 +0300)
This is a big of a kludge since in theory a camera could be used in
multiple scenes, but likely to work fine in practice.

blender/io_mspgl/export_camera.py

index 78afbd1235594f62e9350f2ef684570846149687..87ccb1e552524860410b43e97e087f20e54e8b89 100644 (file)
@@ -1,5 +1,6 @@
 import math
 import mathutils
+import bpy
 
 class CameraExporter:
        def export_camera(self, obj):
@@ -14,7 +15,18 @@ class CameraExporter:
                look_dir = obj.matrix_world@mathutils.Vector((0, 0, -1, 0))
                resource.statements.append(Statement("look_direction", look_dir[0], look_dir[1], look_dir[2]))
                resource.statements.append(Statement("up_direction", 0.0, 0.0, 1.0))
-               resource.statements.append(Statement("field_of_view", obj.data.angle_y*180/math.pi))
+
+               # Auto seems to be the same as horizontal
+               if obj.data.sensor_fit=='HORIZONTAL' or obj.data.sensor_fit=='AUTO':
+                       aspect = 16/9
+                       for s in bpy.data.scenes:
+                               if obj.name in s.collection.all_objects:
+                                       aspect = s.render.resolution_x/s.render.resolution_y
+                       fov = math.atan(obj.data.sensor_width/aspect/2/obj.data.lens)*360/math.pi
+               elif obj.data.sensor_fit=='VERTICAL':
+                       fov = obj.data.angle_y*180/math.pi
+               resource.statements.append(Statement("field_of_view", fov))
+
                resource.statements.append(Statement("depth_clip", obj.data.clip_start, obj.data.clip_end))
 
                return resource