@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,330 @@
1
+ /**
2
+ * `plumbing:equipment` — Water Heaters (Electric/Gas Tank, Tankless, HPWH),
3
+ * Expansion Tanks, PRV/Shutoff, Water Softener, Sump/Sewage Pumps, Recirc Pump, Gas Meter, Backwater Valve.
4
+ * Render-safe module: zero `@pascal-app/editor` imports.
5
+ */
6
+
7
+ import {
8
+ BaseNode,
9
+ type FloorplanGeometry,
10
+ type GeometryContext,
11
+ type NodeDefinition,
12
+ type NodePort,
13
+ nodeType,
14
+ objectId,
15
+ } from '@pascal-app/core'
16
+ import { Group } from 'three'
17
+ import { z } from 'zod'
18
+ import { buildEquipmentCad } from '../cad/equipment'
19
+ import { getEquipmentElectricalDemand } from '../ipc/framing-interop'
20
+ import type { EquipmentKind } from '../ipc/tables'
21
+
22
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
23
+
24
+ export const ElectricalDemandSchema = z.object({
25
+ required: z.boolean().default(true),
26
+ voltage: z.union([z.literal(120), z.literal(208), z.literal(240), z.literal(480)]).default(120),
27
+ poles: z.union([z.literal(1), z.literal(2), z.literal(3)]).default(1),
28
+ breakerAmps: z.number().min(15).max(200).default(20),
29
+ loadVa: z.number().min(0).max(50000).default(1200),
30
+ continuous: z.boolean().default(false),
31
+ dedicatedCircuit: z.boolean().default(true),
32
+ gfciRequired: z.boolean().default(false),
33
+ afciRequired: z.boolean().default(false),
34
+ loadCategory: z
35
+ .enum(['fixed', 'appliance', 'motor', 'hvac-heating', 'hvac-cooling', 'heat-pump'])
36
+ .default('fixed'),
37
+ label: z.string().default('Plumbing Equipment'),
38
+ })
39
+
40
+ export const EquipmentKindEnum = z.enum([
41
+ 'water-heater-tank-gas',
42
+ 'water-heater-tank-electric',
43
+ 'water-heater-tankless-gas',
44
+ 'water-heater-hpwh',
45
+ 'expansion-tank',
46
+ 'main-shutoff-prv',
47
+ 'water-softener',
48
+ 'sump-pump',
49
+ 'sewage-ejector',
50
+ 'recirc-pump',
51
+ 'gas-meter',
52
+ 'backwater-valve',
53
+ ])
54
+
55
+ export const PlumbingEquipmentNode = BaseNode.extend({
56
+ id: objectId('plumbeq'),
57
+ type: nodeType('plumbing:equipment'),
58
+ position: Vec3Schema.default([0, 0, 0]),
59
+ rotation: z.number().default(0),
60
+ equipmentKind: EquipmentKindEnum.default('water-heater-tank-electric'),
61
+ roomName: z.string().default('Utility'),
62
+ capacityGal: z.number().min(0).max(500).default(50),
63
+ gasBtuh: z.number().min(0).max(500000).default(0),
64
+ watts: z.number().min(0).max(50000).default(4500),
65
+ roomVolumeCuFt: z.number().min(0).max(50000).optional(),
66
+ hasDrainPan: z.boolean().default(true),
67
+ hasTpDischarge: z.boolean().default(true),
68
+ hasExpansionTank: z.boolean().default(true),
69
+ electricalDemand: ElectricalDemandSchema.nullable().optional(),
70
+ furnishingSourceId: z.string().optional(),
71
+ catalogSku: z.string().optional(),
72
+ roughInOnly: z.boolean().default(false),
73
+ })
74
+
75
+ export type PlumbingEquipmentNode = z.infer<typeof PlumbingEquipmentNode>
76
+
77
+ export function getPlumbingEquipmentPorts(node: PlumbingEquipmentNode): NodePort[] {
78
+ const [x, y, zPos] = node.position
79
+ const rot = node.rotation ?? 0
80
+ const cos = Math.cos(rot)
81
+ const sin = Math.sin(rot)
82
+ const rotOffset = (lx: number, lz: number): [number, number] => [
83
+ x + lx * cos + lz * sin,
84
+ zPos - lx * sin + lz * cos,
85
+ ]
86
+
87
+ switch (node.equipmentKind) {
88
+ case 'gas-meter': {
89
+ const [gxIn, gzIn] = rotOffset(-0.11, 0)
90
+ const [gxOut, gzOut] = rotOffset(0.11, 0)
91
+ return [
92
+ { id: 'gas-in', position: [gxIn, y + 0.35, gzIn], direction: [0, 1, 0], diameter: 0.75, system: 'gas' },
93
+ { id: 'gas-out', position: [gxOut, y + 0.35, gzOut], direction: [0, 1, 0], diameter: 0.75, system: 'gas' },
94
+ ]
95
+ }
96
+ case 'water-heater-tankless-gas': {
97
+ const [cx, cz] = rotOffset(0.1, 0)
98
+ const [hx, hz] = rotOffset(-0.1, 0)
99
+ return [
100
+ { id: 'cold-in', position: [cx, y + 0.90, cz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
101
+ { id: 'hot-out', position: [hx, y + 0.90, hz], direction: [0, -1, 0], diameter: 0.75, system: 'water' },
102
+ { id: 'gas-in', position: [x, y + 0.90, zPos], direction: [0, -1, 0], diameter: 0.75, system: 'gas' },
103
+ ]
104
+ }
105
+ case 'expansion-tank':
106
+ return [
107
+ { id: 'water-in', position: [x, y + 0.25, zPos], direction: [0, 1, 0], diameter: 0.75, system: 'water' },
108
+ ]
109
+ case 'main-shutoff-prv':
110
+ return [
111
+ { id: 'main-in', position: [x, y - 0.28, zPos], direction: [0, -1, 0], diameter: 1, system: 'water' },
112
+ { id: 'main-out', position: [x, y + 0.28, zPos], direction: [0, 1, 0], diameter: 1, system: 'water' },
113
+ ]
114
+ case 'water-softener': {
115
+ const [inX, inZ] = rotOffset(-0.26, 0)
116
+ const [outX, outZ] = rotOffset(-0.18, 0)
117
+ return [
118
+ { id: 'cold-in', position: [inX, y + 1.32, inZ], direction: [0, 1, 0], diameter: 1, system: 'water' },
119
+ { id: 'cold-out', position: [outX, y + 1.32, outZ], direction: [0, 1, 0], diameter: 1, system: 'water' },
120
+ ]
121
+ }
122
+ case 'sump-pump': {
123
+ const [dx, dz] = rotOffset(0.08, 0)
124
+ return [
125
+ { id: 'discharge', position: [dx, y + 1.25, dz], direction: [0, 1, 0], diameter: 1.5, system: 'dwv' },
126
+ ]
127
+ }
128
+ case 'sewage-ejector': {
129
+ const [dx, dz] = rotOffset(0.08, 0)
130
+ const [vx, vz] = rotOffset(-0.09, 0)
131
+ return [
132
+ { id: 'discharge', position: [dx, y + 1.25, dz], direction: [0, 1, 0], diameter: 2, system: 'dwv' },
133
+ { id: 'vent', position: [vx, y + 1.25, vz], direction: [0, 1, 0], diameter: 2, system: 'dwv' },
134
+ ]
135
+ }
136
+ case 'recirc-pump': {
137
+ const [inX, inZ] = rotOffset(-0.10, 0)
138
+ const [outX, outZ] = rotOffset(0.10, 0)
139
+ return [
140
+ { id: 'recirc-in', position: [inX, y, inZ], direction: [-cos, 0, sin], diameter: 0.75, system: 'water' },
141
+ { id: 'recirc-out', position: [outX, y, outZ], direction: [cos, 0, -sin], diameter: 0.75, system: 'water' },
142
+ ]
143
+ }
144
+ case 'backwater-valve': {
145
+ const [inX, inZ] = rotOffset(-0.17, 0)
146
+ const [outX, outZ] = rotOffset(0.17, 0)
147
+ return [
148
+ { id: 'dwv-in', position: [inX, y, inZ], direction: [-cos, 0, sin], diameter: 3, system: 'dwv' },
149
+ { id: 'dwv-out', position: [outX, y, outZ], direction: [cos, 0, -sin], diameter: 3, system: 'dwv' },
150
+ ]
151
+ }
152
+ default: {
153
+ const [cx, cz] = rotOffset(0.1, 0)
154
+ const [hx, hz] = rotOffset(-0.1, 0)
155
+ const ports: NodePort[] = [
156
+ { id: 'cold-in', position: [cx, y + 1.45, cz], direction: [0, 1, 0], diameter: 0.75, system: 'water' },
157
+ { id: 'hot-out', position: [hx, y + 1.45, hz], direction: [0, 1, 0], diameter: 0.75, system: 'water' },
158
+ ]
159
+ if (node.equipmentKind === 'water-heater-tank-gas') {
160
+ const [gx, gz] = rotOffset(0, 0.30)
161
+ ports.push({ id: 'gas-in', position: [gx, y + 0.34, gz], direction: [sin, 0, cos], diameter: 0.5, system: 'gas' })
162
+ }
163
+ return ports
164
+ }
165
+ }
166
+ }
167
+
168
+ export function buildPlumbingEquipmentGeometry(
169
+ node: PlumbingEquipmentNode,
170
+ _ctx: GeometryContext,
171
+ ): Group {
172
+ const group = new Group()
173
+ group.name = `plumbing-equipment-${node.id}`
174
+ group.add(
175
+ buildEquipmentCad({
176
+ equipmentKind: node.equipmentKind as EquipmentKind,
177
+ capacityGal: node.capacityGal,
178
+ hasDrainPan: node.hasDrainPan,
179
+ roughInOnly: Boolean(node.roughInOnly),
180
+ }),
181
+ )
182
+ return group
183
+ }
184
+
185
+ const RECT_EQUIPMENT_FOOTPRINTS: Readonly<Partial<Record<EquipmentKind, readonly [number, number]>>> = {
186
+ 'gas-meter': [0.34, 0.24],
187
+ 'water-heater-tankless-gas': [0.40, 0.28],
188
+ 'water-softener': [0.76, 0.40],
189
+ 'main-shutoff-prv': [0.22, 0.14],
190
+ 'recirc-pump': [0.22, 0.14],
191
+ 'backwater-valve': [0.34, 0.16],
192
+ }
193
+
194
+ export function buildPlumbingEquipmentFloorplan(
195
+ node: PlumbingEquipmentNode,
196
+ ctx: GeometryContext,
197
+ ): FloorplanGeometry {
198
+ const view = ctx.viewState
199
+ const selected = (view?.selected || view?.highlighted) ?? false
200
+ const [cx, , cz] = node.position
201
+ const rot = node.rotation ?? 0
202
+ const cos = Math.cos(rot)
203
+ const sin = Math.sin(rot)
204
+ const toWorld = (lx: number, lz: number): [number, number] => [
205
+ cx + lx * cos + lz * sin,
206
+ cz - lx * sin + lz * cos,
207
+ ]
208
+
209
+ const baseStroke =
210
+ node.equipmentKind === 'gas-meter'
211
+ ? '#eab308'
212
+ : node.equipmentKind === 'sump-pump' ||
213
+ node.equipmentKind === 'sewage-ejector' ||
214
+ node.equipmentKind === 'backwater-valve'
215
+ ? '#64748b'
216
+ : '#2563eb'
217
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : baseStroke
218
+
219
+ if (node.roughInOnly) {
220
+ const r = 0.09
221
+ const children: FloorplanGeometry[] = [
222
+ { kind: 'circle', cx, cy: cz, r, fill: baseStroke, fillOpacity: 0.25, stroke, strokeWidth: 0.02 },
223
+ { kind: 'line', x1: cx - r, y1: cz, x2: cx + r, y2: cz, stroke, strokeWidth: 0.015 },
224
+ { kind: 'line', x1: cx, y1: cz - r, x2: cx, y2: cz + r, stroke, strokeWidth: 0.015 },
225
+ ]
226
+ if (selected) {
227
+ children.push({ kind: 'move-handle', point: [cx, cz] })
228
+ }
229
+ return { kind: 'group', children }
230
+ }
231
+
232
+ const rectDims = RECT_EQUIPMENT_FOOTPRINTS[node.equipmentKind as EquipmentKind]
233
+ const children: FloorplanGeometry[] = []
234
+
235
+ if (rectDims) {
236
+ const hw = rectDims[0] / 2
237
+ const hd = rectDims[1] / 2
238
+ const [fx1, fy1] = toWorld(-hw * 0.7, hd * 0.6)
239
+ const [fx2, fy2] = toWorld(hw * 0.7, hd * 0.6)
240
+ children.push(
241
+ {
242
+ kind: 'polygon',
243
+ points: [toWorld(-hw, -hd), toWorld(hw, -hd), toWorld(hw, hd), toWorld(-hw, hd)],
244
+ fill: baseStroke,
245
+ fillOpacity: 0.14,
246
+ stroke,
247
+ strokeWidth: 0.025,
248
+ },
249
+ { kind: 'line', x1: fx1, y1: fy1, x2: fx2, y2: fy2, stroke, strokeWidth: 0.02 },
250
+ )
251
+ } else {
252
+ const r =
253
+ node.equipmentKind.startsWith('water-heater-tank') || node.equipmentKind === 'water-heater-hpwh'
254
+ ? 0.3
255
+ : node.equipmentKind === 'expansion-tank'
256
+ ? 0.14
257
+ : 0.25
258
+ const [lx1, ly1] = toWorld(-r * 0.65, 0)
259
+ const [lx2, ly2] = toWorld(r * 0.65, 0)
260
+ const [lz1, lz1y] = toWorld(0, -r * 0.65)
261
+ const [lz2, lz2y] = toWorld(0, r * 0.95)
262
+ children.push(
263
+ {
264
+ kind: 'circle',
265
+ cx,
266
+ cy: cz,
267
+ r,
268
+ fill: baseStroke,
269
+ fillOpacity: 0.14,
270
+ stroke,
271
+ strokeWidth: 0.025,
272
+ },
273
+ { kind: 'line', x1: lx1, y1: ly1, x2: lx2, y2: ly2, stroke, strokeWidth: 0.02 },
274
+ { kind: 'line', x1: lz1, y1: lz1y, x2: lz2, y2: lz2y, stroke, strokeWidth: 0.02 },
275
+ )
276
+ }
277
+ if (selected) {
278
+ children.push({ kind: 'move-handle', point: [cx, cz] })
279
+ }
280
+ return { kind: 'group', children }
281
+ }
282
+
283
+ export const plumbingEquipmentRenderDefinition: NodeDefinition<typeof PlumbingEquipmentNode> = {
284
+ kind: 'plumbing:equipment',
285
+ schemaVersion: 1,
286
+ schema: PlumbingEquipmentNode,
287
+ category: 'utility',
288
+ distributionRole: 'equipment',
289
+ facingIndicator: true,
290
+ defaults: () => ({
291
+ object: 'node',
292
+ parentId: null,
293
+ visible: true,
294
+ metadata: {},
295
+ name: 'Water Heater (50 gal)',
296
+ position: [0, 0, 0],
297
+ rotation: 0,
298
+ equipmentKind: 'water-heater-tank-electric',
299
+ roomName: 'Utility',
300
+ capacityGal: 50,
301
+ gasBtuh: 0,
302
+ watts: 4500,
303
+ hasDrainPan: true,
304
+ hasTpDischarge: true,
305
+ hasExpansionTank: true,
306
+ electricalDemand: getEquipmentElectricalDemand('water-heater-tank-electric', 4500),
307
+ roughInOnly: false,
308
+ }),
309
+ capabilities: {
310
+ selectable: { hitVolume: 'bbox' },
311
+ movable: { axes: ['x', 'y', 'z'], gridSnap: true },
312
+ rotatable: { axes: ['y'], snapAngles: [Math.PI / 2] },
313
+ duplicable: true,
314
+ deletable: true,
315
+ snappable: {},
316
+ },
317
+ geometry: buildPlumbingEquipmentGeometry,
318
+ geometryKey: (n) => JSON.stringify([n.equipmentKind, n.capacityGal, n.hasDrainPan, Boolean(n.roughInOnly)]),
319
+ ports: getPlumbingEquipmentPorts,
320
+ floorplan: buildPlumbingEquipmentFloorplan,
321
+ presentation: {
322
+ label: 'Plumbing Equipment',
323
+ description: 'Water heaters (electric/gas tank, tankless, HPWH), expansion tanks, PRVs, softeners, pumps, and gas meters.',
324
+ icon: { kind: 'iconify', name: 'lucide:flame' },
325
+ paletteSection: 'structure',
326
+ },
327
+ mcp: {
328
+ description: 'Plumbing mechanical equipment with IPC safety flags and standardized cross-trade electricalDemand metadata.',
329
+ },
330
+ }
@@ -0,0 +1,245 @@
1
+ /**
2
+ * `plumbing:fixture` — 18 Residential & Light-Commercial Plumbing Fixture Rough-Ins.
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 { buildFixtureCad } from '../cad/fixtures'
18
+ import { getFixtureElectricalDemand } from '../ipc/framing-interop'
19
+ import { FIXTURE_SPECS, type FixtureKind, PIPE_NOMINAL_INCHES } from '../ipc/tables'
20
+ import { ElectricalDemandSchema } from './equipment'
21
+
22
+ const Vec3Schema = z.tuple([z.number(), z.number(), z.number()])
23
+
24
+ export const FixtureKindEnum = z.enum([
25
+ 'water-closet',
26
+ 'lavatory',
27
+ 'kitchen-sink',
28
+ 'bathtub',
29
+ 'shower',
30
+ 'tub-shower-combo',
31
+ 'dishwasher',
32
+ 'clothes-washer',
33
+ 'laundry-sink',
34
+ 'bar-sink',
35
+ 'floor-drain',
36
+ 'hose-bibb',
37
+ 'bidet',
38
+ 'garbage-disposal',
39
+ 'urinal',
40
+ 'mop-sink',
41
+ 'drinking-fountain',
42
+ 'grease-interceptor',
43
+ ])
44
+
45
+ export const PipeNominalSizeEnum = z.enum([
46
+ '3/8"',
47
+ '1/2"',
48
+ '3/4"',
49
+ '1"',
50
+ '1-1/4"',
51
+ '1-1/2"',
52
+ '2"',
53
+ '2-1/2"',
54
+ '3"',
55
+ '4"',
56
+ '6"',
57
+ ])
58
+
59
+ export const PlumbingFixtureNode = BaseNode.extend({
60
+ id: objectId('plumbfix'),
61
+ type: nodeType('plumbing:fixture'),
62
+ position: Vec3Schema.default([0, 0.53, 0]),
63
+ rotation: z.number().default(0),
64
+ fixtureKind: FixtureKindEnum.default('lavatory'),
65
+ roomName: z.string().default('Bathroom'),
66
+ wallId: z.string().optional(),
67
+ dfu: z.number().min(0).max(20).default(1),
68
+ wsfuCold: z.number().min(0).max(20).default(0.5),
69
+ wsfuHot: z.number().min(0).max(20).default(0.5),
70
+ wsfuTotal: z.number().min(0).max(25).default(0.7),
71
+ trapSize: PipeNominalSizeEnum.nullable().default('1-1/4"'),
72
+ drainSize: PipeNominalSizeEnum.nullable().default('1-1/2"'),
73
+ ventSize: PipeNominalSizeEnum.nullable().default('1-1/2"'),
74
+ supplySize: PipeNominalSizeEnum.nullable().default('1/2"'),
75
+ hasVacuumBreaker: z.boolean().default(false),
76
+ hasPTrap: z.boolean().default(true),
77
+ electricalDemand: ElectricalDemandSchema.nullable().optional(),
78
+ furnishingSourceId: z.string().optional(),
79
+ catalogSku: z.string().optional(),
80
+ roughInOnly: z.boolean().default(false),
81
+ })
82
+
83
+ export type PlumbingFixtureNode = z.infer<typeof PlumbingFixtureNode>
84
+
85
+ function rotateLocal2D(
86
+ cx: number,
87
+ cz: number,
88
+ lx: number,
89
+ lz: number,
90
+ rot: number,
91
+ ): [number, number] {
92
+ const cos = Math.cos(rot)
93
+ const sin = Math.sin(rot)
94
+ return [cx + lx * cos + lz * sin, cz - lx * sin + lz * cos]
95
+ }
96
+
97
+ export function getPlumbingFixturePorts(node: PlumbingFixtureNode): NodePort[] {
98
+ const [x, y, zPos] = node.position
99
+ const rot = node.rotation ?? 0
100
+ const backDir: [number, number, number] = [-Math.sin(rot), 0, -Math.cos(rot)]
101
+ const ports: NodePort[] = []
102
+ if (node.drainSize) {
103
+ const drainDia = PIPE_NOMINAL_INCHES[node.drainSize] ?? 2
104
+ ports.push({ id: 'drain', position: [x, Math.max(0, y - 0.15), zPos], direction: [0, -1, 0], diameter: drainDia, system: 'dwv' })
105
+ }
106
+ if (node.supplySize && (node.wsfuCold > 0 || node.wsfuHot > 0)) {
107
+ const supplyDia = PIPE_NOMINAL_INCHES[node.supplySize] ?? 0.5
108
+ if (node.wsfuCold > 0) {
109
+ const [cx, cz] = rotateLocal2D(x, zPos, 0.08, 0, rot)
110
+ ports.push({ id: 'cold', position: [cx, y, cz], direction: backDir, diameter: supplyDia, system: 'water' })
111
+ }
112
+ if (node.wsfuHot > 0) {
113
+ const [hx, hz] = rotateLocal2D(x, zPos, -0.08, 0, rot)
114
+ ports.push({ id: 'hot', position: [hx, y, hz], direction: backDir, diameter: supplyDia, system: 'water' })
115
+ }
116
+ }
117
+ return ports
118
+ }
119
+
120
+ export function buildPlumbingFixtureGeometry(
121
+ node: PlumbingFixtureNode,
122
+ _ctx: GeometryContext,
123
+ ): Group {
124
+ const group = new Group()
125
+ group.name = `plumbing-fixture-${node.id}`
126
+ const cad = buildFixtureCad({
127
+ fixtureKind: node.fixtureKind as FixtureKind,
128
+ roughInOnly: Boolean(node.roughInOnly),
129
+ })
130
+ const spec = FIXTURE_SPECS[node.fixtureKind as FixtureKind]
131
+ // Offset CAD by nominal rough-in height (not -node.position[1]) so Y-axis dragging moves the 3D fixture naturally
132
+ if (
133
+ spec &&
134
+ node.fixtureKind !== 'clothes-washer' &&
135
+ node.fixtureKind !== 'hose-bibb' &&
136
+ node.fixtureKind !== 'garbage-disposal'
137
+ ) {
138
+ cad.position.y = -spec.roughInHeightM
139
+ }
140
+ group.add(cad)
141
+ return group
142
+ }
143
+
144
+ export function buildPlumbingFixtureFloorplan(
145
+ node: PlumbingFixtureNode,
146
+ ctx: GeometryContext,
147
+ ): FloorplanGeometry {
148
+ const view = ctx.viewState
149
+ const selected = (view?.selected || view?.highlighted) ?? false
150
+ const [cx, , cz] = node.position
151
+ const rot = node.rotation ?? 0
152
+ const spec = FIXTURE_SPECS[node.fixtureKind as FixtureKind]
153
+ const hw = (spec?.dimensionsM[0] ?? 0.5) / 2
154
+ const hd = (spec?.dimensionsM[2] ?? 0.5) / 2
155
+ const baseStroke = node.fixtureKind === 'hose-bibb' ? '#2563eb' : '#0ea5e9'
156
+ const stroke = selected && view?.palette ? view.palette.selectedStroke : baseStroke
157
+
158
+ if (node.roughInOnly) {
159
+ // Compact 2D rough-in port marker when linked to a placed catalog/furnishing SKU (avoids drawing double footprints)
160
+ const r = 0.08
161
+ const children: FloorplanGeometry[] = [
162
+ { kind: 'circle', cx, cy: cz, r, fill: baseStroke, fillOpacity: 0.18, stroke, strokeWidth: 0.018 },
163
+ { kind: 'line', x1: cx - r, y1: cz, x2: cx + r, y2: cz, stroke, strokeWidth: 0.014 },
164
+ { kind: 'line', x1: cx, y1: cz - r, x2: cx, y2: cz + r, stroke, strokeWidth: 0.014 },
165
+ ]
166
+ if (selected) children.push({ kind: 'move-handle', point: [cx, cz] })
167
+ return { kind: 'group', children }
168
+ }
169
+
170
+ const p0 = rotateLocal2D(cx, cz, -hw, -hd, rot)
171
+ const p1 = rotateLocal2D(cx, cz, hw, -hd, rot)
172
+ const p2 = rotateLocal2D(cx, cz, hw, hd, rot)
173
+ const p3 = rotateLocal2D(cx, cz, -hw, hd, rot)
174
+ const d0 = rotateLocal2D(cx, cz, -hw * 0.5, -hd * 0.5, rot)
175
+ const d1 = rotateLocal2D(cx, cz, hw * 0.5, hd * 0.5, rot)
176
+
177
+ const children: FloorplanGeometry[] = [
178
+ {
179
+ kind: 'polygon',
180
+ points: [p0, p1, p2, p3],
181
+ fill: baseStroke,
182
+ fillOpacity: 0.12,
183
+ stroke,
184
+ strokeWidth: 0.02,
185
+ },
186
+ { kind: 'line', x1: d0[0], y1: d0[1], x2: d1[0], y2: d1[1], stroke, strokeWidth: 0.015 },
187
+ ]
188
+ if (selected) {
189
+ children.push({ kind: 'move-handle', point: [cx, cz] })
190
+ }
191
+ return { kind: 'group', children }
192
+ }
193
+
194
+ export const plumbingFixtureRenderDefinition: NodeDefinition<typeof PlumbingFixtureNode> = {
195
+ kind: 'plumbing:fixture',
196
+ schemaVersion: 1,
197
+ schema: PlumbingFixtureNode,
198
+ category: 'utility',
199
+ distributionRole: 'terminal',
200
+ facingIndicator: true,
201
+ defaults: () => ({
202
+ object: 'node',
203
+ parentId: null,
204
+ visible: true,
205
+ metadata: {},
206
+ name: 'Lavatory Rough-In',
207
+ position: [0, 0.53, 0],
208
+ rotation: 0,
209
+ fixtureKind: 'lavatory',
210
+ roomName: 'Bathroom',
211
+ dfu: 1,
212
+ wsfuCold: 0.5,
213
+ wsfuHot: 0.5,
214
+ wsfuTotal: 0.7,
215
+ trapSize: '1-1/4"',
216
+ drainSize: '1-1/2"',
217
+ ventSize: '1-1/2"',
218
+ supplySize: '1/2"',
219
+ hasVacuumBreaker: false,
220
+ hasPTrap: true,
221
+ electricalDemand: getFixtureElectricalDemand('lavatory'),
222
+ roughInOnly: false,
223
+ }),
224
+ capabilities: {
225
+ selectable: { hitVolume: 'bbox' },
226
+ movable: { axes: ['x', 'y', 'z'], gridSnap: true },
227
+ rotatable: { axes: ['y'], snapAngles: [Math.PI / 2] },
228
+ duplicable: true,
229
+ deletable: true,
230
+ snappable: {},
231
+ },
232
+ geometry: buildPlumbingFixtureGeometry,
233
+ geometryKey: (n) => JSON.stringify([n.fixtureKind, Boolean(n.roughInOnly)]),
234
+ ports: getPlumbingFixturePorts,
235
+ floorplan: buildPlumbingFixtureFloorplan,
236
+ presentation: {
237
+ label: 'Plumbing Fixture',
238
+ description: 'Residential & commercial plumbing fixture rough-in with IPC DFU/WSFU units and drain/vent/supply ports.',
239
+ icon: { kind: 'iconify', name: 'lucide:bath' },
240
+ paletteSection: 'structure',
241
+ },
242
+ mcp: {
243
+ description: 'Plumbing fixture node tracking DFU, cold/hot WSFU, rough-in sizes, P-trap, and electricalDemand metadata.',
244
+ },
245
+ }