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
This commit is contained in:
parent
da3b43174c
commit
93a181b4c7
@ -78,6 +78,8 @@ public class BatchNode extends Node implements Savable {
|
||||
private float[] tmpFloat;
|
||||
private float[] tmpFloatN;
|
||||
private float[] tmpFloatT;
|
||||
int maxVertCount = 0;
|
||||
boolean useTangents = false;
|
||||
|
||||
/**
|
||||
* Construct a batchNode
|
||||
@ -178,7 +180,7 @@ public class BatchNode extends Node implements Savable {
|
||||
protected void doBatch() {
|
||||
///List<Geometry> tmpList = new ArrayList<Geometry>();
|
||||
Map<Material, List<Geometry>> matMap = new HashMap<Material, List<Geometry>>();
|
||||
|
||||
maxVertCount = 0;
|
||||
gatherGeomerties(matMap, this);
|
||||
batches.clear();
|
||||
int nbGeoms = 0;
|
||||
@ -200,6 +202,12 @@ public class BatchNode extends Node implements Savable {
|
||||
batch.geometry.getMesh().updateBound();
|
||||
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()});
|
||||
}
|
||||
|
||||
@ -352,7 +360,6 @@ public class BatchNode extends Node implements Savable {
|
||||
int totalVerts = 0;
|
||||
int totalTris = 0;
|
||||
int totalLodLevels = 0;
|
||||
int maxVertCount = 0;
|
||||
|
||||
Mesh.Mode mode = null;
|
||||
for (Geometry geom : geometries) {
|
||||
@ -464,6 +471,9 @@ public class BatchNode extends Node implements Savable {
|
||||
FloatBuffer inPos = (FloatBuffer) inBuf.getData();
|
||||
FloatBuffer outPos = (FloatBuffer) outBuf.getData();
|
||||
doCopyBuffer(inPos, globalVertIndex, outPos);
|
||||
if (VertexBuffer.Type.Tangent.ordinal() == bufType) {
|
||||
useTangents = true;
|
||||
}
|
||||
} else {
|
||||
for (int vert = 0; vert < geomVertCount; vert++) {
|
||||
int curGlobalVertIndex = globalVertIndex + vert;
|
||||
@ -475,9 +485,6 @@ public class BatchNode extends Node implements Savable {
|
||||
globalVertIndex += geomVertCount;
|
||||
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) {
|
||||
@ -593,8 +600,6 @@ public class BatchNode extends Node implements Savable {
|
||||
bufTangents.put(tmpFloatT, 0, tanLength);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf) {
|
||||
TempVars vars = TempVars.get();
|
||||
Vector3f pos = vars.vect1;
|
||||
|
Loading…
x
Reference in New Issue
Block a user