5 def export_to_file(self, context, out_fn, *, collection=False, shared_resources=False):
6 from .util import Progress
7 progress = Progress(context)
9 objects = context.selected_objects
14 dummy_res = self.export_resources(context, objects, resources, material_atlases, progress)
16 path, base = os.path.split(out_fn)
17 base, ext = os.path.splitext(base)
19 refs = dummy_res.collect_references()
20 if not shared_resources:
23 res_ext = os.path.splitext(r.name)[1]
24 n = numbers.get(res_ext, 0)
26 r.name = "{}_{}{}".format(base, n, res_ext)
29 numbers[res_ext] = n+1
32 dummy_res.write_collection(out_fn, exclude_self=True)
35 r.write_to_file(os.path.join(path, r.name))
37 def export_resources(self, context, objects, resources, material_atlases, progress):
38 if material_atlases is None:
41 object_exporter = None
42 camera_exporter = None
43 armature_exporter = None
46 from .datafile import Resource
47 dummy_res = Resource("dummy", "dummy")
49 for i, obj in enumerate(objects):
50 progress.push_task_slice(obj.name, i, len(objects))
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(context, obj, resources, material_atlases, progress)
60 res = object_exporter.export_object(obj, resources, progress)
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(context, 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)
91 class ProjectExporter:
92 def export_to_directory(self, context, out_dir):
93 from .util import Progress
94 progress = Progress(context)
96 from .scene import create_scene_chain
100 for s in context.blend_data.scenes:
101 if s.export_disposition=='IGNORE':
104 if s.export_disposition=='SEQUENCE':
105 scene = create_scene_chain(s, scenes)
106 sequences.append(scene)
107 elif s.name not in scenes:
108 scene = create_scene(s)
109 if s.export_disposition=='SCENE':
110 scenes[scene.name] = scene
113 for s in scenes.values():
114 all_objects += s.prototypes
115 all_objects += s.lights
117 all_objects.append(s.camera)
119 scene_queue = list(scenes.values())
122 s = scene_queue.pop(0)
123 if not s.background_set or s.background_set in ordered_scenes:
124 ordered_scenes.append(s)
126 scene_queue.append(s)
128 from .util import make_unique
129 all_objects = make_unique(all_objects)
131 from .export_scene import SceneExporter
132 scene_exporter = SceneExporter()
133 data_exporter = DataExporter()
136 dummy_res = data_exporter.export_resources(context, all_objects, resources, None, progress)
137 for s in ordered_scenes:
138 scene_name = s.name+".scene"
139 if scene_name not in resources:
140 scene_res = scene_exporter.export_scene(s, resources)
141 resources[scene_name] = scene_res
142 dummy_res.create_reference_statement("ref", scene_res)
145 seq_name = s.name+".seq"
146 if seq_name not in resources:
147 scene_exporter.export_sequence_resources(s, resources)
148 seq_res = scene_exporter.export_sequence(s, resources)
149 resources[seq_name] = seq_res
150 dummy_res.create_reference_statement("ref", seq_res)
152 refs = dummy_res.collect_references()
154 r.write_to_file(os.path.join(out_dir, r.name))