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
3.0
rem..om 13 years ago
parent b7affd0147
commit bc0207f1fc
  1. 19
      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<Material, Batch> batches = new HashMap<Material, Batch>();
/**
* a map storing he batches by geometry to qickly acces the batch when updating
*/
protected Map<Geometry, Batch> batchesByGeom = new HashMap<Geometry, Batch>();
/**
* 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<Material, List<Geometry>> entry : matMap.entrySet()) {
Mesh m = new Mesh();
@ -202,6 +205,7 @@ 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);
@ -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<Geometry> list) {
for (Geometry geom : list) {
batchesByGeom.put(geom, this);
}
}
Geometry geometry;
boolean needMeshUpdate = false;
}

Loading…
Cancel
Save