From 7c96745555e84bedf644ee437cc88efb5b51fb55 Mon Sep 17 00:00:00 2001 From: Adam Johnson Date: Sat, 13 Jun 2015 15:54:22 -0400 Subject: [PATCH] Tweaks for physical exporting - Applying scale to *all* objects in the scene is now a pre-export step. - Make sure we always export the physical's coordinates--this matches Plasma's behavior. --- korman/exporter/convert.py | 7 +++++++ korman/exporter/physics.py | 21 ++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/korman/exporter/convert.py b/korman/exporter/convert.py index 4d3dfa6..f445a4e 100644 --- a/korman/exporter/convert.py +++ b/korman/exporter/convert.py @@ -79,10 +79,17 @@ class Exporter: print("\nExported {}.age in {:.2f} seconds".format(self.age_name, end-start)) def _collect_objects(self): + apply_xform = bpy.ops.object.transform_apply for obj in bpy.data.objects: if obj.plasma_object.enabled: self._objects.append(obj) + # For our own sanity, we should apply any scale transform this object has. + # Physicals often have issues with unapplied scale transforms. Other transforms + # will be saved to the DSpan or CoordInterface. + context = {"object": obj, "selected_editable_objects": [obj]} + apply_xform(context, scale=True) + def _export_age_info(self): # Make life slightly easier... age_info = bpy.context.scene.world.plasma_age diff --git a/korman/exporter/physics.py b/korman/exporter/physics.py index be5faa0..5d93af4 100644 --- a/korman/exporter/physics.py +++ b/korman/exporter/physics.py @@ -25,21 +25,16 @@ class PhysicsConverter: def _convert_mesh_data(self, bo, physical, indices=True): mesh = bo.data - mesh.update(calc_tessface=True) + mesh.update(calc_tessface=indices) + # Yes, we have to have transform data here, even if we have a CoordInterface mat = bo.matrix_world - if not self._mgr.has_coordiface(bo): - physical.rot = utils.quaternion(mat.to_quaternion()) - physical.pos = utils.vector3(mat.to_translation()) - - # Physicals can't have scale... - scale = mat.to_scale() - if scale[0] == 1.0 and scale[1] == 1.0 and scale[2] == 1.0: - # Whew, don't need to do any math! - vertices = [hsVector3(i.co.x, i.co.y, i.co.z) for i in mesh.vertices] - else: - # Dagnabbit... - vertices = [hsVector3(i.co.x * scale.x, i.co.y * scale.y, i.co.z * scale.z) for i in mesh.vertices] + physical.rot = utils.quaternion(mat.to_quaternion()) + physical.pos = utils.vector3(mat.to_translation()) + + # Vertices are simple. Note that all scale transforms were applied by the exporter long + # before we got here. Yay! + vertices = [hsVector3(i.co.x, i.co.y, i.co.z) for i in mesh.vertices] if indices: indices = []