Convert a 2D grid of tile values into the minimal set of axis-aligned
rectangles that cover the solid cells, using the requested merge strategy.
The result is geometry-only — no Body or Shape is created — which makes
this function reusable for debug overlays, rendering, or custom body
construction. buildTilemapBody is a thin wrapper that converts the
rectangles to Polygon shapes.
Greedy meshing reduces shape count dramatically for typical platformer
maps. A 50-tile floor strip becomes one rectangle; a solid 10x10 block
becomes one rectangle instead of 100. Fewer shapes = smaller broadphase
footprint, faster narrowphase, less debug-draw work.
Convert a 2D grid of tile values into the minimal set of axis-aligned rectangles that cover the solid cells, using the requested merge strategy.
The result is geometry-only — no
BodyorShapeis created — which makes this function reusable for debug overlays, rendering, or custom body construction. buildTilemapBody is a thin wrapper that converts the rectangles toPolygonshapes.Greedy meshing reduces shape count dramatically for typical platformer maps. A 50-tile floor strip becomes one rectangle; a solid 10x10 block becomes one rectangle instead of 100. Fewer shapes = smaller broadphase footprint, faster narrowphase, less debug-draw work.