]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_light.py
Split the Light class into subclasses by light type
[libs/gl.git] / blender / io_mspgl / export_light.py
index 4da2ba29a717c6b7bf6ac9417d4157b4ddc12302..2fc8c8dd02bd3dbccec4b0204dd75ed0930c378e 100644 (file)
@@ -6,15 +6,19 @@ class LightExporter:
                        raise ValueError("Object {} is not a light".format(obj.name))
                light = obj.data
 
-               from .datafile import Resource, Statement
+               from .datafile import Resource, Statement, Token
                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:
+                       light_res.statements.append(Statement("type", Token("directional")))
+                       light_res.statements.append(Statement("direction", *(-obj.matrix_world.col[2])[0:3]))
+               elif light.type=='POINT':
+                       light_res.statements.append(Statement("type", Token("point")))
                        pos = obj.matrix_world@mathutils.Vector((0.0, 0.0, 0.0, 1.0))
+                       light_res.statements.append(Statement("position", *obj.matrix_world.col[3][0:3]))
+               else:
+                       raise Exception("Can't export light {} of unknown type {}".format(light.name, light.type))
 
-               light_res.statements.append(Statement("position", *tuple(pos)))
                c = light.color*light.energy
                light_res.statements.append(Statement("color", *tuple(c)))