6 self.resource_collection = True
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]
12 from .outfile import open_output
13 out_file = open_output(out_file)
15 path, base = os.path.split(out_file.filename)
16 base, ext = os.path.splitext(base)
18 from .export_object import ObjectExporter
19 object_export = ObjectExporter()
21 object_prototypes = {}
24 if o.name in object_prototypes:
28 if not any(s.link=="OBJECT" for s in o.material_slots):
32 if u.data.name!=o.data.name:
34 if u.technique!=o.technique:
36 if any(s.link=="OBJECT" for s in u.material_slots):
41 unique_objects.append(o)
43 object_prototypes[c.name] = o
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"))
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)
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):
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)
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:]
77 if o.rotation_mode=="QUATERNION":
78 q = o.rotation_quaternion
80 q = o.rotation_euler.to_quaternion()
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])