4 def export_to_file(self, ctx, out_fn, *, collection=False, shared_resources=False):
5 objects = ctx.context.selected_objects
9 task = ctx.task("Exporting resources", 1.0)
10 dummy_res = self.export_resources(task, objects, resources)
12 path, base = os.path.split(out_fn)
13 base, ext = os.path.splitext(base)
15 task = ctx.task("Writing files", 1.0)
16 refs = dummy_res.collect_references()
17 if not shared_resources:
20 res_ext = os.path.splitext(r.name)[1]
21 n = numbers.get(res_ext, 0)
23 r.name = "{}_{}{}".format(base, n, res_ext)
26 numbers[res_ext] = n+1
29 dummy_res.write_collection(out_fn, exclude_self=True)
32 r.write_to_file(os.path.join(path, r.name))
34 def export_resources(self, ctx, objects, resources):
35 object_exporter = None
36 camera_exporter = None
37 armature_exporter = None
40 from .datafile import Resource
41 dummy_res = Resource("dummy", "dummy")
43 ctx.set_slices(len(objects))
45 task = ctx.next_slice(obj)
49 res_name = obj.name+".object"
50 if res_name not in resources:
51 if not object_exporter:
52 from .export_object import ObjectExporter
53 object_exporter = ObjectExporter()
54 object_exporter.export_object_resources(task, obj, resources)
55 res = object_exporter.export_object(obj, resources)
56 elif obj.type=='CAMERA':
57 res_name = obj.name+".camera"
58 if res_name not in resources:
59 if not camera_exporter:
60 from .export_camera import CameraExporter
61 camera_exporter = CameraExporter()
62 res = camera_exporter.export_camera(obj)
63 elif obj.type=='ARMATURE':
64 res_name = obj.name+".arma"
65 if res_name not in resources:
66 if not armature_exporter:
67 from .export_armature import ArmatureExporter
68 armature_exporter = ArmatureExporter()
69 res = armature_exporter.export_armature(obj)
70 elif obj.type=='LIGHT':
71 res_name = obj.name+".light"
72 if res_name not in resources:
73 if not light_exporter:
74 from .export_light import LightExporter
75 light_exporter = LightExporter()
76 res = light_exporter.export_light(obj)
79 resources[res_name] = res
80 dummy_res.create_reference_statement("ref", res)
84 class ProjectExporter:
85 def export_to_directory(self, ctx, out_dir):
86 from .scene import create_scene, create_scene_chain
88 task = ctx.task("Preparing scenes", 0.0)
89 task.set_slices(len(ctx.context.blend_data.scenes))
94 for s in ctx.context.blend_data.scenes:
95 subtask = task.next_slice(s)
96 if s.export_disposition=='SEQUENCE':
97 scene = create_scene_chain(s, scenes)
98 sequences.append(scene)
99 scene_queue.append(scene)
100 elif s.export_disposition!='IGNORE' and s.name not in scenes:
101 scene = create_scene(s)
102 scenes[scene.name] = scene
103 if s.export_disposition=='SCENE':
104 scene_queue.append(scene)
107 for s in scenes.values():
108 all_objects += [p.object for p in s.prototypes]
109 all_objects += s.lights
111 all_objects.append(s.camera)
115 s = scene_queue.pop(0)
116 if not s.background_set or s.background_set in ordered_scenes:
117 ordered_scenes.append(s)
119 scene_queue.append(s)
121 from .util import make_unique
122 all_objects = make_unique(all_objects)
124 from .export_scene import SceneExporter
125 scene_exporter = SceneExporter()
126 data_exporter = DataExporter()
128 task = ctx.task("Exporting resources", 1.0)
130 dummy_res = data_exporter.export_resources(task, all_objects, resources)
132 task = ctx.task("Exporting scenes", 1.0)
133 for s in ordered_scenes:
134 subtask = task.task(s, 0.5)
135 scene_name = s.name+".scene"
136 if scene_name not in resources:
137 scene_res = scene_exporter.export_scene(s, resources)
138 resources[scene_name] = scene_res
139 dummy_res.create_reference_statement("ref", scene_res)
141 task = ctx.task("Exporting sequences", 1.0)
143 subtask = task.task(s, 0.5)
144 seq_name = s.name+".seq"
145 if seq_name not in resources:
146 scene_exporter.export_sequence_resources(s, resources)
147 seq_res = scene_exporter.export_sequence(s, resources)
148 resources[seq_name] = seq_res
149 dummy_res.create_reference_statement("ref", seq_res)
151 task = ctx.task("Writing files", 1.0)
152 refs = dummy_res.collect_references()
154 r.write_to_file(os.path.join(out_dir, r.name))