feat(nodes): roof accessories — gutters, downspouts & vents + gizmos (#355)
* Add roof surface placement support for items Items (e.g. solar panels) can now be placed on sloped roof surfaces. The placement system computes euler rotation from the roof surface normal so items sit flush on the slope instead of going inside. - Add roofStrategy to placement-strategies with enter/move/click/leave - Wire roof:enter/move/click/leave events in the placement coordinator - Add calculateRoofRotation in placement-math using surface normals - Support full 3D cursor rotation for sloped surfaces - Items on roofs are parented to the level with world-space rotation Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fixed conflict * fix(editor): ceiling-attached item placement from 2D floor plan The 3D viewer drives ceiling-item placement via ceiling:enter/move/click raycast events on the ceiling mesh. The floor plan has no such mesh, so ceiling-attached items (lights, fans) never transitioned out of surface: 'floor' — the draft sat at floor height while the 2D cursor moved freely, reading as a 2D/3D sync bug. Synthesise the same ceiling events from 2D plan points by hit-testing ceiling polygons on the active level, and publish the building-local cursor (not world-space) to useLiveTransforms so the floorplan registry override renders the draft under the cursor regardless of building position / rotation. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): chevron arrows render on SCENE_LAYER so ink-edge shader outlines them Node arrow handles and polygon-editor edge arrows were tagged for EDITOR_LAYER, which hides them from the post-processing scenePass — the ink-edge shader reads the depth/normal MRT from that pass, so the chevrons rendered flat with no outlined edges. Drop the EDITOR_LAYER tagging on both, matching the wall-height arrow which already stays on SCENE_LAYER for the same reason. Pair with depthWrite: true on the chevron materials so their silhouettes enter the depth buffer; depthTest stays off to keep the chevron drawn on top of underlying geometry. Without depthWrite, only the normal-discontinuity branch of the ink shader can detect the chevron, and the lines drop out when faces align with whatever sits behind them in screen space. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): ceiling grid overlay no longer blocks selecting items under it Two issues kept the ceiling grid overlay covering the room after the user moved on from a ceiling-related action: 1. CeilingSystem treated any selected descendant of a ceiling as "reveal the grid" — so after placing a ceiling light and the new item became selected, the grid stayed on and its mesh intercepted every subsequent 3D click, re-selecting the ceiling instead of the items below. Restrict the reveal to directly-selected ceilings. 2. The ceiling top material used the opaque surface-role material, so a top-down camera lost view of everything under the ceiling the moment the overlay turned on. Swap the top material for the transparent grid-pattern material (bottom stays opaque so the in-room view still reads as a solid surface). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(core): curve- and thickness-aware wall/slab overlap detection `wallOverlapsPolygon` and `getSlabElevationForWall` previously treated a wall as an infinitely thin chord from start to end. Two failure modes fell out of that: 1. Curved walls whose chord lies outside the slab but whose centerline bows into the slab interior were missed entirely. The wall stayed at Y=0 while the slab elevation moved, and `markNodesOverlappingSlab` never re-dirtied it when the slab Y changed. 2. Perimeter walls of a room — whose centerline sits exactly on (or just outside) the slab's polygon edge — also missed detection, because pointInPolygon on the boundary is unreliable. Half the wall's body is inside the slab; it should follow the slab elevation. Switch `wallOverlapsPolygon` to a wall-shaped input (start/end + optional curveOffset + thickness), sample the centerline for curved walls, and add a ±halfThickness perpendicular test for straight walls. Threaded through `getSlabElevationForWall`, the wall system, and the `markNodesOverlappingSlab` pass. Legacy chord-only call shape preserved for callers that don't yet have a wall in hand. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(editor): show Move button for legacy-movable kinds in floating action menu `isRegistryMovable` only sees kinds wired through `capabilities.movable`, `floorplanMoveTarget`, or `affordanceTools.move`. The legacy tail of `MoveTool` (tools/item/move-tool.tsx) still handles roof, roof-segment, stair, stair-segment, building, and elevator, but the floating action menu was hiding the Move button for them because the registry check returned false. The mover worked once invoked — the entry point was missing. Add a `LEGACY_MOVABLE_KINDS` set alongside the registry check so those kinds get the Move button until they migrate onto kind-owned affordances; drop a kind from the set once it does. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(nodes): in-world registry handles for roof accessories + axis-stable surface basis Adds the registry-driven chevron / tracker / rotate-gizmo handle set to skylight, solar-panel, chimney, and roof-segment so every roof-mounted kind has consistent in-world manipulation, and fixes the underlying renderer + surface-basis bugs that made those handles land on the wrong spot or behave inconsistently across mirrored slopes. Handles - `LinearResizeHandle` gains `shape: 'arrow' | 'tracker'`. `'tracker'` renders a dashed vertical leader from the surface up to a draggable cube, reusing the linear-resize drag pipeline. Roof-segment's wall-height handle adopts it. - Roof-segment: width chevrons split into two asymmetric handles (each grows its own edge, opposite stays world-fixed via `apply` recomputing `position`). - Skylight: width × 2 (asymmetric), height × 2 (asymmetric), curb-height tracker, rotate gizmo (corner, lifted off surface), and a diagonal frame-thickness chevron at the -X+Z corner. - Solar panel: same six handles operating on total array dimensions (back-solving `panelWidth` / `panelHeight` from `columns` / `rows`), plus a frame-depth chevron above the array. - Chimney: registry handle set following the same idioms. Skylight / solar-panel renderer - Collapse the previously nested `position → surfaceQuat → rotation-y → rotation-x` groups into a single registered transform group whose local `position` + composed `quaternion` carry the full pose in segment frame. The registry handles read this Object3D's local matrix (via `portal: 'grandparent'`), and a split tree exposed only the bottom group's local pose so handles landed at the segment origin on the roof floor. Surface basis (solar-panel/geometry.ts) - `surfaceQuatFromNormal` builds `right` by projecting world +X onto the surface plane instead of `up × normal`. The cross-product version flipped sign when the normal's Z component flipped (e.g. the two slopes of a gable roof), so hosted children's local +X pointed in opposite world directions across the ridge and asymmetric chevrons anchored the wrong edge. Projecting +X keeps the basis stable across mirror-image slopes. Skylight move-tool ghost - Switch from the raycast normal (`event.normal × normalMatrix`) to the analytical normal (`getAnalyticalNormal`) on every pointer move, and mirror the placement tool's transform stack: `position → yaw (roof + segment) → surfaceQuat → skylight rotation → preview`. Re-engaging Move from the floating action menu now shows the same correctly oriented ghost the first-placement tool does. * feat(nodes): split roof-segment depth chevron into asymmetric front/back arrows Brings the depth handle in line with the width handles: one chevron on each Z edge, each anchored to the opposite edge so dragging only moves its own side. `apply` recomputes `position` along the segment's local +Z arm (yaw-aware) so the anchored edge stays world-fixed. Depth also feeds the slope-frame math via `getActiveRoofHeight`, so a naïve depth change would also raise/lower the peak (constant pitch across a larger run). We hold the peak fixed by back-solving a new `pitch` for the new depth via `getPitchFromActiveRoofHeight`, clamped to the schema's pitch range — the segment grows along the deck plane without ramping up. * feat(nodes): in-world handles for dormer + window-bottom clipping check Dormer joins chimney / roof-segment with chevron handles on the selected node. Five body handles (width L/R, depth, wall-height tracker, rotate) plus four window-opening handles (width L/R, height top/bottom) — the window handles re-emit windowOffsetX / windowOffsetY in `apply` so the anchored edge stays put as the dragged edge follows the pointer. Handle visibility on roof accessories needed an editor-side assist: the host segment's mesh registers inside RoofRenderer's `<group segments-wrapper visible={false}>`, which hides anything portaled into it. Chimney's `portal: 'grandparent'` escape trips a WebGPU "Color target has no corresponding fragment stage output" pipeline error on dormer (likely an MRT interaction with the window-assembly's transparent glazing), so RoofEditSystem now flips the wrapper visible whenever ANY accessory hosted on a segment of this roof is selected — and resets each segment mesh to an empty 4-group placeholder on the transition so stale per-segment CSG from a prior edit doesn't double-render on top of the merged shell. Window clipping was using wall-top-above-slope as the exposure threshold, but the window sits in the skirt well below the eave — so a dormer whose eave barely cleared the host roof rendered a fully-buried window. `getDormerExposedFaces` now gates on window-bottom-above-slope; both the CSG cut decision and the window-assembly render path feed off the same number. The in-world window chevrons resolve the host segment via sceneApi and flip to whichever face is currently exposed, so dragging the dormer across the ridge moves the chevrons to the visible gable. Also fixes the BoxGeometry vs ExtrudeGeometry mismatch in `buildDormerFallbackGeometry` — body was indexed, roof was not, so `mergeGeometries` rejected the pair and spammed the console on every height-drag frame. Body is now `.toNonIndexed()` before the merge. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(viewer): glazing role uses FrontSide to avoid MRT back-face pipeline error DoubleSide on a NodeMaterial inside the MRT scene pass makes WebGPU compile a back-face shader variant that doesn't declare outputs for every MRT target — the validator rejects it and poisons the render context with "Color target has no corresponding fragment stage output". The warning was already documented on `glassMaterial` (materials.ts:77), but `createSurfaceRoleMaterial` was still forcing DoubleSide for the glazing role. Manifested on scene open as soon as a dormer was present: the dormer's window-assembly mounts the glazing material on both gable faces on the first frame, so the back-face pipeline gets compiled immediately. Glazing now resolves to FrontSide; the dormer's back gable group flips 180° so its FrontSide normals point outward (the sill no longer needs its per-face Z mirror since the group rotation handles it). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(nodes): in-world handles for box-vent + ridge-vent; freeze non-active arrows during drag Adds 5 chevron handles to box-vent (width L/R, depth, height, rotate) and ridge-vent (length L/R, width, height, rotate). Box-vent's renderer now composes slope tilt + yaw onto the registered ref's quaternion (mirrors solar-panel) so handle placements use vent-mesh-local coords directly; ridge-vent's registered ref was already at the vent frame. Ridge-vent renderer now merges `useLiveNodeOverrides` so the mesh updates in-flight during a handle drag instead of freezing until commit. Box-vent / dormer / chimney already did this; ridge-vent was the only roof accessory not subscribed. `NodeArrowHandles` now tracks the active drag descriptor + a pre-drag store snapshot. Non-active arrows render against the snapshot with a node-local freeze offset that cancels the mesh's `position` drift — asymmetric resize (width / length L+R) recomputes position to anchor the opposite edge, and without the freeze every other chevron would slide along with the moving mesh center. The active arrow's freeze offset is null, so it tracks the cursor as before. Rotation drags collapse the offset to zero (position doesn't change), so non-active chevrons naturally rotate with the mesh. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(nodes): gutter accessory — eave-mounted rain channel with three profiles New `gutter` node kind hosted on a roof-segment. Placement tool snaps to the eave line of the segment under the cursor (segment-local `Z = +depth/2`, `Y = wallHeight`); the back wall of the gutter then sits flush against the fascia and the trough hangs outward (+Z). Three cross-section profiles share the same outer-outline-minus-cavity extrude recipe and only differ in the outline curve: - `k-style`: ogee fascia (S-curve) — default residential look - `half-round`: semicircular trough — colonial / classical feel - `box`: rectangular u-channel — commercial / industrial Three in-world chevron handles via the registry: - length L + R (asymmetric — drag one end, the other stays world-fixed) - size (anchor='max', drops the trough downward as the cursor pulls) Wiring touches every node-kind ledger: schema (core/schema/nodes/ gutter.ts), AnyNode union, schema barrel, material targets, roof-segment hosted-accessory comment, event bus (`gutter:*`), nodes barrel + registry, plus the per-kind file set under `packages/nodes/src/gutter/` (geometry, schema re-export, parametrics, renderer, preview, tool, definition, index). V1 ships gutters only — downspouts deferred so the eave-snap + cross-section pipeline can be eyeballed before stacking the downspout-corner placement logic on top. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gutter): roof-panel entry, eave-edge snap, open-top U-channel, move tool UI surface area: - Roof inspector "Elements" section now lists existing gutters + an "Add Gutter" button. Adds `'gutter'` to the StructureTool union so setTool('gutter') typechecks. - Sidebar tree-node map gets a GutterTreeNode entry; selecting a gutter in the outline focuses it just like other roof accessories. - Floating action menu now shows a Move button on a selected gutter via the new `affordanceTools.move`. MoveGutterTool ghost-follows the cursor, eave-snaps on each frame, and commits to the new segment + side on click. Mirrors the ridge-vent move flow. Geometry fix: - Three cross-sections were authored as a closed outline + inset hole, which extrudes as a sealed box with a tunnel through it (top sealed). Real gutters need an OPEN top. Each profile now traces a single U-shape polygon around the channel material: outer wall down -> bottom -> outer wall up -> front rim -> inner wall down -> inner bottom -> inner wall up -> back rim. The interior of the U is empty space, not a hole inside a closed shape. Placement fix: - Snap now lands on the OUTER drip edge of the roof, not the wall line. Segment-local Z = sign * (depth/2 + overhang - 4 cm tuck), Y = wallHeight - overhang * tan(pitch) + 4 cm tuck. Sign of the cursor's localZ picks the near eave; back eave uses rotation = pi so the trough hangs outward in both directions. The 4 cm tuck offsets keep the gutter visually attached to the fascia rather than floating at the very tip of the overhang. Hook order fix (regression from the previous commit): - `NodeArrowHandlesForNode` had its new useState/useMemo hooks AFTER the `if (!portalObject ...) return null` guard. The registry-resolve useEffect flips portalObject from null to object one frame later, so the guard passed on render N+1 and three new hooks suddenly appeared in the hook list. Moved them above the early return. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * fix(viewer/nodes): drop DoubleSide NodeMaterial MRT landmines across slab, vents, gutter, window DoubleSide on any NodeMaterial inside the MRT scenePass makes WebGPU compile a back-face shader variant whose fragment outputs don't cover every MRT target — the validator rejects the pipeline and poisons the render context with "Color target has no corresponding fragment stage output but writeMask is not zero", manifesting as renderPipeline_NNN invalid on scene open. The pattern was already documented at materials.ts:77 and fixed for glazing in 9400f1c5, but several roof / floor renderers still requested DoubleSide on `createSurfaceRoleMaterial` (which returns a `MeshLambertNodeMaterial`) and on user-supplied materials (which may also be NodeMaterials): - slab/geometry.ts — fired on every untextured floor; the live culprit on scene reload after the gutter renderer was switched to FrontSide. - gutter/renderer.tsx — the U-channel cross-section is traced as a single closed polygon around the material, so ExtrudeGeometry already produces outward-facing normals on every visible face; DoubleSide was speculative. - box-vent / ridge-vent renderers — DoubleSide was deliberate (to keep back faces of thin extrudes visible from below); now a known visual tradeoff. Build the geometry as a closed solid in `geometry.ts` if the underside-view becomes noticeable; do not bring DoubleSide back. - viewer/lib/materials.ts `DEFAULT_WINDOW_MATERIAL` — same fix on the fallback window material. Local `defaultMaterial` constants in box-vent / ridge-vent / gutter also lose their `side: DoubleSide` for consistency (those are `MeshStandardMaterial`, hit only when a preset ref fails to resolve, but the same landmine pattern). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(editor): Shift-snap rotate gizmos to 15° increments Holding Shift while dragging a whole-node rotation arrow now snaps the delta to π/12 (15°) steps. Scoped to `descriptor.shape === 'rotate'` so curved-stair sweep handles keep their continuous feel. * feat(nodes): stair railings track live segment-drag overrides `StairRailings` was reading each child segment from zustand only, so width/length/height drag handles (which publish to `useLiveNodeOverrides` and only flush on release) left the railing frozen at the pre-drag values until release. Subscribe to the override map and merge each child's override onto its zustand snapshot so the railing rebuilds every frame during the drag. * chore(ifc-converter): next-env routes path moves under .next/dev/types Auto-generated next-env.d.ts update from the local Next.js dev server — the routes type now lives under `.next/dev/types/routes.d.ts` rather than `.next/types/routes.d.ts`. * fix(gutter): roofType-aware eave snap — 4-way on hip/flat, low side on shed Gutter place + move tools were hard-coded to snap to ±Z eaves, working for gable / gambrel / mansard / dutch but missing: - Hip / flat: 4 eaves, not 2. Clicks on the side slopes (±X eaves) collapsed back onto ±Z, so users couldn't place a gutter on a hip's side eave at all. - Shed: only one real eave (the low side at +Z). Clicking on the high wall side used to snap to -Z, which is the rake / high end with no fascia to hang from. New shared `eave-snap.ts` module: - `resolveEaveSnap(segment, localX, localZ)` returns `{ eaveX, eaveY, eaveZ, rotation, side }`. - Hip / flat picker uses `max(|lx|/halfW, |lz|/halfD)` — same discriminator `analyticalSurfaceY` uses for hip — to pick which of the four slopes the cursor is on, then signs +/-. - ±X eaves rotate the gutter ±π/2 so its outward axis points away from the building. - Shed always returns +Z (the low side). - Gable / gambrel / mansard / dutch unchanged (±Z). Both tools collapsed their duplicated tuck constants + inlined resolver — the "keep these in sync" comment became a landmine once the resolver grew non-trivial. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gutter): end caps + corner mitre + ghost-placed parity - Ghost/move previews mirror the GutterRenderer transform chain (roof → segment → snap) and use FrontSide. Removes drift between the placement ghost and the gutter that lands on click. - New endCapLeft / endCapRight booleans (default true) slice a solid-outer plug into the extrusion at each enabled end. Inspector exposes both toggles; caps subtract from node.length so the user-set span is preserved. - corner-mitre.ts detects sibling gutters meeting within 5 cm on the same segment and returns per-end mitre angles. The end-face skew holds back walls at the inner corner while front rims extend to the outer eave intersection; cap on a mitred end is force- suppressed so the L-junction stays open. Renderer pulls siblings via useShallow. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gutter): drag-snap corners, live eave Y, hangers - Length L/R handles now snap to sibling gutter endpoints within 10 cm and pull BOTH gutters' lengths to the axis intersection — the geometric eave corner — so the 5 cm corner-mitre window fires reliably. Sibling adjustment writes through sceneApi.update; the drag pipeline's history pause batches it with the main commit into one undo step. - Renderer derives eave Y live from segment.wallHeight, overhang, and pitch via the new shared computeEaveY() — instead of trusting node.position[1] from placement time. Subscribes to the segment's useLiveNodeOverrides entry too, so a wall-height drag on the segment moves the gutter on every frame (not just at commit). - Hangers: new hangerStyle (strap / none) + hangerSpacing fields. buildHangers() lays thin 25mm × 3mm × rim-width box straps across the rim at the configured spacing, inset by 5 cm from each end and skipping any cap slabs. BoxGeometry is converted to non-indexed before merge — ExtrudeGeometry isn't indexed, and mergeGeometries rejects mixed-index sets. Inspector exposes both fields in a new "Hangers" group. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(gutter): downspout outlet with real CSG-drilled hole New schema fields: outletSide ('none' | 'left' | 'right'), outletInset, outletDiameter. Default 'none' so existing gutters don't sprout outlets on schema upgrade. Geometry adds a solid cylindrical stub at bore + 3 mm wall radius descending 6 cm from the trough floor, profile-aware Z midpoint (k-style 0.4·size, half-round size, box size/2), X clamped between the caps. After merging into the channel + caps + hangers, a three-bvh-csg SUBTRACTION drills a bore-wide cylinder vertically through the floor and stub — so the result is a real hole in the trough floor with a hollow tube hanging through it. Drill overshoots floor + stub by 1 cm each side to keep cut planes from coinciding with mesh faces (csg-evaluator produces degenerate output on coplanar cuts). CSG only runs when outletSide ≠ 'none' — the existing merge path is the fast path for capped-only gutters. Inspector exposes the three fields under a new 'Outlet' group. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(downspout): new node + gutter inspector list section DownspoutNode lives next to the other roof accessories. Scene-graph parent is the same roof-segment the host gutter sits on; logical attach is via `gutterId`. Schema: length (default 2.5 m), diameter (default 0.07 m / 3″ — matches gutter outlet default), material. Renderer mounts a CylinderGeometry under the same transform chain the gutter uses (segment → gutter-mesh-local → outlet); pulls `computeEaveY` from the live + drag-override segment so wallHeight / overhang / pitch changes track on the same frame as the gutter. `resolveGutterOutletPlacement` (gutter/outlet-lookup.ts) is the shared helper both the downspout renderer and the inline Add path use to compute (x, y, z, bore) in gutter-mesh-local space. Two arrow handles on a selected downspout: - length: tracker shape (dashed leader + draggable cube). Anchored to the outlet, cube at the pipe bottom — readable even when the cube ends up below ground. - diameter: symmetric `z`-axis chevron sitting at a fixed −20 cm Y below the outlet with 25 cm of outward clearance past the worst- case k-style rim, so it stays inside the gutter's camera frame instead of floating mid-pipe. Inspector UX: new optional `trailingSection` slot on ParametricDescriptor — a lazy-loaded React subsection rendered between groups and the Actions section. Gutter's slot loads a `downspouts-panel` that lists every attached downspout (button per item, click → select), and an "Add Downspout" button below that immediately creates a new one parented to the gutter's segment — matches the roof inspector's gutter list pattern. Disabled with a helper line when `outletSide === 'none'`. Multiple downspouts per gutter are allowed. `StructureTool` union picks up 'downspout' so the placement tool remains addressable (used by the legacy roof-panel button before the inspector list took over). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * chore: pending floorplan alignment-guide work-in-progress Snapshot of in-flight alignment-guide files that have been sitting in the working tree (not authored in this session). New service + zustand store wire up the data; the floorplan layer + overlay are the visible consumers. Committed as-is to clear the tree. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> * feat(core): gutter multi-outlet model + downspout routing options Replace the gutter's single outletSide/outletInset/outletDiameter triple with an `outlets` array of `{ id, offset, diameter }` so one run can host several downspouts on independent drops instead of stacking on one. Each downspout links to an outlet by `outletId`. Add downspout routing/styling fields: `standoff` (gap proud of the wall), `shape` (auto/round/rect), `strapStyle`/`strapSpacing`, and `terminal` (splash/kickout/straight). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(editor): in-world rotate & move gizmos with live-drag dimension pill Add two new handle-descriptor capabilities to the core registry — a free `translate` handle (ground-plane or wall-normal move cross) and `rotationPlane` for arc-resize (yaw vs spin-flat-against-wall) — plus `measureLabel`, which routes a resize handle's readout to a floating dimension pill instead of its inline chip, and `overrideTarget`, a cross-node redirect for handles that edit a sibling's value. node-arrow-handles implements all four, merging the in-flight drag into `useLiveNodeOverrides` so the mesh moves in real time and commits only on release. Item gains in-world rotate + move gizmos (floor items: world-Y rotate + floor-plane move; wall items: wall-normal spin + wall-face move). Add the shared MeasurementPill (H · L · T) and formatMeasurement, wired into the floating action menu (live wall/fence height drag) and the wall / fence endpoint move tools. Side handles merge live overrides so every affordance tracks the height mid-drag. Item duplicate now drag-to-places (no auto-insert) and the placement coordinator rotates in 45° steps to match the R-key step. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(gutter): multi-downspout outlets with CSG drops, routing & profiles Build out the multi-outlet gutter against the new schema. Each outlet is drilled through the trough floor via CSG (profile-geometry shares the trough cross-section), and a downspout links to one outlet by id so several no longer stack on a single drop. The downspouts panel manages the outlet list; outlet-lookup resolves a downspout's mount from its gutter + outlet. Downspout gains real routing (routing.ts): offset elbows step the run back from the eave overhang to the wall (standoff escape hatch), auto/round/rect cross-section following the gutter profile, wall straps, and splash / kickout / straight terminals, with inspector-editors for the new fields. Length-snap now snaps only the dragged gutter to the geometric corner — never moving its corner-mate — so dragging one gutter can't reset another the user placed deliberately. Adds gutter floorplan (eave-line silhouette). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(floorplan): 2D footprints for roof nodes + rotate-handle angle wedge Add floorplan builders for box-vent, chimney, dormer, ridge-vent, roof, skylight, and solar-panel, and wire each into its definition, so roof-layer nodes finally draw a 2D footprint. Roof draws the merged silhouette of its child segments, and roof-segment now renders proper architectural roof linework (ridge / hip / break + shed downslope arrow) per shape instead of a bare rectangle. Add a `pivot` to the floorplan rotate affordance so the layer can sweep a live angle wedge + degree readout during a rotate drag — the 2D twin of the 3D rotate gizmo. Column / elevator / shelf / stair pass their pivot through. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): select ceiling only via its corner handles, not the grid body Add `viaHandle` to NodeEvent and set it on ceiling corner-bracket clicks. The selection manager now ignores non-handle ceiling clicks without stopping propagation, so a top-down click on the revealed ceiling grid falls through to the item hosted beneath it instead of re-selecting the ceiling and swallowing the click. The corner brackets draw with depthTest off at a high render order so they stay visible and clickable through occluding geometry. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(editor): highlight wall openings on a selected wall Add WallOpeningHighlights — an indigo accent frame + translucent pane drawn around each door / window opening of the selected wall, so editable children (including frameless openings with no visible geometry) are easy to locate. The accent is deliberately distinct from the white selection outline, and draws with depthTest off so it reads on top of the wall. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(solar-panel): derive surface frame live so panels re-seat on roof changes Compute the panel's Y and tilt from the parent roof-segment's finished (deck + shingle) surface every render via getRoofOuterSurfaceFrameAtPoint — the same helper skylights use — instead of reading the stored position[1]/surfaceNormal snapshot. Merging the segment's live overrides means the panel re-seats and re-tilts continuously during a wall-height / pitch drag rather than floating or burying until the value commits. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(first-person): coerce imported item geometry attrs to Float32 for collider merge mergeGeometries requires every merged geometry to share the same typed-array constructor per attribute. Imported item GLBs using KHR_mesh_quantization or interleaved buffers broke the merge against Float32 wall/slab geometry, so decode each attribute into a plain non-normalized Float32 BufferAttribute before cloning into the collider world. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * fix(editor): lower camera minimum zoom distance to 6m Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * chore(mcp): bump @pascal-app/mcp to 0.3.0 in lockfile Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * refactor(nodes): registry-own move dispatch + hoist shared roof helpers Addresses the architecture-review findings on the gutter/downspout branch: - Move dispatch: port the bespoke roof/roof-segment/stair/stair-segment movers (MoveRoofTool) and the building mover (MoveBuildingContent) into @pascal-app/nodes (shared/move-roof-tool.tsx, building/move-tool.tsx) and declare them via `affordanceTools.move`. Delete both hardcoded dispatch lists — `LEGACY_MOVABLE_KINDS` in floating-action-menu and the roof/stair/ building arms of MoveTool. `onMove` is now purely `isRegistryMovable`. Editor internals the movers need are exported from @pascal-app/editor (adds clearRoofDuplicateMetadata); sfxEmitter.emit -> triggerSFX. elevator keeps its existing capabilities.movable path (its legacy arm is the lone remaining one, now documented). - Cross-kind imports: hoist resolveRoofSegmentHit (roof/segment-hit.ts) and the roof-surface normal math (getSurfaceY/getAnalyticalNormal/ surfaceQuatFromNormal, formerly in solar-panel/geometry.ts) into packages/nodes/src/shared/, so the 8 roof accessories + skylight/box-vent stop reaching into sibling kind folders. roof/index and solar-panel/index re-export from shared so public surfaces are unchanged. - Inspector: make ParametricInspector action `enabledIf` reactive by subscribing to its boolean result (ParamActionButton), matching the existing FieldRenderer/visibleIf pattern. Type-checked (tsc) and linted (biome) across editor + nodes. Move behaviour is preserved by construction but not yet runtime-verified in the editor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(nodes): add cupola + turbine-vent roof accessories; group-rotate gizmo; in-ring rotation readout New roof-accessory node types and editor gizmo work: - feat(nodes): cupola (roof lantern) and turbine-vent (whirlybird) node types — schema, geometry, parametrics, renderer, panel, move/placement tools, floorplan, and tests; registered in the node + core schema indexes with site-panel tree nodes. - feat(editor): group-rotate handle — a single rotation gizmo for 2+ movable nodes that spins the selection rigidly about its shared bbox center. - fix(editor): the live rotation readout (degree wedge + chip) now renders as a child of the node frame, concentric and coplanar with the guide ring, so it sits centered in the ring on pitched roofs instead of floating off to the side. Flat-ground gizmos and the group-rotate readout are unchanged. - refactor(nodes): rework box-vent / ridge-vent geometry + definitions and share roof helpers; tidy roof/box-vent panels. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> * feat(nodes): eyebrow-vent kind; ridge-vent tracks roof height; vent paint + tree-node go registry-driven New eyebrow-vent roof accessory plus two follow-on cleanups: - feat(nodes): eyebrow-vent — a louvered roof vent in three styles (`scoop` swept eyebrow, `half-round` D-vent, `slant-box` hooded box). Solid louver slabs set into a framed/contained front, double-sided geometry, and adjustable style / louver-count / dimensions / slant (`backRatio`). Full registry wiring: core schema, node dir (definition/geometry/renderer/tool/ move-tool/panel/floorplan/preview/tests), event type, palette button. - fix(nodes): ridge vent derives its Y from the segment's current surface (`getSurfaceY`) instead of a stored value, so lowering a roof drops the cap onto the new ridge automatically. - refactor(nodes,editor): migrate the vent family (box / ridge / turbine / cupola / eyebrow) to `capabilities.paint` via a shared single-surface capability, removing the hardcoded `node.type` paint arms from the editor's selection-manager + material-paint (matches chimney/dormer). - refactor(editor): replace the five identical vent tree-node components with one `def.presentation`-driven `RegistryTreeNode`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
96d6e0afdb
commit
eb1f2d12c2
@@ -1,8 +1,327 @@
|
||||
import { ChimneyNode as ChimneyNodeSchema, type NodeDefinition } from '@pascal-app/core'
|
||||
import {
|
||||
type AnyNodeId,
|
||||
type ChimneyNode as ChimneyNodeType,
|
||||
ChimneyNode as ChimneyNodeSchema,
|
||||
getActiveRoofHeight,
|
||||
type HandleDescriptor,
|
||||
type NodeDefinition,
|
||||
type RoofSegmentNode as RoofSegmentNodeType,
|
||||
type SceneApi,
|
||||
} from '@pascal-app/core'
|
||||
import { buildChimneyFloorplan } from './floorplan'
|
||||
import { chimneyPaint } from './paint'
|
||||
import { chimneyParametrics } from './parametrics'
|
||||
import { ChimneyNode } from './schema'
|
||||
|
||||
// Side handle offsets in metres. Match the roof-segment values so a
|
||||
// segment + chimney selected back-to-back use the same visual rhythm.
|
||||
const SIDE_HANDLE_OFFSET = 0.25
|
||||
const HEIGHT_HANDLE_OFFSET = 0.25
|
||||
const ROTATE_CORNER_OFFSET = 0.35
|
||||
const MIN_BODY_DIM = 0.3
|
||||
const MIN_HEIGHT_ABOVE_RIDGE = 0.05
|
||||
const MIN_FLUE_HEIGHT = 0.05
|
||||
const MAX_FLUE_HEIGHT = 1.5
|
||||
const MIN_CAP_THICKNESS = 0.02
|
||||
const MAX_CAP_THICKNESS = 0.5
|
||||
const MIN_CAP_OVERHANG = 0
|
||||
const MAX_CAP_OVERHANG = 0.3
|
||||
// Cap-reveal gap between body top and cap base — mirrors the
|
||||
// `CAP_REVEAL` constant in `geometry.ts`. Local copy because handle
|
||||
// placements need to know the cap's Y range and the geometry's
|
||||
// constant isn't exported. If you change it here, change it there.
|
||||
const CAP_REVEAL = 0.003
|
||||
// Fallback Y when the host segment can't be resolved (shouldn't happen
|
||||
// for a placed chimney, but `placement.position` runs synchronously and
|
||||
// must always return a vector).
|
||||
const FALLBACK_BODY_MID_Y = 1.5
|
||||
|
||||
// Resolve the segment that hosts this chimney. Returns undefined if the
|
||||
// chimney is unparented or the parent isn't in the scene yet.
|
||||
function resolveHostSegment(
|
||||
node: ChimneyNodeType,
|
||||
sceneApi: SceneApi,
|
||||
): RoofSegmentNodeType | undefined {
|
||||
if (!node.roofSegmentId) return undefined
|
||||
return sceneApi.get<RoofSegmentNodeType>(node.roofSegmentId as AnyNodeId)
|
||||
}
|
||||
|
||||
// Mid-Y of the visible chimney body in the host segment's local frame.
|
||||
// Matches the geometry builder: body runs from `baseY = max(0, wallHeight
|
||||
// - 0.2)` up to `peakY + heightAboveRidge`. The handle Y picks the
|
||||
// midpoint of the *visible* portion (deck plane → top) so chevrons sit
|
||||
// next to the body, not buried inside the roof deck or floating over
|
||||
// the eave.
|
||||
function getBodyMidY(node: ChimneyNodeType, segment: RoofSegmentNodeType): number {
|
||||
const peakY = segment.wallHeight + getActiveRoofHeight(segment)
|
||||
const topY = peakY + node.heightAboveRidge
|
||||
return (segment.wallHeight + topY) / 2
|
||||
}
|
||||
|
||||
// Top of the chimney body (where the cap reveal gap begins). Tracker
|
||||
// handle and cap-thickness handle both reference this Y.
|
||||
function getBodyTopY(node: ChimneyNodeType, segment: RoofSegmentNodeType): number {
|
||||
return segment.wallHeight + getActiveRoofHeight(segment) + node.heightAboveRidge
|
||||
}
|
||||
|
||||
// Cap base Y — the bottom of the cap slab. Sits just above the body
|
||||
// top with a small reveal gap so a shadow line separates them.
|
||||
function getCapBaseY(node: ChimneyNodeType, segment: RoofSegmentNodeType): number {
|
||||
return getBodyTopY(node, segment) + CAP_REVEAL
|
||||
}
|
||||
|
||||
// Cap top Y — the top of the cap slab. Falls back to body top when no
|
||||
// cap is rendered (flues mount on whichever is the upper surface).
|
||||
function getCapTopY(node: ChimneyNodeType, segment: RoofSegmentNodeType): number {
|
||||
if (!node.cap || node.capShape === 'none') return getBodyTopY(node, segment)
|
||||
return getCapBaseY(node, segment) + node.capThickness
|
||||
}
|
||||
|
||||
// Width arrow on the +X (right) or -X (left) side. Asymmetric resize:
|
||||
// dragging one arrow grows the chimney outward from its own edge while
|
||||
// the opposite edge stays world-fixed. Handles live in the chimney's
|
||||
// registered ref frame (the nested inner group in the renderer that
|
||||
// applies `node.position` / `node.rotation`), so placements are in
|
||||
// chimney-local coordinates — no per-arrow rotation/translation
|
||||
// compensation. `apply` keeps the world-fixed edge anchored even when
|
||||
// the chimney is rotated by recentering `position` along the chimney's
|
||||
// own +X arm in segment frame.
|
||||
function chimneyWidthHandle(side: 'left' | 'right'): HandleDescriptor<ChimneyNodeType> {
|
||||
const sign = side === 'right' ? 1 : -1
|
||||
return {
|
||||
kind: 'linear-resize',
|
||||
axis: 'x',
|
||||
anchor: side === 'right' ? 'min' : 'max',
|
||||
// Portal into the roof (grandparent), not the segment (parent). Unpainted
|
||||
// roof segments live inside a `visible={false}` wrapper, which would
|
||||
// hide the handles. The roof itself is always visible. Skylight does
|
||||
// the same.
|
||||
portal: 'grandparent',
|
||||
min: MIN_BODY_DIM,
|
||||
currentValue: (n) => n.width,
|
||||
apply: (initial, newWidth) => {
|
||||
const rotY = initial.rotation ?? 0
|
||||
const armX = Math.cos(rotY)
|
||||
const armZ = -Math.sin(rotY)
|
||||
const anchorX = initial.position[0] - sign * (initial.width / 2) * armX
|
||||
const anchorZ = initial.position[2] - sign * (initial.width / 2) * armZ
|
||||
const newCenterX = anchorX + sign * (newWidth / 2) * armX
|
||||
const newCenterZ = anchorZ + sign * (newWidth / 2) * armZ
|
||||
return {
|
||||
width: newWidth,
|
||||
position: [newCenterX, initial.position[1], newCenterZ],
|
||||
}
|
||||
},
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
const y = segment ? getBodyMidY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
return [sign * (n.width / 2 + SIDE_HANDLE_OFFSET), y, 0]
|
||||
},
|
||||
// Chevron faces along the chimney's own ±X; the left arrow flips
|
||||
// 180°. No node.rotation here — the registered inner group is
|
||||
// already rotated by `node.rotation`, so chimney-local +X is the
|
||||
// chevron's natural direction.
|
||||
rotationY: () => (side === 'right' ? 0 : Math.PI),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Depth arrow — symmetric on the +Z side. Only meaningful for square
|
||||
// bodies; round chimneys are circular (depth field is ignored by the
|
||||
// geometry builder, so a depth handle would just resize an invisible
|
||||
// field). The chimneys factory below omits this descriptor for round
|
||||
// bodies.
|
||||
function chimneyDepthHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'linear-resize',
|
||||
axis: 'z',
|
||||
anchor: 'center',
|
||||
min: MIN_BODY_DIM,
|
||||
currentValue: (n) => n.depth,
|
||||
apply: (_n, newValue) => ({ depth: newValue }),
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
const y = segment ? getBodyMidY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
return [0, y, n.depth / 2 + SIDE_HANDLE_OFFSET]
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Height-above-ridge tracker. Dashed leader spans the chimney body's
|
||||
// visible extent — from the roof deck plane up to the body top — and
|
||||
// terminates in a draggable cube at the body top. Cap, flues, cricket
|
||||
// and bands sit ABOVE the body and are explicitly excluded from the
|
||||
// leader so the height affordance reads as "this is the body height",
|
||||
// not "this is the whole stack height". Dragging the cube vertically
|
||||
// adjusts `heightAboveRidge` 1:1.
|
||||
function chimneyHeightAboveRidgeHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'linear-resize',
|
||||
axis: 'y',
|
||||
anchor: 'min',
|
||||
shape: 'tracker',
|
||||
min: MIN_HEIGHT_ABOVE_RIDGE,
|
||||
currentValue: (n) => n.heightAboveRidge,
|
||||
apply: (initial, newValue) => ({
|
||||
heightAboveRidge: Math.max(MIN_HEIGHT_ABOVE_RIDGE, newValue),
|
||||
}),
|
||||
placement: {
|
||||
// Cube sits AT the body top (no offset) so the leader terminates
|
||||
// exactly at the body's top edge — visually the "ceiling" of the
|
||||
// body, before the cap reveal gap.
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
const y = segment ? getBodyTopY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
return [0, y, 0]
|
||||
},
|
||||
},
|
||||
// Leader bottom = deck plane (segment.wallHeight). The chimney body
|
||||
// geometry actually extends a touch below the deck so the bottom
|
||||
// doesn't show above the eave on low-slope roofs (`baseY = max(0,
|
||||
// wallHeight - 0.2)`), but the visible portion starts at the deck —
|
||||
// and starting the leader there is what reads as "body height" to
|
||||
// the user.
|
||||
trackerBaseY: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
return segment?.wallHeight ?? 0
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Whole-chimney rotation gizmo at the +X/+Z corner of the body
|
||||
// footprint. The registered inner group already centers on the chimney
|
||||
// and applies its yaw, so the default rotation pivot (rideObject origin)
|
||||
// is correct — no `rotationCenter` override needed.
|
||||
function chimneyRotateHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'arc-resize',
|
||||
axis: 'angular',
|
||||
shape: 'rotate',
|
||||
apply: (initial, delta) => ({ rotation: (initial.rotation ?? 0) - delta }),
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
const y = segment ? getBodyMidY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
const isRound = n.bodyShape === 'round'
|
||||
const halfX = n.width / 2 + ROTATE_CORNER_OFFSET
|
||||
const halfZ = (isRound ? n.width : n.depth) / 2 + ROTATE_CORNER_OFFSET
|
||||
return [halfX, y, halfZ]
|
||||
},
|
||||
// The two-headed icon's natural bias points along +X; aim it
|
||||
// toward the corner (45° outward from the chimney's local frame).
|
||||
rotationY: () => -Math.PI / 4,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Flue-height chevron at the center of the cap top, pointing upward.
|
||||
// Drag adjusts `flueHeight` for ALL flues uniformly — the schema only
|
||||
// carries a single scalar. Placed at chimney center (X=Z=0) so the
|
||||
// handle stays valid regardless of `flueCount` / `flueSpacing`. Anchor
|
||||
// is 'min' so the flue base stays pinned to the cap and the top edge
|
||||
// follows the pointer.
|
||||
function chimneyFlueHeightHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'linear-resize',
|
||||
axis: 'y',
|
||||
anchor: 'min',
|
||||
portal: 'grandparent',
|
||||
min: MIN_FLUE_HEIGHT,
|
||||
max: MAX_FLUE_HEIGHT,
|
||||
currentValue: (n) => n.flueHeight,
|
||||
apply: (_n, newValue) => ({ flueHeight: newValue }),
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
// Sit the chevron at the flue top so it visually attaches to
|
||||
// the thing being dragged. Fallback Y mirrors the body-top
|
||||
// fallback above.
|
||||
const baseY = segment ? getCapTopY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
return [0, baseY + n.flueHeight, 0]
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Cap-thickness chevron above the cap top, pointing upward. Anchor is
|
||||
// 'min' so the cap base stays at body-top + reveal and the top edge
|
||||
// follows the pointer.
|
||||
function chimneyCapThicknessHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'linear-resize',
|
||||
axis: 'y',
|
||||
anchor: 'min',
|
||||
portal: 'grandparent',
|
||||
min: MIN_CAP_THICKNESS,
|
||||
max: MAX_CAP_THICKNESS,
|
||||
currentValue: (n) => n.capThickness,
|
||||
apply: (_n, newValue) => ({ capThickness: newValue }),
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
// Offset toward +Z (away from chimney center on the depth axis)
|
||||
// so the cap-thickness chevron doesn't overlap the flue-height
|
||||
// chevron at X=0,Z=0. Pick the cap edge minus a small margin so
|
||||
// it sits on top of the cap, not floating off to the side.
|
||||
const isRound = n.bodyShape === 'round'
|
||||
const halfZ = (isRound ? n.width : n.depth) / 2
|
||||
const z = halfZ * 0.35
|
||||
const y = segment ? getCapTopY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
return [0, y, z]
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Cap-overhang radial chevron on the +X edge of the cap. Outward 1:1
|
||||
// drag grows the overhang; the cap's half-extent is `width/2 + overhang`.
|
||||
function chimneyCapOverhangHandle(): HandleDescriptor<ChimneyNodeType> {
|
||||
return {
|
||||
kind: 'radial-resize',
|
||||
axis: 'x',
|
||||
portal: 'grandparent',
|
||||
min: MIN_CAP_OVERHANG,
|
||||
max: MAX_CAP_OVERHANG,
|
||||
currentValue: (n) => n.capOverhang,
|
||||
apply: (_n, newValue) => ({ capOverhang: newValue }),
|
||||
placement: {
|
||||
position: (n, sceneApi) => {
|
||||
const segment = resolveHostSegment(n, sceneApi)
|
||||
// Cap mid-height in the chimney-local frame so the chevron sits
|
||||
// on the cap edge, not above or below it.
|
||||
const capBaseY = segment ? getCapBaseY(n, segment) : FALLBACK_BODY_MID_Y
|
||||
const y = capBaseY + n.capThickness / 2
|
||||
return [n.width / 2 + n.capOverhang + SIDE_HANDLE_OFFSET, y, 0]
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
const chimneyHandles = (node: ChimneyNodeType): HandleDescriptor<ChimneyNodeType>[] => {
|
||||
const descriptors: HandleDescriptor<ChimneyNodeType>[] = [
|
||||
chimneyWidthHandle('right'),
|
||||
chimneyWidthHandle('left'),
|
||||
]
|
||||
if (node.bodyShape !== 'round') descriptors.push(chimneyDepthHandle())
|
||||
descriptors.push(chimneyHeightAboveRidgeHandle(), chimneyRotateHandle())
|
||||
// Conditional flue/cap handles are temporarily disabled — they fired
|
||||
// a "Color target has no corresponding fragment stage output" WebGPU
|
||||
// validation error that the original four handles don't trigger. The
|
||||
// descriptor shapes (linear-resize y / radial-resize x) match other
|
||||
// working handles in the codebase, so the cause is likely a TSL/MRT
|
||||
// pipeline interaction we haven't pinned down. Re-enable one at a
|
||||
// time after isolating the trigger; the factory + helpers are kept so
|
||||
// we can flip them back on without re-deriving the placement math.
|
||||
// if (node.cap && node.capShape !== 'none') {
|
||||
// descriptors.push(chimneyCapThicknessHandle(), chimneyCapOverhangHandle())
|
||||
// }
|
||||
// if (node.flueCount > 0) descriptors.push(chimneyFlueHeightHandle())
|
||||
return descriptors
|
||||
}
|
||||
|
||||
// Every fresh chimney starts as plain white (body + top). The paint
|
||||
// flow / material picker writes preset refs or full `MaterialSchema`
|
||||
// objects on top of this; until then both roles render `#ffffff`.
|
||||
@@ -73,6 +392,8 @@ export const chimneyDefinition: NodeDefinition<typeof ChimneyNode> = {
|
||||
},
|
||||
|
||||
parametrics: chimneyParametrics,
|
||||
handles: chimneyHandles,
|
||||
floorplan: buildChimneyFloorplan,
|
||||
|
||||
renderer: {
|
||||
kind: 'parametric',
|
||||
|
||||
@@ -0,0 +1,215 @@
|
||||
import type {
|
||||
AnyNodeId,
|
||||
ChimneyNode,
|
||||
FloorplanGeometry,
|
||||
FloorplanPoint,
|
||||
GeometryContext,
|
||||
RoofNode,
|
||||
RoofSegmentNode,
|
||||
} from '@pascal-app/core'
|
||||
import { flueXPositions } from './geometry'
|
||||
|
||||
/**
|
||||
* Floor-plan builder for a chimney. A chimney is a masonry stack hosted on
|
||||
* a roof segment. Seen from above it reads as its crown/cap footprint with
|
||||
* the body shaft nested inside (the cap overhangs the body) and the flue
|
||||
* openings poking out the top.
|
||||
*
|
||||
* Coordinate frame mirrors the 3D transform stack
|
||||
* (roof → roof-segment → chimney). The chimney's `position` is
|
||||
* segment-local (X = width axis, Z = depth axis; Y is ignored — the 3D
|
||||
* renderer anchors it to the slope). `rotation` is yaw. We compose with
|
||||
* the floor-plan's negated-rotation convention (see
|
||||
* `buildRoofSegmentFloorplan`). Unlike the gutter there's no eave/overhang
|
||||
* offset — a chimney sits at its own footprint, not on the drip edge.
|
||||
*/
|
||||
export function buildChimneyFloorplan(
|
||||
node: ChimneyNode,
|
||||
ctx: GeometryContext,
|
||||
): FloorplanGeometry | null {
|
||||
const segment = ctx.parent as RoofSegmentNode | null
|
||||
if (!segment || segment.type !== 'roof-segment') return null
|
||||
const roofId = segment.parentId as AnyNodeId | null
|
||||
const roof = roofId ? (ctx.resolve(roofId) as RoofNode | undefined) : undefined
|
||||
if (!roof || roof.type !== 'roof') return null
|
||||
|
||||
// Compose roof → segment → chimney in plan coords. Each rotation is
|
||||
// negated so SVG's y-down CW matches Three.js' top-down CCW.
|
||||
const cosR = Math.cos(-roof.rotation)
|
||||
const sinR = Math.sin(-roof.rotation)
|
||||
const segCx = roof.position[0] + segment.position[0] * cosR - segment.position[2] * sinR
|
||||
const segCz = roof.position[2] + segment.position[0] * sinR + segment.position[2] * cosR
|
||||
|
||||
const segRot = -(roof.rotation + segment.rotation)
|
||||
const cosS = Math.cos(segRot)
|
||||
const sinS = Math.sin(segRot)
|
||||
const cx = segCx + node.position[0] * cosS - node.position[2] * sinS
|
||||
const cz = segCz + node.position[0] * sinS + node.position[2] * cosS
|
||||
|
||||
const rot = -(roof.rotation + segment.rotation + node.rotation)
|
||||
const cos = Math.cos(rot)
|
||||
const sin = Math.sin(rot)
|
||||
const toPlan = (lx: number, lz: number): FloorplanPoint => [
|
||||
cx + lx * cos - lz * sin,
|
||||
cz + lx * sin + lz * cos,
|
||||
]
|
||||
|
||||
const view = ctx.viewState
|
||||
const palette = view?.palette
|
||||
const isSelected = view?.selected ?? false
|
||||
const isHighlighted = view?.highlighted ?? false
|
||||
const isHovered = view?.hovered ?? false
|
||||
const showSelectedChrome = isSelected || isHighlighted
|
||||
|
||||
// Masonry — warm stone grey, accent on select, light blue on hover.
|
||||
const baseInk = '#44403c'
|
||||
const stroke =
|
||||
showSelectedChrome && palette
|
||||
? palette.selectedStroke
|
||||
: isHovered && palette
|
||||
? palette.wallHoverStroke
|
||||
: baseInk
|
||||
const fill = showSelectedChrome ? '#fed7aa' : '#d6d3d1'
|
||||
const fillOpacity = showSelectedChrome ? 0.55 : 0.6
|
||||
const lineWidth = showSelectedChrome ? 0.03 : 0.022
|
||||
|
||||
const isRound = node.bodyShape === 'round'
|
||||
const halfW = Math.max(node.width, 0.05) / 2
|
||||
// Round bodies use `width` as the diameter and ignore `depth`.
|
||||
const halfD = isRound ? halfW : Math.max(node.depth, 0.05) / 2
|
||||
const hasCap = node.cap && node.capShape !== 'none'
|
||||
const overhang = hasCap ? Math.max(node.capOverhang, 0) : 0
|
||||
const capHalfW = halfW + overhang
|
||||
const capHalfD = halfD + overhang
|
||||
const showBodyInset = hasCap && overhang > 0.001
|
||||
|
||||
const children: FloorplanGeometry[] = []
|
||||
|
||||
if (isRound) {
|
||||
const c = toPlan(0, 0)
|
||||
// Transparent hit-target across the crown footprint.
|
||||
children.push({
|
||||
kind: 'circle',
|
||||
cx: c[0],
|
||||
cy: c[1],
|
||||
r: capHalfW,
|
||||
fill: stroke,
|
||||
fillOpacity: 0,
|
||||
stroke: 'none',
|
||||
strokeWidth: 0,
|
||||
pointerEvents: 'all',
|
||||
})
|
||||
// Crown / outer body footprint, filled.
|
||||
children.push({
|
||||
kind: 'circle',
|
||||
cx: c[0],
|
||||
cy: c[1],
|
||||
r: capHalfW,
|
||||
fill,
|
||||
fillOpacity,
|
||||
stroke,
|
||||
strokeWidth: lineWidth,
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
// Body shaft inside the cap overhang.
|
||||
if (showBodyInset) {
|
||||
children.push({
|
||||
kind: 'circle',
|
||||
cx: c[0],
|
||||
cy: c[1],
|
||||
r: halfW,
|
||||
fill: 'none',
|
||||
stroke,
|
||||
strokeWidth: lineWidth * 0.8,
|
||||
strokeOpacity: 0.7,
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
}
|
||||
} else {
|
||||
const capCorners: FloorplanPoint[] = [
|
||||
toPlan(-capHalfW, -capHalfD),
|
||||
toPlan(capHalfW, -capHalfD),
|
||||
toPlan(capHalfW, capHalfD),
|
||||
toPlan(-capHalfW, capHalfD),
|
||||
]
|
||||
children.push({
|
||||
kind: 'polygon',
|
||||
points: capCorners,
|
||||
fill: stroke,
|
||||
fillOpacity: 0,
|
||||
stroke: 'none',
|
||||
strokeWidth: 0,
|
||||
pointerEvents: 'all',
|
||||
})
|
||||
children.push({
|
||||
kind: 'polygon',
|
||||
points: capCorners,
|
||||
fill,
|
||||
fillOpacity,
|
||||
stroke,
|
||||
strokeWidth: lineWidth,
|
||||
strokeLinejoin: 'miter',
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
if (showBodyInset) {
|
||||
children.push({
|
||||
kind: 'polygon',
|
||||
points: [
|
||||
toPlan(-halfW, -halfD),
|
||||
toPlan(halfW, -halfD),
|
||||
toPlan(halfW, halfD),
|
||||
toPlan(-halfW, halfD),
|
||||
],
|
||||
fill: 'none',
|
||||
stroke,
|
||||
strokeWidth: lineWidth * 0.8,
|
||||
strokeOpacity: 0.7,
|
||||
strokeLinejoin: 'miter',
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Flue openings poking out the crown — drawn along the chimney's local X
|
||||
// at z = 0, matching `flueXPositions` (the same layout the 3D pots use).
|
||||
// Round or square per `flueShape`. Hollow so they read as openings.
|
||||
const flueCount = Math.max(0, Math.min(4, node.flueCount))
|
||||
if (flueCount > 0) {
|
||||
const d = Math.max(0.02, node.flueDiameter)
|
||||
const r = d / 2
|
||||
const xs = flueXPositions(flueCount, node.width, d, node.flueSpacing)
|
||||
const flueStroke = showSelectedChrome && palette ? palette.selectedStroke : '#292524'
|
||||
for (const fx of xs) {
|
||||
if (node.flueShape === 'square') {
|
||||
children.push({
|
||||
kind: 'polygon',
|
||||
points: [
|
||||
toPlan(fx - r, -r),
|
||||
toPlan(fx + r, -r),
|
||||
toPlan(fx + r, r),
|
||||
toPlan(fx - r, r),
|
||||
],
|
||||
fill: 'none',
|
||||
stroke: flueStroke,
|
||||
strokeWidth: lineWidth * 0.8,
|
||||
strokeLinejoin: 'miter',
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
} else {
|
||||
const c = toPlan(fx, 0)
|
||||
children.push({
|
||||
kind: 'circle',
|
||||
cx: c[0],
|
||||
cy: c[1],
|
||||
r,
|
||||
fill: 'none',
|
||||
stroke: flueStroke,
|
||||
strokeWidth: lineWidth * 0.8,
|
||||
pointerEvents: 'none',
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return { kind: 'group', children }
|
||||
}
|
||||
@@ -138,7 +138,6 @@ function buildBodyGeometry(node: ChimneyNode, baseY: number, topY: number): THRE
|
||||
parts.push(buildSmoothCylinder(baseY + sh, topY, r, r))
|
||||
}
|
||||
const merged = mergeAndDispose(parts)
|
||||
applyNodeTransform(merged, node)
|
||||
return merged
|
||||
}
|
||||
|
||||
@@ -213,7 +212,6 @@ function buildCapGeometry(node: ChimneyNode, capBaseY: number): THREE.BufferGeom
|
||||
break
|
||||
}
|
||||
const merged = mergeAndDispose(parts)
|
||||
applyNodeTransform(merged, node)
|
||||
return merged
|
||||
}
|
||||
|
||||
@@ -450,7 +448,6 @@ function buildBandsGeometry(
|
||||
}
|
||||
if (parts.length === 0) return null
|
||||
const merged = mergeAndDispose(parts)
|
||||
applyNodeTransform(merged, node)
|
||||
return merged
|
||||
}
|
||||
|
||||
@@ -484,10 +481,14 @@ function buildBandsGeometry(
|
||||
|
||||
// ─── Helpers ─────────────────────────────────────────────────────────
|
||||
|
||||
function applyNodeTransform(geo: THREE.BufferGeometry, node: ChimneyNode) {
|
||||
if (Math.abs(node.rotation) > 1e-4) geo.rotateY(node.rotation)
|
||||
geo.translate(node.position[0] ?? 0, 0, node.position[2] ?? 0)
|
||||
}
|
||||
// Each builder returns geometry in chimney-local frame (chimney center
|
||||
// at X/Z origin, Y absolute in the host segment's frame). The renderer
|
||||
// applies `node.position` / `node.rotation` via a nested registered
|
||||
// group, which lets `NodeArrowHandles` read a chimney-local mesh frame
|
||||
// when placing the resize / rotation arrows. Kept as a no-op shim so
|
||||
// the existing call sites don't need to be touched if a future refactor
|
||||
// re-introduces per-builder baking.
|
||||
function applyNodeTransform(_geo: THREE.BufferGeometry, _node: ChimneyNode) {}
|
||||
|
||||
function buildBufferGeometry(positions: number[], uvs: number[]): THREE.BufferGeometry {
|
||||
const geo = new THREE.BufferGeometry()
|
||||
|
||||
@@ -270,8 +270,9 @@ function buildPanelCutters(node: ChimneyNode, topY: number): Brush[] {
|
||||
for (const f of faces) {
|
||||
const geo = new THREE.BoxGeometry(f.sizeX, h, f.sizeZ)
|
||||
geo.translate(f.cx, midY, f.cz)
|
||||
if (Math.abs(node.rotation) > 1e-4) geo.rotateY(node.rotation)
|
||||
geo.translate(node.position[0] ?? 0, 0, node.position[2] ?? 0)
|
||||
// Body geometry is in chimney-local frame (node.position/rotation are
|
||||
// applied by the renderer's nested ref'd group, not baked into the
|
||||
// buffer geometry), so cutters need to stay in chimney-local too.
|
||||
|
||||
const idx = geo.getIndex()?.count ?? 0
|
||||
geo.clearGroups()
|
||||
@@ -298,10 +299,9 @@ function buildCutter(
|
||||
? new THREE.CylinderGeometry(spec.sizeX / 2, spec.sizeX / 2, h, 24, 1, false)
|
||||
: new THREE.BoxGeometry(spec.sizeX, h, spec.sizeZ)
|
||||
geo.translate(spec.xCenter, midY, 0)
|
||||
// Match the same node-local transform that `geometry.ts:applyNodeTransform`
|
||||
// bakes into the body/cap/flue vertices.
|
||||
if (Math.abs(node.rotation) > 1e-4) geo.rotateY(node.rotation)
|
||||
geo.translate(node.position[0] ?? 0, 0, node.position[2] ?? 0)
|
||||
// Cutter stays in chimney-local frame to match the body/cap/flue
|
||||
// geometry (node.position/rotation are applied via the renderer's
|
||||
// nested ref'd group, not baked into the buffer geometry).
|
||||
|
||||
const idx = geo.getIndex()?.count ?? 0
|
||||
geo.clearGroups()
|
||||
|
||||
@@ -15,7 +15,7 @@ import { triggerSFX, useEditor } from '@pascal-app/editor'
|
||||
import { useViewer } from '@pascal-app/viewer'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import * as THREE from 'three'
|
||||
import { resolveRoofSegmentHit } from '../roof/segment-hit'
|
||||
import { resolveRoofSegmentHit } from '../shared/roof-segment-hit'
|
||||
import ChimneyPreview from './preview'
|
||||
|
||||
const tmpMatrix = new THREE.Matrix4()
|
||||
|
||||
@@ -223,67 +223,71 @@ const ChimneyRenderer = ({ node: storeNode }: { node: ChimneyNode }) => {
|
||||
|
||||
if (!segment || !geo) return null
|
||||
|
||||
// The chimney's geometry bakes its baseY using segment.wallHeight inside
|
||||
// the builder, so the outer group only needs the segment-local X/Z
|
||||
// offset. Y stays at 0 here.
|
||||
|
||||
// Chimneys are mounted inside `RoofRenderer`'s `roof-elements` group,
|
||||
// which sits at the ROOF's origin — not inside the host segment's
|
||||
// transform. Apply the segment's own position/rotation here so a
|
||||
// chimney parented to segment N lands on segment N (and not on the
|
||||
// first segment) once the chimney's segment-local `node.position[0/2]`
|
||||
// is layered in by `geometry.ts`. Mirrors skylight's renderer.
|
||||
// transform. Apply the segment's pose on the outer group, then nest a
|
||||
// ref'd inner group at the chimney's segment-local position +
|
||||
// rotation so the registered Object3D's local frame is *chimney-local*
|
||||
// — that's what `NodeArrowHandles` reads to place its arrows.
|
||||
// Mirrors skylight's renderer; geometry comes from `geometry.ts` in
|
||||
// chimney-local frame (no transform baking) and lands in the right
|
||||
// world spot via the two-group stack below.
|
||||
return (
|
||||
<group
|
||||
position={segment.position}
|
||||
ref={ref}
|
||||
rotation-y={segment.rotation}
|
||||
visible={node.visible}
|
||||
{...handlers}
|
||||
>
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={trimmedBody ?? geo.body}
|
||||
material={surfaceArray}
|
||||
name="chimney-body"
|
||||
receiveShadow
|
||||
/>
|
||||
{geo.cap && (
|
||||
<group
|
||||
position={[node.position[0] ?? 0, 0, node.position[2] ?? 0]}
|
||||
ref={ref}
|
||||
rotation-y={node.rotation ?? 0}
|
||||
>
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.cap}
|
||||
geometry={trimmedBody ?? geo.body}
|
||||
material={surfaceArray}
|
||||
name="chimney-cap"
|
||||
name="chimney-body"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.flues && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.flues}
|
||||
material={surfaceArray}
|
||||
name="chimney-flues"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.cricket && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.cricket}
|
||||
material={surfaceMaterial}
|
||||
name="chimney-cricket"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.bands && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.bands}
|
||||
material={surfaceMaterial}
|
||||
name="chimney-bands"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.cap && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.cap}
|
||||
material={surfaceArray}
|
||||
name="chimney-cap"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.flues && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.flues}
|
||||
material={surfaceArray}
|
||||
name="chimney-flues"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.cricket && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.cricket}
|
||||
material={surfaceMaterial}
|
||||
name="chimney-cricket"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
{geo.bands && (
|
||||
<mesh
|
||||
castShadow
|
||||
geometry={geo.bands}
|
||||
material={surfaceMaterial}
|
||||
name="chimney-bands"
|
||||
receiveShadow
|
||||
/>
|
||||
)}
|
||||
</group>
|
||||
</group>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -40,12 +40,21 @@ export function trimChimneyBodyAgainstRoof(
|
||||
): THREE.BufferGeometry {
|
||||
const { shinSlab, wallBrush } = segBrushes
|
||||
|
||||
// Wrap the chimney body in a Brush. The body has `node.position` /
|
||||
// `node.rotation` baked into its vertices via `applyNodeTransform`
|
||||
// in `geometry.ts`, so it's already in segment-local space — the
|
||||
// same frame as the roof brushes from `getRoofSegmentBrushes`.
|
||||
// The body comes in chimney-local frame — `node.position` /
|
||||
// `node.rotation` are applied by the renderer's nested ref'd group
|
||||
// rather than baked into the geometry. Segment brushes from
|
||||
// `getRoofSegmentBrushes` are in segment-local frame, so we move the
|
||||
// chimney brush into segment-local space for the CSG pass, then strip
|
||||
// the same transform back off the result before returning, so the
|
||||
// mesh stays in chimney-local for the renderer to position via the
|
||||
// inner ref group.
|
||||
const indexed = mergeVertices(body, 1e-4)
|
||||
if (!indexed.getAttribute('normal')) indexed.computeVertexNormals()
|
||||
const hasRotation = Math.abs(node.rotation) > 1e-4
|
||||
const posX = node.position[0] ?? 0
|
||||
const posZ = node.position[2] ?? 0
|
||||
if (hasRotation) indexed.rotateY(node.rotation)
|
||||
indexed.translate(posX, 0, posZ)
|
||||
const indexCount = indexed.getIndex()?.count ?? 0
|
||||
indexed.clearGroups()
|
||||
if (indexCount > 0) indexed.addGroup(0, indexCount, 0)
|
||||
@@ -70,6 +79,11 @@ export function trimChimneyBodyAgainstRoof(
|
||||
const step2 = csgEvaluator.evaluate(step1, shinSlab, SUBTRACTION) as Brush
|
||||
|
||||
const out = csgGeometry(step2).clone()
|
||||
// Strip the same node transform we baked onto the input so the
|
||||
// returned geometry is back in chimney-local frame (the renderer's
|
||||
// inner ref'd group applies `node.position` / `node.rotation`).
|
||||
out.translate(-posX, 0, -posZ)
|
||||
if (hasRotation) out.rotateY(-node.rotation)
|
||||
const ic = out.getIndex()?.count ?? 0
|
||||
out.clearGroups()
|
||||
if (ic > 0) out.addGroup(0, ic, 0)
|
||||
|
||||
@@ -14,7 +14,7 @@ import { triggerSFX } from '@pascal-app/editor'
|
||||
import { useViewer } from '@pascal-app/viewer'
|
||||
import { useEffect, useMemo, useRef, useState } from 'react'
|
||||
import * as THREE from 'three'
|
||||
import { resolveRoofSegmentHit } from '../roof/segment-hit'
|
||||
import { resolveRoofSegmentHit } from '../shared/roof-segment-hit'
|
||||
import { chimneyDefinition } from './definition'
|
||||
import ChimneyPreview from './preview'
|
||||
|
||||
|
||||
Reference in New Issue
Block a user