mapbox / martini

A JavaScript library for real-time RTIN terrain mesh generation
https://observablehq.com/@mourner/martin-real-time-rtin-terrain-mesh
ISC License
609 stars 41 forks source link

Stitching seams #7

Open sjlynch opened 4 years ago

sjlynch commented 4 years ago

Cool library! I tiled a bunch of RTIN terrains together and there is a seams issue that I was unable to resolve. The edges of each mesh has an irregular number of vertices, so it is not sufficient to average each edge's height because the vertices don't line up. Adding difference thresholds (i.e. average each vertex as long as it is within some lat/lng range) will work but it results in texture stretching. Is there any plan to address seams? Included some screenshots below. I'm on a gtx 1080 getting 120fps with this many tiles.

Another method, directly applying height to a planebuffergeometry, works and is easy to stitch but I get 55fps with that method. Clearly RTINs offer an immense amount of optimization, but I don't know where to go from here with the seams issue. I could try hiding seams with skirts? Is there a better way?

image

image

mourner commented 4 years ago

Yeah, I think skirts are the easiest option — probably worth adding an API for generating them to the library.

mourner commented 4 years ago

Equivalent issue in Delatin: https://github.com/mapbox/delatin/issues/2

chrisgervang commented 4 years ago

How could I generate skirts?

kylebarron commented 4 years ago

Making skirts inside Martini itself would improve performance compared to implementing it downstream so that the triangles array wouldn't have to be copied into a new, larger array.

It looks like getMesh would have to be modified with an optional skirt argument, and then both the initial scan to count the required number of vertices and triangles and the second pass filling them into the arrays would need to be updated. I'm still struggling to actually wrap my head around the code, so I'm not sure I'll be able to write a PR for this.