From 18ce27faae3b3f5229ac328e713f574fa93686f0 Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Sun, 23 Oct 2011 14:30:22 +0000 Subject: [PATCH] Changes to Y-is-Up-Axis issue. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8516 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../scene/plugins/blender/BlenderLoader.java | 4 +++- .../plugins/blender/meshes/MeshHelper.java | 13 +++++++++--- .../plugins/blender/objects/ObjectHelper.java | 20 +++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java index fd25d1357..49998293f 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/BlenderLoader.java @@ -210,7 +210,9 @@ public class BlenderLoader extends AbstractBlenderLoader { helper = blenderContext.getHelper(CurvesHelper.class); helper.setyIsUpAxis(true); helper = blenderContext.getHelper(ArmatureHelper.class); - helper.setyIsUpAxis(true); + helper.setyIsUpAxis(true); + helper = blenderContext.getHelper(MeshHelper.class); + helper.setyIsUpAxis(true); } MaterialHelper materialHelper = blenderContext.getHelper(MaterialHelper.class); materialHelper.setFaceCullMode(blenderKey.getFaceCullMode()); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java index 6584fa6f8..9b74f4031 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java @@ -498,9 +498,16 @@ public class MeshHelper extends AbstractBlenderHelper { Pointer pMVert = (Pointer) meshStructure.getFieldValue("mvert"); List mVerts = pMVert.fetchData(blenderContext.getInputStream()); - for (int i = 0; i < verticesAmount; ++i) { - DynamicArray coordinates = (DynamicArray) mVerts.get(i).getFieldValue("co"); - vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue()); + if(this.fixUpAxis) { + for (int i = 0; i < verticesAmount; ++i) { + DynamicArray coordinates = (DynamicArray) mVerts.get(i).getFieldValue("co"); + vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(2).floatValue(), coordinates.get(1).floatValue()); + } + } else { + for (int i = 0; i < verticesAmount; ++i) { + DynamicArray coordinates = (DynamicArray) mVerts.get(i).getFieldValue("co"); + vertices[i] = new Vector3f(coordinates.get(0).floatValue(), coordinates.get(1).floatValue(), coordinates.get(2).floatValue()); + } } return vertices; } diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java index 71cd407cf..1089b8b7c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/objects/ObjectHelper.java @@ -282,14 +282,6 @@ public class ObjectHelper extends AbstractBlenderHelper { //load parent inverse matrix Pointer pParent = (Pointer) objectStructure.getFieldValue("parent"); - Structure parent = null; - if(pParent.isNotNull()) { - try { - parent = pParent.fetchData(blenderContext.getInputStream()).get(0); - } catch (BlenderFileException e) { - LOGGER.log(Level.WARNING, "Cannot fetch parent for object! Reason: {0}", e.getLocalizedMessage()); - } - } Matrix4f parentInv = pParent.isNull() ? Matrix4f.IDENTITY : this.getMatrix(objectStructure, "parentinv"); //create the global matrix (without the scale) @@ -309,12 +301,18 @@ public class ObjectHelper extends AbstractBlenderHelper { size.get(1).floatValue() * scaleY, size.get(2).floatValue() * scaleZ); - //the root object is transformed if the Y axis is UP - if(fixUpAxis && (pParent.isNull() || (parent!=null && !this.shouldBeLoaded(parent, blenderContext)))) { + if(fixUpAxis) { float y = translation.y; translation.y = translation.z; translation.z = -y; - rotation = this.upAxisRotationQuaternion.mult(rotation); + + y = rotation.getY(); + float z = rotation.getZ(); + rotation.set(rotation.getX(), z, -y, rotation.getW()); + + y=scale.y; + scale.y = scale.z; + scale.z = -y; } //create the result