]> git.tdb.fi Git - libs/gl.git/blob - blender/io_mspgl/export_scene.py
Remove the external tech exporter property
[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.resource_collection = True
7
8         def export(self, context, out_file):
9                 objs = context.selected_objects
10                 objs = [o for o in objs if o.type=="MESH" and (not o.compound or o.parent not in objs) and not o.lod_for_parent]
11
12                 from .outfile import open_output
13                 out_file = open_output(out_file)
14
15                 path, base = os.path.split(out_file.filename)
16                 base, ext = os.path.splitext(base)
17
18                 from .export_object import ObjectExporter
19                 object_export = ObjectExporter()
20
21                 object_prototypes = {}
22                 unique_objects = []
23                 for o in objs:
24                         if o.name in object_prototypes:
25                                 continue
26
27                         clones = [o]
28                         if not any(s.link=="OBJECT" for s in o.material_slots):
29                                 for u in objs:
30                                         if u is o:
31                                                 continue
32                                         if u.data.name!=o.data.name:
33                                                 continue
34                                         if u.technique!=o.technique:
35                                                 continue
36                                         if any(s.link=="OBJECT" for s in u.material_slots):
37                                                 continue
38
39                                         clones.append(u)
40
41                         unique_objects.append(o)
42                         for c in clones:
43                                 object_prototypes[c.name] = o
44
45                 from .util import Progress
46                 progress = Progress(context)
47                 if self.resource_collection:
48                         res_out = open_output(os.path.join(path, base+"_resources.mdc"))
49
50                         # TODO Export techniques as separate items in the collection
51                         for i, o in enumerate(unique_objects):
52                                 res_out.begin("object", '"{}.object"'.format(o.name))
53                                 progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
54                                 object_export.export(context, res_out, o, progress)
55                                 progress.pop_task()
56                                 res_out.end()
57                 else:
58                         object_export.separate_mesh = True
59                         object_export.separate_tech = True
60                         res_dir = os.path.join(path, base+"_resources")
61                         if not os.path.exists(res_dir):
62                                 os.makedirs(res_dir)
63                         for i, o in enumerate(unique_objects):
64                                 obj_out = open_output(os.path.join(res_dir, o.name+".object"))
65                                 progress.push_task(o.name, i/len(objs), (i+1)/len(objs))
66                                 object_export.export(context, obj_out, o, progress)
67                                 progress.pop_task()
68
69                 for o in objs:
70                         out_file.begin("object", '"{}.object"'.format(object_prototypes[o.name].name))
71                         # XXX Parent relationships screw up the location and rotation
72                         out_file.write("position", o.location[0], o.location[1], o.location[2])
73                         if o.rotation_mode=="AXIS_ANGLE":
74                                 angle = o.rotation_axis_angle[0]
75                                 axis = o.rotation_axis_angle[1:]
76                         else:
77                                 if o.rotation_mode=="QUATERNION":
78                                         q = o.rotation_quaternion
79                                 else:
80                                         q = o.rotation_euler.to_quaternion()
81                                 angle = q.angle
82                                 axis = q.axis
83                         out_file.write("rotation", angle*180/math.pi, axis[0], axis[1], axis[2])
84                         out_file.write("scale", o.scale[0], o.scale[1], o.scale[2])
85                         out_file.end();