Sort TerrainQuads

I can’t think of a good solution to sort all the TerrainQuads from TerraMonkey into a 2D Node Array. I’ve already managed to find all of them in one terrain node (recursive).
Thank you for help and pls reply,

You can get the local translation of each one and sort them from that.
The only other way would be to create a class in the same package as TerrainQuad so you can get access to the findLeftPatch() fintTopPatch() etc. methods of each patch.

Trying to manage this, but there’s an error:

java.lang.ArrayIndexOutOfBoundsException: 8
at main.nav_mesh.NavMeshAppState.sort2D(
at main.nav_mesh.NavMeshAppState.<init>(
at main.GameAppState.initialize(
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(

and here’s my code:
[java]private Node[][] sort2D(Node[] nodes, int size) {
double dsize = Math.sqrt(nodes.length);
int quadSize = (int) dsize;
if(quadSize != dsize) {
throw new IllegalArgumentException(“Size must be a square”);
int quadWidth = Math.abs((int) nodes[0].getLocalTranslation().x);
Node[][] chunks = new Node[quadSize][quadSize];
for(int i = 0; i < nodes.length; i++) {
Vector3f trans = nodes[i].getWorldTranslation();
trans = trans.add(size / 2, 0, size / 2);
float xpos = (int) trans.x / quadWidth;
float zpos = (int) trans.z / quadWidth;
if(i == 16) {
chunks[(int) xpos - 1][(int) zpos - 1] = nodes[i];
return chunks;

Hard to tell what line 8 is in your pasted code.
Why are you pulling out the quads and storing them in an array in a nav mesh class? If you are trying to have the terrain parsed by the nav mesh generator, the NavMeshGenerator class in the SDK will do that for you automatically.

Ik, but im trying to regen the NavMesh in specific chunks.