]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_scene.py
Allow flagging meshes for winding test in Blender
[libs/gl.git] / blender / io_mspgl / export_scene.py
1 import math
2 import os
3
4 class SceneExporter:
5         def __init__(self):
6                 self.external_tech = True
7                 self.resource_collection = True
8
9         def export(self, context, out_file):
10                 objs = context.selected_objects
11                 objs = [o for o in objs if o.type=="MESH" and (not o.compound or o.parent not in objs)]
12
13                 from .outfile import open_output
14                 out_file = open_output(out_file)
15
16                 path, base = os.path.split(out_file.filename)
17                 base, ext = os.path.splitext(base)
18
19                 from .export_object import ObjectExporter
20                 object_export = ObjectExporter()
21                 object_export.compound = True
22                 object_export.external_tech = self.external_tech
23
24                 from .util import Progress
25                 progress = Progress(context)
26                 if self.resource_collection:
27                         res_out = open_output(os.path.join(path, base+"_resources.mdc"))
28
29                         # TODO Export techniques as separate items in the collection
30                         for i, o in enumerate(objs):
31                                 res_out.begin("object", '"{}.object"'.format(o.name))
32                                 progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
33                                 object_export.export(context, res_out, [o], progress)
34                                 progress.pop_task()
35                                 res_out.end()
36                 else:
37                         object_export.separate_tech = True
38                         res_dir = os.path.join(path, base+"_resources")
39                         if not os.path.exists(res_dir):
40                                 os.makedirs(res_dir)
41                         for o in objs:
42                                 obj_out = open_output(os.path.join(res_dir, o.name+".object"))
43                                 progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
44                                 object_export.export(context, obj_out, [o], progress)
45                                 progress.pop_task()
46
47                 for o in objs:
48                         out_file.begin("object", '"{}.object"'.format(o.name))
49                         # XXX Parent relationships screw up the location and rotation
50                         out_file.write("position", o.location[0], o.location[1], o.location[2])
51                         if o.rotation_mode=="AXIS_ANGLE":
52                                 angle = o.rotation_axis_angle[0]
53                                 axis = o.rotation_axis_angle[1:]
54                         else:
55                                 if o.rotation_mode=="QUATERNION":
56                                         q = o.rotation_quaternion
57                                 else:
58                                         q = o.rotation_euler.to_quaternion()
59                                 angle = q.angle
60                                 axis = q.axis
61                         out_file.write("rotation", angle*180/math.pi, axis[0], axis[1], axis[2])
62                         out_file.end();