@holoscript/core 1.0.0-alpha.2 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/HoloScript2DParser.js +227 -0
- package/src/HoloScript2DParser.ts +5 -0
- package/src/HoloScriptCodeParser.js +1102 -0
- package/src/HoloScriptCodeParser.ts +145 -20
- package/src/HoloScriptDebugger.js +458 -0
- package/src/HoloScriptParser.js +338 -0
- package/src/HoloScriptPlusParser.js +371 -0
- package/src/HoloScriptPlusParser.ts +543 -0
- package/src/HoloScriptRuntime.js +1399 -0
- package/src/HoloScriptRuntime.test.js +351 -0
- package/src/HoloScriptRuntime.ts +17 -3
- package/src/HoloScriptTypeChecker.js +356 -0
- package/src/__tests__/GraphicsServices.test.js +357 -0
- package/src/__tests__/GraphicsServices.test.ts +427 -0
- package/src/__tests__/HoloScriptPlusParser.test.js +317 -0
- package/src/__tests__/HoloScriptPlusParser.test.ts +392 -0
- package/src/__tests__/integration.test.js +336 -0
- package/src/__tests__/performance.bench.js +218 -0
- package/src/__tests__/type-checker.test.js +60 -0
- package/src/__tests__/type-checker.test.ts +73 -0
- package/src/index.js +217 -0
- package/src/index.ts +158 -18
- package/src/interop/Interoperability.js +413 -0
- package/src/interop/Interoperability.ts +494 -0
- package/src/logger.js +42 -0
- package/src/parser/EnhancedParser.js +205 -0
- package/src/parser/EnhancedParser.ts +251 -0
- package/src/parser/HoloScriptPlusParser.js +928 -0
- package/src/parser/HoloScriptPlusParser.ts +1089 -0
- package/src/runtime/HoloScriptPlusRuntime.js +674 -0
- package/src/runtime/HoloScriptPlusRuntime.ts +861 -0
- package/src/runtime/PerformanceTelemetry.js +323 -0
- package/src/runtime/PerformanceTelemetry.ts +467 -0
- package/src/runtime/RuntimeOptimization.js +361 -0
- package/src/runtime/RuntimeOptimization.ts +416 -0
- package/src/services/HololandGraphicsPipelineService.js +506 -0
- package/src/services/HololandGraphicsPipelineService.ts +662 -0
- package/src/services/PlatformPerformanceOptimizer.js +356 -0
- package/src/services/PlatformPerformanceOptimizer.ts +503 -0
- package/src/state/ReactiveState.js +427 -0
- package/src/state/ReactiveState.ts +572 -0
- package/src/tools/DeveloperExperience.js +376 -0
- package/src/tools/DeveloperExperience.ts +438 -0
- package/src/traits/AIDriverTrait.js +322 -0
- package/src/traits/AIDriverTrait.test.js +329 -0
- package/src/traits/AIDriverTrait.test.ts +357 -0
- package/src/traits/AIDriverTrait.ts +474 -0
- package/src/traits/LightingTrait.js +313 -0
- package/src/traits/LightingTrait.test.js +410 -0
- package/src/traits/LightingTrait.test.ts +462 -0
- package/src/traits/LightingTrait.ts +505 -0
- package/src/traits/MaterialTrait.js +194 -0
- package/src/traits/MaterialTrait.test.js +286 -0
- package/src/traits/MaterialTrait.test.ts +329 -0
- package/src/traits/MaterialTrait.ts +324 -0
- package/src/traits/RenderingTrait.js +356 -0
- package/src/traits/RenderingTrait.test.js +363 -0
- package/src/traits/RenderingTrait.test.ts +427 -0
- package/src/traits/RenderingTrait.ts +555 -0
- package/src/traits/VRTraitSystem.js +740 -0
- package/src/traits/VRTraitSystem.ts +1040 -0
- package/src/traits/VoiceInputTrait.js +284 -0
- package/src/traits/VoiceInputTrait.test.js +226 -0
- package/src/traits/VoiceInputTrait.test.ts +252 -0
- package/src/traits/VoiceInputTrait.ts +401 -0
- package/src/types/AdvancedTypeSystem.js +226 -0
- package/src/types/AdvancedTypeSystem.ts +494 -0
- package/src/types/HoloScriptPlus.d.ts +853 -0
- package/src/types.js +6 -0
- package/src/types.ts +96 -1
- package/tsconfig.json +1 -1
- package/tsup.config.d.ts +2 -0
- package/tsup.config.js +18 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
LightingTrait,
|
|
4
|
+
createLightingTrait,
|
|
5
|
+
LIGHTING_PRESETS,
|
|
6
|
+
type GlobalIlluminationConfig,
|
|
7
|
+
type Vector3,
|
|
8
|
+
type Color,
|
|
9
|
+
} from '../traits/LightingTrait';
|
|
10
|
+
|
|
11
|
+
describe('LightingTrait', () => {
|
|
12
|
+
let lighting: LightingTrait;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
lighting = new LightingTrait();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe('initialization', () => {
|
|
19
|
+
it('should initialize with default GI settings', () => {
|
|
20
|
+
const gi = lighting.getGlobalIllumination();
|
|
21
|
+
expect(gi.enabled).toBe(true);
|
|
22
|
+
expect(gi.intensity).toBe(1.0);
|
|
23
|
+
expect(gi.probes).toBe(true);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('should initialize with custom GI config', () => {
|
|
27
|
+
const config: GlobalIlluminationConfig = {
|
|
28
|
+
enabled: true,
|
|
29
|
+
intensity: 2.0,
|
|
30
|
+
skyColor: { r: 1, g: 1, b: 1 },
|
|
31
|
+
probes: false,
|
|
32
|
+
};
|
|
33
|
+
const lig = new LightingTrait(config);
|
|
34
|
+
const gi = lig.getGlobalIllumination();
|
|
35
|
+
expect(gi.intensity).toBe(2.0);
|
|
36
|
+
expect(gi.probes).toBe(false);
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('light management', () => {
|
|
41
|
+
it('should add light and return ID', () => {
|
|
42
|
+
const id = lighting.addLight({
|
|
43
|
+
type: 'directional',
|
|
44
|
+
direction: { x: 1, y: 1, z: 1 },
|
|
45
|
+
color: { r: 1, g: 1, b: 1 },
|
|
46
|
+
intensity: 1.0,
|
|
47
|
+
});
|
|
48
|
+
expect(id).toBeDefined();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it('should retrieve added light by ID', () => {
|
|
52
|
+
const lightId = lighting.addLight({
|
|
53
|
+
type: 'point',
|
|
54
|
+
position: { x: 0, y: 0, z: 0 },
|
|
55
|
+
color: { r: 1, g: 0, b: 0 },
|
|
56
|
+
intensity: 1.0,
|
|
57
|
+
range: 10,
|
|
58
|
+
});
|
|
59
|
+
const light = lighting.getLight(lightId);
|
|
60
|
+
expect(light?.type).toBe('point');
|
|
61
|
+
expect(light?.color.r).toBe(1);
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should get all lights', () => {
|
|
65
|
+
lighting.addLight({
|
|
66
|
+
type: 'directional',
|
|
67
|
+
direction: { x: 0, y: 1, z: 0 },
|
|
68
|
+
color: { r: 1, g: 1, b: 1 },
|
|
69
|
+
intensity: 1.0,
|
|
70
|
+
});
|
|
71
|
+
lighting.addLight({
|
|
72
|
+
type: 'point',
|
|
73
|
+
position: { x: 0, y: 0, z: 0 },
|
|
74
|
+
color: { r: 0, g: 1, b: 0 },
|
|
75
|
+
intensity: 0.8,
|
|
76
|
+
range: 5,
|
|
77
|
+
});
|
|
78
|
+
const lights = lighting.getLights();
|
|
79
|
+
expect(lights).toHaveLength(2);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it('should filter lights by type', () => {
|
|
83
|
+
lighting.addLight({
|
|
84
|
+
type: 'directional',
|
|
85
|
+
direction: { x: 0, y: 1, z: 0 },
|
|
86
|
+
color: { r: 1, g: 1, b: 1 },
|
|
87
|
+
intensity: 1.0,
|
|
88
|
+
});
|
|
89
|
+
lighting.addLight({
|
|
90
|
+
type: 'point',
|
|
91
|
+
position: { x: 0, y: 0, z: 0 },
|
|
92
|
+
color: { r: 0, g: 1, b: 0 },
|
|
93
|
+
intensity: 0.8,
|
|
94
|
+
range: 5,
|
|
95
|
+
});
|
|
96
|
+
lighting.addLight({
|
|
97
|
+
type: 'point',
|
|
98
|
+
position: { x: 5, y: 0, z: 0 },
|
|
99
|
+
color: { r: 0, g: 0, b: 1 },
|
|
100
|
+
intensity: 0.5,
|
|
101
|
+
range: 3,
|
|
102
|
+
});
|
|
103
|
+
const points = lighting.getLightsByType('point');
|
|
104
|
+
expect(points).toHaveLength(2);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe('light updates', () => {
|
|
109
|
+
it('should update existing light', () => {
|
|
110
|
+
const id = lighting.addLight({
|
|
111
|
+
type: 'point',
|
|
112
|
+
position: { x: 0, y: 0, z: 0 },
|
|
113
|
+
color: { r: 1, g: 0, b: 0 },
|
|
114
|
+
intensity: 1.0,
|
|
115
|
+
range: 10,
|
|
116
|
+
});
|
|
117
|
+
lighting.updateLight(id, { intensity: 0.5 });
|
|
118
|
+
const light = lighting.getLight(id);
|
|
119
|
+
expect(light?.intensity).toBe(0.5);
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it('should return false for non-existent light', () => {
|
|
123
|
+
const result = lighting.updateLight('non-existent', { intensity: 0.5 });
|
|
124
|
+
expect(result).toBe(false);
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
it('should remove light', () => {
|
|
128
|
+
const id = lighting.addLight({
|
|
129
|
+
type: 'point',
|
|
130
|
+
position: { x: 0, y: 0, z: 0 },
|
|
131
|
+
color: { r: 1, g: 0, b: 0 },
|
|
132
|
+
intensity: 1.0,
|
|
133
|
+
range: 10,
|
|
134
|
+
});
|
|
135
|
+
const result = lighting.removeLight(id);
|
|
136
|
+
expect(result).toBe(true);
|
|
137
|
+
expect(lighting.getLight(id)).toBeUndefined();
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should clear all lights', () => {
|
|
141
|
+
lighting.addLight({
|
|
142
|
+
type: 'point',
|
|
143
|
+
position: { x: 0, y: 0, z: 0 },
|
|
144
|
+
color: { r: 1, g: 0, b: 0 },
|
|
145
|
+
intensity: 1.0,
|
|
146
|
+
range: 10,
|
|
147
|
+
});
|
|
148
|
+
lighting.addLight({
|
|
149
|
+
type: 'point',
|
|
150
|
+
position: { x: 5, y: 0, z: 0 },
|
|
151
|
+
color: { r: 0, g: 1, b: 0 },
|
|
152
|
+
intensity: 1.0,
|
|
153
|
+
range: 10,
|
|
154
|
+
});
|
|
155
|
+
lighting.clearLights();
|
|
156
|
+
expect(lighting.getLights()).toHaveLength(0);
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
describe('global illumination', () => {
|
|
161
|
+
it('should get GI configuration', () => {
|
|
162
|
+
const gi = lighting.getGlobalIllumination();
|
|
163
|
+
expect(gi).toBeDefined();
|
|
164
|
+
expect(gi.skyColor).toBeDefined();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it('should update GI configuration', () => {
|
|
168
|
+
lighting.updateGlobalIllumination({
|
|
169
|
+
intensity: 1.5,
|
|
170
|
+
skyIntensity: 2.0,
|
|
171
|
+
});
|
|
172
|
+
const gi = lighting.getGlobalIllumination();
|
|
173
|
+
expect(gi.intensity).toBe(1.5);
|
|
174
|
+
expect(gi.skyIntensity).toBe(2.0);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should enable/disable GI', () => {
|
|
178
|
+
lighting.setGIEnabled(false);
|
|
179
|
+
const gi = lighting.getGlobalIllumination();
|
|
180
|
+
expect(gi.enabled).toBe(false);
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it('should set ambient light colors', () => {
|
|
184
|
+
const skyColor: Color = { r: 0.8, g: 0.8, b: 1.0 };
|
|
185
|
+
const groundColor: Color = { r: 0.3, g: 0.3, b: 0.2 };
|
|
186
|
+
lighting.setAmbientLight(skyColor, groundColor, 0.8);
|
|
187
|
+
const gi = lighting.getGlobalIllumination();
|
|
188
|
+
expect(gi.skyColor).toEqual(skyColor);
|
|
189
|
+
expect(gi.groundColor).toEqual(groundColor);
|
|
190
|
+
expect(gi.skyIntensity).toBe(0.8);
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
it('should enable screen-space AO', () => {
|
|
194
|
+
lighting.setScreenSpaceAO(true, 1.5);
|
|
195
|
+
const gi = lighting.getGlobalIllumination();
|
|
196
|
+
expect(gi.screenSpaceAO).toBe(true);
|
|
197
|
+
expect(gi.aoIntensity).toBe(1.5);
|
|
198
|
+
});
|
|
199
|
+
});
|
|
200
|
+
|
|
201
|
+
describe('light creation helpers', () => {
|
|
202
|
+
it('should create directional light (sun)', () => {
|
|
203
|
+
const dir: Vector3 = { x: 1, y: 1, z: 1 };
|
|
204
|
+
const color: Color = { r: 1, g: 1, b: 1 };
|
|
205
|
+
const id = lighting.createDirectionalLight(dir, color, 1.0, true);
|
|
206
|
+
const light = lighting.getLight(id);
|
|
207
|
+
expect(light?.type).toBe('directional');
|
|
208
|
+
expect(light?.shadow?.type).toBe('soft');
|
|
209
|
+
expect(light?.shadow?.cascades).toBe(4);
|
|
210
|
+
});
|
|
211
|
+
|
|
212
|
+
it('should create point light', () => {
|
|
213
|
+
const pos: Vector3 = { x: 0, y: 5, z: 0 };
|
|
214
|
+
const color: Color = { r: 1, g: 0, b: 0 };
|
|
215
|
+
const id = lighting.createPointLight(pos, color, 1.0, 20, false);
|
|
216
|
+
const light = lighting.getLight(id);
|
|
217
|
+
expect(light?.type).toBe('point');
|
|
218
|
+
expect(light?.position).toEqual(pos);
|
|
219
|
+
expect(light?.range).toBe(20);
|
|
220
|
+
expect(light?.shadow).toBeUndefined();
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
it('should create spot light', () => {
|
|
224
|
+
const pos: Vector3 = { x: 0, y: 10, z: 0 };
|
|
225
|
+
const dir: Vector3 = { x: 0, y: -1, z: 0 };
|
|
226
|
+
const color: Color = { r: 1, g: 1, b: 0 };
|
|
227
|
+
const id = lighting.createSpotLight(pos, dir, color, 1.0, 30, 45, true);
|
|
228
|
+
const light = lighting.getLight(id);
|
|
229
|
+
expect(light?.type).toBe('spot');
|
|
230
|
+
expect(light?.spotAngle).toBe(45);
|
|
231
|
+
expect(light?.shadow?.type).toBe('soft');
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
it('should create area light', () => {
|
|
235
|
+
const pos: Vector3 = { x: 0, y: 5, z: 0 };
|
|
236
|
+
const color: Color = { r: 0, g: 1, b: 1 };
|
|
237
|
+
const id = lighting.createAreaLight(pos, color, 0.8, 2, 2);
|
|
238
|
+
const light = lighting.getLight(id);
|
|
239
|
+
expect(light?.type).toBe('area');
|
|
240
|
+
expect(light?.range).toBeDefined();
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe('performance analysis', () => {
|
|
245
|
+
it('should get shadow-casting lights', () => {
|
|
246
|
+
const lig = new LightingTrait();
|
|
247
|
+
lig.addLight({
|
|
248
|
+
type: 'directional',
|
|
249
|
+
direction: { x: 0, y: 1, z: 0 },
|
|
250
|
+
color: { r: 1, g: 1, b: 1 },
|
|
251
|
+
intensity: 1.0,
|
|
252
|
+
shadow: { type: 'soft' },
|
|
253
|
+
});
|
|
254
|
+
lig.addLight({
|
|
255
|
+
type: 'point',
|
|
256
|
+
position: { x: 0, y: 0, z: 0 },
|
|
257
|
+
color: { r: 1, g: 0, b: 0 },
|
|
258
|
+
intensity: 1.0,
|
|
259
|
+
range: 10,
|
|
260
|
+
});
|
|
261
|
+
const shadowCasters = lig.getShadowCastingLights();
|
|
262
|
+
expect(shadowCasters).toHaveLength(1);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it('should count lights by type', () => {
|
|
266
|
+
const lig = new LightingTrait();
|
|
267
|
+
lig.addLight({
|
|
268
|
+
type: 'directional',
|
|
269
|
+
direction: { x: 0, y: 1, z: 0 },
|
|
270
|
+
color: { r: 1, g: 1, b: 1 },
|
|
271
|
+
intensity: 1.0,
|
|
272
|
+
});
|
|
273
|
+
lig.addLight({
|
|
274
|
+
type: 'point',
|
|
275
|
+
position: { x: 0, y: 0, z: 0 },
|
|
276
|
+
color: { r: 1, g: 0, b: 0 },
|
|
277
|
+
intensity: 1.0,
|
|
278
|
+
range: 10,
|
|
279
|
+
});
|
|
280
|
+
lig.addLight({
|
|
281
|
+
type: 'point',
|
|
282
|
+
position: { x: 5, y: 0, z: 0 },
|
|
283
|
+
color: { r: 0, g: 1, b: 0 },
|
|
284
|
+
intensity: 1.0,
|
|
285
|
+
range: 10,
|
|
286
|
+
});
|
|
287
|
+
lig.addLight({
|
|
288
|
+
type: 'spot',
|
|
289
|
+
position: { x: 0, y: 5, z: 0 },
|
|
290
|
+
direction: { x: 0, y: -1, z: 0 },
|
|
291
|
+
color: { r: 0, g: 0, b: 1 },
|
|
292
|
+
intensity: 1.0,
|
|
293
|
+
range: 15,
|
|
294
|
+
spotAngle: 45,
|
|
295
|
+
});
|
|
296
|
+
const counts = lig.getLightCount();
|
|
297
|
+
expect(counts.directional).toBe(1);
|
|
298
|
+
expect(counts.point).toBe(2);
|
|
299
|
+
expect(counts.spot).toBe(1);
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
it('should estimate GPU performance impact', () => {
|
|
303
|
+
const lig = new LightingTrait();
|
|
304
|
+
for (let i = 0; i < 10; i++) {
|
|
305
|
+
lig.addLight({
|
|
306
|
+
type: 'point',
|
|
307
|
+
position: { x: i, y: 0, z: 0 },
|
|
308
|
+
color: { r: 1, g: 1, b: 1 },
|
|
309
|
+
intensity: 0.5,
|
|
310
|
+
range: 10,
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
const impact = lig.getPerformanceImpact();
|
|
314
|
+
expect(impact.totalLights).toBe(10);
|
|
315
|
+
expect(['low', 'medium', 'high']).toContain(impact.estimatedGPUCost);
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
it('should estimate high cost with many shadow casters', () => {
|
|
319
|
+
const lig = new LightingTrait();
|
|
320
|
+
for (let i = 0; i < 5; i++) {
|
|
321
|
+
lig.addLight({
|
|
322
|
+
type: 'spot',
|
|
323
|
+
position: { x: i, y: 0, z: 0 },
|
|
324
|
+
direction: { x: 0, y: -1, z: 0 },
|
|
325
|
+
color: { r: 1, g: 1, b: 1 },
|
|
326
|
+
intensity: 0.5,
|
|
327
|
+
range: 10,
|
|
328
|
+
spotAngle: 45,
|
|
329
|
+
shadow: { type: 'soft' },
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
const impact = lig.getPerformanceImpact();
|
|
333
|
+
expect(impact.shadowCasters).toBe(5);
|
|
334
|
+
expect(impact.estimatedGPUCost).toBe('high');
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
it('should generate scene info string', () => {
|
|
338
|
+
lighting.createDirectionalLight({ x: 0, y: 1, z: 0 }, { r: 1, g: 1, b: 1 }, 1.0, true);
|
|
339
|
+
lighting.createPointLight({ x: 0, y: 0, z: 0 }, { r: 1, g: 0, b: 0 }, 1.0, 10, false);
|
|
340
|
+
const info = lighting.getSceneInfo();
|
|
341
|
+
expect(info).toContain('Lighting:');
|
|
342
|
+
expect(info).toContain('Shadows:');
|
|
343
|
+
expect(info).toContain('GPU:');
|
|
344
|
+
});
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
describe('presets', () => {
|
|
348
|
+
it('should create studio lighting', () => {
|
|
349
|
+
const config = LIGHTING_PRESETS.studio();
|
|
350
|
+
expect(config.enabled).toBe(true);
|
|
351
|
+
expect(config.skyIntensity).toBe(0.5);
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
it('should create outdoor lighting', () => {
|
|
355
|
+
const config = LIGHTING_PRESETS.outdoor();
|
|
356
|
+
expect(config.intensity).toBe(1.2);
|
|
357
|
+
expect(config.indirectDiffuse).toBe(1.2);
|
|
358
|
+
});
|
|
359
|
+
|
|
360
|
+
it('should create interior lighting', () => {
|
|
361
|
+
const config = LIGHTING_PRESETS.interior();
|
|
362
|
+
expect(config.intensity).toBe(0.6);
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
it('should create night lighting', () => {
|
|
366
|
+
const config = LIGHTING_PRESETS.night();
|
|
367
|
+
expect(config.intensity).toBe(0.3);
|
|
368
|
+
expect(config.screenSpaceAO).toBe(false);
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
it('should create sunset lighting', () => {
|
|
372
|
+
const config = LIGHTING_PRESETS.sunset();
|
|
373
|
+
expect(config.skyColor?.r).toBe(1.0);
|
|
374
|
+
expect(config.skyColor?.g).toBe(0.7);
|
|
375
|
+
});
|
|
376
|
+
});
|
|
377
|
+
|
|
378
|
+
describe('factory function', () => {
|
|
379
|
+
it('should create lighting via factory', () => {
|
|
380
|
+
const lig = createLightingTrait();
|
|
381
|
+
expect(lig.getGlobalIllumination().enabled).toBe(true);
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
it('should create lighting with config via factory', () => {
|
|
385
|
+
const config: GlobalIlluminationConfig = {
|
|
386
|
+
enabled: false,
|
|
387
|
+
intensity: 0.5,
|
|
388
|
+
};
|
|
389
|
+
const lig = createLightingTrait(config);
|
|
390
|
+
expect(lig.getGlobalIllumination().enabled).toBe(false);
|
|
391
|
+
expect(lig.getGlobalIllumination().intensity).toBe(0.5);
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
describe('complex lighting setup', () => {
|
|
396
|
+
it('should setup complete scene lighting', () => {
|
|
397
|
+
const lig = new LightingTrait();
|
|
398
|
+
|
|
399
|
+
// Sun
|
|
400
|
+
lig.addLight({
|
|
401
|
+
type: 'directional',
|
|
402
|
+
direction: { x: 0.5, y: 1, z: 0.5 },
|
|
403
|
+
color: { r: 1, g: 0.95, b: 0.8 },
|
|
404
|
+
intensity: 1.2,
|
|
405
|
+
shadow: {
|
|
406
|
+
type: 'soft',
|
|
407
|
+
resolution: 2048,
|
|
408
|
+
cascades: 4,
|
|
409
|
+
},
|
|
410
|
+
});
|
|
411
|
+
|
|
412
|
+
// Ambient key light
|
|
413
|
+
lig.addLight({
|
|
414
|
+
type: 'point',
|
|
415
|
+
position: { x: -5, y: 3, z: 0 },
|
|
416
|
+
color: { r: 1, g: 1, b: 1 },
|
|
417
|
+
intensity: 0.6,
|
|
418
|
+
range: 20,
|
|
419
|
+
});
|
|
420
|
+
|
|
421
|
+
// Fill light
|
|
422
|
+
lig.addLight({
|
|
423
|
+
type: 'point',
|
|
424
|
+
position: { x: 5, y: 2, z: -5 },
|
|
425
|
+
color: { r: 0.8, g: 0.8, b: 1 },
|
|
426
|
+
intensity: 0.4,
|
|
427
|
+
range: 15,
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// Rim light
|
|
431
|
+
lig.addLight({
|
|
432
|
+
type: 'spot',
|
|
433
|
+
position: { x: 0, y: 5, z: -10 },
|
|
434
|
+
direction: { x: 0, y: -1, z: 0.5 },
|
|
435
|
+
color: { r: 1, g: 1, b: 1 },
|
|
436
|
+
intensity: 0.8,
|
|
437
|
+
range: 30,
|
|
438
|
+
spotAngle: 30,
|
|
439
|
+
});
|
|
440
|
+
|
|
441
|
+
// Setup GI
|
|
442
|
+
lig.setAmbientLight(
|
|
443
|
+
{ r: 0.5, g: 0.7, b: 1 },
|
|
444
|
+
{ r: 0.4, g: 0.4, b: 0.35 },
|
|
445
|
+
1.0
|
|
446
|
+
);
|
|
447
|
+
lig.setScreenSpaceAO(true, 1.0);
|
|
448
|
+
|
|
449
|
+
const lights = lig.getLights();
|
|
450
|
+
expect(lights).toHaveLength(4);
|
|
451
|
+
expect(lig.getPerformanceImpact().shadowCasters).toBe(1);
|
|
452
|
+
});
|
|
453
|
+
});
|
|
454
|
+
|
|
455
|
+
describe('disposal', () => {
|
|
456
|
+
it('should dispose and cleanup', () => {
|
|
457
|
+
lighting.createDirectionalLight({ x: 0, y: 1, z: 0 }, { r: 1, g: 1, b: 1 }, 1.0, true);
|
|
458
|
+
lighting.dispose();
|
|
459
|
+
expect(lighting.getLights()).toHaveLength(0);
|
|
460
|
+
});
|
|
461
|
+
});
|
|
462
|
+
});
|