@playcanvas/web-components 0.3.0 → 0.5.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 (40) hide show
  1. package/LICENSE +21 -21
  2. package/README.md +84 -84
  3. package/dist/components/light-component.d.ts +48 -0
  4. package/dist/components/splat-component.d.ts +0 -13
  5. package/dist/pwc.cjs +275 -207
  6. package/dist/pwc.cjs.map +1 -1
  7. package/dist/pwc.js +275 -207
  8. package/dist/pwc.js.map +1 -1
  9. package/dist/pwc.min.js +1 -1
  10. package/dist/pwc.min.js.map +1 -1
  11. package/dist/pwc.mjs +276 -208
  12. package/dist/pwc.mjs.map +1 -1
  13. package/package.json +76 -66
  14. package/src/app.ts +612 -606
  15. package/src/asset.ts +159 -159
  16. package/src/async-element.ts +46 -46
  17. package/src/colors.ts +150 -150
  18. package/src/components/camera-component.ts +557 -557
  19. package/src/components/collision-component.ts +183 -183
  20. package/src/components/component.ts +97 -97
  21. package/src/components/element-component.ts +367 -367
  22. package/src/components/light-component.ts +570 -466
  23. package/src/components/listener-component.ts +30 -30
  24. package/src/components/particlesystem-component.ts +155 -155
  25. package/src/components/render-component.ts +147 -147
  26. package/src/components/rigidbody-component.ts +227 -227
  27. package/src/components/screen-component.ts +157 -157
  28. package/src/components/script-component.ts +270 -270
  29. package/src/components/script.ts +90 -90
  30. package/src/components/sound-component.ts +230 -230
  31. package/src/components/sound-slot.ts +288 -288
  32. package/src/components/splat-component.ts +102 -133
  33. package/src/entity.ts +360 -360
  34. package/src/index.ts +63 -63
  35. package/src/material.ts +141 -141
  36. package/src/model.ts +111 -111
  37. package/src/module.ts +43 -43
  38. package/src/scene.ts +217 -217
  39. package/src/sky.ts +293 -293
  40. package/src/utils.ts +71 -71
@@ -1,557 +1,557 @@
1
- import { CameraComponent, Color, Vec4, GAMMA_NONE, GAMMA_SRGB, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, TONEMAP_LINEAR, TONEMAP_FILMIC, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_NONE, XRTYPE_VR } from 'playcanvas';
2
-
3
- import { ComponentElement } from './component';
4
- import { parseColor, parseVec4 } from '../utils';
5
-
6
- const tonemaps = new Map([
7
- ['none', TONEMAP_NONE],
8
- ['linear', TONEMAP_LINEAR],
9
- ['filmic', TONEMAP_FILMIC],
10
- ['hejl', TONEMAP_HEJL],
11
- ['aces', TONEMAP_ACES],
12
- ['aces2', TONEMAP_ACES2],
13
- ['neutral', TONEMAP_NEUTRAL]
14
- ]);
15
-
16
- /**
17
- * The CameraComponentElement interface provides properties and methods for manipulating
18
- * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
19
- * The CameraComponentElement interface also inherits the properties and methods of the
20
- * {@link HTMLElement} interface.
21
- *
22
- * @category Components
23
- */
24
- class CameraComponentElement extends ComponentElement {
25
- private _clearColor = new Color(0.75, 0.75, 0.75, 1);
26
-
27
- private _clearColorBuffer = true;
28
-
29
- private _clearDepthBuffer = true;
30
-
31
- private _clearStencilBuffer = false;
32
-
33
- private _cullFaces = true;
34
-
35
- private _farClip = 1000;
36
-
37
- private _flipFaces = false;
38
-
39
- private _fov = 45;
40
-
41
- private _frustumCulling = true;
42
-
43
- private _gamma: 'linear' | 'srgb' = 'srgb';
44
-
45
- private _horizontalFov = false;
46
-
47
- private _nearClip = 0.1;
48
-
49
- private _orthographic = false;
50
-
51
- private _orthoHeight = 10;
52
-
53
- private _priority = 0;
54
-
55
- private _rect = new Vec4(0, 0, 1, 1);
56
-
57
- private _scissorRect = new Vec4(0, 0, 1, 1);
58
-
59
- private _tonemap: 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral' = 'none';
60
-
61
- /** @ignore */
62
- constructor() {
63
- super('camera');
64
- }
65
-
66
- getInitialComponentData() {
67
- return {
68
- clearColor: this._clearColor,
69
- clearColorBuffer: this._clearColorBuffer,
70
- clearDepthBuffer: this._clearDepthBuffer,
71
- clearStencilBuffer: this._clearStencilBuffer,
72
- cullFaces: this._cullFaces,
73
- farClip: this._farClip,
74
- flipFaces: this._flipFaces,
75
- fov: this._fov,
76
- frustumCulling: this._frustumCulling,
77
- gammaCorrection: this._gamma === 'srgb' ? GAMMA_SRGB : GAMMA_NONE,
78
- horizontalFov: this._horizontalFov,
79
- nearClip: this._nearClip,
80
- orthographic: this._orthographic,
81
- orthoHeight: this._orthoHeight,
82
- priority: this._priority,
83
- rect: this._rect,
84
- scissorRect: this._scissorRect,
85
- toneMapping: tonemaps.get(this._tonemap)
86
- };
87
- }
88
-
89
- get xrAvailable() {
90
- const xrManager = this.component?.system.app.xr;
91
- return xrManager && xrManager.supported && xrManager.isAvailable(XRTYPE_VR);
92
- }
93
-
94
- /**
95
- * Starts the camera in XR mode.
96
- * @param type - The type of XR mode to start.
97
- * @param space - The space to start the camera in.
98
- */
99
- startXr(type: 'immersive-ar' | 'immersive-vr', space: 'bounded-floor' | 'local' | 'local-floor' | 'unbounded' | 'viewer') {
100
- if (this.component && this.xrAvailable) {
101
- this.component.startXr(type, space, {
102
- callback: (err: any) => {
103
- if (err) console.error(`WebXR Immersive VR failed to start: ${err.message}`);
104
- }
105
- });
106
- }
107
- }
108
-
109
- /**
110
- * Ends the camera's XR mode.
111
- */
112
- endXr() {
113
- if (this.component) {
114
- this.component.endXr();
115
- }
116
- }
117
-
118
- /**
119
- * Gets the underlying PlayCanvas camera component.
120
- * @returns The camera component.
121
- */
122
- get component(): CameraComponent | null {
123
- return super.component as CameraComponent | null;
124
- }
125
-
126
- /**
127
- * Sets the clear color of the camera.
128
- * @param value - The clear color.
129
- */
130
- set clearColor(value) {
131
- this._clearColor = value;
132
- if (this.component) {
133
- this.component.clearColor = value;
134
- }
135
- }
136
-
137
- /**
138
- * Gets the clear color of the camera.
139
- * @returns The clear color.
140
- */
141
- get clearColor(): Color {
142
- return this._clearColor;
143
- }
144
-
145
- /**
146
- * Sets the clear color buffer of the camera.
147
- * @param value - The clear color buffer.
148
- */
149
- set clearColorBuffer(value: boolean) {
150
- this._clearColorBuffer = value;
151
- if (this.component) {
152
- this.component.clearColorBuffer = value;
153
- }
154
- }
155
-
156
- /**
157
- * Gets the clear color buffer of the camera.
158
- * @returns The clear color buffer.
159
- */
160
- get clearColorBuffer(): boolean {
161
- return this._clearColorBuffer;
162
- }
163
-
164
- /**
165
- * Sets the clear depth buffer of the camera.
166
- * @param value - The clear depth buffer.
167
- */
168
- set clearDepthBuffer(value: boolean) {
169
- this._clearDepthBuffer = value;
170
- if (this.component) {
171
- this.component.clearDepthBuffer = value;
172
- }
173
- }
174
-
175
- /**
176
- * Gets the clear depth buffer of the camera.
177
- * @returns The clear depth buffer.
178
- */
179
- get clearDepthBuffer(): boolean {
180
- return this._clearDepthBuffer;
181
- }
182
-
183
- /**
184
- * Sets the clear stencil buffer of the camera.
185
- * @param value - The clear stencil buffer.
186
- */
187
- set clearStencilBuffer(value: boolean) {
188
- this._clearStencilBuffer = value;
189
- if (this.component) {
190
- this.component.clearStencilBuffer = value;
191
- }
192
- }
193
-
194
- /**
195
- * Gets the clear stencil buffer of the camera.
196
- * @returns The clear stencil buffer.
197
- */
198
- get clearStencilBuffer(): boolean {
199
- return this._clearStencilBuffer;
200
- }
201
-
202
- /**
203
- * Sets the cull faces of the camera.
204
- * @param value - The cull faces.
205
- */
206
- set cullFaces(value: boolean) {
207
- this._cullFaces = value;
208
- if (this.component) {
209
- this.component.cullFaces = value;
210
- }
211
- }
212
-
213
- /**
214
- * Gets the cull faces of the camera.
215
- * @returns The cull faces.
216
- */
217
- get cullFaces(): boolean {
218
- return this._cullFaces;
219
- }
220
-
221
- /**
222
- * Sets the far clip distance of the camera.
223
- * @param value - The far clip distance.
224
- */
225
- set farClip(value: number) {
226
- this._farClip = value;
227
- if (this.component) {
228
- this.component.farClip = value;
229
- }
230
- }
231
-
232
- /**
233
- * Gets the far clip distance of the camera.
234
- * @returns The far clip distance.
235
- */
236
- get farClip(): number {
237
- return this._farClip;
238
- }
239
-
240
- /**
241
- * Sets the flip faces of the camera.
242
- * @param value - The flip faces.
243
- */
244
- set flipFaces(value: boolean) {
245
- this._flipFaces = value;
246
- if (this.component) {
247
- this.component.flipFaces = value;
248
- }
249
- }
250
-
251
- /**
252
- * Gets the flip faces of the camera.
253
- * @returns The flip faces.
254
- */
255
- get flipFaces(): boolean {
256
- return this._flipFaces;
257
- }
258
-
259
- /**
260
- * Sets the field of view of the camera.
261
- * @param value - The field of view.
262
- */
263
- set fov(value: number) {
264
- this._fov = value;
265
- if (this.component) {
266
- this.component.fov = value;
267
- }
268
- }
269
-
270
- /**
271
- * Gets the field of view of the camera.
272
- * @returns The field of view.
273
- */
274
- get fov(): number {
275
- return this._fov;
276
- }
277
-
278
- /**
279
- * Sets the frustum culling of the camera.
280
- * @param value - The frustum culling.
281
- */
282
- set frustumCulling(value: boolean) {
283
- this._frustumCulling = value;
284
- if (this.component) {
285
- this.component.frustumCulling = value;
286
- }
287
- }
288
-
289
- /**
290
- * Gets the frustum culling of the camera.
291
- * @returns The frustum culling.
292
- */
293
- get frustumCulling(): boolean {
294
- return this._frustumCulling;
295
- }
296
-
297
- /**
298
- * Sets the gamma correction of the camera.
299
- * @param value - The gamma correction.
300
- */
301
- set gamma(value: 'linear' | 'srgb') {
302
- this._gamma = value;
303
- if (this.component) {
304
- this.component.gammaCorrection = value === 'srgb' ? GAMMA_SRGB : GAMMA_NONE;
305
- }
306
- }
307
-
308
- /**
309
- * Gets the gamma correction of the camera.
310
- * @returns The gamma correction.
311
- */
312
- get gamma(): 'linear' | 'srgb' {
313
- return this._gamma;
314
- }
315
-
316
- /**
317
- * Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
318
- * (meaning it is vertical be default).
319
- * @param value - Whether the camera's field of view is horizontal.
320
- */
321
- set horizontalFov(value: boolean) {
322
- this._horizontalFov = value;
323
- if (this.component) {
324
- this.component.horizontalFov = value;
325
- }
326
- }
327
-
328
- /**
329
- * Gets whether the camera's field of view (fov) is horizontal or vertical.
330
- * @returns Whether the camera's field of view is horizontal.
331
- */
332
- get horizontalFov(): boolean {
333
- return this._horizontalFov;
334
- }
335
-
336
- /**
337
- * Sets the near clip distance of the camera.
338
- * @param value - The near clip distance.
339
- */
340
- set nearClip(value: number) {
341
- this._nearClip = value;
342
- if (this.component) {
343
- this.component.nearClip = value;
344
- }
345
- }
346
-
347
- /**
348
- * Gets the near clip distance of the camera.
349
- * @returns The near clip distance.
350
- */
351
- get nearClip(): number {
352
- return this._nearClip;
353
- }
354
-
355
- /**
356
- * Sets the orthographic projection of the camera.
357
- * @param value - The orthographic projection.
358
- */
359
- set orthographic(value) {
360
- this._orthographic = value;
361
- if (this.component) {
362
- this.component.projection = value ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE;
363
- }
364
- }
365
-
366
- /**
367
- * Gets the orthographic projection of the camera.
368
- * @returns The orthographic projection.
369
- */
370
- get orthographic(): boolean {
371
- return this._orthographic;
372
- }
373
-
374
- /**
375
- * Sets the orthographic height of the camera.
376
- * @param value - The orthographic height.
377
- */
378
- set orthoHeight(value: number) {
379
- this._orthoHeight = value;
380
- if (this.component) {
381
- this.component.orthoHeight = value;
382
- }
383
- }
384
-
385
- /**
386
- * Gets the orthographic height of the camera.
387
- * @returns The orthographic height.
388
- */
389
- get orthoHeight() {
390
- return this._orthoHeight;
391
- }
392
-
393
- /**
394
- * Sets the priority of the camera.
395
- * @param value - The priority.
396
- */
397
- set priority(value: number) {
398
- this._priority = value;
399
- if (this.component) {
400
- this.component.priority = value;
401
- }
402
- }
403
-
404
- /**
405
- * Gets the priority of the camera.
406
- * @returns The priority.
407
- */
408
- get priority(): number {
409
- return this._priority;
410
- }
411
-
412
- /**
413
- * Sets the rect of the camera.
414
- * @param value - The rect.
415
- */
416
- set rect(value: Vec4) {
417
- this._rect = value;
418
- if (this.component) {
419
- this.component.rect = value;
420
- }
421
- }
422
-
423
- /**
424
- * Gets the rect of the camera.
425
- * @returns The rect.
426
- */
427
- get rect(): Vec4 {
428
- return this._rect;
429
- }
430
-
431
- /**
432
- * Sets the scissor rect of the camera.
433
- * @param value - The scissor rect.
434
- */
435
- set scissorRect(value: Vec4) {
436
- this._scissorRect = value;
437
- if (this.component) {
438
- this.component.scissorRect = value;
439
- }
440
- }
441
-
442
- /**
443
- * Gets the scissor rect of the camera.
444
- * @returns The scissor rect.
445
- */
446
- get scissorRect(): Vec4 {
447
- return this._scissorRect;
448
- }
449
-
450
- /**
451
- * Sets the tone mapping of the camera.
452
- * @param value - The tone mapping.
453
- */
454
- set tonemap(value: 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral') {
455
- this._tonemap = value;
456
- if (this.component) {
457
- this.component.toneMapping = tonemaps.get(value) ?? TONEMAP_NONE;
458
- }
459
- }
460
-
461
- /**
462
- * Gets the tone mapping of the camera.
463
- * @returns The tone mapping.
464
- */
465
- get tonemap(): 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral' {
466
- return this._tonemap;
467
- }
468
-
469
- static get observedAttributes() {
470
- return [
471
- ...super.observedAttributes,
472
- 'clear-color',
473
- 'clear-color-buffer',
474
- 'clear-depth-buffer',
475
- 'clear-stencil-buffer',
476
- 'cull-faces',
477
- 'far-clip',
478
- 'flip-faces',
479
- 'fov',
480
- 'frustum-culling',
481
- 'gamma',
482
- 'horizontal-fov',
483
- 'near-clip',
484
- 'orthographic',
485
- 'ortho-height',
486
- 'priority',
487
- 'rect',
488
- 'scissor-rect',
489
- 'tonemap'
490
- ];
491
- }
492
-
493
- attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
494
- super.attributeChangedCallback(name, _oldValue, newValue);
495
-
496
- switch (name) {
497
- case 'clear-color':
498
- this.clearColor = parseColor(newValue);
499
- break;
500
- case 'clear-color-buffer':
501
- this.clearColorBuffer = newValue !== 'false';
502
- break;
503
- case 'clear-depth-buffer':
504
- this.clearDepthBuffer = newValue !== 'false';
505
- break;
506
- case 'clear-stencil-buffer':
507
- this.clearStencilBuffer = newValue !== 'false';
508
- break;
509
- case 'cull-faces':
510
- this.cullFaces = newValue !== 'false';
511
- break;
512
- case 'far-clip':
513
- this.farClip = parseFloat(newValue);
514
- break;
515
- case 'flip-faces':
516
- this.flipFaces = newValue !== 'true';
517
- break;
518
- case 'fov':
519
- this.fov = parseFloat(newValue);
520
- break;
521
- case 'frustum-culling':
522
- this.frustumCulling = newValue !== 'false';
523
- break;
524
- case 'gamma':
525
- this.gamma = newValue as 'linear' | 'srgb';
526
- break;
527
- case 'horizontal-fov':
528
- this.horizontalFov = this.hasAttribute('horizontal-fov');
529
- break;
530
- case 'near-clip':
531
- this.nearClip = parseFloat(newValue);
532
- break;
533
- case 'orthographic':
534
- this.orthographic = this.hasAttribute('orthographic');
535
- break;
536
- case 'ortho-height':
537
- this.orthoHeight = parseFloat(newValue);
538
- break;
539
- case 'priority':
540
- this.priority = parseFloat(newValue);
541
- break;
542
- case 'rect':
543
- this.rect = parseVec4(newValue);
544
- break;
545
- case 'scissor-rect':
546
- this.scissorRect = parseVec4(newValue);
547
- break;
548
- case 'tonemap':
549
- this.tonemap = newValue as 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral';
550
- break;
551
- }
552
- }
553
- }
554
-
555
- customElements.define('pc-camera', CameraComponentElement);
556
-
557
- export { CameraComponentElement };
1
+ import { CameraComponent, Color, Vec4, GAMMA_NONE, GAMMA_SRGB, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, TONEMAP_LINEAR, TONEMAP_FILMIC, TONEMAP_NEUTRAL, TONEMAP_ACES2, TONEMAP_ACES, TONEMAP_HEJL, TONEMAP_NONE, XRTYPE_VR } from 'playcanvas';
2
+
3
+ import { ComponentElement } from './component';
4
+ import { parseColor, parseVec4 } from '../utils';
5
+
6
+ const tonemaps = new Map([
7
+ ['none', TONEMAP_NONE],
8
+ ['linear', TONEMAP_LINEAR],
9
+ ['filmic', TONEMAP_FILMIC],
10
+ ['hejl', TONEMAP_HEJL],
11
+ ['aces', TONEMAP_ACES],
12
+ ['aces2', TONEMAP_ACES2],
13
+ ['neutral', TONEMAP_NEUTRAL]
14
+ ]);
15
+
16
+ /**
17
+ * The CameraComponentElement interface provides properties and methods for manipulating
18
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
19
+ * The CameraComponentElement interface also inherits the properties and methods of the
20
+ * {@link HTMLElement} interface.
21
+ *
22
+ * @category Components
23
+ */
24
+ class CameraComponentElement extends ComponentElement {
25
+ private _clearColor = new Color(0.75, 0.75, 0.75, 1);
26
+
27
+ private _clearColorBuffer = true;
28
+
29
+ private _clearDepthBuffer = true;
30
+
31
+ private _clearStencilBuffer = false;
32
+
33
+ private _cullFaces = true;
34
+
35
+ private _farClip = 1000;
36
+
37
+ private _flipFaces = false;
38
+
39
+ private _fov = 45;
40
+
41
+ private _frustumCulling = true;
42
+
43
+ private _gamma: 'linear' | 'srgb' = 'srgb';
44
+
45
+ private _horizontalFov = false;
46
+
47
+ private _nearClip = 0.1;
48
+
49
+ private _orthographic = false;
50
+
51
+ private _orthoHeight = 10;
52
+
53
+ private _priority = 0;
54
+
55
+ private _rect = new Vec4(0, 0, 1, 1);
56
+
57
+ private _scissorRect = new Vec4(0, 0, 1, 1);
58
+
59
+ private _tonemap: 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral' = 'none';
60
+
61
+ /** @ignore */
62
+ constructor() {
63
+ super('camera');
64
+ }
65
+
66
+ getInitialComponentData() {
67
+ return {
68
+ clearColor: this._clearColor,
69
+ clearColorBuffer: this._clearColorBuffer,
70
+ clearDepthBuffer: this._clearDepthBuffer,
71
+ clearStencilBuffer: this._clearStencilBuffer,
72
+ cullFaces: this._cullFaces,
73
+ farClip: this._farClip,
74
+ flipFaces: this._flipFaces,
75
+ fov: this._fov,
76
+ frustumCulling: this._frustumCulling,
77
+ gammaCorrection: this._gamma === 'srgb' ? GAMMA_SRGB : GAMMA_NONE,
78
+ horizontalFov: this._horizontalFov,
79
+ nearClip: this._nearClip,
80
+ orthographic: this._orthographic,
81
+ orthoHeight: this._orthoHeight,
82
+ priority: this._priority,
83
+ rect: this._rect,
84
+ scissorRect: this._scissorRect,
85
+ toneMapping: tonemaps.get(this._tonemap)
86
+ };
87
+ }
88
+
89
+ get xrAvailable() {
90
+ const xrManager = this.component?.system.app.xr;
91
+ return xrManager && xrManager.supported && xrManager.isAvailable(XRTYPE_VR);
92
+ }
93
+
94
+ /**
95
+ * Starts the camera in XR mode.
96
+ * @param type - The type of XR mode to start.
97
+ * @param space - The space to start the camera in.
98
+ */
99
+ startXr(type: 'immersive-ar' | 'immersive-vr', space: 'bounded-floor' | 'local' | 'local-floor' | 'unbounded' | 'viewer') {
100
+ if (this.component && this.xrAvailable) {
101
+ this.component.startXr(type, space, {
102
+ callback: (err: any) => {
103
+ if (err) console.error(`WebXR Immersive VR failed to start: ${err.message}`);
104
+ }
105
+ });
106
+ }
107
+ }
108
+
109
+ /**
110
+ * Ends the camera's XR mode.
111
+ */
112
+ endXr() {
113
+ if (this.component) {
114
+ this.component.endXr();
115
+ }
116
+ }
117
+
118
+ /**
119
+ * Gets the underlying PlayCanvas camera component.
120
+ * @returns The camera component.
121
+ */
122
+ get component(): CameraComponent | null {
123
+ return super.component as CameraComponent | null;
124
+ }
125
+
126
+ /**
127
+ * Sets the clear color of the camera.
128
+ * @param value - The clear color.
129
+ */
130
+ set clearColor(value) {
131
+ this._clearColor = value;
132
+ if (this.component) {
133
+ this.component.clearColor = value;
134
+ }
135
+ }
136
+
137
+ /**
138
+ * Gets the clear color of the camera.
139
+ * @returns The clear color.
140
+ */
141
+ get clearColor(): Color {
142
+ return this._clearColor;
143
+ }
144
+
145
+ /**
146
+ * Sets the clear color buffer of the camera.
147
+ * @param value - The clear color buffer.
148
+ */
149
+ set clearColorBuffer(value: boolean) {
150
+ this._clearColorBuffer = value;
151
+ if (this.component) {
152
+ this.component.clearColorBuffer = value;
153
+ }
154
+ }
155
+
156
+ /**
157
+ * Gets the clear color buffer of the camera.
158
+ * @returns The clear color buffer.
159
+ */
160
+ get clearColorBuffer(): boolean {
161
+ return this._clearColorBuffer;
162
+ }
163
+
164
+ /**
165
+ * Sets the clear depth buffer of the camera.
166
+ * @param value - The clear depth buffer.
167
+ */
168
+ set clearDepthBuffer(value: boolean) {
169
+ this._clearDepthBuffer = value;
170
+ if (this.component) {
171
+ this.component.clearDepthBuffer = value;
172
+ }
173
+ }
174
+
175
+ /**
176
+ * Gets the clear depth buffer of the camera.
177
+ * @returns The clear depth buffer.
178
+ */
179
+ get clearDepthBuffer(): boolean {
180
+ return this._clearDepthBuffer;
181
+ }
182
+
183
+ /**
184
+ * Sets the clear stencil buffer of the camera.
185
+ * @param value - The clear stencil buffer.
186
+ */
187
+ set clearStencilBuffer(value: boolean) {
188
+ this._clearStencilBuffer = value;
189
+ if (this.component) {
190
+ this.component.clearStencilBuffer = value;
191
+ }
192
+ }
193
+
194
+ /**
195
+ * Gets the clear stencil buffer of the camera.
196
+ * @returns The clear stencil buffer.
197
+ */
198
+ get clearStencilBuffer(): boolean {
199
+ return this._clearStencilBuffer;
200
+ }
201
+
202
+ /**
203
+ * Sets the cull faces of the camera.
204
+ * @param value - The cull faces.
205
+ */
206
+ set cullFaces(value: boolean) {
207
+ this._cullFaces = value;
208
+ if (this.component) {
209
+ this.component.cullFaces = value;
210
+ }
211
+ }
212
+
213
+ /**
214
+ * Gets the cull faces of the camera.
215
+ * @returns The cull faces.
216
+ */
217
+ get cullFaces(): boolean {
218
+ return this._cullFaces;
219
+ }
220
+
221
+ /**
222
+ * Sets the far clip distance of the camera.
223
+ * @param value - The far clip distance.
224
+ */
225
+ set farClip(value: number) {
226
+ this._farClip = value;
227
+ if (this.component) {
228
+ this.component.farClip = value;
229
+ }
230
+ }
231
+
232
+ /**
233
+ * Gets the far clip distance of the camera.
234
+ * @returns The far clip distance.
235
+ */
236
+ get farClip(): number {
237
+ return this._farClip;
238
+ }
239
+
240
+ /**
241
+ * Sets the flip faces of the camera.
242
+ * @param value - The flip faces.
243
+ */
244
+ set flipFaces(value: boolean) {
245
+ this._flipFaces = value;
246
+ if (this.component) {
247
+ this.component.flipFaces = value;
248
+ }
249
+ }
250
+
251
+ /**
252
+ * Gets the flip faces of the camera.
253
+ * @returns The flip faces.
254
+ */
255
+ get flipFaces(): boolean {
256
+ return this._flipFaces;
257
+ }
258
+
259
+ /**
260
+ * Sets the field of view of the camera.
261
+ * @param value - The field of view.
262
+ */
263
+ set fov(value: number) {
264
+ this._fov = value;
265
+ if (this.component) {
266
+ this.component.fov = value;
267
+ }
268
+ }
269
+
270
+ /**
271
+ * Gets the field of view of the camera.
272
+ * @returns The field of view.
273
+ */
274
+ get fov(): number {
275
+ return this._fov;
276
+ }
277
+
278
+ /**
279
+ * Sets the frustum culling of the camera.
280
+ * @param value - The frustum culling.
281
+ */
282
+ set frustumCulling(value: boolean) {
283
+ this._frustumCulling = value;
284
+ if (this.component) {
285
+ this.component.frustumCulling = value;
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Gets the frustum culling of the camera.
291
+ * @returns The frustum culling.
292
+ */
293
+ get frustumCulling(): boolean {
294
+ return this._frustumCulling;
295
+ }
296
+
297
+ /**
298
+ * Sets the gamma correction of the camera.
299
+ * @param value - The gamma correction.
300
+ */
301
+ set gamma(value: 'linear' | 'srgb') {
302
+ this._gamma = value;
303
+ if (this.component) {
304
+ this.component.gammaCorrection = value === 'srgb' ? GAMMA_SRGB : GAMMA_NONE;
305
+ }
306
+ }
307
+
308
+ /**
309
+ * Gets the gamma correction of the camera.
310
+ * @returns The gamma correction.
311
+ */
312
+ get gamma(): 'linear' | 'srgb' {
313
+ return this._gamma;
314
+ }
315
+
316
+ /**
317
+ * Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
318
+ * (meaning it is vertical be default).
319
+ * @param value - Whether the camera's field of view is horizontal.
320
+ */
321
+ set horizontalFov(value: boolean) {
322
+ this._horizontalFov = value;
323
+ if (this.component) {
324
+ this.component.horizontalFov = value;
325
+ }
326
+ }
327
+
328
+ /**
329
+ * Gets whether the camera's field of view (fov) is horizontal or vertical.
330
+ * @returns Whether the camera's field of view is horizontal.
331
+ */
332
+ get horizontalFov(): boolean {
333
+ return this._horizontalFov;
334
+ }
335
+
336
+ /**
337
+ * Sets the near clip distance of the camera.
338
+ * @param value - The near clip distance.
339
+ */
340
+ set nearClip(value: number) {
341
+ this._nearClip = value;
342
+ if (this.component) {
343
+ this.component.nearClip = value;
344
+ }
345
+ }
346
+
347
+ /**
348
+ * Gets the near clip distance of the camera.
349
+ * @returns The near clip distance.
350
+ */
351
+ get nearClip(): number {
352
+ return this._nearClip;
353
+ }
354
+
355
+ /**
356
+ * Sets the orthographic projection of the camera.
357
+ * @param value - The orthographic projection.
358
+ */
359
+ set orthographic(value) {
360
+ this._orthographic = value;
361
+ if (this.component) {
362
+ this.component.projection = value ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE;
363
+ }
364
+ }
365
+
366
+ /**
367
+ * Gets the orthographic projection of the camera.
368
+ * @returns The orthographic projection.
369
+ */
370
+ get orthographic(): boolean {
371
+ return this._orthographic;
372
+ }
373
+
374
+ /**
375
+ * Sets the orthographic height of the camera.
376
+ * @param value - The orthographic height.
377
+ */
378
+ set orthoHeight(value: number) {
379
+ this._orthoHeight = value;
380
+ if (this.component) {
381
+ this.component.orthoHeight = value;
382
+ }
383
+ }
384
+
385
+ /**
386
+ * Gets the orthographic height of the camera.
387
+ * @returns The orthographic height.
388
+ */
389
+ get orthoHeight() {
390
+ return this._orthoHeight;
391
+ }
392
+
393
+ /**
394
+ * Sets the priority of the camera.
395
+ * @param value - The priority.
396
+ */
397
+ set priority(value: number) {
398
+ this._priority = value;
399
+ if (this.component) {
400
+ this.component.priority = value;
401
+ }
402
+ }
403
+
404
+ /**
405
+ * Gets the priority of the camera.
406
+ * @returns The priority.
407
+ */
408
+ get priority(): number {
409
+ return this._priority;
410
+ }
411
+
412
+ /**
413
+ * Sets the rect of the camera.
414
+ * @param value - The rect.
415
+ */
416
+ set rect(value: Vec4) {
417
+ this._rect = value;
418
+ if (this.component) {
419
+ this.component.rect = value;
420
+ }
421
+ }
422
+
423
+ /**
424
+ * Gets the rect of the camera.
425
+ * @returns The rect.
426
+ */
427
+ get rect(): Vec4 {
428
+ return this._rect;
429
+ }
430
+
431
+ /**
432
+ * Sets the scissor rect of the camera.
433
+ * @param value - The scissor rect.
434
+ */
435
+ set scissorRect(value: Vec4) {
436
+ this._scissorRect = value;
437
+ if (this.component) {
438
+ this.component.scissorRect = value;
439
+ }
440
+ }
441
+
442
+ /**
443
+ * Gets the scissor rect of the camera.
444
+ * @returns The scissor rect.
445
+ */
446
+ get scissorRect(): Vec4 {
447
+ return this._scissorRect;
448
+ }
449
+
450
+ /**
451
+ * Sets the tone mapping of the camera.
452
+ * @param value - The tone mapping.
453
+ */
454
+ set tonemap(value: 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral') {
455
+ this._tonemap = value;
456
+ if (this.component) {
457
+ this.component.toneMapping = tonemaps.get(value) ?? TONEMAP_NONE;
458
+ }
459
+ }
460
+
461
+ /**
462
+ * Gets the tone mapping of the camera.
463
+ * @returns The tone mapping.
464
+ */
465
+ get tonemap(): 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral' {
466
+ return this._tonemap;
467
+ }
468
+
469
+ static get observedAttributes() {
470
+ return [
471
+ ...super.observedAttributes,
472
+ 'clear-color',
473
+ 'clear-color-buffer',
474
+ 'clear-depth-buffer',
475
+ 'clear-stencil-buffer',
476
+ 'cull-faces',
477
+ 'far-clip',
478
+ 'flip-faces',
479
+ 'fov',
480
+ 'frustum-culling',
481
+ 'gamma',
482
+ 'horizontal-fov',
483
+ 'near-clip',
484
+ 'orthographic',
485
+ 'ortho-height',
486
+ 'priority',
487
+ 'rect',
488
+ 'scissor-rect',
489
+ 'tonemap'
490
+ ];
491
+ }
492
+
493
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
494
+ super.attributeChangedCallback(name, _oldValue, newValue);
495
+
496
+ switch (name) {
497
+ case 'clear-color':
498
+ this.clearColor = parseColor(newValue);
499
+ break;
500
+ case 'clear-color-buffer':
501
+ this.clearColorBuffer = newValue !== 'false';
502
+ break;
503
+ case 'clear-depth-buffer':
504
+ this.clearDepthBuffer = newValue !== 'false';
505
+ break;
506
+ case 'clear-stencil-buffer':
507
+ this.clearStencilBuffer = newValue !== 'false';
508
+ break;
509
+ case 'cull-faces':
510
+ this.cullFaces = newValue !== 'false';
511
+ break;
512
+ case 'far-clip':
513
+ this.farClip = parseFloat(newValue);
514
+ break;
515
+ case 'flip-faces':
516
+ this.flipFaces = newValue !== 'true';
517
+ break;
518
+ case 'fov':
519
+ this.fov = parseFloat(newValue);
520
+ break;
521
+ case 'frustum-culling':
522
+ this.frustumCulling = newValue !== 'false';
523
+ break;
524
+ case 'gamma':
525
+ this.gamma = newValue as 'linear' | 'srgb';
526
+ break;
527
+ case 'horizontal-fov':
528
+ this.horizontalFov = this.hasAttribute('horizontal-fov');
529
+ break;
530
+ case 'near-clip':
531
+ this.nearClip = parseFloat(newValue);
532
+ break;
533
+ case 'orthographic':
534
+ this.orthographic = this.hasAttribute('orthographic');
535
+ break;
536
+ case 'ortho-height':
537
+ this.orthoHeight = parseFloat(newValue);
538
+ break;
539
+ case 'priority':
540
+ this.priority = parseFloat(newValue);
541
+ break;
542
+ case 'rect':
543
+ this.rect = parseVec4(newValue);
544
+ break;
545
+ case 'scissor-rect':
546
+ this.scissorRect = parseVec4(newValue);
547
+ break;
548
+ case 'tonemap':
549
+ this.tonemap = newValue as 'none' | 'linear' | 'filmic' | 'hejl' | 'aces' | 'aces2' | 'neutral';
550
+ break;
551
+ }
552
+ }
553
+ }
554
+
555
+ customElements.define('pc-camera', CameraComponentElement);
556
+
557
+ export { CameraComponentElement };