Hi, i was creating a voxel game and I used roboleary’s code for greedy meshing:
But the problem is, when i set the chunk width and height to not be equal, it throws an IndexOutOfBoundsException at
for(x[v] = 0; x[v] < CHUNK_HEIGHT; x[v]++) {
for(x[u] = 0; x[u] < CHUNK_WIDTH; x[u]++) {
/*
* Here we retrieve two voxel faces for comparison.
*/
voxelFace = (x[d] >= 0 ) ? getVoxelFace(x[0], x[1], x[2], side) : null;
voxelFace1 = (x[d] < CHUNK_WIDTH - 1) ? getVoxelFace(x[0] + q[0], x[1] + q[1], x[2] + q[2], side) : null;
/*
* Note that we're using the equals function in the voxel face class here, which lets the faces
* be compared based on any number of attributes.
*
* Also, we choose the face to add to the mask depending on whether we're moving through on a backface or not.
*/
mask[n++] = ((voxelFace != null && voxelFace1 != null && voxelFace.equals(voxelFace1)))
? null
: backFace ? voxelFace1 : voxelFace;
}
}
The Exception is at
voxelFace1 = (x[d] < CHUNK_WIDTH - 1) ? getVoxelFace(x[0] + q[0], x[1] + q[1], x[2] + q[2], side) : null;
thrown at the getVoxelFace method
The Exception goes like
“Index 64 out of Bounds for length 64”
When chunk width is 64 and height 128
Anyone know whats going on?