]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_light.py
Split the Light class into subclasses by light type
[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                 else:
20                         raise Exception("Can't export light {} of unknown type {}".format(light.name, light.type))
21
22                 c = light.color*light.energy
23                 light_res.statements.append(Statement("color", *tuple(c)))
24
25                 return light_res