@kruschdev/pascal-plugin-plumbing 0.0.0-stage → 0.3.0
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 +854 -0
- package/src/agent-tools.ts +258 -0
- package/src/cad/catalog.ts +151 -0
- package/src/cad/equipment.ts +172 -0
- package/src/cad/fittings.ts +322 -0
- package/src/cad/fixtures.ts +255 -0
- package/src/cad/index.ts +6 -0
- package/src/cad/manifold-interior.ts +248 -0
- package/src/cad/materials.ts +122 -0
- package/src/index.ts +156 -0
- package/src/ipc/audit.ts +927 -0
- package/src/ipc/autopopulate.ts +5071 -0
- package/src/ipc/framing-interop.ts +843 -0
- package/src/ipc/index.ts +9 -0
- package/src/ipc/pricing.ts +571 -0
- package/src/ipc/routing.ts +2410 -0
- package/src/ipc/rules.ts +271 -0
- package/src/ipc/schedule.ts +653 -0
- package/src/ipc/sizing.ts +663 -0
- package/src/ipc/tables.ts +780 -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 +170 -0
- package/src/nodes/pipe-run.ts +393 -0
- package/src/render.ts +64 -0
- package/src/ui/chat-card.tsx +209 -0
- package/src/ui/inspector-card.tsx +243 -0
- package/src/ui/manifold-cutaway-view.tsx +297 -0
- package/src/ui/plumbing-panel.tsx +812 -0
- package/src/ui/schedule-view.tsx +523 -0
- package/src/ui/store.ts +98 -0
|
@@ -0,0 +1,243 @@
|
|
|
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 { calculateSupplyHydraulics, wsfuToGpm } from '../ipc/sizing'
|
|
23
|
+
import { METERS_TO_FEET, type PipeMaterial, type PipeNominalSize, round2 } from '../ipc/tables'
|
|
24
|
+
import { PLUMBING_SCHEDULE_VIEW_ID } from './plumbing-panel'
|
|
25
|
+
import { usePlumbingUi } from './store'
|
|
26
|
+
|
|
27
|
+
export default function PlumbingInspectorCard({ node }: { node?: AnyNode }) {
|
|
28
|
+
const nodes = useScene((s) => s.nodes) as unknown as Readonly<Record<string, SceneNodeLike>>
|
|
29
|
+
const codeEdition = usePlumbingUi((s) => s.codeEdition)
|
|
30
|
+
const occupancy = usePlumbingUi((s) => s.occupancy)
|
|
31
|
+
const setActiveTab = usePlumbingUi((s) => s.setActiveTab)
|
|
32
|
+
const setSelectedManifoldId = usePlumbingUi((s) => s.setSelectedManifoldId)
|
|
33
|
+
|
|
34
|
+
const raw = node as unknown as SceneNodeLike | undefined
|
|
35
|
+
const audit = useMemo(
|
|
36
|
+
() => (raw ? auditScenePlumbing(nodes, { codeEdition, occupancy }) : null),
|
|
37
|
+
[raw, nodes, codeEdition, occupancy],
|
|
38
|
+
)
|
|
39
|
+
const nodeFindings = useMemo(
|
|
40
|
+
() => (raw && audit ? audit.findings.filter((f) => f.nodeIds.includes(raw.id)) : []),
|
|
41
|
+
[audit, raw],
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
const pipeMetrics = useMemo(() => {
|
|
45
|
+
if (!raw || raw.type !== 'plumbing:pipe-run' || !Array.isArray(raw.path)) return null
|
|
46
|
+
const path = raw.path as ReadonlyArray<Vec3>
|
|
47
|
+
const lengthFt = round2(polylineLengthM(path) * METERS_TO_FEET)
|
|
48
|
+
const slope = raw.system === 'dwv-drain' ? measureDrainPathSlope(path) : null
|
|
49
|
+
const material = (raw.material as PipeMaterial) || 'pex-a'
|
|
50
|
+
const pipeSize = (raw.nominalSize as PipeNominalSize) || '1/2"'
|
|
51
|
+
const wsfu = typeof raw.wsfuLoad === 'number' ? raw.wsfuLoad : 0
|
|
52
|
+
let supplyHydraulics: ReturnType<typeof calculateSupplyHydraulics> | null = null
|
|
53
|
+
if (
|
|
54
|
+
(raw.system === 'cold-water' || raw.system === 'hot-water' || raw.system === 'hot-recirc') &&
|
|
55
|
+
wsfu > 0 &&
|
|
56
|
+
(material === 'pex-a' ||
|
|
57
|
+
material === 'pex-b' ||
|
|
58
|
+
material === 'copper-l' ||
|
|
59
|
+
material === 'copper-m' ||
|
|
60
|
+
material === 'cpvc')
|
|
61
|
+
) {
|
|
62
|
+
const flushType =
|
|
63
|
+
raw.system === 'cold-water' && occupancy === 'commercial' ? 'flushometer' : 'flush-tank'
|
|
64
|
+
const gpm = wsfuToGpm(wsfu, flushType)
|
|
65
|
+
supplyHydraulics = calculateSupplyHydraulics({
|
|
66
|
+
gpm,
|
|
67
|
+
size: pipeSize,
|
|
68
|
+
material,
|
|
69
|
+
isHot: raw.system === 'hot-water' || raw.system === 'hot-recirc',
|
|
70
|
+
lengthFt: Math.max(10, lengthFt),
|
|
71
|
+
})
|
|
72
|
+
}
|
|
73
|
+
const lvlId = resolveNodeLevelId(nodes, raw)
|
|
74
|
+
const walls = extractWallSegments(nodes, lvlId)
|
|
75
|
+
const bones = extractBonesPlumbingContext(nodes, lvlId)
|
|
76
|
+
const pens = computePipeFramingPenetrations({
|
|
77
|
+
pipeRunId: raw.id,
|
|
78
|
+
path,
|
|
79
|
+
pipeSize,
|
|
80
|
+
material,
|
|
81
|
+
walls,
|
|
82
|
+
bonesContext: bones,
|
|
83
|
+
})
|
|
84
|
+
return { lengthFt, slope, supplyHydraulics, pens }
|
|
85
|
+
}, [nodes, raw, occupancy])
|
|
86
|
+
|
|
87
|
+
if (!raw) return null
|
|
88
|
+
|
|
89
|
+
const openTab = (tab: 'audit' | 'penetrations' | 'manifold') => {
|
|
90
|
+
setActiveTab(tab)
|
|
91
|
+
openEditorView(PLUMBING_SCHEDULE_VIEW_ID, { beside: true })
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const demand = resolveNodeElectricalDemand(raw)
|
|
95
|
+
|
|
96
|
+
return (
|
|
97
|
+
<div style={{ padding: 10, display: 'flex', flexDirection: 'column', gap: 6, fontSize: 12 }}>
|
|
98
|
+
<div
|
|
99
|
+
style={{
|
|
100
|
+
padding: '6px 8px',
|
|
101
|
+
borderRadius: 6,
|
|
102
|
+
background: nodeFindings.some((f) => f.severity === 'error')
|
|
103
|
+
? 'rgba(239,68,68,0.18)'
|
|
104
|
+
: nodeFindings.length > 0
|
|
105
|
+
? 'rgba(245,158,11,0.18)'
|
|
106
|
+
: 'rgba(34,197,94,0.15)',
|
|
107
|
+
border: `1px solid ${
|
|
108
|
+
nodeFindings.some((f) => f.severity === 'error')
|
|
109
|
+
? '#ef4444'
|
|
110
|
+
: nodeFindings.length > 0
|
|
111
|
+
? '#f59e0b'
|
|
112
|
+
: '#22c55e'
|
|
113
|
+
}`,
|
|
114
|
+
display: 'flex',
|
|
115
|
+
justifyContent: 'space-between',
|
|
116
|
+
alignItems: 'center',
|
|
117
|
+
fontWeight: 600,
|
|
118
|
+
fontSize: 11,
|
|
119
|
+
}}
|
|
120
|
+
>
|
|
121
|
+
<span>
|
|
122
|
+
{nodeFindings.some((f) => f.severity === 'error')
|
|
123
|
+
? `NOT TO CODE (${nodeFindings.length})`
|
|
124
|
+
: nodeFindings.length > 0
|
|
125
|
+
? `WARNINGS (${nodeFindings.length})`
|
|
126
|
+
: `${codeEdition} COMPLIANT`}
|
|
127
|
+
</span>
|
|
128
|
+
<button
|
|
129
|
+
type="button"
|
|
130
|
+
onClick={() => openTab('audit')}
|
|
131
|
+
style={{ background: 'transparent', border: 'none', color: '#38bdf8', cursor: 'pointer', fontSize: 11 }}
|
|
132
|
+
>
|
|
133
|
+
Audit
|
|
134
|
+
</button>
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
{pipeMetrics && (
|
|
138
|
+
<>
|
|
139
|
+
<Row label="System / Size" value={`${String(raw.system)} · ${String(raw.nominalSize)} ${String(raw.material)}`} />
|
|
140
|
+
<Row label="Run Length" value={`${pipeMetrics.lengthFt} ft`} />
|
|
141
|
+
{pipeMetrics.slope && (
|
|
142
|
+
<Row
|
|
143
|
+
label="Measured DWV Slope"
|
|
144
|
+
value={`${pipeMetrics.slope.overallSlopeInPerFt}"/ft`}
|
|
145
|
+
warn={pipeMetrics.slope.hasUphillSegment}
|
|
146
|
+
/>
|
|
147
|
+
)}
|
|
148
|
+
{pipeMetrics.supplyHydraulics && (
|
|
149
|
+
<Row
|
|
150
|
+
label="Supply Flow / Velocity"
|
|
151
|
+
value={`${pipeMetrics.supplyHydraulics.gpm} GPM · ${pipeMetrics.supplyHydraulics.velocityFps} ft/s`}
|
|
152
|
+
warn={!pipeMetrics.supplyHydraulics.velocityOk}
|
|
153
|
+
/>
|
|
154
|
+
)}
|
|
155
|
+
<Row label="Framing Penetrations" value={`${pipeMetrics.pens.length} stud/plate bore(s)`} />
|
|
156
|
+
{pipeMetrics.pens.length > 0 && (
|
|
157
|
+
<button type="button" onClick={() => openTab('penetrations')} style={linkBtnStyle}>
|
|
158
|
+
View Drill Schedule & Hole-Saw Sizes
|
|
159
|
+
</button>
|
|
160
|
+
)}
|
|
161
|
+
</>
|
|
162
|
+
)}
|
|
163
|
+
|
|
164
|
+
{raw.type === 'plumbing:fixture' && (
|
|
165
|
+
<>
|
|
166
|
+
<Row label="DFU / WSFU" value={`${String(raw.dfu ?? 0)} DFU · ${String(raw.wsfuTotal ?? 0)} WSFU`} />
|
|
167
|
+
<Row label="Drain / Vent / Supply" value={`${String(raw.drainSize ?? '-')} / ${String(raw.ventSize ?? '-')} / ${String(raw.supplySize ?? '-')}`} />
|
|
168
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
169
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
170
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
171
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
172
|
+
) : null}
|
|
173
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
174
|
+
</>
|
|
175
|
+
)}
|
|
176
|
+
|
|
177
|
+
{raw.type === 'plumbing:equipment' && (
|
|
178
|
+
<>
|
|
179
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
180
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
181
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
182
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
183
|
+
) : null}
|
|
184
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
185
|
+
</>
|
|
186
|
+
)}
|
|
187
|
+
|
|
188
|
+
{raw.type === 'plumbing:manifold' && (
|
|
189
|
+
<>
|
|
190
|
+
<Row label="Manifold" value={`${String(raw.manifoldKind)} (${String(raw.portCount ?? 12)} ports)`} />
|
|
191
|
+
{typeof raw.catalogSku === 'string' && raw.catalogSku ? (
|
|
192
|
+
<Row label="Linked Catalog SKU" value={raw.catalogSku} />
|
|
193
|
+
) : typeof raw.furnishingSourceId === 'string' && raw.furnishingSourceId ? (
|
|
194
|
+
<Row label="Linked Scene Item" value={raw.furnishingSourceId} />
|
|
195
|
+
) : null}
|
|
196
|
+
{raw.roughInOnly === true && <Row label="CAD Mode" value="Rough-In Stub-Out Only" />}
|
|
197
|
+
<button
|
|
198
|
+
type="button"
|
|
199
|
+
onClick={() => {
|
|
200
|
+
setSelectedManifoldId(raw.id)
|
|
201
|
+
openTab('manifold')
|
|
202
|
+
}}
|
|
203
|
+
style={linkBtnStyle}
|
|
204
|
+
>
|
|
205
|
+
Open 3D Manifold & Wet-Wall Cutaway
|
|
206
|
+
</button>
|
|
207
|
+
</>
|
|
208
|
+
)}
|
|
209
|
+
|
|
210
|
+
{demand?.required && (
|
|
211
|
+
<div style={{ padding: 6, borderRadius: 6, background: 'rgba(245,158,11,0.12)', fontSize: 11 }}>
|
|
212
|
+
<strong>Electrical Coordination:</strong> {demand.voltage}V {demand.poles}P {demand.breakerAmps}A ({demand.loadVa} VA
|
|
213
|
+
{demand.gfciRequired ? ', GFCI' : ''})
|
|
214
|
+
</div>
|
|
215
|
+
)}
|
|
216
|
+
|
|
217
|
+
{nodeFindings.slice(0, 3).map((f) => (
|
|
218
|
+
<div key={f.id} style={{ fontSize: 11, opacity: 0.9 }}>
|
|
219
|
+
<strong>{f.codeRef}:</strong> {f.title}
|
|
220
|
+
</div>
|
|
221
|
+
))}
|
|
222
|
+
</div>
|
|
223
|
+
)
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
function Row({ label, value, warn }: { label: string; value: string; warn?: boolean }) {
|
|
227
|
+
return (
|
|
228
|
+
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: 11 }}>
|
|
229
|
+
<span style={{ opacity: 0.78 }}>{label}</span>
|
|
230
|
+
<strong style={{ color: warn ? '#ef4444' : 'inherit' }}>{value}</strong>
|
|
231
|
+
</div>
|
|
232
|
+
)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const linkBtnStyle = {
|
|
236
|
+
padding: '4px 8px',
|
|
237
|
+
borderRadius: 5,
|
|
238
|
+
border: '1px solid rgba(56,189,248,0.45)',
|
|
239
|
+
background: 'rgba(56,189,248,0.12)',
|
|
240
|
+
color: 'inherit',
|
|
241
|
+
cursor: 'pointer',
|
|
242
|
+
fontSize: 11,
|
|
243
|
+
}
|
|
@@ -0,0 +1,297 @@
|
|
|
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
|
+
Box3,
|
|
12
|
+
type BufferGeometry,
|
|
13
|
+
Color,
|
|
14
|
+
DirectionalLight,
|
|
15
|
+
type Group,
|
|
16
|
+
type Material,
|
|
17
|
+
type Object3D,
|
|
18
|
+
PerspectiveCamera,
|
|
19
|
+
Scene,
|
|
20
|
+
Vector3,
|
|
21
|
+
WebGLRenderer,
|
|
22
|
+
} from 'three'
|
|
23
|
+
import {
|
|
24
|
+
type ManifoldCutawayViewMode,
|
|
25
|
+
type ManifoldPortAssignment,
|
|
26
|
+
buildWiredManifoldCutawayCad,
|
|
27
|
+
} from '../cad/manifold-interior'
|
|
28
|
+
import type { ManifoldKind } from '../ipc/tables'
|
|
29
|
+
|
|
30
|
+
function disposeObject3DTree(root: Object3D): void {
|
|
31
|
+
const geometries = new Set<BufferGeometry>()
|
|
32
|
+
const materials = new Set<Material>()
|
|
33
|
+
root.traverse((obj) => {
|
|
34
|
+
const candidate = obj as Object3D & {
|
|
35
|
+
geometry?: BufferGeometry
|
|
36
|
+
material?: Material | Material[]
|
|
37
|
+
}
|
|
38
|
+
if (candidate.geometry && typeof candidate.geometry.dispose === 'function') {
|
|
39
|
+
geometries.add(candidate.geometry)
|
|
40
|
+
}
|
|
41
|
+
if (Array.isArray(candidate.material)) {
|
|
42
|
+
for (const m of candidate.material) {
|
|
43
|
+
if (m && typeof m.dispose === 'function') materials.add(m)
|
|
44
|
+
}
|
|
45
|
+
} else if (candidate.material && typeof candidate.material.dispose === 'function') {
|
|
46
|
+
materials.add(candidate.material)
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
for (const geo of geometries) geo.dispose()
|
|
50
|
+
for (const mat of materials) mat.dispose()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
type CutawayContext = {
|
|
54
|
+
scene: Scene
|
|
55
|
+
camera: PerspectiveCamera
|
|
56
|
+
renderer: WebGLRenderer
|
|
57
|
+
model: Group | null
|
|
58
|
+
rotY: number
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export default function ManifoldCutawayView({
|
|
62
|
+
manifoldKind,
|
|
63
|
+
portCount,
|
|
64
|
+
viewMode,
|
|
65
|
+
ports,
|
|
66
|
+
onChangeViewMode,
|
|
67
|
+
}: {
|
|
68
|
+
manifoldKind: ManifoldKind
|
|
69
|
+
portCount: number
|
|
70
|
+
viewMode: ManifoldCutawayViewMode
|
|
71
|
+
ports?: ReadonlyArray<ManifoldPortAssignment>
|
|
72
|
+
onChangeViewMode: (m: ManifoldCutawayViewMode) => void
|
|
73
|
+
}) {
|
|
74
|
+
const containerRef = useRef<HTMLDivElement | null>(null)
|
|
75
|
+
const ctxRef = useRef<CutawayContext | null>(null)
|
|
76
|
+
const draggingRef = useRef(false)
|
|
77
|
+
const [webglError, setWebglError] = useState<string | null>(null)
|
|
78
|
+
|
|
79
|
+
const portsKey = useMemo(() => (ports === undefined ? '__demo__' : JSON.stringify(ports)), [ports])
|
|
80
|
+
const stablePorts = useMemo(() => ports, [portsKey])
|
|
81
|
+
|
|
82
|
+
// Effect 1: Create & persist WebGLRenderer / Scene / Camera across prop updates
|
|
83
|
+
useEffect(() => {
|
|
84
|
+
const el = containerRef.current
|
|
85
|
+
if (!el) return
|
|
86
|
+
|
|
87
|
+
const width = Math.max(320, el.clientWidth || 520)
|
|
88
|
+
const height = 340
|
|
89
|
+
|
|
90
|
+
let renderer: WebGLRenderer
|
|
91
|
+
try {
|
|
92
|
+
renderer = new WebGLRenderer({ antialias: true })
|
|
93
|
+
} catch {
|
|
94
|
+
setWebglError('WebGL is unavailable in this browser context. 3D cutaway preview disabled.')
|
|
95
|
+
return
|
|
96
|
+
}
|
|
97
|
+
setWebglError(null)
|
|
98
|
+
|
|
99
|
+
const scene = new Scene()
|
|
100
|
+
scene.background = new Color(0x0f172a)
|
|
101
|
+
|
|
102
|
+
const camera = new PerspectiveCamera(42, width / height, 0.05, 20)
|
|
103
|
+
camera.position.set(0.32, 0.12, 1.95)
|
|
104
|
+
camera.lookAt(0.14, 0, 0)
|
|
105
|
+
|
|
106
|
+
renderer.setSize(width, height)
|
|
107
|
+
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2))
|
|
108
|
+
renderer.domElement.style.touchAction = 'none'
|
|
109
|
+
renderer.domElement.style.userSelect = 'none'
|
|
110
|
+
el.innerHTML = ''
|
|
111
|
+
el.appendChild(renderer.domElement)
|
|
112
|
+
|
|
113
|
+
scene.add(new AmbientLight(0xffffff, 0.85))
|
|
114
|
+
const key = new DirectionalLight(0xffffff, 1.3)
|
|
115
|
+
key.position.set(2, 3, 4)
|
|
116
|
+
scene.add(key)
|
|
117
|
+
|
|
118
|
+
const ctx: CutawayContext = {
|
|
119
|
+
scene,
|
|
120
|
+
camera,
|
|
121
|
+
renderer,
|
|
122
|
+
model: null,
|
|
123
|
+
rotY: -0.18,
|
|
124
|
+
}
|
|
125
|
+
ctxRef.current = ctx
|
|
126
|
+
|
|
127
|
+
let prevX = 0
|
|
128
|
+
|
|
129
|
+
const onDown = (e: PointerEvent) => {
|
|
130
|
+
draggingRef.current = true
|
|
131
|
+
prevX = e.clientX
|
|
132
|
+
}
|
|
133
|
+
const onMove = (e: PointerEvent) => {
|
|
134
|
+
if (!draggingRef.current || !ctx.model) return
|
|
135
|
+
ctx.rotY += (e.clientX - prevX) * 0.01
|
|
136
|
+
prevX = e.clientX
|
|
137
|
+
ctx.model.rotation.y = ctx.rotY
|
|
138
|
+
renderer.render(scene, camera)
|
|
139
|
+
}
|
|
140
|
+
const onUpOrCancel = () => {
|
|
141
|
+
draggingRef.current = false
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
renderer.domElement.addEventListener('pointerdown', onDown)
|
|
145
|
+
renderer.domElement.addEventListener('pointercancel', onUpOrCancel)
|
|
146
|
+
window.addEventListener('pointermove', onMove)
|
|
147
|
+
window.addEventListener('pointerup', onUpOrCancel)
|
|
148
|
+
window.addEventListener('pointercancel', onUpOrCancel)
|
|
149
|
+
|
|
150
|
+
const resizeObserver =
|
|
151
|
+
typeof ResizeObserver !== 'undefined'
|
|
152
|
+
? new ResizeObserver((entries) => {
|
|
153
|
+
const nextW = Math.max(320, Math.round(entries[0]?.contentRect.width || el.clientWidth || 520))
|
|
154
|
+
camera.aspect = nextW / height
|
|
155
|
+
camera.updateProjectionMatrix()
|
|
156
|
+
renderer.setSize(nextW, height)
|
|
157
|
+
renderer.render(scene, camera)
|
|
158
|
+
})
|
|
159
|
+
: null
|
|
160
|
+
resizeObserver?.observe(el)
|
|
161
|
+
|
|
162
|
+
return () => {
|
|
163
|
+
resizeObserver?.disconnect()
|
|
164
|
+
draggingRef.current = false
|
|
165
|
+
renderer.domElement.removeEventListener('pointerdown', onDown)
|
|
166
|
+
renderer.domElement.removeEventListener('pointercancel', onUpOrCancel)
|
|
167
|
+
window.removeEventListener('pointermove', onMove)
|
|
168
|
+
window.removeEventListener('pointerup', onUpOrCancel)
|
|
169
|
+
window.removeEventListener('pointercancel', onUpOrCancel)
|
|
170
|
+
if (ctx.model) {
|
|
171
|
+
scene.remove(ctx.model)
|
|
172
|
+
disposeObject3DTree(ctx.model)
|
|
173
|
+
ctx.model = null
|
|
174
|
+
}
|
|
175
|
+
scene.clear()
|
|
176
|
+
renderer.dispose()
|
|
177
|
+
renderer.forceContextLoss()
|
|
178
|
+
ctxRef.current = null
|
|
179
|
+
el.innerHTML = ''
|
|
180
|
+
}
|
|
181
|
+
}, [])
|
|
182
|
+
|
|
183
|
+
// Effect 2: Rebuild & swap ONLY the 3D manifold mesh group when parameters change, scaling camera radius via Box3
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
const ctx = ctxRef.current
|
|
186
|
+
if (!ctx) return
|
|
187
|
+
|
|
188
|
+
if (ctx.model) {
|
|
189
|
+
ctx.scene.remove(ctx.model)
|
|
190
|
+
disposeObject3DTree(ctx.model)
|
|
191
|
+
ctx.model = null
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
const model = buildWiredManifoldCutawayCad({
|
|
195
|
+
manifoldKind,
|
|
196
|
+
portCount,
|
|
197
|
+
viewMode,
|
|
198
|
+
...(stablePorts !== undefined ? { ports: stablePorts } : {}),
|
|
199
|
+
})
|
|
200
|
+
|
|
201
|
+
const box = new Box3().setFromObject(model)
|
|
202
|
+
const size = new Vector3()
|
|
203
|
+
const center = new Vector3()
|
|
204
|
+
box.getSize(size)
|
|
205
|
+
box.getCenter(center)
|
|
206
|
+
const fovRad = (ctx.camera.fov * Math.PI) / 180
|
|
207
|
+
const halfTan = Math.tan(fovRad / 2)
|
|
208
|
+
const aspect = Math.max(0.5, ctx.camera.aspect || 1.5)
|
|
209
|
+
const fitDistV = Math.max(0.35, size.y / 2) / halfTan
|
|
210
|
+
const fitDistH = Math.max(0.25, Math.hypot(size.x, size.z) / 2) / (halfTan * aspect)
|
|
211
|
+
const camRadius = Math.max(1.55, Math.max(fitDistV, fitDistH) * 1.22)
|
|
212
|
+
ctx.camera.position.set(center.x + camRadius * 0.16, center.y + camRadius * 0.06, center.z + camRadius)
|
|
213
|
+
ctx.camera.lookAt(center.x, center.y, center.z)
|
|
214
|
+
|
|
215
|
+
model.rotation.y = ctx.rotY
|
|
216
|
+
ctx.scene.add(model)
|
|
217
|
+
ctx.model = model
|
|
218
|
+
ctx.renderer.render(ctx.scene, ctx.camera)
|
|
219
|
+
}, [manifoldKind, portCount, viewMode, stablePorts])
|
|
220
|
+
|
|
221
|
+
const caption =
|
|
222
|
+
manifoldKind === 'gas-csst'
|
|
223
|
+
? '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.'
|
|
224
|
+
: manifoldKind === 'copper-header'
|
|
225
|
+
? '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.'
|
|
226
|
+
: '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.'
|
|
227
|
+
|
|
228
|
+
return (
|
|
229
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 10 }}>
|
|
230
|
+
<div style={{ display: 'flex', gap: 8, alignItems: 'center', flexWrap: 'wrap' }}>
|
|
231
|
+
<strong style={{ fontSize: 12 }}>3D Cutaway Mode:</strong>
|
|
232
|
+
{(
|
|
233
|
+
[
|
|
234
|
+
['wet-wall-cutaway', '2x6 Wet-Wall & 3" Stack Cutaway'],
|
|
235
|
+
['open-manifold', 'Manifold Cover Off'],
|
|
236
|
+
['enclosure-closed', 'Steel Enclosure Closed'],
|
|
237
|
+
] as const
|
|
238
|
+
).map(([mode, label]) => (
|
|
239
|
+
<button
|
|
240
|
+
key={mode}
|
|
241
|
+
type="button"
|
|
242
|
+
onClick={() => onChangeViewMode(mode)}
|
|
243
|
+
style={{
|
|
244
|
+
padding: '4px 9px',
|
|
245
|
+
borderRadius: 6,
|
|
246
|
+
fontSize: 11,
|
|
247
|
+
cursor: 'pointer',
|
|
248
|
+
border: '1px solid rgba(56,189,248,0.5)',
|
|
249
|
+
background: viewMode === mode ? 'rgba(56,189,248,0.25)' : 'transparent',
|
|
250
|
+
color: 'inherit',
|
|
251
|
+
}}
|
|
252
|
+
>
|
|
253
|
+
{label}
|
|
254
|
+
</button>
|
|
255
|
+
))}
|
|
256
|
+
</div>
|
|
257
|
+
|
|
258
|
+
{webglError ? (
|
|
259
|
+
<div
|
|
260
|
+
style={{
|
|
261
|
+
width: '100%',
|
|
262
|
+
height: 340,
|
|
263
|
+
borderRadius: 8,
|
|
264
|
+
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
265
|
+
display: 'flex',
|
|
266
|
+
alignItems: 'center',
|
|
267
|
+
justifyContent: 'center',
|
|
268
|
+
padding: 16,
|
|
269
|
+
fontSize: 12,
|
|
270
|
+
opacity: 0.85,
|
|
271
|
+
}}
|
|
272
|
+
>
|
|
273
|
+
{webglError}
|
|
274
|
+
</div>
|
|
275
|
+
) : (
|
|
276
|
+
<div
|
|
277
|
+
ref={containerRef}
|
|
278
|
+
onPointerCancel={() => {
|
|
279
|
+
draggingRef.current = false
|
|
280
|
+
}}
|
|
281
|
+
style={{
|
|
282
|
+
width: '100%',
|
|
283
|
+
height: 340,
|
|
284
|
+
borderRadius: 8,
|
|
285
|
+
overflow: 'hidden',
|
|
286
|
+
border: '1px solid var(--border, rgba(255,255,255,0.16))',
|
|
287
|
+
cursor: 'grab',
|
|
288
|
+
touchAction: 'none',
|
|
289
|
+
userSelect: 'none',
|
|
290
|
+
}}
|
|
291
|
+
/>
|
|
292
|
+
)}
|
|
293
|
+
|
|
294
|
+
<div style={{ fontSize: 11, opacity: 0.8 }}>{caption}</div>
|
|
295
|
+
</div>
|
|
296
|
+
)
|
|
297
|
+
}
|