From 61ad7717488918af6fb19eb1e1fbf009372788de Mon Sep 17 00:00:00 2001 From: "Kae..pl" Date: Sun, 13 Jan 2013 21:32:04 +0000 Subject: [PATCH] Bugfix: 538: Multiple issues with female3.blend Yay finally found that one :D Models with multiple materials and armatures should now load withour mesh deformations :D git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10066 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../plugins/blender/meshes/MeshContext.java | 29 ++++++++++++------- .../plugins/blender/meshes/MeshHelper.java | 8 ++--- .../blender/modifiers/ArmatureModifier.java | 10 ++++--- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java index e273d4bc6..b62173a21 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java @@ -21,9 +21,9 @@ public class MeshContext { /** The UV-coordinates for each of the geometries. */ private Map uvCoordinates = new HashMap(); /** Bind buffer for vertices is stored here and applied when required. */ - private VertexBuffer bindPoseBuffer; + private Map bindPoseBuffer = new HashMap(); /** Bind buffer for normals is stored here and applied when required. */ - private VertexBuffer bindNormalBuffer; + private Map bindNormalBuffer = new HashMap(); /** * Adds a geometry for the specified material index. @@ -102,34 +102,43 @@ public class MeshContext { /** * This method sets the bind buffer for vertices. * + * @param materialIndex + * the index of the mesh's material * @param bindNormalBuffer * the bind buffer for vertices */ - public void setBindNormalBuffer(VertexBuffer bindNormalBuffer) { - this.bindNormalBuffer = bindNormalBuffer; + public void setBindNormalBuffer(int materialIndex, + VertexBuffer bindNormalBuffer) { + this.bindNormalBuffer.put(materialIndex, bindNormalBuffer); } /** + * @param materialIndex + * the index of the mesh's material * @return the bind buffer for vertices */ - public VertexBuffer getBindNormalBuffer() { - return bindNormalBuffer; + public VertexBuffer getBindNormalBuffer(int materialIndex) { + return bindNormalBuffer.get(materialIndex); } /** * This method sets the bind buffer for normals. * + * @param materialIndex + * the index of the mesh's material * @param bindNormalBuffer * the bind buffer for normals */ - public void setBindPoseBuffer(VertexBuffer bindPoseBuffer) { - this.bindPoseBuffer = bindPoseBuffer; + public void setBindPoseBuffer(int materialIndex, VertexBuffer bindPoseBuffer) { + this.bindPoseBuffer.put(materialIndex, bindPoseBuffer); } /** + * @param materialIndex + * the index of the mesh's material * @return the bind buffer for normals */ - public VertexBuffer getBindPoseBuffer() { - return bindPoseBuffer; + public VertexBuffer getBindPoseBuffer(int materialIndex) { + return bindPoseBuffer.get(materialIndex); } } 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 c8e71a3b0..7dbdf72e8 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 @@ -173,17 +173,17 @@ public class MeshHelper extends AbstractBlenderHelper { // initial vertex position (used with animation) VertexBuffer verticesBind = new VertexBuffer(Type.BindPosePosition); - verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.clone(verticesBuffer.getData())); + verticesBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getVertices(materialIndex))); VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal); normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex))); // initial normals position (used with animation) VertexBuffer normalsBind = new VertexBuffer(Type.BindPoseNormal); - normalsBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.clone(normalsBuffer.getData())); + normalsBind.setupData(Usage.CpuOnly, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex))); mesh.setBuffer(verticesBuffer); - meshContext.setBindPoseBuffer(verticesBind);//this is stored in the context and applied when needed (when animation is applied to the mesh) + meshContext.setBindPoseBuffer(materialIndex, verticesBind);//this is stored in the context and applied when needed (when animation is applied to the mesh) // setting vertices colors if (verticesColors != null) { @@ -193,7 +193,7 @@ public class MeshHelper extends AbstractBlenderHelper { // setting faces' normals mesh.setBuffer(normalsBuffer); - meshContext.setBindNormalBuffer(normalsBind);//this is stored in the context and applied when needed (when animation is applied to the mesh) + meshContext.setBindNormalBuffer(materialIndex, normalsBind);//this is stored in the context and applied when needed (when animation is applied to the mesh) // creating the result Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh); diff --git a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java index ee5da3002..f077a198c 100644 --- a/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java +++ b/engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java @@ -206,11 +206,13 @@ import com.jme3.util.BufferUtils; mesh.setBuffer(buffers[0]); mesh.setBuffer(buffers[1]); - if(meshContext.getBindNormalBuffer() != null) { - mesh.setBuffer(meshContext.getBindNormalBuffer()); + VertexBuffer bindNormalBuffer = (meshContext.getBindNormalBuffer(materialIndex)); + if(bindNormalBuffer != null) { + mesh.setBuffer(bindNormalBuffer); } - if(meshContext.getBindPoseBuffer() != null) { - mesh.setBuffer(meshContext.getBindPoseBuffer()); + VertexBuffer bindPoseBuffer = (meshContext.getBindPoseBuffer(materialIndex)); + if(bindPoseBuffer != null) { + mesh.setBuffer(bindPoseBuffer); } //change the usage type of vertex and normal buffers from Static to Stream mesh.getBuffer(Type.Position).setUsage(Usage.Stream);