tangram-es
tangram-es copied to clipboard
Extruded polygon markers rendering problem (i16 vertex wraparound)
TO REPRODUCE THE ISSUE, FOLLOW THESE STEPS:
-
create a small polygon: double size = 0.000005; Tangram::LngLat coordinates[] = { {lng - size, lat}, {lng, lat + size}, {lng + size, lat}, {lng, lat - size}, {lng - size, lat}, }; map->markerSetPolygon(marker_id, coordinates, counts, 1);
-
in the style, set elevation to
elevation: 100
RESULT:
Extruded polygon is distorted/reaches into the ground (and is basically not visible),
EXPECTED RESULT:
See a large extruded polygon.
ENVIRONMENT:
- OSX App
- master, roughly on 0.8.0
OTHER:
Hello everyone,
I tried to use extruded polygon markers and they actually work nicely - as long as the 2D bounding box is reasonably big in relation to the extrusion. When the bounding box is too small, the extrusion stops working and the geometry is weirdly destroyed.
I debugged that and the reason seems to be that the model-coordinates for the polygon are normalized on the extent of the 2D bounding box (MarkerManager::setPolygon
/ float scale = 1.f / marker->extent()
). This does not include the height/extrusion. When extrusion is added to a small polygon, the vertex z coordinates in glm::i16vec4 PolygonVertexNoUVs::pos
wrap around. I was able to fix that (somehow), by adding a constant to Marker::extent() :
float Marker::extent() const {
return glm::max(glm::max(m_bounds.width(), m_bounds.height()), 100.);
}
But that is probably not a good idea, or is it?
If I read the GeoJSON parser code right, then GeoJSON geometry is normalised on the tile size (
GeoJson::parseTile
/ double tileInverseScale = 1.0 / tileBounds.width()
). The same seems to be true of Mvt (Mvt::getGeometry
/ double invTileExtent = (1.0/(_ctx.tileExtent-1.0))
) and TopoJson (TopoJson::parseTile
/ double tileInverseScale = 1.0 / tileBounds.width()
). ClientGeoJsonSource seems to use a constant of 4096.
Hi all,
I have an internal patch for this. I added a method
float Marker::modelScale() const {
return glm::max(extent(), 1024.f);
}
In the model building code I replaced some calls where the Marker::extent() was used as the model scale with this. This fixes the problem. Do you want me to make a pull request?
So, I have a patch for this issue and made a video.
This is the problem:
What you see here is two rectangular extruded polygons. The extrusion property is changed with marker style string updates. Both markers always have the same extrusion value. As you can see they wrap around. You can also see, that the smaller one wraps around much earlier than the bigger one due to the smaller extent.
This is the same with the fix:
Reopening! (See #2100) for more details.