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

@@ -40,6 +40,8 @@ import math
import sys
from pathlib import Path
import showcase_schema
def parse_args() -> argparse.Namespace:
p = argparse.ArgumentParser(description=__doc__)
@@ -48,8 +50,12 @@ def parse_args() -> argparse.Namespace:
p.add_argument("--out", required=True)
p.add_argument("--project-name", default=None)
p.add_argument("--description", default=None)
p.add_argument("--gap-warn", type=float, default=0.10,
help="warn when two buildings' wall envelopes are closer than this (m); overlap always fails")
p.add_argument(
"--gap-warn",
type=float,
default=0.10,
help="warn when two buildings' wall envelopes are closer than this (m); overlap always fails",
)
p.add_argument("--allow-overlap", action="store_true", help="downgrade overlap FAIL to warning")
return p.parse_args()
@@ -61,6 +67,7 @@ def make_xf(anchor, survey_m, origin_m, cos_t, sin_t):
def xf(p):
dx, dy = p[0] - ax, p[1] - ay
return [round(dx * cos_t - dy * sin_t + tx, 6), round(dx * sin_t + dy * cos_t + ty, 6)]
return xf
@@ -142,9 +149,15 @@ def main() -> int:
envelopes: dict[str, tuple] = {}
for name, b in manifest.get("buildings", {}).items():
if not isinstance(b, dict) or "spec" not in b:
print(f"skip {name}: no spec (status: {b.get('status', '?') if isinstance(b, dict) else b})", file=sys.stderr)
print(
f"skip {name}: no spec (status: {b.get('status', '?') if isinstance(b, dict) else b})", file=sys.stderr
)
continue
spec = json.loads(Path(b["spec"]).read_text(encoding="utf-8"))
spec = showcase_schema.normalize_spec(json.loads(Path(b["spec"]).read_text(encoding="utf-8")))
try:
showcase_schema.validate_spec(spec)
except showcase_schema.ValidationFailure as exc:
raise SystemExit(f"{name}: {exc}") from exc
if base_spec is None:
base_spec = spec
anchor = b.get("model_anchor_m") or b.get("model_anchor_center_m") or b.get("model_anchor_SE_wall_corner_m")
@@ -164,8 +177,11 @@ def main() -> int:
envelopes[name] = env
# re-key this building's roof_specs into the campus config later
b["_roof_specs"] = [
{**r, "floor_key": prefix + str(r.get("floor_key")),
"footprint_from": [prefix + str(k) for k in r.get("footprint_from", [r.get("floor_key")])]}
{
**r,
"floor_key": prefix + str(r.get("floor_key")),
"footprint_from": [prefix + str(k) for k in r.get("footprint_from", [r.get("floor_key")])],
}
for r in spec.get("source", {}).get("config", {}).get("roof_specs", [])
]
@@ -212,20 +228,31 @@ def main() -> int:
floors.update(placed)
campus = base_spec
campus["schema_version"] = showcase_schema.SCHEMA_VERSION
campus["floors"] = floors
campus["project"] = {
"name": args.project_name or manifest.get("project_name", "厂区"),
"description": args.description or manifest.get("description", "多栋建筑 + 场地(assemble_campus.py 合成)"),
}
cfg = campus.setdefault("source", {}).setdefault("config", {})
cfg["roof_specs"] = [r for b in manifest.get("buildings", {}).values()
if isinstance(b, dict) for r in b.get("_roof_specs", [])]
cfg["config_version"] = showcase_schema.CONFIG_VERSION
cfg["roof_specs"] = [
r for b in manifest.get("buildings", {}).values() if isinstance(b, dict) for r in b.get("_roof_specs", [])
]
cfg["floor_order"] = site_keys + [k for k in placed]
out = Path(args.out)
try:
showcase_schema.validate_spec(campus)
except showcase_schema.ValidationFailure as exc:
raise SystemExit(str(exc)) from exc
out.parent.mkdir(parents=True, exist_ok=True)
out.write_text(json.dumps(campus, ensure_ascii=False, indent=1), encoding="utf-8")
print(json.dumps({"out": str(out), "floors": len(floors), "buildings": len(envelopes),
"site_floors": len(site_keys)}, ensure_ascii=False))
print(
json.dumps(
{"out": str(out), "floors": len(floors), "buildings": len(envelopes), "site_floors": len(site_keys)},
ensure_ascii=False,
)
)
return 0