TerrainPatch Stitching

I am loading my terrain from a byte array height map, and converting it into a terrainpatch and putting it on screen, my issue resides in connecting the height maps when I load a grid of them, I could make them all into one mesh but I simply don’t want to do that for the purpose of this program. I have done my best with research, but with no luck. I write this psudo code to try and get me started but I am still not sure:

public static void normalize(){
	int top = -1;
	int left = -1;
	int bottom = -1;
	int right = -1;
	int topleft = -1;
	int topright = -1;
	int bottomright = -1;
	int bottomleft = -1;
	int center = -1;
	ArrayList<Integer> arr = new ArrayList<Integer>();
	while (!arr.isEmpty()) {
		int next = findSmallest(arr);
		if (topleft == -1) {
			topleft = next;
		} else if (top == -1) {
			top = next;
		} else if (topright == -1) {
			topright = next;
		} else if (left == -1) {
			left = next;
		} else if (center == -1) {
			center = next;
		} else if (right == -1) {
			right = next;
		} else if (bottomleft == -1) {
			bottomleft = next;
		} else if (bottom == -1) {
			bottom = next;
		} else if (bottomright == -1) {
			bottomright = next;
		} else {

I just want to connect the terrain at the edges as it does inside the terrainpatch, each patch of terrain needs to be separate (or at least accessible that way) because each height map is loaded from a separate file.

Any ideas on how to stitch together the terrain? I have done sufficient research, I think, to merit a forum post. The closest I got in concept was loading a 3x3 grid, indexed by a number from top left to bottom right, then processing them and sending them to the fixnormaledges method, never even got to try it because the method is protected.

Any help is appreciated! Thanks!

Something like this?

1 Like

yeah! sorry for the latent reply, been trying to get it to work but for some reason my terrain looks like this when using that code

any ideas? If I figure it out I’ll post the fix.

figured it out, still having issues though, in my original code (back when I was using quads) I had tile size of 13, and block size of 65, my data was bit shifted by 3 – the issue displayed above was because of me trying to put the bit shift back to 3. The issue is that it only seems to accept a block size of 129, if it is the original 65, then it just does not render, but if it is the block size of 129, my height map does not account for that, any ideas?

wait, I got it working but it still is not attaching the terrain, like, the edges are not touching, my goal in this post is to get the edges of each grid to meet eachother. am I missing something?

Maybe this will help.

private int bitCalc(int blockSize)
        switch (blockSize)
            case 17: return 4;
            case 33: return 5;
            case 65: return 6;
            case 129: return 7;
            case 257: return 8;
            case 513: return 9;
            case 1025: return 10;

        throw new IllegalArgumentException("Invalid block size specified.");

I am on my phone right now, will try to be a little more verbose when i get on my pc if you are still stuck.

I got the bitshift working with that, thanks! but I am still unclear about terrain stitching, such as the fixnormaledges method in terrainpatch (which is protected for some reason) - I want to connect adjacent terrainchunks the same way that tiles connect to eachother within each chunk, seamless type thing.

They will stitch if your height maps are correct. Can you maybe post some that should be next to each other so we can check?

err sure! I’ll post the .chunks because the files I am loading them from are stupid complex and you can likely load these easier, MEGA

The height maps I have do not line up directly on their own, in the game engine I am using to draw the game they are stitched manually, but I am using jmonkey to make a map editor.

wait, I think it does line up! I just have a 64x64 height map, is there any way to compensate for the extra row of height maps? – sorry for being all over the place, I am trying to work it out as much as I can.

Erm… not really im afraid…

not really was right, but I did a cheaty thing to get close enough for the purposes of my application for now:
tq.setLocalScale(1.015625f, 1f, 1.015625f);
in the getterrainchunk method