import math
import mathutils
+import bpy
class CameraExporter:
def export_camera(self, obj):
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