]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_camera.py
Translate cube map sampling function for old GLSL versions
[libs/gl.git] / blender / io_mspgl / export_camera.py
1 import math
2 import mathutils
3
4 class CameraExporter:
5         def export_to_file(self, context, out_fn):
6                 obj = context.active_object
7
8                 resource = self.export_camera(obj)
9
10                 with open(out_fn, "w") as out_file:
11                         for s in resource.statements:
12                                 s.write_to_file(out_file)
13
14         def export_camera(self, obj):
15                 if obj.type!='CAMERA':
16                         raise Exception("Object is not a camera")
17
18                 from .datafile import Resource, Statement
19                 resource = Resource(obj.name+".camera")
20
21                 position = obj.matrix_world*mathutils.Vector((0, 0, 0))
22                 resource.statements.append(Statement("position", position[0], position[1], position[2]))
23                 look_dir = obj.matrix_world*mathutils.Vector((0, 0, -1, 0))
24                 resource.statements.append(Statement("look_direction", look_dir[0], look_dir[1], look_dir[2]))
25                 resource.statements.append(Statement("up_direction", 0.0, 0.0, 1.0))
26                 resource.statements.append(Statement("field_of_view", obj.data.angle_y*180/math.pi))
27                 resource.statements.append(Statement("depth_clip", obj.data.clip_start, obj.data.clip_end))
28
29                 return resource