Fixed IndexArrayOutOfBound that may occur in BatchNode.Also optimized temp array allocation in case there is no tangents buffer

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@8965 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
rem..om 13 years ago
parent da3b43174c
commit 93a181b4c7
  1. 19
      engine/src/core/com/jme3/scene/BatchNode.java

@ -78,6 +78,8 @@ public class BatchNode extends Node implements Savable {
private float[] tmpFloat; private float[] tmpFloat;
private float[] tmpFloatN; private float[] tmpFloatN;
private float[] tmpFloatT; private float[] tmpFloatT;
int maxVertCount = 0;
boolean useTangents = false;
/** /**
* Construct a batchNode * Construct a batchNode
@ -178,7 +180,7 @@ public class BatchNode extends Node implements Savable {
protected void doBatch() { protected void doBatch() {
///List<Geometry> tmpList = new ArrayList<Geometry>(); ///List<Geometry> tmpList = new ArrayList<Geometry>();
Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>(); Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>();
maxVertCount = 0;
gatherGeomerties(matMap, this); gatherGeomerties(matMap, this);
batches.clear(); batches.clear();
int nbGeoms = 0; int nbGeoms = 0;
@ -200,6 +202,12 @@ public class BatchNode extends Node implements Savable {
batch.geometry.getMesh().updateBound(); batch.geometry.getMesh().updateBound();
batches.put(material, batch); batches.put(material, batch);
} }
//init temp float arrays
tmpFloat = new float[maxVertCount * 3];
tmpFloatN = new float[maxVertCount * 3];
if (useTangents) {
tmpFloatT = new float[maxVertCount * 4];
}
logger.log(Level.INFO, "Batched {0} geometries in {1} batches.", new Object[]{nbGeoms, batches.size()}); logger.log(Level.INFO, "Batched {0} geometries in {1} batches.", new Object[]{nbGeoms, batches.size()});
} }
@ -352,7 +360,6 @@ public class BatchNode extends Node implements Savable {
int totalVerts = 0; int totalVerts = 0;
int totalTris = 0; int totalTris = 0;
int totalLodLevels = 0; int totalLodLevels = 0;
int maxVertCount = 0;
Mesh.Mode mode = null; Mesh.Mode mode = null;
for (Geometry geom : geometries) { for (Geometry geom : geometries) {
@ -464,6 +471,9 @@ public class BatchNode extends Node implements Savable {
FloatBuffer inPos = (FloatBuffer) inBuf.getData(); FloatBuffer inPos = (FloatBuffer) inBuf.getData();
FloatBuffer outPos = (FloatBuffer) outBuf.getData(); FloatBuffer outPos = (FloatBuffer) outBuf.getData();
doCopyBuffer(inPos, globalVertIndex, outPos); doCopyBuffer(inPos, globalVertIndex, outPos);
if (VertexBuffer.Type.Tangent.ordinal() == bufType) {
useTangents = true;
}
} else { } else {
for (int vert = 0; vert < geomVertCount; vert++) { for (int vert = 0; vert < geomVertCount; vert++) {
int curGlobalVertIndex = globalVertIndex + vert; int curGlobalVertIndex = globalVertIndex + vert;
@ -475,9 +485,6 @@ public class BatchNode extends Node implements Savable {
globalVertIndex += geomVertCount; globalVertIndex += geomVertCount;
globalTriIndex += geomTriCount; globalTriIndex += geomTriCount;
} }
tmpFloat = new float[maxVertCount * 3];
tmpFloatN = new float[maxVertCount * 3];
tmpFloatT = new float[maxVertCount * 4];
} }
private void doTransforms(FloatBuffer bufPos, FloatBuffer bufNorm, int start, int end, Matrix4f transform) { private void doTransforms(FloatBuffer bufPos, FloatBuffer bufNorm, int start, int end, Matrix4f transform) {
@ -593,8 +600,6 @@ public class BatchNode extends Node implements Savable {
bufTangents.put(tmpFloatT, 0, tanLength); bufTangents.put(tmpFloatT, 0, tanLength);
} }
private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf) { private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf) {
TempVars vars = TempVars.get(); TempVars vars = TempVars.get();
Vector3f pos = vars.vect1; Vector3f pos = vars.vect1;

Loading…
Cancel
Save