@kruschdev/pascal-plugin-furnishings 0.0.0-stage → 0.2.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.
@@ -0,0 +1,273 @@
1
+ /**
2
+ * Pure Zod-only Agent Tool Contracts (`@kruschdev/pascal-plugin-furnishings/agent-tools`).
3
+ * Conforms to Pascal DECISIONS.md E-016: zero Three.js, React, viewer, or editor imports.
4
+ */
5
+
6
+ import type { PluginAgentTools } from '@pascal-app/core/agent-tools'
7
+ import { z } from 'zod'
8
+ import { FURNISHINGS_CATALOG } from './furnishings/catalog'
9
+ import {
10
+ BUDGET_TIERS,
11
+ ELECTRONICS_CHANNEL_ROLES,
12
+ ELECTRONICS_FINISHES,
13
+ ELECTRONICS_MOUNT_STYLES,
14
+ FABRIC_FINISHES,
15
+ FURNISHING_DOMAINS,
16
+ METAL_FINISHES,
17
+ PLANT_MATURITIES,
18
+ PLANT_PLACEMENTS,
19
+ PLANT_SEASONS,
20
+ POT_STYLES,
21
+ SCREEN_STATES,
22
+ STYLE_PRESETS,
23
+ WOOD_FINISHES,
24
+ } from './furnishings/types'
25
+ import { DEFAULT_STAGING_DESIGN_AXES } from './furnishings/spatial-grounding'
26
+
27
+ const Vec2Xz = z.tuple([z.number().finite(), z.number().finite()])
28
+ const Vec3 = z.tuple([z.number().finite(), z.number().finite(), z.number().finite()])
29
+
30
+ export const furnishingsAgentTools: PluginAgentTools = {
31
+ pluginId: 'krusch:furnishings',
32
+ apiVersion: 1,
33
+ version: '0.1.0',
34
+ instructions:
35
+ `FF&E, Consumer Electronics/AV/Workstations, Architectural Lighting, Decorative HVAC Grates, Soft Goods, Outdoor Living, and Procedural Botanicals & Landscape Plants plugin (${FURNISHINGS_CATALOG.length} curated non-cabinetry item kinds across 7 domains: Seating, Tables & Desks, Beds & Freestanding Storage, TVs/Audio/Computers, Rugs/Lights/Grates/Decor, Outdoor/Patio, and Trees/Bushes/Hedges/Houseplants). Coordinates plug-in electrical loads with krusch:electrical and decorative HVAC grates with krusch:hvac, while excluding built-in cabinetry and concealed MEP distribution.`,
36
+ skills: [
37
+ {
38
+ name: 'furnishings-staging-landscaping',
39
+ summary: 'Stage rooms with furniture, TVs, speakers, computers, houseplants, and exterior trees/bushes, then audit clearances & export CSI Div 12/23/26/27/32 BOM',
40
+ body: [
41
+ '1. Run `furnishings_autopopulate` to stage all detected rooms and exterior yard beds with style-coherent furniture, AV/computers, houseplants, and landscape trees/bushes.',
42
+ `2. Search the ${FURNISHINGS_CATALOG.length}-item catalog via \`furnishings_search_catalog\` and place individual items using \`furnishings_place_item\`, \`furnishings_place_electronics\`, or \`furnishings_place_plant\`.`,
43
+ '3. Swap finishes, species, screen sizes, or compatible sibling items live with `furnishings_swap_item`.',
44
+ '4. Run `furnishings_audit_layout` to check overlaps, door egress clearances, TV viewing distance, stereo symmetry, 15A branch circuit loads, and tree-to-foundation clearance.',
45
+ '5. Run `furnishings_compile_render_prompt` for grounded camera-relative interior render prompts + right-handed wall elevations, and `furnishings_check_directions_diversity` to verify multi-option staging proposals differ on >= 4 of 7 structural axes.',
46
+ '6. Run `furnishings_generate_schedule` to produce the room staging schedule, electrical load handoff, botanical schedule, and CSI Div 12/23/26/27/32 priced BOM CSV.',
47
+ ].join('\n'),
48
+ },
49
+ ],
50
+ tools: [
51
+ {
52
+ name: 'furnishings_autopopulate',
53
+ title: 'Auto-furnish interior rooms & landscape exterior yard',
54
+ description:
55
+ 'Scan rooms, walls, doors, and building footprint to stage living rooms, bedrooms, dining rooms, home offices, media rooms, patios, and exterior foundation bushes, privacy hedges, and shade/ornamental trees.',
56
+ runsIn: 'operation',
57
+ input: {
58
+ levelId: z.string().optional(),
59
+ stylePreset: z.enum(STYLE_PRESETS).default('mid-century'),
60
+ budgetTier: z.enum(BUDGET_TIERS).default('mid-tier'),
61
+ season: z.enum(PLANT_SEASONS).default('summer'),
62
+ includeInteriorFurniture: z.boolean().default(true),
63
+ includeElectronics: z.boolean().default(true),
64
+ includeHouseplants: z.boolean().default(true),
65
+ includeRugsAndDecor: z.boolean().default(true),
66
+ includeExteriorLandscaping: z.boolean().default(true),
67
+ clearExisting: z.boolean().default(true),
68
+ },
69
+ annotations: { destructiveHint: true, idempotentHint: false },
70
+ },
71
+ {
72
+ name: 'furnishings_search_catalog',
73
+ title: `Search ${FURNISHINGS_CATALOG.length} furnishings, electronics & botanical plant kinds`,
74
+ description:
75
+ 'Search the curated non-cabinetry catalog by keyword or domain (seating, tables-desks, beds-storage, electronics-av, soft-goods-decor, outdoor-patio, trees-plants).',
76
+ runsIn: 'operation',
77
+ input: {
78
+ query: z.string().default(''),
79
+ domain: z.enum(FURNISHING_DOMAINS).optional(),
80
+ outdoorOnly: z.boolean().optional(),
81
+ indoorOnly: z.boolean().optional(),
82
+ limit: z.number().int().min(1).max(100).default(25),
83
+ },
84
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
85
+ },
86
+ {
87
+ name: 'furnishings_place_item',
88
+ title: 'Place a furniture, rug, lamp, luminaire, HVAC grate, decor, or outdoor patio piece',
89
+ description:
90
+ 'Place any seating, table, desk, bed, freestanding storage, rug, lamp, architectural luminaire, decorative HVAC grate/grille, decor, or outdoor patio furnishing (excludes cabinetry).',
91
+ runsIn: 'operation',
92
+ input: {
93
+ levelId: z.string().optional(),
94
+ itemKind: z.string().default('sofa-3seat'),
95
+ name: z.string().optional(),
96
+ position: Vec3.optional(),
97
+ rotation: z.number().finite().default(0),
98
+ roomName: z.string().default('Living Room'),
99
+ stylePreset: z.enum(STYLE_PRESETS).default('mid-century'),
100
+ woodFinish: z.enum(WOOD_FINISHES).optional(),
101
+ fabricFinish: z.enum(FABRIC_FINISHES).optional(),
102
+ metalFinish: z.enum(METAL_FINISHES).optional(),
103
+ widthM: z.number().finite().min(0.15).max(10).optional(),
104
+ depthM: z.number().finite().min(0.03).max(10).optional(),
105
+ heightM: z.number().finite().min(0.01).max(6).optional(),
106
+ quantity: z.number().int().min(1).max(200).default(1),
107
+ unitPriceOverrideUsd: z.number().finite().min(0).optional(),
108
+ customSku: z.string().optional(),
109
+ customBrand: z.string().optional(),
110
+ customGlbUrl: z.string().optional(),
111
+ notes: z.string().default(''),
112
+ },
113
+ annotations: { destructiveHint: false, idempotentHint: false },
114
+ },
115
+ {
116
+ name: 'furnishings_place_electronics',
117
+ title: 'Place a TV, speaker system, projector, AV rack, or computer workstation',
118
+ description:
119
+ 'Place an OLED TV, projector/screen, Dolby soundbar, tower/bookshelf/center speaker, subwoofer, AV receiver, turntable, or desktop/laptop PC workstation with wattage tracking.',
120
+ runsIn: 'operation',
121
+ input: {
122
+ levelId: z.string().optional(),
123
+ itemKind: z.string().default('tv-oled-wall'),
124
+ name: z.string().optional(),
125
+ position: Vec3.optional(),
126
+ rotation: z.number().finite().default(0),
127
+ roomName: z.string().default('Living Room'),
128
+ screenDiagonalIn: z.number().finite().min(13).max(150).optional(),
129
+ mountStyle: z.enum(ELECTRONICS_MOUNT_STYLES).optional(),
130
+ finish: z.enum(ELECTRONICS_FINISHES).default('matte-black'),
131
+ widthM: z.number().finite().min(0.12).max(5).optional(),
132
+ depthM: z.number().finite().min(0.03).max(2).optional(),
133
+ heightM: z.number().finite().min(0.05).max(3).optional(),
134
+ wattageW: z.number().finite().min(0).max(4000).optional(),
135
+ channelRole: z.enum(ELECTRONICS_CHANNEL_ROLES).optional(),
136
+ screenState: z.enum(SCREEN_STATES).default('ambient'),
137
+ quantity: z.number().int().min(1).max(100).default(1),
138
+ unitPriceOverrideUsd: z.number().finite().min(0).optional(),
139
+ customSku: z.string().optional(),
140
+ customBrand: z.string().optional(),
141
+ customGlbUrl: z.string().optional(),
142
+ notes: z.string().default(''),
143
+ },
144
+ annotations: { destructiveHint: false, idempotentHint: false },
145
+ },
146
+ {
147
+ name: 'furnishings_place_plant',
148
+ title: 'Place a tree, bush, hedge, shrub, grass, or potted indoor houseplant',
149
+ description:
150
+ 'Place a procedural oak, Japanese maple, pine, cypress, palm, olive tree, boxwood bush, privacy hedge, hydrangea, ornamental grass, fiddle-leaf fig, monstera, snake plant, fern, or succulent trough.',
151
+ runsIn: 'operation',
152
+ input: {
153
+ levelId: z.string().optional(),
154
+ plantKind: z.string().default('tree-oak-deciduous'),
155
+ name: z.string().optional(),
156
+ position: Vec3.optional(),
157
+ rotation: z.number().finite().default(0),
158
+ zoneName: z.string().default('Yard'),
159
+ placement: z.enum(PLANT_PLACEMENTS).optional(),
160
+ species: z.string().optional(),
161
+ maturity: z.enum(PLANT_MATURITIES).default('mature'),
162
+ season: z.enum(PLANT_SEASONS).default('summer'),
163
+ potStyle: z.enum(POT_STYLES).optional(),
164
+ heightM: z.number().finite().min(0.2).max(25).optional(),
165
+ canopyRadiusM: z.number().finite().min(0.12).max(12).optional(),
166
+ seed: z.number().int().min(1).max(999999).default(42),
167
+ quantity: z.number().int().min(1).max(200).default(1),
168
+ unitPriceOverrideUsd: z.number().finite().min(0).optional(),
169
+ customSku: z.string().optional(),
170
+ customBrand: z.string().optional(),
171
+ customGlbUrl: z.string().optional(),
172
+ notes: z.string().default(''),
173
+ },
174
+ annotations: { destructiveHint: false, idempotentHint: false },
175
+ },
176
+ {
177
+ name: 'furnishings_swap_item',
178
+ title: 'Swap a placed furnishing, electronics, or plant to a sibling kind or new finish/season',
179
+ description:
180
+ 'Atomically swap a placed item to another compatible catalog kind (resetting default dimensions & clearing stale price overrides) or update finishes, screen size, maturity, season, or pot style.',
181
+ runsIn: 'operation',
182
+ input: {
183
+ nodeId: z.string(),
184
+ newKind: z.string().optional(),
185
+ woodFinish: z.enum(WOOD_FINISHES).optional(),
186
+ fabricFinish: z.enum(FABRIC_FINISHES).optional(),
187
+ metalFinish: z.enum(METAL_FINISHES).optional(),
188
+ electronicsFinish: z.enum(ELECTRONICS_FINISHES).optional(),
189
+ screenDiagonalIn: z.number().finite().min(13).max(150).optional(),
190
+ screenState: z.enum(SCREEN_STATES).optional(),
191
+ maturity: z.enum(PLANT_MATURITIES).optional(),
192
+ season: z.enum(PLANT_SEASONS).optional(),
193
+ potStyle: z.enum(POT_STYLES).optional(),
194
+ wattageW: z.number().finite().min(0).max(4000).optional(),
195
+ quantity: z.number().int().min(1).max(200).optional(),
196
+ unitPriceOverrideUsd: z.number().finite().min(0).optional(),
197
+ customSku: z.string().optional(),
198
+ customBrand: z.string().optional(),
199
+ customGlbUrl: z.string().optional(),
200
+ },
201
+ annotations: { destructiveHint: false, idempotentHint: true },
202
+ },
203
+ {
204
+ name: 'furnishings_audit_layout',
205
+ title: 'Audit furnishings for clearances, ergonomics, AV acoustics, electrical loads & tree roots',
206
+ description:
207
+ 'Check footprint overlaps, doorway egress clearance, coffee-table reach, TV viewing distance & eye-level mount, stereo speaker symmetry, 15A circuit plug-in load limits, outlet proximity, and exterior tree foundation clearances.',
208
+ runsIn: 'operation',
209
+ input: {},
210
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
211
+ },
212
+ {
213
+ name: 'furnishings_generate_schedule',
214
+ title: 'Generate FF&E room schedule, electrical load handoff, botanical schedule & CSI BOM CSV',
215
+ description:
216
+ 'Compile room-by-room staging summaries, electronics wattage handoff to krusch:electrical, botanical plant counts, and consolidated CSI Division 12/23/26/27/32 priced BOM with formula-safe CSV exports.',
217
+ runsIn: 'operation',
218
+ input: {
219
+ markupPct: z.number().finite().min(0).max(200).default(0),
220
+ salesTaxPct: z.number().finite().min(0).max(25).default(0),
221
+ budgetTier: z.enum(BUDGET_TIERS).optional(),
222
+ stylePreset: z.enum(STYLE_PRESETS).optional(),
223
+ season: z.enum(PLANT_SEASONS).optional(),
224
+ },
225
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
226
+ },
227
+ {
228
+ name: 'furnishings_compile_render_prompt',
229
+ title: 'Compile grounded interior render prompt & right-handed wall elevations for a room',
230
+ description:
231
+ 'Project a staged room into right-handed wall elevations and compile a hallucination-guarded camera render prompt with solid-wall invariants, tight-room scale lock, camera LEFT/AHEAD/RIGHT/BEHIND orientation, and scene conflict auditing.',
232
+ runsIn: 'operation',
233
+ input: {
234
+ roomIdOrName: z.string().trim().min(1).default('Living Room'),
235
+ levelId: z.string().trim().min(1).optional(),
236
+ viewId: z.string().trim().min(1).default('hero-in'),
237
+ fromXz: Vec2Xz.optional(),
238
+ lookAtXz: Vec2Xz.optional(),
239
+ camera: z.string().optional(),
240
+ scene: z.string().optional(),
241
+ mustAppear: z.array(z.string().trim().min(1)).optional(),
242
+ shellNotes: z.array(z.string()).optional(),
243
+ includeStagedItemsInMustAppear: z.boolean().default(true),
244
+ },
245
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
246
+ },
247
+ {
248
+ name: 'furnishings_check_directions_diversity',
249
+ title: 'Verify multi-option room staging directions differ on >= 4 of 7 structural axes',
250
+ description:
251
+ `Audit candidate interior staging directions across (${DEFAULT_STAGING_DESIGN_AXES.join(', ')}) with lexical Jaccard near-duplicate rejection and required budget-tier coverage.`,
252
+ runsIn: 'operation',
253
+ input: {
254
+ candidates: z
255
+ .array(
256
+ z.object({
257
+ id: z.string().trim().min(1),
258
+ name: z.string().optional(),
259
+ budgetTier: z.enum(BUDGET_TIERS).optional(),
260
+ axes: z.record(z.string(), z.string()),
261
+ }),
262
+ )
263
+ .min(1)
264
+ .max(30),
265
+ axes: z.array(z.string().trim().min(1)).min(1).max(20).optional(),
266
+ minDifferingAxes: z.number().int().min(1).max(20).optional(),
267
+ similarityThreshold: z.number().finite().gt(0).max(1).default(0.72),
268
+ requiredBudgetTiers: z.array(z.enum(BUDGET_TIERS)).optional(),
269
+ },
270
+ annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true },
271
+ },
272
+ ],
273
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Complete 86-Model Procedural Furnishings, Lighting, Architectural Grates, Electronics & Botanicals CAD Catalog (`src/cad/catalog.ts`).
3
+ * Editor-free & React-free: powers both live Pascal 3D rendering and `bun run export:cad` (.glb).
4
+ */
5
+
6
+ import type { Group } from 'three'
7
+ import { FURNISHINGS_CATALOG, getFurnishingSpec } from '../furnishings/catalog'
8
+ import type {
9
+ ElectronicsFinish,
10
+ ElectronicsMountStyle,
11
+ FabricFinish,
12
+ FurnishingDomain,
13
+ MetalFinish,
14
+ PlantMaturity,
15
+ PlantSeason,
16
+ PotStyle,
17
+ ScreenState,
18
+ WoodFinish,
19
+ } from '../furnishings/types'
20
+ import { buildElectronicsCad } from './electronics-geometry'
21
+ import { buildFurnitureCad } from './furniture-geometry'
22
+ import { buildPlantCad } from './plants-geometry'
23
+
24
+ export type FurnishingCadPart = {
25
+ readonly id: string
26
+ readonly label: string
27
+ readonly domain: FurnishingDomain
28
+ readonly csiDivision: string
29
+ readonly build: () => Group
30
+ }
31
+
32
+ export type UnifiedCadBuildParams = {
33
+ readonly kind: string
34
+ readonly widthM?: number
35
+ readonly depthM?: number
36
+ readonly heightM?: number
37
+ readonly woodFinish?: WoodFinish
38
+ readonly fabricFinish?: FabricFinish
39
+ readonly metalFinish?: MetalFinish
40
+ readonly electronicsFinish?: ElectronicsFinish
41
+ readonly screenDiagonalIn?: number
42
+ readonly mountStyle?: ElectronicsMountStyle
43
+ readonly screenState?: ScreenState
44
+ readonly maturity?: PlantMaturity
45
+ readonly season?: PlantSeason
46
+ readonly potStyle?: PotStyle
47
+ readonly canopyRadiusM?: number
48
+ readonly seed?: number
49
+ }
50
+
51
+ function posNum(value: number | undefined, fallback: number, min = 0.01, max = 50): number {
52
+ const raw = typeof value === 'number' && Number.isFinite(value) ? value : fallback
53
+ return Math.min(max, Math.max(min, raw))
54
+ }
55
+
56
+ export function buildFurnishingCadByKind(params: UnifiedCadBuildParams): Group {
57
+ const spec = getFurnishingSpec(params.kind)
58
+ const widthM = posNum(params.widthM, spec?.widthM ?? 0.8, 0.05, 25)
59
+ const depthM = posNum(params.depthM, spec?.depthM ?? 0.8, 0.02, 25)
60
+ const heightM = posNum(params.heightM, spec?.heightM ?? 0.8, 0.01, 30)
61
+
62
+ if (spec?.nodeType === 'furnishings:plant' || params.kind.startsWith('tree-') || params.kind.startsWith('bush-') || params.kind.startsWith('plant-')) {
63
+ return buildPlantCad({
64
+ kind: params.kind,
65
+ heightM: posNum(params.heightM, spec?.heightM ?? heightM, 0.15, 25),
66
+ canopyRadiusM: posNum(params.canopyRadiusM, widthM / 2, 0.1, 15),
67
+ maturity: params.maturity ?? 'mature',
68
+ season: params.season ?? 'summer',
69
+ potStyle: params.potStyle ?? spec?.defaultPotStyle ?? 'none',
70
+ seed: typeof params.seed === 'number' && Number.isFinite(params.seed) ? Math.max(1, Math.min(999999, Math.round(params.seed))) : 42,
71
+ })
72
+ }
73
+
74
+ if (spec?.nodeType === 'furnishings:electronics') {
75
+ const rawDiag = params.screenDiagonalIn ?? spec.defaultScreenDiagonalIn
76
+ const screenDiagonalIn =
77
+ typeof rawDiag === 'number' && Number.isFinite(rawDiag) ? Math.min(150, Math.max(13, rawDiag)) : undefined
78
+ return buildElectronicsCad({
79
+ kind: params.kind,
80
+ widthM,
81
+ depthM,
82
+ heightM,
83
+ screenDiagonalIn,
84
+ mountStyle: params.mountStyle ?? spec.defaultMountStyle,
85
+ finish: params.electronicsFinish ?? 'matte-black',
86
+ screenState: params.screenState ?? 'ambient',
87
+ })
88
+ }
89
+
90
+ return buildFurnitureCad({
91
+ kind: params.kind,
92
+ widthM,
93
+ depthM,
94
+ heightM,
95
+ woodFinish: params.woodFinish ?? 'natural-oak',
96
+ fabricFinish: params.fabricFinish ?? 'warm-linen',
97
+ metalFinish: params.metalFinish ?? (params.kind === 'vent-grate-floor-brass' ? 'brushed-brass' : 'matte-black'),
98
+ })
99
+ }
100
+
101
+ export const FURNISHINGS_CAD_CATALOG: readonly FurnishingCadPart[] = FURNISHINGS_CATALOG.map((spec) => ({
102
+ id: spec.kind,
103
+ label: spec.label,
104
+ domain: spec.domain,
105
+ csiDivision: spec.csiDivision,
106
+ build: () => buildFurnishingCadByKind({ kind: spec.kind }),
107
+ }))
@@ -0,0 +1,298 @@
1
+ /**
2
+ * Clean-Room MIT Procedural 3D CAD Builders for Consumer Electronics, TVs, Speakers & Computers (14 items).
3
+ *
4
+ * All geometry is emitted in local space grounded at `y = 0` relative to the node's mount elevation.
5
+ * Zero React or `@pascal-app/*` imports.
6
+ */
7
+
8
+ import {
9
+ BoxGeometry,
10
+ CylinderGeometry,
11
+ Group,
12
+ Mesh,
13
+ type MeshStandardMaterial,
14
+ TorusGeometry,
15
+ } from 'three'
16
+ import { deriveDisplayDimensionsM, getFurnishingSpec } from '../furnishings/catalog'
17
+ import type { ElectronicsFinish, ElectronicsMountStyle, ScreenState } from '../furnishings/types'
18
+ import { createFurnishingsMaterialPool } from './materials'
19
+
20
+ export type ElectronicsCadParams = {
21
+ readonly kind: string
22
+ readonly widthM: number
23
+ readonly depthM: number
24
+ readonly heightM: number
25
+ readonly screenDiagonalIn?: number
26
+ readonly mountStyle?: ElectronicsMountStyle
27
+ readonly finish?: ElectronicsFinish
28
+ readonly screenState?: ScreenState
29
+ }
30
+
31
+ function addBox(
32
+ parent: Group,
33
+ w: number,
34
+ h: number,
35
+ d: number,
36
+ x: number,
37
+ y: number,
38
+ z: number,
39
+ mat: MeshStandardMaterial,
40
+ rotX = 0,
41
+ rotY = 0,
42
+ ): Mesh {
43
+ const m = new Mesh(new BoxGeometry(Math.max(0.004, w), Math.max(0.004, h), Math.max(0.004, d)), mat)
44
+ m.position.set(x, y, z)
45
+ if (rotX) m.rotation.x = rotX
46
+ if (rotY) m.rotation.y = rotY
47
+ m.castShadow = true
48
+ m.receiveShadow = true
49
+ parent.add(m)
50
+ return m
51
+ }
52
+
53
+ function addCyl(
54
+ parent: Group,
55
+ rTop: number,
56
+ rBot: number,
57
+ h: number,
58
+ x: number,
59
+ y: number,
60
+ z: number,
61
+ mat: MeshStandardMaterial,
62
+ seg = 18,
63
+ rotX = 0,
64
+ ): Mesh {
65
+ const m = new Mesh(new CylinderGeometry(Math.max(0.003, rTop), Math.max(0.003, rBot), Math.max(0.004, h), seg), mat)
66
+ m.position.set(x, y, z)
67
+ if (rotX) m.rotation.x = rotX
68
+ m.castShadow = true
69
+ m.receiveShadow = true
70
+ parent.add(m)
71
+ return m
72
+ }
73
+
74
+ function addSpeakerDriver(
75
+ parent: Group,
76
+ x: number,
77
+ y: number,
78
+ z: number,
79
+ radius: number,
80
+ coneMat: MeshStandardMaterial,
81
+ ringMat: MeshStandardMaterial,
82
+ ) {
83
+ const ring = new Mesh(new TorusGeometry(radius, radius * 0.12, 10, 22), ringMat)
84
+ ring.position.set(x, y, z)
85
+ parent.add(ring)
86
+ addCyl(parent, radius * 0.85, radius * 0.3, 0.016, x, y, z - 0.004, coneMat, 18, Math.PI / 2)
87
+ }
88
+
89
+ export function buildElectronicsCad(params: ElectronicsCadParams): Group {
90
+ const clampDim = (v: number, fallback: number, min: number, max: number): number =>
91
+ Number.isFinite(v) ? Math.min(max, Math.max(min, v)) : fallback
92
+ let w = clampDim(params.widthM, 0.8, 0.14, 10)
93
+ const d = clampDim(params.depthM, 0.25, 0.03, 10)
94
+ let h = clampDim(params.heightM, 0.5, 0.06, 6)
95
+
96
+ const pool = createFurnishingsMaterialPool()
97
+ // Lazy per-build getters so unused DataTextures / PBR materials are never allocated or leaked.
98
+ const chassis = () => pool.electronics(params.finish ?? 'matte-black')
99
+ const screenMat = () => pool.screen(params.screenState ?? 'ambient')
100
+ const grille = () => pool.acousticGrille('#1d2025')
101
+ const coneMat = () => pool.make({ color: '#17191d', roughness: 0.45, metalness: 0.35 })
102
+ const copperRing = () => pool.make({ color: '#d97706', roughness: 0.25, metalness: 0.85 })
103
+ const ledCyan = () => pool.make({ color: '#38bdf8', roughness: 0.2, emissive: '#38bdf8', emissiveIntensity: 1.2 })
104
+ const silver = () => pool.metal('brushed-nickel')
105
+
106
+ const g = new Group()
107
+ g.name = `electronics:${params.kind}`
108
+
109
+ // Derive 16:9 display dimensions from screenDiagonalIn when using catalog default width/height
110
+ const spec = getFurnishingSpec(params.kind)
111
+ const usesCatalogDefaults =
112
+ (!Number.isFinite(params.widthM) || params.widthM === spec?.widthM) &&
113
+ (!Number.isFinite(params.heightM) || params.heightM === spec?.heightM)
114
+ const derived = deriveDisplayDimensionsM(params.kind, params.screenDiagonalIn)
115
+ if (derived && usesCatalogDefaults) {
116
+ w = derived.widthM
117
+ h = derived.heightM
118
+ }
119
+
120
+ switch (params.kind) {
121
+ case 'tv-oled-wall': {
122
+ // Low-profile VESA wall bracket + ultra-thin OLED panel + emissive display
123
+ addBox(g, w * 0.42, h * 0.42, 0.026, 0, h / 2, -0.014, silver())
124
+ addBox(g, w, h, 0.026, 0, h / 2, 0.006, chassis())
125
+ addBox(g, w - 0.022, h - 0.024, 0.008, 0, h / 2, 0.02, screenMat())
126
+ // Status LED dot
127
+ addBox(g, 0.018, 0.006, 0.006, 0, 0.01, 0.022, ledCyan())
128
+ return g
129
+ }
130
+
131
+ case 'tv-oled-stand': {
132
+ const standH = 0.085
133
+ const panelH = h - standH
134
+ // Weighted base plate + center neck
135
+ addBox(g, w * 0.34, 0.018, Math.max(0.2, d), 0, 0.009, 0, silver())
136
+ addBox(g, 0.14, standH + 0.06, 0.04, 0, standH / 2 + 0.02, -0.03, chassis())
137
+ // Ultra-slim display
138
+ addBox(g, w, panelH, 0.028, 0, standH + panelH / 2, 0, chassis())
139
+ addBox(g, w - 0.022, panelH - 0.024, 0.008, 0, standH + panelH / 2, 0.016, screenMat())
140
+ return g
141
+ }
142
+
143
+ case 'projector-ceiling': {
144
+ // Ceiling pole + laser projector body + recessed glass lens
145
+ addCyl(g, 0.02, 0.02, h * 0.45, 0, h * 0.77, 0, silver(), 12)
146
+ addBox(g, w, h * 0.46, d, 0, h * 0.34, 0, chassis())
147
+ addCyl(g, 0.055, 0.055, 0.04, 0, h * 0.34, d / 2 + 0.01, silver(), 20, Math.PI / 2)
148
+ addCyl(g, 0.044, 0.044, 0.02, 0, h * 0.34, d / 2 + 0.025, pool.glass('#38bdf8', 0.75), 20, Math.PI / 2)
149
+ return g
150
+ }
151
+
152
+ case 'projector-screen': {
153
+ const border = 0.055
154
+ addBox(g, w, h, d, 0, h / 2, 0, chassis())
155
+ addBox(
156
+ g,
157
+ w - border * 2,
158
+ h - border * 2,
159
+ 0.008,
160
+ 0,
161
+ h / 2,
162
+ d / 2 + 0.002,
163
+ params.screenState === 'off'
164
+ ? pool.make({ color: '#e5e7eb', roughness: 0.85 })
165
+ : screenMat(),
166
+ )
167
+ return g
168
+ }
169
+
170
+ case 'soundbar-dolby': {
171
+ addBox(g, w, h, d, 0, h / 2, 0, chassis())
172
+ addBox(g, w - 0.03, h - 0.016, 0.01, 0, h / 2, d / 2 + 0.003, grille())
173
+ addBox(g, 0.05, 0.008, 0.008, 0, h * 0.5, d / 2 + 0.008, ledCyan())
174
+ return g
175
+ }
176
+
177
+ case 'speaker-tower': {
178
+ // Plinth base + tall enclosure + tweeter + midrange + dual woofers
179
+ addBox(g, w + 0.05, 0.03, d + 0.05, 0, 0.015, 0, silver())
180
+ addBox(g, w, h - 0.03, d, 0, 0.03 + (h - 0.03) / 2, 0, chassis())
181
+ addBox(g, w - 0.03, h - 0.08, 0.01, 0, 0.03 + (h - 0.03) / 2, d / 2 + 0.003, grille())
182
+ addSpeakerDriver(g, 0, h * 0.84, d / 2 + 0.012, w * 0.16, coneMat(), silver())
183
+ addSpeakerDriver(g, 0, h * 0.65, d / 2 + 0.012, w * 0.28, coneMat(), copperRing())
184
+ addSpeakerDriver(g, 0, h * 0.42, d / 2 + 0.012, w * 0.34, coneMat(), copperRing())
185
+ addSpeakerDriver(g, 0, h * 0.21, d / 2 + 0.012, w * 0.34, coneMat(), copperRing())
186
+ return g
187
+ }
188
+
189
+ case 'speaker-bookshelf': {
190
+ addBox(g, w, 0.02, d, 0, 0.01, 0, silver())
191
+ addBox(g, w, h - 0.02, d, 0, 0.02 + (h - 0.02) / 2, 0, chassis())
192
+ addSpeakerDriver(g, 0, h * 0.72, d / 2 + 0.01, w * 0.18, coneMat(), silver())
193
+ addSpeakerDriver(g, 0, h * 0.36, d / 2 + 0.01, w * 0.33, coneMat(), copperRing())
194
+ return g
195
+ }
196
+
197
+ case 'speaker-center': {
198
+ addBox(g, w, h, d, 0, h / 2, 0, chassis())
199
+ addSpeakerDriver(g, -w * 0.3, h * 0.5, d / 2 + 0.01, h * 0.34, coneMat(), copperRing())
200
+ addSpeakerDriver(g, 0, h * 0.5, d / 2 + 0.01, h * 0.2, coneMat(), silver())
201
+ addSpeakerDriver(g, w * 0.3, h * 0.5, d / 2 + 0.01, h * 0.34, coneMat(), copperRing())
202
+ return g
203
+ }
204
+
205
+ case 'subwoofer-powered': {
206
+ // Vibration feet + sealed cube + 12" woofer
207
+ for (const sx of [-1, 1]) {
208
+ for (const sz of [-1, 1]) {
209
+ addCyl(g, 0.025, 0.025, 0.03, sx * (w * 0.38), 0.015, sz * (d * 0.38), silver(), 10)
210
+ }
211
+ }
212
+ addBox(g, w, h - 0.03, d, 0, 0.03 + (h - 0.03) / 2, 0, chassis())
213
+ addSpeakerDriver(g, 0, h * 0.52, d / 2 + 0.012, Math.min(w, h) * 0.38, coneMat(), copperRing())
214
+ return g
215
+ }
216
+
217
+ case 'av-receiver-rack': {
218
+ // Stacked AVR + media streamer + OLED readout + dual volume dials
219
+ addBox(g, w, h * 0.58, d, 0, h * 0.29, 0, chassis())
220
+ addBox(g, w * 0.96, h * 0.32, d * 0.9, 0, h * 0.78, 0, chassis())
221
+ addBox(g, w * 0.42, 0.045, 0.01, 0, h * 0.34, d / 2 + 0.005, ledCyan())
222
+ addCyl(g, 0.028, 0.028, 0.024, -w * 0.36, h * 0.34, d / 2 + 0.012, silver(), 16, Math.PI / 2)
223
+ addCyl(g, 0.028, 0.028, 0.024, w * 0.36, h * 0.34, d / 2 + 0.012, silver(), 16, Math.PI / 2)
224
+ return g
225
+ }
226
+
227
+ case 'turntable-hifi': {
228
+ const plinthMat = pool.wood('american-walnut')
229
+ addBox(g, w, 0.055, d, 0, 0.038, 0, plinthMat)
230
+ // Vinyl record platter
231
+ addCyl(g, d * 0.42, d * 0.42, 0.018, -w * 0.08, 0.074, 0, coneMat(), 28)
232
+ addCyl(g, 0.048, 0.048, 0.02, -w * 0.08, 0.076, 0, pool.make({ color: '#dc2626', roughness: 0.4 }), 18)
233
+ // Tonearm
234
+ addCyl(g, 0.02, 0.02, 0.03, w * 0.34, 0.08, -d * 0.28, silver(), 12)
235
+ addBox(g, 0.012, 0.012, d * 0.6, w * 0.28, 0.095, 0, silver(), 0, 0.24)
236
+ // Clear dust cover
237
+ addBox(g, w * 0.98, h - 0.06, d * 0.98, 0, 0.065 + (h - 0.06) / 2, 0, pool.glass('#ffffff', 0.16))
238
+ return g
239
+ }
240
+
241
+ case 'desktop-pc-dual-monitor':
242
+ case 'desktop-pc-ultrawide':
243
+ case 'laptop-dock-setup': {
244
+ const codeScreen = pool.screen(params.screenState ?? 'code')
245
+ // Desk mat
246
+ addBox(g, w * 0.66, 0.005, d * 0.62, -w * 0.1, 0.0025, d * 0.12, grille())
247
+ // Mechanical keyboard + wireless mouse
248
+ addBox(g, 0.36, 0.022, 0.13, -w * 0.12, 0.015, d * 0.24, chassis())
249
+ addBox(g, 0.065, 0.028, 0.11, w * 0.14, 0.016, d * 0.24, chassis())
250
+
251
+ if (params.kind === 'desktop-pc-dual-monitor') {
252
+ // Dual 27" monitors angled inward slightly + mid-tower PC cleanly spaced on right
253
+ for (const [mx, yaw] of [[-0.44, 0.12], [0.12, -0.12]] as const) {
254
+ addCyl(g, 0.018, 0.022, 0.28, mx, 0.14, -d * 0.26, silver(), 10)
255
+ addBox(g, 0.54, 0.33, 0.024, mx, 0.34, -d * 0.22, chassis(), 0, yaw)
256
+ addBox(g, 0.52, 0.31, 0.008, mx, 0.34, -d * 0.205, codeScreen, 0, yaw)
257
+ }
258
+ // Tempered-glass mid-tower PC case on +X side with clear air gap from right monitor
259
+ const pcX = w / 2 - 0.11
260
+ addBox(g, 0.22, 0.46, 0.44, pcX, 0.23, -0.02, chassis())
261
+ addBox(g, 0.008, 0.4, 0.38, pcX - 0.112, 0.23, -0.02, pool.glass('#38bdf8', 0.25))
262
+ // Subtle front fan LED rings
263
+ for (let f = 0; f < 3; f++) {
264
+ const ring = new Mesh(new TorusGeometry(0.048, 0.007, 8, 18), ledCyan())
265
+ ring.position.set(pcX, 0.12 + f * 0.11, 0.202)
266
+ g.add(ring)
267
+ }
268
+ } else if (params.kind === 'desktop-pc-ultrawide') {
269
+ // 3-segment curved 49" super-ultrawide display + SFF tower
270
+ addCyl(g, 0.024, 0.032, 0.26, -0.06, 0.13, -d * 0.26, silver(), 12)
271
+ addBox(g, 0.32, 0.015, 0.22, -0.06, 0.008, -d * 0.24, silver())
272
+ addBox(g, 0.44, 0.34, 0.025, -0.06, 0.33, -d * 0.22, chassis())
273
+ addBox(g, 0.42, 0.32, 0.008, -0.06, 0.33, -d * 0.205, codeScreen)
274
+ addBox(g, 0.36, 0.34, 0.025, -0.44, 0.33, -d * 0.18, chassis(), 0, 0.24)
275
+ addBox(g, 0.34, 0.32, 0.008, -0.44, 0.33, -d * 0.165, codeScreen, 0, 0.24)
276
+ addBox(g, 0.36, 0.34, 0.025, 0.32, 0.33, -d * 0.18, chassis(), 0, -0.24)
277
+ addBox(g, 0.34, 0.32, 0.008, 0.32, 0.33, -d * 0.165, codeScreen, 0, -0.24)
278
+ // Compact SFF workstation tower
279
+ addBox(g, 0.16, 0.32, 0.3, w / 2 - 0.09, 0.16, -0.05, silver())
280
+ } else {
281
+ // Laptop on riser + 32" external display
282
+ addCyl(g, 0.02, 0.025, 0.26, 0.16, 0.13, -d * 0.24, silver(), 12)
283
+ addBox(g, 0.72, 0.42, 0.024, 0.16, 0.34, -d * 0.2, chassis())
284
+ addBox(g, 0.7, 0.4, 0.008, 0.16, 0.34, -d * 0.185, codeScreen)
285
+ // 16" laptop on left riser
286
+ addBox(g, 0.35, 0.016, 0.24, -0.34, 0.08, -0.02, silver(), 0.22, 0.18)
287
+ addBox(g, 0.35, 0.23, 0.012, -0.36, 0.19, -0.14, silver(), -0.18, 0.18)
288
+ addBox(g, 0.33, 0.21, 0.006, -0.36, 0.19, -0.132, codeScreen, -0.18, 0.18)
289
+ }
290
+ return g
291
+ }
292
+
293
+ default: {
294
+ addBox(g, w, h, d, 0, h / 2, 0, chassis())
295
+ return g
296
+ }
297
+ }
298
+ }