- resources = {}
- self.export_scene_resources(context, unique_objects, resources, progress)
-
- scene_res = self.export_scene(context, objs, progress, prototypes=object_prototypes, resources=resources)
- refs = scene_res.collect_references()
-
- from .datafile import Statement
- if self.resource_collection:
- keywords = { ".mat": "material",
- ".mesh": "mesh",
- ".object": "object",
- ".tech": "technique",
- ".tex2d": "texture2d" }
- with open(os.path.join(path, base+"_resources.mdc"), "w") as res_out:
- for r in refs:
- st = Statement(keywords[os.path.splitext(r.name)[1]], r.name)
- st.sub = r.statements
- st.write_to_file(res_out)
- else:
- res_dir = os.path.join(path, base+"_resources")
- if not os.path.exists(res_dir):
- os.makedirs(res_dir)
- for r in refs:
- with open(os.path.join(res_dir, r.name), "w") as res_out:
- for s in r.statements:
- s.write_to_file(res_out)
-
- with open(out_fn, "w") as out_file:
- for s in scene_res.statements:
- s.write_to_file(out_file)
-
- def export_scene_resources(self, context, objs, resources, progress):
- from .export_object import ObjectExporter
- object_export = ObjectExporter()
- object_export.single_file = False
-
- material_maps = {}
-
- for i, o in enumerate(objs):
- progress.push_task_slice(o.name, i, len(objs))
- object_export.export_object_resources(context, o, resources, progress, material_maps=material_maps)
- obj_name = o.name+".object"
- resources[obj_name] = object_export.export_object(context, o, progress, resources=resources)
- progress.pop_task()
-
- def export_scene(self, context, objs, progress, *, prototypes, resources):
- from .datafile import Resource, Statement
- scene_res = Resource("scene.scene")
-
- for o in objs:
- obj_res = resources[prototypes[o.name].name+".object"]
- st = scene_res.create_reference_statement("object", obj_res)
- # XXX Parent relationships screw up the location and rotation
- st.sub.append(Statement("position", o.location[0], o.location[1], o.location[2]))
- if o.rotation_mode=="AXIS_ANGLE":
- angle = o.rotation_axis_angle[0]
- axis = o.rotation_axis_angle[1:]
+ data_exporter.export_resources(context, scene.prototypes, resources, None, progress)
+
+ def export_scene(self, scene, resources):
+ from .datafile import Resource, Statement, Token
+ scene_res = Resource(scene.name+".scene", "scene")
+
+ scene_res.statements.append(Statement("type", Token(scene.scene_type.lower())))
+
+ for i in scene.instances:
+ obj_res = resources[i.prototype+".object"]
+ st = scene_res.create_reference_statement("object", obj_res, i.name)
+
+ ss = Statement("transform")
+
+ loc = i.matrix_world.to_translation()
+ ss.sub.append(Statement("position", *tuple(loc)))
+
+ quat = i.matrix_world.to_quaternion()
+ if i.rotation_mode in ('XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'):
+ angles = [a*180/math.pi for a in quat.to_euler()]
+ ss.sub.append(Statement("euler", *angles));