@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.
@@ -0,0 +1,194 @@
1
+ /**
2
+ * `plumbing:manifold` — PEX Home-Run Manifold, Copper Trunk Header, or CSST Fuel-Gas Manifold.
3
+ * Render-safe module: zero `@pascal-app/editor` imports.
4
+ */
5
+
6
+ import {
7
+ BaseNode,
8
+ type FloorplanGeometry,
9
+ type GeometryContext,
10
+ type NodeDefinition,
11
+ type NodePort,
12
+ nodeType,
13
+ objectId,
14
+ } from '@pascal-app/core'
15
+ import { Group } from 'three'
16
+ import { z } from 'zod'
17
+ import { buildManifoldCad } from '../cad/manifold-interior'
18
+ import type { ManifoldKind } from '../ipc/tables'
19
+
20
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
21
+
22
+ export const ManifoldKindEnum = z.enum(['pex-homerun', 'copper-header', 'gas-csst'])
23
+
24
+ export const PlumbingManifoldNode = BaseNode.extend({
25
+ id: objectId('plumbman'),
26
+ type: nodeType('plumbing:manifold'),
27
+ position: Vec3Schema.default([0, 1.35, 0]),
28
+ rotation: z.number().default(0),
29
+ manifoldKind: ManifoldKindEnum.default('pex-homerun'),
30
+ portCount: z.number().int().min(4).max(36).default(12),
31
+ supplyMaterial: z
32
+ .enum(['pex-a', 'pex-b', 'copper-l', 'copper-m', 'cpvc', 'csst', 'black-iron'])
33
+ .default('pex-a'),
34
+ coverRemoved: z.boolean().default(false),
35
+ furnishingSourceId: z.string().optional(),
36
+ catalogSku: z.string().optional(),
37
+ roughInOnly: z.boolean().default(false),
38
+ })
39
+
40
+ export type PlumbingManifoldNode = z.infer<typeof PlumbingManifoldNode>
41
+
42
+ function rotateManifoldLocal2D(
43
+ cx: number,
44
+ cz: number,
45
+ lx: number,
46
+ lz: number,
47
+ rot: number,
48
+ ): [number, number] {
49
+ const cos = Math.cos(rot)
50
+ const sin = Math.sin(rot)
51
+ return [cx + lx * cos + lz * sin, cz - lx * sin + lz * cos]
52
+ }
53
+
54
+ export function getPlumbingManifoldPorts(node: PlumbingManifoldNode): NodePort[] {
55
+ const [x, y, zPos] = node.position
56
+ const rot = node.rotation ?? 0
57
+ const perSide = Math.max(4, Math.min(18, Math.ceil(node.portCount / 2)))
58
+ if (node.manifoldKind === 'gas-csst') {
59
+ const cabinetH = Math.max(0.56, 0.24 + Math.min(8, node.portCount) * 0.052)
60
+ const [gx, gz] = rotateManifoldLocal2D(x, zPos, 0, 0.02, rot)
61
+ return [
62
+ { id: 'gas-in', position: [gx, y - (cabinetH / 2 + 0.12), gz], direction: [0, -1, 0], diameter: 0.75, system: 'gas' },
63
+ ]
64
+ }
65
+ const cabinetH = Math.max(0.56, 0.22 + perSide * 0.048)
66
+ const [hx, hz] = rotateManifoldLocal2D(x, zPos, -0.085, 0.02, rot)
67
+ const [cx, cz] = rotateManifoldLocal2D(x, zPos, 0.085, 0.02, rot)
68
+ return [
69
+ { id: 'hot-in', position: [hx, y - (cabinetH / 2 + 0.14), hz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
70
+ { id: 'cold-in', position: [cx, y - (cabinetH / 2 + 0.14), cz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
71
+ ]
72
+ }
73
+
74
+ export function buildPlumbingManifoldGeometry(
75
+ node: PlumbingManifoldNode,
76
+ _ctx: GeometryContext,
77
+ ): Group {
78
+ const group = new Group()
79
+ group.name = `plumbing-manifold-${node.id}`
80
+ group.add(
81
+ buildManifoldCad({
82
+ manifoldKind: node.manifoldKind as ManifoldKind,
83
+ portCount: node.portCount,
84
+ coverRemoved: node.coverRemoved,
85
+ roughInOnly: node.roughInOnly,
86
+ }),
87
+ )
88
+ return group
89
+ }
90
+
91
+ export function buildPlumbingManifoldFloorplan(
92
+ node: PlumbingManifoldNode,
93
+ ctx: GeometryContext,
94
+ ): FloorplanGeometry {
95
+ const view = ctx.viewState
96
+ const selected = (view?.selected || view?.highlighted) ?? false
97
+ const [cx, , cz] = node.position
98
+ const rot = node.rotation ?? 0
99
+ const hw = node.manifoldKind === 'gas-csst' ? 0.18 : 0.22
100
+ const hd = 0.08
101
+ const baseStroke = node.manifoldKind === 'gas-csst' ? '#eab308' : '#0284c7'
102
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : baseStroke
103
+
104
+ if (node.roughInOnly) {
105
+ const r = 0.08
106
+ const children: FloorplanGeometry[] = [
107
+ { kind: 'circle', cx, cy: cz, r, fill: baseStroke, fillOpacity: 0.25, stroke, strokeWidth: 0.02 },
108
+ { kind: 'line', x1: cx - r, y1: cz, x2: cx + r, y2: cz, stroke, strokeWidth: 0.015 },
109
+ { kind: 'line', x1: cx, y1: cz - r, x2: cx, y2: cz + r, stroke, strokeWidth: 0.015 },
110
+ ]
111
+ if (selected) {
112
+ children.push({ kind: 'move-handle', point: [cx, cz] })
113
+ }
114
+ return { kind: 'group', children }
115
+ }
116
+
117
+ const p0 = rotateManifoldLocal2D(cx, cz, -hw, -hd, rot)
118
+ const p1 = rotateManifoldLocal2D(cx, cz, hw, -hd, rot)
119
+ const p2 = rotateManifoldLocal2D(cx, cz, hw, hd, rot)
120
+ const p3 = rotateManifoldLocal2D(cx, cz, -hw, hd, rot)
121
+
122
+ const children: FloorplanGeometry[] = [
123
+ {
124
+ kind: 'polygon',
125
+ points: [p0, p1, p2, p3],
126
+ fill: baseStroke,
127
+ fillOpacity: 0.16,
128
+ stroke,
129
+ strokeWidth: 0.025,
130
+ },
131
+ ]
132
+ if (node.manifoldKind === 'gas-csst') {
133
+ const g0 = rotateManifoldLocal2D(cx, cz, -hw * 0.7, 0, rot)
134
+ const g1 = rotateManifoldLocal2D(cx, cz, hw * 0.7, 0, rot)
135
+ children.push({ kind: 'line', x1: g0[0], y1: g0[1], x2: g1[0], y2: g1[1], stroke: '#eab308', strokeWidth: 0.025 })
136
+ } else {
137
+ const h0 = rotateManifoldLocal2D(cx, cz, -hw * 0.45, -hd, rot)
138
+ const h1 = rotateManifoldLocal2D(cx, cz, -hw * 0.45, hd, rot)
139
+ const c0 = rotateManifoldLocal2D(cx, cz, hw * 0.45, -hd, rot)
140
+ const c1 = rotateManifoldLocal2D(cx, cz, hw * 0.45, hd, rot)
141
+ children.push(
142
+ { kind: 'line', x1: h0[0], y1: h0[1], x2: h1[0], y2: h1[1], stroke: '#dc2626', strokeWidth: 0.025 },
143
+ { kind: 'line', x1: c0[0], y1: c0[1], x2: c1[0], y2: c1[1], stroke: '#2563eb', strokeWidth: 0.025 },
144
+ )
145
+ }
146
+ if (selected) {
147
+ children.push({ kind: 'move-handle', point: [cx, cz] })
148
+ }
149
+ return { kind: 'group', children }
150
+ }
151
+
152
+ export const plumbingManifoldRenderDefinition: NodeDefinition<typeof PlumbingManifoldNode> = {
153
+ kind: 'plumbing:manifold',
154
+ schemaVersion: 1,
155
+ schema: PlumbingManifoldNode,
156
+ category: 'utility',
157
+ distributionRole: 'equipment',
158
+ facingIndicator: true,
159
+ defaults: () => ({
160
+ object: 'node',
161
+ parentId: null,
162
+ visible: true,
163
+ metadata: {},
164
+ name: 'PEX Home-Run Manifold (12-Port)',
165
+ position: [0, 1.35, 0],
166
+ rotation: 0,
167
+ manifoldKind: 'pex-homerun',
168
+ portCount: 12,
169
+ supplyMaterial: 'pex-a',
170
+ coverRemoved: false,
171
+ roughInOnly: false,
172
+ }),
173
+ capabilities: {
174
+ selectable: { hitVolume: 'bbox' },
175
+ movable: { axes: ['x', 'y', 'z'], gridSnap: true },
176
+ rotatable: { axes: ['y'], snapAngles: [Math.PI / 2] },
177
+ duplicable: true,
178
+ deletable: true,
179
+ snappable: {},
180
+ },
181
+ geometry: buildPlumbingManifoldGeometry,
182
+ geometryKey: (n) => JSON.stringify([n.manifoldKind, n.portCount, n.coverRemoved, n.roughInOnly ?? false]),
183
+ ports: getPlumbingManifoldPorts,
184
+ floorplan: buildPlumbingManifoldFloorplan,
185
+ presentation: {
186
+ label: 'Plumbing Manifold',
187
+ description: 'PEX home-run manifold with quarter-turn ball valves, copper trunk header, or CSST gas distribution block.',
188
+ icon: { kind: 'iconify', name: 'lucide:sliders-horizontal' },
189
+ paletteSection: 'structure',
190
+ },
191
+ mcp: {
192
+ description: 'Plumbing distribution manifold (PEX home-run, copper header, or CSST gas block).',
193
+ },
194
+ }
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Auto-derived Pascal Inspector Parametrics for all 4 `plumbing:*` node kinds.
3
+ */
4
+
5
+ import type { ParametricDescriptor } from '@pascal-app/core'
6
+ import { EquipmentKindEnum, type PlumbingEquipmentNode } from './equipment'
7
+ import { FixtureKindEnum, PipeNominalSizeEnum, type PlumbingFixtureNode } from './fixture'
8
+ import { ManifoldKindEnum, type PlumbingManifoldNode } from './manifold'
9
+ import { PipeMaterialEnum, type PlumbingPipeRunNode, PlumbingSystemEnum } from './pipe-run'
10
+
11
+ export const plumbingEquipmentParametrics: ParametricDescriptor<PlumbingEquipmentNode> = {
12
+ groups: [
13
+ {
14
+ label: 'Equipment & Capacity',
15
+ fields: [
16
+ { key: 'equipmentKind', kind: 'enum', options: [...EquipmentKindEnum.options] },
17
+ { key: 'capacityGal', kind: 'number', unit: 'gal', min: 0, max: 500, step: 5 },
18
+ { key: 'gasBtuh', kind: 'number', unit: 'BTU/h', min: 0, max: 500000, step: 5000 },
19
+ { key: 'watts', kind: 'number', unit: 'W', min: 0, max: 50000, step: 500 },
20
+ { key: 'roomVolumeCuFt', kind: 'number', unit: 'cu ft', min: 0, max: 50000, step: 50, label: 'Room Volume (HPWH >= 700 cu ft)' },
21
+ ],
22
+ },
23
+ {
24
+ label: 'IPC Safety & Compliance',
25
+ fields: [
26
+ { key: 'hasDrainPan', kind: 'boolean', label: 'Safety Drain Pan (IPC 504.7)' },
27
+ { key: 'hasTpDischarge', kind: 'boolean', label: 'T&P Relief Pipe (IPC 504.6)' },
28
+ { key: 'hasExpansionTank', kind: 'boolean', label: 'Expansion Tank (IPC 607.3)' },
29
+ ],
30
+ },
31
+ ],
32
+ }
33
+
34
+ export const plumbingManifoldParametrics: ParametricDescriptor<PlumbingManifoldNode> = {
35
+ groups: [
36
+ {
37
+ label: 'Manifold Configuration',
38
+ fields: [
39
+ { key: 'manifoldKind', kind: 'enum', options: [...ManifoldKindEnum.options], display: 'segmented' },
40
+ { key: 'portCount', kind: 'number', min: 4, max: 36, step: 2 },
41
+ { key: 'coverRemoved', kind: 'boolean', label: 'Expose Open Manifold Valves' },
42
+ ],
43
+ },
44
+ ],
45
+ }
46
+
47
+ export const plumbingFixtureParametrics: ParametricDescriptor<PlumbingFixtureNode> = {
48
+ groups: [
49
+ {
50
+ label: 'Fixture & IPC Units',
51
+ fields: [
52
+ { key: 'fixtureKind', kind: 'enum', options: [...FixtureKindEnum.options] },
53
+ { key: 'dfu', kind: 'number', unit: 'DFU', min: 0, max: 20, step: 0.5 },
54
+ { key: 'wsfuCold', kind: 'number', unit: 'WSFU', min: 0, max: 20, step: 0.5 },
55
+ { key: 'wsfuHot', kind: 'number', unit: 'WSFU', min: 0, max: 20, step: 0.5 },
56
+ ],
57
+ },
58
+ {
59
+ label: 'Rough-In Sizing & Protection',
60
+ fields: [
61
+ { key: 'hasPTrap', kind: 'boolean', label: 'P-Trap Installed (IPC 1002.1)' },
62
+ { key: 'hasVacuumBreaker', kind: 'boolean', label: 'Anti-Siphon Vacuum Breaker' },
63
+ ],
64
+ },
65
+ ],
66
+ }
67
+
68
+ export const plumbingPipeRunParametrics: ParametricDescriptor<PlumbingPipeRunNode> = {
69
+ groups: [
70
+ {
71
+ label: 'System & Material',
72
+ fields: [
73
+ { key: 'system', kind: 'enum', options: [...PlumbingSystemEnum.options] },
74
+ { key: 'material', kind: 'enum', options: [...PipeMaterialEnum.options] },
75
+ { key: 'nominalSize', kind: 'enum', options: [...PipeNominalSizeEnum.options] },
76
+ ],
77
+ },
78
+ {
79
+ label: 'Slope, Loads & Framing Bore Visualization',
80
+ fields: [
81
+ { key: 'slopeInPerFt', kind: 'number', unit: 'in/ft', min: 0, max: 2, step: 0.125 },
82
+ { key: 'trapArmLengthFt', kind: 'number', unit: 'ft', min: 0, max: 50, step: 0.5 },
83
+ { key: 'dfuLoad', kind: 'number', unit: 'DFU', min: 0, max: 1000, step: 1 },
84
+ { key: 'wsfuLoad', kind: 'number', unit: 'WSFU', min: 0, max: 1000, step: 0.5 },
85
+ { key: 'gasBtuh', kind: 'number', unit: 'BTU/h', min: 0, max: 2000000, step: 5000 },
86
+ { key: 'hasCleanout', kind: 'boolean', label: 'Cleanout Installed (IPC 708.1)' },
87
+ { key: 'hasSedimentTrap', kind: 'boolean', label: 'Gas Drip Leg (IFGC 408.4)' },
88
+ { key: 'isMainVentStack', kind: 'boolean', label: 'Main Vent Stack Through Roof (IPC 903.1)' },
89
+ { key: 'isHorizontalSanTee', kind: 'boolean', label: 'Horizontal Sanitary Tee (Flagged per IPC 706.3)' },
90
+ { key: 'showFramingPenetrations', kind: 'boolean', label: 'Show 3D Stud Bore Rings & Nail Plates' },
91
+ ],
92
+ },
93
+ ],
94
+ }
@@ -0,0 +1,342 @@
1
+ /**
2
+ * `plumbing:pipe-run` — 3D Gravity-Sloped DWV, Vent Stack, Cold/Hot/Recirc Supply,
3
+ * Fuel Gas (IFGC), Condensate, and Rigid Dryer Vent Pipe Runs.
4
+ * Automatically renders 3D framing bore collars & steel nail plates at Bones stud/plate crossings!
5
+ * Render-safe module: zero `@pascal-app/editor` imports.
6
+ */
7
+
8
+ import {
9
+ BaseNode,
10
+ type FloorplanGeometry,
11
+ type GeometryContext,
12
+ type NodeDefinition,
13
+ type NodePort,
14
+ nodeType,
15
+ objectId,
16
+ } from '@pascal-app/core'
17
+ import { Box3, Group, Mesh, MeshStandardMaterial } from 'three'
18
+ import { z } from 'zod'
19
+ import { buildPipeRunCad } from '../cad/fittings'
20
+ import { systemColorMeta } from '../cad/materials'
21
+ import {
22
+ type SceneNodeLike,
23
+ computePipeFramingPenetrations,
24
+ extractBonesPlumbingContext,
25
+ resolveNodeLevelId,
26
+ } from '../ipc/framing-interop'
27
+ import { extractWallSegments } from '../ipc/routing'
28
+ import {
29
+ PIPE_NOMINAL_INCHES,
30
+ type PipeMaterial,
31
+ type PipeNominalSize,
32
+ type PlumbingSystem,
33
+ getPipeOuterDiameterM,
34
+ } from '../ipc/tables'
35
+ import { PipeNominalSizeEnum } from './fixture'
36
+
37
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
38
+
39
+ export const PlumbingSystemEnum = z.enum([
40
+ 'cold-water',
41
+ 'hot-water',
42
+ 'hot-recirc',
43
+ 'dwv-drain',
44
+ 'dwv-vent',
45
+ 'fuel-gas',
46
+ 'condensate',
47
+ 'dryer-vent',
48
+ ])
49
+
50
+ export const PipeMaterialEnum = z.enum([
51
+ 'pex-a',
52
+ 'pex-b',
53
+ 'copper-l',
54
+ 'copper-m',
55
+ 'cpvc',
56
+ 'pvc-dwv',
57
+ 'abs-dwv',
58
+ 'cast-iron',
59
+ 'csst',
60
+ 'black-iron',
61
+ 'rigid-aluminum',
62
+ ])
63
+
64
+ export const PlumbingPipeRunNode = BaseNode.extend({
65
+ id: objectId('plumbpipe'),
66
+ type: nodeType('plumbing:pipe-run'),
67
+ path: z.array(Vec3Schema).min(2),
68
+ system: PlumbingSystemEnum.default('cold-water'),
69
+ material: PipeMaterialEnum.default('pex-a'),
70
+ nominalSize: PipeNominalSizeEnum.default('1/2"'),
71
+ slopeInPerFt: z.number().min(0).max(2).default(0),
72
+ dfuLoad: z.number().min(0).max(1000).default(0),
73
+ wsfuLoad: z.number().min(0).max(1000).default(0),
74
+ gasBtuh: z.number().min(0).max(2000000).default(0),
75
+ trapArmLengthFt: z.number().min(0).max(50).optional(),
76
+ sourceNodeId: z.string().optional(),
77
+ targetNodeId: z.string().optional(),
78
+ wallId: z.string().optional(),
79
+ hasCleanout: z.boolean().default(false),
80
+ hasSedimentTrap: z.boolean().default(true),
81
+ hasShutoffWithin6Ft: z.boolean().default(true),
82
+ isHorizontalSanTee: z.boolean().default(false),
83
+ isMainVentStack: z.boolean().default(false),
84
+ showFramingPenetrations: z.boolean().default(true),
85
+ /** When true, sub-slab / below-grade runs render through the opaque ground plane & floor slab (X-Ray Ground). */
86
+ xraySubSlab: z.boolean().default(false),
87
+ /** Optional revision token bumped when adjacent walls/framing change to invalidate cached 3D bore collars. */
88
+ framingRevision: z.number().int().min(0).optional(),
89
+ })
90
+
91
+ export type PlumbingPipeRunNode = z.infer<typeof PlumbingPipeRunNode>
92
+
93
+ function normalizeDir(
94
+ a: readonly [number, number, number],
95
+ b: readonly [number, number, number],
96
+ sign: 1 | -1,
97
+ ): [number, number, number] {
98
+ const dx = (b[0] - a[0]) * sign
99
+ const dy = (b[1] - a[1]) * sign
100
+ const dz = (b[2] - a[2]) * sign
101
+ const len = Math.hypot(dx, dy, dz)
102
+ if (len < 1e-5) return [0, 1, 0]
103
+ return [dx / len, dy / len, dz / len]
104
+ }
105
+
106
+ export function getPlumbingPipeRunPorts(node: PlumbingPipeRunNode): NodePort[] {
107
+ const start = node.path[0]
108
+ const end = node.path[node.path.length - 1]
109
+ if (!start || !end) return []
110
+ let second = end
111
+ for (let i = 1; i < node.path.length; i++) {
112
+ const p = node.path[i]!
113
+ if (Math.hypot(p[0] - start[0], p[1] - start[1], p[2] - start[2]) >= 1e-5) {
114
+ second = p
115
+ break
116
+ }
117
+ }
118
+ let prev = start
119
+ for (let i = node.path.length - 2; i >= 0; i--) {
120
+ const p = node.path[i]!
121
+ if (Math.hypot(end[0] - p[0], end[1] - p[1], end[2] - p[2]) >= 1e-5) {
122
+ prev = p
123
+ break
124
+ }
125
+ }
126
+ const sys =
127
+ node.system.startsWith('dwv') || node.system === 'condensate'
128
+ ? 'dwv'
129
+ : node.system === 'fuel-gas'
130
+ ? 'gas'
131
+ : node.system === 'dryer-vent'
132
+ ? 'exhaust'
133
+ : 'water'
134
+ const diameter = PIPE_NOMINAL_INCHES[node.nominalSize as PipeNominalSize] ?? 1
135
+ return [
136
+ { id: 'start', position: start, direction: normalizeDir(start, second, -1), diameter, system: sys },
137
+ { id: 'end', position: end, direction: normalizeDir(prev, end, 1), diameter, system: sys },
138
+ ]
139
+ }
140
+
141
+ export function buildPlumbingPipeRunGeometry(
142
+ node: PlumbingPipeRunNode,
143
+ ctx: GeometryContext,
144
+ ): Group {
145
+ let penetrations: ReturnType<typeof computePipeFramingPenetrations> = []
146
+ if (node.showFramingPenetrations && ctx && typeof ctx === 'object' && 'nodes' in ctx && ctx.nodes) {
147
+ const record = ctx.nodes as unknown as Readonly<Record<string, SceneNodeLike>>
148
+ const levelId = resolveNodeLevelId(record, node as unknown as SceneNodeLike) ?? node.parentId ?? null
149
+ const walls = extractWallSegments(record, levelId)
150
+ const bones = extractBonesPlumbingContext(record, levelId)
151
+ penetrations = computePipeFramingPenetrations({
152
+ pipeRunId: node.id,
153
+ path: node.path,
154
+ pipeSize: node.nominalSize as PipeNominalSize,
155
+ material: node.material as PipeMaterial,
156
+ walls,
157
+ bonesContext: bones,
158
+ })
159
+ }
160
+
161
+ const group = buildPipeRunCad({
162
+ id: node.id,
163
+ path: node.path,
164
+ system: node.system as PlumbingSystem,
165
+ material: node.material as PipeMaterial,
166
+ nominalSize: node.nominalSize as PipeNominalSize,
167
+ hasCleanout: node.hasCleanout,
168
+ penetrations,
169
+ })
170
+
171
+ // Sub-Slab X-Ray Ground Visibility: render ONLY below-grade pipe segments/fittings (maxY < 0.04 m)
172
+ // through Pascal's opaque y=0 ground plane and floor slab so above-grade risers & bore collars stay
173
+ // properly depth-tested behind opaque walls and cabinets.
174
+ const hasBelowGradePoint = node.path.some((p) => p[1] < -0.005)
175
+ if (node.xraySubSlab && hasBelowGradePoint && node.system !== 'dwv-vent') {
176
+ const isDarkDwv =
177
+ node.system === 'dwv-drain' && (node.material === 'abs-dwv' || node.material === 'cast-iron')
178
+ group.updateMatrixWorld(true)
179
+ const meshBox = new Box3()
180
+ group.traverse((obj) => {
181
+ if (!(obj instanceof Mesh)) return
182
+ meshBox.setFromObject(obj)
183
+ if (!Number.isFinite(meshBox.max.y) || meshBox.max.y >= 0.04) return
184
+ obj.renderOrder = 30
185
+ const mats = Array.isArray(obj.material) ? obj.material : [obj.material]
186
+ const cloned = mats.map((m) => {
187
+ if (!(m instanceof MeshStandardMaterial)) return m
188
+ const next = m.clone()
189
+ next.depthTest = false
190
+ next.depthWrite = false
191
+ next.transparent = true
192
+ next.opacity = 0.92
193
+ if (isDarkDwv) {
194
+ next.emissive.setHex(0x38bdf8)
195
+ next.emissiveIntensity = 0.28
196
+ }
197
+ next.needsUpdate = true
198
+ return next
199
+ })
200
+ obj.material = Array.isArray(obj.material) ? cloned : cloned[0]!
201
+ })
202
+ }
203
+
204
+ return group
205
+ }
206
+
207
+ export function buildPlumbingPipeRunFloorplan(
208
+ node: PlumbingPipeRunNode,
209
+ ctx: GeometryContext,
210
+ ): FloorplanGeometry {
211
+ const view = ctx.viewState
212
+ const selected = (view?.selected || view?.highlighted) ?? false
213
+ const meta = systemColorMeta(node.system as PlumbingSystem)
214
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : meta.hex
215
+ const children: FloorplanGeometry[] = []
216
+
217
+ let drewHorizontal = false
218
+ for (let i = 0; i < node.path.length - 1; i++) {
219
+ const a = node.path[i]!
220
+ const b = node.path[i + 1]!
221
+ if (Math.hypot(b[0] - a[0], b[2] - a[2]) < 1e-3) continue
222
+ drewHorizontal = true
223
+ children.push({
224
+ kind: 'line',
225
+ x1: a[0],
226
+ y1: a[2],
227
+ x2: b[0],
228
+ y2: b[2],
229
+ stroke,
230
+ strokeWidth: selected ? 0.042 : node.system === 'dwv-drain' ? 0.032 : 0.022,
231
+ strokeDasharray: meta.dash2d ? '0.14 0.07' : undefined,
232
+ })
233
+ }
234
+
235
+ const start = node.path[0]
236
+ if (!drewHorizontal && start && node.path.length >= 2) {
237
+ // Pure vertical pipe stack (e.g., 3"/4" Main Vent Stack): render a visible 2D riser circle + crosshair
238
+ const odM = getPipeOuterDiameterM(node.nominalSize as PipeNominalSize, node.material as PipeMaterial)
239
+ const r = Math.max(0.085, (odM / 2) * 1.6)
240
+ const sw = selected ? 0.036 : 0.024
241
+ children.push(
242
+ {
243
+ kind: 'circle',
244
+ cx: start[0],
245
+ cy: start[2],
246
+ r,
247
+ fill: meta.hex,
248
+ fillOpacity: 0.22,
249
+ stroke,
250
+ strokeWidth: sw,
251
+ },
252
+ {
253
+ kind: 'line',
254
+ x1: start[0] - r * 0.85,
255
+ y1: start[2],
256
+ x2: start[0] + r * 0.85,
257
+ y2: start[2],
258
+ stroke,
259
+ strokeWidth: 0.018,
260
+ },
261
+ {
262
+ kind: 'line',
263
+ x1: start[0],
264
+ y1: start[2] - r * 0.85,
265
+ x2: start[0],
266
+ y2: start[2] + r * 0.85,
267
+ stroke,
268
+ strokeWidth: 0.018,
269
+ },
270
+ )
271
+ }
272
+
273
+ if (selected && start) {
274
+ children.push({ kind: 'move-handle', point: [start[0], start[2]] })
275
+ }
276
+ return { kind: 'group', children }
277
+ }
278
+
279
+ export const plumbingPipeRunRenderDefinition: NodeDefinition<typeof PlumbingPipeRunNode> = {
280
+ kind: 'plumbing:pipe-run',
281
+ schemaVersion: 1,
282
+ schema: PlumbingPipeRunNode,
283
+ category: 'utility',
284
+ distributionRole: 'run',
285
+ defaults: () => ({
286
+ object: 'node',
287
+ parentId: null,
288
+ visible: true,
289
+ metadata: {},
290
+ name: 'Pipe Run',
291
+ path: [
292
+ [0, 0.5, 0],
293
+ [1, 0.5, 0],
294
+ ],
295
+ system: 'cold-water',
296
+ material: 'pex-a',
297
+ nominalSize: '1/2"',
298
+ slopeInPerFt: 0,
299
+ dfuLoad: 0,
300
+ wsfuLoad: 0,
301
+ gasBtuh: 0,
302
+ hasCleanout: false,
303
+ hasSedimentTrap: true,
304
+ hasShutoffWithin6Ft: true,
305
+ isHorizontalSanTee: false,
306
+ isMainVentStack: false,
307
+ showFramingPenetrations: true,
308
+ xraySubSlab: false,
309
+ }),
310
+ capabilities: {
311
+ selectable: { hitVolume: 'bbox' },
312
+ duplicable: true,
313
+ deletable: true,
314
+ snappable: {},
315
+ },
316
+ geometry: buildPlumbingPipeRunGeometry,
317
+ geometryKey: (n) =>
318
+ JSON.stringify([
319
+ n.parentId ?? null,
320
+ n.path,
321
+ n.system,
322
+ n.material,
323
+ n.nominalSize,
324
+ n.hasCleanout,
325
+ n.showFramingPenetrations,
326
+ n.xraySubSlab ?? false,
327
+ n.wallId ?? null,
328
+ n.framingRevision ?? 0,
329
+ ]),
330
+ ports: getPlumbingPipeRunPorts,
331
+ floorplan: buildPlumbingPipeRunFloorplan,
332
+ presentation: {
333
+ label: 'Pipe Run',
334
+ description:
335
+ 'Gravity-sloped 3D DWV drain, vent stack, cold/hot/recirc supply, fuel gas, or rigid dryer vent run with framing bore collars.',
336
+ icon: { kind: 'iconify', name: 'lucide:git-branch' },
337
+ paletteSection: 'structure',
338
+ },
339
+ mcp: {
340
+ description: '3D plumbing pipe polyline in level-local meters tracking system, material, nominalSize, gravity slope, DFU/WSFU/gas loads, and framing penetrations.',
341
+ },
342
+ }
package/src/render.ts ADDED
@@ -0,0 +1,64 @@
1
+ /**
2
+ * Read-only viewer entry (`@kruschdev/pascal-plugin-plumbing/render`).
3
+ * Same plugin ID, contract version, schemas, defaults, 3D geometry, and 2D floorplan symbols
4
+ * as `plumbingPlugin`, with ZERO imports from `@pascal-app/editor` or `next`.
5
+ */
6
+
7
+ import type { AnyNodeDefinition, Plugin } from '@pascal-app/core'
8
+ import { plumbingEquipmentRenderDefinition } from './nodes/equipment'
9
+ import { plumbingFixtureRenderDefinition } from './nodes/fixture'
10
+ import { plumbingManifoldRenderDefinition } from './nodes/manifold'
11
+ import { plumbingPipeRunRenderDefinition } from './nodes/pipe-run'
12
+
13
+ export const PLUMBING_PLUGIN_ID = 'krusch:plumbing' as const
14
+ export const PLUMBING_SCHEDULE_VIEW_ID = 'krusch:plumbing:schedule' as const
15
+
16
+ export const plumbingRenderPlugin: Plugin = {
17
+ id: PLUMBING_PLUGIN_ID,
18
+ apiVersion: 1,
19
+ nodes: [
20
+ plumbingEquipmentRenderDefinition as unknown as AnyNodeDefinition,
21
+ plumbingManifoldRenderDefinition as unknown as AnyNodeDefinition,
22
+ plumbingFixtureRenderDefinition as unknown as AnyNodeDefinition,
23
+ plumbingPipeRunRenderDefinition as unknown as AnyNodeDefinition,
24
+ ],
25
+ }
26
+
27
+ export {
28
+ PlumbingEquipmentNode,
29
+ EquipmentKindEnum,
30
+ ElectricalDemandSchema,
31
+ plumbingEquipmentRenderDefinition,
32
+ buildPlumbingEquipmentGeometry,
33
+ buildPlumbingEquipmentFloorplan,
34
+ getPlumbingEquipmentPorts,
35
+ } from './nodes/equipment'
36
+
37
+ export {
38
+ PlumbingManifoldNode,
39
+ ManifoldKindEnum,
40
+ plumbingManifoldRenderDefinition,
41
+ buildPlumbingManifoldGeometry,
42
+ buildPlumbingManifoldFloorplan,
43
+ getPlumbingManifoldPorts,
44
+ } from './nodes/manifold'
45
+
46
+ export {
47
+ PlumbingFixtureNode,
48
+ FixtureKindEnum,
49
+ PipeNominalSizeEnum,
50
+ plumbingFixtureRenderDefinition,
51
+ buildPlumbingFixtureGeometry,
52
+ buildPlumbingFixtureFloorplan,
53
+ getPlumbingFixturePorts,
54
+ } from './nodes/fixture'
55
+
56
+ export {
57
+ PlumbingPipeRunNode,
58
+ PlumbingSystemEnum,
59
+ PipeMaterialEnum,
60
+ plumbingPipeRunRenderDefinition,
61
+ buildPlumbingPipeRunGeometry,
62
+ buildPlumbingPipeRunFloorplan,
63
+ getPlumbingPipeRunPorts,
64
+ } from './nodes/pipe-run'