+import mathutils
+
+class LightExporter:
+ def export_light(self, obj):
+ if obj.type!='LIGHT':
+ raise ValueError("Object is not a light")
+ light = obj.data
+
+ from .datafile import Resource, Statement
+ light_res = Resource(light.name+".light", "light")
+
+ if light.type=='SUN':
+ pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 1.0, 0.0))
+ else:
+ pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0))
+
+ light_res.statements.append(Statement("position", *tuple(pos)))
+ c = light.color
+ e = light.energy
+ light_res.statements.append(Statement("color", c.r*e, c.g*e, c.b*e))
+
+ return light_res