mapbox/martini

Vertex winding order

davenquinn opened this issue · 3 comments

I'm working on a prototype module that uses this library + Mapbox elevation tiles to render QuantizedMeshTerrainData tiles in Cesium.

I've managed to get a version working that creates a mesh in Cesium, but all of the tiles are (rather hilariously) warped.

image

I think the issue relates to some combination of the winding order of triangles and the sorting of vertices. Cesium apparently expects triangles wound in counterclockwise order; there may be some restrictions on the sorting of vertices as well (see e.g. this example dataset). I've tried several combinations of rewinding triangles and sorting vertices to no avail.

This may be a better issue to raise in the Cesium context, but I thought I would start here: are there any guarantees on winding order given by this library? Does the pattern of artifacts in my image above look diagnostic of any particular failure mode? Perhaps a few words in the documentation about how the output mesh is structured would allay my confusion.

This seems like it could be the same issue as #5 (comment) — can you check?

Hey @mourner,

It works now! Thanks for looking at this and resetting my brain. I had already looked at #5 and dismissed (I was already extracting heightfield values). But reviewing it again at your behest, I found an off-by-one indexing error in my code. 🤦

image

I'll be working on some of the low-hanging performance and optimization fruit, and bundling into a module, but we can now represent global terrain in Cesium using only streaming Mapbox data! Thanks for laying the groundwork for this advance.