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
This commit is contained in:
parent
b7affd0147
commit
bc0207f1fc
@ -37,7 +37,6 @@ import com.jme3.math.Matrix4f;
|
|||||||
import com.jme3.math.Transform;
|
import com.jme3.math.Transform;
|
||||||
import com.jme3.math.Vector3f;
|
import com.jme3.math.Vector3f;
|
||||||
import com.jme3.scene.mesh.IndexBuffer;
|
import com.jme3.scene.mesh.IndexBuffer;
|
||||||
import com.jme3.util.IntMap.Entry;
|
|
||||||
import com.jme3.util.TempVars;
|
import com.jme3.util.TempVars;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.Buffer;
|
import java.nio.Buffer;
|
||||||
@ -46,7 +45,6 @@ import java.util.ArrayList;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
@ -73,6 +71,10 @@ public class BatchNode extends Node implements Savable {
|
|||||||
* the map of geometry holding the batched meshes
|
* the map of geometry holding the batched meshes
|
||||||
*/
|
*/
|
||||||
protected Map<Material, Batch> batches = new HashMap<Material, Batch>();
|
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
|
* 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) {
|
protected void updateSubBatch(Geometry bg) {
|
||||||
Batch batch = batches.get(bg.getMaterial());
|
Batch batch = batchesByGeom.get(bg);
|
||||||
if (batch != null) {
|
if (batch != null) {
|
||||||
Mesh mesh = batch.geometry.getMesh();
|
Mesh mesh = batch.geometry.getMesh();
|
||||||
|
|
||||||
@ -190,6 +192,7 @@ public class BatchNode extends Node implements Savable {
|
|||||||
batch.geometry.removeFromParent();
|
batch.geometry.removeFromParent();
|
||||||
}
|
}
|
||||||
batches.clear();
|
batches.clear();
|
||||||
|
batchesByGeom.clear();
|
||||||
}
|
}
|
||||||
for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) {
|
for (Map.Entry<Material, List<Geometry>> entry : matMap.entrySet()) {
|
||||||
Mesh m = new Mesh();
|
Mesh m = new Mesh();
|
||||||
@ -202,6 +205,7 @@ public class BatchNode extends Node implements Savable {
|
|||||||
mergeGeometries(m, list);
|
mergeGeometries(m, list);
|
||||||
m.setDynamic();
|
m.setDynamic();
|
||||||
Batch batch = new Batch();
|
Batch batch = new Batch();
|
||||||
|
batch.updateGeomList(list);
|
||||||
|
|
||||||
batch.geometry = new Geometry(name + "-batch" + batches.size());
|
batch.geometry = new Geometry(name + "-batch" + batches.size());
|
||||||
batch.geometry.setMaterial(material);
|
batch.geometry.setMaterial(material);
|
||||||
@ -648,6 +652,15 @@ public class BatchNode extends Node implements Savable {
|
|||||||
|
|
||||||
protected class Batch {
|
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;
|
Geometry geometry;
|
||||||
boolean needMeshUpdate = false;
|
boolean needMeshUpdate = false;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user