5 self.show_progress = True
6 self.collection = False
7 self.shared_resources = True
9 def export_to_file(self, context, out_fn):
10 from .util import Progress
11 progress = Progress(self.show_progress and context)
13 objects = context.selected_objects
18 dummy_res = self.export_resources(context, objects, resources, material_atlases, progress)
20 path, base = os.path.split(out_fn)
21 base, ext = os.path.splitext(base)
23 refs = dummy_res.collect_references()
24 if not self.shared_resources:
27 res_ext = os.path.splitext(r.name)[1]
28 n = numbers.get(res_ext, 0)
30 r.name = "{}_{}{}".format(base, n, res_ext)
33 numbers[res_ext] = n+1
36 dummy_res.write_collection(out_fn, exclude_self=True)
39 r.write_to_file(os.path.join(path, r.name))
41 def export_resources(self, context, objects, resources, material_atlases, progress):
42 if material_atlases is None:
45 object_exporter = None
46 camera_exporter = None
47 armature_exporter = None
49 from .datafile import Resource
50 dummy_res = Resource("dummy", "dummy")
52 for i, obj in enumerate(objects):
53 progress.push_task_slice(obj.name, i, len(objects))
57 res_name = obj.name+".object"
58 if res_name not in resources:
59 if not object_exporter:
60 from .export_object import ObjectExporter
61 object_exporter = ObjectExporter()
62 object_exporter.export_object_resources(context, obj, resources, material_atlases, progress)
63 res = object_exporter.export_object(obj, resources, progress)
64 elif obj.type=='CAMERA':
65 res_name = obj.name+".camera"
66 if res_name not in resources:
67 if not camera_exporter:
68 from .export_camera import CameraExporter
69 camera_exporter = CameraExporter()
70 res = camera_exporter.export_camera(obj)
71 elif obj.type=='ARMATURE':
72 res_name = obj.name+".arma"
73 if res_name not in resources:
74 if not armature_exporter:
75 from .export_armature import ArmatureExporter
76 armature_exporter = ArmatureExporter()
77 res = armature_exporter.export_armature(context, obj)
80 resources[res_name] = res
81 dummy_res.create_reference_statement("ref", res)