@kruschdev/pascal-plugin-mit-assets 0.0.0-stage → 0.1.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.
Files changed (78) hide show
  1. package/ASSETS.md +298 -0
  2. package/LICENSE +21 -0
  3. package/README.md +71 -2
  4. package/dist/agent-operations.d.ts +8 -0
  5. package/dist/agent-operations.js +305 -0
  6. package/dist/agent-tools.d.ts +7 -0
  7. package/dist/agent-tools.js +128 -0
  8. package/dist/audit.d.ts +78 -0
  9. package/dist/bin/pascal-mit-assets.js +5238 -0
  10. package/dist/bom.d.ts +123 -0
  11. package/dist/cad/appliance-mep-builders.d.ts +7 -0
  12. package/dist/cad/furniture-builders.d.ts +9 -0
  13. package/dist/cad/index.d.ts +48 -0
  14. package/dist/cad/index.js +23 -0
  15. package/dist/cad/kitchen-bath-builders.d.ts +9 -0
  16. package/dist/cad/outdoor-fenestration-builders.d.ts +8 -0
  17. package/dist/cad/primitives.d.ts +56 -0
  18. package/dist/cad/props-vehicles-builders.d.ts +8 -0
  19. package/dist/chunk-2qgndrap.js +5200 -0
  20. package/dist/chunk-6hzyh6qv.js +346 -0
  21. package/dist/chunk-f72r2bmp.js +84 -0
  22. package/dist/chunk-hqgm57dv.js +310 -0
  23. package/dist/chunk-kgwk6kan.js +150 -0
  24. package/dist/chunk-raafkn3w.js +286 -0
  25. package/dist/chunk-vzmjt9dz.js +4380 -0
  26. package/dist/chunk-xhkwv6t4.js +5080 -0
  27. package/dist/hdri/index.d.ts +1 -0
  28. package/dist/hdri/index.js +322 -0
  29. package/dist/hdri/sky.d.ts +26 -0
  30. package/dist/index.d.ts +30 -0
  31. package/dist/index.js +198 -0
  32. package/dist/manifest.d.ts +46 -0
  33. package/dist/materials/index.d.ts +10 -0
  34. package/dist/materials/index.js +1464 -0
  35. package/dist/materials/ktx2.d.ts +10 -0
  36. package/dist/materials/noise.d.ts +89 -0
  37. package/dist/materials/patterns.d.ts +15 -0
  38. package/dist/nodes/mit-item.d.ts +76 -0
  39. package/dist/render.d.ts +10 -0
  40. package/dist/render.js +24 -0
  41. package/dist/scripts/build-assets.js +17129 -0
  42. package/dist/sfx/index.d.ts +1 -0
  43. package/dist/sfx/index.js +1223 -0
  44. package/dist/sfx/synth.d.ts +25 -0
  45. package/dist/sku-crosswalk.d.ts +46 -0
  46. package/dist/ui/chat-card.d.ts +7 -0
  47. package/dist/ui/host-panel.d.ts +1 -0
  48. package/dist/ui/inspector-card.d.ts +4 -0
  49. package/dist/ui/schedule-view.d.ts +1 -0
  50. package/package.json +135 -4
  51. package/src/agent-operations.ts +373 -0
  52. package/src/agent-tools.ts +136 -0
  53. package/src/audit.ts +356 -0
  54. package/src/bom.ts +512 -0
  55. package/src/cad/appliance-mep-builders.ts +1336 -0
  56. package/src/cad/furniture-builders.ts +1622 -0
  57. package/src/cad/index.ts +993 -0
  58. package/src/cad/kitchen-bath-builders.ts +1189 -0
  59. package/src/cad/outdoor-fenestration-builders.ts +1499 -0
  60. package/src/cad/primitives.ts +286 -0
  61. package/src/cad/props-vehicles-builders.ts +1065 -0
  62. package/src/hdri/index.ts +5 -0
  63. package/src/hdri/sky.ts +481 -0
  64. package/src/index.ts +127 -0
  65. package/src/manifest.ts +5296 -0
  66. package/src/materials/index.ts +56 -0
  67. package/src/materials/ktx2.ts +138 -0
  68. package/src/materials/noise.ts +417 -0
  69. package/src/materials/patterns.ts +1507 -0
  70. package/src/nodes/mit-item.ts +163 -0
  71. package/src/render.ts +25 -0
  72. package/src/sfx/index.ts +6 -0
  73. package/src/sfx/synth.ts +1495 -0
  74. package/src/sku-crosswalk.ts +3868 -0
  75. package/src/ui/chat-card.tsx +93 -0
  76. package/src/ui/host-panel.tsx +330 -0
  77. package/src/ui/inspector-card.tsx +213 -0
  78. package/src/ui/schedule-view.tsx +188 -0
@@ -0,0 +1,5 @@
1
+ export {
2
+ encodeRadianceRgbe,
3
+ synthesizeSunsetHdri,
4
+ type SynthesizedHdri,
5
+ } from './sky'
@@ -0,0 +1,481 @@
1
+ /**
2
+ * Clean-room MIT procedural equirectangular golden-hour sunset HDRI synthesizer
3
+ * and Radiance RGBE (`.hdr`) encoder.
4
+ *
5
+ * Purity invariant: ZERO imports from react, three, @pascal-app/*, next, or node:*.
6
+ * Pure deterministic TypeScript math and typed arrays.
7
+ */
8
+
9
+ export type SynthesizedHdri = {
10
+ readonly width: number
11
+ readonly height: number
12
+ readonly rgb: Float32Array
13
+ }
14
+
15
+ const TWO_PI = Math.PI * 2
16
+ const DEG_TO_RAD = Math.PI / 180
17
+
18
+ function clamp(v: number, lo: number, hi: number): number {
19
+ return v < lo ? lo : v > hi ? hi : v
20
+ }
21
+
22
+ function lerp(a: number, b: number, t: number): number {
23
+ return a + (b - a) * t
24
+ }
25
+
26
+ function smoothstep(edge0: number, edge1: number, x: number): number {
27
+ const t = clamp((x - edge0) / (edge1 - edge0), 0, 1)
28
+ return t * t * (3 - 2 * t)
29
+ }
30
+
31
+ // ---------------------------------------------------------------------------
32
+ // Deterministic Seamless 3D Value Noise & fBm (evaluated on 3D unit rays,
33
+ // guaranteeing mathematically zero seams at u = 0/1 and smooth zenith/nadir)
34
+ // ---------------------------------------------------------------------------
35
+
36
+ function hash3(ix: number, iy: number, iz: number): number {
37
+ let h = Math.imul(ix, 374761393) + Math.imul(iy, 668265263) + Math.imul(iz, 2147483647)
38
+ h = (h ^ (h >>> 13)) >>> 0
39
+ h = Math.imul(h, 1274126177) >>> 0
40
+ return ((h ^ (h >>> 16)) >>> 0) / 4294967296
41
+ }
42
+
43
+ function quintic(t: number): number {
44
+ return t * t * t * (t * (t * 6 - 15) + 10)
45
+ }
46
+
47
+ function valueNoise3D(x: number, y: number, z: number): number {
48
+ const ix = Math.floor(x)
49
+ const iy = Math.floor(y)
50
+ const iz = Math.floor(z)
51
+
52
+ const fx = quintic(x - ix)
53
+ const fy = quintic(y - iy)
54
+ const fz = quintic(z - iz)
55
+
56
+ const n000 = hash3(ix, iy, iz)
57
+ const n100 = hash3(ix + 1, iy, iz)
58
+ const n010 = hash3(ix, iy + 1, iz)
59
+ const n110 = hash3(ix + 1, iy + 1, iz)
60
+ const n001 = hash3(ix, iy, iz + 1)
61
+ const n101 = hash3(ix + 1, iy, iz + 1)
62
+ const n011 = hash3(ix, iy + 1, iz + 1)
63
+ const n111 = hash3(ix + 1, iy + 1, iz + 1)
64
+
65
+ const x00 = lerp(n000, n100, fx)
66
+ const x10 = lerp(n010, n110, fx)
67
+ const x01 = lerp(n001, n101, fx)
68
+ const x11 = lerp(n011, n111, fx)
69
+
70
+ const y0 = lerp(x00, x10, fy)
71
+ const y1 = lerp(x01, x11, fy)
72
+
73
+ return lerp(y0, y1, fz)
74
+ }
75
+
76
+ function fbm3D(x: number, y: number, z: number, octaves = 4): number {
77
+ let sum = 0
78
+ let amp = 0.5
79
+ let freq = 1
80
+ let norm = 0
81
+
82
+ for (let o = 0; o < octaves; o++) {
83
+ sum += amp * valueNoise3D(x * freq + o * 17.3, y * freq - o * 9.1, z * freq + o * 23.7)
84
+ norm += amp
85
+ amp *= 0.5
86
+ freq *= 2.04
87
+ }
88
+ return norm > 0 ? sum / norm : 0
89
+ }
90
+
91
+ /**
92
+ * Henyey-Greenstein phase function normalized so peak forward scatter is well-behaved.
93
+ */
94
+ function henyeyGreenstein(cosTheta: number, g: number): number {
95
+ const g2 = g * g
96
+ const denom = Math.max(1e-4, 1 + g2 - 2 * g * cosTheta)
97
+ return (1 - g2) / (4 * Math.PI * denom * Math.sqrt(denom))
98
+ }
99
+
100
+ // ---------------------------------------------------------------------------
101
+ // Procedural Sunset Sky Dome Synthesizer
102
+ // ---------------------------------------------------------------------------
103
+
104
+ /**
105
+ * Synthesize a seamless equirectangular warm golden-hour sunset HDRI dome.
106
+ *
107
+ * Orientation matches Radiance `-Y <height> +X <width>` (row 0 = zenith `+Y`,
108
+ * row `height / 2` = horizon `0`, row `height - 1` = nadir `-Y`), matching
109
+ * Three.js `HDRLoader` (`flipY: true`) and `EquirectangularReflectionMapping`.
110
+ */
111
+ export function synthesizeSunsetHdri(width = 1024, height = 512): SynthesizedHdri {
112
+ if (!Number.isInteger(width) || width <= 0 || !Number.isInteger(height) || height <= 0) {
113
+ throw new RangeError(`Invalid HDRI dimensions: ${width}x${height}`)
114
+ }
115
+
116
+ const rgb = new Float32Array(width * height * 3)
117
+
118
+ // Low golden-hour sun at elevation ~10 deg, azimuth ~215 deg
119
+ const sunElevRad = 10 * DEG_TO_RAD
120
+ const sunAzimRad = 215 * DEG_TO_RAD
121
+ const sunCosEl = Math.cos(sunElevRad)
122
+ const sunX = sunCosEl * Math.cos(sunAzimRad)
123
+ const sunY = Math.sin(sunElevRad)
124
+ const sunZ = sunCosEl * Math.sin(sunAzimRad)
125
+ const sunHorizX = Math.cos(sunAzimRad)
126
+ const sunHorizZ = Math.sin(sunAzimRad)
127
+
128
+ // Precompute cos/sin lookup tables for longitude (u = x / width -> 0..2*PI)
129
+ const cosPhi = new Float64Array(width)
130
+ const sinPhi = new Float64Array(width)
131
+ for (let x = 0; x < width; x++) {
132
+ const phi = (x / width) * TWO_PI
133
+ cosPhi[x] = Math.cos(phi)
134
+ sinPhi[x] = Math.sin(phi)
135
+ }
136
+
137
+ for (let y = 0; y < height; y++) {
138
+ const theta = ((y + 0.5) / height) * Math.PI // 0 = zenith, PI/2 = horizon, PI = nadir
139
+ const dy = Math.cos(theta) // sin(lat): +1 at zenith, 0 at horizon, -1 at nadir
140
+ const cosLat = Math.sin(theta) // 0 at poles, 1 at horizon
141
+
142
+ const rowBase = y * width * 3
143
+
144
+ for (let x = 0; x < width; x++) {
145
+ const cPhi = cosPhi[x] ?? 1
146
+ const sPhi = sinPhi[x] ?? 0
147
+ const dx = cosLat * cPhi
148
+ const dz = cosLat * sPhi
149
+
150
+ const cosGamma = clamp(dx * sunX + dy * sunY + dz * sunZ, -1, 1)
151
+ const sunAngle = Math.acos(cosGamma)
152
+
153
+ // Azimuthal alignment toward the sunset (0 = anti-solar, 1 = toward sun)
154
+ const horizDot = cPhi * sunHorizX + sPhi * sunHorizZ
155
+ const sunSide = 0.5 + 0.5 * horizDot
156
+
157
+ let r = 0
158
+ let g = 0
159
+ let b = 0
160
+
161
+ // Compute sky color for the horizon/upper dome (also blended into slight sub-horizon haze)
162
+ const elev = Math.max(0, dy)
163
+
164
+ // 1. Multi-stop golden-hour Rayleigh atmospheric gradient
165
+ // Zenith: deep twilight cobalt-blue
166
+ const zenithR = 0.055
167
+ const zenithG = 0.11
168
+ const zenithB = 0.31
169
+
170
+ // Mid-sky: soft sunset lavender / dusky violet
171
+ const midR = lerp(0.22, 0.38, sunSide)
172
+ const midG = lerp(0.2, 0.25, sunSide)
173
+ const midB = lerp(0.38, 0.44, sunSide)
174
+
175
+ // Lower sky: warm peach / coral apricot
176
+ const peachR = lerp(0.55, 1.08, sunSide)
177
+ const peachG = lerp(0.34, 0.52, sunSide)
178
+ const peachB = lerp(0.42, 0.31, sunSide)
179
+
180
+ // Horizon band: luminous golden-amber on sun side, rosy twilight Belt of Venus opposite
181
+ const horizR = lerp(0.72, 1.72, sunSide)
182
+ const horizG = lerp(0.42, 0.84, sunSide)
183
+ const horizB = lerp(0.44, 0.32, sunSide)
184
+
185
+ // Blend horizon -> peach -> lavender -> zenith smoothly with elevation
186
+ const tLow = smoothstep(0.0, 0.14, elev)
187
+ const tMid = smoothstep(0.1, 0.42, elev)
188
+ const tTop = smoothstep(0.34, 0.92, elev)
189
+
190
+ let skyR = lerp(horizR, peachR, tLow)
191
+ let skyG = lerp(horizG, peachG, tLow)
192
+ let skyB = lerp(horizB, peachB, tLow)
193
+
194
+ skyR = lerp(skyR, midR, tMid)
195
+ skyG = lerp(skyG, midG, tMid)
196
+ skyB = lerp(skyB, midB, tMid)
197
+
198
+ skyR = lerp(skyR, zenithR, tTop)
199
+ skyG = lerp(skyG, zenithG, tTop)
200
+ skyB = lerp(skyB, zenithB, tTop)
201
+
202
+ // 2. Mie forward-scattering golden atmospheric halo
203
+ const airMass = 1 / (elev + 0.16)
204
+ const mieWide = henyeyGreenstein(cosGamma, 0.68) * clamp(airMass * 0.28, 0.18, 1.15)
205
+ const mieTight = henyeyGreenstein(cosGamma, 0.9) * 0.14
206
+ const corona = Math.exp(-Math.pow(sunAngle / 0.14, 2)) * 1.9
207
+
208
+ skyR += mieWide * 2.2 + mieTight * 1.55 + corona * 1.05
209
+ skyG += mieWide * 1.25 + mieTight * 0.98 + corona * 0.72
210
+ skyB += mieWide * 0.48 + mieTight * 0.42 + corona * 0.34
211
+
212
+ // 3. Seamless wispy golden-hour sunset clouds (evaluated on continuous 3D sky ray)
213
+ if (dy > -0.02) {
214
+ const cloudMask = smoothstep(0.03, 0.14, elev) * (1 - smoothstep(0.58, 0.92, elev))
215
+ if (cloudMask > 1e-4) {
216
+ const invProj = 1.65 / (elev + 0.34)
217
+ const cx = dx * invProj
218
+ const cy = elev * 2.2
219
+ const cz = dz * invProj
220
+
221
+ // Domain-warped wispy bands
222
+ const warp = fbm3D(cx * 0.55 + 3.1, cy * 0.8, cz * 0.55 - 1.7, 3)
223
+ const densityRaw = fbm3D(cx * 1.1 + warp * 0.9, cy * 1.35, cz * 1.1 - warp * 0.7, 4)
224
+ const cloudCoverage = smoothstep(0.49, 0.76, densityRaw) * cloudMask * 0.58
225
+
226
+ if (cloudCoverage > 1e-4) {
227
+ // Sun-lit golden underside vs. cool mauve shadow side
228
+ const rimLight = Math.pow(Math.max(0, cosGamma), 5)
229
+ const cloudLit = clamp(sunSide * 0.75 + rimLight * 0.6, 0, 1.3)
230
+ const cR = lerp(0.28, 1.55, Math.min(1, cloudLit)) + rimLight * 1.35
231
+ const cG = lerp(0.21, 0.76, Math.min(1, cloudLit)) + rimLight * 0.78
232
+ const cB = lerp(0.32, 0.42, Math.min(1, cloudLit)) + rimLight * 0.32
233
+
234
+ skyR = lerp(skyR, cR, cloudCoverage)
235
+ skyG = lerp(skyG, cG, cloudCoverage)
236
+ skyB = lerp(skyB, cB, cloudCoverage)
237
+ }
238
+ }
239
+ }
240
+
241
+ // 4. Limb-darkened HDR solar disc (peaking ~18.0 linear luminance for crisp specular IBL)
242
+ if (dy > -0.04) {
243
+ const sunFadeBelowHorizon = smoothstep(-0.025, 0.015, dy)
244
+ const disc = Math.exp(-Math.pow(sunAngle / 0.038, 2)) * sunFadeBelowHorizon
245
+ const discCore = Math.exp(-Math.pow(sunAngle / 0.019, 2)) * sunFadeBelowHorizon
246
+ const sunEnergy = disc * 10.5 + discCore * 3.8
247
+ skyR += sunEnergy * 1.05
248
+ skyG += sunEnergy * 0.82
249
+ skyB += sunEnergy * 0.48
250
+ }
251
+
252
+ if (dy >= 0) {
253
+ r = skyR
254
+ g = skyG
255
+ b = skyB
256
+ } else {
257
+ // 5. Warm architectural ground-bounce hemisphere (never pitch black)
258
+ const depth = clamp(-dy, 0, 1)
259
+ const groundNoise = (fbm3D(dx * 2.4, dy * 2.4, dz * 2.4, 3) - 0.5) * 0.14
260
+ const bounceMod = 1 + groundNoise
261
+
262
+ // Warm sunlit terracotta/sandstone haze near horizon -> grounded umber at nadir
263
+ const nearR = lerp(0.38, 0.62, sunSide)
264
+ const nearG = lerp(0.27, 0.4, sunSide)
265
+ const nearB = lerp(0.22, 0.25, sunSide)
266
+
267
+ const midGR = lerp(0.22, 0.31, sunSide)
268
+ const midGG = lerp(0.17, 0.22, sunSide)
269
+ const midGB = lerp(0.14, 0.16, sunSide)
270
+
271
+ const nadirR = 0.13
272
+ const nadirG = 0.105
273
+ const nadirB = 0.092
274
+
275
+ const tG1 = smoothstep(0.0, 0.35, depth)
276
+ const tG2 = smoothstep(0.28, 1.0, depth)
277
+
278
+ let gR = lerp(nearR, midGR, tG1)
279
+ let gG = lerp(nearG, midGG, tG1)
280
+ let gB = lerp(nearB, midGB, tG1)
281
+
282
+ gR = lerp(gR, nadirR, tG2) * bounceMod
283
+ gG = lerp(gG, nadirG, tG2) * bounceMod
284
+ gB = lerp(gB, nadirB, tG2) * bounceMod
285
+
286
+ // Soft atmospheric haze transition across the horizon (-0.06..0.0)
287
+ const horizonBlend = smoothstep(0.0, 0.055, depth)
288
+ r = lerp(skyR * 0.72, gR, horizonBlend)
289
+ g = lerp(skyG * 0.72, gG, horizonBlend)
290
+ b = lerp(skyB * 0.72, gB, horizonBlend)
291
+ }
292
+
293
+ const idx = rowBase + x * 3
294
+ rgb[idx] = r > 0 && Number.isFinite(r) ? r : 0
295
+ rgb[idx + 1] = g > 0 && Number.isFinite(g) ? g : 0
296
+ rgb[idx + 2] = b > 0 && Number.isFinite(b) ? b : 0
297
+ }
298
+ }
299
+
300
+ return { width, height, rgb }
301
+ }
302
+
303
+ // ---------------------------------------------------------------------------
304
+ // Radiance RGBE (.hdr) Encoder
305
+ // ---------------------------------------------------------------------------
306
+
307
+ function floatRgbToRgbe(
308
+ rRaw: number,
309
+ gRaw: number,
310
+ bRaw: number,
311
+ outR: Uint8Array,
312
+ outG: Uint8Array,
313
+ outB: Uint8Array,
314
+ outE: Uint8Array,
315
+ x: number,
316
+ ): void {
317
+ const r = Number.isFinite(rRaw) && rRaw > 0 ? rRaw : 0
318
+ const g = Number.isFinite(gRaw) && gRaw > 0 ? gRaw : 0
319
+ const b = Number.isFinite(bRaw) && bRaw > 0 ? bRaw : 0
320
+ const maxVal = r >= g ? (r >= b ? r : b) : g >= b ? g : b
321
+
322
+ if (maxVal < 1e-32) {
323
+ outR[x] = 0
324
+ outG[x] = 0
325
+ outB[x] = 0
326
+ outE[x] = 0
327
+ return
328
+ }
329
+
330
+ const exp = Math.floor(Math.log2(maxVal)) + 1
331
+ const eByte = clamp(exp + 128, 1, 255)
332
+ const scale = Math.pow(2, 8 - (eByte - 128))
333
+
334
+ outR[x] = clamp(Math.floor(r * scale), 0, 255)
335
+ outG[x] = clamp(Math.floor(g * scale), 0, 255)
336
+ outB[x] = clamp(Math.floor(b * scale), 0, 255)
337
+ outE[x] = eByte
338
+ }
339
+
340
+ function encodeRleChannel(chan: Uint8Array, width: number, dst: Uint8Array, startPos: number): number {
341
+ let pos = startPos
342
+ let i = 0
343
+ while (i < width) {
344
+ const val = chan[i] ?? 0
345
+ let runLen = 1
346
+ while (i + runLen < width && runLen < 127 && (chan[i + runLen] ?? 0) === val) {
347
+ runLen++
348
+ }
349
+
350
+ if (runLen >= 4) {
351
+ dst[pos++] = 128 + runLen
352
+ dst[pos++] = val
353
+ i += runLen
354
+ } else {
355
+ const litStart = i
356
+ let litLen = 0
357
+ while (i < width && litLen < 127) {
358
+ if (
359
+ litLen > 0 &&
360
+ i + 3 < width &&
361
+ (chan[i] ?? 0) === (chan[i + 1] ?? 0) &&
362
+ (chan[i] ?? 0) === (chan[i + 2] ?? 0) &&
363
+ (chan[i] ?? 0) === (chan[i + 3] ?? 0)
364
+ ) {
365
+ break
366
+ }
367
+ i++
368
+ litLen++
369
+ }
370
+ dst[pos++] = litLen
371
+ for (let k = litStart; k < litStart + litLen; k++) {
372
+ dst[pos++] = chan[k] ?? 0
373
+ }
374
+ }
375
+ }
376
+ return pos
377
+ }
378
+
379
+ /**
380
+ * Encode linear float32 RGB pixels (`width * height * 3`) into a standard
381
+ * Radiance RGBE `.hdr` file compatible with Three.js `HDRLoader` / `RGBELoader`,
382
+ * Radiance tools, Blender, and ImageMagick.
383
+ */
384
+ export function encodeRadianceRgbe(rgb: Float32Array, width: number, height: number): Uint8Array {
385
+ if (!Number.isInteger(width) || width <= 0 || !Number.isInteger(height) || height <= 0) {
386
+ throw new RangeError(`Invalid HDRI dimensions: ${width}x${height}`)
387
+ }
388
+ if (rgb.length < width * height * 3) {
389
+ throw new RangeError(`RGB buffer too small: got ${rgb.length}, expected >= ${width * height * 3}`)
390
+ }
391
+
392
+ const headerStr =
393
+ '#?RADIANCE\n' +
394
+ 'FORMAT=32-bit_rle_rgbe\n' +
395
+ 'SOFTWARE=@kruschdev/pascal-plugin-mit-assets (MIT)\n' +
396
+ 'GAMMA=1.0\n' +
397
+ 'EXPOSURE=1.0\n' +
398
+ '\n' +
399
+ `-Y ${height} +X ${width}\n`
400
+
401
+ const headerLen = headerStr.length
402
+ const useRle = width >= 8 && width <= 0x7fff
403
+
404
+ const rowR = new Uint8Array(width)
405
+ const rowG = new Uint8Array(width)
406
+ const rowB = new Uint8Array(width)
407
+ const rowE = new Uint8Array(width)
408
+
409
+ if (!useRle) {
410
+ // Radiance spec requires uncompressed flat scanlines when width < 8 or > 32767
411
+ const out = new Uint8Array(headerLen + width * height * 4)
412
+ for (let i = 0; i < headerLen; i++) {
413
+ out[i] = headerStr.charCodeAt(i) & 0x7f
414
+ }
415
+ let pos = headerLen
416
+ for (let y = 0; y < height; y++) {
417
+ const rowOffset = y * width * 3
418
+ for (let x = 0; x < width; x++) {
419
+ const idx = rowOffset + x * 3
420
+ floatRgbToRgbe(
421
+ rgb[idx] ?? 0,
422
+ rgb[idx + 1] ?? 0,
423
+ rgb[idx + 2] ?? 0,
424
+ rowR,
425
+ rowG,
426
+ rowB,
427
+ rowE,
428
+ x,
429
+ )
430
+ out[pos++] = rowR[x] ?? 0
431
+ out[pos++] = rowG[x] ?? 0
432
+ out[pos++] = rowB[x] ?? 0
433
+ out[pos++] = rowE[x] ?? 0
434
+ }
435
+ }
436
+ return out
437
+ }
438
+
439
+ // Worst-case RLE size per scanline: 4 header bytes + 4 channels * (width + ceil(width/127) + 1)
440
+ const maxBytesPerChannel = width + Math.ceil(width / 127) + 2
441
+ const maxTotalBytes = headerLen + height * (4 + 4 * maxBytesPerChannel)
442
+ const buf = new Uint8Array(maxTotalBytes)
443
+
444
+ for (let i = 0; i < headerLen; i++) {
445
+ buf[i] = headerStr.charCodeAt(i) & 0x7f
446
+ }
447
+
448
+ let pos = headerLen
449
+ const widthHi = (width >> 8) & 0xff
450
+ const widthLo = width & 0xff
451
+
452
+ for (let y = 0; y < height; y++) {
453
+ const rowOffset = y * width * 3
454
+ for (let x = 0; x < width; x++) {
455
+ const idx = rowOffset + x * 3
456
+ floatRgbToRgbe(
457
+ rgb[idx] ?? 0,
458
+ rgb[idx + 1] ?? 0,
459
+ rgb[idx + 2] ?? 0,
460
+ rowR,
461
+ rowG,
462
+ rowB,
463
+ rowE,
464
+ x,
465
+ )
466
+ }
467
+
468
+ // Standard Radiance new-style RLE scanline marker
469
+ buf[pos++] = 0x02
470
+ buf[pos++] = 0x02
471
+ buf[pos++] = widthHi
472
+ buf[pos++] = widthLo
473
+
474
+ pos = encodeRleChannel(rowR, width, buf, pos)
475
+ pos = encodeRleChannel(rowG, width, buf, pos)
476
+ pos = encodeRleChannel(rowB, width, buf, pos)
477
+ pos = encodeRleChannel(rowE, width, buf, pos)
478
+ }
479
+
480
+ return buf.slice(0, pos)
481
+ }
package/src/index.ts ADDED
@@ -0,0 +1,127 @@
1
+ /**
2
+ * Main browser entry (`@kruschdev/pascal-plugin-mit-assets`).
3
+ *
4
+ * Clean-room MIT asset replacement plugin & static `public/` asset pack companion
5
+ * solving `pascalorg/editor#1327` with full real-world SKU & `pascal-bom/1.1` pricing integration:
6
+ * - `mitAssetsPlugin`: Core `Plugin` (`apiVersion: 1`, `mit-assets:item` + InspectorExtension)
7
+ * - `mitAssetsHostPanel`: Left-rail `EditorHostPanel` (155 MIT items, 68 PBR materials, 38 SFX)
8
+ * - `mitAssetsScheduleView`: Full-pane `EditorHostView` (MIT Provenance & Commercial Readiness Audit)
9
+ * - `mitAssetsChatExtension`: `PluginChatExtension` (`/mit-audit`, `/mit-place`, `/mit-bom`)
10
+ * - `configureMitAssetsViewer(baseUrl)`: Point `@pascal-app/viewer` at self-hosted MIT assets
11
+ */
12
+
13
+ import type { AnyNodeDefinition, InspectorExtension, Plugin } from '@pascal-app/core'
14
+ import type { EditorHostPanel, EditorHostView, PluginChatExtension } from '@pascal-app/editor'
15
+ import { configureViewer } from '@pascal-app/viewer'
16
+ import { normalizeBaseUrl } from './audit'
17
+ import { mitAssetsItemRenderDefinition } from './nodes/mit-item'
18
+ import {
19
+ MIT_ASSETS_PLUGIN_ID,
20
+ MIT_ASSETS_SCHEDULE_VIEW_ID,
21
+ mitAssetsRenderPlugin,
22
+ } from './render'
23
+
24
+ export const mitAssetsInspectorExtensions: InspectorExtension[] = [
25
+ {
26
+ id: `${MIT_ASSETS_PLUGIN_ID}:item-inspector`,
27
+ pluginId: MIT_ASSETS_PLUGIN_ID,
28
+ kinds: ['mit-assets:item'],
29
+ icon: { kind: 'iconify', name: 'lucide:shield-check' },
30
+ title: 'MIT Asset & Real-SKU Pricing',
31
+ component: () => import('./ui/inspector-card'),
32
+ primaryWhen: () => true,
33
+ },
34
+ ]
35
+
36
+ export const mitAssetsItemDefinition: AnyNodeDefinition = {
37
+ ...mitAssetsItemRenderDefinition,
38
+ } as unknown as AnyNodeDefinition
39
+
40
+ export const mitAssetsPlugin: Plugin = {
41
+ ...mitAssetsRenderPlugin,
42
+ nodes: [mitAssetsItemDefinition],
43
+ inspectorExtensions: mitAssetsInspectorExtensions,
44
+ }
45
+
46
+ export const mitAssetsHostPanel: EditorHostPanel = {
47
+ id: `${MIT_ASSETS_PLUGIN_ID}:panel`,
48
+ pluginId: MIT_ASSETS_PLUGIN_ID,
49
+ kinds: ['mit-assets:item'],
50
+ label: 'MIT Assets (#1327)',
51
+ summary:
52
+ '155 clean-room MIT 3D items, 68 procedural PBR material packs, 38 DSP SFX cues & sunset HDRI with real-world SKU pricing.',
53
+ description:
54
+ '100% clean-room MIT replacement for all bundled Pascal Editor assets (items/, material/, audios/sfx/, hdri/venice_sunset_1k.hdr) plus real-world SKU crosswalk and pascal-bom/1.1 procurement pricing.',
55
+ category: 'Assets & Licensing',
56
+ creator: {
57
+ name: '@kruschdev',
58
+ url: 'https://github.com/kruschdev',
59
+ },
60
+ pluginUrl: 'https://github.com/kruschdev/pascal-plugin-mit-assets',
61
+ icon: { kind: 'iconify', name: 'lucide:shield-check' },
62
+ component: () => import('./ui/host-panel'),
63
+ defaultInstalled: false,
64
+ }
65
+
66
+ export const mitAssetsScheduleView: EditorHostView = {
67
+ id: MIT_ASSETS_SCHEDULE_VIEW_ID,
68
+ pluginId: MIT_ASSETS_PLUGIN_ID,
69
+ label: 'MIT Asset Audit & BOM',
70
+ description:
71
+ 'Audit active scenes for external Supabase / unattributed bundled assets and inspect 1:1 MIT replacements & real-world SKU pricing.',
72
+ icon: { kind: 'iconify', name: 'lucide:file-check-2' },
73
+ component: () => import('./ui/schedule-view'),
74
+ workspaces: ['edit'],
75
+ defaultPinned: false,
76
+ }
77
+
78
+ export const mitAssetsChatExtension: PluginChatExtension = {
79
+ pluginId: MIT_ASSETS_PLUGIN_ID,
80
+ cards: {
81
+ mit_search_items: () => import('./ui/chat-card'),
82
+ mit_list_materials: () => import('./ui/chat-card'),
83
+ mit_audit_scene: () => import('./ui/chat-card'),
84
+ mit_place_item: () => import('./ui/chat-card'),
85
+ mit_replace_scene_items: () => import('./ui/chat-card'),
86
+ mit_schedule_bom: () => import('./ui/chat-card'),
87
+ },
88
+ actions: [
89
+ {
90
+ id: 'mit-audit',
91
+ label: 'Audit Scene MIT Readiness',
92
+ hint: 'Check for non-MIT Supabase or bundled assets and list 1:1 clean-room MIT replacements',
93
+ prompt: 'Run mit_audit_scene to check commercial MIT license readiness across all nodes.',
94
+ },
95
+ {
96
+ id: 'mit-replace',
97
+ label: 'Migrate Scene Items to MIT',
98
+ hint: 'Replace non-MIT Pascal item nodes with clean-room MIT procedural mit-assets:item nodes',
99
+ prompt: 'Run mit_replace_scene_items to migrate replaceable scene items to clean-room MIT nodes.',
100
+ },
101
+ {
102
+ id: 'mit-bom',
103
+ label: 'MIT Real-SKU Priced BOM',
104
+ hint: 'Generate a CSI MasterFormat priced procurement BOM & CSV for all placed MIT assets',
105
+ prompt: 'Run mit_schedule_bom to compile real-world manufacturer SKUs, pricing, and CSV.',
106
+ },
107
+ ],
108
+ }
109
+
110
+ /**
111
+ * Configure `@pascal-app/viewer` to resolve all materials, SFX, and static assets
112
+ * from a self-hosted drop-in MIT `public/` directory (e.g. `""` for local `/public` or a CDN URL).
113
+ */
114
+ export function configureMitAssetsViewer(baseUrl = ''): void {
115
+ const base = normalizeBaseUrl(baseUrl)
116
+ configureViewer({
117
+ assetsBaseUrl: base,
118
+ sfxBaseUrl: `${base}/audios/sfx`,
119
+ })
120
+ }
121
+
122
+ export default mitAssetsPlugin
123
+ export * from './render'
124
+ export * from './manifest'
125
+ export * from './audit'
126
+ export * from './sku-crosswalk'
127
+ export * from './bom'