4 def export_to_file(self, ctx, out_fn, *, collection=False, shared_resources=False):
5 objects = context.context.selected_objects
10 task = ctx.task("Exporting resources", 1.0)
11 dummy_res = self.export_resources(task, objects, resources, material_atlases)
13 path, base = os.path.split(out_fn)
14 base, ext = os.path.splitext(base)
16 task = ctx.task("Writing files", 1.0)
17 refs = dummy_res.collect_references()
18 if not shared_resources:
21 res_ext = os.path.splitext(r.name)[1]
22 n = numbers.get(res_ext, 0)
24 r.name = "{}_{}{}".format(base, n, res_ext)
27 numbers[res_ext] = n+1
30 dummy_res.write_collection(out_fn, exclude_self=True)
33 r.write_to_file(os.path.join(path, r.name))
35 def export_resources(self, ctx, objects, resources, material_atlases):
36 if material_atlases is None:
39 object_exporter = None
40 camera_exporter = None
41 armature_exporter = None
44 from .datafile import Resource
45 dummy_res = Resource("dummy", "dummy")
47 ctx.set_slices(len(objects))
49 task = ctx.next_slice(obj)
53 res_name = obj.name+".object"
54 if res_name not in resources:
55 if not object_exporter:
56 from .export_object import ObjectExporter
57 object_exporter = ObjectExporter()
58 object_exporter.export_object_resources(task, obj, resources, material_atlases)
59 res = object_exporter.export_object(obj, resources)
60 elif obj.type=='CAMERA':
61 res_name = obj.name+".camera"
62 if res_name not in resources:
63 if not camera_exporter:
64 from .export_camera import CameraExporter
65 camera_exporter = CameraExporter()
66 res = camera_exporter.export_camera(obj)
67 elif obj.type=='ARMATURE':
68 res_name = obj.name+".arma"
69 if res_name not in resources:
70 if not armature_exporter:
71 from .export_armature import ArmatureExporter
72 armature_exporter = ArmatureExporter()
73 res = armature_exporter.export_armature(obj)
74 elif obj.type=='LIGHT':
75 res_name = obj.name+".light"
76 if res_name not in resources:
77 if not light_exporter:
78 from .export_light import LightExporter
79 light_exporter = LightExporter()
80 res = light_exporter.export_light(obj)
83 resources[res_name] = res
84 dummy_res.create_reference_statement("ref", res)
88 class ProjectExporter:
89 def export_to_directory(self, ctx, out_dir):
90 from .scene import create_scene_chain
92 task = ctx.task("Preparing scenes", 0.0)
93 task.set_slices(len(ctx.context.blend_data.scenes))
97 for s in ctx.context.blend_data.scenes:
98 subtask = task.next_slice(s)
99 if s.export_disposition=='IGNORE':
102 if s.export_disposition=='SEQUENCE':
103 scene = create_scene_chain(s, scenes)
104 sequences.append(scene)
105 elif s.export_disposition!='IGNORE' and s.name not in scenes:
106 scene = create_scene(s)
107 if s.export_disposition=='SCENE':
108 scenes[scene.name] = scene
111 for s in scenes.values():
112 all_objects += s.prototypes
113 all_objects += s.lights
115 all_objects.append(s.camera)
117 scene_queue = list(scenes.values())
120 s = scene_queue.pop(0)
121 if not s.background_set or s.background_set in ordered_scenes:
122 ordered_scenes.append(s)
124 scene_queue.append(s)
126 from .util import make_unique
127 all_objects = make_unique(all_objects)
129 from .export_scene import SceneExporter
130 scene_exporter = SceneExporter()
131 data_exporter = DataExporter()
133 task = ctx.task("Exporting resources", 1.0)
135 dummy_res = data_exporter.export_resources(task, all_objects, resources, None)
137 task = ctx.task("Exporting scenes", 1.0)
138 for s in ordered_scenes:
139 subtask = task.task(s, 0.5)
140 scene_name = s.name+".scene"
141 if scene_name not in resources:
142 scene_res = scene_exporter.export_scene(s, resources)
143 resources[scene_name] = scene_res
144 dummy_res.create_reference_statement("ref", scene_res)
147 subtask = task.task(s, 0.5)
148 seq_name = s.name+".seq"
149 if seq_name not in resources:
150 scene_exporter.export_sequence_resources(s, resources)
151 seq_res = scene_exporter.export_sequence(s, resources)
152 resources[seq_name] = seq_res
153 dummy_res.create_reference_statement("ref", seq_res)
155 task = ctx.task("Writing files", 1.0)
156 refs = dummy_res.collect_references()
158 r.write_to_file(os.path.join(out_dir, r.name))