@kruschdev/pascal-plugin-plumbing 0.0.0-stage → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +123 -2
- package/docs/AGENT-TOOLS.md +12 -0
- package/docs/ARCHITECTURE.md +15 -0
- package/docs/CAD-CATALOG.md +10 -0
- package/docs/IPC-REFERENCE.md +17 -0
- package/package.json +89 -4
- package/src/agent-operations.ts +842 -0
- package/src/agent-tools.ts +257 -0
- package/src/cad/catalog.ts +151 -0
- package/src/cad/equipment.ts +172 -0
- package/src/cad/fittings.ts +304 -0
- package/src/cad/fixtures.ts +255 -0
- package/src/cad/index.ts +6 -0
- package/src/cad/manifold-interior.ts +249 -0
- package/src/cad/materials.ts +122 -0
- package/src/index.ts +153 -0
- package/src/ipc/audit.ts +829 -0
- package/src/ipc/autopopulate.ts +4555 -0
- package/src/ipc/framing-interop.ts +842 -0
- package/src/ipc/index.ts +9 -0
- package/src/ipc/pricing.ts +473 -0
- package/src/ipc/routing.ts +2280 -0
- package/src/ipc/rules.ts +271 -0
- package/src/ipc/schedule.ts +630 -0
- package/src/ipc/sizing.ts +523 -0
- package/src/ipc/tables.ts +777 -0
- package/src/nodes/equipment.ts +330 -0
- package/src/nodes/fixture.ts +245 -0
- package/src/nodes/manifold.ts +194 -0
- package/src/nodes/parametrics.ts +94 -0
- package/src/nodes/pipe-run.ts +342 -0
- package/src/render.ts +64 -0
- package/src/ui/chat-card.tsx +157 -0
- package/src/ui/inspector-card.tsx +211 -0
- package/src/ui/manifold-cutaway-view.tsx +270 -0
- package/src/ui/plumbing-panel.tsx +810 -0
- package/src/ui/schedule-view.tsx +523 -0
- package/src/ui/store.ts +115 -0
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Persisted ChatToolCard for `krusch:plumbing` (`PluginChatExtension`).
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import type { ChatToolCardProps } from '@pascal-app/editor'
|
|
8
|
+
import { PLUMBING_SCHEDULE_VIEW_ID } from './plumbing-panel'
|
|
9
|
+
|
|
10
|
+
export default function PlumbingChatCard({ toolName, output, state, actions }: ChatToolCardProps) {
|
|
11
|
+
const data = output?.data as Record<string, unknown> | undefined
|
|
12
|
+
const rawFindings =
|
|
13
|
+
data?.findings ?? (data?.audit as { findings?: unknown } | undefined)?.findings
|
|
14
|
+
const findings = Array.isArray(rawFindings)
|
|
15
|
+
? (rawFindings as Array<{ id: string; title: string; codeRef: string; nodeIds?: string[] }>)
|
|
16
|
+
: []
|
|
17
|
+
const scheduleObj = data?.schedule as
|
|
18
|
+
| {
|
|
19
|
+
fixtures?: unknown[]
|
|
20
|
+
loads?: { totalDfu?: number; peakDemandGpm?: number; recommendedBuildingDrain?: string }
|
|
21
|
+
}
|
|
22
|
+
| undefined
|
|
23
|
+
const loadsObj = (data?.loads ?? scheduleObj?.loads) as
|
|
24
|
+
| {
|
|
25
|
+
totalDfu?: number
|
|
26
|
+
totalWsfu?: number
|
|
27
|
+
peakDemandGpm?: number
|
|
28
|
+
recommendedBuildingDrain?: string
|
|
29
|
+
recommendedVentStack?: string
|
|
30
|
+
}
|
|
31
|
+
| undefined
|
|
32
|
+
const autoSummary = typeof data?.summary === 'string' ? data.summary : null
|
|
33
|
+
const bomObj = data?.bom as { grandTotalUsd?: number; totalLaborHours?: number } | undefined
|
|
34
|
+
const penetrations = Array.isArray(data?.penetrations) ? data.penetrations : null
|
|
35
|
+
const routedNodeId = typeof data?.nodeId === 'string' ? data.nodeId : null
|
|
36
|
+
const lengthFt = typeof data?.lengthFt === 'number' ? data.lengthFt : null
|
|
37
|
+
const slopeInPerFt = typeof data?.slopeInPerFt === 'number' ? data.slopeInPerFt : null
|
|
38
|
+
const showSlope =
|
|
39
|
+
slopeInPerFt !== null && (slopeInPerFt !== 0 || data?.system === 'dwv-drain')
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<div
|
|
43
|
+
style={{
|
|
44
|
+
padding: 10,
|
|
45
|
+
borderRadius: 8,
|
|
46
|
+
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
47
|
+
fontSize: 12,
|
|
48
|
+
display: 'flex',
|
|
49
|
+
flexDirection: 'column',
|
|
50
|
+
gap: 6,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', fontWeight: 600 }}>
|
|
54
|
+
<span>{toolName}</span>
|
|
55
|
+
<span style={{ fontSize: 11, opacity: 0.75 }}>{state}</span>
|
|
56
|
+
</div>
|
|
57
|
+
{output?.text && <div style={{ opacity: 0.85 }}>{output.text}</div>}
|
|
58
|
+
|
|
59
|
+
{/* Summary for plumbing_autopopulate */}
|
|
60
|
+
{autoSummary && (
|
|
61
|
+
<div style={{ fontSize: 11, opacity: 0.9 }}>
|
|
62
|
+
<strong>Auto-Populate:</strong> {autoSummary}
|
|
63
|
+
</div>
|
|
64
|
+
)}
|
|
65
|
+
|
|
66
|
+
{/* Summary for plumbing_calculate_loads */}
|
|
67
|
+
{!scheduleObj && loadsObj && (
|
|
68
|
+
<div style={{ fontSize: 11 }}>
|
|
69
|
+
<strong>Loads:</strong> {loadsObj.totalDfu ?? 0} DFU · {loadsObj.totalWsfu ?? 0} WSFU ({loadsObj.peakDemandGpm ?? 0} GPM) · Drain{' '}
|
|
70
|
+
{loadsObj.recommendedBuildingDrain ?? '-'} · Stack {loadsObj.recommendedVentStack ?? '-'}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
|
|
74
|
+
{/* Summary for plumbing_generate_schedule */}
|
|
75
|
+
{(scheduleObj || bomObj) && (
|
|
76
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 3, fontSize: 11 }}>
|
|
77
|
+
{scheduleObj?.loads && (
|
|
78
|
+
<div>
|
|
79
|
+
<strong>Schedule:</strong> {scheduleObj.fixtures?.length ?? 0} fixtures · {scheduleObj.loads.totalDfu ?? 0} DFU ·{' '}
|
|
80
|
+
{scheduleObj.loads.peakDemandGpm ?? 0} GPM · Drain {scheduleObj.loads.recommendedBuildingDrain ?? '-'}
|
|
81
|
+
</div>
|
|
82
|
+
)}
|
|
83
|
+
{bomObj && typeof bomObj.grandTotalUsd === 'number' && (
|
|
84
|
+
<div>
|
|
85
|
+
<strong>Estimated BOM:</strong> ${bomObj.grandTotalUsd.toLocaleString(undefined, { minimumFractionDigits: 2 })} (
|
|
86
|
+
{bomObj.totalLaborHours ?? 0} labor hrs)
|
|
87
|
+
</div>
|
|
88
|
+
)}
|
|
89
|
+
{penetrations && (
|
|
90
|
+
<div>
|
|
91
|
+
<strong>Framing Drill List:</strong> {penetrations.length} stud/plate penetration(s)
|
|
92
|
+
</div>
|
|
93
|
+
)}
|
|
94
|
+
</div>
|
|
95
|
+
)}
|
|
96
|
+
|
|
97
|
+
{/* Summary for plumbing_route_pipe */}
|
|
98
|
+
{lengthFt !== null && (
|
|
99
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', fontSize: 11 }}>
|
|
100
|
+
<span>
|
|
101
|
+
<strong>Routed Pipe:</strong> {lengthFt} ft
|
|
102
|
+
{showSlope && (
|
|
103
|
+
<span style={slopeInPerFt! <= 0 ? { color: '#ef4444', fontWeight: 600 } : undefined}>
|
|
104
|
+
{` · ${slopeInPerFt}"/ft slope`}
|
|
105
|
+
</span>
|
|
106
|
+
)}
|
|
107
|
+
{penetrations ? ` · ${penetrations.length} bore(s)` : ''}
|
|
108
|
+
</span>
|
|
109
|
+
{routedNodeId && (
|
|
110
|
+
<button
|
|
111
|
+
type="button"
|
|
112
|
+
onClick={() => actions.select([routedNodeId])}
|
|
113
|
+
style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
|
|
114
|
+
>
|
|
115
|
+
Select
|
|
116
|
+
</button>
|
|
117
|
+
)}
|
|
118
|
+
</div>
|
|
119
|
+
)}
|
|
120
|
+
|
|
121
|
+
{/* Summary for plumbing_audit_ipc */}
|
|
122
|
+
{findings.slice(0, 4).map((f) => (
|
|
123
|
+
<div key={f.id} style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11 }}>
|
|
124
|
+
<span>
|
|
125
|
+
<strong>{f.codeRef}</strong>: {f.title}
|
|
126
|
+
</span>
|
|
127
|
+
{f.nodeIds && f.nodeIds.length > 0 && (
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
onClick={() => actions.select(f.nodeIds!)}
|
|
131
|
+
style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
|
|
132
|
+
>
|
|
133
|
+
Select
|
|
134
|
+
</button>
|
|
135
|
+
)}
|
|
136
|
+
</div>
|
|
137
|
+
))}
|
|
138
|
+
<div style={{ display: 'flex', gap: 8, marginTop: 4 }}>
|
|
139
|
+
<button
|
|
140
|
+
type="button"
|
|
141
|
+
onClick={() => actions.openView(PLUMBING_SCHEDULE_VIEW_ID, { beside: true })}
|
|
142
|
+
style={{
|
|
143
|
+
padding: '4px 8px',
|
|
144
|
+
borderRadius: 5,
|
|
145
|
+
border: '1px solid rgba(37,99,235,0.55)',
|
|
146
|
+
background: 'rgba(37,99,235,0.18)',
|
|
147
|
+
color: 'inherit',
|
|
148
|
+
cursor: 'pointer',
|
|
149
|
+
fontSize: 11,
|
|
150
|
+
}}
|
|
151
|
+
>
|
|
152
|
+
Open Plumbing Schedule
|
|
153
|
+
</button>
|
|
154
|
+
</div>
|
|
155
|
+
</div>
|
|
156
|
+
)
|
|
157
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* InspectorExtension card for `plumbing:*` nodes:
|
|
5
|
+
* Shows live NOT TO CODE / COMPLIANT status, DFU/WSFU/slope/velocity/framing-penetration metrics,
|
|
6
|
+
* and cross-trade Electrical Power Demand info.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import type { AnyNode } from '@pascal-app/core'
|
|
10
|
+
import { openEditorView, useScene } from '@pascal-app/editor'
|
|
11
|
+
import { useMemo } from 'react'
|
|
12
|
+
import { auditScenePlumbing } from '../ipc/audit'
|
|
13
|
+
import {
|
|
14
|
+
type SceneNodeLike,
|
|
15
|
+
type Vec3,
|
|
16
|
+
computePipeFramingPenetrations,
|
|
17
|
+
extractBonesPlumbingContext,
|
|
18
|
+
resolveNodeLevelId,
|
|
19
|
+
} from '../ipc/framing-interop'
|
|
20
|
+
import { extractWallSegments, measureDrainPathSlope, polylineLengthM } from '../ipc/routing'
|
|
21
|
+
import { resolveNodeElectricalDemand } from '../ipc/schedule'
|
|
22
|
+
import { METERS_TO_FEET, type PipeMaterial, type PipeNominalSize, round2 } from '../ipc/tables'
|
|
23
|
+
import { PLUMBING_SCHEDULE_VIEW_ID } from './plumbing-panel'
|
|
24
|
+
import { usePlumbingUi } from './store'
|
|
25
|
+
|
|
26
|
+
export default function PlumbingInspectorCard({ node }: { node?: AnyNode }) {
|
|
27
|
+
const nodes = useScene((s) => s.nodes) as unknown as Readonly<Record<string, SceneNodeLike>>
|
|
28
|
+
const codeEdition = usePlumbingUi((s) => s.codeEdition)
|
|
29
|
+
const occupancy = usePlumbingUi((s) => s.occupancy)
|
|
30
|
+
const setActiveTab = usePlumbingUi((s) => s.setActiveTab)
|
|
31
|
+
const setSelectedManifoldId = usePlumbingUi((s) => s.setSelectedManifoldId)
|
|
32
|
+
|
|
33
|
+
const raw = node as unknown as SceneNodeLike | undefined
|
|
34
|
+
const audit = useMemo(
|
|
35
|
+
() => (raw ? auditScenePlumbing(nodes, { codeEdition, occupancy }) : null),
|
|
36
|
+
[raw, nodes, codeEdition, occupancy],
|
|
37
|
+
)
|
|
38
|
+
const nodeFindings = useMemo(
|
|
39
|
+
() => (raw && audit ? audit.findings.filter((f) => f.nodeIds.includes(raw.id)) : []),
|
|
40
|
+
[audit, raw],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
const pipeMetrics = useMemo(() => {
|
|
44
|
+
if (!raw || raw.type !== 'plumbing:pipe-run' || !Array.isArray(raw.path)) return null
|
|
45
|
+
const path = raw.path as ReadonlyArray<Vec3>
|
|
46
|
+
const lengthFt = round2(polylineLengthM(path) * METERS_TO_FEET)
|
|
47
|
+
const slope = raw.system === 'dwv-drain' ? measureDrainPathSlope(path) : null
|
|
48
|
+
const lvlId = resolveNodeLevelId(nodes, raw)
|
|
49
|
+
const walls = extractWallSegments(nodes, lvlId)
|
|
50
|
+
const bones = extractBonesPlumbingContext(nodes, lvlId)
|
|
51
|
+
const pens = computePipeFramingPenetrations({
|
|
52
|
+
pipeRunId: raw.id,
|
|
53
|
+
path,
|
|
54
|
+
pipeSize: (raw.nominalSize as PipeNominalSize) || '1/2"',
|
|
55
|
+
material: (raw.material as PipeMaterial) || 'pex-a',
|
|
56
|
+
walls,
|
|
57
|
+
bonesContext: bones,
|
|
58
|
+
})
|
|
59
|
+
return { lengthFt, slope, pens }
|
|
60
|
+
}, [nodes, raw])
|
|
61
|
+
|
|
62
|
+
if (!raw) return null
|
|
63
|
+
|
|
64
|
+
const openTab = (tab: 'audit' | 'penetrations' | 'manifold') => {
|
|
65
|
+
setActiveTab(tab)
|
|
66
|
+
openEditorView(PLUMBING_SCHEDULE_VIEW_ID, { beside: true })
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const demand = resolveNodeElectricalDemand(raw)
|
|
70
|
+
|
|
71
|
+
return (
|
|
72
|
+
<div style={{ padding: 10, display: 'flex', flexDirection: 'column', gap: 6, fontSize: 12 }}>
|
|
73
|
+
<div
|
|
74
|
+
style={{
|
|
75
|
+
padding: '6px 8px',
|
|
76
|
+
borderRadius: 6,
|
|
77
|
+
background: nodeFindings.some((f) => f.severity === 'error')
|
|
78
|
+
? 'rgba(239,68,68,0.18)'
|
|
79
|
+
: nodeFindings.length > 0
|
|
80
|
+
? 'rgba(245,158,11,0.18)'
|
|
81
|
+
: 'rgba(34,197,94,0.15)',
|
|
82
|
+
border: `1px solid ${
|
|
83
|
+
nodeFindings.some((f) => f.severity === 'error')
|
|
84
|
+
? '#ef4444'
|
|
85
|
+
: nodeFindings.length > 0
|
|
86
|
+
? '#f59e0b'
|
|
87
|
+
: '#22c55e'
|
|
88
|
+
}`,
|
|
89
|
+
display: 'flex',
|
|
90
|
+
justifyContent: 'space-between',
|
|
91
|
+
alignItems: 'center',
|
|
92
|
+
fontWeight: 600,
|
|
93
|
+
fontSize: 11,
|
|
94
|
+
}}
|
|
95
|
+
>
|
|
96
|
+
<span>
|
|
97
|
+
{nodeFindings.some((f) => f.severity === 'error')
|
|
98
|
+
? `NOT TO CODE (${nodeFindings.length})`
|
|
99
|
+
: nodeFindings.length > 0
|
|
100
|
+
? `WARNINGS (${nodeFindings.length})`
|
|
101
|
+
: `${codeEdition} COMPLIANT`}
|
|
102
|
+
</span>
|
|
103
|
+
<button
|
|
104
|
+
type="button"
|
|
105
|
+
onClick={() => openTab('audit')}
|
|
106
|
+
style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
|
|
107
|
+
>
|
|
108
|
+
Audit
|
|
109
|
+
</button>
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
{pipeMetrics && (
|
|
113
|
+
<>
|
|
114
|
+
<Row label="System / Size" value={`${String(raw.system)} · ${String(raw.nominalSize)} ${String(raw.material)}`} />
|
|
115
|
+
<Row label="Run Length" value={`${pipeMetrics.lengthFt} ft`} />
|
|
116
|
+
{pipeMetrics.slope && (
|
|
117
|
+
<Row
|
|
118
|
+
label="Measured DWV Slope"
|
|
119
|
+
value={`${pipeMetrics.slope.overallSlopeInPerFt}"/ft`}
|
|
120
|
+
warn={pipeMetrics.slope.hasUphillSegment}
|
|
121
|
+
/>
|
|
122
|
+
)}
|
|
123
|
+
<Row label="Framing Penetrations" value={`${pipeMetrics.pens.length} stud/plate bore(s)`} />
|
|
124
|
+
{pipeMetrics.pens.length > 0 && (
|
|
125
|
+
<button type="button" onClick={() => openTab('penetrations')} style={linkBtnStyle}>
|
|
126
|
+
View Drill Schedule & Hole-Saw Sizes
|
|
127
|
+
</button>
|
|
128
|
+
)}
|
|
129
|
+
</>
|
|
130
|
+
)}
|
|
131
|
+
|
|
132
|
+
{raw.type === 'plumbing:fixture' && (
|
|
133
|
+
<>
|
|
134
|
+
<Row label="DFU / WSFU" value={`${String(raw.dfu ?? 0)} DFU · ${String(raw.wsfuTotal ?? 0)} WSFU`} />
|
|
135
|
+
<Row label="Drain / Vent / Supply" value={`${String(raw.drainSize ?? '-')} / ${String(raw.ventSize ?? '-')} / ${String(raw.supplySize ?? '-')}`} />
|
|
136
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
137
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
138
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
139
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
140
|
+
) : null}
|
|
141
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
142
|
+
</>
|
|
143
|
+
)}
|
|
144
|
+
|
|
145
|
+
{raw.type === 'plumbing:equipment' && (
|
|
146
|
+
<>
|
|
147
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
148
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
149
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
150
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
151
|
+
) : null}
|
|
152
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
153
|
+
</>
|
|
154
|
+
)}
|
|
155
|
+
|
|
156
|
+
{raw.type === 'plumbing:manifold' && (
|
|
157
|
+
<>
|
|
158
|
+
<Row label="Manifold" value={`${String(raw.manifoldKind)} (${String(raw.portCount ?? 12)} ports)`} />
|
|
159
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
160
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
161
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
162
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
163
|
+
) : null}
|
|
164
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
165
|
+
<button
|
|
166
|
+
type="button"
|
|
167
|
+
onClick={() => {
|
|
168
|
+
setSelectedManifoldId(raw.id)
|
|
169
|
+
openTab('manifold')
|
|
170
|
+
}}
|
|
171
|
+
style={linkBtnStyle}
|
|
172
|
+
>
|
|
173
|
+
Open 3D Manifold & Wet-Wall Cutaway
|
|
174
|
+
</button>
|
|
175
|
+
</>
|
|
176
|
+
)}
|
|
177
|
+
|
|
178
|
+
{demand?.required && (
|
|
179
|
+
<div style={{ padding: 6, borderRadius: 6, background: 'rgba(245,158,11,0.12)', fontSize: 11 }}>
|
|
180
|
+
<strong>Electrical Coordination:</strong> {demand.voltage}V {demand.poles}P {demand.breakerAmps}A ({demand.loadVa} VA
|
|
181
|
+
{demand.gfciRequired ? ', GFCI' : ''})
|
|
182
|
+
</div>
|
|
183
|
+
)}
|
|
184
|
+
|
|
185
|
+
{nodeFindings.slice(0, 3).map((f) => (
|
|
186
|
+
<div key={f.id} style={{ fontSize: 11, opacity: 0.9 }}>
|
|
187
|
+
<strong>{f.codeRef}:</strong> {f.title}
|
|
188
|
+
</div>
|
|
189
|
+
))}
|
|
190
|
+
</div>
|
|
191
|
+
)
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function Row({ label, value, warn }: { label: string; value: string; warn?: boolean }) {
|
|
195
|
+
return (
|
|
196
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11 }}>
|
|
197
|
+
<span style={{ opacity: 0.78 }}>{label}</span>
|
|
198
|
+
<strong style={{ color: warn ? '#ef4444' : 'inherit' }}>{value}</strong>
|
|
199
|
+
</div>
|
|
200
|
+
)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
const linkBtnStyle = {
|
|
204
|
+
padding: '4px 8px',
|
|
205
|
+
borderRadius: 5,
|
|
206
|
+
border: '1px solid rgba(56,189,248,0.45)',
|
|
207
|
+
background: 'rgba(56,189,248,0.12)',
|
|
208
|
+
color: 'inherit',
|
|
209
|
+
cursor: 'pointer',
|
|
210
|
+
fontSize: 11,
|
|
211
|
+
}
|
|
@@ -0,0 +1,270 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Interactive 3D PEX Manifold & 2x6 Wet-Wall Framing Cutaway Viewer (`src/ui/manifold-cutaway-view.tsx`).
|
|
5
|
+
* Plumbing's signature interactive 3D cutaway view inside the split-pane Plumbing Schedule.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
9
|
+
import {
|
|
10
|
+
AmbientLight,
|
|
11
|
+
type BufferGeometry,
|
|
12
|
+
Color,
|
|
13
|
+
DirectionalLight,
|
|
14
|
+
type Group,
|
|
15
|
+
type Material,
|
|
16
|
+
type Object3D,
|
|
17
|
+
PerspectiveCamera,
|
|
18
|
+
Scene,
|
|
19
|
+
WebGLRenderer,
|
|
20
|
+
} from 'three'
|
|
21
|
+
import {
|
|
22
|
+
type ManifoldCutawayViewMode,
|
|
23
|
+
type ManifoldPortAssignment,
|
|
24
|
+
buildWiredManifoldCutawayCad,
|
|
25
|
+
} from '../cad/manifold-interior'
|
|
26
|
+
import type { ManifoldKind } from '../ipc/tables'
|
|
27
|
+
|
|
28
|
+
function disposeObject3DTree(root: Object3D): void {
|
|
29
|
+
const geometries = new Set<BufferGeometry>()
|
|
30
|
+
const materials = new Set<Material>()
|
|
31
|
+
root.traverse((obj) => {
|
|
32
|
+
const candidate = obj as Object3D & {
|
|
33
|
+
geometry?: BufferGeometry
|
|
34
|
+
material?: Material | Material[]
|
|
35
|
+
}
|
|
36
|
+
if (candidate.geometry && typeof candidate.geometry.dispose === 'function') {
|
|
37
|
+
geometries.add(candidate.geometry)
|
|
38
|
+
}
|
|
39
|
+
if (Array.isArray(candidate.material)) {
|
|
40
|
+
for (const m of candidate.material) {
|
|
41
|
+
if (m && typeof m.dispose === 'function') materials.add(m)
|
|
42
|
+
}
|
|
43
|
+
} else if (candidate.material && typeof candidate.material.dispose === 'function') {
|
|
44
|
+
materials.add(candidate.material)
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
for (const geo of geometries) geo.dispose()
|
|
48
|
+
for (const mat of materials) mat.dispose()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
type CutawayContext = {
|
|
52
|
+
scene: Scene
|
|
53
|
+
camera: PerspectiveCamera
|
|
54
|
+
renderer: WebGLRenderer
|
|
55
|
+
model: Group | null
|
|
56
|
+
rotY: number
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
export default function ManifoldCutawayView({
|
|
60
|
+
manifoldKind,
|
|
61
|
+
portCount,
|
|
62
|
+
viewMode,
|
|
63
|
+
ports,
|
|
64
|
+
onChangeViewMode,
|
|
65
|
+
}: {
|
|
66
|
+
manifoldKind: ManifoldKind
|
|
67
|
+
portCount: number
|
|
68
|
+
viewMode: ManifoldCutawayViewMode
|
|
69
|
+
ports: ReadonlyArray<ManifoldPortAssignment>
|
|
70
|
+
onChangeViewMode: (m: ManifoldCutawayViewMode) => void
|
|
71
|
+
}) {
|
|
72
|
+
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
73
|
+
const ctxRef = useRef<CutawayContext | null>(null)
|
|
74
|
+
const [webglError, setWebglError] = useState<string | null>(null)
|
|
75
|
+
|
|
76
|
+
const portsKey = useMemo(() => JSON.stringify(ports), [ports])
|
|
77
|
+
const stablePorts = useMemo(() => ports, [portsKey])
|
|
78
|
+
|
|
79
|
+
// Effect 1: Create & persist WebGLRenderer / Scene / Camera across prop updates
|
|
80
|
+
useEffect(() => {
|
|
81
|
+
const el = containerRef.current
|
|
82
|
+
if (!el) return
|
|
83
|
+
|
|
84
|
+
const width = Math.max(320, el.clientWidth || 520)
|
|
85
|
+
const height = 340
|
|
86
|
+
|
|
87
|
+
let renderer: WebGLRenderer
|
|
88
|
+
try {
|
|
89
|
+
renderer = new WebGLRenderer({ antialias: true })
|
|
90
|
+
} catch {
|
|
91
|
+
setWebglError('WebGL is unavailable in this browser context. 3D cutaway preview disabled.')
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
setWebglError(null)
|
|
95
|
+
|
|
96
|
+
const scene = new Scene()
|
|
97
|
+
scene.background = new Color(0x0f172a)
|
|
98
|
+
|
|
99
|
+
const camera = new PerspectiveCamera(42, width / height, 0.05, 20)
|
|
100
|
+
camera.position.set(0.32, 0.12, 1.95)
|
|
101
|
+
camera.lookAt(0.14, 0, 0)
|
|
102
|
+
|
|
103
|
+
renderer.setSize(width, height)
|
|
104
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2))
|
|
105
|
+
el.innerHTML = ''
|
|
106
|
+
el.appendChild(renderer.domElement)
|
|
107
|
+
|
|
108
|
+
scene.add(new AmbientLight(0xffffff, 0.85))
|
|
109
|
+
const key = new DirectionalLight(0xffffff, 1.3)
|
|
110
|
+
key.position.set(2, 3, 4)
|
|
111
|
+
scene.add(key)
|
|
112
|
+
|
|
113
|
+
const ctx: CutawayContext = {
|
|
114
|
+
scene,
|
|
115
|
+
camera,
|
|
116
|
+
renderer,
|
|
117
|
+
model: null,
|
|
118
|
+
rotY: -0.18,
|
|
119
|
+
}
|
|
120
|
+
ctxRef.current = ctx
|
|
121
|
+
|
|
122
|
+
let dragging = false
|
|
123
|
+
let prevX = 0
|
|
124
|
+
|
|
125
|
+
const onDown = (e: PointerEvent) => {
|
|
126
|
+
dragging = true
|
|
127
|
+
prevX = e.clientX
|
|
128
|
+
}
|
|
129
|
+
const onMove = (e: PointerEvent) => {
|
|
130
|
+
if (!dragging || !ctx.model) return
|
|
131
|
+
ctx.rotY += (e.clientX - prevX) * 0.01
|
|
132
|
+
prevX = e.clientX
|
|
133
|
+
ctx.model.rotation.y = ctx.rotY
|
|
134
|
+
renderer.render(scene, camera)
|
|
135
|
+
}
|
|
136
|
+
const onUpOrCancel = () => {
|
|
137
|
+
dragging = false
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
renderer.domElement.addEventListener('pointerdown', onDown)
|
|
141
|
+
window.addEventListener('pointermove', onMove)
|
|
142
|
+
window.addEventListener('pointerup', onUpOrCancel)
|
|
143
|
+
window.addEventListener('pointercancel', onUpOrCancel)
|
|
144
|
+
|
|
145
|
+
const resizeObserver =
|
|
146
|
+
typeof ResizeObserver !== 'undefined'
|
|
147
|
+
? new ResizeObserver((entries) => {
|
|
148
|
+
const nextW = Math.max(320, Math.round(entries[0]?.contentRect.width || el.clientWidth || 520))
|
|
149
|
+
camera.aspect = nextW / height
|
|
150
|
+
camera.updateProjectionMatrix()
|
|
151
|
+
renderer.setSize(nextW, height)
|
|
152
|
+
renderer.render(scene, camera)
|
|
153
|
+
})
|
|
154
|
+
: null
|
|
155
|
+
resizeObserver?.observe(el)
|
|
156
|
+
|
|
157
|
+
return () => {
|
|
158
|
+
resizeObserver?.disconnect()
|
|
159
|
+
renderer.domElement.removeEventListener('pointerdown', onDown)
|
|
160
|
+
window.removeEventListener('pointermove', onMove)
|
|
161
|
+
window.removeEventListener('pointerup', onUpOrCancel)
|
|
162
|
+
window.removeEventListener('pointercancel', onUpOrCancel)
|
|
163
|
+
if (ctx.model) {
|
|
164
|
+
scene.remove(ctx.model)
|
|
165
|
+
disposeObject3DTree(ctx.model)
|
|
166
|
+
ctx.model = null
|
|
167
|
+
}
|
|
168
|
+
scene.clear()
|
|
169
|
+
renderer.dispose()
|
|
170
|
+
renderer.forceContextLoss()
|
|
171
|
+
ctxRef.current = null
|
|
172
|
+
el.innerHTML = ''
|
|
173
|
+
}
|
|
174
|
+
}, [])
|
|
175
|
+
|
|
176
|
+
// Effect 2: Rebuild & swap ONLY the 3D manifold mesh group when parameters change
|
|
177
|
+
useEffect(() => {
|
|
178
|
+
const ctx = ctxRef.current
|
|
179
|
+
if (!ctx) return
|
|
180
|
+
|
|
181
|
+
if (ctx.model) {
|
|
182
|
+
ctx.scene.remove(ctx.model)
|
|
183
|
+
disposeObject3DTree(ctx.model)
|
|
184
|
+
ctx.model = null
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
const model = buildWiredManifoldCutawayCad({
|
|
188
|
+
manifoldKind,
|
|
189
|
+
portCount,
|
|
190
|
+
viewMode,
|
|
191
|
+
ports: stablePorts,
|
|
192
|
+
})
|
|
193
|
+
model.rotation.y = ctx.rotY
|
|
194
|
+
ctx.scene.add(model)
|
|
195
|
+
ctx.model = model
|
|
196
|
+
ctx.renderer.render(ctx.scene, ctx.camera)
|
|
197
|
+
}, [manifoldKind, portCount, viewMode, stablePorts])
|
|
198
|
+
|
|
199
|
+
const caption =
|
|
200
|
+
manifoldKind === 'gas-csst'
|
|
201
|
+
? 'Drag horizontally to orbit. Shows brass CSST fuel-gas distribution block, black-iron main feed, yellow CSST appliance branches, galvanized steel nail plates (IRC R602.6), and adjacent 3" PVC DWV stack inside a 2x6 wet wall.'
|
|
202
|
+
: manifoldKind === 'copper-header'
|
|
203
|
+
? 'Drag horizontally to orbit. Shows Type L Copper hot & cold distribution headers, brass quarter-turn isolation ball valves, galvanized steel nail plates (IRC R602.6), and adjacent 3" PVC DWV stack inside a 2x6 wet wall.'
|
|
204
|
+
: 'Drag horizontally to orbit. Shows color-coded Red Hot & Blue Cold PEX-A home-run quarter-turn ball valves, galvanized steel nail plates (IRC R602.6), and adjacent 3" PVC DWV stack inside a 2x6 wet wall.'
|
|
205
|
+
|
|
206
|
+
return (
|
|
207
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
|
208
|
+
<div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
|
|
209
|
+
<strong style={{ fontSize: 12 }}>3D Cutaway Mode:</strong>
|
|
210
|
+
{(
|
|
211
|
+
[
|
|
212
|
+
['wet-wall-cutaway', '2x6 Wet-Wall & 3" Stack Cutaway'],
|
|
213
|
+
['open-manifold', 'Manifold Cover Off'],
|
|
214
|
+
['enclosure-closed', 'Steel Enclosure Closed'],
|
|
215
|
+
] as const
|
|
216
|
+
).map(([mode, label]) => (
|
|
217
|
+
<button
|
|
218
|
+
key={mode}
|
|
219
|
+
type="button"
|
|
220
|
+
onClick={() => onChangeViewMode(mode)}
|
|
221
|
+
style={{
|
|
222
|
+
padding: '4px 9px',
|
|
223
|
+
borderRadius: 6,
|
|
224
|
+
fontSize: 11,
|
|
225
|
+
cursor: 'pointer',
|
|
226
|
+
border: '1px solid rgba(56,189,248,0.5)',
|
|
227
|
+
background: viewMode === mode ? 'rgba(56,189,248,0.25)' : 'transparent',
|
|
228
|
+
color: 'inherit',
|
|
229
|
+
}}
|
|
230
|
+
>
|
|
231
|
+
{label}
|
|
232
|
+
</button>
|
|
233
|
+
))}
|
|
234
|
+
</div>
|
|
235
|
+
|
|
236
|
+
{webglError ? (
|
|
237
|
+
<div
|
|
238
|
+
style={{
|
|
239
|
+
width: '100%',
|
|
240
|
+
height: 340,
|
|
241
|
+
borderRadius: 8,
|
|
242
|
+
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
243
|
+
display: 'flex',
|
|
244
|
+
alignItems: 'center',
|
|
245
|
+
justifyContent: 'center',
|
|
246
|
+
padding: 16,
|
|
247
|
+
fontSize: 12,
|
|
248
|
+
opacity: 0.85,
|
|
249
|
+
}}
|
|
250
|
+
>
|
|
251
|
+
{webglError}
|
|
252
|
+
</div>
|
|
253
|
+
) : (
|
|
254
|
+
<div
|
|
255
|
+
ref={containerRef}
|
|
256
|
+
style={{
|
|
257
|
+
width: '100%',
|
|
258
|
+
height: 340,
|
|
259
|
+
borderRadius: 8,
|
|
260
|
+
overflow: 'hidden',
|
|
261
|
+
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
262
|
+
cursor: 'grab',
|
|
263
|
+
}}
|
|
264
|
+
/>
|
|
265
|
+
)}
|
|
266
|
+
|
|
267
|
+
<div style={{ fontSize: 11, opacity: 0.8 }}>{caption}</div>
|
|
268
|
+
</div>
|
|
269
|
+
)
|
|
270
|
+
}
|