@playcanvas/web-components 0.3.0 → 0.6.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 (43) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +84 -84
  3. package/dist/components/gsplat-component.d.ts +79 -0
  4. package/dist/components/light-component.d.ts +48 -0
  5. package/dist/index.d.ts +2 -2
  6. package/dist/pwc.cjs +324 -203
  7. package/dist/pwc.cjs.map +1 -1
  8. package/dist/pwc.js +324 -203
  9. package/dist/pwc.js.map +1 -1
  10. package/dist/pwc.min.js +1 -1
  11. package/dist/pwc.min.js.map +1 -1
  12. package/dist/pwc.mjs +325 -204
  13. package/dist/pwc.mjs.map +1 -1
  14. package/package.json +76 -66
  15. package/src/app.ts +612 -606
  16. package/src/asset.ts +159 -159
  17. package/src/async-element.ts +46 -46
  18. package/src/colors.ts +150 -150
  19. package/src/components/camera-component.ts +557 -557
  20. package/src/components/collision-component.ts +183 -183
  21. package/src/components/component.ts +97 -97
  22. package/src/components/element-component.ts +367 -367
  23. package/src/components/gsplat-component.ts +161 -0
  24. package/src/components/light-component.ts +570 -466
  25. package/src/components/listener-component.ts +30 -30
  26. package/src/components/particlesystem-component.ts +155 -155
  27. package/src/components/render-component.ts +147 -147
  28. package/src/components/rigidbody-component.ts +227 -227
  29. package/src/components/screen-component.ts +157 -157
  30. package/src/components/script-component.ts +270 -270
  31. package/src/components/script.ts +90 -90
  32. package/src/components/sound-component.ts +230 -230
  33. package/src/components/sound-slot.ts +288 -288
  34. package/src/entity.ts +360 -360
  35. package/src/index.ts +63 -63
  36. package/src/material.ts +141 -141
  37. package/src/model.ts +111 -111
  38. package/src/module.ts +43 -43
  39. package/src/scene.ts +217 -217
  40. package/src/sky.ts +293 -293
  41. package/src/utils.ts +71 -71
  42. package/dist/components/splat-component.d.ts +0 -61
  43. package/src/components/splat-component.ts +0 -133
@@ -1,466 +1,570 @@
1
- import { Color, LightComponent, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF3_32F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_PCSS_32F, SHADOW_VSM_16F, SHADOW_VSM_32F } from 'playcanvas';
2
-
3
- import { ComponentElement } from './component';
4
- import { parseColor } from '../utils';
5
-
6
- const shadowTypes = new Map([
7
- ['pcf1-16f', SHADOW_PCF1_16F],
8
- ['pcf1-32f', SHADOW_PCF1_32F],
9
- ['pcf3-16f', SHADOW_PCF3_16F],
10
- ['pcf3-32f', SHADOW_PCF3_32F],
11
- ['pcf5-16f', SHADOW_PCF5_16F],
12
- ['pcf5-32f', SHADOW_PCF5_32F],
13
- ['vsm-16f', SHADOW_VSM_16F],
14
- ['vsm-32f', SHADOW_VSM_32F],
15
- ['pcss-32f', SHADOW_PCSS_32F]
16
- ]);
17
-
18
- /**
19
- * The LightComponentElement interface provides properties and methods for manipulating
20
- * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-light/ | `<pc-light>`} elements.
21
- * The LightComponentElement interface also inherits the properties and methods of the
22
- * {@link HTMLElement} interface.
23
- *
24
- * @category Components
25
- */
26
- class LightComponentElement extends ComponentElement {
27
- private _castShadows = false;
28
-
29
- private _color = new Color(1, 1, 1);
30
-
31
- private _innerConeAngle = 40;
32
-
33
- private _intensity = 1;
34
-
35
- private _normalOffsetBias = 0.05;
36
-
37
- private _outerConeAngle = 45;
38
-
39
- private _range = 10;
40
-
41
- private _shadowBias = 0.2;
42
-
43
- private _shadowDistance = 16;
44
-
45
- private _shadowIntensity = 1;
46
-
47
- private _shadowResolution = 1024;
48
-
49
- private _shadowType: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f' = 'pcf3-32f';
50
-
51
- private _type = 'directional';
52
-
53
- private _vsmBias = 0.01;
54
-
55
- private _vsmBlurSize = 11;
56
-
57
- /** @ignore */
58
- constructor() {
59
- super('light');
60
- }
61
-
62
- getInitialComponentData() {
63
- return {
64
- castShadows: this._castShadows,
65
- color: this._color,
66
- innerConeAngle: this._innerConeAngle,
67
- intensity: this._intensity,
68
- normalOffsetBias: this._normalOffsetBias,
69
- outerConeAngle: this._outerConeAngle,
70
- range: this._range,
71
- shadowBias: this._shadowBias,
72
- shadowDistance: this._shadowDistance,
73
- shadowIntensity: this._shadowIntensity,
74
- shadowResolution: this._shadowResolution,
75
- shadowType: shadowTypes.get(this._shadowType),
76
- type: this._type,
77
- vsmBias: this._vsmBias,
78
- vsmBlurSize: this._vsmBlurSize
79
- };
80
- }
81
-
82
- /**
83
- * Gets the underlying PlayCanvas light component.
84
- * @returns The light component.
85
- */
86
- get component(): LightComponent | null {
87
- return super.component as LightComponent | null;
88
- }
89
-
90
- /**
91
- * Sets the cast shadows flag of the light.
92
- * @param value - The cast shadows flag.
93
- */
94
- set castShadows(value: boolean) {
95
- this._castShadows = value;
96
- if (this.component) {
97
- this.component.castShadows = value;
98
- }
99
- }
100
-
101
- /**
102
- * Gets the cast shadows flag of the light.
103
- * @returns The cast shadows flag.
104
- */
105
- get castShadows() {
106
- return this._castShadows;
107
- }
108
-
109
- /**
110
- * Sets the color of the light.
111
- * @param value - The color.
112
- */
113
- set color(value: Color) {
114
- this._color = value;
115
- if (this.component) {
116
- this.component.color = value;
117
- }
118
- }
119
-
120
- /**
121
- * Gets the color of the light.
122
- * @returns The color.
123
- */
124
- get color() {
125
- return this._color;
126
- }
127
-
128
- /**
129
- * Sets the inner cone angle of the light.
130
- * @param value - The inner cone angle.
131
- */
132
- set innerConeAngle(value: number) {
133
- this._innerConeAngle = value;
134
- if (this.component) {
135
- this.component.innerConeAngle = value;
136
- }
137
- }
138
-
139
- /**
140
- * Gets the inner cone angle of the light.
141
- * @returns The inner cone angle.
142
- */
143
- get innerConeAngle() {
144
- return this._innerConeAngle;
145
- }
146
-
147
- /**
148
- * Sets the intensity of the light.
149
- * @param value - The intensity.
150
- */
151
- set intensity(value: number) {
152
- this._intensity = value;
153
- if (this.component) {
154
- this.component.intensity = value;
155
- }
156
- }
157
-
158
- /**
159
- * Gets the intensity of the light.
160
- * @returns The intensity.
161
- */
162
- get intensity() {
163
- return this._intensity;
164
- }
165
-
166
- /**
167
- * Sets the normal offset bias of the light.
168
- * @param value - The normal offset bias.
169
- */
170
- set normalOffsetBias(value: number) {
171
- this._normalOffsetBias = value;
172
- if (this.component) {
173
- this.component.normalOffsetBias = value;
174
- }
175
- }
176
-
177
- /**
178
- * Gets the normal offset bias of the light.
179
- * @returns The normal offset bias.
180
- */
181
- get normalOffsetBias() {
182
- return this._normalOffsetBias;
183
- }
184
-
185
- /**
186
- * Sets the outer cone angle of the light.
187
- * @param value - The outer cone angle.
188
- */
189
- set outerConeAngle(value: number) {
190
- this._outerConeAngle = value;
191
- if (this.component) {
192
- this.component.outerConeAngle = value;
193
- }
194
- }
195
-
196
- /**
197
- * Gets the outer cone angle of the light.
198
- * @returns The outer cone angle.
199
- */
200
- get outerConeAngle() {
201
- return this._outerConeAngle;
202
- }
203
-
204
- /**
205
- * Sets the range of the light.
206
- * @param value - The range.
207
- */
208
- set range(value: number) {
209
- this._range = value;
210
- if (this.component) {
211
- this.component.range = value;
212
- }
213
- }
214
-
215
- /**
216
- * Gets the range of the light.
217
- * @returns The range.
218
- */
219
- get range() {
220
- return this._range;
221
- }
222
-
223
- /**
224
- * Sets the shadow bias of the light.
225
- * @param value - The shadow bias.
226
- */
227
- set shadowBias(value: number) {
228
- this._shadowBias = value;
229
- if (this.component) {
230
- this.component.shadowBias = value;
231
- }
232
- }
233
-
234
- /**
235
- * Gets the shadow bias of the light.
236
- * @returns The shadow bias.
237
- */
238
- get shadowBias() {
239
- return this._shadowBias;
240
- }
241
-
242
- /**
243
- * Sets the shadow distance of the light.
244
- * @param value - The shadow distance.
245
- */
246
- set shadowDistance(value: number) {
247
- this._shadowDistance = value;
248
- if (this.component) {
249
- this.component.shadowDistance = value;
250
- }
251
- }
252
-
253
- /**
254
- * Gets the shadow distance of the light.
255
- * @returns The shadow distance.
256
- */
257
- get shadowDistance() {
258
- return this._shadowDistance;
259
- }
260
-
261
- /**
262
- * Sets the shadow intensity of the light.
263
- * @param value - The shadow intensity.
264
- */
265
- set shadowIntensity(value: number) {
266
- this._shadowIntensity = value;
267
- if (this.component) {
268
- this.component.shadowIntensity = value;
269
- }
270
- }
271
-
272
- /**
273
- * Gets the shadow intensity of the light.
274
- * @returns The shadow intensity.
275
- */
276
- get shadowIntensity() {
277
- return this._shadowIntensity;
278
- }
279
-
280
- /**
281
- * Sets the shadow resolution of the light.
282
- * @param value - The shadow resolution.
283
- */
284
- set shadowResolution(value: number) {
285
- this._shadowResolution = value;
286
- if (this.component) {
287
- this.component.shadowResolution = value;
288
- }
289
- }
290
-
291
- /**
292
- * Gets the shadow resolution of the light.
293
- * @returns The shadow resolution.
294
- */
295
- get shadowResolution() {
296
- return this._shadowResolution;
297
- }
298
-
299
- /**
300
- * Sets the shadow type of the light.
301
- * @param value - The shadow type. Can be:
302
- *
303
- * - `pcf1-16f` - 1-tap percentage-closer filtered shadow map with 16-bit depth.
304
- * - `pcf1-32f` - 1-tap percentage-closer filtered shadow map with 32-bit depth.
305
- * - `pcf3-16f` - 3-tap percentage-closer filtered shadow map with 16-bit depth.
306
- * - `pcf3-32f` - 3-tap percentage-closer filtered shadow map with 32-bit depth.
307
- * - `pcf5-16f` - 5-tap percentage-closer filtered shadow map with 16-bit depth.
308
- * - `pcf5-32f` - 5-tap percentage-closer filtered shadow map with 32-bit depth.
309
- * - `vsm-16f` - Variance shadow map with 16-bit depth.
310
- * - `vsm-32f` - Variance shadow map with 32-bit depth.
311
- * - `pcss-32f` - Percentage-closer soft shadow with 32-bit depth.
312
- */
313
- set shadowType(value: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f') {
314
- this._shadowType = value;
315
- if (this.component) {
316
- this.component.shadowType = shadowTypes.get(value) ?? SHADOW_PCF3_32F;
317
- }
318
- }
319
-
320
- /**
321
- * Gets the shadow type of the light.
322
- * @returns The shadow type.
323
- */
324
- get shadowType() {
325
- return this._shadowType;
326
- }
327
-
328
- /**
329
- * Sets the type of the light.
330
- * @param value - The type.
331
- */
332
- set type(value: string) {
333
- if (!['directional', 'omni', 'spot'].includes(value)) {
334
- console.warn(`Invalid light type '${value}', using default type '${this._type}'.`);
335
- return;
336
- }
337
-
338
- this._type = value;
339
- if (this.component) {
340
- this.component.type = value;
341
- }
342
- }
343
-
344
- /**
345
- * Gets the type of the light.
346
- * @returns The type.
347
- */
348
- get type() {
349
- return this._type;
350
- }
351
-
352
- /**
353
- * Sets the VSM bias of the light.
354
- * @param value - The VSM bias.
355
- */
356
- set vsmBias(value: number) {
357
- this._vsmBias = value;
358
- if (this.component) {
359
- this.component.vsmBias = value;
360
- }
361
- }
362
-
363
- /**
364
- * Gets the VSM bias of the light.
365
- * @returns The VSM bias.
366
- */
367
- get vsmBias() {
368
- return this._vsmBias;
369
- }
370
-
371
- /**
372
- * Sets the VSM blur size of the light. Minimum is 1, maximum is 25. Default is 11.
373
- * @param value - The VSM blur size.
374
- */
375
- set vsmBlurSize(value: number) {
376
- this._vsmBlurSize = value;
377
- if (this.component) {
378
- this.component.vsmBlurSize = value;
379
- }
380
- }
381
-
382
- /**
383
- * Gets the VSM blur size of the light.
384
- * @returns The VSM blur size.
385
- */
386
- get vsmBlurSize() {
387
- return this._vsmBlurSize;
388
- }
389
-
390
- static get observedAttributes() {
391
- return [
392
- ...super.observedAttributes,
393
- 'color',
394
- 'cast-shadows',
395
- 'intensity',
396
- 'inner-cone-angle',
397
- 'normal-offset-bias',
398
- 'outer-cone-angle',
399
- 'range',
400
- 'shadow-bias',
401
- 'shadow-distance',
402
- 'shadow-intensity',
403
- 'shadow-resolution',
404
- 'shadow-type',
405
- 'type',
406
- 'vsm-bias',
407
- 'vsm-blur-size'
408
- ];
409
- }
410
-
411
- attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
412
- super.attributeChangedCallback(name, _oldValue, newValue);
413
-
414
- switch (name) {
415
- case 'color':
416
- this.color = parseColor(newValue);
417
- break;
418
- case 'cast-shadows':
419
- this.castShadows = this.hasAttribute('cast-shadows');
420
- break;
421
- case 'inner-cone-angle':
422
- this.innerConeAngle = Number(newValue);
423
- break;
424
- case 'intensity':
425
- this.intensity = Number(newValue);
426
- break;
427
- case 'normal-offset-bias':
428
- this.normalOffsetBias = Number(newValue);
429
- break;
430
- case 'outer-cone-angle':
431
- this.outerConeAngle = Number(newValue);
432
- break;
433
- case 'range':
434
- this.range = Number(newValue);
435
- break;
436
- case 'shadow-bias':
437
- this.shadowBias = Number(newValue);
438
- break;
439
- case 'shadow-distance':
440
- this.shadowDistance = Number(newValue);
441
- break;
442
- case 'shadow-resolution':
443
- this.shadowResolution = Number(newValue);
444
- break;
445
- case 'shadow-intensity':
446
- this.shadowIntensity = Number(newValue);
447
- break;
448
- case 'shadow-type':
449
- this.shadowType = newValue as 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f';
450
- break;
451
- case 'type':
452
- this.type = newValue;
453
- break;
454
- case 'vsm-bias':
455
- this.vsmBias = Number(newValue);
456
- break;
457
- case 'vsm-blur-size':
458
- this.vsmBlurSize = Number(newValue);
459
- break;
460
- }
461
- }
462
- }
463
-
464
- customElements.define('pc-light', LightComponentElement);
465
-
466
- export { LightComponentElement };
1
+ import { Color, LightComponent, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF3_32F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_PCSS_32F, SHADOW_VSM_16F, SHADOW_VSM_32F } from 'playcanvas';
2
+
3
+ import { ComponentElement } from './component';
4
+ import { parseColor } from '../utils';
5
+
6
+ const shadowTypes = new Map([
7
+ ['pcf1-16f', SHADOW_PCF1_16F],
8
+ ['pcf1-32f', SHADOW_PCF1_32F],
9
+ ['pcf3-16f', SHADOW_PCF3_16F],
10
+ ['pcf3-32f', SHADOW_PCF3_32F],
11
+ ['pcf5-16f', SHADOW_PCF5_16F],
12
+ ['pcf5-32f', SHADOW_PCF5_32F],
13
+ ['vsm-16f', SHADOW_VSM_16F],
14
+ ['vsm-32f', SHADOW_VSM_32F],
15
+ ['pcss-32f', SHADOW_PCSS_32F]
16
+ ]);
17
+
18
+ /**
19
+ * The LightComponentElement interface provides properties and methods for manipulating
20
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-light/ | `<pc-light>`} elements.
21
+ * The LightComponentElement interface also inherits the properties and methods of the
22
+ * {@link HTMLElement} interface.
23
+ *
24
+ * @category Components
25
+ */
26
+ class LightComponentElement extends ComponentElement {
27
+ private _castShadows = false;
28
+
29
+ private _color = new Color(1, 1, 1);
30
+
31
+ private _innerConeAngle = 40;
32
+
33
+ private _intensity = 1;
34
+
35
+ private _normalOffsetBias = 0.05;
36
+
37
+ private _outerConeAngle = 45;
38
+
39
+ private _range = 10;
40
+
41
+ private _shadowBias = 0.2;
42
+
43
+ private _shadowDistance = 16;
44
+
45
+ private _shadowIntensity = 1;
46
+
47
+ private _shadowResolution = 1024;
48
+
49
+ private _shadowType: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f' = 'pcf3-32f';
50
+
51
+ private _type = 'directional';
52
+
53
+ private _vsmBias = 0.01;
54
+
55
+ private _vsmBlurSize = 11;
56
+
57
+ private _penumbraSize = 1;
58
+
59
+ private _penumbraFalloff = 1;
60
+
61
+ private _shadowSamples = 16;
62
+
63
+ private _shadowBlockerSamples = 16;
64
+
65
+ /** @ignore */
66
+ constructor() {
67
+ super('light');
68
+ }
69
+
70
+ getInitialComponentData() {
71
+ return {
72
+ castShadows: this._castShadows,
73
+ color: this._color,
74
+ innerConeAngle: this._innerConeAngle,
75
+ intensity: this._intensity,
76
+ normalOffsetBias: this._normalOffsetBias,
77
+ outerConeAngle: this._outerConeAngle,
78
+ penumbraFalloff: this._penumbraFalloff,
79
+ penumbraSize: this._penumbraSize,
80
+ range: this._range,
81
+ shadowBias: this._shadowBias,
82
+ shadowBlockerSamples: this._shadowBlockerSamples,
83
+ shadowDistance: this._shadowDistance,
84
+ shadowIntensity: this._shadowIntensity,
85
+ shadowResolution: this._shadowResolution,
86
+ shadowSamples: this._shadowSamples,
87
+ shadowType: shadowTypes.get(this._shadowType),
88
+ type: this._type,
89
+ vsmBias: this._vsmBias,
90
+ vsmBlurSize: this._vsmBlurSize
91
+ };
92
+ }
93
+
94
+ /**
95
+ * Gets the underlying PlayCanvas light component.
96
+ * @returns The light component.
97
+ */
98
+ get component(): LightComponent | null {
99
+ return super.component as LightComponent | null;
100
+ }
101
+
102
+ /**
103
+ * Sets the cast shadows flag of the light.
104
+ * @param value - The cast shadows flag.
105
+ */
106
+ set castShadows(value: boolean) {
107
+ this._castShadows = value;
108
+ if (this.component) {
109
+ this.component.castShadows = value;
110
+ }
111
+ }
112
+
113
+ /**
114
+ * Gets the cast shadows flag of the light.
115
+ * @returns The cast shadows flag.
116
+ */
117
+ get castShadows() {
118
+ return this._castShadows;
119
+ }
120
+
121
+ /**
122
+ * Sets the color of the light.
123
+ * @param value - The color.
124
+ */
125
+ set color(value: Color) {
126
+ this._color = value;
127
+ if (this.component) {
128
+ this.component.color = value;
129
+ }
130
+ }
131
+
132
+ /**
133
+ * Gets the color of the light.
134
+ * @returns The color.
135
+ */
136
+ get color() {
137
+ return this._color;
138
+ }
139
+
140
+ /**
141
+ * Sets the inner cone angle of the light.
142
+ * @param value - The inner cone angle.
143
+ */
144
+ set innerConeAngle(value: number) {
145
+ this._innerConeAngle = value;
146
+ if (this.component) {
147
+ this.component.innerConeAngle = value;
148
+ }
149
+ }
150
+
151
+ /**
152
+ * Gets the inner cone angle of the light.
153
+ * @returns The inner cone angle.
154
+ */
155
+ get innerConeAngle() {
156
+ return this._innerConeAngle;
157
+ }
158
+
159
+ /**
160
+ * Sets the intensity of the light.
161
+ * @param value - The intensity.
162
+ */
163
+ set intensity(value: number) {
164
+ this._intensity = value;
165
+ if (this.component) {
166
+ this.component.intensity = value;
167
+ }
168
+ }
169
+
170
+ /**
171
+ * Gets the intensity of the light.
172
+ * @returns The intensity.
173
+ */
174
+ get intensity() {
175
+ return this._intensity;
176
+ }
177
+
178
+ /**
179
+ * Sets the normal offset bias of the light.
180
+ * @param value - The normal offset bias.
181
+ */
182
+ set normalOffsetBias(value: number) {
183
+ this._normalOffsetBias = value;
184
+ if (this.component) {
185
+ this.component.normalOffsetBias = value;
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Gets the normal offset bias of the light.
191
+ * @returns The normal offset bias.
192
+ */
193
+ get normalOffsetBias() {
194
+ return this._normalOffsetBias;
195
+ }
196
+
197
+ /**
198
+ * Sets the outer cone angle of the light.
199
+ * @param value - The outer cone angle.
200
+ */
201
+ set outerConeAngle(value: number) {
202
+ this._outerConeAngle = value;
203
+ if (this.component) {
204
+ this.component.outerConeAngle = value;
205
+ }
206
+ }
207
+
208
+ /**
209
+ * Gets the outer cone angle of the light.
210
+ * @returns The outer cone angle.
211
+ */
212
+ get outerConeAngle() {
213
+ return this._outerConeAngle;
214
+ }
215
+
216
+ /**
217
+ * Sets the range of the light.
218
+ * @param value - The range.
219
+ */
220
+ set range(value: number) {
221
+ this._range = value;
222
+ if (this.component) {
223
+ this.component.range = value;
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Gets the range of the light.
229
+ * @returns The range.
230
+ */
231
+ get range() {
232
+ return this._range;
233
+ }
234
+
235
+ /**
236
+ * Sets the shadow bias of the light.
237
+ * @param value - The shadow bias.
238
+ */
239
+ set shadowBias(value: number) {
240
+ this._shadowBias = value;
241
+ if (this.component) {
242
+ this.component.shadowBias = value;
243
+ }
244
+ }
245
+
246
+ /**
247
+ * Gets the shadow bias of the light.
248
+ * @returns The shadow bias.
249
+ */
250
+ get shadowBias() {
251
+ return this._shadowBias;
252
+ }
253
+
254
+ /**
255
+ * Sets the shadow distance of the light.
256
+ * @param value - The shadow distance.
257
+ */
258
+ set shadowDistance(value: number) {
259
+ this._shadowDistance = value;
260
+ if (this.component) {
261
+ this.component.shadowDistance = value;
262
+ }
263
+ }
264
+
265
+ /**
266
+ * Gets the shadow distance of the light.
267
+ * @returns The shadow distance.
268
+ */
269
+ get shadowDistance() {
270
+ return this._shadowDistance;
271
+ }
272
+
273
+ /**
274
+ * Sets the shadow intensity of the light.
275
+ * @param value - The shadow intensity.
276
+ */
277
+ set shadowIntensity(value: number) {
278
+ this._shadowIntensity = value;
279
+ if (this.component) {
280
+ this.component.shadowIntensity = value;
281
+ }
282
+ }
283
+
284
+ /**
285
+ * Gets the shadow intensity of the light.
286
+ * @returns The shadow intensity.
287
+ */
288
+ get shadowIntensity() {
289
+ return this._shadowIntensity;
290
+ }
291
+
292
+ /**
293
+ * Sets the shadow resolution of the light.
294
+ * @param value - The shadow resolution.
295
+ */
296
+ set shadowResolution(value: number) {
297
+ this._shadowResolution = value;
298
+ if (this.component) {
299
+ this.component.shadowResolution = value;
300
+ }
301
+ }
302
+
303
+ /**
304
+ * Gets the shadow resolution of the light.
305
+ * @returns The shadow resolution.
306
+ */
307
+ get shadowResolution() {
308
+ return this._shadowResolution;
309
+ }
310
+
311
+ /**
312
+ * Sets the shadow type of the light.
313
+ * @param value - The shadow type. Can be:
314
+ *
315
+ * - `pcf1-16f` - 1-tap percentage-closer filtered shadow map with 16-bit depth.
316
+ * - `pcf1-32f` - 1-tap percentage-closer filtered shadow map with 32-bit depth.
317
+ * - `pcf3-16f` - 3-tap percentage-closer filtered shadow map with 16-bit depth.
318
+ * - `pcf3-32f` - 3-tap percentage-closer filtered shadow map with 32-bit depth.
319
+ * - `pcf5-16f` - 5-tap percentage-closer filtered shadow map with 16-bit depth.
320
+ * - `pcf5-32f` - 5-tap percentage-closer filtered shadow map with 32-bit depth.
321
+ * - `vsm-16f` - Variance shadow map with 16-bit depth.
322
+ * - `vsm-32f` - Variance shadow map with 32-bit depth.
323
+ * - `pcss-32f` - Percentage-closer soft shadow with 32-bit depth.
324
+ */
325
+ set shadowType(value: 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f') {
326
+ this._shadowType = value;
327
+ if (this.component) {
328
+ this.component.shadowType = shadowTypes.get(value) ?? SHADOW_PCF3_32F;
329
+ }
330
+ }
331
+
332
+ /**
333
+ * Gets the shadow type of the light.
334
+ * @returns The shadow type.
335
+ */
336
+ get shadowType() {
337
+ return this._shadowType;
338
+ }
339
+
340
+ /**
341
+ * Sets the type of the light.
342
+ * @param value - The type.
343
+ */
344
+ set type(value: string) {
345
+ if (!['directional', 'omni', 'spot'].includes(value)) {
346
+ console.warn(`Invalid light type '${value}', using default type '${this._type}'.`);
347
+ return;
348
+ }
349
+
350
+ this._type = value;
351
+ if (this.component) {
352
+ this.component.type = value;
353
+ }
354
+ }
355
+
356
+ /**
357
+ * Gets the type of the light.
358
+ * @returns The type.
359
+ */
360
+ get type() {
361
+ return this._type;
362
+ }
363
+
364
+ /**
365
+ * Sets the VSM bias of the light.
366
+ * @param value - The VSM bias.
367
+ */
368
+ set vsmBias(value: number) {
369
+ this._vsmBias = value;
370
+ if (this.component) {
371
+ this.component.vsmBias = value;
372
+ }
373
+ }
374
+
375
+ /**
376
+ * Gets the VSM bias of the light.
377
+ * @returns The VSM bias.
378
+ */
379
+ get vsmBias() {
380
+ return this._vsmBias;
381
+ }
382
+
383
+ /**
384
+ * Sets the VSM blur size of the light. Minimum is 1, maximum is 25. Default is 11.
385
+ * @param value - The VSM blur size.
386
+ */
387
+ set vsmBlurSize(value: number) {
388
+ this._vsmBlurSize = value;
389
+ if (this.component) {
390
+ this.component.vsmBlurSize = value;
391
+ }
392
+ }
393
+
394
+ /**
395
+ * Gets the VSM blur size of the light.
396
+ * @returns The VSM blur size.
397
+ */
398
+ get vsmBlurSize() {
399
+ return this._vsmBlurSize;
400
+ }
401
+
402
+ /**
403
+ * Sets the penumbra size of the light. Used for PCSS shadows.
404
+ * @param value - The penumbra size.
405
+ */
406
+ set penumbraSize(value: number) {
407
+ this._penumbraSize = value;
408
+ if (this.component) {
409
+ this.component.penumbraSize = value;
410
+ }
411
+ }
412
+
413
+ /**
414
+ * Gets the penumbra size of the light.
415
+ * @returns The penumbra size.
416
+ */
417
+ get penumbraSize() {
418
+ return this._penumbraSize;
419
+ }
420
+
421
+ /**
422
+ * Sets the penumbra falloff of the light. Used for PCSS shadows.
423
+ * @param value - The penumbra falloff.
424
+ */
425
+ set penumbraFalloff(value: number) {
426
+ this._penumbraFalloff = value;
427
+ if (this.component) {
428
+ this.component.penumbraFalloff = value;
429
+ }
430
+ }
431
+
432
+ /**
433
+ * Gets the penumbra falloff of the light.
434
+ * @returns The penumbra falloff.
435
+ */
436
+ get penumbraFalloff() {
437
+ return this._penumbraFalloff;
438
+ }
439
+
440
+ /**
441
+ * Sets the number of shadow samples. Used for PCSS shadows.
442
+ * @param value - The number of shadow samples.
443
+ */
444
+ set shadowSamples(value: number) {
445
+ this._shadowSamples = value;
446
+ if (this.component) {
447
+ this.component.shadowSamples = value;
448
+ }
449
+ }
450
+
451
+ /**
452
+ * Gets the number of shadow samples.
453
+ * @returns The number of shadow samples.
454
+ */
455
+ get shadowSamples() {
456
+ return this._shadowSamples;
457
+ }
458
+
459
+ /**
460
+ * Sets the number of shadow blocker samples. Used for PCSS shadows.
461
+ * @param value - The number of shadow blocker samples.
462
+ */
463
+ set shadowBlockerSamples(value: number) {
464
+ this._shadowBlockerSamples = value;
465
+ if (this.component) {
466
+ this.component.shadowBlockerSamples = value;
467
+ }
468
+ }
469
+
470
+ /**
471
+ * Gets the number of shadow blocker samples.
472
+ * @returns The number of shadow blocker samples.
473
+ */
474
+ get shadowBlockerSamples() {
475
+ return this._shadowBlockerSamples;
476
+ }
477
+
478
+ static get observedAttributes() {
479
+ return [
480
+ ...super.observedAttributes,
481
+ 'color',
482
+ 'cast-shadows',
483
+ 'intensity',
484
+ 'inner-cone-angle',
485
+ 'normal-offset-bias',
486
+ 'outer-cone-angle',
487
+ 'penumbra-falloff',
488
+ 'penumbra-size',
489
+ 'range',
490
+ 'shadow-bias',
491
+ 'shadow-blocker-samples',
492
+ 'shadow-distance',
493
+ 'shadow-intensity',
494
+ 'shadow-resolution',
495
+ 'shadow-samples',
496
+ 'shadow-type',
497
+ 'type',
498
+ 'vsm-bias',
499
+ 'vsm-blur-size'
500
+ ];
501
+ }
502
+
503
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
504
+ super.attributeChangedCallback(name, _oldValue, newValue);
505
+
506
+ switch (name) {
507
+ case 'color':
508
+ this.color = parseColor(newValue);
509
+ break;
510
+ case 'cast-shadows':
511
+ this.castShadows = this.hasAttribute('cast-shadows');
512
+ break;
513
+ case 'inner-cone-angle':
514
+ this.innerConeAngle = Number(newValue);
515
+ break;
516
+ case 'intensity':
517
+ this.intensity = Number(newValue);
518
+ break;
519
+ case 'normal-offset-bias':
520
+ this.normalOffsetBias = Number(newValue);
521
+ break;
522
+ case 'outer-cone-angle':
523
+ this.outerConeAngle = Number(newValue);
524
+ break;
525
+ case 'penumbra-falloff':
526
+ this.penumbraFalloff = Number(newValue);
527
+ break;
528
+ case 'penumbra-size':
529
+ this.penumbraSize = Number(newValue);
530
+ break;
531
+ case 'range':
532
+ this.range = Number(newValue);
533
+ break;
534
+ case 'shadow-bias':
535
+ this.shadowBias = Number(newValue);
536
+ break;
537
+ case 'shadow-distance':
538
+ this.shadowDistance = Number(newValue);
539
+ break;
540
+ case 'shadow-blocker-samples':
541
+ this.shadowBlockerSamples = Number(newValue);
542
+ break;
543
+ case 'shadow-resolution':
544
+ this.shadowResolution = Number(newValue);
545
+ break;
546
+ case 'shadow-intensity':
547
+ this.shadowIntensity = Number(newValue);
548
+ break;
549
+ case 'shadow-samples':
550
+ this.shadowSamples = Number(newValue);
551
+ break;
552
+ case 'shadow-type':
553
+ this.shadowType = newValue as 'pcf1-16f' | 'pcf1-32f' | 'pcf3-16f' | 'pcf3-32f' | 'pcf5-16f' | 'pcf5-32f' | 'vsm-16f' | 'vsm-32f' | 'pcss-32f';
554
+ break;
555
+ case 'type':
556
+ this.type = newValue;
557
+ break;
558
+ case 'vsm-bias':
559
+ this.vsmBias = Number(newValue);
560
+ break;
561
+ case 'vsm-blur-size':
562
+ this.vsmBlurSize = Number(newValue);
563
+ break;
564
+ }
565
+ }
566
+ }
567
+
568
+ customElements.define('pc-light', LightComponentElement);
569
+
570
+ export { LightComponentElement };