]> git.tdb.fi Git - libs/gl.git/blobdiff - blender/io_mspgl/export_light.py
Add a Blender operator to export the entire project at once
[libs/gl.git] / blender / io_mspgl / export_light.py
diff --git a/blender/io_mspgl/export_light.py b/blender/io_mspgl/export_light.py
new file mode 100644 (file)
index 0000000..cfa4a19
--- /dev/null
@@ -0,0 +1,22 @@
+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