Sort TerrainQuads

Hello,
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,
Turakar

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(NavMeshAppState.java:83)
at main.nav_mesh.NavMeshAppState.<init>(NavMeshAppState.java:28)
at main.GameAppState.initialize(GameAppState.java:70)
at com.jme3.app.state.AppStateManager.initializePending(AppStateManager.java:219)
at com.jme3.app.state.AppStateManager.update(AppStateManager.java:249)
at com.jme3.app.SimpleApplication.update(SimpleApplication.java:238)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.runLoop(LwjglAbstractDisplay.java:151)
at com.jme3.system.lwjgl.LwjglDisplay.runLoop(LwjglDisplay.java:185)
at com.jme3.system.lwjgl.LwjglAbstractDisplay.run(LwjglAbstractDisplay.java:228)
at java.lang.Thread.run(Thread.java:722)

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) {
System.out.println();
}
chunks[(int) xpos - 1][(int) zpos - 1] = nodes[i];
}
return chunks;
}[/java]

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.