- res_dir = os.path.join(path, base+"_resources")
- if not os.path.exists(res_dir):
- os.makedirs(res_dir)
- for i, o in enumerate(unique_objects):
- progress.push_task_slice(o.name, i, len(unique_objects))
- st = object_export.export_object(context, o, progress)
- with open(os.path.join(res_dir, o.name+".object"), "w") as obj_out:
- for s in st:
- s.write_to_file(obj_out)
- progress.pop_task()
-
- statements = self.export_scene(context, objs, progress, prototypes=object_prototypes)
-
- with open(out_fn, "w") as out_file:
- for s in statements:
- s.write_to_file(out_file)
-
- def export_scene(self, context, objs, progress, *, prototypes=None):
- from .datafile import Statement
- statements = []
-
- for o in objs:
- st = Statement("object", "{}.object".format(prototypes[o.name].name))
- # 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:]
+ scene_res.write_to_file(out_fn)
+ for r in refs:
+ r.write_to_file(os.path.join(path, r.name))
+
+ def export_scene(self, scene, resources, progress):
+ 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));