[SOLVED] Adding two vertex index arrays together

Title basically says it all… I’m trying to add two vertex indices (int[]) arrays together… And it’s not really working. :-\ I think I’m taking the wrong approach on it.

if(this.vertexPositions == null){
        // The vertex buffer is clear
	this.vertexPositions = modelPositions;
	this.vertexTextureUVs = modelTextureUVs;
	this.vertexNormals = modelNormals;
	this.vertexIndices = modelIndices;
} else {
        // A model previously has been added to the vertex buffer
	vertexPositions = concatenate(vertexPositions, modelPositions);
	vertexTextureUVs = concatenate(vertexTextureUVs, modelTextureUVs);
	vertexNormals = concatenate(vertexNormals, modelNormals);
	
-    Bulk of the problem:
	int oldSize = vertexIndices.length;
	for(int i = 0; i < modelIndices.length; i++){
		modelIndices[i] += oldSize;
	}
	
	vertexIndices = concatenate(vertexIndices, modelIndices);
}

Concatenate int[] with int[], I have another for float arrays, but they’re really the same… :wink:

private int[] concatenate (int[] A, int[] B) {
    int aLen = A.length;
    int bLen = B.length;

    int[] C = (int[]) Array.newInstance(A.getClass().getComponentType(), aLen+bLen);
    System.arraycopy(A, 0, C, 0, aLen);
    System.arraycopy(B, 0, C, aLen, bLen);

    return C;
}

Hehe, used the old indices length, instead of how many vertices were added.

int oldSize = (vertexPositions.length / 4);
for(int i = 0; i < modelIndices.length; i++){
	modelIndices[i] += oldSize;
	
}
			
vertexIndices = concatenate(vertexIndices, modelIndices);

vertexPositions = concatenate(vertexPositions, modelPositions);
vertexTextureUVs = concatenate(vertexTextureUVs, modelTextureUVs);
vertexNormals = concatenate(vertexNormals, modelNormals);