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
3.0
Kae..pl 12 years ago
parent 4bbbf7dbe8
commit 61ad771748
  1. 29
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshContext.java
  2. 8
      engine/src/blender/com/jme3/scene/plugins/blender/meshes/MeshHelper.java
  3. 10
      engine/src/blender/com/jme3/scene/plugins/blender/modifiers/ArmatureModifier.java

@ -21,9 +21,9 @@ public class MeshContext {
/** The UV-coordinates for each of the geometries. */ /** The UV-coordinates for each of the geometries. */
private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>(); private Map<Geometry, VertexBuffer> uvCoordinates = new HashMap<Geometry, VertexBuffer>();
/** Bind buffer for vertices is stored here and applied when required. */ /** Bind buffer for vertices is stored here and applied when required. */
private VertexBuffer bindPoseBuffer; private Map<Integer, VertexBuffer> bindPoseBuffer = new HashMap<Integer, VertexBuffer>();
/** Bind buffer for normals is stored here and applied when required. */ /** Bind buffer for normals is stored here and applied when required. */
private VertexBuffer bindNormalBuffer; private Map<Integer, VertexBuffer> bindNormalBuffer = new HashMap<Integer, VertexBuffer>();
/** /**
* Adds a geometry for the specified material index. * Adds a geometry for the specified material index.
@ -102,34 +102,43 @@ public class MeshContext {
/** /**
* This method sets the bind buffer for vertices. * This method sets the bind buffer for vertices.
* *
* @param materialIndex
* the index of the mesh's material
* @param bindNormalBuffer * @param bindNormalBuffer
* the bind buffer for vertices * the bind buffer for vertices
*/ */
public void setBindNormalBuffer(VertexBuffer bindNormalBuffer) { public void setBindNormalBuffer(int materialIndex,
this.bindNormalBuffer = bindNormalBuffer; VertexBuffer bindNormalBuffer) {
this.bindNormalBuffer.put(materialIndex, bindNormalBuffer);
} }
/** /**
* @param materialIndex
* the index of the mesh's material
* @return the bind buffer for vertices * @return the bind buffer for vertices
*/ */
public VertexBuffer getBindNormalBuffer() { public VertexBuffer getBindNormalBuffer(int materialIndex) {
return bindNormalBuffer; return bindNormalBuffer.get(materialIndex);
} }
/** /**
* This method sets the bind buffer for normals. * This method sets the bind buffer for normals.
* *
* @param materialIndex
* the index of the mesh's material
* @param bindNormalBuffer * @param bindNormalBuffer
* the bind buffer for normals * the bind buffer for normals
*/ */
public void setBindPoseBuffer(VertexBuffer bindPoseBuffer) { public void setBindPoseBuffer(int materialIndex, VertexBuffer bindPoseBuffer) {
this.bindPoseBuffer = bindPoseBuffer; this.bindPoseBuffer.put(materialIndex, bindPoseBuffer);
} }
/** /**
* @param materialIndex
* the index of the mesh's material
* @return the bind buffer for normals * @return the bind buffer for normals
*/ */
public VertexBuffer getBindPoseBuffer() { public VertexBuffer getBindPoseBuffer(int materialIndex) {
return bindPoseBuffer; return bindPoseBuffer.get(materialIndex);
} }
} }

@ -173,17 +173,17 @@ public class MeshHelper extends AbstractBlenderHelper {
// initial vertex position (used with animation) // initial vertex position (used with animation)
VertexBuffer verticesBind = new VertexBuffer(Type.BindPosePosition); 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); VertexBuffer normalsBuffer = new VertexBuffer(Type.Normal);
normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex))); normalsBuffer.setupData(Usage.Static, 3, Format.Float, BufferUtils.createFloatBuffer(meshBuilder.getNormals(materialIndex)));
// initial normals position (used with animation) // initial normals position (used with animation)
VertexBuffer normalsBind = new VertexBuffer(Type.BindPoseNormal); 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); 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 // setting vertices colors
if (verticesColors != null) { if (verticesColors != null) {
@ -193,7 +193,7 @@ public class MeshHelper extends AbstractBlenderHelper {
// setting faces' normals // setting faces' normals
mesh.setBuffer(normalsBuffer); 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 // creating the result
Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh); Geometry geometry = new Geometry(name + (geometries.size() + 1), mesh);

@ -206,11 +206,13 @@ import com.jme3.util.BufferUtils;
mesh.setBuffer(buffers[0]); mesh.setBuffer(buffers[0]);
mesh.setBuffer(buffers[1]); mesh.setBuffer(buffers[1]);
if(meshContext.getBindNormalBuffer() != null) { VertexBuffer bindNormalBuffer = (meshContext.getBindNormalBuffer(materialIndex));
mesh.setBuffer(meshContext.getBindNormalBuffer()); if(bindNormalBuffer != null) {
mesh.setBuffer(bindNormalBuffer);
} }
if(meshContext.getBindPoseBuffer() != null) { VertexBuffer bindPoseBuffer = (meshContext.getBindPoseBuffer(materialIndex));
mesh.setBuffer(meshContext.getBindPoseBuffer()); if(bindPoseBuffer != null) {
mesh.setBuffer(bindPoseBuffer);
} }
//change the usage type of vertex and normal buffers from Static to Stream //change the usage type of vertex and normal buffers from Static to Stream
mesh.getBuffer(Type.Position).setUsage(Usage.Stream); mesh.getBuffer(Type.Position).setUsage(Usage.Stream);

Loading…
Cancel
Save