From bc0207f1fc10f3005818277503102d570d18a33c Mon Sep 17 00:00:00 2001 From: "rem..om" Date: Wed, 11 Apr 2012 22:03:11 +0000 Subject: [PATCH] BatchNode is now indexing the batches by geometry to easily retrieve them during the update phase. This is fixing this issue http://jmonkeyengine.org/groups/general-2/forum/topic/batchnode-not-accounting-for-transformations-in-cloned-spatials/#post-170945 git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9287 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- engine/src/core/com/jme3/scene/BatchNode.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/engine/src/core/com/jme3/scene/BatchNode.java b/engine/src/core/com/jme3/scene/BatchNode.java index 6b9035b7a..d47118df4 100644 --- a/engine/src/core/com/jme3/scene/BatchNode.java +++ b/engine/src/core/com/jme3/scene/BatchNode.java @@ -37,7 +37,6 @@ import com.jme3.math.Matrix4f; import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.scene.mesh.IndexBuffer; -import com.jme3.util.IntMap.Entry; import com.jme3.util.TempVars; import java.io.IOException; import java.nio.Buffer; @@ -46,7 +45,6 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; @@ -73,6 +71,10 @@ public class BatchNode extends Node implements Savable { * the map of geometry holding the batched meshes */ protected Map batches = new HashMap(); + /** + * a map storing he batches by geometry to qickly acces the batch when updating + */ + protected Map batchesByGeom = new HashMap(); /** * used to store transformed vectors before proceeding to a bulk put into the FloatBuffer */ @@ -141,7 +143,7 @@ public class BatchNode extends Node implements Savable { } protected void updateSubBatch(Geometry bg) { - Batch batch = batches.get(bg.getMaterial()); + Batch batch = batchesByGeom.get(bg); if (batch != null) { Mesh mesh = batch.geometry.getMesh(); @@ -190,6 +192,7 @@ public class BatchNode extends Node implements Savable { batch.geometry.removeFromParent(); } batches.clear(); + batchesByGeom.clear(); } for (Map.Entry> entry : matMap.entrySet()) { Mesh m = new Mesh(); @@ -202,7 +205,8 @@ public class BatchNode extends Node implements Savable { mergeGeometries(m, list); m.setDynamic(); Batch batch = new Batch(); - + batch.updateGeomList(list); + batch.geometry = new Geometry(name + "-batch" + batches.size()); batch.geometry.setMaterial(material); this.attachChild(batch.geometry); @@ -648,6 +652,15 @@ public class BatchNode extends Node implements Savable { protected class Batch { + /** + * update the batchesByGeom map for this batch with the given List of geometries + * @param list + */ + void updateGeomList(List list) { + for (Geometry geom : list) { + batchesByGeom.put(geom, this); + } + } Geometry geometry; boolean needMeshUpdate = false; }