Generating contour in the mesh

I generated a terrain with heightmap and mapped an image over the terrain.

This is my terrain.

I want user to be able to click a pixel in the scene and pixel around that selected pixel with same height should be selected.

I dont know how can i do that. I have been checking so many things and still has no idea what to do.

As far as i have checked, i am sensing that this is something related to contour tree.

Can anyone please help me?

I’m not aware of a solution, sorry. You need some sort of object detection to find the river in the image first. And then you have to map somehow the related parts of the image to a connected list of triangles. This is all non-trivial stuff.

I updated the question, can you please check it again

I can only add advice of one of solution. After click, need to render screen like renderTarget, then get pixel color of clicked coordinate. Then in terrrain shader add uniform there can add selected pixel color. And into shader add code which highlight same pixel of color height. But its highlight all same pixels, not only arround.
If need hightlight only river, then maybe need second invisible terrain with texture where terrrain white, and river blue. Then click, run renderTarget, get pixel color. If color is blue, then in real terrain highlight river. Its mean need add in terrain shader code with uniform like:

uniform float river;
uniform sampler2D riverMap;
if(river==1.0){
gl_FragColor+=texture2D(riverMap,vUv);
}

dist_21_readpixel.zip (1.4 MB)

You should look into flood fill and marching ants algorithm, that’s too broad so i can only describe it in short, especially since there’s plenty room for optimizations.

For a brief description of the solution:

  1. Use a 1 channel Uint8Array mask in the resolution of the terrain
  2. Use flood fill to mark the texels of the pixels of same height (or with tolerance) in that mask
  3. Use marching ants to get the contour line of the mask

The mask could be obviously smaller by doing a flood fill bounding box pre-pass. You might also want or need to prevent 1 pixel lines from the flood fill causing too noisy details or the contouring to fail.

Technically it’s like the magic wand selection in Photoshop.

/cc

1 Like

For me it seems, that the desired result is something like this:

hi thank you for the response !!

It turned out for my case for selection, i need to create a contour tree but i don’t know how to make a contour tree.

Can you please guide me how can i create a contour tree in my case where i have mesh, heightmap and the texture to map over the terrain?

Hi @Chaser_Code , It turned out for my case, for selection i need to create a contour tree but i don’t know how to make a contour tree.

Can you please guide me how can i create a contour tree in my case where i have mesh, heightmap and the texture to map over the terrain?

i didn’t know where to start with but what i needed was to select a space in the terrain and rather than just selecting the pixel i want it to select multiple pixel. For that it turned out that i need to create a contour tree but i dont know how to make a contour tree in my case where i have mesh, elevation map / height map data/image, and image to map over the terrain. Can you please help me !!!

@Pravin_Poudel
I still didn’t get what you want to achieve.
Flat surface with isolines, made from heightmap:

What i described gives you the contour as a linked list you can simplify by angle then. If you don’t know how to do any of it you can also commission someone.

1 Like

Ok, thank you, i will study more and i will check again if I can get more from your answer once i have more knowledge.

Regarding doing, i don’t have option to commission to someone because this is me learning stuff on my own, not related to professional job.

Thank you so much !!!