Преглед на файлове

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

Kae..pl преди 12 години
родител
ревизия
61ad771748

+ 19 - 10
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<Geometry, VertexBuffer>	uvCoordinates	= new HashMap<Geometry, VertexBuffer>();
 	/** 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. */
-	private VertexBuffer				bindNormalBuffer;
+	private Map<Integer, VertexBuffer>				bindNormalBuffer = new HashMap<Integer, VertexBuffer>();
 
 	/**
 	 * 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);
 	}
 }

+ 4 - 4
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);

+ 6 - 4
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);