5 def export_to_file(self, ctx, out_fn, *, collection=False, shared_resources=False):
6 objects = context.context.selected_objects
11 task = ctx.task("Exporting resources", 1.0)
12 dummy_res = self.export_resources(task, objects, resources, material_atlases)
14 path, base = os.path.split(out_fn)
15 base, ext = os.path.splitext(base)
17 task = ctx.task("Writing files", 1.0)
18 refs = dummy_res.collect_references()
19 if not shared_resources:
22 res_ext = os.path.splitext(r.name)[1]
23 n = numbers.get(res_ext, 0)
25 r.name = "{}_{}{}".format(base, n, res_ext)
28 numbers[res_ext] = n+1
31 dummy_res.write_collection(out_fn, exclude_self=True)
34 r.write_to_file(os.path.join(path, r.name))
36 def export_resources(self, ctx, objects, resources, material_atlases):
37 if material_atlases is None:
40 object_exporter = None
41 camera_exporter = None
42 armature_exporter = None
45 from .datafile import Resource
46 dummy_res = Resource("dummy", "dummy")
48 ctx.set_slices(len(objects))
50 task = ctx.next_slice(obj)
54 res_name = obj.name+".object"
55 if res_name not in resources:
56 if not object_exporter:
57 from .export_object import ObjectExporter
58 object_exporter = ObjectExporter()
59 object_exporter.export_object_resources(task, obj, resources, material_atlases)
60 res = object_exporter.export_object(obj, resources)
61 elif obj.type=='CAMERA':
62 res_name = obj.name+".camera"
63 if res_name not in resources:
64 if not camera_exporter:
65 from .export_camera import CameraExporter
66 camera_exporter = CameraExporter()
67 res = camera_exporter.export_camera(obj)
68 elif obj.type=='ARMATURE':
69 res_name = obj.name+".arma"
70 if res_name not in resources:
71 if not armature_exporter:
72 from .export_armature import ArmatureExporter
73 armature_exporter = ArmatureExporter()
74 res = armature_exporter.export_armature(obj)
75 elif obj.type=='LIGHT':
76 res_name = obj.name+".light"
77 if res_name not in resources:
78 if not light_exporter:
79 from .export_light import LightExporter
80 light_exporter = LightExporter()
81 res = light_exporter.export_light(obj)
84 resources[res_name] = res
85 dummy_res.create_reference_statement("ref", res)
89 class ProjectExporter:
90 def export_to_directory(self, ctx, out_dir):
91 from .scene import create_scene_chain
93 task = ctx.task("Preparing scenes", 0.0)
94 task.set_slices(len(ctx.context.blend_data.scenes))
98 for s in ctx.context.blend_data.scenes:
99 subtask = task.next_slice(s)
100 if s.export_disposition=='IGNORE':
103 if s.export_disposition=='SEQUENCE':
104 scene = create_scene_chain(s, scenes)
105 sequences.append(scene)
106 elif s.export_disposition!='IGNORE' and s.name not in scenes:
107 scene = create_scene(s)
108 if s.export_disposition=='SCENE':
109 scenes[scene.name] = scene
112 for s in scenes.values():
113 all_objects += s.prototypes
114 all_objects += s.lights
116 all_objects.append(s.camera)
118 scene_queue = list(scenes.values())
121 s = scene_queue.pop(0)
122 if not s.background_set or s.background_set in ordered_scenes:
123 ordered_scenes.append(s)
125 scene_queue.append(s)
127 from .util import make_unique
128 all_objects = make_unique(all_objects)
130 from .export_scene import SceneExporter
131 scene_exporter = SceneExporter()
132 data_exporter = DataExporter()
134 task = ctx.task("Exporting resources", 1.0)
136 dummy_res = data_exporter.export_resources(task, all_objects, resources, None)
138 task = ctx.task("Exporting scenes", 1.0)
139 for s in ordered_scenes:
140 subtask = task.task(s, 0.5)
141 scene_name = s.name+".scene"
142 if scene_name not in resources:
143 scene_res = scene_exporter.export_scene(s, resources)
144 resources[scene_name] = scene_res
145 dummy_res.create_reference_statement("ref", scene_res)
148 subtask = task.task(s, 0.5)
149 seq_name = s.name+".seq"
150 if seq_name not in resources:
151 scene_exporter.export_sequence_resources(s, resources)
152 seq_res = scene_exporter.export_sequence(s, resources)
153 resources[seq_name] = seq_res
154 dummy_res.create_reference_statement("ref", seq_res)
156 task = ctx.task("Writing files", 1.0)
157 refs = dummy_res.collect_references()
159 r.write_to_file(os.path.join(out_dir, r.name))