kekscom / osmbuildings

OSM Buildings Classic 2.5D
http://osmbuildings.org
BSD 2-Clause "Simplified" License
505 stars 140 forks source link

Clipping issues where buildings/building-parts touch each other #59

Closed eliasp closed 5 years ago

eliasp commented 10 years ago

See this building for example.

Move the viewport slightly to the left/right to see a weird clipping issue between the building-parts.

As GIF:
osmb-anim

kekscom commented 10 years ago

There should be full triangulation in order to determine each face's position and correct overlapping. because of performance I rather compare centroids of building objects. At some point near CAM_Y axis or if objects bboxes are nested (like in your example), there will be such effects.

Unfortunately I have not much time to solve this quickly.

I'll link this to #34.

AbelVM commented 9 years ago

Maybe taking relative heights into account, could fix some cases. Test case: two nested polygons, outer' height=1, inner' height = 10: Image of practical case (Labels are placed in centroids) Higher buildings roofs should never be overlapped by lower buildings roofs

kekscom commented 9 years ago

Problem here is overlapping. I can easily sort heights and also distances of object centers from view point. It's also possible to check for intersection but that is a very costly operation. For the 2.5D renderer I see only web workers as an option to handle all the sorting.

AbelVM commented 9 years ago

So, you get the center of each 2D polygon, extrude it to its height and then apply Painter's algorithm, setting a z-index to each 3D building (as a whole) using its 2D center.

I've been playing for some hours triying to make a 3D calculation of z-index sorting without performance hit and keeping Painter's algorithm as core to avoid deep changes. No success.

The only way to keep this algorithm is checking each poligon 3D center, I mean each wall and ceiling as 3D polygons. And even this way, nested or concave buildings could fail. Painter's algorithm has this issue.

Maybe Newell's Algorithm could help with this cases. Will play some more and post results if any.

kekscom commented 9 years ago

Hi, Thanks for putting in the effort. I'm curious for a better solution as well but can't make it right now. I ended up with these conclusions:

  1. It should be feasible to improve the current 2D sorting rules to eliminate more glitches.
  2. Performance wise, there is likely no proper solution at all for nested objects. Maybe it has to be accepted.
  3. I see potential in handling faces instead of objects (like you do). It could be even faster to draw that way. Keep going!