Fuse touching plinth wings, tighten slab/roof simplification, and trim LOD2 size

This commit is contained in:
Meta Vens 2026-12-06 02:57:45 +01:00
commit 59780cf3e5

View file

@ -945,7 +945,8 @@ def _build_roof_zones(
geoms = list(merged.geoms) if hasattr(merged, "geoms") else [merged]
for g in geoms:
if isinstance(g, Polygon) and g.area > 0.8:
gs = g.simplify(0.42, preserve_topology=True)
simp_r = 0.42 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 0.72
gs = g.simplify(simp_r, preserve_topology=True)
if isinstance(gs, Polygon) and gs.area > 0.8:
g = gs
# Add gentle eave overhang on pitched slopes
@ -1064,24 +1065,38 @@ def build_cga_building(
micro_zone, arch_style = classify_sion_micro_zone(objektart, name, pts_enz, r_rtd, raw_min_y, raw_max_y)
pal = _choose_building_palette(b_hash, micro_zone, objektart)
simplify_tol = 0.25 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 0.55
simplify_tol = 0.30 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 0.75
footprints = _extract_footprint_polygons(fl_rtd, w_rtd, r_rtd, s_rtd, simplify_tol=simplify_tol)
if not footprints:
xmin, zmin = float(all_pts[:, 0].min()), float(all_pts[:, 2].min())
xmax, zmax = float(all_pts[:, 0].max()), float(all_pts[:, 2].max())
footprints = [_clean_polygon_2d(box(xmin, zmin, max(xmin + 1.5, xmax), max(zmin + 1.5, zmax))) or box(xmin, zmin, xmin + 2.0, zmin + 2.0)]
if len(footprints) > 1:
fused = unary_union([fp.buffer(0.12, join_style="mitre") for fp in footprints]).buffer(-0.12, join_style="mitre")
f_geoms = list(fused.geoms) if hasattr(fused, "geoms") else [fused]
cleaned_f = []
for g in f_geoms:
if isinstance(g, Polygon):
pc = _clean_polygon_2d(g, min_area=1.5)
if pc is not None:
cleaned_f.append(pc)
if cleaned_f:
cleaned_f.sort(key=lambda p: p.area, reverse=True)
footprints = cleaned_f
primary_fp = footprints[0]
fp_cx, fp_cz = primary_fp.centroid.x, primary_fp.centroid.y
bldg_center_xz = np.array([fp_cx, fp_cz], dtype=np.float64)
# Final Plinth polygons (NO minimum_rotated_rectangle expansion -> 0 floating overhang)
plinth_tol = 0.30 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 0.70
# Final Plinth polygons (NO minimum_rotated_rectangle expansion; secondary parts kept strictly separated)
plinth_tol = 0.45 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 1.05
plinth_fps: list[Polygon] = []
for fp in footprints:
ps = fp.simplify(plinth_tol, preserve_topology=True)
pc = _clean_polygon_2d(ps if isinstance(ps, Polygon) else fp, min_area=0.8) or fp
plinth_fps.append(pc)
pc = _clean_polygon_2d(ps if isinstance(ps, Polygon) else fp, min_area=1.2) or fp
if not plinth_fps or all(pc.distance(prev) > 0.25 for prev in plinth_fps):
plinth_fps.append(pc)
plinth_fp = plinth_fps[0]
# Sample terrain height across the FINAL baked Plinth footprint polygons
@ -1195,8 +1210,8 @@ def build_cga_building(
lod2_solids: list[tuple[np.ndarray, int]] = []
lod2_body_h = max(1.0, eave_y - plinth_bot_y - 0.02)
for pfp in plinth_fps:
l2_fp = pfp.simplify(0.65, preserve_topology=True)
l2_fp = _clean_polygon_2d(l2_fp if isinstance(l2_fp, Polygon) else pfp, min_area=0.5) or pfp
l2_fp = pfp.simplify(1.25, preserve_topology=True)
l2_fp = _clean_polygon_2d(l2_fp if isinstance(l2_fp, Polygon) else pfp, min_area=1.0) or pfp
l2_t, _, _, _ = extrude_2d_poly_prism(
np.array([0.0, plinth_bot_y, 0.0]), u_xz, v_xz, n_up, fp_to_uv(l2_fp),
0.0, lod2_body_h,
@ -1222,11 +1237,11 @@ def build_cga_building(
if is_mauer:
max_roofs = 0
elif micro_zone in (MICRO_FORTRESS, MICRO_CIVIC):
max_roofs = 8
max_roofs = 6
elif micro_zone in (MICRO_OLD_TOWN, MICRO_CLAVAU, MICRO_SUBURBAN):
max_roofs = 4
else:
max_roofs = 3
else:
max_roofs = 2
roof_items = _build_roof_zones(
r_rtd, plinth_fps, eave_y, bldg_center_xz, pal, max_roofs, micro_zone, objektart
)
@ -1316,16 +1331,24 @@ def build_cga_building(
slab_inset = min(wall_thick * 0.45, 0.20)
slab_polys_uv: list[Polygon] = []
for pfp in plinth_fps:
sfp = pfp.buffer(-slab_inset, join_style="mitre")
sfp = pfp.simplify(0.95, preserve_topology=True)
if not isinstance(sfp, Polygon) or sfp.is_empty or sfp.area < 0.8:
sfp = pfp
sfp = sfp.buffer(-slab_inset, join_style="mitre")
if not isinstance(sfp, (Polygon, MultiPolygon)) or sfp.is_empty:
sfp = pfp.buffer(-0.05, join_style="mitre")
sfp = sfp.intersection(pfp)
geoms = list(sfp.geoms) if hasattr(sfp, "geoms") else [sfp]
valid_geoms = [_clean_polygon_2d(g, min_area=0.4) for g in geoms if isinstance(g, Polygon)]
valid_geoms = [_clean_polygon_2d(g, min_area=0.6) for g in geoms if isinstance(g, Polygon)]
valid_geoms = [g for g in valid_geoms if g is not None]
if not valid_geoms:
valid_geoms = [pfp]
# Keep secondary sub-polygons strictly non-touching
kept_geoms: list[Polygon] = []
for vg in valid_geoms:
if not kept_geoms or all(vg.distance(k) > 0.15 for k in kept_geoms):
kept_geoms.append(vg)
for vg in kept_geoms:
slab_polys_uv.append(fp_to_uv(vg))
slab_thick = 0.28
@ -1396,7 +1419,8 @@ def build_cga_building(
prev_bay_mids = cur_bay_mids
# 5. Roof Zones anchored to top-tier perimeter WallBays (never floating solely on 0.8m core)
for r_render, r_col, r_c3 in roof_items:
lod2_roof_cap = 4 if micro_zone in (MICRO_FORTRESS, MICRO_CIVIC) else 2
for r_i, (r_render, r_col, r_c3) in enumerate(roof_items):
if len(zones) >= MAX_ZONES_PER_BUILDING:
break
if prev_bay_indices:
@ -1411,7 +1435,8 @@ def build_cga_building(
else:
r_sup = plinth_bit
r_idx = add_zone(ZONE_ROOF_SEGMENT, pal["roof_class"], ZONE_FLAG_EXTERIOR, r_sup, r_render, r_col)
lod2_solids.append((zones[r_idx].col_tris, pal["roof"]))
if r_i < lod2_roof_cap:
lod2_solids.append((zones[r_idx].col_tris, pal["roof"]))
all_pts_bounds = np.vstack([z.render_tris.reshape(-1, 3) for z in zones] + [z.col_tris.reshape(-1, 3) for z in zones])
bmin = all_pts_bounds.min(axis=0)