+ return center, radius
+
+ def make_external_name(self, base_name, resource_name, ext, index):
+ if self.shared_resources:
+ return resource_name+ext
+ elif lod_index>0:
+ return "{}_lod{}{}".format(base_name, lod_index, ext)
+ else:
+ return base_name+ext
+
+ def create_mesh_exporter(self):
+ from .export_mesh import MeshExporter
+ mesh_export = MeshExporter()
+ mesh_export.use_strips = self.use_strips
+ mesh_export.use_degen_tris = self.use_degen_tris
+ return mesh_export
+
+ def export_to_file(self, context, out_fn):
+ obj = context.active_object
+
+ from .util import Progress
+ progress = Progress(self.show_progress and context)
+
+ path, base = os.path.split(out_fn)
+ base = os.path.splitext(base)[0]
+
+ meshes = self.export_object_meshes(context, obj, progress, base_name=base)
+ if self.separate_mesh:
+ for name, st in meshes.items():
+ with open(os.path.join(path, name), "w") as out_file:
+ for s in st:
+ s.write_to_file(out_file)
+
+ if self.separate_tech:
+ lods = [obj]
+ if self.export_lods:
+ lods += [c for c in obj.children if c.lod_for_parent]
+
+ for l in lods:
+ lod_index = l.lod_index if l.lod_for_parent else 0
+
+ material = None
+ if obj.material_slots:
+ material = obj.material_slots[0].material
+
+ if not l.technique:
+ tech_name = self.make_external_name(base, material.name, ".tech", lod_index)
+ st = self.export_object_technique(l, base_name=base)
+ with open(os.path.join(path, tech_name), "w") as out_file:
+ for s in st:
+ s.write_to_file(out_file)
+ elif material and l.override_material:
+ mat_name = self.make_external_name(base, material.name, ".mat", lod_index)
+ st = self.export_material(material)
+ with open(os.path.join(path, mat_name), "w") as out_file:
+ for s in st:
+ s.write_to_file(out_file)
+
+ statements = self.export_object(context, obj, progress, meshes=meshes, base_name=base)
+
+ with open(out_fn, "w") as out_file:
+ for s in statements:
+ s.write_to_file(out_file)
+
+ def export_object_meshes(self, context, obj, progress, *, base_name=None):
+ if base_name is None:
+ base_name = obj.name
+
+ lods = [obj]
+ if self.export_lods:
+ lods += [c for c in obj.children if c.lod_for_parent]
+
+ from .mesh import create_mesh_from_object
+ mesh_export = self.create_mesh_exporter()
+ meshes = {}
+
+ for i, l in enumerate(lods):
+ lod_index = l.lod_index if l.lod_for_parent else 0
+ progress.push_task_slice("LOD {}".format(lod_index), i, len(lods))
+
+ mesh_name = self.make_external_name(base_name, l.data.name, ".mesh", lod_index)
+ if mesh_name not in meshes:
+ mesh = create_mesh_from_object(context, l, progress)
+ meshes[mesh_name] = mesh_export.export_mesh(context, mesh, progress)
+
+ progress.pop_task()
+
+ return meshes
+
+ def export_object(self, context, obj, progress, *, meshes=None, base_name=None):
+ if base_name is None:
+ base_name = obj.name
+
+ if meshes is None:
+ meshes = self.export_object_meshes(context, obj, progress, base_name=base_name)
+
+ lods = [obj]
+ for c in obj.children:
+ if c.lod_for_parent:
+ if c.lod_index>=len(lods):
+ lods += [None]*(c.lod_index+1-len(lods))
+ lods[c.lod_index] = c
+
+ from .datafile import Statement
+ statements = []
+
+ center, radius = self.compute_bounding_sphere(obj)
+ statements.append(Statement("bounding_sphere_hint", *center, radius))