6 self.resource_collection = True
7 self.show_progress = True
9 def export_to_file(self, context, out_fn):
10 objs = [o for o in context.selected_objects if o.type=="MESH" and not o.lod_for_parent]
11 objs = [o for o in objs if (not o.compound or o.parent not in objs)]
13 path, base = os.path.split(out_fn)
14 base, ext = os.path.splitext(base)
16 from .export_object import ObjectExporter
17 object_export = ObjectExporter()
19 object_prototypes = {}
23 if o.name in object_prototypes:
27 if not any(s.link=="OBJECT" for s in o.material_slots):
31 if u.data.name!=o.data.name:
33 if u.technique!=o.technique:
35 if any(s.link=="OBJECT" for s in u.material_slots):
42 for i in range(min(len(c.name), len(prefix))):
43 if c.name[i]!=prefix[i]:
48 export_names[o.name+".object"] = prefix.strip(" .")+".object"
50 unique_objects.append(o)
52 object_prototypes[c.name] = o
54 from .util import Progress
55 progress = Progress(self.show_progress and context)
58 self.export_scene_resources(context, unique_objects, resources, progress)
59 for n, r in resources.items():
60 if r.name in export_names:
61 r.name = export_names[r.name]
63 scene_res = self.export_scene(context, objs, progress, prototypes=object_prototypes, resources=resources)
64 refs = scene_res.collect_references()
66 from .datafile import Statement
67 if self.resource_collection:
68 keywords = { ".mat": "material",
72 ".tex2d": "texture2d" }
73 with open(os.path.join(path, base+"_resources.mdc"), "w") as res_out:
75 st = Statement(keywords[os.path.splitext(r.name)[1]], r.name)
77 st.write_to_file(res_out)
79 res_dir = os.path.join(path, base+"_resources")
80 if not os.path.exists(res_dir):
83 with open(os.path.join(res_dir, r.name), "w") as res_out:
84 for s in r.statements:
85 s.write_to_file(res_out)
87 with open(out_fn, "w") as out_file:
88 for s in scene_res.statements:
89 s.write_to_file(out_file)
91 def export_scene_resources(self, context, objs, resources, progress):
92 from .export_object import ObjectExporter
93 object_export = ObjectExporter()
94 object_export.single_file = False
98 for i, o in enumerate(objs):
99 progress.push_task_slice(o.name, i, len(objs))
100 object_export.export_object_resources(context, o, resources, progress, material_maps=material_maps)
101 obj_name = o.name+".object"
102 resources[obj_name] = object_export.export_object(context, o, progress, resources=resources)
105 def export_scene(self, context, objs, progress, *, prototypes, resources):
106 from .datafile import Resource, Statement
107 scene_res = Resource("scene.scene")
110 obj_res = resources[prototypes[o.name].name+".object"]
111 st = scene_res.create_reference_statement("object", obj_res, o.name)
112 # XXX Parent relationships screw up the location and rotation
113 st.sub.append(Statement("position", o.location[0], o.location[1], o.location[2]))
114 if o.rotation_mode=="AXIS_ANGLE":
115 angle = o.rotation_axis_angle[0]
116 axis = o.rotation_axis_angle[1:]
118 if o.rotation_mode=="QUATERNION":
119 q = o.rotation_quaternion
121 q = o.rotation_euler.to_quaternion()
124 st.sub.append(Statement("rotation", angle*180/math.pi, axis[0], axis[1], axis[2]))
125 st.sub.append(Statement("scale", o.scale[0], o.scale[1], o.scale[2]))
126 scene_res.statements.append(st)
128 progress.set_progress(1.0)