* 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 * feat(duct): ceiling-snap drawing + connected-joint endpoint move Duct draw tool's ceiling mode now hangs each path point just below the ceiling actually covering it (per-room heights tracked), with a translucent surface highlight and a plumb line to the floor so the in-flight point reads clearly from any angle. Dragging a duct corner that sits on a fitting now carries the fitting's other ducts along (port-connectivity second hop), so the joint moves together instead of tearing apart. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): detach + vertical modifiers for duct/pipe joint editing Alt detaches a dragged duct/pipe endpoint or fitting from its connected joint (no elbow re-aim, no connectivity follow); Ctrl/Cmd drives vertical riser movement on the fitting move. Behavioral parity across 2D and 3D. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): full DWV pipe parity for joint editing Bring pipe-segment endpoint drags and pipe-fitting moves to parity with duct: free-drag endpoints, Alt-detach, Ctrl/Cmd-vertical riser, elbow re-aim, and connectivity follow. Generalizes the shared elbow-reaim and auto-fitting helpers to dispatch by run kind so 2D and 3D share one path. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): wall-style arrow handles for duct fittings + segments Add violet directional arrow affordances to duct-fitting selection (height, move cross, rotate arc) mirroring the duct-segment rig: portaled into the parent frame to stay out of the selection outline, rendered via the shared HandleArrow, and carrying mated-run connectivity through the single-undo dance. The move cross engages press-drag-release (placementDragMode) the same way the floating drag does, so the markup hit-areas go inert and the fitting move tool commits on pointer-up. Also re-export the HandleArrow primitives from @pascal-app/editor and extend the duct-segment side-move/floorplan affordances. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): click-to-latch cube handles for duct + fitting editing Replace the hover-reveal / multi-handle selection rigs with a single click-to-latch cube that opens a directional cluster, shared between duct segments and fittings via a new selection-handles module (HandleCube / MoveChevron / RotateArc, all sized to the roof pitch cube). - Duct segment: per-vertex + run-center cubes reveal axis-locked move chevrons (down arrow always shown), plus a roll arc at the run center. - Duct fitting: center cube reveals six ±XYZ move arrows and three per-axis rotation arcs (oriented in place), replacing the old height/move/rotate trio with axis-cycling. - Rotation (fitting arcs + duct roll) snaps to 45° steps; Shift = smooth. - thin chevron profile + press-drag-release commit retained. * fix(mep): orient duct roll arc consistently + drop Ctrl-vertical drag Build a fully-determined basis for the duct roll gizmo so the curved arrow always seats at the top-outer 45° corner regardless of run direction, instead of an arbitrary apex from a single setFromUnitVectors. The selection-rig ±Y arrows now own vertical movement, so the redundant Ctrl-modifier riser drag is removed from the fitting move tool. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): run-aligned duct handles, swing snapping, elbow flatten Align the duct run-center cube + horizontal arrows to the run axis (matching the per-vertex handles) while keeping whole-run translate. Endpoint side / up-down swing arrows now follow grid snap points and port-snap onto nearby collars (Shift sweeps smoothly). Relax elbow realign + fitting schemas to flatten to a straight 0° coupling. Surface HVAC-specific hints in the select-mode helper panel for duct / fitting. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): per-segment linesets/liquid-lines with joint-follow editing Linesets and liquid lines now commit one independent two-point node per drawn segment instead of folding into a single mitered polyline, so each line selects and deletes on its own. Endpoint caps fill shared-coordinate joints so connected segments still read as continuous pipe. Dragging a shared endpoint carries mated segments along via port connectivity (Alt detaches), so a run still edits as one welded piece. Liquid-line follow mode traces the whole connected lineset run, laying a per-segment parallel line down its full assembled length. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * feat(mep): vertical-offset auto-routing on duct center-cube ±Y drag Lifting/lowering a connected run with the run-center cube now keeps each connected end welded to its stationary partner instead of dragging the whole network. Run-to-run ends get the classic S/Z offset (two elbows + plumb riser, partner trimmed back one leg); elbow-connected ends form a clean L — the existing elbow stays put and re-aims its collar vertical, with one new top elbow + riser reconnecting to the lifted endpoint. The offset is ghosted live and minted as a single undo step on release. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com> * Add roof accessory placement guides Measure roof accessory placement against the active roof face using visible surface bounds and preview geometry footprints. Add dormer-local guides and special linear handling for ridge vents and gutters. * Improve duct and placement routing * Fix duct vertical movement routing * Fix duct vertical offsets and roof accessory movement * Add DWV movement parity and line endpoint controls * Fix MEP handle review issues * Fix chimney placement and duct offset cleanup * Use snapped targets for roof accessory commits * fix(nodes): repair MEP movement review issues - auto-fitting: tee branch now follows the drawn lateral angle; update the stale square-tee test + doc comment that contradicted the rewrite - duct-segment: re-enable the vertical auto-offset rewind (the disabled stub left mintedIds empty, so re-dragging a tagged duct stranded old elbows/risers and stacked duplicates); remove the dead stub - duct-segment: strip the stale auto-offset tag on manual corner/roll commits so the horizontal-move path no longer trusts an out-of-date base - chimney: resume history before mutating segment children arrays so a cross-segment move reparents in one tracked transaction (undo stays consistent) - dormer: align schema test with the new windowSill=false default * fix: address mep movement review issues * fix: address follow-up mep review comments * fix: address additional mep review comments --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: pascal-open-bot <open@pascal.app>
184 lines
7.1 KiB
TypeScript
184 lines
7.1 KiB
TypeScript
import type { AnyNode, AnyNodeId, DuctFittingNode, PipeFittingNode } from '@pascal-app/core'
|
|
import { getDuctFittingPorts } from '../duct-fitting/ports'
|
|
import { getPipeFittingPorts } from '../pipe-fitting/ports'
|
|
import { planElbowRealign, planPipeElbowRealign, planTeeBranchRealign } from './auto-fitting'
|
|
|
|
/**
|
|
* Shared "drag a run end, the connected fitting re-aims" logic for the
|
|
* selection-time endpoint drag — duct (`duct-segment`) and DWV pipe
|
|
* (`pipe-segment`) alike, plus their 2D `move-path-point` twins.
|
|
*
|
|
* Two re-aim shapes share this path:
|
|
*
|
|
* - **Elbow** (duct + pipe): when you grab the free end of a straight run
|
|
* whose OTHER end sits on an elbow collar, the elbow's junction and far
|
|
* (mated) collar stay put while the near collar swings to face the
|
|
* dragged end — the bend `angle` adjusts to fit. Mirrors a wall corner.
|
|
*
|
|
* - **Tee branch** (duct only): when you grab the free end of a run mated
|
|
* to a tee's BRANCH collar, the tee's run legs stay locked to the trunk
|
|
* and only its `branchAngle` swings, so the branch keeps pointing at the
|
|
* dragged end.
|
|
*
|
|
* Detection runs ONCE at drag start (`detectFittingEndpoint`) against a
|
|
* snapshot of the fitting; the per-frame plan (`planFittingEndpointReaim`)
|
|
* always re-derives from that original snapshot, so live mutation of the
|
|
* fitting never compounds.
|
|
*/
|
|
|
|
type Point = [number, number, number]
|
|
|
|
/** Distance (m) under which a run end counts as sitting on a fitting collar —
|
|
* matches core's port-coincidence epsilon. */
|
|
const COINCIDENT_EPS_M = 0.05
|
|
|
|
/** Which run kind we're editing decides which fitting kind to look for. */
|
|
type ReaimFitting = DuctFittingNode | PipeFittingNode
|
|
|
|
export type FittingEndpoint = {
|
|
/** The fitting node as it stood at drag start (the stable reference). */
|
|
fitting: ReaimFitting
|
|
/** Whether the re-aim re-orients the whole elbow body or just swings a
|
|
* duct tee's branch lean. */
|
|
reaim: 'elbow' | 'tee-branch'
|
|
/** Which fitting collar the run's non-dragged end is mated to. */
|
|
portId: 'inlet' | 'outlet' | 'branch'
|
|
/** The fitting kind, so the per-frame plan calls the right realign. */
|
|
fittingType: 'duct-fitting' | 'pipe-fitting'
|
|
/** Patch that restores the fitting to its drag-start state, for the
|
|
* single-undo dance's pre-resume revert. */
|
|
revert: { id: AnyNodeId; data: Partial<AnyNode> }
|
|
}
|
|
|
|
export type FittingEndpointReaimPlan = {
|
|
/** New path for the dragged run: the dragged end at the cursor, the
|
|
* fitting end pulled onto the re-aimed collar. */
|
|
path: Point[]
|
|
/** Patch re-aiming the fitting (elbow: angle + rotation; tee: branchAngle). */
|
|
fittingUpdate: { id: AnyNodeId; data: Partial<AnyNode> }
|
|
}
|
|
|
|
/** A run kind ('duct-segment' / 'pipe-segment') → the fitting kind it
|
|
* mates to. Anything else has no re-aim. */
|
|
function fittingTypeForRun(runKind: string): 'duct-fitting' | 'pipe-fitting' | null {
|
|
if (runKind === 'duct-segment') return 'duct-fitting'
|
|
if (runKind === 'pipe-segment') return 'pipe-fitting'
|
|
return null
|
|
}
|
|
|
|
function distSq(a: Point | readonly number[], b: Point | readonly number[]): number {
|
|
const dx = a[0]! - b[0]!
|
|
const dy = a[1]! - b[1]!
|
|
const dz = a[2]! - b[2]!
|
|
return dx * dx + dy * dy + dz * dz
|
|
}
|
|
|
|
/**
|
|
* If `runPath` is a straight two-point run whose NON-dragged end sits on a
|
|
* fitting collar that can re-aim, return that fitting snapshot + the mated
|
|
* port id and re-aim shape. `runKind` selects which fitting kind to scan
|
|
* for. Elbow inlet/outlet collars re-aim the whole elbow; a duct tee's
|
|
* branch collar swings only the branch. Otherwise null — the caller falls
|
|
* back to plain free-drag.
|
|
*/
|
|
export function detectFittingEndpoint(
|
|
runKind: string,
|
|
runPath: ReadonlyArray<readonly [number, number, number]>,
|
|
draggedIndex: number,
|
|
nodes: Record<string, AnyNode>,
|
|
): FittingEndpoint | null {
|
|
if (runPath.length !== 2) return null
|
|
const fittingType = fittingTypeForRun(runKind)
|
|
if (!fittingType) return null
|
|
const fittingEnd = runPath[draggedIndex === 0 ? 1 : 0]!
|
|
const eps2 = COINCIDENT_EPS_M * COINCIDENT_EPS_M
|
|
for (const node of Object.values(nodes)) {
|
|
if (!node || node.type !== fittingType) continue
|
|
const fitting = node as ReaimFitting
|
|
const isElbow = fitting.fittingType === 'elbow'
|
|
// Tee-branch re-aim is duct-only (a sanitary tee has no adjustable
|
|
// branch lean).
|
|
const isDuctTee = fittingType === 'duct-fitting' && fitting.fittingType === 'tee'
|
|
if (!isElbow && !isDuctTee) continue
|
|
const ports =
|
|
fittingType === 'duct-fitting'
|
|
? getDuctFittingPorts(fitting as DuctFittingNode)
|
|
: getPipeFittingPorts(fitting as PipeFittingNode)
|
|
for (const port of ports) {
|
|
if (isElbow && port.id !== 'inlet' && port.id !== 'outlet') continue
|
|
if (isDuctTee && port.id !== 'branch') continue
|
|
if (distSq(port.position, fittingEnd) > eps2) continue
|
|
if (isElbow) {
|
|
return {
|
|
fitting,
|
|
reaim: 'elbow',
|
|
portId: port.id as 'inlet' | 'outlet',
|
|
fittingType,
|
|
revert: {
|
|
id: fitting.id as AnyNodeId,
|
|
data: { angle: fitting.angle, rotation: fitting.rotation } as Partial<AnyNode>,
|
|
},
|
|
}
|
|
}
|
|
return {
|
|
fitting,
|
|
reaim: 'tee-branch',
|
|
portId: 'branch',
|
|
fittingType,
|
|
revert: {
|
|
id: fitting.id as AnyNodeId,
|
|
data: { branchAngle: (fitting as DuctFittingNode).branchAngle } as Partial<AnyNode>,
|
|
},
|
|
}
|
|
}
|
|
}
|
|
return null
|
|
}
|
|
|
|
/**
|
|
* Plan the run path + fitting re-aim for the dragged end at `draggedPoint`.
|
|
* The fitting swings its mated collar to face the junction→cursor direction;
|
|
* the run goes from that collar to the cursor. Returns null when the
|
|
* required turn falls outside the fitting's buildable range (caller keeps
|
|
* the plain free-drag for that frame).
|
|
*/
|
|
export function planFittingEndpointReaim(
|
|
endpoint: FittingEndpoint,
|
|
draggedIndex: number,
|
|
draggedPoint: Point,
|
|
): FittingEndpointReaimPlan | null {
|
|
const { fitting, reaim, portId, fittingType } = endpoint
|
|
const j = fitting.position
|
|
const away: Point = [draggedPoint[0] - j[0], draggedPoint[1] - j[1], draggedPoint[2] - j[2]]
|
|
if (away[0] * away[0] + away[1] * away[1] + away[2] * away[2] < 1e-10) return null
|
|
|
|
if (reaim === 'tee-branch') {
|
|
const realign = planTeeBranchRealign(fitting as DuctFittingNode, away)
|
|
if (!realign) return null
|
|
const path: Point[] =
|
|
draggedIndex === 0 ? [draggedPoint, realign.collarPoint] : [realign.collarPoint, draggedPoint]
|
|
return {
|
|
path,
|
|
fittingUpdate: {
|
|
id: realign.update.id as AnyNodeId,
|
|
data: realign.update.data as Partial<AnyNode>,
|
|
},
|
|
}
|
|
}
|
|
|
|
const realign =
|
|
fittingType === 'duct-fitting'
|
|
? planElbowRealign(fitting as DuctFittingNode, portId, away)
|
|
: planPipeElbowRealign(fitting as PipeFittingNode, portId, away)
|
|
if (!realign) return null
|
|
const path: Point[] =
|
|
draggedIndex === 0 ? [draggedPoint, realign.collarPoint] : [realign.collarPoint, draggedPoint]
|
|
return {
|
|
path,
|
|
fittingUpdate: {
|
|
id: realign.update.id as AnyNodeId,
|
|
data: realign.update.data as Partial<AnyNode>,
|
|
},
|
|
}
|
|
}
|