124 lines
4.8 KiB
Python
124 lines
4.8 KiB
Python
#!/usr/bin/env python3
|
|
"""Honest massing spec from a site-plan outline x storey count x storey height.
|
|
|
|
For buildings named on the 总平面 but with NO delivered drawings (27号 3#/4#:
|
|
EVTR outlines + `22F`/`21F` labels), the honest showcase move is an outline
|
|
extrusion clearly labeled as such — never a silently faked detailed model.
|
|
The spec slots straight into assemble_campus (per-floor walls from the
|
|
outline edges, footprint slabs, top cap) and prints manifest-ready anchors.
|
|
|
|
Usage:
|
|
python3 massing_from_outline.py --outline outline.json --storeys 22 \
|
|
--height 3.0 --name dikuai27_b3 [--label "3#楼 22F住宅"] --out spec.json
|
|
|
|
outline JSON: [[x,y],...] site-plan meters (or {"points": [...]}). The spec is
|
|
localized to the outline's min corner; anchors printed as JSON on stdout:
|
|
model_anchor_m (local centroid) + survey_anchor_m (site centroid), rotation 0
|
|
(the outline is already site-true).
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import argparse
|
|
import json
|
|
from pathlib import Path
|
|
|
|
import showcase_schema
|
|
|
|
|
|
def main() -> int:
|
|
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
parser.add_argument("--outline", required=True, help="JSON [[x,y],...] site meters")
|
|
parser.add_argument("--storeys", type=int, required=True)
|
|
parser.add_argument("--height", type=float, default=3.0, help="storey height (m)")
|
|
parser.add_argument("--name", required=True, help="project_name for the spec")
|
|
parser.add_argument("--label", default="", help="human label for the description")
|
|
parser.add_argument("--wall-width", type=float, default=0.25)
|
|
parser.add_argument("--out", required=True)
|
|
args = parser.parse_args()
|
|
|
|
raw = json.loads(Path(args.outline).read_text(encoding="utf-8"))
|
|
pts = raw.get("points") if isinstance(raw, dict) else raw
|
|
outline = [(float(p[0]), float(p[1])) for p in pts]
|
|
if len(outline) < 3:
|
|
raise SystemExit("outline needs at least 3 points")
|
|
if args.storeys < 1:
|
|
raise SystemExit("storeys must be >= 1")
|
|
|
|
xs = [p[0] for p in outline]
|
|
ys = [p[1] for p in outline]
|
|
ox, oy = min(xs), min(ys)
|
|
poly = [[round(x - ox, 3), round(y - oy, 3)] for x, y in outline]
|
|
bounds = [0.0, 0.0, round(max(xs) - ox, 3), round(max(ys) - oy, 3)]
|
|
top_z = round(args.storeys * args.height, 3)
|
|
|
|
floors = {}
|
|
for i in range(1, args.storeys + 1):
|
|
walls = [
|
|
{"start": a, "end": b, "width": args.wall_width, "layer": "MASSING", "source_type": "site_outline"}
|
|
for a, b in zip(poly, poly[1:] + poly[:1])
|
|
]
|
|
floors[f"F{i}"] = {
|
|
"name": f"{i}层(总图轮廓体量)",
|
|
"z": round((i - 1) * args.height, 3),
|
|
"height": args.height,
|
|
"bounds": bounds,
|
|
"source_file": "site_outline",
|
|
"segments": {"walls": walls},
|
|
"footprint": {"source": "site_outline", "polygons": [poly]},
|
|
"caps": [{"z": top_z, "polygons": [poly]}] if i == args.storeys else [],
|
|
}
|
|
|
|
label = args.label or args.name
|
|
spec = {
|
|
"schema_version": showcase_schema.SCHEMA_VERSION,
|
|
"project": {
|
|
"name": args.name,
|
|
"description": (
|
|
f"{label}:无交付图纸,按总平面轮廓×{args.storeys}层×{args.height}m 出体量(诚实标注,非详图模型)"
|
|
),
|
|
},
|
|
"units": {"source": "meters", "scale_to_meters": 1.0, "origin_source": [ox, oy]},
|
|
"categories": {
|
|
"walls": {"label": "墙体(体量)", "color": "#d4cbb8", "width": args.wall_width},
|
|
"slab": {"label": "楼板", "color": "#c8ccc2", "width": 0.0},
|
|
},
|
|
"source": {
|
|
"config": {
|
|
"config_version": showcase_schema.CONFIG_VERSION,
|
|
"use_footprint_slabs": True,
|
|
"generate_caps": True,
|
|
"roof_specs": [],
|
|
"project_name": args.name,
|
|
}
|
|
},
|
|
"floors": floors,
|
|
}
|
|
try:
|
|
showcase_schema.validate_spec(spec)
|
|
except showcase_schema.ValidationFailure as exc:
|
|
raise SystemExit(str(exc)) from exc
|
|
out = Path(args.out)
|
|
out.parent.mkdir(parents=True, exist_ok=True)
|
|
out.write_text(json.dumps(spec, ensure_ascii=False), encoding="utf-8")
|
|
|
|
ctr = [round(sum(p[0] for p in poly) / len(poly), 3), round(sum(p[1] for p in poly) / len(poly), 3)]
|
|
print(
|
|
json.dumps(
|
|
{
|
|
"out": str(out),
|
|
"floors": args.storeys,
|
|
"top_z": top_z,
|
|
"model_anchor_m": ctr,
|
|
"survey_anchor_m": [round(ctr[0] + ox, 3), round(ctr[1] + oy, 3)],
|
|
"rotation_deg": 0.0,
|
|
},
|
|
ensure_ascii=False,
|
|
)
|
|
)
|
|
return 0
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|