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