From 5f7a07246b36458118b64becaa0649393f3761d1 Mon Sep 17 00:00:00 2001 From: Meta Vens Date: Sun, 6 Dec 2026 06:13:24 +0100 Subject: [PATCH] Cut 13b: clean two-sided WallBay buffer, sort plinth wings, and trim LOD2/RCGA budget --- tools/maps/sion/cga_builder.py | 57 ++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/tools/maps/sion/cga_builder.py b/tools/maps/sion/cga_builder.py index e571473..952505f 100644 --- a/tools/maps/sion/cga_builder.py +++ b/tools/maps/sion/cga_builder.py @@ -288,6 +288,8 @@ def extrude_2d_poly_prism( for candidate in ( cleaned, cleaned.simplify(0.05, preserve_topology=True), + cleaned.simplify(0.12, preserve_topology=True), + cleaned.buffer(0.02, join_style="bevel").buffer(-0.02, join_style="bevel"), Polygon(cleaned.exterior.coords), box(*cleaned.bounds), ): @@ -680,6 +682,7 @@ def _partition_ring_into_wall_chains( plinth_fp: Polygon, max_bays: int, base_bay_len: float, + subdivide_long: bool = True, ) -> list[list[tuple[float, float]]]: """ Partition 100% of plinth_fp's outer perimeter ring into <= max_bays contiguous edge chains @@ -709,7 +712,7 @@ def _partition_ring_into_wall_chains( bx, bz = pts[(k + 1) % m] elen = elens[k] n_sub = 1 - if slack > 0 and elen > base_bay_len * 1.15: + if subdivide_long and slack > 0 and elen > base_bay_len * 1.15: want_sub = min(slack + 1, max(1, int(math.ceil(elen / base_bay_len)))) n_sub = want_sub slack -= (n_sub - 1) @@ -757,10 +760,12 @@ def _build_multi_edge_wall_bay_geometry( volume spanning [y_bot, y_top] and lying inward from the outer perimeter inside plinth_fp. """ ls = LineString(chain_pts) - band = ls.buffer(wall_thick, single_sided=True, join_style="mitre", mitre_limit=2.0) + band = ls.buffer(wall_thick, cap_style="flat", join_style="mitre", mitre_limit=2.0) w2d = band.intersection(plinth_fp) if w2d.is_empty: w2d = band + if isinstance(w2d, MultiPolygon): + w2d = w2d.buffer(0.02, join_style="bevel").buffer(-0.02, join_style="bevel") if isinstance(w2d, Polygon): raw_polys = [w2d] if w2d.area >= 0.02 else [] @@ -768,7 +773,7 @@ def _build_multi_edge_wall_bay_geometry( raw_polys = [g for g in getattr(w2d, "geoms", []) if isinstance(g, Polygon) and g.area >= 0.02] if not raw_polys: - fallback = ls.buffer(wall_thick, single_sided=True, join_style="bevel") + fallback = ls.buffer(wall_thick, cap_style="flat", join_style="bevel").intersection(plinth_fp) raw_polys = [fallback] if isinstance(fallback, Polygon) and not fallback.is_empty else [ g for g in getattr(fallback, "geoms", []) if isinstance(g, Polygon) and g.area >= 0.02 ] @@ -1055,7 +1060,8 @@ def _build_roof_zones( mat_top=roof_mat, mat_bot=pal["trim"], mat_side=pal["trim"], ao_top=245, ao_bot=165, ao_side=200, ) - l2_poly_s = poly.simplify(2.4, preserve_topology=True) + l2_roof_tol = 2.4 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 3.6 + l2_poly_s = poly.simplify(l2_roof_tol, preserve_topology=True) l2_poly = _clean_polygon_2d(l2_poly_s if isinstance(l2_poly_s, Polygon) else poly, min_area=0.8) or poly l2_roof_parts = extrude_2d_poly_prism( origin, u_axis, v_axis, n_axis, l2_poly, @@ -1082,7 +1088,8 @@ def _build_roof_zones( mat_top=roof_mat, mat_bot=pal["slab"], mat_side=pal["trim"], ao_top=240, ao_bot=175, ao_side=205, ) - l2_fp_s = uv_poly.simplify(2.2, preserve_topology=True) + l2_roof_tol = 2.2 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 3.6 + l2_fp_s = uv_poly.simplify(l2_roof_tol, preserve_topology=True) l2_uv = _clean_polygon_2d(l2_fp_s if isinstance(l2_fp_s, Polygon) else uv_poly, min_area=0.8) or uv_poly l2_roof_parts = extrude_2d_poly_prism( origin, u_axis, v_axis, n_axis, l2_uv, @@ -1173,13 +1180,18 @@ def build_cga_building( bldg_center_xz = np.array([fp_cx, fp_cz], dtype=np.float64) # Final Plinth polygons (NO minimum_rotated_rectangle expansion; secondary parts kept strictly separated) - plinth_tol = 0.85 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 1.65 + plinth_tol = 0.95 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN, MICRO_CIVIC) else 2.20 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=1.2) or fp + # Strip sub-10cm hairline spikes before Plinth/WallBay/FloorSlab construction + pc_sp = _clean_polygon_2d(pc.buffer(-0.06, join_style="mitre").buffer(0.06, join_style="mitre"), min_area=1.2) + if pc_sp is not None: + pc = pc_sp if not plinth_fps or all(pc.distance(prev) > 0.25 for prev in plinth_fps): plinth_fps.append(pc) + plinth_fps.sort(key=lambda p: p.area, reverse=True) plinth_fp = plinth_fps[0] # Sample terrain height across the FINAL baked Plinth footprint polygons @@ -1292,7 +1304,7 @@ def build_cga_building( # Build real-footprint + pitched-roof watertight LOD2 solids lod2_solids: list[tuple[np.ndarray, int]] = [] lod2_body_h = max(1.0, eave_y - plinth_bot_y - 0.02) - l2_simp = 2.2 if micro_zone in (MICRO_FORTRESS, MICRO_CIVIC, MICRO_OLD_TOWN) else 3.6 + l2_simp = 2.2 if micro_zone in (MICRO_FORTRESS, MICRO_CIVIC, MICRO_OLD_TOWN) else 4.2 l2_wings = plinth_fps if micro_zone in (MICRO_FORTRESS, MICRO_CIVIC) else plinth_fps[:1] for pfp in l2_wings: l2_fp = pfp.simplify(l2_simp, preserve_topology=True) @@ -1375,7 +1387,7 @@ def build_cga_building( perim = float(plinth_fp.exterior.length) base_bay_len = 15.0 if hero_zone else (22.0 if (is_mauer or micro_zone == MICRO_RONQUOZ or perim > 70.0) else 20.0) - bay_chains = _partition_ring_into_wall_chains(plinth_fp, max_bays_per_tier, base_bay_len) + bay_chains = _partition_ring_into_wall_chains(plinth_fp, max_bays_per_tier, base_bay_len, subdivide_long=hero_zone) # 4a. InteriorCore zone (spans full height plinth_top_y .. eave_y - 0.15) minx, minz, maxx, maxz = plinth_fp.bounds @@ -1441,8 +1453,8 @@ def build_cga_building( blen = float(np.linalg.norm(sb - sa)) want_win = (not is_mauer) and ( (hero_zone and blen >= 5.2 and t_idx == 0 and (b_i == 0 or (micro_zone in (MICRO_FORTRESS, MICRO_CIVIC) and b_i == 2 and blen >= 6.5))) - or (micro_zone in (MICRO_VISSIGEN, MICRO_CLAVAU, MICRO_SUBURBAN) and blen >= 10.5 and b_i == 0 and t_idx == 0) - or (micro_zone == MICRO_RONQUOZ and blen >= 14.0 and b_i == 0 and t_idx == 0) + or (micro_zone in (MICRO_VISSIGEN, MICRO_CLAVAU, MICRO_SUBURBAN) and blen >= 16.0 and b_i == 0 and t_idx == 0) + or (micro_zone == MICRO_RONQUOZ and blen >= 22.0 and b_i == 0 and t_idx == 0) ) r_parts, c_parts, has_win = _build_wall_bay_geometry( sa, sb, blen, y0, bay_y_top, wall_thick, pal, micro_zone, @@ -1511,10 +1523,10 @@ def build_cga_building( else: r_sup = plinth_bit add_zone(ZONE_ROOF_SEGMENT, pal["roof_class"], ZONE_FLAG_EXTERIOR, r_sup, r_render, r_render) - # In LOD2, skip redundant flat top slab when building has flat roof unless hero_zone (pitched/spires always kept) + # In LOD2, skip redundant flat top slab when building has flat roof unless Fortress/Civic (pitched/spires always kept) if r_i < lod2_roof_cap and (hero_zone or len(r_rtd) > 0): r_l2 = r_col[2] - if not hero_zone and (float(np.max(r_l2[:, :, 1])) - float(np.min(r_l2[:, :, 1])) < 0.55): + if micro_zone not in (MICRO_FORTRESS, MICRO_CIVIC) and (float(np.max(r_l2[:, :, 1])) - float(np.min(r_l2[:, :, 1])) < 0.55): continue lod2_solids.append((r_l2, pal["roof"])) @@ -2283,6 +2295,7 @@ def verify_rcga_outputs(sion_dir) -> dict[str, int | float | str]: verified_buildings += 1 plinth_verts_xz: np.ndarray | None = None plinth_min_y = 0.0 + first_wb_y: float | None = None plinth_top_polys: list[Polygon] = [] wall_top_polys: list[Polygon] = [] wall_boxes_xz: list[tuple[float, float, float, float]] = [] @@ -2327,7 +2340,8 @@ def verify_rcga_outputs(sion_dir) -> dict[str, int | float | str]: if tp.is_valid and tp.area > 1e-4: plinth_top_polys.append(tp) elif z_kind == ZONE_WALL_BAY: - wb_h = float(c_pos[:, 1].max() - c_pos[:, 1].min()) + wb_min_y = float(c_pos[:, 1].min()) + wb_h = float(c_pos[:, 1].max() - wb_min_y) if wb_h < min_wallbay_height: min_wallbay_height = wb_h if wb_h < 0.35: @@ -2336,13 +2350,16 @@ def verify_rcga_outputs(sion_dir) -> dict[str, int | float | str]: float(c_pos[:, 0].min()), float(c_pos[:, 2].min()), float(c_pos[:, 0].max()), float(c_pos[:, 2].max()), )) - tri_p = c_pos[ci_arr.reshape(-1, 3)] - cr = np.cross(tri_p[:, 1] - tri_p[:, 0], tri_p[:, 2] - tri_p[:, 0]) - ny_u = cr[:, 1] / np.maximum(1e-9, np.linalg.norm(cr, axis=1)) - for t2 in tri_p[ny_u > 0.7][:, :, [0, 2]]: - tp = Polygon(t2) - if tp.is_valid and tp.area > 1e-4: - wall_top_polys.append(tp) + if first_wb_y is None: + first_wb_y = wb_min_y + if abs(wb_min_y - first_wb_y) < 0.50: + tri_p = c_pos[ci_arr.reshape(-1, 3)] + cr = np.cross(tri_p[:, 1] - tri_p[:, 0], tri_p[:, 2] - tri_p[:, 0]) + ny_u = cr[:, 1] / np.maximum(1e-9, np.linalg.norm(cr, axis=1)) + for t2 in tri_p[ny_u > 0.7][:, :, [0, 2]]: + tp = Polygon(t2) + if tp.is_valid and tp.area > 1e-4: + wall_top_polys.append(tp) elif z_kind == ZONE_FLOOR_SLAB and plinth_verts_xz is not None: p_x0, p_z0 = float(plinth_verts_xz[:, 0].min()), float(plinth_verts_xz[:, 1].min()) p_x1, p_z1 = float(plinth_verts_xz[:, 0].max()), float(plinth_verts_xz[:, 1].max())