@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,10 @@
1
+ /**
2
+ * Clean-Room MIT Procedural Three.js CAD Engine (`@kruschdev/pascal-plugin-furnishings/cad`).
3
+ * Strictly React-free and editor-free (`bun run check:render` verified).
4
+ */
5
+
6
+ export * from './materials'
7
+ export * from './furniture-geometry'
8
+ export * from './electronics-geometry'
9
+ export * from './plants-geometry'
10
+ export * from './catalog'
@@ -0,0 +1,274 @@
1
+ /**
2
+ * Fresh per-build PBR material factory for clean-room MIT 3D Furnishings, Electronics & Botanicals CAD.
3
+ * Editor-free and React-free: zero React, `@pascal-app/*`, or `next` imports.
4
+ *
5
+ * IMPORTANT: Always call `createFurnishingsMaterialPool()` fresh per build call.
6
+ * NEVER cache global singleton materials so Pascal `<GeometrySystem>` disposal never corrupts sibling meshes.
7
+ */
8
+
9
+ import {
10
+ Color,
11
+ DataTexture,
12
+ DoubleSide,
13
+ LinearFilter,
14
+ MeshStandardMaterial,
15
+ RGBAFormat,
16
+ RepeatWrapping,
17
+ SRGBColorSpace,
18
+ UnsignedByteType,
19
+ } from 'three'
20
+ import {
21
+ ELECTRONICS_FINISH_HEX,
22
+ type ElectronicsFinish,
23
+ FABRIC_FINISH_HEX,
24
+ type FabricFinish,
25
+ METAL_FINISH_HEX,
26
+ type MetalFinish,
27
+ POT_STYLE_HEX,
28
+ type PotStyle,
29
+ type ScreenState,
30
+ WOOD_FINISH_HEX,
31
+ type WoodFinish,
32
+ } from '../furnishings/types'
33
+
34
+ export type FurnishingTexturePattern =
35
+ | 'wood-grain'
36
+ | 'fabric-weave'
37
+ | 'rug-pattern'
38
+ | 'bark'
39
+ | 'acoustic-grille'
40
+ | 'screen-ambient'
41
+ | 'screen-cinema'
42
+ | 'screen-code'
43
+ | 'ceramic-speckle'
44
+
45
+ export type FurnishingsMaterialPool = {
46
+ readonly make: (params: {
47
+ color: string | number
48
+ roughness?: number
49
+ metalness?: number
50
+ opacity?: number
51
+ depthWrite?: boolean
52
+ doubleSided?: boolean
53
+ emissive?: string | number
54
+ emissiveIntensity?: number
55
+ pattern?: FurnishingTexturePattern
56
+ }) => MeshStandardMaterial
57
+ readonly wood: (finish?: WoodFinish) => MeshStandardMaterial
58
+ readonly fabric: (finish?: FabricFinish) => MeshStandardMaterial
59
+ readonly metal: (finish?: MetalFinish) => MeshStandardMaterial
60
+ readonly electronics: (finish?: ElectronicsFinish) => MeshStandardMaterial
61
+ readonly screen: (state?: ScreenState) => MeshStandardMaterial
62
+ readonly acousticGrille: (tintHex?: string) => MeshStandardMaterial
63
+ readonly pot: (style?: PotStyle) => MeshStandardMaterial
64
+ readonly bark: (tintHex?: string) => MeshStandardMaterial
65
+ readonly foliage: (hex: string, roughness?: number) => MeshStandardMaterial
66
+ readonly glass: (tintHex?: string, opacity?: number) => MeshStandardMaterial
67
+ }
68
+
69
+ function buildPatternTexture(pattern: FurnishingTexturePattern, baseHex: string | number): DataTexture {
70
+ const size = 64
71
+ const data = new Uint8Array(size * size * 4)
72
+ const base = new Color(baseHex)
73
+ const r0 = Math.round(base.r * 255)
74
+ const g0 = Math.round(base.g * 255)
75
+ const b0 = Math.round(base.b * 255)
76
+
77
+ const setPx = (x: number, y: number, r: number, g: number, b: number) => {
78
+ const idx = (y * size + x) * 4
79
+ data[idx] = Math.max(0, Math.min(255, Math.round(r)))
80
+ data[idx + 1] = Math.max(0, Math.min(255, Math.round(g)))
81
+ data[idx + 2] = Math.max(0, Math.min(255, Math.round(b)))
82
+ data[idx + 3] = 255
83
+ }
84
+
85
+ for (let y = 0; y < size; y++) {
86
+ for (let x = 0; x < size; x++) {
87
+ if (pattern === 'wood-grain') {
88
+ const wave = Math.sin(y * 0.42 + Math.sin(x * 0.14) * 1.8) * 12 + Math.sin(y * 1.1) * 5
89
+ setPx(x, y, r0 + wave, g0 + wave * 0.85, b0 + wave * 0.65)
90
+ } else if (pattern === 'fabric-weave') {
91
+ const warp = ((x + y) % 4 === 0 ? 7 : -4) + ((x % 2 === 0 && y % 2 === 1) ? 5 : -3)
92
+ setPx(x, y, r0 + warp, g0 + warp, b0 + warp)
93
+ } else if (pattern === 'rug-pattern') {
94
+ const border = x < 5 || x >= size - 5 || y < 5 || y >= size - 5
95
+ const diamond = Math.abs(((x % 16) - 8)) + Math.abs(((y % 16) - 8)) <= 3
96
+ const delta = border ? -26 : diamond ? 20 : ((x + y) % 2 === 0 ? 4 : -4)
97
+ setPx(x, y, r0 + delta, g0 + delta, b0 + delta)
98
+ } else if (pattern === 'bark') {
99
+ const furrow = Math.sin(x * 0.9 + Math.sin(y * 0.25) * 1.5) * 18 + ((x * 13 + y * 7) % 11) - 5
100
+ setPx(x, y, r0 + furrow, g0 + furrow * 0.85, b0 + furrow * 0.7)
101
+ } else if (pattern === 'acoustic-grille') {
102
+ const hole = x % 4 === 1 && y % 4 === 1
103
+ const d = hole ? -24 : 6
104
+ setPx(x, y, r0 + d, g0 + d, b0 + d)
105
+ } else if (pattern === 'ceramic-speckle') {
106
+ const speck = (x * 37 + y * 17) % 29 === 0 ? -18 : (x * 19 + y * 31) % 23 === 0 ? 12 : 0
107
+ setPx(x, y, r0 + speck, g0 + speck, b0 + speck)
108
+ } else if (pattern === 'screen-ambient') {
109
+ // Warm sunset architectural gradient
110
+ const ty = y / size
111
+ const tx = x / size
112
+ const rr = 28 + 150 * Math.pow(1 - ty, 1.3) + 35 * Math.sin(tx * Math.PI)
113
+ const gg = 42 + 92 * (1 - Math.abs(ty - 0.45) * 1.7)
114
+ const bb = 88 + 115 * ty
115
+ setPx(x, y, rr, gg, bb)
116
+ } else if (pattern === 'screen-cinema') {
117
+ // Deep cinematic blue-gold twilight scene
118
+ const ty = y / size
119
+ const letterbox = y < 6 || y >= size - 6
120
+ if (letterbox) {
121
+ setPx(x, y, 8, 9, 12)
122
+ } else {
123
+ const glow = Math.exp(-((x - 32) ** 2 + (y - 30) ** 2) / 260)
124
+ setPx(x, y, 22 + glow * 190, 32 + glow * 145, 58 + (1 - ty) * 90)
125
+ }
126
+ } else if (pattern === 'screen-code') {
127
+ // Dark IDE theme with syntax-colored code bars
128
+ const isSidebar = x < 12
129
+ if (isSidebar) {
130
+ setPx(x, y, 22, 26, 36)
131
+ } else if (y % 5 === 2 && x > 15 && x < 24 + ((y * 17) % 34)) {
132
+ const accent = y % 15 === 2 ? [56, 189, 248] : y % 10 === 2 ? [167, 139, 250] : [74, 222, 128]
133
+ setPx(x, y, accent[0]!, accent[1]!, accent[2]!)
134
+ } else {
135
+ setPx(x, y, 16, 20, 29)
136
+ }
137
+ }
138
+ }
139
+ }
140
+
141
+ const tex = new DataTexture(data, size, size, RGBAFormat, UnsignedByteType)
142
+ tex.colorSpace = SRGBColorSpace
143
+ tex.wrapS = RepeatWrapping
144
+ tex.wrapT = RepeatWrapping
145
+ tex.minFilter = LinearFilter
146
+ tex.magFilter = LinearFilter
147
+ tex.needsUpdate = true
148
+ return tex
149
+ }
150
+
151
+ export function createFurnishingsMaterialPool(): FurnishingsMaterialPool {
152
+ const cache = new Map<string, MeshStandardMaterial>()
153
+
154
+ const make: FurnishingsMaterialPool['make'] = (params) => {
155
+ const opacity = params.opacity ?? 1
156
+ const transparent = opacity < 1
157
+ const depthWrite = params.depthWrite ?? !transparent
158
+ const key = JSON.stringify([
159
+ params.color,
160
+ params.roughness ?? 0.65,
161
+ params.metalness ?? 0.05,
162
+ opacity,
163
+ depthWrite,
164
+ Boolean(params.doubleSided),
165
+ params.emissive ?? null,
166
+ params.emissive !== undefined ? (params.emissiveIntensity ?? 0.35) : null,
167
+ params.pattern ?? null,
168
+ ])
169
+ const cached = cache.get(key)
170
+ if (cached) return cached
171
+
172
+ const map = params.pattern ? buildPatternTexture(params.pattern, params.color) : undefined
173
+ const mat = new MeshStandardMaterial({
174
+ color: params.pattern?.startsWith('screen-') ? '#ffffff' : params.color,
175
+ ...(map ? { map } : {}),
176
+ roughness: params.roughness ?? 0.65,
177
+ metalness: params.metalness ?? 0.05,
178
+ transparent,
179
+ opacity,
180
+ depthWrite,
181
+ ...(params.doubleSided ? { side: DoubleSide } : {}),
182
+ ...(params.emissive !== undefined
183
+ ? {
184
+ emissive: new Color(params.emissive),
185
+ emissiveIntensity: params.emissiveIntensity ?? 0.35,
186
+ }
187
+ : {}),
188
+ })
189
+ cache.set(key, mat)
190
+ return mat
191
+ }
192
+
193
+ return {
194
+ make,
195
+ wood: (finish = 'natural-oak') =>
196
+ make({
197
+ color: WOOD_FINISH_HEX[finish] ?? WOOD_FINISH_HEX['natural-oak'],
198
+ roughness: finish === 'matte-black' ? 0.58 : 0.52,
199
+ metalness: 0.04,
200
+ pattern: 'wood-grain',
201
+ }),
202
+ fabric: (finish = 'warm-linen') =>
203
+ make({
204
+ color: FABRIC_FINISH_HEX[finish] ?? FABRIC_FINISH_HEX['warm-linen'],
205
+ roughness: finish === 'cognac-leather' ? 0.42 : 0.88,
206
+ metalness: 0.02,
207
+ pattern: 'fabric-weave',
208
+ }),
209
+ metal: (finish = 'matte-black') =>
210
+ make({
211
+ color: METAL_FINISH_HEX[finish] ?? METAL_FINISH_HEX['matte-black'],
212
+ roughness: finish === 'chrome' ? 0.16 : finish === 'brushed-brass' || finish === 'brushed-nickel' ? 0.3 : 0.46,
213
+ metalness: finish === 'white-powdercoat' ? 0.25 : 0.82,
214
+ }),
215
+ electronics: (finish = 'matte-black') =>
216
+ make({
217
+ color: ELECTRONICS_FINISH_HEX[finish] ?? ELECTRONICS_FINISH_HEX['matte-black'],
218
+ roughness: finish === 'silver-aluminum' ? 0.28 : 0.44,
219
+ metalness: finish === 'walnut-grille' ? 0.08 : 0.65,
220
+ ...(finish === 'walnut-grille' ? { pattern: 'wood-grain' as const } : {}),
221
+ }),
222
+ screen: (state = 'ambient') => {
223
+ if (state === 'off') {
224
+ return make({ color: '#111418', roughness: 0.12, metalness: 0.25 })
225
+ }
226
+ const pattern =
227
+ state === 'cinema' ? 'screen-cinema' : state === 'code' ? 'screen-code' : 'screen-ambient'
228
+ return make({
229
+ color: '#ffffff',
230
+ roughness: 0.18,
231
+ metalness: 0.1,
232
+ emissive: state === 'code' ? '#1e3a5f' : '#2a2238',
233
+ emissiveIntensity: 0.28,
234
+ pattern,
235
+ })
236
+ },
237
+ acousticGrille: (tintHex = '#23262b') =>
238
+ make({
239
+ color: tintHex,
240
+ roughness: 0.82,
241
+ metalness: 0.15,
242
+ pattern: 'acoustic-grille',
243
+ }),
244
+ pot: (style = 'ceramic-white') =>
245
+ make({
246
+ color: POT_STYLE_HEX[style] ?? POT_STYLE_HEX['ceramic-white'],
247
+ roughness: style === 'terracotta' || style === 'concrete-trough' ? 0.85 : style === 'woven-basket' ? 0.9 : 0.35,
248
+ metalness: 0.04,
249
+ pattern: style === 'woven-basket' ? 'fabric-weave' : style === 'cedar-box' ? 'wood-grain' : 'ceramic-speckle',
250
+ }),
251
+ bark: (tintHex = '#5d4635') =>
252
+ make({
253
+ color: tintHex,
254
+ roughness: 0.92,
255
+ metalness: 0.02,
256
+ pattern: 'bark',
257
+ }),
258
+ foliage: (hex: string, roughness = 0.78) =>
259
+ make({
260
+ color: hex,
261
+ roughness,
262
+ metalness: 0.02,
263
+ doubleSided: true,
264
+ }),
265
+ glass: (tintHex = '#cce4f6', opacity = 0.34) =>
266
+ make({
267
+ color: tintHex,
268
+ roughness: 0.08,
269
+ metalness: 0.18,
270
+ opacity,
271
+ depthWrite: opacity >= 1,
272
+ }),
273
+ }
274
+ }