@holoscript/core 6.0.4 → 7.0.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 (236) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +1 -1
  3. package/dist/compiler/index.d.ts +82 -0
  4. package/dist/constants.d.ts +3 -2
  5. package/dist/coordinators/index.d.ts +189 -0
  6. package/dist/index.d.ts +501 -19
  7. package/dist/paper-0c-spike/index.d.ts +29 -0
  8. package/dist/reconstruction/index.d.ts +78 -0
  9. package/dist/tools/index.d.ts +22 -1
  10. package/dist/traitDocs/traitDocs.d.ts +69 -0
  11. package/dist/traits/index.d.ts +61 -0
  12. package/package.json +105 -57
  13. package/dist/GLTFPipeline-DEN36VNK.js +0 -12
  14. package/dist/GLTFPipeline-YPCAK236.cjs +0 -33
  15. package/dist/HoloScriptPlusParser-BN6KVRCM.js +0 -692
  16. package/dist/HoloScriptPlusParser-NC5FE6AL.cjs +0 -697
  17. package/dist/USDZExporter-NTMBNTDB.js +0 -707
  18. package/dist/USDZExporter-UWGWNMMD.cjs +0 -709
  19. package/dist/chunk-27LWW5FU.cjs +0 -410
  20. package/dist/chunk-2CWOLHTE.js +0 -69
  21. package/dist/chunk-33LSUQDD.cjs +0 -835
  22. package/dist/chunk-3FJCK5XA.js +0 -2232
  23. package/dist/chunk-3FXV5S25.cjs +0 -633
  24. package/dist/chunk-3FYZOR7S.cjs +0 -69
  25. package/dist/chunk-3SAK5KFL.cjs +0 -83
  26. package/dist/chunk-4XSNJCLC.cjs +0 -1859
  27. package/dist/chunk-54FHG2MX.js +0 -655
  28. package/dist/chunk-56IF4NTA.js +0 -56
  29. package/dist/chunk-5BGSECRJ.cjs +0 -2237
  30. package/dist/chunk-5GLCTO44.js +0 -161
  31. package/dist/chunk-5O6TQC6M.cjs +0 -1871
  32. package/dist/chunk-5OEOHAAW.cjs +0 -682
  33. package/dist/chunk-5TOFIR6L.js +0 -407
  34. package/dist/chunk-5WUNN6ZN.cjs +0 -428
  35. package/dist/chunk-6TZPZCOJ.cjs +0 -1404
  36. package/dist/chunk-6UEHYZ7V.cjs +0 -773
  37. package/dist/chunk-6XSERL6L.js +0 -5678
  38. package/dist/chunk-72EQECGT.cjs +0 -908
  39. package/dist/chunk-7AGYRWKW.cjs +0 -507
  40. package/dist/chunk-7LCYLPW2.cjs +0 -663
  41. package/dist/chunk-A7PIMZGU.js +0 -263
  42. package/dist/chunk-ATSKSYVE.cjs +0 -51683
  43. package/dist/chunk-B5TCIAPQ.cjs +0 -117
  44. package/dist/chunk-BF2235SI.cjs +0 -5714
  45. package/dist/chunk-BKIGPPVM.js +0 -629
  46. package/dist/chunk-BND3ST2K.cjs +0 -662
  47. package/dist/chunk-BU7VWW2K.js +0 -2522
  48. package/dist/chunk-BWFJEM5A.js +0 -5419
  49. package/dist/chunk-CAUCGUEA.cjs +0 -130
  50. package/dist/chunk-CBJSLA2E.cjs +0 -5423
  51. package/dist/chunk-CDPGV4DN.js +0 -114
  52. package/dist/chunk-CLYEIWA5.cjs +0 -408
  53. package/dist/chunk-CS2EMTGF.js +0 -1966
  54. package/dist/chunk-DMG7C4H2.js +0 -975
  55. package/dist/chunk-DXJQDCFL.js +0 -468
  56. package/dist/chunk-E3FWRT3Z.js +0 -608
  57. package/dist/chunk-E3UALNFA.js +0 -421
  58. package/dist/chunk-EONILVMF.js +0 -762
  59. package/dist/chunk-EQV4R3EV.cjs +0 -769
  60. package/dist/chunk-F3HH56EB.cjs +0 -5538
  61. package/dist/chunk-F4IULT7N.js +0 -1488
  62. package/dist/chunk-FF3Q7ADR.js +0 -380
  63. package/dist/chunk-FFKU7BTK.cjs +0 -1046
  64. package/dist/chunk-FHQVYCH2.js +0 -70
  65. package/dist/chunk-FSF7EQVA.cjs +0 -1974
  66. package/dist/chunk-G4VZTCIB.js +0 -659
  67. package/dist/chunk-G7CT3EMP.cjs +0 -1002
  68. package/dist/chunk-GGHSW2NN.js +0 -51334
  69. package/dist/chunk-GVUR45UF.cjs +0 -777
  70. package/dist/chunk-H5Z7NASB.js +0 -9662
  71. package/dist/chunk-HE7ULERA.cjs +0 -697
  72. package/dist/chunk-HJJLD366.js +0 -1169
  73. package/dist/chunk-HPS76H7Q.js +0 -309
  74. package/dist/chunk-HQUEA5R6.cjs +0 -424
  75. package/dist/chunk-HYNTS5CP.js +0 -422
  76. package/dist/chunk-I6XZ5DZF.cjs +0 -488
  77. package/dist/chunk-IBDG74G2.cjs +0 -1219
  78. package/dist/chunk-IFNQFCTM.js +0 -3098
  79. package/dist/chunk-IHOUYQIA.js +0 -406
  80. package/dist/chunk-ILRBGFVD.cjs +0 -72
  81. package/dist/chunk-IWI6J7FX.js +0 -421
  82. package/dist/chunk-K3JDKWGI.cjs +0 -270
  83. package/dist/chunk-K6EKD26I.js +0 -630
  84. package/dist/chunk-KCQ5NDYC.cjs +0 -3172
  85. package/dist/chunk-KED34ILP.js +0 -832
  86. package/dist/chunk-KSGXLT74.cjs +0 -457
  87. package/dist/chunk-L4G4RLXX.js +0 -767
  88. package/dist/chunk-LDP5OK6G.js +0 -1216
  89. package/dist/chunk-LGGRPKTV.cjs +0 -735
  90. package/dist/chunk-LK5IAVH6.cjs +0 -1173
  91. package/dist/chunk-LSW7P7ML.js +0 -3675
  92. package/dist/chunk-LXJ4667L.cjs +0 -3874
  93. package/dist/chunk-LZ266PCM.cjs +0 -4499
  94. package/dist/chunk-MD6KDHVE.cjs +0 -237
  95. package/dist/chunk-MEASWI2Y.js +0 -126
  96. package/dist/chunk-MPXBVFHQ.js +0 -768
  97. package/dist/chunk-N5FTS757.cjs +0 -415
  98. package/dist/chunk-NCUKG4SK.cjs +0 -3075
  99. package/dist/chunk-NDQNIJEH.js +0 -1715
  100. package/dist/chunk-NOZZ46QU.js +0 -168
  101. package/dist/chunk-OFKWH2IP.js +0 -449
  102. package/dist/chunk-PHENW4MQ.js +0 -65
  103. package/dist/chunk-PMGODDJA.cjs +0 -319
  104. package/dist/chunk-Q4QX3AET.cjs +0 -1505
  105. package/dist/chunk-Q56TT7IL.js +0 -483
  106. package/dist/chunk-Q5JT3YML.cjs +0 -129
  107. package/dist/chunk-Q5SJOGHQ.cjs +0 -4256
  108. package/dist/chunk-QGKNANZ3.js +0 -3071
  109. package/dist/chunk-QLEAOI3Q.cjs +0 -424
  110. package/dist/chunk-R7MA7QWV.js +0 -732
  111. package/dist/chunk-RVYPEYPX.js +0 -678
  112. package/dist/chunk-S2N5TNMA.js +0 -1855
  113. package/dist/chunk-S565K7NK.js +0 -752
  114. package/dist/chunk-SDAMZIRE.js +0 -765
  115. package/dist/chunk-T36DDXSF.js +0 -4250
  116. package/dist/chunk-T4NKMBDL.js +0 -5474
  117. package/dist/chunk-T7LEXZUZ.cjs +0 -2526
  118. package/dist/chunk-TEWCN33Y.js +0 -694
  119. package/dist/chunk-TQSZUOW5.cjs +0 -793
  120. package/dist/chunk-TSH3MSQU.cjs +0 -129
  121. package/dist/chunk-UERJ3YJV.js +0 -504
  122. package/dist/chunk-UPJBDCVF.js +0 -1395
  123. package/dist/chunk-V3NN3HPP.js +0 -4462
  124. package/dist/chunk-VJ3L7CHT.cjs +0 -169
  125. package/dist/chunk-WB4Z63GG.js +0 -229
  126. package/dist/chunk-WDW67DZB.cjs +0 -9728
  127. package/dist/chunk-WGMEAYBG.js +0 -126
  128. package/dist/chunk-X4ZF6CNE.cjs +0 -473
  129. package/dist/chunk-X6SEAXAX.cjs +0 -3681
  130. package/dist/chunk-XCWFGZAA.js +0 -1043
  131. package/dist/chunk-XD6IYDUX.js +0 -903
  132. package/dist/chunk-XG23EUQX.cjs +0 -1717
  133. package/dist/chunk-XRKWN5PL.cjs +0 -173
  134. package/dist/chunk-XUILI4KB.cjs +0 -430
  135. package/dist/chunk-XUTX5CBW.js +0 -126
  136. package/dist/chunk-XWPNTWDN.cjs +0 -755
  137. package/dist/chunk-XXINBTZK.cjs +0 -633
  138. package/dist/chunk-YCXFCXDS.js +0 -1868
  139. package/dist/chunk-YQK5JNFK.js +0 -3725
  140. package/dist/chunk-YYXH45E2.js +0 -426
  141. package/dist/chunk-Z34RLXRA.cjs +0 -612
  142. package/dist/chunk-ZP4D3CSX.cjs +0 -72
  143. package/dist/cli/holoscript-runner.cjs +0 -2259
  144. package/dist/cli/holoscript-runner.js +0 -2234
  145. package/dist/codebase/index.cjs +0 -336
  146. package/dist/codebase/index.js +0 -331
  147. package/dist/compiler/agent-inference.cjs +0 -28
  148. package/dist/compiler/agent-inference.js +0 -5
  149. package/dist/compiler/android-xr.cjs +0 -19
  150. package/dist/compiler/android-xr.js +0 -9
  151. package/dist/compiler/android.cjs +0 -20
  152. package/dist/compiler/android.js +0 -10
  153. package/dist/compiler/ar.cjs +0 -20
  154. package/dist/compiler/ar.js +0 -8
  155. package/dist/compiler/babylon.cjs +0 -17
  156. package/dist/compiler/babylon.js +0 -11
  157. package/dist/compiler/coco.cjs +0 -27
  158. package/dist/compiler/coco.js +0 -4
  159. package/dist/compiler/domain-block-utils.cjs +0 -602
  160. package/dist/compiler/domain-block-utils.js +0 -8
  161. package/dist/compiler/dtdl.cjs +0 -24
  162. package/dist/compiler/dtdl.js +0 -8
  163. package/dist/compiler/gltf-pipeline.cjs +0 -39
  164. package/dist/compiler/gltf-pipeline.js +0 -4
  165. package/dist/compiler/godot.cjs +0 -15
  166. package/dist/compiler/godot.js +0 -9
  167. package/dist/compiler/incremental.cjs +0 -29
  168. package/dist/compiler/incremental.js +0 -4
  169. package/dist/compiler/index.cjs +0 -2578
  170. package/dist/compiler/index.js +0 -2383
  171. package/dist/compiler/ios.cjs +0 -20
  172. package/dist/compiler/ios.js +0 -10
  173. package/dist/compiler/multi-layer.cjs +0 -20
  174. package/dist/compiler/multi-layer.js +0 -11
  175. package/dist/compiler/nodetoy.cjs +0 -23
  176. package/dist/compiler/nodetoy.js +0 -4
  177. package/dist/compiler/openxr.cjs +0 -15
  178. package/dist/compiler/openxr.js +0 -9
  179. package/dist/compiler/playcanvas.cjs +0 -16
  180. package/dist/compiler/playcanvas.js +0 -10
  181. package/dist/compiler/r3f.cjs +0 -34
  182. package/dist/compiler/r3f.js +0 -12
  183. package/dist/compiler/remotion.cjs +0 -23
  184. package/dist/compiler/remotion.js +0 -4
  185. package/dist/compiler/reproducibility.cjs +0 -39
  186. package/dist/compiler/reproducibility.js +0 -4
  187. package/dist/compiler/sdf.cjs +0 -21
  188. package/dist/compiler/sdf.js +0 -9
  189. package/dist/compiler/semantic-scene.cjs +0 -31
  190. package/dist/compiler/semantic-scene.js +0 -4
  191. package/dist/compiler/state.cjs +0 -17
  192. package/dist/compiler/state.js +0 -7
  193. package/dist/compiler/trait-composition.cjs +0 -26
  194. package/dist/compiler/trait-composition.js +0 -5
  195. package/dist/compiler/unity.cjs +0 -15
  196. package/dist/compiler/unity.js +0 -9
  197. package/dist/compiler/unreal.cjs +0 -19
  198. package/dist/compiler/unreal.js +0 -9
  199. package/dist/compiler/urdf.cjs +0 -45
  200. package/dist/compiler/urdf.js +0 -9
  201. package/dist/compiler/usd-physics.cjs +0 -23
  202. package/dist/compiler/usd-physics.js +0 -6
  203. package/dist/compiler/visionos.cjs +0 -15
  204. package/dist/compiler/visionos.js +0 -9
  205. package/dist/compiler/vrchat.cjs +0 -19
  206. package/dist/compiler/vrchat.js +0 -9
  207. package/dist/compiler/vrr.cjs +0 -21
  208. package/dist/compiler/vrr.js +0 -9
  209. package/dist/compiler/wasm.cjs +0 -33
  210. package/dist/compiler/wasm.js +0 -9
  211. package/dist/compiler/webgpu.cjs +0 -15
  212. package/dist/compiler/webgpu.js +0 -9
  213. package/dist/debugger.cjs +0 -21
  214. package/dist/debugger.js +0 -8
  215. package/dist/entries/interop.cjs +0 -62
  216. package/dist/entries/interop.js +0 -5
  217. package/dist/entries/scripting.cjs +0 -68
  218. package/dist/entries/scripting.js +0 -11
  219. package/dist/index.cjs +0 -40921
  220. package/dist/index.js +0 -37763
  221. package/dist/math/vec3.cjs +0 -57
  222. package/dist/math/vec3.js +0 -4
  223. package/dist/ml-dsa-PHCWUBPX.cjs +0 -1178
  224. package/dist/ml-dsa-WYLJHJO6.js +0 -1178
  225. package/dist/parser.cjs +0 -27
  226. package/dist/parser.js +0 -10
  227. package/dist/playwright-5OSAPTNH.js +0 -98660
  228. package/dist/playwright-RL6GY4F7.cjs +0 -98673
  229. package/dist/runtime.cjs +0 -16
  230. package/dist/runtime.js +0 -7
  231. package/dist/storage/index.cjs +0 -37
  232. package/dist/storage/index.js +0 -4
  233. package/dist/traits/index.cjs +0 -14649
  234. package/dist/traits/index.js +0 -12243
  235. package/dist/type-checker.cjs +0 -18
  236. package/dist/type-checker.js +0 -5
@@ -1,1505 +0,0 @@
1
- 'use strict';
2
-
3
- // src/traits/LightingTrait.ts
4
- var LightingTrait = class {
5
- constructor(config) {
6
- this.lights = /* @__PURE__ */ new Map();
7
- this.lightIdCounter = 0;
8
- this.globalIllumination = {
9
- enabled: true,
10
- intensity: 1,
11
- skyColor: { r: 0.5, g: 0.7, b: 1 },
12
- skyIntensity: 1,
13
- groundColor: { r: 0.4, g: 0.4, b: 0.4 },
14
- groundIntensity: 0.5,
15
- probes: true,
16
- indirectDiffuse: 1,
17
- indirectSpecular: 1,
18
- aoIntensity: 1,
19
- screenSpaceAO: true,
20
- ...config
21
- };
22
- }
23
- /**
24
- * Add a light to the scene
25
- */
26
- addLight(light) {
27
- const id = light.name || `light_${this.lightIdCounter++}`;
28
- this.lights.set(id, light);
29
- return id;
30
- }
31
- /**
32
- * Get light by ID
33
- */
34
- getLight(id) {
35
- return this.lights.get(id);
36
- }
37
- /**
38
- * Get all lights
39
- */
40
- getLights() {
41
- return Array.from(this.lights.values());
42
- }
43
- /**
44
- * Get lights by type
45
- */
46
- getLightsByType(type) {
47
- return Array.from(this.lights.values()).filter((l) => l.type === type);
48
- }
49
- /**
50
- * Update light properties
51
- */
52
- updateLight(id, updates) {
53
- const light = this.lights.get(id);
54
- if (!light) return false;
55
- this.lights.set(id, { ...light, ...updates });
56
- return true;
57
- }
58
- /**
59
- * Remove light
60
- */
61
- removeLight(id) {
62
- return this.lights.delete(id);
63
- }
64
- /**
65
- * Clear all lights
66
- */
67
- clearLights() {
68
- this.lights.clear();
69
- }
70
- /**
71
- * Get global illumination config
72
- */
73
- getGlobalIllumination() {
74
- return { ...this.globalIllumination };
75
- }
76
- /**
77
- * Update global illumination
78
- */
79
- updateGlobalIllumination(updates) {
80
- this.globalIllumination = {
81
- ...this.globalIllumination,
82
- ...updates
83
- };
84
- }
85
- /**
86
- * Enable/disable GI
87
- */
88
- setGIEnabled(enabled) {
89
- this.globalIllumination.enabled = enabled;
90
- }
91
- /**
92
- * Set ambient light colors (skybox mode)
93
- */
94
- setAmbientLight(skyColor, groundColor, intensity = 1) {
95
- this.globalIllumination.skyColor = skyColor;
96
- this.globalIllumination.groundColor = groundColor;
97
- this.globalIllumination.skyIntensity = intensity;
98
- this.globalIllumination.groundIntensity = intensity * 0.5;
99
- }
100
- /**
101
- * Enable/disable screen-space ambient occlusion
102
- */
103
- setScreenSpaceAO(enabled, intensity = 1) {
104
- this.globalIllumination.screenSpaceAO = enabled;
105
- this.globalIllumination.aoIntensity = intensity;
106
- }
107
- /**
108
- * Create directional light (sun)
109
- */
110
- createDirectionalLight(direction, color, intensity = 1, castShadows = true) {
111
- const light = {
112
- type: "directional",
113
- name: `sun_${this.lightIdCounter}`,
114
- direction,
115
- color,
116
- intensity,
117
- shadow: castShadows ? {
118
- type: "soft",
119
- resolution: 2048,
120
- cascades: 4,
121
- softness: 1
122
- } : void 0,
123
- volumetric: true,
124
- priority: 100
125
- };
126
- return this.addLight(light);
127
- }
128
- /**
129
- * Create point light
130
- */
131
- createPointLight(position, color, intensity, range, castShadows = false) {
132
- const light = {
133
- type: "point",
134
- name: `point_${this.lightIdCounter}`,
135
- position,
136
- color,
137
- intensity,
138
- range,
139
- shadow: castShadows ? {
140
- type: "soft",
141
- resolution: 512,
142
- softness: 0.5
143
- } : void 0,
144
- priority: 50
145
- };
146
- return this.addLight(light);
147
- }
148
- /**
149
- * Create spot light
150
- */
151
- createSpotLight(position, direction, color, intensity, range, spotAngle = 45, castShadows = true) {
152
- const light = {
153
- type: "spot",
154
- name: `spot_${this.lightIdCounter}`,
155
- position,
156
- direction,
157
- color,
158
- intensity,
159
- range,
160
- spotAngle,
161
- innerSpotAngle: spotAngle * 0.5,
162
- shadow: castShadows ? {
163
- type: "soft",
164
- resolution: 1024,
165
- softness: 0.8
166
- } : void 0,
167
- priority: 75
168
- };
169
- return this.addLight(light);
170
- }
171
- /**
172
- * Create area light for soft lighting
173
- */
174
- createAreaLight(position, color, intensity, width, height) {
175
- const light = {
176
- type: "area",
177
- name: `area_${this.lightIdCounter}`,
178
- position,
179
- color,
180
- intensity,
181
- range: Math.max(width, height) * 2,
182
- priority: 25
183
- };
184
- return this.addLight(light);
185
- }
186
- /**
187
- * Get shadow-casting lights
188
- */
189
- getShadowCastingLights() {
190
- return Array.from(this.lights.values()).filter((l) => l.shadow && l.shadow.type !== "none");
191
- }
192
- /**
193
- * Get light count by type
194
- */
195
- getLightCount() {
196
- const counts = {
197
- directional: 0,
198
- point: 0,
199
- spot: 0,
200
- area: 0,
201
- probe: 0
202
- };
203
- for (const light of Array.from(this.lights.values())) {
204
- counts[light.type]++;
205
- }
206
- return counts;
207
- }
208
- /**
209
- * Estimate light impact for performance optimization
210
- */
211
- getPerformanceImpact() {
212
- const totalLights = this.lights.size;
213
- const shadowCasters = this.getShadowCastingLights().length;
214
- let estimatedGPUCost = "low";
215
- if (totalLights > 16 || shadowCasters > 4) {
216
- estimatedGPUCost = "high";
217
- } else if (totalLights > 8 || shadowCasters > 2) {
218
- estimatedGPUCost = "medium";
219
- }
220
- return {
221
- totalLights,
222
- shadowCasters,
223
- estimatedGPUCost
224
- };
225
- }
226
- /**
227
- * Get scene complexity info
228
- */
229
- getSceneInfo() {
230
- const counts = this.getLightCount();
231
- const impact = this.getPerformanceImpact();
232
- return `Lighting: ${counts.directional} dir, ${counts.point} point, ${counts.spot} spot | Shadows: ${impact.shadowCasters} | GPU: ${impact.estimatedGPUCost}`;
233
- }
234
- /**
235
- * Dispose and cleanup
236
- */
237
- dispose() {
238
- this.lights.clear();
239
- }
240
- };
241
- function createLightingTrait(config) {
242
- return new LightingTrait(config);
243
- }
244
- var LIGHTING_PRESETS = {
245
- /** Neutral studio lighting */
246
- studio: () => ({
247
- enabled: true,
248
- intensity: 1,
249
- skyColor: { r: 0.5, g: 0.5, b: 0.5 },
250
- skyIntensity: 0.5,
251
- groundColor: { r: 0.3, g: 0.3, b: 0.3 },
252
- groundIntensity: 0.3
253
- }),
254
- /** Bright outdoor lighting */
255
- outdoor: () => ({
256
- enabled: true,
257
- intensity: 1.2,
258
- skyColor: { r: 0.7, g: 0.85, b: 1 },
259
- skyIntensity: 1,
260
- groundColor: { r: 0.4, g: 0.4, b: 0.35 },
261
- groundIntensity: 0.6,
262
- indirectDiffuse: 1.2
263
- }),
264
- /** Dim interior lighting */
265
- interior: () => ({
266
- enabled: true,
267
- intensity: 0.6,
268
- skyColor: { r: 0.3, g: 0.3, b: 0.35 },
269
- skyIntensity: 0.4,
270
- groundColor: { r: 0.2, g: 0.2, b: 0.2 },
271
- groundIntensity: 0.2
272
- }),
273
- /** Night scene */
274
- night: () => ({
275
- enabled: true,
276
- intensity: 0.3,
277
- skyColor: { r: 0.01, g: 0.01, b: 0.02 },
278
- skyIntensity: 0.1,
279
- groundColor: { r: 0.02, g: 0.02, b: 0.02 },
280
- groundIntensity: 0.05,
281
- screenSpaceAO: false
282
- }),
283
- /** Sunset/golden hour */
284
- sunset: () => ({
285
- enabled: true,
286
- intensity: 1.1,
287
- skyColor: { r: 1, g: 0.7, b: 0.3 },
288
- skyIntensity: 1,
289
- groundColor: { r: 0.6, g: 0.4, b: 0.2 },
290
- groundIntensity: 0.8
291
- })
292
- };
293
- var lightingHandler = {
294
- name: "lighting",
295
- defaultConfig: {},
296
- onAttach(node, config, ctx) {
297
- const instance = new LightingTrait(config);
298
- node.__lighting_instance = instance;
299
- ctx.emit("lighting_attached", { node, config });
300
- },
301
- onDetach(node, _config, ctx) {
302
- const instance = node.__lighting_instance;
303
- if (instance) {
304
- if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
305
- else if (typeof instance.dispose === "function") instance.dispose();
306
- else if (typeof instance.cleanup === "function") instance.cleanup();
307
- }
308
- ctx.emit("lighting_detached", { node });
309
- delete node.__lighting_instance;
310
- },
311
- onEvent(node, _config, ctx, event) {
312
- const instance = node.__lighting_instance;
313
- if (!instance) return;
314
- if (typeof instance.onEvent === "function") instance.onEvent(event);
315
- else if (typeof instance.emit === "function" && event.type) instance.emit(event);
316
- if (event.type === "lighting_configure" && event.payload) {
317
- Object.assign(instance, event.payload);
318
- ctx.emit("lighting_configured", { node });
319
- }
320
- },
321
- onUpdate(node, _config, ctx, dt) {
322
- const instance = node.__lighting_instance;
323
- if (!instance) return;
324
- if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
325
- }
326
- };
327
-
328
- // src/traits/MaterialTrait.ts
329
- var MaterialTrait = class {
330
- constructor(config) {
331
- this.textureCache = /* @__PURE__ */ new Map();
332
- this.material = {
333
- ...{ type: "pbr" },
334
- ...config
335
- };
336
- }
337
- /**
338
- * Get material properties
339
- */
340
- getMaterial() {
341
- return { ...this.material };
342
- }
343
- /**
344
- * Update material property
345
- */
346
- setProperty(key, value) {
347
- this.material[key] = value;
348
- }
349
- /**
350
- * Get PBR properties
351
- */
352
- getPBRProperties() {
353
- return this.material.pbr;
354
- }
355
- /**
356
- * Update PBR material
357
- */
358
- updatePBR(pbr) {
359
- if (!this.material.pbr) {
360
- this.material.pbr = {
361
- baseColor: { r: 1, g: 1, b: 1 },
362
- metallic: 0,
363
- roughness: 0.5
364
- };
365
- }
366
- this.material.pbr = { ...this.material.pbr, ...pbr };
367
- }
368
- /**
369
- * Add texture map
370
- */
371
- addTexture(texture) {
372
- if (!this.material.textures) {
373
- this.material.textures = [];
374
- }
375
- this.material.textures.push(texture);
376
- }
377
- /**
378
- * Get all textures
379
- */
380
- getTextures() {
381
- return [...this.material.textures || []];
382
- }
383
- /**
384
- * Clear texture cache (for memory optimization)
385
- */
386
- clearTextureCache() {
387
- this.textureCache.clear();
388
- }
389
- /**
390
- * Get shader code if custom
391
- */
392
- getCustomShader() {
393
- return this.material.customShader;
394
- }
395
- /**
396
- * Set custom shader
397
- */
398
- setCustomShader(shader) {
399
- this.material.customShader = shader;
400
- }
401
- /**
402
- * Get optimization hints
403
- */
404
- getOptimization() {
405
- return this.material.optimization;
406
- }
407
- /**
408
- * Enable/disable texture streaming
409
- */
410
- setTextureStreaming(enabled) {
411
- if (!this.material.optimization) {
412
- this.material.optimization = {};
413
- }
414
- this.material.optimization.streamTextures = enabled;
415
- }
416
- /**
417
- * Set texture compression
418
- */
419
- setCompression(compression) {
420
- if (!this.material.optimization) {
421
- this.material.optimization = {};
422
- }
423
- this.material.optimization.compression = compression;
424
- }
425
- /**
426
- * Enable material instancing for performance
427
- */
428
- setInstanced(instanced) {
429
- if (!this.material.optimization) {
430
- this.material.optimization = {};
431
- }
432
- this.material.optimization.instanced = instanced;
433
- }
434
- /**
435
- * Dispose and cleanup
436
- */
437
- dispose() {
438
- this.textureCache.clear();
439
- }
440
- };
441
- function createMaterialTrait(config) {
442
- return new MaterialTrait(config);
443
- }
444
- var MATERIAL_PRESETS = {
445
- /** Shiny metal */
446
- chrome: () => ({
447
- type: "pbr",
448
- pbr: {
449
- baseColor: { r: 0.77, g: 0.77, b: 0.77 },
450
- metallic: 1,
451
- roughness: 0.1
452
- }
453
- }),
454
- /** Rough plastic */
455
- plastic: () => ({
456
- type: "pbr",
457
- pbr: {
458
- baseColor: { r: 1, g: 1, b: 1 },
459
- metallic: 0,
460
- roughness: 0.8
461
- }
462
- }),
463
- /** Wood texture */
464
- wood: () => ({
465
- type: "pbr",
466
- pbr: {
467
- baseColor: { r: 0.6, g: 0.4, b: 0.2 },
468
- metallic: 0,
469
- roughness: 0.4
470
- }
471
- }),
472
- /** Glass */
473
- glass: () => ({
474
- type: "transparent",
475
- blendMode: "blend",
476
- pbr: {
477
- baseColor: { r: 1, g: 1, b: 1, a: 0.3 },
478
- metallic: 0,
479
- roughness: 0,
480
- ior: 1.5,
481
- transmission: 0.9
482
- }
483
- }),
484
- /** Emissive (glowing) */
485
- emissive: () => ({
486
- type: "pbr",
487
- pbr: {
488
- baseColor: { r: 0, g: 1, b: 0 },
489
- metallic: 0,
490
- roughness: 1,
491
- emission: {
492
- color: { r: 0, g: 1, b: 0 },
493
- intensity: 2
494
- }
495
- }
496
- }),
497
- /** Skin material */
498
- skin: () => ({
499
- type: "pbr",
500
- pbr: {
501
- baseColor: { r: 1, g: 0.8, b: 0.7 },
502
- metallic: 0,
503
- roughness: 0.5,
504
- ambientOcclusion: 0.8
505
- }
506
- })
507
- };
508
- var materialHandler = {
509
- name: "material",
510
- defaultConfig: {},
511
- onAttach(node, config, ctx) {
512
- const instance = new MaterialTrait(config);
513
- node.__material_instance = instance;
514
- ctx.emit("material_attached", { node, config });
515
- },
516
- onDetach(node, _config, ctx) {
517
- const instance = node.__material_instance;
518
- if (instance) {
519
- if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
520
- else if (typeof instance.dispose === "function") instance.dispose();
521
- else if (typeof instance.cleanup === "function") instance.cleanup();
522
- }
523
- ctx.emit("material_detached", { node });
524
- delete node.__material_instance;
525
- },
526
- onEvent(node, _config, ctx, event) {
527
- const instance = node.__material_instance;
528
- if (!instance) return;
529
- if (typeof instance.onEvent === "function") instance.onEvent(event);
530
- else if (typeof instance.emit === "function" && event.type) instance.emit(event);
531
- if (event.type === "material_configure" && event.payload) {
532
- Object.assign(instance, event.payload);
533
- ctx.emit("material_configured", { node });
534
- }
535
- },
536
- onUpdate(node, _config, ctx, dt) {
537
- const instance = node.__material_instance;
538
- if (!instance) return;
539
- if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
540
- }
541
- };
542
-
543
- // src/traits/RenderingTrait.ts
544
- var RenderingTrait = class {
545
- constructor(config) {
546
- this.optimization = {
547
- lodStrategy: "automatic",
548
- culling: {
549
- mode: "back",
550
- frustum: true,
551
- occlusion: true
552
- },
553
- batching: {
554
- static: true,
555
- dynamic: true,
556
- instancing: true,
557
- maxInstanceCount: 1e3
558
- },
559
- textures: {
560
- streaming: true,
561
- compression: "auto",
562
- mipmaps: true,
563
- maxResolution: 2048
564
- },
565
- shaders: {
566
- simplifiedShaders: true,
567
- lodBias: 0
568
- },
569
- targetGPUTier: "high",
570
- adaptiveQuality: true,
571
- targetFrameRate: 60,
572
- ...config
573
- };
574
- }
575
- /**
576
- * Get rendering optimization config
577
- */
578
- getOptimization() {
579
- return JSON.parse(JSON.stringify(this.optimization));
580
- }
581
- /**
582
- * Update rendering configuration
583
- */
584
- updateOptimization(updates) {
585
- this.optimization = { ...this.optimization, ...updates };
586
- }
587
- /**
588
- * Setup LOD levels (3 levels is typical)
589
- */
590
- setupLODLevels(strategy = "automatic") {
591
- const levels = [
592
- {
593
- level: 0,
594
- screenRelativeSize: 0.5,
595
- polygonReduction: 1,
596
- textureScale: 1
597
- },
598
- {
599
- level: 1,
600
- screenRelativeSize: 0.25,
601
- polygonReduction: 0.6,
602
- disabledFeatures: ["specular"],
603
- textureScale: 0.5
604
- },
605
- {
606
- level: 2,
607
- screenRelativeSize: 0.1,
608
- polygonReduction: 0.3,
609
- disabledFeatures: ["specular", "normals"],
610
- textureScale: 0.25
611
- }
612
- ];
613
- this.optimization.lodStrategy = strategy;
614
- this.optimization.lodLevels = levels;
615
- }
616
- /**
617
- * Get LOD levels
618
- */
619
- getLODLevels() {
620
- return [...this.optimization.lodLevels || []];
621
- }
622
- /**
623
- * Configure culling
624
- */
625
- setCulling(config) {
626
- const defaultCulling = { mode: "back" };
627
- this.optimization.culling = {
628
- ...defaultCulling,
629
- ...this.optimization.culling,
630
- ...config
631
- };
632
- }
633
- /**
634
- * Enable frustum culling
635
- */
636
- setFrustumCulling(enabled) {
637
- if (!this.optimization.culling) {
638
- this.optimization.culling = { mode: "back" };
639
- }
640
- this.optimization.culling.frustum = enabled;
641
- }
642
- /**
643
- * Enable occlusion culling
644
- */
645
- setOcclusionCulling(enabled, distance) {
646
- if (!this.optimization.culling) {
647
- this.optimization.culling = { mode: "back" };
648
- }
649
- this.optimization.culling.occlusion = enabled;
650
- if (distance) {
651
- this.optimization.culling.occlusionDistance = distance;
652
- }
653
- }
654
- /**
655
- * Configure batching
656
- */
657
- setBatching(config) {
658
- this.optimization.batching = {
659
- ...this.optimization.batching,
660
- ...config
661
- };
662
- }
663
- /**
664
- * Enable GPU instancing
665
- */
666
- setInstancing(enabled, maxInstances) {
667
- if (!this.optimization.batching) {
668
- this.optimization.batching = {};
669
- }
670
- this.optimization.batching.instancing = enabled;
671
- if (maxInstances) {
672
- this.optimization.batching.maxInstanceCount = maxInstances;
673
- }
674
- }
675
- /**
676
- * Configure texture optimization
677
- */
678
- setTextureOptimization(config) {
679
- this.optimization.textures = {
680
- ...this.optimization.textures,
681
- ...config
682
- };
683
- }
684
- /**
685
- * Enable texture streaming
686
- */
687
- setTextureStreaming(enabled, budgetMB) {
688
- if (!this.optimization.textures) {
689
- this.optimization.textures = {};
690
- }
691
- this.optimization.textures.streaming = enabled;
692
- if (budgetMB) {
693
- this.optimization.textures.streamingBudget = budgetMB;
694
- }
695
- }
696
- /**
697
- * Set texture compression
698
- */
699
- setTextureCompression(compression) {
700
- if (!this.optimization.textures) {
701
- this.optimization.textures = {};
702
- }
703
- this.optimization.textures.compression = compression;
704
- }
705
- /**
706
- * Set max texture resolution
707
- */
708
- setMaxTextureResolution(resolution) {
709
- if (!this.optimization.textures) {
710
- this.optimization.textures = {};
711
- }
712
- this.optimization.textures.maxResolution = resolution;
713
- }
714
- /**
715
- * Configure shader optimization
716
- */
717
- setShaderOptimization(config) {
718
- this.optimization.shaders = {
719
- ...this.optimization.shaders,
720
- ...config
721
- };
722
- }
723
- /**
724
- * Set target GPU tier
725
- */
726
- setTargetGPUTier(tier) {
727
- this.optimization.targetGPUTier = tier;
728
- }
729
- /**
730
- * Enable adaptive quality (adjust based on frame rate)
731
- */
732
- setAdaptiveQuality(enabled, targetFrameRate) {
733
- this.optimization.adaptiveQuality = enabled;
734
- if (targetFrameRate) {
735
- this.optimization.targetFrameRate = targetFrameRate;
736
- }
737
- }
738
- /**
739
- * Set fixed timestep for VR/AR
740
- */
741
- setFixedTimestep(timestep) {
742
- this.optimization.fixedTimestep = timestep;
743
- }
744
- /**
745
- * Get rendering preset for quality level
746
- */
747
- getPresetForQuality(quality) {
748
- const presets = {
749
- low: {
750
- targetGPUTier: "low",
751
- lodStrategy: "automatic",
752
- culling: { mode: "back", frustum: true, occlusion: false },
753
- batching: { instancing: true, maxInstanceCount: 500 },
754
- textures: {
755
- compression: "astc",
756
- maxResolution: 512,
757
- streaming: true,
758
- streamingBudget: 128
759
- },
760
- adaptiveQuality: true,
761
- targetFrameRate: 30
762
- },
763
- medium: {
764
- targetGPUTier: "medium",
765
- lodStrategy: "automatic",
766
- culling: { mode: "back", frustum: true, occlusion: true },
767
- batching: { instancing: true, maxInstanceCount: 1e3 },
768
- textures: {
769
- compression: "basis",
770
- maxResolution: 1024,
771
- streaming: true,
772
- streamingBudget: 256
773
- },
774
- adaptiveQuality: true,
775
- targetFrameRate: 60
776
- },
777
- high: {
778
- targetGPUTier: "high",
779
- lodStrategy: "automatic",
780
- culling: { mode: "back", frustum: true, occlusion: true },
781
- batching: { instancing: true, maxInstanceCount: 2e3 },
782
- textures: {
783
- compression: "dxt",
784
- maxResolution: 2048,
785
- streaming: true,
786
- streamingBudget: 512
787
- },
788
- adaptiveQuality: false,
789
- targetFrameRate: 60
790
- },
791
- ultra: {
792
- targetGPUTier: "ultra",
793
- lodStrategy: "manual",
794
- culling: {
795
- mode: "back",
796
- frustum: true,
797
- occlusion: true,
798
- hierarchicalZ: true
799
- },
800
- batching: { instancing: true, maxInstanceCount: 5e3 },
801
- textures: {
802
- compression: "none",
803
- maxResolution: 4096,
804
- virtualTexturing: true,
805
- streaming: true,
806
- streamingBudget: 1024
807
- },
808
- adaptiveQuality: false,
809
- targetFrameRate: 120
810
- }
811
- };
812
- return { ...this.optimization, ...presets[quality] };
813
- }
814
- /**
815
- * Apply quality preset
816
- */
817
- applyQualityPreset(quality) {
818
- const preset = this.getPresetForQuality(quality);
819
- this.optimization = preset;
820
- }
821
- /**
822
- * Estimate GPU memory usage
823
- */
824
- estimateGPUMemory() {
825
- let textureMemory = 0;
826
- let vertexBuffers = 0;
827
- const maxRes = this.optimization.textures?.maxResolution || 2048;
828
- textureMemory = maxRes * maxRes * 4 / (1024 * 1024);
829
- const instanceCount = this.optimization.batching?.maxInstanceCount || 1e3;
830
- const verticesPerMesh = 1e4;
831
- vertexBuffers = verticesPerMesh * 36 * instanceCount / (1024 * 1024) * 0.1;
832
- return {
833
- textureMemory: Math.round(textureMemory),
834
- vertexBuffers: Math.max(1, Math.round(vertexBuffers)),
835
- // At least 1MB
836
- estimatedTotal: Math.round(textureMemory + Math.max(1, vertexBuffers))
837
- };
838
- }
839
- /**
840
- * Get rendering statistics/info
841
- */
842
- getInfo() {
843
- const tier = this.optimization.targetGPUTier;
844
- const lod = this.optimization.lodStrategy;
845
- const culling = this.optimization.culling?.mode;
846
- const instancing = this.optimization.batching?.instancing ? "yes" : "no";
847
- const memory = this.estimateGPUMemory();
848
- return `Rendering: tier=${tier} | LOD=${lod} | culling=${culling} | instancing=${instancing} | memory=${memory.estimatedTotal}MB`;
849
- }
850
- /**
851
- * Optimize for VR/AR (fixed timestep, fast culling)
852
- */
853
- optimizeForVRAR(targetFPS = 90) {
854
- this.optimization.fixedTimestep = 1 / targetFPS;
855
- this.optimization.targetFrameRate = targetFPS;
856
- this.setOcclusionCulling(true, 50);
857
- this.setInstancing(true, 5e3);
858
- this.setAdaptiveQuality(true, targetFPS);
859
- }
860
- /**
861
- * Optimize for mobile (lower resources)
862
- */
863
- optimizeForMobile() {
864
- this.applyQualityPreset("low");
865
- this.setTextureCompression("astc");
866
- this.setInstancing(true, 256);
867
- }
868
- /**
869
- * Optimize for desktop (higher resources)
870
- */
871
- optimizeForDesktop() {
872
- this.applyQualityPreset("ultra");
873
- this.setTextureCompression("none");
874
- this.setInstancing(true, 5e3);
875
- }
876
- /**
877
- * Dispose and cleanup
878
- */
879
- dispose() {
880
- }
881
- };
882
- function createRenderingTrait(config) {
883
- return new RenderingTrait(config);
884
- }
885
- var renderingHandler = {
886
- name: "rendering",
887
- defaultConfig: {},
888
- onAttach(node, config, ctx) {
889
- const instance = new RenderingTrait(config);
890
- node.__rendering_instance = instance;
891
- ctx.emit("rendering_attached", { node, config });
892
- },
893
- onDetach(node, _config, ctx) {
894
- const instance = node.__rendering_instance;
895
- if (instance) {
896
- if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
897
- else if (typeof instance.dispose === "function") instance.dispose();
898
- else if (typeof instance.cleanup === "function") instance.cleanup();
899
- }
900
- ctx.emit("rendering_detached", { node });
901
- delete node.__rendering_instance;
902
- },
903
- onEvent(node, _config, ctx, event) {
904
- const instance = node.__rendering_instance;
905
- if (!instance) return;
906
- if (typeof instance.onEvent === "function") instance.onEvent(event);
907
- else if (typeof instance.emit === "function" && event.type) instance.emit(event);
908
- if (event.type === "rendering_configure" && event.payload) {
909
- Object.assign(instance, event.payload);
910
- ctx.emit("rendering_configured", { node });
911
- }
912
- },
913
- onUpdate(node, _config, ctx, dt) {
914
- const instance = node.__rendering_instance;
915
- if (!instance) return;
916
- if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
917
- }
918
- };
919
-
920
- // src/traits/ShaderTrait.ts
921
- var SHADER_CHUNKS = {
922
- /** Common noise functions */
923
- noise: `
924
- // Simplex 2D noise
925
- vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
926
- vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
927
- vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
928
-
929
- float snoise(vec2 v) {
930
- const vec4 C = vec4(0.211324865405187, 0.366025403784439,
931
- -0.577350269189626, 0.024390243902439);
932
- vec2 i = floor(v + dot(v, C.yy));
933
- vec2 x0 = v - i + dot(i, C.xx);
934
- vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
935
- vec4 x12 = x0.xyxy + C.xxzz;
936
- x12.xy -= i1;
937
- i = mod289(i);
938
- vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
939
- vec3 m = max(0.5 - vec3(dot(x0,x0), dot(x12.xy,x12.xy), dot(x12.zw,x12.zw)), 0.0);
940
- m = m*m;
941
- m = m*m;
942
- vec3 x = 2.0 * fract(p * C.www) - 1.0;
943
- vec3 h = abs(x) - 0.5;
944
- vec3 ox = floor(x + 0.5);
945
- vec3 a0 = x - ox;
946
- m *= 1.79284291400159 - 0.85373472095314 * (a0*a0 + h*h);
947
- vec3 g;
948
- g.x = a0.x * x0.x + h.x * x0.y;
949
- g.yz = a0.yz * x12.xz + h.yz * x12.yw;
950
- return 130.0 * dot(m, g);
951
- }
952
- `,
953
- /** Hologram effect */
954
- hologram: `
955
- // Hologram scanline effect
956
- float hologramScanline(vec2 uv, float time, float density) {
957
- return sin(uv.y * density + time * 2.0) * 0.5 + 0.5;
958
- }
959
-
960
- // Hologram flicker
961
- float hologramFlicker(float time) {
962
- return 0.9 + 0.1 * sin(time * 20.0) * sin(time * 13.0);
963
- }
964
-
965
- // Hologram edge glow
966
- float hologramEdge(vec3 normal, vec3 viewDir) {
967
- return pow(1.0 - abs(dot(normal, viewDir)), 2.0);
968
- }
969
- `,
970
- /** Fresnel effect */
971
- fresnel: `
972
- // Basic Fresnel
973
- float fresnel(vec3 normal, vec3 viewDir, float power) {
974
- return pow(1.0 - abs(dot(normal, viewDir)), power);
975
- }
976
-
977
- // Schlick's approximation
978
- float fresnelSchlick(float cosTheta, float F0) {
979
- return F0 + (1.0 - F0) * pow(1.0 - cosTheta, 5.0);
980
- }
981
- `,
982
- /** PBR lighting */
983
- pbr: `
984
- // Distribution function (GGX/Trowbridge-Reitz)
985
- float distributionGGX(vec3 N, vec3 H, float roughness) {
986
- float a = roughness * roughness;
987
- float a2 = a * a;
988
- float NdotH = max(dot(N, H), 0.0);
989
- float NdotH2 = NdotH * NdotH;
990
- float num = a2;
991
- float denom = (NdotH2 * (a2 - 1.0) + 1.0);
992
- denom = 3.14159265 * denom * denom;
993
- return num / denom;
994
- }
995
-
996
- // Geometry function (Schlick-GGX)
997
- float geometrySchlickGGX(float NdotV, float roughness) {
998
- float r = (roughness + 1.0);
999
- float k = (r * r) / 8.0;
1000
- float num = NdotV;
1001
- float denom = NdotV * (1.0 - k) + k;
1002
- return num / denom;
1003
- }
1004
-
1005
- // Smith's geometry function
1006
- float geometrySmith(vec3 N, vec3 V, vec3 L, float roughness) {
1007
- float NdotV = max(dot(N, V), 0.0);
1008
- float NdotL = max(dot(N, L), 0.0);
1009
- float ggx2 = geometrySchlickGGX(NdotV, roughness);
1010
- float ggx1 = geometrySchlickGGX(NdotL, roughness);
1011
- return ggx1 * ggx2;
1012
- }
1013
- `,
1014
- /** UV utilities */
1015
- uv: `
1016
- // Rotate UV
1017
- vec2 rotateUV(vec2 uv, float angle) {
1018
- float c = cos(angle);
1019
- float s = sin(angle);
1020
- return vec2(c * uv.x - s * uv.y, s * uv.x + c * uv.y);
1021
- }
1022
-
1023
- // Tile UV
1024
- vec2 tileUV(vec2 uv, vec2 scale) {
1025
- return fract(uv * scale);
1026
- }
1027
-
1028
- // Parallax mapping
1029
- vec2 parallaxUV(vec2 uv, vec3 viewDir, sampler2D heightMap, float scale) {
1030
- float height = texture2D(heightMap, uv).r;
1031
- vec2 p = viewDir.xy / viewDir.z * (height * scale);
1032
- return uv - p;
1033
- }
1034
- `
1035
- };
1036
- var ShaderTrait = class {
1037
- constructor(config) {
1038
- this.uniformValues = /* @__PURE__ */ new Map();
1039
- this.config = {
1040
- ...config,
1041
- source: {
1042
- language: config.source?.language || "glsl",
1043
- vertex: config.source?.vertex || "",
1044
- fragment: config.source?.fragment || "",
1045
- geometry: config.source?.geometry,
1046
- tessellationControl: config.source?.tessellationControl,
1047
- tessellationEvaluation: config.source?.tessellationEvaluation,
1048
- compute: config.source?.compute
1049
- }
1050
- };
1051
- if (config.uniforms) {
1052
- for (const [name, uniform] of Object.entries(config.uniforms)) {
1053
- this.uniformValues.set(name, uniform.value);
1054
- }
1055
- }
1056
- }
1057
- /**
1058
- * Get shader configuration
1059
- */
1060
- getConfig() {
1061
- return { ...this.config };
1062
- }
1063
- /**
1064
- * Get vertex shader source with includes
1065
- */
1066
- getVertexSource() {
1067
- return this.assembleShaderSource("vertex");
1068
- }
1069
- /**
1070
- * Get fragment shader source with includes
1071
- */
1072
- getFragmentSource() {
1073
- return this.assembleShaderSource("fragment");
1074
- }
1075
- /**
1076
- * Assemble shader source with includes and uniforms
1077
- */
1078
- assembleShaderSource(stage) {
1079
- const source = this.config.source ? this.config.source[stage] : void 0;
1080
- if (!source) return "";
1081
- let assembled = "";
1082
- if (this.config.source?.language === "glsl") {
1083
- assembled += "precision highp float;\n\n";
1084
- }
1085
- if (this.config.uniforms) {
1086
- for (const [name, uniform] of Object.entries(this.config.uniforms)) {
1087
- assembled += `uniform ${this.getGLSLType(uniform.type)} ${name};
1088
- `;
1089
- }
1090
- assembled += "\n";
1091
- }
1092
- if (this.config.includes) {
1093
- for (const include of this.config.includes) {
1094
- const chunk = SHADER_CHUNKS[include.path];
1095
- if (chunk) {
1096
- assembled += `// Include: ${include.path}
1097
- ${chunk}
1098
- `;
1099
- }
1100
- }
1101
- }
1102
- assembled += source;
1103
- return assembled;
1104
- }
1105
- /**
1106
- * Convert uniform type to GLSL type
1107
- */
1108
- getGLSLType(type) {
1109
- const typeMap = {
1110
- float: "float",
1111
- int: "int",
1112
- bool: "bool",
1113
- vec2: "vec2",
1114
- vec3: "vec3",
1115
- vec4: "vec4",
1116
- mat2: "mat2",
1117
- mat3: "mat3",
1118
- mat4: "mat4",
1119
- sampler2D: "sampler2D",
1120
- samplerCube: "samplerCube"
1121
- };
1122
- return typeMap[type] || "float";
1123
- }
1124
- /**
1125
- * Set uniform value
1126
- */
1127
- setUniform(name, value) {
1128
- this.uniformValues.set(name, value);
1129
- }
1130
- /**
1131
- * Get uniform value
1132
- */
1133
- getUniform(name) {
1134
- return this.uniformValues.get(name);
1135
- }
1136
- /**
1137
- * Get all uniform values
1138
- */
1139
- getUniforms() {
1140
- return new Map(this.uniformValues);
1141
- }
1142
- /**
1143
- * Validate shader syntax
1144
- */
1145
- validate() {
1146
- const errors = [];
1147
- const warnings = [];
1148
- if (this.config.source?.vertex) {
1149
- const vertexErrors = this.validateShaderSyntax(this.config.source.vertex, "vertex");
1150
- errors.push(...vertexErrors);
1151
- }
1152
- if (this.config.source?.fragment) {
1153
- const fragmentErrors = this.validateShaderSyntax(this.config.source.fragment, "fragment");
1154
- errors.push(...fragmentErrors);
1155
- }
1156
- if (this.config.source?.vertex && !this.config.source.vertex.includes("void main")) {
1157
- errors.push({
1158
- stage: "vertex",
1159
- line: 1,
1160
- message: "Vertex shader must contain a main() function",
1161
- code: "E001"
1162
- });
1163
- }
1164
- if (this.config.source?.fragment && !this.config.source.fragment.includes("void main")) {
1165
- errors.push({
1166
- stage: "fragment",
1167
- line: 1,
1168
- message: "Fragment shader must contain a main() function",
1169
- code: "E002"
1170
- });
1171
- }
1172
- this.compilationResult = {
1173
- success: errors.length === 0,
1174
- errors,
1175
- warnings
1176
- };
1177
- return this.compilationResult;
1178
- }
1179
- /**
1180
- * Basic shader syntax validation
1181
- */
1182
- validateShaderSyntax(source, stage) {
1183
- const errors = [];
1184
- const lines = source.split("\n");
1185
- let braceCount = 0;
1186
- for (let i = 0; i < lines.length; i++) {
1187
- const line = lines[i];
1188
- braceCount += (line.match(/{/g) || []).length;
1189
- braceCount -= (line.match(/}/g) || []).length;
1190
- }
1191
- if (braceCount !== 0) {
1192
- errors.push({
1193
- stage,
1194
- line: lines.length,
1195
- message: `Unbalanced braces in ${stage} shader`,
1196
- code: "E003"
1197
- });
1198
- }
1199
- let parenCount = 0;
1200
- for (let i = 0; i < lines.length; i++) {
1201
- const line = lines[i];
1202
- parenCount += (line.match(/\(/g) || []).length;
1203
- parenCount -= (line.match(/\)/g) || []).length;
1204
- }
1205
- if (parenCount !== 0) {
1206
- errors.push({
1207
- stage,
1208
- line: lines.length,
1209
- message: `Unbalanced parentheses in ${stage} shader`,
1210
- code: "E004"
1211
- });
1212
- }
1213
- return errors;
1214
- }
1215
- /**
1216
- * Compile shader to target platform
1217
- */
1218
- compile(options) {
1219
- const validation = this.validate();
1220
- if (!validation.success) {
1221
- return validation;
1222
- }
1223
- let vertexSource = this.getVertexSource();
1224
- let fragmentSource = this.getFragmentSource();
1225
- if (options?.defines) {
1226
- for (const [key, value] of Object.entries(options.defines)) {
1227
- const define = `#define ${key} ${value}
1228
- `;
1229
- vertexSource = define + vertexSource;
1230
- fragmentSource = define + fragmentSource;
1231
- }
1232
- }
1233
- return {
1234
- success: true,
1235
- errors: [],
1236
- warnings: [],
1237
- compiledCode: {
1238
- vertex: vertexSource,
1239
- fragment: fragmentSource
1240
- }
1241
- };
1242
- }
1243
- /**
1244
- * Create Three.js ShaderMaterial config
1245
- */
1246
- toThreeJSConfig() {
1247
- const uniformsObj = {};
1248
- for (const [name, value] of this.uniformValues) {
1249
- uniformsObj[name] = { value };
1250
- }
1251
- return {
1252
- vertexShader: this.getVertexSource(),
1253
- fragmentShader: this.getFragmentSource(),
1254
- uniforms: uniformsObj,
1255
- transparent: this.config.blendMode !== "opaque",
1256
- depthTest: this.config.depthTest ?? true,
1257
- depthWrite: this.config.depthWrite ?? true,
1258
- side: this.getCullSide()
1259
- };
1260
- }
1261
- getCullSide() {
1262
- const THREE_FrontSide = 0;
1263
- const THREE_BackSide = 1;
1264
- const THREE_DoubleSide = 2;
1265
- switch (this.config.cullFace) {
1266
- case "front":
1267
- return THREE_BackSide;
1268
- case "back":
1269
- return THREE_FrontSide;
1270
- case "none":
1271
- return THREE_DoubleSide;
1272
- default:
1273
- return THREE_FrontSide;
1274
- }
1275
- }
1276
- };
1277
- var SHADER_PRESETS = {
1278
- /** Hologram effect shader */
1279
- hologram: {
1280
- name: "hologram",
1281
- source: {
1282
- language: "glsl",
1283
- vertex: `
1284
- varying vec2 vUv;
1285
- varying vec3 vNormal;
1286
- varying vec3 vViewPosition;
1287
-
1288
- void main() {
1289
- vUv = uv;
1290
- vNormal = normalize(normalMatrix * normal);
1291
- vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);
1292
- vViewPosition = -mvPosition.xyz;
1293
- gl_Position = projectionMatrix * mvPosition;
1294
- }
1295
- `,
1296
- fragment: `
1297
- uniform float time;
1298
- uniform vec3 color;
1299
- uniform float opacity;
1300
- uniform float scanlineIntensity;
1301
- uniform float flickerIntensity;
1302
-
1303
- varying vec2 vUv;
1304
- varying vec3 vNormal;
1305
- varying vec3 vViewPosition;
1306
-
1307
- void main() {
1308
- // Fresnel edge glow
1309
- vec3 viewDir = normalize(vViewPosition);
1310
- float fresnel = pow(1.0 - abs(dot(vNormal, viewDir)), 2.0);
1311
-
1312
- // Scanlines
1313
- float scanline = sin(vUv.y * 100.0 + time * 2.0) * scanlineIntensity;
1314
-
1315
- // Flicker
1316
- float flicker = 0.9 + flickerIntensity * sin(time * 20.0) * sin(time * 13.0);
1317
-
1318
- // Combine
1319
- float alpha = (opacity + fresnel * 0.3 + scanline) * flicker;
1320
- vec3 finalColor = color + fresnel * 0.5;
1321
-
1322
- gl_FragColor = vec4(finalColor, alpha);
1323
- }
1324
- `
1325
- },
1326
- uniforms: {
1327
- time: { type: "float", value: 0 },
1328
- color: { type: "vec3", value: [0, 1, 1] },
1329
- opacity: { type: "float", value: 0.5, min: 0, max: 1 },
1330
- scanlineIntensity: { type: "float", value: 0.1, min: 0, max: 0.5 },
1331
- flickerIntensity: { type: "float", value: 0.1, min: 0, max: 0.3 }
1332
- },
1333
- blendMode: "blend",
1334
- depthWrite: false,
1335
- cullFace: "none"
1336
- },
1337
- /** Force field shader */
1338
- forceField: {
1339
- name: "forceField",
1340
- source: {
1341
- language: "glsl",
1342
- vertex: `
1343
- varying vec2 vUv;
1344
- varying vec3 vNormal;
1345
- varying vec3 vWorldPosition;
1346
-
1347
- void main() {
1348
- vUv = uv;
1349
- vNormal = normalize(normalMatrix * normal);
1350
- vWorldPosition = (modelMatrix * vec4(position, 1.0)).xyz;
1351
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1352
- }
1353
- `,
1354
- fragment: `
1355
- uniform float time;
1356
- uniform vec3 color;
1357
- uniform float pulseSpeed;
1358
- uniform float hexScale;
1359
-
1360
- varying vec2 vUv;
1361
- varying vec3 vNormal;
1362
- varying vec3 vWorldPosition;
1363
-
1364
- float hexPattern(vec2 p) {
1365
- vec2 q = vec2(p.x * 2.0 * 0.5773503, p.y + p.x * 0.5773503);
1366
- vec2 pi = floor(q);
1367
- vec2 pf = fract(q);
1368
- float v = mod(pi.x + pi.y, 3.0);
1369
- float ca = step(1.0, v);
1370
- float cb = step(2.0, v);
1371
- vec2 ma = step(pf.xy, pf.yx);
1372
- float e = dot(ma, 1.0 - pf.yx + ca * (pf.x + pf.y - 1.0) + cb * (pf.yx - 2.0 * pf.xy));
1373
- return e;
1374
- }
1375
-
1376
- void main() {
1377
- float hex = hexPattern(vUv * hexScale);
1378
- float pulse = sin(time * pulseSpeed) * 0.5 + 0.5;
1379
- float alpha = hex * (0.3 + pulse * 0.2);
1380
- gl_FragColor = vec4(color, alpha);
1381
- }
1382
- `
1383
- },
1384
- uniforms: {
1385
- time: { type: "float", value: 0 },
1386
- color: { type: "vec3", value: [0.2, 0.5, 1] },
1387
- pulseSpeed: { type: "float", value: 2, min: 0.5, max: 5 },
1388
- hexScale: { type: "float", value: 10, min: 5, max: 50 }
1389
- },
1390
- blendMode: "additive",
1391
- depthWrite: false,
1392
- cullFace: "none"
1393
- },
1394
- /** Dissolve effect shader */
1395
- dissolve: {
1396
- name: "dissolve",
1397
- source: {
1398
- language: "glsl",
1399
- vertex: `
1400
- varying vec2 vUv;
1401
- varying vec3 vPosition;
1402
-
1403
- void main() {
1404
- vUv = uv;
1405
- vPosition = position;
1406
- gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
1407
- }
1408
- `,
1409
- fragment: `
1410
- uniform float progress;
1411
- uniform vec3 edgeColor;
1412
- uniform float edgeWidth;
1413
- uniform sampler2D noiseTexture;
1414
-
1415
- varying vec2 vUv;
1416
- varying vec3 vPosition;
1417
-
1418
- void main() {
1419
- float noise = texture2D(noiseTexture, vUv).r;
1420
- float diff = noise - progress;
1421
-
1422
- if (diff < 0.0) discard;
1423
-
1424
- float edge = smoothstep(0.0, edgeWidth, diff);
1425
- vec3 color = mix(edgeColor, vec3(1.0), edge);
1426
-
1427
- gl_FragColor = vec4(color, 1.0);
1428
- }
1429
- `
1430
- },
1431
- uniforms: {
1432
- progress: { type: "float", value: 0, min: 0, max: 1 },
1433
- edgeColor: { type: "vec3", value: [1, 0.5, 0] },
1434
- edgeWidth: { type: "float", value: 0.1, min: 0.01, max: 0.5 },
1435
- noiseTexture: { type: "sampler2D", value: "" }
1436
- },
1437
- blendMode: "opaque"
1438
- }
1439
- };
1440
- function createShaderTrait(config) {
1441
- return new ShaderTrait({
1442
- name: "custom",
1443
- source: {
1444
- language: "glsl",
1445
- vertex: "",
1446
- fragment: ""
1447
- },
1448
- uniforms: {},
1449
- blendMode: "opaque",
1450
- ...config
1451
- });
1452
- }
1453
- var shaderHandler = {
1454
- name: "shader",
1455
- defaultConfig: {},
1456
- onAttach(node, config, ctx) {
1457
- const instance = new ShaderTrait(config);
1458
- node.__shader_instance = instance;
1459
- ctx.emit("shader_attached", { node, config });
1460
- },
1461
- onDetach(node, _config, ctx) {
1462
- const instance = node.__shader_instance;
1463
- if (instance) {
1464
- if (typeof instance.onDetach === "function") instance.onDetach(node, ctx);
1465
- else if (typeof instance.dispose === "function") instance.dispose();
1466
- else if (typeof instance.cleanup === "function") instance.cleanup();
1467
- }
1468
- ctx.emit("shader_detached", { node });
1469
- delete node.__shader_instance;
1470
- },
1471
- onEvent(node, _config, ctx, event) {
1472
- const instance = node.__shader_instance;
1473
- if (!instance) return;
1474
- if (typeof instance.onEvent === "function") instance.onEvent(event);
1475
- else if (typeof instance.emit === "function" && event.type) instance.emit(event);
1476
- if (event.type === "shader_configure" && event.payload) {
1477
- Object.assign(instance, event.payload);
1478
- ctx.emit("shader_configured", { node });
1479
- }
1480
- },
1481
- onUpdate(node, _config, ctx, dt) {
1482
- const instance = node.__shader_instance;
1483
- if (!instance) return;
1484
- if (typeof instance.onUpdate === "function") instance.onUpdate(node, ctx, dt);
1485
- }
1486
- };
1487
-
1488
- exports.LIGHTING_PRESETS = LIGHTING_PRESETS;
1489
- exports.LightingTrait = LightingTrait;
1490
- exports.MATERIAL_PRESETS = MATERIAL_PRESETS;
1491
- exports.MaterialTrait = MaterialTrait;
1492
- exports.RenderingTrait = RenderingTrait;
1493
- exports.SHADER_CHUNKS = SHADER_CHUNKS;
1494
- exports.SHADER_PRESETS = SHADER_PRESETS;
1495
- exports.ShaderTrait = ShaderTrait;
1496
- exports.createLightingTrait = createLightingTrait;
1497
- exports.createMaterialTrait = createMaterialTrait;
1498
- exports.createRenderingTrait = createRenderingTrait;
1499
- exports.createShaderTrait = createShaderTrait;
1500
- exports.lightingHandler = lightingHandler;
1501
- exports.materialHandler = materialHandler;
1502
- exports.renderingHandler = renderingHandler;
1503
- exports.shaderHandler = shaderHandler;
1504
- //# sourceMappingURL=chunk-Q4QX3AET.cjs.map
1505
- //# sourceMappingURL=chunk-Q4QX3AET.cjs.map