]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_light.py
Change default binding ranges to match lowest OpenGL standard
[libs/gl.git] / blender / io_mspgl / export_light.py
1 import mathutils
2
3 class LightExporter:
4         def export_light(self, obj):
5                 if obj.type!='LIGHT':
6                         raise ValueError("Object {} is not a light".format(obj.name))
7                 light = obj.data
8
9                 from .datafile import Resource, Statement, Token
10                 light_res = Resource(light.name+".light", "light")
11
12                 if light.type=='SUN':
13                         light_res.statements.append(Statement("type", Token("directional")))
14                         light_res.statements.append(Statement("direction", *(-obj.matrix_world.col[2])[0:3]))
15                 elif light.type=='POINT':
16                         light_res.statements.append(Statement("type", Token("point")))
17                         pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0))
18                         light_res.statements.append(Statement("position", *obj.matrix_world.col[3][0:3]))
19                         light_res.statements.append(Statement("attenuation", 1.0, 0.0, 1.0))
20                 else:
21                         raise Exception("Can't export light {} of unknown type {}".format(light.name, light.type))
22
23                 c = light.color*light.energy
24                 light_res.statements.append(Statement("color", *tuple(c)))
25
26                 return light_res