Closed eliasp closed 5 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.
Maybe taking relative heights into account, could fix some cases. Test case: two nested polygons, outer' height=1, inner' height = 10: (Labels are placed in centroids) Higher buildings roofs should never be overlapped by lower buildings roofs
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.
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.
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:
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: