feat: harden CAD showcase skill and delivery pipeline
This commit is contained in:
@@ -9,6 +9,8 @@ import math
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import showcase_schema
|
||||
|
||||
|
||||
CATEGORY_DRAW_ORDER = (
|
||||
"grid",
|
||||
@@ -43,7 +45,7 @@ def parse_args() -> argparse.Namespace:
|
||||
if "--" in argv:
|
||||
argv = argv[argv.index("--") + 1 :]
|
||||
else:
|
||||
argv = []
|
||||
argv = argv[1:]
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--spec", required=True, help="Path to building_spec.json")
|
||||
parser.add_argument("--out-dir", required=True, help="Output folder")
|
||||
@@ -210,7 +212,9 @@ def segment_prism(segment: dict, z0: float, z1: float):
|
||||
]
|
||||
|
||||
|
||||
def create_segment_mesh(bpy, name: str, segments: list[dict], z0: float, z1: float, material, floor_key: str, category: str):
|
||||
def create_segment_mesh(
|
||||
bpy, name: str, segments: list[dict], z0: float, z1: float, material, floor_key: str, category: str
|
||||
):
|
||||
verts = []
|
||||
faces = []
|
||||
for segment in segments:
|
||||
@@ -288,7 +292,9 @@ def extend_shared_wall_ends(segments: list[dict], tol: float = 1e-3) -> list[dic
|
||||
return out
|
||||
|
||||
|
||||
def create_merged_wall_mesh(bpy, name: str, segments: list[dict], z0: float, z1: float, material, floor_key: str, category: str):
|
||||
def create_merged_wall_mesh(
|
||||
bpy, name: str, segments: list[dict], z0: float, z1: float, material, floor_key: str, category: str
|
||||
):
|
||||
"""Union wall-segment rectangles into one continuous solid (config
|
||||
{"merge_wall_solids": true}) — removes corner seams and z-fighting at
|
||||
junctions. Blender-native: delaunay_2d_cdt (output_type=1) triangulates the
|
||||
@@ -339,7 +345,9 @@ def create_merged_wall_mesh(bpy, name: str, segments: list[dict], z0: float, z1:
|
||||
return obj
|
||||
|
||||
|
||||
def glazing_mullion_segments(bands: list[dict], z0: float, z1: float, panel_w: float = 1.5, profile: float = 0.06, depth: float = 0.10) -> list[dict]:
|
||||
def glazing_mullion_segments(
|
||||
bands: list[dict], z0: float, z1: float, panel_w: float = 1.5, profile: float = 0.06, depth: float = 0.10
|
||||
) -> list[dict]:
|
||||
"""Curtain-wall panel grid over glazing bands (mirror of spec_to_glb).
|
||||
|
||||
Emits pseudo wall segments (thin box profiles, rendered into the
|
||||
@@ -361,18 +369,28 @@ def glazing_mullion_segments(bands: list[dict], z0: float, z1: float, panel_w: f
|
||||
for i in range(panels + 1):
|
||||
t = i * step
|
||||
cx, cy = start[0] + ux * t, start[1] + uy * t
|
||||
out.append({
|
||||
"start": [cx - ux * profile / 2.0, cy - uy * profile / 2.0],
|
||||
"end": [cx + ux * profile / 2.0, cy + uy * profile / 2.0],
|
||||
"width": depth, "layer": segment.get("layer", ""), "source_type": "mullion",
|
||||
})
|
||||
out.append(
|
||||
{
|
||||
"start": [cx - ux * profile / 2.0, cy - uy * profile / 2.0],
|
||||
"end": [cx + ux * profile / 2.0, cy + uy * profile / 2.0],
|
||||
"width": depth,
|
||||
"layer": segment.get("layer", ""),
|
||||
"source_type": "mullion",
|
||||
}
|
||||
)
|
||||
thickness = 0.08
|
||||
for tz0, tz1 in ((z0, z0 + thickness), (z1 - thickness, z1)):
|
||||
out.append({
|
||||
"start": [float(start[0]), float(start[1])], "end": [float(end[0]), float(end[1])],
|
||||
"width": depth, "layer": segment.get("layer", ""), "source_type": "transom",
|
||||
"_z0": tz0, "_z1": tz1,
|
||||
})
|
||||
out.append(
|
||||
{
|
||||
"start": [float(start[0]), float(start[1])],
|
||||
"end": [float(end[0]), float(end[1])],
|
||||
"width": depth,
|
||||
"layer": segment.get("layer", ""),
|
||||
"source_type": "transom",
|
||||
"_z0": tz0,
|
||||
"_z1": tz1,
|
||||
}
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
@@ -536,12 +554,8 @@ def point_in_or_near_polygons(point: tuple[float, float], polygons: list[list[li
|
||||
return False
|
||||
|
||||
|
||||
def floor_group(floor_key: str) -> str:
|
||||
if floor_key.startswith("AUX_"):
|
||||
return "AUX"
|
||||
if floor_key in {"B1", "B1M"}:
|
||||
return "BASE"
|
||||
return "MAIN"
|
||||
def floor_group(floor_key: str, config: dict | None = None) -> str:
|
||||
return showcase_schema.floor_group(floor_key, config)
|
||||
|
||||
|
||||
def point_segment_distance(point: tuple[float, float], start: tuple[float, float], end: tuple[float, float]) -> float:
|
||||
@@ -564,10 +578,10 @@ def column_has_upper_support(point: tuple[float, float], floor_key: str, floor:
|
||||
structural_categories = set(config.get("column_support_categories", ["walls", "glazing", "columns", "beams"]))
|
||||
require_upper_plate = bool(config.get("column_support_requires_upper_plate", True))
|
||||
allow_plate_only = bool(config.get("column_support_allow_plate_only", False))
|
||||
group = floor_group(floor_key)
|
||||
group = floor_group(floor_key, config)
|
||||
|
||||
for other_key, other in spec.get("floors", {}).items():
|
||||
if floor_group(other_key) != group:
|
||||
if floor_group(other_key, config) != group:
|
||||
continue
|
||||
other_z = float(other.get("z", 0.0))
|
||||
if not (floor_top - 0.05 <= other_z <= floor_top + z_tolerance):
|
||||
@@ -587,7 +601,7 @@ def column_has_upper_support(point: tuple[float, float], floor_key: str, floor:
|
||||
|
||||
roof_z_tolerance = float(config.get("column_roof_support_z_tolerance", 0.65))
|
||||
for roof in generated_roof_bounds(spec):
|
||||
if floor_group(str(roof["floor_key"])) != group:
|
||||
if floor_group(str(roof["floor_key"]), config) != group:
|
||||
continue
|
||||
if abs(float(roof["z"]) - floor_top) > roof_z_tolerance:
|
||||
continue
|
||||
@@ -679,10 +693,15 @@ def add_floor(bpy, floor_key: str, floor: dict, materials: dict[str, object], sp
|
||||
if config.get("glazing_mullions", False) and floor_segments.get("glazing"):
|
||||
gz0, gz1 = z_window_for_category("glazing", z, height, floor_key, floor)
|
||||
mullion_segments = glazing_mullion_segments(
|
||||
floor_segments["glazing"], gz0, gz1, panel_w=float(config.get("glazing_panel_w", 1.5)),
|
||||
floor_segments["glazing"],
|
||||
gz0,
|
||||
gz1,
|
||||
panel_w=float(config.get("glazing_panel_w", 1.5)),
|
||||
)
|
||||
known = [category for category in CATEGORY_DRAW_ORDER if floor_segments.get(category)]
|
||||
extra = sorted(category for category in floor_segments if category not in CATEGORY_DRAW_ORDER and floor_segments.get(category))
|
||||
extra = sorted(
|
||||
category for category in floor_segments if category not in CATEGORY_DRAW_ORDER and floor_segments.get(category)
|
||||
)
|
||||
if mullion_segments and "walls" not in known:
|
||||
known.append("walls") # glazing-only floor still needs a walls object for the grid
|
||||
for category in known + extra:
|
||||
@@ -694,7 +713,14 @@ def add_floor(bpy, floor_key: str, floor: dict, materials: dict[str, object], sp
|
||||
z0, z1 = z_window_for_category(category, z, height, floor_key, floor)
|
||||
if category == "walls" and config.get("merge_wall_solids", False) and segments:
|
||||
merged = create_merged_wall_mesh(
|
||||
bpy, f"{floor_key}__walls", segments, z0, z1, materials[category], floor_key, category,
|
||||
bpy,
|
||||
f"{floor_key}__walls",
|
||||
segments,
|
||||
z0,
|
||||
z1,
|
||||
materials[category],
|
||||
floor_key,
|
||||
category,
|
||||
)
|
||||
if merged is not None:
|
||||
segments = [] # walls handled; mullions (if any) get their own pass below
|
||||
@@ -849,6 +875,8 @@ def setup_scene(bpy, spec: dict):
|
||||
def metadata(spec: dict, bounds: list[float], max_z: float, name: str) -> dict:
|
||||
config = spec.get("source", {}).get("config", {})
|
||||
return {
|
||||
"metadata_version": 1,
|
||||
"schema_version": spec.get("schema_version"),
|
||||
"project": spec.get("project", {"name": name}),
|
||||
"floors": [
|
||||
{"key": key, "name": floor.get("name", key), "z": floor.get("z", 0), "height": floor.get("height", 4.2)}
|
||||
@@ -868,12 +896,19 @@ def main() -> int:
|
||||
try:
|
||||
import bpy # type: ignore
|
||||
except ImportError as exc:
|
||||
raise SystemExit("Run this script with Blender: blender -b --python build_blender_showcase.py -- --spec ...") from exc
|
||||
raise SystemExit(
|
||||
"Run this script with Blender: blender -b --python build_blender_showcase.py -- --spec ..."
|
||||
) from exc
|
||||
|
||||
spec_path = Path(args.spec)
|
||||
out_dir = Path(args.out_dir)
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
spec = json.loads(spec_path.read_text(encoding="utf-8"))
|
||||
spec = showcase_schema.normalize_spec(json.loads(spec_path.read_text(encoding="utf-8")))
|
||||
try:
|
||||
showcase_schema.validate_spec(spec)
|
||||
except showcase_schema.ValidationFailure as exc:
|
||||
print(str(exc), file=sys.stderr)
|
||||
return 3
|
||||
clear_scene(bpy)
|
||||
bounds, max_z = setup_scene(bpy, spec)
|
||||
|
||||
@@ -896,14 +931,21 @@ def main() -> int:
|
||||
if args.render:
|
||||
bpy.context.scene.render.filepath = str(png_path)
|
||||
bpy.ops.render.render(write_still=True)
|
||||
metadata_path.write_text(json.dumps(metadata(spec, bounds, max_z, args.name), ensure_ascii=False, indent=2), encoding="utf-8")
|
||||
print(json.dumps({
|
||||
"blend": str(blend_path),
|
||||
"glb": str(glb_path),
|
||||
"png": str(png_path),
|
||||
"metadata": str(metadata_path),
|
||||
"objects": len(bpy.data.objects),
|
||||
}, ensure_ascii=False))
|
||||
metadata_path.write_text(
|
||||
json.dumps(metadata(spec, bounds, max_z, args.name), ensure_ascii=False, indent=2), encoding="utf-8"
|
||||
)
|
||||
print(
|
||||
json.dumps(
|
||||
{
|
||||
"blend": str(blend_path),
|
||||
"glb": str(glb_path),
|
||||
"png": str(png_path),
|
||||
"metadata": str(metadata_path),
|
||||
"objects": len(bpy.data.objects),
|
||||
},
|
||||
ensure_ascii=False,
|
||||
)
|
||||
)
|
||||
return 0
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user