feat: harden CAD showcase skill and delivery pipeline

This commit is contained in:
2026-07-10 09:21:13 +08:00
parent a6856f903d
commit 8b1b1d5e89
53 changed files with 5405 additions and 1327 deletions

View File

@@ -25,16 +25,31 @@ import json
import math
from pathlib import Path
ROAD_LAYERS = {"Z5-车行道": 0.30, "Z5-道路中心线": 0.10, "Z6-其他符号": 0.12,
"Z2-绿化控制线": 0.08, "Z2-建筑退界线": 0.08, "竖向": 0.08}
ROAD_LAYERS = {
"Z5-车行道": 0.30,
"Z5-道路中心线": 0.10,
"Z6-其他符号": 0.12,
"Z2-绿化控制线": 0.08,
"Z2-建筑退界线": 0.08,
"竖向": 0.08,
}
PARKING_LAYERS = {"Z3-车位": 0.08}
FENCE_LAYERS = {"Z3-围墙": 0.15}
BOUNDARY_LAYERS = ["Z2-用地红线"]
TREE_LAYERS = ["Z4-树层(行道树)", "*树*"]
MASSING_LAYERS = ["平面", "屋面", "面积核算", "*建筑轮廓*"]
MASSING_HEIGHTS = [("2#", 24.0), ("3#", 8.5), ("辅房", 8.5), ("门卫", 3.5),
("停车", 4.0), ("污水", 2.0), ("水池", 2.0), ("消控", 3.5),
("连廊", 4.5), ("钢楼梯", 6.5)]
MASSING_HEIGHTS = [
("2#", 24.0),
("3#", 8.5),
("辅房", 8.5),
("门卫", 3.5),
("停车", 4.0),
("污水", 2.0),
("水池", 2.0),
("消控", 3.5),
("连廊", 4.5),
("钢楼梯", 6.5),
]
MASSING_SKIP = ("出入口",) # gate openings marked as small rects; not volumes
LABEL_SKIP = __import__("re").compile(r"^[XxYy]=|^[-+]?\d+([.,]\d+)?$")
DEFAULT_MASSING_H = 6.0
@@ -43,14 +58,35 @@ DEFAULT_MASSING_H = 6.0
def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser(description=__doc__)
p.add_argument("--dump", action="append", required=True, help="dump JSON path (repeatable)")
p.add_argument("--scale", action="append", required=True, type=float,
help="units->meters factor for the matching --dump (1.0 for m, 0.001 for mm)")
p.add_argument("--region", nargs=4, type=float, required=True, metavar=("X0", "Y0", "X1", "Y1"),
help="surveying-meter window selecting ONE plan copy")
p.add_argument("--origin", nargs=2, type=float, required=True,
help="campus local origin in surveying meters (e.g. 红线 min corner)")
p.add_argument("--exclude-quad", nargs=8, type=float, default=None,
help="4 corners (m) of the real-model building; site geometry inside is dropped")
p.add_argument(
"--scale",
action="append",
required=True,
type=float,
help="units->meters factor for the matching --dump (1.0 for m, 0.001 for mm)",
)
p.add_argument(
"--region",
nargs=4,
type=float,
required=True,
metavar=("X0", "Y0", "X1", "Y1"),
help="surveying-meter window selecting ONE plan copy",
)
p.add_argument(
"--origin",
nargs=2,
type=float,
required=True,
help="campus local origin in surveying meters (e.g. 红线 min corner)",
)
p.add_argument(
"--exclude-quad",
nargs=8,
type=float,
default=None,
help="4 corners (m) of the real-model building; site geometry inside is dropped",
)
p.add_argument("--out", required=True)
return p.parse_args()
@@ -59,8 +95,10 @@ def flatten_arc(c, r, sa, ea, scale):
if ea < sa:
ea += math.tau
steps = max(8, min(48, int(abs(ea - sa) * r * scale / 1.5) + 8))
return [(c[0] + math.cos(sa + (ea - sa) * i / steps) * r,
c[1] + math.sin(sa + (ea - sa) * i / steps) * r) for i in range(steps + 1)]
return [
(c[0] + math.cos(sa + (ea - sa) * i / steps) * r, c[1] + math.sin(sa + (ea - sa) * i / steps) * r)
for i in range(steps + 1)
]
def in_quad(pt, quad):
@@ -82,6 +120,7 @@ def in_quad(pt, quad):
def match(layer: str, patterns) -> bool:
import fnmatch
return any(fnmatch.fnmatch(layer, p) for p in patterns)
@@ -109,7 +148,8 @@ def main() -> int:
if math.hypot(b[0] - a[0], b[1] - a[1]) < 0.15:
return
segs[floor].setdefault(cat, []).append(
{"start": local(a), "end": local(b), "width": width, "layer": layer, "source_type": "SITE"})
{"start": local(a), "end": local(b), "width": width, "layer": layer, "source_type": "SITE"}
)
for dump_path, scale in zip(args.dump, args.scale):
d = json.loads(Path(dump_path).read_text(encoding="utf-8"))
@@ -127,6 +167,7 @@ def main() -> int:
def tf(pt):
tx, ty = pt[0] * sx, pt[1] * sy
return (px + tx * cr - ty * srr, py + tx * srr + ty * cr)
for be in blocks.get(name, []):
if be["t"] == "LINE":
yield "seg", (tf(be["a"]), tf(be["b"]))
@@ -199,39 +240,80 @@ def main() -> int:
xs = [p[0] for p in mpts]
ys = [p[1] for p in mpts]
w, h = max(xs) - min(xs), max(ys) - min(ys)
if (len(mpts) >= 4 and w >= 3.0 and h >= 3.0 and
max(w, h) / max(min(w, h), 0.1) <= 8.0 and not in_quad((mx, my), quad)):
if (
len(mpts) >= 4
and w >= 3.0
and h >= 3.0
and max(w, h) / max(min(w, h), 0.1) <= 8.0
and not in_quad((mx, my), quad)
):
massings.append({"pts": [local(p) for p in mpts], "c": (mx, my), "w": w, "h": h})
floors = {}
if boundary_polys:
biggest = max(boundary_polys, key=lambda poly: (max(p[0] for p in poly) - min(p[0] for p in poly)) *
(max(p[1] for p in poly) - min(p[1] for p in poly)))
floors["SITE"] = {"name": "场地地面", "z": -0.45, "height": 0.45,
"bounds": [0, 0, x1 - x0, y1 - y0], "source_file": "site",
"segments": {}, "footprint": {"source": "用地红线", "polygons": [biggest]}}
floors["ROADS"] = {"name": "道路/车位", "z": 0.02, "height": 0.05,
"bounds": [0, 0, x1 - x0, y1 - y0], "source_file": "site",
"segments": segs["ROADS"]}
biggest = max(
boundary_polys,
key=lambda poly: (max(p[0] for p in poly) - min(p[0] for p in poly))
* (max(p[1] for p in poly) - min(p[1] for p in poly)),
)
floors["SITE"] = {
"name": "场地地面",
"z": -0.45,
"height": 0.45,
"bounds": [0, 0, x1 - x0, y1 - y0],
"source_file": "site",
"segments": {},
"footprint": {"source": "用地红线", "polygons": [biggest]},
}
floors["ROADS"] = {
"name": "道路/车位",
"z": 0.02,
"height": 0.05,
"bounds": [0, 0, x1 - x0, y1 - y0],
"source_file": "site",
"segments": segs["ROADS"],
}
if segs["FENCE"]:
floors["FENCE"] = {"name": "围墙", "z": 0.0, "height": 1.8,
"bounds": [0, 0, x1 - x0, y1 - y0], "source_file": "site",
"segments": segs["FENCE"]}
floors["FENCE"] = {
"name": "围墙",
"z": 0.0,
"height": 1.8,
"bounds": [0, 0, x1 - x0, y1 - y0],
"source_file": "site",
"segments": segs["FENCE"],
}
if trees:
tree_segs = []
for p in trees:
lp = local(p)
tree_segs.append({"start": [lp[0] - 0.3, lp[1]], "end": [lp[0] + 0.3, lp[1]],
"width": 2.4, "layer": "行道树", "source_type": "TREE"})
floors["TREES"] = {"name": "行道树", "z": 0.0, "height": 3.5,
"bounds": [0, 0, x1 - x0, y1 - y0], "source_file": "site",
"segments": {"trees": tree_segs}}
tree_segs.append(
{
"start": [lp[0] - 0.3, lp[1]],
"end": [lp[0] + 0.3, lp[1]],
"width": 2.4,
"layer": "行道树",
"source_type": "TREE",
}
)
floors["TREES"] = {
"name": "行道树",
"z": 0.0,
"height": 3.5,
"bounds": [0, 0, x1 - x0, y1 - y0],
"source_file": "site",
"segments": {"trees": tree_segs},
}
# de-duplicate massings (copies drawn twice) and name them by nearest label
kept = []
for m in sorted(massings, key=lambda m: -(m["w"] * m["h"])):
if any(abs(m["c"][0] - k["c"][0]) < 2 and abs(m["c"][1] - k["c"][1]) < 2 and
abs(m["w"] - k["w"]) < 2 and abs(m["h"] - k["h"]) < 2 for k in kept):
if any(
abs(m["c"][0] - k["c"][0]) < 2
and abs(m["c"][1] - k["c"][1]) < 2
and abs(m["w"] - k["w"]) < 2
and abs(m["h"] - k["h"]) < 2
for k in kept
):
continue
kept.append(m)
for idx, m in enumerate(kept, start=1):
@@ -245,22 +327,37 @@ def main() -> int:
if any(key in name for key in MASSING_SKIP):
continue
height = next((hh for key, hh in MASSING_HEIGHTS if key in name), DEFAULT_MASSING_H)
wsegs = [{"start": a, "end": b, "width": 0.25, "layer": "massing", "source_type": "SITE"}
for a, b in zip(m["pts"], m["pts"][1:])]
wsegs = [
{"start": a, "end": b, "width": 0.25, "layer": "massing", "source_type": "SITE"}
for a, b in zip(m["pts"], m["pts"][1:])
]
if m["pts"][0] != m["pts"][-1]:
wsegs.append({"start": m["pts"][-1], "end": m["pts"][0], "width": 0.25,
"layer": "massing", "source_type": "SITE"})
floors[f"CTX{idx}"] = {"name": f"体量-{name}", "z": 0.0, "height": height,
"bounds": [0, 0, x1 - x0, y1 - y0], "source_file": "site",
"segments": {"walls": wsegs},
"footprint": {"source": "site_outline", "polygons": [m["pts"]]}}
wsegs.append(
{"start": m["pts"][-1], "end": m["pts"][0], "width": 0.25, "layer": "massing", "source_type": "SITE"}
)
floors[f"CTX{idx}"] = {
"name": f"体量-{name}",
"z": 0.0,
"height": height,
"bounds": [0, 0, x1 - x0, y1 - y0],
"source_file": "site",
"segments": {"walls": wsegs},
"footprint": {"source": "site_outline", "polygons": [m["pts"]]},
}
out = {"floors": floors,
"categories": {"trees": {"label": "行道树", "color": "#3e7d4f"}}}
out = {"floors": floors, "categories": {"trees": {"label": "行道树", "color": "#3e7d4f"}}}
Path(args.out).write_text(json.dumps(out, ensure_ascii=False, indent=1), encoding="utf-8")
print(json.dumps({"out": args.out,
"floors": {k: {c: len(s) for c, s in v.get("segments", {}).items()} for k, v in floors.items()},
"trees": len(trees), "massings": len(kept)}, ensure_ascii=False))
print(
json.dumps(
{
"out": args.out,
"floors": {k: {c: len(s) for c, s in v.get("segments", {}).items()} for k, v in floors.items()},
"trees": len(trees),
"massings": len(kept),
},
ensure_ascii=False,
)
)
return 0