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(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
50 from .datafile import Resource
51 dummy_res = Resource("dummy", "dummy")
53 for i, obj in enumerate(objects):
54 progress.push_task_slice(obj.name, i, len(objects))
58 res_name = obj.name+".object"
59 if res_name not in resources:
60 if not object_exporter:
61 from .export_object import ObjectExporter
62 object_exporter = ObjectExporter()
63 object_exporter.export_object_resources(context, obj, resources, material_atlases, progress)
64 res = object_exporter.export_object(obj, resources, progress)
65 elif obj.type=='CAMERA':
66 res_name = obj.name+".camera"
67 if res_name not in resources:
68 if not camera_exporter:
69 from .export_camera import CameraExporter
70 camera_exporter = CameraExporter()
71 res = camera_exporter.export_camera(obj)
72 elif obj.type=='ARMATURE':
73 res_name = obj.name+".arma"
74 if res_name not in resources:
75 if not armature_exporter:
76 from .export_armature import ArmatureExporter
77 armature_exporter = ArmatureExporter()
78 res = armature_exporter.export_armature(context, obj)
79 elif obj.type=='LIGHT':
80 res_name = obj.name+".light"
81 if res_name not in resources:
82 if not light_exporter:
83 from .export_light import LightExporter
84 light_exporter = LightExporter()
85 res = light_exporter.export_light(obj)
88 resources[res_name] = res
89 dummy_res.create_reference_statement("ref", res)
95 class ProjectExporter:
96 def export_to_directory(self, context, out_dir):
97 from .util import Progress
98 progress = Progress(context)
100 from .scene import create_scene_chain
104 for s in context.blend_data.scenes:
105 if s.export_disposition=='IGNORE':
108 if s.export_disposition=='SEQUENCE':
109 scene = create_scene_chain(s, scenes)
110 sequences.append(scene)
111 elif s.name not in scenes:
112 scene = create_scene(s)
113 if s.export_disposition=='SCENE':
114 scenes[scene.name] = scene
117 for s in scenes.values():
118 all_objects += s.prototypes
119 all_objects += s.lights
121 all_objects.append(s.camera)
123 from .util import make_unique
124 all_objects = make_unique(all_objects)
126 from .export_scene import SceneExporter
127 scene_exporter = SceneExporter()
128 data_exporter = DataExporter()
131 dummy_res = data_exporter.export_resources(context, all_objects, resources, None, progress)
132 for s in scenes.values():
133 scene_name = s.name+".scene"
134 if scene_name not in resources:
135 scene_res = scene_exporter.export_scene(s, resources)
136 resources[scene_name] = scene_res
137 dummy_res.create_reference_statement("ref", scene_res)
140 seq_name = s.name+".seq"
141 if seq_name not in resources:
142 scene_exporter.export_sequence_resources(s, resources)
143 seq_res = scene_exporter.export_sequence(s, resources)
144 resources[seq_name] = seq_res
145 dummy_res.create_reference_statement("ref", seq_res)
147 refs = dummy_res.collect_references()
149 r.write_to_file(os.path.join(out_dir, r.name))