X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=blender%2Fio_mspgl%2Fexport_scene.py;h=ac812abf7b115766ab0c08af3848614a4ff99ab4;hb=HEAD;hp=ac3bf0be184e31999e285eeb54c3a29c16c1dcfd;hpb=26b3d7bb741bf27468bfad7224a3d06a72579a68;p=libs%2Fgl.git diff --git a/blender/io_mspgl/export_scene.py b/blender/io_mspgl/export_scene.py index ac3bf0be..4f983977 100644 --- a/blender/io_mspgl/export_scene.py +++ b/blender/io_mspgl/export_scene.py @@ -33,7 +33,7 @@ class SceneExporter: from .export import DataExporter data_exporter = DataExporter() - data_exporter.export_resources(ctx, scene.prototypes, resources, None) + data_exporter.export_resources(ctx, [p.object for p in scene.prototypes], resources) def export_scene(self, scene, resources): from .datafile import Resource, Statement, Token @@ -67,28 +67,53 @@ class SceneExporter: def add_instances(self, scene_res, statements, instances, resources): from .datafile import Statement + array_prototypes = [] + for i in instances: - obj_res = resources[i.prototype.name+".object"] - st = scene_res.create_reference_statement("object", obj_res, i.name) + if i.prototype.use_array: + if i.prototype not in array_prototypes: + array_prototypes.append(i.prototype) + continue - ss = Statement("transform") + obj_res = resources[i.prototype.name+".object"] + st = scene_res.create_reference_statement("object", obj_res) + if i.name: + st.append(i.name) - loc = i.matrix_world.to_translation() - ss.sub.append(Statement("position", *tuple(loc))) + st.sub.append(self.create_transform_statement(i)) + statements.append(st) - 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)); - else: - ss.sub.append(Statement("rotation", quat.angle*180/math.pi, *tuple(quat.axis))) + for p in array_prototypes: + obj_res = resources[p.name+".object"] + st = scene_res.create_reference_statement("array", obj_res) - scale = i.matrix_world.to_scale() - ss.sub.append(Statement("scale", *tuple(scale))) + for i in p.instances: + ss = Statement("instance") + ss.sub.append(self.create_transform_statement(i)) + st.sub.append(ss) - st.sub.append(ss) statements.append(st) + def create_transform_statement(self, instance): + from .datafile import Statement + + st = Statement("transform") + + loc = instance.matrix_world.to_translation() + st.sub.append(Statement("position", *tuple(loc))) + + quat = instance.matrix_world.to_quaternion() + if instance.rotation_mode in ('XYZ', 'XZY', 'YXZ', 'YZX', 'ZXY', 'ZYX'): + angles = [a*180/math.pi for a in quat.to_euler()] + st.sub.append(Statement("euler", *angles)); + else: + st.sub.append(Statement("rotation", quat.angle*180/math.pi, *tuple(quat.axis))) + + scale = instance.matrix_world.to_scale() + st.sub.append(Statement("scale", *tuple(scale))) + + return st + def export_sequence_resources(self, scene, resources): from .datafile import Resource, Statement, Token @@ -149,8 +174,8 @@ class SceneExporter: use_shadow = True shadowed_lights += [l.data for l in s.lights if l.data.use_shadow] for i in itertools.chain(s.instances, s.blended_instances): - p = i.prototype - if p.material_slots and p.material_slots[0].material and p.material_slots[0].material.shadow_method!='NONE': + o = i.prototype.object + if o.material_slots and o.material_slots[0].material and o.material_slots[0].material.shadow_method!='NONE': shadow_casters.append(i) s = s.background_set @@ -288,7 +313,7 @@ class SceneExporter: def compute_bounding_sphere(self, instances): points = [] for i in instances: - points += [i.matrix_world@mathutils.Vector(c) for c in i.prototype.bound_box] + points += [i.matrix_world@mathutils.Vector(c) for c in i.prototype.object.bound_box] from .util import compute_bounding_sphere return compute_bounding_sphere(points)