diff --git a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java index 42034ea047..883090c7aa 100644 --- a/jme3-core/src/main/java/com/jme3/scene/BatchNode.java +++ b/jme3-core/src/main/java/com/jme3/scene/BatchNode.java @@ -246,13 +246,7 @@ protected void doBatch() { //init the temp arrays if something has been batched only. if (matMap.size() > 0) { - //TODO these arrays should be allocated by chunk instead to avoid recreating them each time the batch is changed. - //init temp float arrays - tmpFloat = new float[maxVertCount * 3]; - tmpFloatN = new float[maxVertCount * 3]; - if (useTangents) { - tmpFloatT = new float[maxVertCount * 4]; - } + initTempFloatArrays(); } } @@ -387,7 +381,6 @@ private void mergeGeometries(Mesh outMesh, List geometries) { int maxWeights = -1; Mesh.Mode mode = null; - float lineWidth = 1f; for (Geometry geom : geometries) { totalVerts += geom.getVertexCount(); totalTris += geom.getTriangleCount(); @@ -537,6 +530,7 @@ private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, Float Vector3f norm = vars.vect2; Vector3f tan = vars.vect3; + validateTempFloatArrays(end - start); int length = (end - start) * 3; int tanLength = (end - start) * 4; @@ -617,6 +611,22 @@ private void doTransforms(FloatBuffer bindBufPos, FloatBuffer bindBufNorm, Float } } + private void validateTempFloatArrays(int vertCount) { + if (maxVertCount < vertCount) { + maxVertCount = vertCount; + initTempFloatArrays(); + } + } + + private void initTempFloatArrays() { + //TODO these arrays should be allocated by chunk instead to avoid recreating them each time the batch is changed. + tmpFloat = new float[maxVertCount * 3]; + tmpFloatN = new float[maxVertCount * 3]; + if (useTangents) { + tmpFloatT = new float[maxVertCount * 4]; + } + } + private void doCopyBuffer(FloatBuffer inBuf, int offset, FloatBuffer outBuf, int componentSize) { TempVars vars = TempVars.get(); Vector3f pos = vars.vect1;