Deduplicate collision vertices by position and trim non-hero bay clutter under 16 MiB
This commit is contained in:
parent
53e88ac2d7
commit
6294af87ca
1 changed files with 34 additions and 19 deletions
|
|
@ -1008,7 +1008,7 @@ 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.32 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN) else 0.70
|
||||
simplify_tol = 0.40 if micro_zone in (MICRO_FORTRESS, MICRO_OLD_TOWN) else 0.95
|
||||
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())
|
||||
|
|
@ -1101,7 +1101,7 @@ def build_cga_building(
|
|||
return Polygon(ext, holes)
|
||||
|
||||
# 1. Zone 0: Plinth / Foundation (IsGroundAnchored = true)
|
||||
plinth_fp = primary_fp.simplify(0.85, preserve_topology=True)
|
||||
plinth_fp = primary_fp.simplify(1.05, preserve_topology=True)
|
||||
plinth_fp = _clean_polygon_2d(plinth_fp if isinstance(plinth_fp, Polygon) else primary_fp, min_area=0.8) or primary_fp
|
||||
plinth_uv = fp_to_uv(plinth_fp)
|
||||
plinth_parts = extrude_2d_poly_prism(
|
||||
|
|
@ -1122,11 +1122,10 @@ def build_cga_building(
|
|||
is_mauer = (objektart == "Mauer gross")
|
||||
|
||||
# Build lean watertight LOD2 silhouette (single simplified prism) for 620..2200m GLB
|
||||
lod2_tol = 1.1 if primary_fp.area > 35.0 else 1.8
|
||||
lod2_fp = primary_fp.simplify(lod2_tol, preserve_topology=True)
|
||||
lod2_fp = primary_fp.simplify(1.25, preserve_topology=True)
|
||||
lod2_fp = _clean_polygon_2d(lod2_fp if isinstance(lod2_fp, Polygon) else primary_fp, min_area=0.5) or primary_fp
|
||||
if len(lod2_fp.exterior.coords) > 9:
|
||||
lod2_fp = box(*lod2_fp.bounds)
|
||||
if len(lod2_fp.exterior.coords) > 6:
|
||||
lod2_fp = lod2_fp.minimum_rotated_rectangle
|
||||
lod2_uv = Polygon([(x, -z) for x, z in lod2_fp.exterior.coords])
|
||||
lod2_h = max(1.2, max(eave_y, raw_max_y) - plinth_bot_y)
|
||||
lod2_t, lod2_m, _, _ = extrude_2d_poly_prism(
|
||||
|
|
@ -1191,14 +1190,14 @@ def build_cga_building(
|
|||
|
||||
# Cap structural tiers cleanly so total city RCGA + LOD2 fits well <= 16 MiB
|
||||
avail_for_stories = MAX_ZONES_PER_BUILDING - (2 + n_roofs)
|
||||
max_tiers = 4 if n_stories >= 7 else (3 if micro_zone in (MICRO_OLD_TOWN, MICRO_FORTRESS) else 2)
|
||||
n_tiers = min(n_stories, max_tiers, max(1, avail_for_stories // max(4, min(raw_bays_len + 1, 8))))
|
||||
max_tiers = 4 if n_stories >= 8 else (3 if micro_zone in (MICRO_OLD_TOWN, MICRO_FORTRESS) and n_stories >= 3 else 2)
|
||||
n_tiers = min(n_stories, max_tiers, max(1, avail_for_stories // max(4, min(raw_bays_len + 1, 7))))
|
||||
n_tiers = max(1, n_tiers)
|
||||
|
||||
max_bays_per_tier = max(3, min(8, (avail_for_stories // n_tiers) - 1))
|
||||
max_bays_per_tier = max(3, min(7, (avail_for_stories // n_tiers) - 1))
|
||||
|
||||
perim = float(primary_fp.exterior.length)
|
||||
base_bay_len = 11.0 if micro_zone in (MICRO_OLD_TOWN, MICRO_FORTRESS) else (16.0 if (is_mauer or micro_zone == MICRO_RONQUOZ or perim > 70.0) else 14.0)
|
||||
base_bay_len = 12.0 if micro_zone in (MICRO_OLD_TOWN, MICRO_FORTRESS) else (18.0 if (is_mauer or micro_zone == MICRO_RONQUOZ or perim > 70.0) else 16.0)
|
||||
bays_2d: list[tuple[np.ndarray, np.ndarray, float]] = []
|
||||
for mult in (1.0, 1.4, 2.0, 3.0, 5.0, 10.0):
|
||||
cand = _split_ring_into_wall_bays(ext_pts, base_bay_len * mult)
|
||||
|
|
@ -1236,9 +1235,11 @@ def build_cga_building(
|
|||
slab_fp = primary_fp.buffer(-slab_inset, join_style="mitre")
|
||||
if not isinstance(slab_fp, Polygon) or slab_fp.is_empty or slab_fp.area < 0.8:
|
||||
slab_fp = primary_fp
|
||||
slab_fp_s = slab_fp.simplify(0.95, preserve_topology=True)
|
||||
slab_fp_s = slab_fp.simplify(1.15, preserve_topology=True)
|
||||
if isinstance(slab_fp_s, Polygon) and not slab_fp_s.is_empty and slab_fp_s.area >= 0.8:
|
||||
slab_fp = slab_fp_s
|
||||
if len(slab_fp.exterior.coords) > 7 and not slab_fp.interiors:
|
||||
slab_fp = slab_fp.minimum_rotated_rectangle
|
||||
slab_uv = fp_to_uv(slab_fp)
|
||||
slab_thick = 0.28
|
||||
|
||||
|
|
@ -1262,7 +1263,10 @@ def build_cga_building(
|
|||
if len(zones) >= MAX_ZONES_PER_BUILDING - n_roofs - 1:
|
||||
break
|
||||
want_win = (not is_mauer) and (
|
||||
(hero_zone and blen >= 3.0) or (blen >= 4.0 and (b_i % 2 == 0) and t_idx == 0)
|
||||
(hero_zone and blen >= 3.2 and (b_i % 2 == 0 or t_idx == 0))
|
||||
or (micro_zone == MICRO_VISSIGEN and blen >= 4.2 and (b_i % 2 == 0))
|
||||
or (micro_zone in (MICRO_CLAVAU, MICRO_SUBURBAN) and blen >= 4.5 and b_i == 0 and t_idx == 0)
|
||||
or (micro_zone == MICRO_RONQUOZ and blen >= 6.5 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,
|
||||
|
|
@ -1395,6 +1399,7 @@ def _pack_zone_mesh_16b(
|
|||
zone_index: int,
|
||||
bldg_slot: int,
|
||||
allow_fallback: bool = True,
|
||||
position_only: bool = False,
|
||||
) -> tuple[bytes, bytes, int, int]:
|
||||
"""
|
||||
Pack triangle soup -> 16 B/vert vertex buffer + uint16 index buffer:
|
||||
|
|
@ -1434,13 +1439,22 @@ def _pack_zone_mesh_16b(
|
|||
|
||||
T = len(tris)
|
||||
flat_qpos = qpos_all.reshape(-1, 3) # (3T, 3) int16
|
||||
flat_qnorm = np.repeat(qnorm_face, 3, axis=0) # (3T, 2) int8
|
||||
flat_uv = np.clip(np.round(uvs.reshape(-1, 2) * UV_QUANT_SCALE), 0, 65535).astype(np.uint16)
|
||||
flat_col = np.empty((T * 3, 4), dtype=np.uint8)
|
||||
flat_col[:, 0] = zone_index & 0xFF
|
||||
flat_col[:, 1] = np.repeat(mats, 3)
|
||||
flat_col[:, 2] = ao.reshape(-1)
|
||||
flat_col[:, 3] = bldg_slot & 0xFF
|
||||
if position_only:
|
||||
flat_qnorm = np.zeros((T * 3, 2), dtype=np.int8)
|
||||
flat_uv = np.zeros((T * 3, 2), dtype=np.uint16)
|
||||
flat_col = np.empty((T * 3, 4), dtype=np.uint8)
|
||||
flat_col[:, 0] = zone_index & 0xFF
|
||||
flat_col[:, 1] = int(mats[0])
|
||||
flat_col[:, 2] = 220
|
||||
flat_col[:, 3] = bldg_slot & 0xFF
|
||||
else:
|
||||
flat_qnorm = np.repeat(qnorm_face, 3, axis=0) # (3T, 2) int8
|
||||
flat_uv = np.clip(np.round(uvs.reshape(-1, 2) * UV_QUANT_SCALE), 0, 65535).astype(np.uint16)
|
||||
flat_col = np.empty((T * 3, 4), dtype=np.uint8)
|
||||
flat_col[:, 0] = zone_index & 0xFF
|
||||
flat_col[:, 1] = np.repeat(mats, 3)
|
||||
flat_col[:, 2] = ao.reshape(-1)
|
||||
flat_col[:, 3] = bldg_slot & 0xFF
|
||||
|
||||
# Pack into 16B structured record array for instant deduplication
|
||||
vert_dtype = np.dtype([
|
||||
|
|
@ -1608,6 +1622,7 @@ def export_rcga_tile(tx: int, tz: int, buildings: list[CgaBuildingResult], out_p
|
|||
cv_bytes, ci_bytes, cv_cnt, ci_cnt = _pack_zone_mesh_16b(
|
||||
z.col_tris, z.col_mats, c_ao, c_uv,
|
||||
pos_origin, pos_scale, z.zone_index, b.local_slot,
|
||||
position_only=True,
|
||||
)
|
||||
zone_hdrs.extend(struct.pack("<4I", rv_cnt, ri_cnt, cv_cnt, ci_cnt))
|
||||
geo_blob.extend(rv_bytes)
|
||||
|
|
|
|||
Loading…
Reference in a new issue