@playcanvas/web-components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/pwc.js ADDED
@@ -0,0 +1,2513 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('playcanvas')) :
3
+ typeof define === 'function' && define.amd ? define(['exports', 'playcanvas'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.pd = {}, global.pc));
5
+ })(this, (function (exports, playcanvas) { 'use strict';
6
+
7
+ class ModuleElement extends HTMLElement {
8
+ constructor() {
9
+ super();
10
+ this.loadPromise = this.loadModule();
11
+ }
12
+ async loadModule() {
13
+ const name = this.getAttribute('name');
14
+ const glue = this.getAttribute('glue');
15
+ const wasm = this.getAttribute('wasm');
16
+ const fallback = this.getAttribute('fallback');
17
+ playcanvas.WasmModule.setConfig(name, {
18
+ glueUrl: glue,
19
+ wasmUrl: wasm,
20
+ fallbackUrl: fallback
21
+ });
22
+ await new Promise((resolve) => {
23
+ playcanvas.WasmModule.getInstance(name, () => resolve());
24
+ });
25
+ }
26
+ getLoadPromise() {
27
+ return this.loadPromise;
28
+ }
29
+ }
30
+ customElements.define('pc-module', ModuleElement);
31
+
32
+ /**
33
+ * The main application element.
34
+ */
35
+ class AppElement extends HTMLElement {
36
+ /**
37
+ * Creates a new AppElement.
38
+ */
39
+ constructor() {
40
+ super();
41
+ /**
42
+ * The canvas element.
43
+ */
44
+ this._canvas = null;
45
+ this._highResolution = false;
46
+ /**
47
+ * The PlayCanvas application instance.
48
+ */
49
+ this.app = null;
50
+ // Bind methods to maintain 'this' context
51
+ this._onWindowResize = this._onWindowResize.bind(this);
52
+ this.appReadyPromise = new Promise((resolve) => {
53
+ this.appReadyResolve = resolve;
54
+ });
55
+ }
56
+ async connectedCallback() {
57
+ // Get all pc-module elements that are direct children of the pc-app element
58
+ const moduleElements = this.querySelectorAll(':scope > pc-module');
59
+ // Wait for all modules to load
60
+ await Promise.all(Array.from(moduleElements).map(module => module.getLoadPromise()));
61
+ // Create and append the canvas to the element
62
+ this._canvas = document.createElement('canvas');
63
+ this.appendChild(this._canvas);
64
+ // Initialize the PlayCanvas application
65
+ this.app = new playcanvas.Application(this._canvas, {
66
+ graphicsDeviceOptions: {
67
+ devicePixelRatio: this._highResolution ? window.devicePixelRatio : 1
68
+ },
69
+ keyboard: new playcanvas.Keyboard(window),
70
+ mouse: new playcanvas.Mouse(this._canvas)
71
+ });
72
+ this.app.setCanvasFillMode(playcanvas.FILLMODE_FILL_WINDOW);
73
+ this.app.setCanvasResolution(playcanvas.RESOLUTION_AUTO);
74
+ // Get all pc-asset elements that are direct children of the pc-app element
75
+ const assetElements = this.querySelectorAll(':scope > pc-asset');
76
+ Array.from(assetElements).forEach((assetElement) => {
77
+ assetElement.createAsset();
78
+ const asset = assetElement.asset;
79
+ if (asset) {
80
+ this.app.assets.add(asset);
81
+ }
82
+ });
83
+ // Load assets before starting the application
84
+ this.app.preload(() => {
85
+ // Start the application
86
+ this.app.start();
87
+ // Handle window resize to keep the canvas responsive
88
+ window.addEventListener('resize', this._onWindowResize);
89
+ this.appReadyResolve(this.app);
90
+ });
91
+ }
92
+ disconnectedCallback() {
93
+ // Clean up the application
94
+ if (this.app) {
95
+ this.app.destroy();
96
+ this.app = null;
97
+ }
98
+ // Remove event listeners
99
+ window.removeEventListener('resize', this._onWindowResize);
100
+ // Remove the canvas
101
+ if (this._canvas && this.contains(this._canvas)) {
102
+ this.removeChild(this._canvas);
103
+ this._canvas = null;
104
+ }
105
+ }
106
+ async getApplication() {
107
+ await this.appReadyPromise;
108
+ return this.app;
109
+ }
110
+ _onWindowResize() {
111
+ if (this.app) {
112
+ this.app.resizeCanvas();
113
+ }
114
+ }
115
+ set highResolution(value) {
116
+ this._highResolution = value;
117
+ if (this.app) {
118
+ this.app.graphicsDevice.maxPixelRatio = value ? window.devicePixelRatio : 1;
119
+ }
120
+ }
121
+ get highResolution() {
122
+ return this._highResolution;
123
+ }
124
+ static get observedAttributes() {
125
+ return ['high-resolution'];
126
+ }
127
+ attributeChangedCallback(name, _oldValue, _newValue) {
128
+ switch (name) {
129
+ case 'high-resolution':
130
+ this.highResolution = this.hasAttribute(name);
131
+ break;
132
+ }
133
+ }
134
+ }
135
+ customElements.define('pc-app', AppElement);
136
+
137
+ /**
138
+ * Parse a color string into a Color object. String can be in the format of '#rgb', '#rgba',
139
+ * '#rrggbb', '#rrggbbaa', or a string of 3 or 4 comma-delimited numbers.
140
+ *
141
+ * @param value - The color string to parse.
142
+ * @returns The parsed Color object.
143
+ */
144
+ const parseColor = (value) => {
145
+ if (value.startsWith('#')) {
146
+ return new playcanvas.Color().fromString(value);
147
+ }
148
+ const components = value.split(',').map(Number);
149
+ return new playcanvas.Color(components);
150
+ };
151
+ /**
152
+ * Parse a Vec2 string into a Vec2 object. String can be in the format of 'x,y'.
153
+ *
154
+ * @param value - The Vec2 string to parse.
155
+ * @returns The parsed Vec2 object.
156
+ */
157
+ const parseVec2 = (value) => {
158
+ const components = value.split(',').map(Number);
159
+ return new playcanvas.Vec2(components);
160
+ };
161
+ /**
162
+ * Parse a Vec3 string into a Vec3 object. String can be in the format of 'x,y,z'.
163
+ *
164
+ * @param value - The Vec3 string to parse.
165
+ * @returns The parsed Vec3 object.
166
+ */
167
+ const parseVec3 = (value) => {
168
+ const components = value.split(',').map(Number);
169
+ return new playcanvas.Vec3(components);
170
+ };
171
+ /**
172
+ * Parse a Vec4 string into a Vec4 object. String can be in the format of 'x,y,z,w'.
173
+ *
174
+ * @param value - The Vec4 string to parse.
175
+ * @returns The parsed Vec4 object.
176
+ */
177
+ const parseVec4 = (value) => {
178
+ const components = value.split(',').map(Number);
179
+ return new playcanvas.Vec4(components);
180
+ };
181
+
182
+ /**
183
+ * Represents an entity in the PlayCanvas engine.
184
+ */
185
+ class EntityElement extends HTMLElement {
186
+ constructor() {
187
+ super(...arguments);
188
+ /**
189
+ * Whether the entity is enabled.
190
+ */
191
+ this._enabled = true;
192
+ /**
193
+ * The name of the entity.
194
+ */
195
+ this._name = 'Untitled';
196
+ /**
197
+ * The position of the entity.
198
+ */
199
+ this._position = new playcanvas.Vec3();
200
+ /**
201
+ * The rotation of the entity.
202
+ */
203
+ this._rotation = new playcanvas.Vec3();
204
+ /**
205
+ * The scale of the entity.
206
+ */
207
+ this._scale = new playcanvas.Vec3(1, 1, 1);
208
+ /**
209
+ * The tags of the entity.
210
+ */
211
+ this._tags = [];
212
+ /**
213
+ * The PlayCanvas entity instance.
214
+ */
215
+ this.entity = null;
216
+ }
217
+ async connectedCallback() {
218
+ // Get the application
219
+ const appElement = this.closest('pc-app');
220
+ if (!appElement) {
221
+ console.warn(`${this.tagName} must be a child of pc-app`);
222
+ return;
223
+ }
224
+ const app = await appElement.getApplication();
225
+ // Create a new entity
226
+ this.entity = new playcanvas.Entity(this._name, app);
227
+ if (this.parentElement && this.parentElement.tagName === 'pc-entity' && this.parentElement.entity) {
228
+ this.parentElement.entity.addChild(this.entity);
229
+ }
230
+ else {
231
+ app.root.addChild(this.entity);
232
+ }
233
+ // Initialize from attributes
234
+ const nameAttr = this.getAttribute('name');
235
+ const positionAttr = this.getAttribute('position');
236
+ const rotationAttr = this.getAttribute('rotation');
237
+ const scaleAttr = this.getAttribute('scale');
238
+ const tagsAttr = this.getAttribute('tags');
239
+ if (nameAttr)
240
+ this.name = nameAttr;
241
+ if (positionAttr)
242
+ this.position = parseVec3(positionAttr);
243
+ if (rotationAttr)
244
+ this.rotation = parseVec3(rotationAttr);
245
+ if (scaleAttr)
246
+ this.scale = parseVec3(scaleAttr);
247
+ if (tagsAttr)
248
+ this.tags = tagsAttr.split(',').map(tag => tag.trim());
249
+ }
250
+ disconnectedCallback() {
251
+ if (this.entity) {
252
+ this.entity.destroy();
253
+ this.entity = null;
254
+ }
255
+ }
256
+ /**
257
+ * Sets the enabled state of the entity.
258
+ * @param value - Whether the entity is enabled.
259
+ */
260
+ set enabled(value) {
261
+ this._enabled = value;
262
+ if (this.entity) {
263
+ this.entity.enabled = value;
264
+ }
265
+ }
266
+ /**
267
+ * Gets the enabled state of the entity.
268
+ * @returns Whether the entity is enabled.
269
+ */
270
+ get enabled() {
271
+ return this._enabled;
272
+ }
273
+ /**
274
+ * Sets the name of the entity.
275
+ * @param value - The name of the entity.
276
+ */
277
+ set name(value) {
278
+ this._name = value;
279
+ if (this.entity) {
280
+ this.entity.name = value;
281
+ }
282
+ }
283
+ /**
284
+ * Gets the name of the entity.
285
+ * @returns The name of the entity.
286
+ */
287
+ get name() {
288
+ return this._name;
289
+ }
290
+ /**
291
+ * Sets the position of the entity.
292
+ * @param value - The position of the entity.
293
+ */
294
+ set position(value) {
295
+ this._position = value;
296
+ if (this.entity) {
297
+ this.entity.setLocalPosition(this._position);
298
+ }
299
+ }
300
+ /**
301
+ * Gets the position of the entity.
302
+ * @returns The position of the entity.
303
+ */
304
+ get position() {
305
+ return this._position;
306
+ }
307
+ /**
308
+ * Sets the rotation of the entity.
309
+ * @param value - The rotation of the entity.
310
+ */
311
+ set rotation(value) {
312
+ this._rotation = value;
313
+ if (this.entity) {
314
+ this.entity.setLocalEulerAngles(this._rotation);
315
+ }
316
+ }
317
+ /**
318
+ * Gets the rotation of the entity.
319
+ * @returns The rotation of the entity.
320
+ */
321
+ get rotation() {
322
+ return this._rotation;
323
+ }
324
+ /**
325
+ * Sets the scale of the entity.
326
+ * @param value - The scale of the entity.
327
+ */
328
+ set scale(value) {
329
+ this._scale = value;
330
+ if (this.entity) {
331
+ this.entity.setLocalScale(this._scale);
332
+ }
333
+ }
334
+ /**
335
+ * Gets the scale of the entity.
336
+ * @returns The scale of the entity.
337
+ */
338
+ get scale() {
339
+ return this._scale;
340
+ }
341
+ /**
342
+ * Sets the tags of the entity.
343
+ * @param value - The tags of the entity.
344
+ */
345
+ set tags(value) {
346
+ this._tags = value;
347
+ if (this.entity) {
348
+ this.entity.tags.clear();
349
+ this.entity.tags.add(this._tags);
350
+ }
351
+ }
352
+ /**
353
+ * Gets the tags of the entity.
354
+ * @returns The tags of the entity.
355
+ */
356
+ get tags() {
357
+ return this._tags;
358
+ }
359
+ static get observedAttributes() {
360
+ return ['enabled', 'name', 'position', 'rotation', 'scale', 'tags'];
361
+ }
362
+ attributeChangedCallback(name, _oldValue, newValue) {
363
+ switch (name) {
364
+ case 'enabled':
365
+ this.enabled = newValue !== 'false';
366
+ break;
367
+ case 'name':
368
+ this.name = newValue;
369
+ break;
370
+ case 'position':
371
+ this.position = parseVec3(newValue);
372
+ break;
373
+ case 'rotation':
374
+ this.rotation = parseVec3(newValue);
375
+ break;
376
+ case 'scale':
377
+ this.scale = parseVec3(newValue);
378
+ break;
379
+ case 'tags':
380
+ this.tags = newValue.split(',').map(tag => tag.trim());
381
+ break;
382
+ }
383
+ }
384
+ }
385
+ customElements.define('pc-entity', EntityElement);
386
+
387
+ const extToType = new Map([
388
+ ['bin', 'binary'],
389
+ ['css', 'css'],
390
+ ['frag', 'shader'],
391
+ ['glb', 'container'],
392
+ ['glsl', 'shader'],
393
+ ['html', 'html'],
394
+ ['jpg', 'texture'],
395
+ ['js', 'script'],
396
+ ['json', 'json'],
397
+ ['mp3', 'audio'],
398
+ ['mjs', 'script'],
399
+ ['ply', 'gsplat'],
400
+ ['png', 'texture'],
401
+ ['txt', 'text'],
402
+ ['vert', 'shader'],
403
+ ['webp', 'texture']
404
+ ]);
405
+ /**
406
+ * Loads an asset into the PlayCanvas engine.
407
+ */
408
+ class AssetElement extends HTMLElement {
409
+ constructor() {
410
+ super(...arguments);
411
+ this._preload = false;
412
+ /**
413
+ * The asset that is loaded.
414
+ */
415
+ this.asset = null;
416
+ }
417
+ async connectedCallback() {
418
+ }
419
+ disconnectedCallback() {
420
+ this.destroyAsset();
421
+ }
422
+ createAsset() {
423
+ var _a;
424
+ const id = this.getAttribute('id') || '';
425
+ const src = this.getAttribute('src') || '';
426
+ let type = this.getAttribute('type');
427
+ // If no type is specified, try to infer it from the file extension.
428
+ if (!type) {
429
+ const ext = src.split('.').pop();
430
+ type = (_a = extToType.get(ext || '')) !== null && _a !== void 0 ? _a : null;
431
+ }
432
+ if (!type) {
433
+ console.warn(`Unsupported asset type: ${src}`);
434
+ return;
435
+ }
436
+ this.asset = new playcanvas.Asset(id, type, { url: src });
437
+ this.asset.preload = this.preload;
438
+ }
439
+ destroyAsset() {
440
+ if (this.asset) {
441
+ this.asset.unload();
442
+ this.asset = null;
443
+ }
444
+ }
445
+ /**
446
+ * Sets the preload flag of the asset.
447
+ * @param value - The preload flag.
448
+ */
449
+ set preload(value) {
450
+ this._preload = value;
451
+ if (this.asset) {
452
+ this.asset.preload = value;
453
+ }
454
+ }
455
+ /**
456
+ * Gets the preload flag of the asset.
457
+ * @returns The preload flag.
458
+ */
459
+ get preload() {
460
+ return this._preload;
461
+ }
462
+ static get observedAttributes() {
463
+ return ['preload'];
464
+ }
465
+ attributeChangedCallback(name, _oldValue, _newValue) {
466
+ if (name === 'preload') {
467
+ this.preload = this.hasAttribute('preload');
468
+ }
469
+ }
470
+ }
471
+ customElements.define('pc-asset', AssetElement);
472
+
473
+ /**
474
+ * Represents a component in the PlayCanvas engine.
475
+ *
476
+ * @category Components
477
+ */
478
+ class ComponentElement extends HTMLElement {
479
+ /**
480
+ * Constructor for the ComponentElement.
481
+ * @param componentName - The name of the component.
482
+ */
483
+ constructor(componentName) {
484
+ super();
485
+ this._enabled = true;
486
+ this._component = null;
487
+ this._componentName = componentName;
488
+ }
489
+ // Method to be overridden by subclasses to provide initial component data
490
+ getInitialComponentData() {
491
+ return {};
492
+ }
493
+ async connectedCallback() {
494
+ const appElement = this.closest('pc-app');
495
+ if (!appElement) {
496
+ console.error(`${this.tagName.toLowerCase()} should be a descendant of pc-app`);
497
+ return;
498
+ }
499
+ await appElement.getApplication();
500
+ this.addComponent();
501
+ }
502
+ addComponent() {
503
+ // Access the parent pc-entity's 'entity' property
504
+ const entityElement = this.closest('pc-entity');
505
+ if (!entityElement) {
506
+ console.error(`${this.tagName.toLowerCase()} should be a child of pc-entity`);
507
+ return;
508
+ }
509
+ if (entityElement && entityElement.entity) {
510
+ // Add the component to the entity
511
+ this._component = entityElement.entity.addComponent(this._componentName, this.getInitialComponentData());
512
+ }
513
+ }
514
+ disconnectedCallback() {
515
+ // Remove the component when the element is disconnected
516
+ if (this.component && this.component.entity) {
517
+ this._component.entity.removeComponent(this._componentName);
518
+ this._component = null;
519
+ }
520
+ }
521
+ get component() {
522
+ return this._component;
523
+ }
524
+ /**
525
+ * Sets the enabled state of the component.
526
+ * @param value - The enabled state of the component.
527
+ */
528
+ set enabled(value) {
529
+ this._enabled = value;
530
+ if (this.component) {
531
+ this.component.enabled = value;
532
+ }
533
+ }
534
+ /**
535
+ * Gets the enabled state of the component.
536
+ * @returns The enabled state of the component.
537
+ */
538
+ get enabled() {
539
+ return this._enabled;
540
+ }
541
+ static get observedAttributes() {
542
+ return ['enabled'];
543
+ }
544
+ attributeChangedCallback(name, _oldValue, newValue) {
545
+ switch (name) {
546
+ case 'enabled':
547
+ this.enabled = newValue !== 'false';
548
+ break;
549
+ }
550
+ }
551
+ }
552
+
553
+ /**
554
+ * Represents a audio listener component in the PlayCanvas engine.
555
+ *
556
+ * @category Components
557
+ */
558
+ class ListenerComponentElement extends ComponentElement {
559
+ constructor() {
560
+ super('audiolistener');
561
+ }
562
+ /**
563
+ * Gets the audio listener component.
564
+ * @returns The audio listener component.
565
+ */
566
+ get component() {
567
+ return super.component;
568
+ }
569
+ }
570
+ customElements.define('pc-listener', ListenerComponentElement);
571
+
572
+ /**
573
+ * Represents a camera component in the PlayCanvas engine.
574
+ *
575
+ * @category Components
576
+ */
577
+ class CameraComponentElement extends ComponentElement {
578
+ /**
579
+ * Creates a new CameraComponentElement.
580
+ */
581
+ constructor() {
582
+ super('camera');
583
+ this._clearColor = new playcanvas.Color(1, 1, 1, 1);
584
+ this._farClip = 1000;
585
+ this._fov = 45;
586
+ this._nearClip = 0.1;
587
+ this._orthographic = false;
588
+ this._orthoHeight = 10;
589
+ }
590
+ getInitialComponentData() {
591
+ return {
592
+ clearColor: this._clearColor,
593
+ farClip: this._farClip,
594
+ fov: this._fov,
595
+ nearClip: this._nearClip,
596
+ projection: this._orthographic ? playcanvas.PROJECTION_ORTHOGRAPHIC : playcanvas.PROJECTION_PERSPECTIVE,
597
+ orthoHeight: this._orthoHeight
598
+ };
599
+ }
600
+ /**
601
+ * Gets the camera component.
602
+ * @returns The camera component.
603
+ */
604
+ get component() {
605
+ return super.component;
606
+ }
607
+ /**
608
+ * Sets the clear color of the camera.
609
+ * @param value - The clear color.
610
+ */
611
+ set clearColor(value) {
612
+ this._clearColor = value;
613
+ if (this.component) {
614
+ this.component.clearColor = value;
615
+ }
616
+ }
617
+ /**
618
+ * Gets the clear color of the camera.
619
+ * @returns The clear color.
620
+ */
621
+ get clearColor() {
622
+ return this._clearColor;
623
+ }
624
+ /**
625
+ * Sets the far clip distance of the camera.
626
+ * @param value - The far clip distance.
627
+ */
628
+ set farClip(value) {
629
+ this._farClip = value;
630
+ if (this.component) {
631
+ this.component.farClip = value;
632
+ }
633
+ }
634
+ /**
635
+ * Gets the far clip distance of the camera.
636
+ * @returns The far clip distance.
637
+ */
638
+ get farClip() {
639
+ return this._farClip;
640
+ }
641
+ /**
642
+ * Sets the field of view of the camera.
643
+ * @param value - The field of view.
644
+ */
645
+ set fov(value) {
646
+ this._fov = value;
647
+ if (this.component) {
648
+ this.component.fov = value;
649
+ }
650
+ }
651
+ /**
652
+ * Gets the field of view of the camera.
653
+ * @returns The field of view.
654
+ */
655
+ get fov() {
656
+ return this._fov;
657
+ }
658
+ /**
659
+ * Sets the near clip distance of the camera.
660
+ * @param value - The near clip distance.
661
+ */
662
+ set nearClip(value) {
663
+ this._nearClip = value;
664
+ if (this.component) {
665
+ this.component.nearClip = value;
666
+ }
667
+ }
668
+ /**
669
+ * Gets the near clip distance of the camera.
670
+ * @returns The near clip distance.
671
+ */
672
+ get nearClip() {
673
+ return this._nearClip;
674
+ }
675
+ /**
676
+ * Sets the orthographic projection of the camera.
677
+ * @param value - The orthographic projection.
678
+ */
679
+ set orthographic(value) {
680
+ this._orthographic = value;
681
+ if (this.component) {
682
+ this.component.projection = value ? playcanvas.PROJECTION_ORTHOGRAPHIC : playcanvas.PROJECTION_PERSPECTIVE;
683
+ }
684
+ }
685
+ /**
686
+ * Gets the orthographic projection of the camera.
687
+ * @returns The orthographic projection.
688
+ */
689
+ get orthographic() {
690
+ return this._orthographic;
691
+ }
692
+ /**
693
+ * Sets the orthographic height of the camera.
694
+ * @param value - The orthographic height.
695
+ */
696
+ set orthoHeight(value) {
697
+ this._orthoHeight = value;
698
+ if (this.component) {
699
+ this.component.orthoHeight = value;
700
+ }
701
+ }
702
+ /**
703
+ * Gets the orthographic height of the camera.
704
+ * @returns The orthographic height.
705
+ */
706
+ get orthoHeight() {
707
+ return this._orthoHeight;
708
+ }
709
+ static get observedAttributes() {
710
+ return [...super.observedAttributes, 'clear-color', 'near-clip', 'far-clip', 'fov', 'orthographic', 'ortho-height'];
711
+ }
712
+ attributeChangedCallback(name, _oldValue, newValue) {
713
+ super.attributeChangedCallback(name, _oldValue, newValue);
714
+ switch (name) {
715
+ case 'clear-color':
716
+ this.clearColor = parseColor(newValue);
717
+ break;
718
+ case 'far-clip':
719
+ this.farClip = parseFloat(newValue);
720
+ break;
721
+ case 'fov':
722
+ this.fov = parseFloat(newValue);
723
+ break;
724
+ case 'near-clip':
725
+ this.nearClip = parseFloat(newValue);
726
+ break;
727
+ case 'orthographic':
728
+ this.orthographic = this.hasAttribute('orthographic');
729
+ break;
730
+ case 'ortho-height':
731
+ this.orthoHeight = parseFloat(newValue);
732
+ break;
733
+ }
734
+ }
735
+ }
736
+ customElements.define('pc-camera', CameraComponentElement);
737
+
738
+ /**
739
+ * Represents a collision component in the PlayCanvas engine.
740
+ *
741
+ * @category Components
742
+ */
743
+ class CollisionComponentElement extends ComponentElement {
744
+ /**
745
+ * Creates a new CollisionComponentElement.
746
+ */
747
+ constructor() {
748
+ super('collision');
749
+ this._axis = 1;
750
+ this._convexHull = false;
751
+ this._halfExtents = new playcanvas.Vec3(0.5, 0.5, 0.5);
752
+ this._height = 2;
753
+ this._radius = 0.5;
754
+ this._type = 'box';
755
+ }
756
+ getInitialComponentData() {
757
+ return {
758
+ axis: this._axis,
759
+ convexHull: this._convexHull,
760
+ halfExtents: this._halfExtents,
761
+ height: this._height,
762
+ radius: this._radius,
763
+ type: this._type
764
+ };
765
+ }
766
+ /**
767
+ * Gets the collision component.
768
+ * @returns The collision component.
769
+ */
770
+ get component() {
771
+ return super.component;
772
+ }
773
+ set axis(value) {
774
+ this._axis = value;
775
+ if (this.component) {
776
+ this.component.axis = value;
777
+ }
778
+ }
779
+ get axis() {
780
+ return this._axis;
781
+ }
782
+ set convexHull(value) {
783
+ this._convexHull = value;
784
+ if (this.component) {
785
+ this.component.convexHull = value;
786
+ }
787
+ }
788
+ get convexHull() {
789
+ return this._convexHull;
790
+ }
791
+ set halfExtents(value) {
792
+ this._halfExtents = value;
793
+ if (this.component) {
794
+ this.component.halfExtents = value;
795
+ }
796
+ }
797
+ get halfExtents() {
798
+ return this._halfExtents;
799
+ }
800
+ set height(value) {
801
+ this._height = value;
802
+ if (this.component) {
803
+ this.component.height = value;
804
+ }
805
+ }
806
+ get height() {
807
+ return this._height;
808
+ }
809
+ set radius(value) {
810
+ this._radius = value;
811
+ if (this.component) {
812
+ this.component.radius = value;
813
+ }
814
+ }
815
+ get radius() {
816
+ return this._radius;
817
+ }
818
+ set type(value) {
819
+ this._type = value;
820
+ if (this.component) {
821
+ this.component.type = value;
822
+ }
823
+ }
824
+ get type() {
825
+ return this._type;
826
+ }
827
+ static get observedAttributes() {
828
+ return [...super.observedAttributes, 'axis', 'convex-hull', 'half-extents', 'height', 'radius', 'type'];
829
+ }
830
+ attributeChangedCallback(name, _oldValue, newValue) {
831
+ super.attributeChangedCallback(name, _oldValue, newValue);
832
+ switch (name) {
833
+ case 'axis':
834
+ this.axis = parseInt(newValue, 10);
835
+ break;
836
+ case 'convex-hull':
837
+ this.convexHull = this.hasAttribute('convex-hull');
838
+ break;
839
+ case 'half-extents':
840
+ this.halfExtents = parseVec3(newValue);
841
+ break;
842
+ case 'height':
843
+ this.height = parseFloat(newValue);
844
+ break;
845
+ case 'radius':
846
+ this.radius = parseFloat(newValue);
847
+ break;
848
+ case 'type':
849
+ this.type = newValue;
850
+ break;
851
+ }
852
+ }
853
+ }
854
+ customElements.define('pc-collision', CollisionComponentElement);
855
+
856
+ /**
857
+ * Represents an element component in the PlayCanvas engine.
858
+ *
859
+ * @category Components
860
+ */
861
+ class ElementComponentElement extends ComponentElement {
862
+ constructor() {
863
+ super('element');
864
+ this._anchor = new playcanvas.Vec4(0.5, 0.5, 0.5, 0.5);
865
+ this._asset = '';
866
+ this._autoWidth = true;
867
+ this._color = new playcanvas.Color(1, 1, 1, 1);
868
+ this._fontSize = 32;
869
+ this._lineHeight = 32;
870
+ this._pivot = new playcanvas.Vec2(0.5, 0.5);
871
+ this._text = '';
872
+ this._type = 'group';
873
+ this._width = 0;
874
+ this._wrapLines = false;
875
+ }
876
+ async connectedCallback() {
877
+ await super.connectedCallback();
878
+ this.component._text._material.useFog = true;
879
+ }
880
+ getAsset() {
881
+ const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
882
+ return assetElement.asset;
883
+ }
884
+ getInitialComponentData() {
885
+ return {
886
+ anchor: this._anchor,
887
+ autoWidth: this._autoWidth,
888
+ color: this._color,
889
+ fontAsset: this.getAsset().id,
890
+ fontSize: this._fontSize,
891
+ lineHeight: this._lineHeight,
892
+ pivot: this._pivot,
893
+ type: this._type,
894
+ text: this._text,
895
+ width: this._width,
896
+ wrapLines: this._wrapLines
897
+ };
898
+ }
899
+ /**
900
+ * Gets the element component.
901
+ * @returns The element component.
902
+ */
903
+ get component() {
904
+ return super.component;
905
+ }
906
+ set anchor(value) {
907
+ this._anchor = value;
908
+ if (this.component) {
909
+ this.component.anchor = value;
910
+ }
911
+ }
912
+ get anchor() {
913
+ return this._anchor;
914
+ }
915
+ set asset(value) {
916
+ this._asset = value;
917
+ const asset = this.getAsset();
918
+ if (this.component && asset) {
919
+ this.component.fontAsset = asset.id;
920
+ }
921
+ }
922
+ get asset() {
923
+ return this._asset;
924
+ }
925
+ set autoWidth(value) {
926
+ this._autoWidth = value;
927
+ if (this.component) {
928
+ this.component.autoWidth = value;
929
+ }
930
+ }
931
+ get autoWidth() {
932
+ return this._autoWidth;
933
+ }
934
+ set color(value) {
935
+ this._color = value;
936
+ if (this.component) {
937
+ this.component.color = value;
938
+ }
939
+ }
940
+ get color() {
941
+ return this._color;
942
+ }
943
+ set fontSize(value) {
944
+ this._fontSize = value;
945
+ if (this.component) {
946
+ this.component.fontSize = value;
947
+ }
948
+ }
949
+ get fontSize() {
950
+ return this._fontSize;
951
+ }
952
+ set lineHeight(value) {
953
+ this._lineHeight = value;
954
+ if (this.component) {
955
+ this.component.lineHeight = value;
956
+ }
957
+ }
958
+ get lineHeight() {
959
+ return this._lineHeight;
960
+ }
961
+ set pivot(value) {
962
+ this._pivot = value;
963
+ if (this.component) {
964
+ this.component.pivot = value;
965
+ }
966
+ }
967
+ get pivot() {
968
+ return this._pivot;
969
+ }
970
+ set text(value) {
971
+ this._text = value;
972
+ if (this.component) {
973
+ this.component.text = value;
974
+ }
975
+ }
976
+ get text() {
977
+ return this._text;
978
+ }
979
+ /**
980
+ * Sets the type of the element component.
981
+ * @param value - The type.
982
+ */
983
+ set type(value) {
984
+ this._type = value;
985
+ if (this.component) {
986
+ this.component.type = value;
987
+ }
988
+ }
989
+ /**
990
+ * Gets the type of the element component.
991
+ * @returns The type.
992
+ */
993
+ get type() {
994
+ return this._type;
995
+ }
996
+ set width(value) {
997
+ this._width = value;
998
+ if (this.component) {
999
+ this.component.width = value;
1000
+ }
1001
+ }
1002
+ get width() {
1003
+ return this._width;
1004
+ }
1005
+ set wrapLines(value) {
1006
+ this._wrapLines = value;
1007
+ if (this.component) {
1008
+ this.component.wrapLines = value;
1009
+ }
1010
+ }
1011
+ get wrapLines() {
1012
+ return this._wrapLines;
1013
+ }
1014
+ static get observedAttributes() {
1015
+ return [...super.observedAttributes, 'anchor', 'asset', 'auto-width', 'color', 'font-size', 'line-height', 'pivot', 'text', 'type', 'width', 'wrap-lines'];
1016
+ }
1017
+ attributeChangedCallback(name, _oldValue, newValue) {
1018
+ super.attributeChangedCallback(name, _oldValue, newValue);
1019
+ switch (name) {
1020
+ case 'anchor':
1021
+ this.anchor = parseVec4(newValue);
1022
+ break;
1023
+ case 'asset':
1024
+ this.asset = newValue;
1025
+ break;
1026
+ case 'auto-width':
1027
+ this.autoWidth = newValue !== 'false';
1028
+ break;
1029
+ case 'color':
1030
+ this.color = parseColor(newValue);
1031
+ break;
1032
+ case 'font-size':
1033
+ this.fontSize = Number(newValue);
1034
+ break;
1035
+ case 'line-height':
1036
+ this.lineHeight = Number(newValue);
1037
+ break;
1038
+ case 'pivot':
1039
+ this.pivot = parseVec2(newValue);
1040
+ break;
1041
+ case 'text':
1042
+ this.text = newValue;
1043
+ break;
1044
+ case 'type':
1045
+ this.type = newValue;
1046
+ break;
1047
+ case 'width':
1048
+ this.width = Number(newValue);
1049
+ break;
1050
+ case 'wrap-lines':
1051
+ this.wrapLines = this.hasAttribute(name);
1052
+ break;
1053
+ }
1054
+ }
1055
+ }
1056
+ customElements.define('pc-element', ElementComponentElement);
1057
+
1058
+ /**
1059
+ * Represents a gsplat component in the PlayCanvas engine.
1060
+ *
1061
+ * @category Components
1062
+ */
1063
+ class GSplatComponentElement extends ComponentElement {
1064
+ constructor() {
1065
+ super('gsplat');
1066
+ this._asset = '';
1067
+ }
1068
+ getAsset() {
1069
+ const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1070
+ return assetElement.asset;
1071
+ }
1072
+ getInitialComponentData() {
1073
+ return {
1074
+ asset: this.getAsset()
1075
+ };
1076
+ }
1077
+ /**
1078
+ * Gets the gsplat component.
1079
+ * @returns The gsplat component.
1080
+ */
1081
+ get component() {
1082
+ return super.component;
1083
+ }
1084
+ set asset(value) {
1085
+ this._asset = value;
1086
+ const asset = this.getAsset();
1087
+ if (this.component && asset) {
1088
+ this.component.asset = asset;
1089
+ }
1090
+ }
1091
+ get asset() {
1092
+ return this._asset;
1093
+ }
1094
+ static get observedAttributes() {
1095
+ return [...super.observedAttributes, 'asset'];
1096
+ }
1097
+ attributeChangedCallback(name, _oldValue, newValue) {
1098
+ super.attributeChangedCallback(name, _oldValue, newValue);
1099
+ switch (name) {
1100
+ case 'asset':
1101
+ this.asset = newValue;
1102
+ break;
1103
+ }
1104
+ }
1105
+ }
1106
+ customElements.define('pc-gsplat', GSplatComponentElement);
1107
+
1108
+ /**
1109
+ * Represents a light component in the PlayCanvas engine.
1110
+ *
1111
+ * @category Components
1112
+ */
1113
+ class LightComponentElement extends ComponentElement {
1114
+ /**
1115
+ * Creates a new LightComponentElement.
1116
+ */
1117
+ constructor() {
1118
+ super('light');
1119
+ this._castShadows = false;
1120
+ this._color = new playcanvas.Color(1, 1, 1);
1121
+ this._innerConeAngle = 40;
1122
+ this._intensity = 1;
1123
+ this._normalOffsetBias = 0.05;
1124
+ this._outerConeAngle = 45;
1125
+ this._range = 10;
1126
+ this._shadowBias = 0.2;
1127
+ this._shadowDistance = 16;
1128
+ this._type = 'directional';
1129
+ }
1130
+ getInitialComponentData() {
1131
+ return {
1132
+ castShadows: this._castShadows,
1133
+ color: this._color,
1134
+ innerConeAngle: this._innerConeAngle,
1135
+ intensity: this._intensity,
1136
+ normalOffsetBias: this._normalOffsetBias,
1137
+ outerConeAngle: this._outerConeAngle,
1138
+ range: this._range,
1139
+ shadowBias: this._shadowBias,
1140
+ shadowDistance: this._shadowDistance,
1141
+ type: this._type
1142
+ };
1143
+ }
1144
+ /**
1145
+ * Gets the light component.
1146
+ * @returns The light component.
1147
+ */
1148
+ get component() {
1149
+ return super.component;
1150
+ }
1151
+ /**
1152
+ * Sets the cast shadows flag of the light.
1153
+ * @param value - The cast shadows flag.
1154
+ */
1155
+ set castShadows(value) {
1156
+ this._castShadows = value;
1157
+ if (this.component) {
1158
+ this.component.castShadows = value;
1159
+ }
1160
+ }
1161
+ /**
1162
+ * Gets the cast shadows flag of the light.
1163
+ * @returns The cast shadows flag.
1164
+ */
1165
+ get castShadows() {
1166
+ return this._castShadows;
1167
+ }
1168
+ /**
1169
+ * Sets the color of the light.
1170
+ * @param value - The color.
1171
+ */
1172
+ set color(value) {
1173
+ this._color = value;
1174
+ if (this.component) {
1175
+ this.component.color = value;
1176
+ }
1177
+ }
1178
+ /**
1179
+ * Gets the color of the light.
1180
+ * @returns The color.
1181
+ */
1182
+ get color() {
1183
+ return this._color;
1184
+ }
1185
+ /**
1186
+ * Sets the inner cone angle of the light.
1187
+ * @param value - The inner cone angle.
1188
+ */
1189
+ set innerConeAngle(value) {
1190
+ this._innerConeAngle = value;
1191
+ if (this.component) {
1192
+ this.component.innerConeAngle = value;
1193
+ }
1194
+ }
1195
+ /**
1196
+ * Gets the inner cone angle of the light.
1197
+ * @returns The inner cone angle.
1198
+ */
1199
+ get innerConeAngle() {
1200
+ return this._innerConeAngle;
1201
+ }
1202
+ /**
1203
+ * Sets the intensity of the light.
1204
+ * @param value - The intensity.
1205
+ */
1206
+ set intensity(value) {
1207
+ this._intensity = value;
1208
+ if (this.component) {
1209
+ this.component.intensity = value;
1210
+ }
1211
+ }
1212
+ /**
1213
+ * Gets the intensity of the light.
1214
+ * @returns The intensity.
1215
+ */
1216
+ get intensity() {
1217
+ return this._intensity;
1218
+ }
1219
+ /**
1220
+ * Sets the normal offset bias of the light.
1221
+ * @param value - The normal offset bias.
1222
+ */
1223
+ set normalOffsetBias(value) {
1224
+ this._normalOffsetBias = value;
1225
+ if (this.component) {
1226
+ this.component.normalOffsetBias = value;
1227
+ }
1228
+ }
1229
+ /**
1230
+ * Gets the normal offset bias of the light.
1231
+ * @returns The normal offset bias.
1232
+ */
1233
+ get normalOffsetBias() {
1234
+ return this._normalOffsetBias;
1235
+ }
1236
+ /**
1237
+ * Sets the outer cone angle of the light.
1238
+ * @param value - The outer cone angle.
1239
+ */
1240
+ set outerConeAngle(value) {
1241
+ this._outerConeAngle = value;
1242
+ if (this.component) {
1243
+ this.component.outerConeAngle = value;
1244
+ }
1245
+ }
1246
+ /**
1247
+ * Gets the outer cone angle of the light.
1248
+ * @returns The outer cone angle.
1249
+ */
1250
+ get outerConeAngle() {
1251
+ return this._outerConeAngle;
1252
+ }
1253
+ /**
1254
+ * Sets the range of the light.
1255
+ * @param value - The range.
1256
+ */
1257
+ set range(value) {
1258
+ this._range = value;
1259
+ if (this.component) {
1260
+ this.component.range = value;
1261
+ }
1262
+ }
1263
+ /**
1264
+ * Gets the range of the light.
1265
+ * @returns The range.
1266
+ */
1267
+ get range() {
1268
+ return this._range;
1269
+ }
1270
+ /**
1271
+ * Sets the shadow bias of the light.
1272
+ * @param value - The shadow bias.
1273
+ */
1274
+ set shadowBias(value) {
1275
+ this._shadowBias = value;
1276
+ if (this.component) {
1277
+ this.component.shadowBias = value;
1278
+ }
1279
+ }
1280
+ /**
1281
+ * Gets the shadow bias of the light.
1282
+ * @returns The shadow bias.
1283
+ */
1284
+ get shadowBias() {
1285
+ return this._shadowBias;
1286
+ }
1287
+ /**
1288
+ * Sets the shadow distance of the light.
1289
+ * @param value - The shadow distance.
1290
+ */
1291
+ set shadowDistance(value) {
1292
+ this._shadowDistance = value;
1293
+ if (this.component) {
1294
+ this.component.shadowDistance = value;
1295
+ }
1296
+ }
1297
+ /**
1298
+ * Gets the shadow distance of the light.
1299
+ * @returns The shadow distance.
1300
+ */
1301
+ get shadowDistance() {
1302
+ return this._shadowDistance;
1303
+ }
1304
+ /**
1305
+ * Sets the type of the light.
1306
+ * @param value - The type.
1307
+ */
1308
+ set type(value) {
1309
+ if (!['directional', 'omni', 'spot'].includes(value)) {
1310
+ console.warn(`Invalid light type '${value}', using default type '${this._type}'.`);
1311
+ return;
1312
+ }
1313
+ this._type = value;
1314
+ if (this.component) {
1315
+ this.component.type = value;
1316
+ }
1317
+ }
1318
+ /**
1319
+ * Gets the type of the light.
1320
+ * @returns The type.
1321
+ */
1322
+ get type() {
1323
+ return this._type;
1324
+ }
1325
+ static get observedAttributes() {
1326
+ return [
1327
+ ...super.observedAttributes,
1328
+ 'color',
1329
+ 'cast-shadows',
1330
+ 'intensity',
1331
+ 'inner-cone-angle',
1332
+ 'normal-offset-bias',
1333
+ 'outer-cone-angle',
1334
+ 'range',
1335
+ 'shadow-bias',
1336
+ 'shadow-distance',
1337
+ 'type'
1338
+ ];
1339
+ }
1340
+ attributeChangedCallback(name, _oldValue, newValue) {
1341
+ super.attributeChangedCallback(name, _oldValue, newValue);
1342
+ switch (name) {
1343
+ case 'color':
1344
+ this.color = parseColor(newValue);
1345
+ break;
1346
+ case 'cast-shadows':
1347
+ this.castShadows = this.hasAttribute('cast-shadows');
1348
+ break;
1349
+ case 'inner-cone-angle':
1350
+ this.innerConeAngle = Number(newValue);
1351
+ break;
1352
+ case 'intensity':
1353
+ this.intensity = Number(newValue);
1354
+ break;
1355
+ case 'normal-offset-bias':
1356
+ this.normalOffsetBias = Number(newValue);
1357
+ break;
1358
+ case 'outer-cone-angle':
1359
+ this.outerConeAngle = Number(newValue);
1360
+ break;
1361
+ case 'range':
1362
+ this.range = Number(newValue);
1363
+ break;
1364
+ case 'shadow-bias':
1365
+ this.shadowBias = Number(newValue);
1366
+ break;
1367
+ case 'shadow-distance':
1368
+ this.shadowDistance = Number(newValue);
1369
+ break;
1370
+ case 'type':
1371
+ this.type = newValue;
1372
+ break;
1373
+ }
1374
+ }
1375
+ }
1376
+ customElements.define('pc-light', LightComponentElement);
1377
+
1378
+ /**
1379
+ * Represents a render component in the PlayCanvas engine.
1380
+ *
1381
+ * @category Components
1382
+ */
1383
+ class RenderComponentElement extends ComponentElement {
1384
+ constructor() {
1385
+ super('render');
1386
+ this._type = 'asset';
1387
+ this._castShadows = true;
1388
+ this._receiveShadows = true;
1389
+ }
1390
+ getInitialComponentData() {
1391
+ return {
1392
+ type: this._type,
1393
+ castShadows: this._castShadows,
1394
+ receiveShadows: this._receiveShadows
1395
+ };
1396
+ }
1397
+ /**
1398
+ * Gets the render component.
1399
+ * @returns The render component.
1400
+ */
1401
+ get component() {
1402
+ return super.component;
1403
+ }
1404
+ /**
1405
+ * Sets the type of the render component.
1406
+ * @param value - The type.
1407
+ */
1408
+ set type(value) {
1409
+ this._type = value;
1410
+ if (this.component) {
1411
+ this.component.type = value;
1412
+ }
1413
+ }
1414
+ /**
1415
+ * Gets the type of the render component.
1416
+ * @returns The type.
1417
+ */
1418
+ get type() {
1419
+ return this._type;
1420
+ }
1421
+ /**
1422
+ * Sets the cast shadows flag of the render component.
1423
+ * @param value - The cast shadows flag.
1424
+ */
1425
+ set castShadows(value) {
1426
+ this._castShadows = value;
1427
+ if (this.component) {
1428
+ this.component.castShadows = value;
1429
+ }
1430
+ }
1431
+ /**
1432
+ * Gets the cast shadows flag of the render component.
1433
+ * @returns The cast shadows flag.
1434
+ */
1435
+ get castShadows() {
1436
+ return this._castShadows;
1437
+ }
1438
+ /**
1439
+ * Sets the receive shadows flag of the render component.
1440
+ * @param value - The receive shadows flag.
1441
+ */
1442
+ set receiveShadows(value) {
1443
+ this._receiveShadows = value;
1444
+ if (this.component) {
1445
+ this.component.receiveShadows = value;
1446
+ }
1447
+ }
1448
+ /**
1449
+ * Gets the receive shadows flag of the render component.
1450
+ * @returns The receive shadows flag.
1451
+ */
1452
+ get receiveShadows() {
1453
+ return this._receiveShadows;
1454
+ }
1455
+ static get observedAttributes() {
1456
+ return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
1457
+ }
1458
+ attributeChangedCallback(name, _oldValue, newValue) {
1459
+ super.attributeChangedCallback(name, _oldValue, newValue);
1460
+ switch (name) {
1461
+ case 'type':
1462
+ this.type = newValue;
1463
+ break;
1464
+ case 'cast-shadows':
1465
+ this.castShadows = newValue !== 'false';
1466
+ break;
1467
+ case 'receive-shadows':
1468
+ this.receiveShadows = newValue !== 'false';
1469
+ break;
1470
+ }
1471
+ }
1472
+ }
1473
+ customElements.define('pc-render', RenderComponentElement);
1474
+
1475
+ /**
1476
+ * Represents a rigidbody component in the PlayCanvas engine.
1477
+ *
1478
+ * @category Components
1479
+ */
1480
+ class RigidBodyComponentElement extends ComponentElement {
1481
+ /**
1482
+ * Creates a new RigidBodyComponentElement.
1483
+ */
1484
+ constructor() {
1485
+ super('rigidbody');
1486
+ /**
1487
+ * The angular damping of the rigidbody.
1488
+ */
1489
+ this._angularDamping = 0;
1490
+ /**
1491
+ * The angular factor of the rigidbody.
1492
+ */
1493
+ this._angularFactor = new playcanvas.Vec3(1, 1, 1);
1494
+ /**
1495
+ * The friction of the rigidbody.
1496
+ */
1497
+ this._friction = 0.5;
1498
+ /**
1499
+ * The linear damping of the rigidbody.
1500
+ */
1501
+ this._linearDamping = 0;
1502
+ /**
1503
+ * The linear factor of the rigidbody.
1504
+ */
1505
+ this._linearFactor = new playcanvas.Vec3(1, 1, 1);
1506
+ /**
1507
+ * The mass of the rigidbody.
1508
+ */
1509
+ this._mass = 1;
1510
+ /**
1511
+ * The restitution of the rigidbody.
1512
+ */
1513
+ this._restitution = 0;
1514
+ /**
1515
+ * The rolling friction of the rigidbody.
1516
+ */
1517
+ this._rollingFriction = 0;
1518
+ /**
1519
+ * The type of the rigidbody.
1520
+ */
1521
+ this._type = 'static';
1522
+ }
1523
+ getInitialComponentData() {
1524
+ return {
1525
+ angularDamping: this._angularDamping,
1526
+ angularFactor: this._angularFactor,
1527
+ friction: this._friction,
1528
+ linearDamping: this._linearDamping,
1529
+ linearFactor: this._linearFactor,
1530
+ mass: this._mass,
1531
+ restitution: this._restitution,
1532
+ rollingFriction: this._rollingFriction,
1533
+ type: this._type
1534
+ };
1535
+ }
1536
+ /**
1537
+ * Gets the collision component.
1538
+ * @returns The collision component.
1539
+ */
1540
+ get component() {
1541
+ return super.component;
1542
+ }
1543
+ set angularDamping(value) {
1544
+ this._angularDamping = value;
1545
+ if (this.component) {
1546
+ this.component.angularDamping = value;
1547
+ }
1548
+ }
1549
+ get angularDamping() {
1550
+ return this._angularDamping;
1551
+ }
1552
+ set angularFactor(value) {
1553
+ this._angularFactor = value;
1554
+ if (this.component) {
1555
+ this.component.angularFactor = value;
1556
+ }
1557
+ }
1558
+ get angularFactor() {
1559
+ return this._angularFactor;
1560
+ }
1561
+ set friction(value) {
1562
+ this._friction = value;
1563
+ if (this.component) {
1564
+ this.component.friction = value;
1565
+ }
1566
+ }
1567
+ get friction() {
1568
+ return this._friction;
1569
+ }
1570
+ set linearDamping(value) {
1571
+ this._linearDamping = value;
1572
+ if (this.component) {
1573
+ this.component.linearDamping = value;
1574
+ }
1575
+ }
1576
+ get linearDamping() {
1577
+ return this._linearDamping;
1578
+ }
1579
+ set linearFactor(value) {
1580
+ this._linearFactor = value;
1581
+ if (this.component) {
1582
+ this.component.linearFactor = value;
1583
+ }
1584
+ }
1585
+ get linearFactor() {
1586
+ return this._linearFactor;
1587
+ }
1588
+ set mass(value) {
1589
+ this._mass = value;
1590
+ if (this.component) {
1591
+ this.component.mass = value;
1592
+ }
1593
+ }
1594
+ get mass() {
1595
+ return this._mass;
1596
+ }
1597
+ set restitution(value) {
1598
+ this._restitution = value;
1599
+ if (this.component) {
1600
+ this.component.restitution = value;
1601
+ }
1602
+ }
1603
+ get restitution() {
1604
+ return this._restitution;
1605
+ }
1606
+ set rollingFriction(value) {
1607
+ this._rollingFriction = value;
1608
+ if (this.component) {
1609
+ this.component.rollingFriction = value;
1610
+ }
1611
+ }
1612
+ get rollingFriction() {
1613
+ return this._rollingFriction;
1614
+ }
1615
+ set type(value) {
1616
+ this._type = value;
1617
+ if (this.component) {
1618
+ this.component.type = value;
1619
+ }
1620
+ }
1621
+ get type() {
1622
+ return this._type;
1623
+ }
1624
+ static get observedAttributes() {
1625
+ return [...super.observedAttributes, 'angular-damping', 'angular-factor', 'friction', 'linear-damping', 'linear-factor', 'mass', 'restitution', 'rolling-friction', 'type'];
1626
+ }
1627
+ attributeChangedCallback(name, _oldValue, newValue) {
1628
+ super.attributeChangedCallback(name, _oldValue, newValue);
1629
+ switch (name) {
1630
+ case 'angular-damping':
1631
+ this.angularDamping = parseFloat(newValue);
1632
+ break;
1633
+ case 'angular-factor':
1634
+ this.angularFactor = parseVec3(newValue);
1635
+ break;
1636
+ case 'friction':
1637
+ this.friction = parseFloat(newValue);
1638
+ break;
1639
+ case 'linear-damping':
1640
+ this.linearDamping = parseFloat(newValue);
1641
+ break;
1642
+ case 'linear-factor':
1643
+ this.linearFactor = parseVec3(newValue);
1644
+ break;
1645
+ case 'mass':
1646
+ this.mass = parseFloat(newValue);
1647
+ break;
1648
+ case 'restitution':
1649
+ this.restitution = parseFloat(newValue);
1650
+ break;
1651
+ case 'rolling-friction':
1652
+ this.rollingFriction = parseFloat(newValue);
1653
+ break;
1654
+ case 'type':
1655
+ this.type = newValue;
1656
+ break;
1657
+ }
1658
+ }
1659
+ }
1660
+ customElements.define('pc-rigidbody', RigidBodyComponentElement);
1661
+
1662
+ /**
1663
+ * Represents a script component in the PlayCanvas engine.
1664
+ *
1665
+ * @category Components
1666
+ */
1667
+ class ScriptComponentElement extends ComponentElement {
1668
+ constructor() {
1669
+ super('script');
1670
+ }
1671
+ /**
1672
+ * Gets the script component.
1673
+ * @returns The script component.
1674
+ */
1675
+ get component() {
1676
+ return super.component;
1677
+ }
1678
+ }
1679
+ customElements.define('pc-scripts', ScriptComponentElement);
1680
+
1681
+ /**
1682
+ * Represents a script in the PlayCanvas engine.
1683
+ */
1684
+ class ScriptElement extends HTMLElement {
1685
+ constructor() {
1686
+ super(...arguments);
1687
+ this._attributes = {};
1688
+ this._enabled = true;
1689
+ this._name = '';
1690
+ this._script = null;
1691
+ }
1692
+ async connectedCallback() {
1693
+ var _a, _b, _c;
1694
+ const appElement = this.closest('pc-app');
1695
+ if (!appElement) {
1696
+ console.error(`${this.tagName.toLowerCase()} should be a descendant of pc-app`);
1697
+ return;
1698
+ }
1699
+ await appElement.getApplication();
1700
+ const scriptAttributes = this.getAttribute('attributes');
1701
+ if (scriptAttributes) {
1702
+ try {
1703
+ this._attributes = JSON.parse(scriptAttributes);
1704
+ }
1705
+ catch (e) {
1706
+ console.error('Failed to parse script attributes:', e);
1707
+ }
1708
+ }
1709
+ // When the script is created, initialize it with the necessary attributes
1710
+ (_a = this.scriptsElement) === null || _a === void 0 ? void 0 : _a.component.on(`create:${this._name}`, (scriptInstance) => {
1711
+ Object.assign(scriptInstance, this._attributes);
1712
+ });
1713
+ this._script = (_c = (_b = this.scriptsElement) === null || _b === void 0 ? void 0 : _b.component.create(this._name, { preloading: false })) !== null && _c !== void 0 ? _c : null;
1714
+ }
1715
+ disconnectedCallback() {
1716
+ var _a;
1717
+ (_a = this.scriptsElement) === null || _a === void 0 ? void 0 : _a.component.destroy(this._name);
1718
+ }
1719
+ refreshAttributes() {
1720
+ if (this._script) {
1721
+ Object.entries(this._attributes).forEach(([name, value]) => {
1722
+ if (this._script && name in this._script) {
1723
+ this._script[name] = value;
1724
+ }
1725
+ });
1726
+ }
1727
+ }
1728
+ get scriptsElement() {
1729
+ const scriptsElement = this.parentElement;
1730
+ if (!(scriptsElement instanceof ScriptComponentElement)) {
1731
+ console.warn('pc-script must be a direct child of a pc-scripts element');
1732
+ return null;
1733
+ }
1734
+ return scriptsElement;
1735
+ }
1736
+ set scriptAttributes(value) {
1737
+ this._attributes = JSON.parse(value);
1738
+ this.refreshAttributes();
1739
+ }
1740
+ get scriptAttributes() {
1741
+ return JSON.stringify(this._attributes);
1742
+ }
1743
+ set enabled(value) {
1744
+ this._enabled = value;
1745
+ if (this._script) {
1746
+ this._script.enabled = value;
1747
+ }
1748
+ }
1749
+ /**
1750
+ * Gets the enabled state of the script.
1751
+ * @returns The enabled state of the script.
1752
+ */
1753
+ get enabled() {
1754
+ return this._enabled;
1755
+ }
1756
+ /**
1757
+ * Sets the name of the script to create.
1758
+ * @param value - The name.
1759
+ */
1760
+ set name(value) {
1761
+ this._name = value;
1762
+ }
1763
+ /**
1764
+ * Gets the name of the script.
1765
+ * @returns The name.
1766
+ */
1767
+ get name() {
1768
+ return this._name;
1769
+ }
1770
+ static get observedAttributes() {
1771
+ return ['attributes', 'enabled', 'name'];
1772
+ }
1773
+ attributeChangedCallback(name, _oldValue, newValue) {
1774
+ switch (name) {
1775
+ case 'attributes':
1776
+ this.scriptAttributes = newValue;
1777
+ break;
1778
+ case 'enabled':
1779
+ this.enabled = newValue !== 'false';
1780
+ break;
1781
+ case 'name':
1782
+ this.name = newValue;
1783
+ break;
1784
+ }
1785
+ }
1786
+ }
1787
+ customElements.define('pc-script', ScriptElement);
1788
+
1789
+ /**
1790
+ * Represents a sound component in the PlayCanvas engine.
1791
+ *
1792
+ * @category Components
1793
+ */
1794
+ class SoundComponentElement extends ComponentElement {
1795
+ constructor() {
1796
+ super('sound');
1797
+ this._pitch = 1;
1798
+ this._positional = false;
1799
+ this._volume = 1;
1800
+ }
1801
+ getInitialComponentData() {
1802
+ return {
1803
+ pitch: this._pitch,
1804
+ positional: this._positional,
1805
+ volume: this._volume
1806
+ };
1807
+ }
1808
+ /**
1809
+ * Gets the sound component.
1810
+ * @returns The sound component.
1811
+ */
1812
+ get component() {
1813
+ return super.component;
1814
+ }
1815
+ /**
1816
+ * Sets the pitch of the sound.
1817
+ * @param value - The pitch.
1818
+ */
1819
+ set pitch(value) {
1820
+ this._pitch = value;
1821
+ if (this.component) {
1822
+ this.component.pitch = value;
1823
+ }
1824
+ }
1825
+ /**
1826
+ * Gets the pitch of the sound.
1827
+ * @returns The pitch.
1828
+ */
1829
+ get pitch() {
1830
+ return this._pitch;
1831
+ }
1832
+ /**
1833
+ * Sets the positional flag of the sound.
1834
+ * @param value - The positional flag.
1835
+ */
1836
+ set positional(value) {
1837
+ this._positional = value;
1838
+ if (this.component) {
1839
+ this.component.positional = value;
1840
+ }
1841
+ }
1842
+ /**
1843
+ * Gets the positional flag of the sound.
1844
+ * @returns The positional flag.
1845
+ */
1846
+ get positional() {
1847
+ return this._positional;
1848
+ }
1849
+ /**
1850
+ * Sets the volume of the sound.
1851
+ * @param value - The volume.
1852
+ */
1853
+ set volume(value) {
1854
+ this._volume = value;
1855
+ if (this.component) {
1856
+ this.component.volume = value;
1857
+ }
1858
+ }
1859
+ /**
1860
+ * Gets the volume of the sound.
1861
+ * @returns The volume.
1862
+ */
1863
+ get volume() {
1864
+ return this._volume;
1865
+ }
1866
+ static get observedAttributes() {
1867
+ return [...super.observedAttributes, 'pitch', 'positional', 'volume'];
1868
+ }
1869
+ attributeChangedCallback(name, _oldValue, newValue) {
1870
+ super.attributeChangedCallback(name, _oldValue, newValue);
1871
+ switch (name) {
1872
+ case 'pitch':
1873
+ this.pitch = parseFloat(newValue);
1874
+ break;
1875
+ case 'positional':
1876
+ this.positional = this.hasAttribute('positional');
1877
+ break;
1878
+ case 'volume':
1879
+ this.volume = parseFloat(newValue);
1880
+ break;
1881
+ }
1882
+ }
1883
+ }
1884
+ customElements.define('pc-sound', SoundComponentElement);
1885
+
1886
+ /**
1887
+ * Represents a sound slot in the PlayCanvas engine.
1888
+ */
1889
+ class SoundSlotElement extends HTMLElement {
1890
+ constructor() {
1891
+ super(...arguments);
1892
+ this._asset = '';
1893
+ this._autoPlay = false;
1894
+ this._duration = null;
1895
+ this._loop = false;
1896
+ this._name = '';
1897
+ this._overlap = false;
1898
+ this._pitch = 1;
1899
+ this._startTime = 0;
1900
+ this._volume = 1;
1901
+ /**
1902
+ * The sound slot.
1903
+ */
1904
+ this.soundSlot = null;
1905
+ }
1906
+ getAsset() {
1907
+ const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1908
+ return assetElement.asset;
1909
+ }
1910
+ async connectedCallback() {
1911
+ const appElement = this.closest('pc-app');
1912
+ if (!appElement) {
1913
+ console.error(`${this.tagName.toLowerCase()} should be a descendant of pc-app`);
1914
+ return;
1915
+ }
1916
+ await appElement.getApplication();
1917
+ const options = {
1918
+ autoPlay: this._autoPlay,
1919
+ loop: this._loop,
1920
+ overlap: this._overlap,
1921
+ pitch: this._pitch,
1922
+ startTime: this._startTime,
1923
+ volume: this._volume
1924
+ };
1925
+ if (this._duration) {
1926
+ options.duration = this._duration;
1927
+ }
1928
+ this.soundSlot = this.soundElement.component.addSlot(this._name, options);
1929
+ this.asset = this._asset;
1930
+ this.soundSlot.play();
1931
+ }
1932
+ disconnectedCallback() {
1933
+ this.soundElement.component.removeSlot(this._name);
1934
+ }
1935
+ get soundElement() {
1936
+ const soundElement = this.parentElement;
1937
+ if (!(soundElement instanceof SoundComponentElement)) {
1938
+ console.warn('pc-sound-slot must be a direct child of a pc-sound element');
1939
+ return null;
1940
+ }
1941
+ return soundElement;
1942
+ }
1943
+ /**
1944
+ * Sets the asset of the sound slot.
1945
+ * @param value - The asset.
1946
+ */
1947
+ set asset(value) {
1948
+ var _a;
1949
+ this._asset = value;
1950
+ if (this.soundSlot) {
1951
+ const id = (_a = this.getAsset()) === null || _a === void 0 ? void 0 : _a.id;
1952
+ if (id) {
1953
+ this.soundSlot.asset = id;
1954
+ }
1955
+ }
1956
+ }
1957
+ /**
1958
+ * Gets the asset of the sound slot.
1959
+ * @returns The asset.
1960
+ */
1961
+ get asset() {
1962
+ return this._asset;
1963
+ }
1964
+ /**
1965
+ * Sets the auto play flag of the sound slot.
1966
+ * @param value - The auto play flag.
1967
+ */
1968
+ set autoPlay(value) {
1969
+ this._autoPlay = value;
1970
+ if (this.soundSlot) {
1971
+ this.soundSlot.autoPlay = value;
1972
+ }
1973
+ }
1974
+ /**
1975
+ * Gets the auto play flag of the sound slot.
1976
+ * @returns The auto play flag.
1977
+ */
1978
+ get autoPlay() {
1979
+ return this._autoPlay;
1980
+ }
1981
+ /**
1982
+ * Sets the duration of the sound slot.
1983
+ * @param value - The duration.
1984
+ */
1985
+ set duration(value) {
1986
+ this._duration = value;
1987
+ if (this.soundSlot) {
1988
+ this.soundSlot.duration = value;
1989
+ }
1990
+ }
1991
+ /**
1992
+ * Gets the duration of the sound slot.
1993
+ * @returns The duration.
1994
+ */
1995
+ get duration() {
1996
+ return this._duration;
1997
+ }
1998
+ /**
1999
+ * Sets the loop flag of the sound slot.
2000
+ * @param value - The loop flag.
2001
+ */
2002
+ set loop(value) {
2003
+ this._loop = value;
2004
+ if (this.soundSlot) {
2005
+ this.soundSlot.loop = value;
2006
+ }
2007
+ }
2008
+ /**
2009
+ * Gets the loop flag of the sound slot.
2010
+ * @returns The loop flag.
2011
+ */
2012
+ get loop() {
2013
+ return this._loop;
2014
+ }
2015
+ /**
2016
+ * Sets the name of the sound slot.
2017
+ * @param value - The name.
2018
+ */
2019
+ set name(value) {
2020
+ this._name = value;
2021
+ if (this.soundSlot) {
2022
+ this.soundSlot.name = value;
2023
+ }
2024
+ }
2025
+ /**
2026
+ * Gets the name of the sound slot.
2027
+ * @returns The name.
2028
+ */
2029
+ get name() {
2030
+ return this._name;
2031
+ }
2032
+ /**
2033
+ * Sets the overlap flag of the sound slot.
2034
+ * @param value - The overlap flag.
2035
+ */
2036
+ set overlap(value) {
2037
+ this._overlap = value;
2038
+ if (this.soundSlot) {
2039
+ this.soundSlot.overlap = value;
2040
+ }
2041
+ }
2042
+ /**
2043
+ * Gets the overlap flag of the sound slot.
2044
+ * @returns The overlap flag.
2045
+ */
2046
+ get overlap() {
2047
+ return this._overlap;
2048
+ }
2049
+ /**
2050
+ * Sets the pitch of the sound slot.
2051
+ * @param value - The pitch.
2052
+ */
2053
+ set pitch(value) {
2054
+ this._pitch = value;
2055
+ if (this.soundSlot) {
2056
+ this.soundSlot.pitch = value;
2057
+ }
2058
+ }
2059
+ /**
2060
+ * Gets the pitch of the sound slot.
2061
+ * @returns The pitch.
2062
+ */
2063
+ get pitch() {
2064
+ return this._pitch;
2065
+ }
2066
+ /**
2067
+ * Sets the start time of the sound slot.
2068
+ * @param value - The start time.
2069
+ */
2070
+ set startTime(value) {
2071
+ this._startTime = value;
2072
+ if (this.soundSlot) {
2073
+ this.soundSlot.startTime = value;
2074
+ }
2075
+ }
2076
+ /**
2077
+ * Gets the start time of the sound slot.
2078
+ * @returns The start time.
2079
+ */
2080
+ get startTime() {
2081
+ return this._startTime;
2082
+ }
2083
+ /**
2084
+ * Sets the volume of the sound slot.
2085
+ * @param value - The volume.
2086
+ */
2087
+ set volume(value) {
2088
+ this._volume = value;
2089
+ if (this.soundSlot) {
2090
+ this.soundSlot.volume = value;
2091
+ }
2092
+ }
2093
+ /**
2094
+ * Gets the volume of the sound slot.
2095
+ * @returns The volume.
2096
+ */
2097
+ get volume() {
2098
+ return this._volume;
2099
+ }
2100
+ static get observedAttributes() {
2101
+ return ['asset', 'autoPlay', 'duration', 'loop', 'name', 'overlap', 'pitch', 'startTime', 'volume'];
2102
+ }
2103
+ attributeChangedCallback(name, _oldValue, newValue) {
2104
+ switch (name) {
2105
+ case 'asset':
2106
+ this.asset = newValue;
2107
+ break;
2108
+ case 'duration':
2109
+ this.duration = parseFloat(newValue);
2110
+ break;
2111
+ case 'loop':
2112
+ this.loop = this.hasAttribute('loop');
2113
+ break;
2114
+ case 'name':
2115
+ this.name = newValue;
2116
+ break;
2117
+ case 'overlap':
2118
+ this.overlap = this.hasAttribute('overlap');
2119
+ break;
2120
+ case 'pitch':
2121
+ this.pitch = parseFloat(newValue);
2122
+ break;
2123
+ case 'startTime':
2124
+ this.startTime = parseFloat(newValue);
2125
+ break;
2126
+ case 'volume':
2127
+ this.volume = parseFloat(newValue);
2128
+ break;
2129
+ }
2130
+ }
2131
+ }
2132
+ customElements.define('pc-sound-slot', SoundSlotElement);
2133
+
2134
+ /**
2135
+ * Represents a model in the PlayCanvas engine.
2136
+ */
2137
+ class ModelElement extends HTMLElement {
2138
+ constructor() {
2139
+ super(...arguments);
2140
+ this._asset = '';
2141
+ }
2142
+ async connectedCallback() {
2143
+ // Get the application
2144
+ const appElement = this.closest('pc-app');
2145
+ if (!appElement) {
2146
+ console.warn(`${this.tagName} must be a child of pc-app`);
2147
+ return;
2148
+ }
2149
+ await appElement.getApplication();
2150
+ const asset = this.getAttribute('asset');
2151
+ if (asset) {
2152
+ this.asset = asset;
2153
+ }
2154
+ }
2155
+ getAsset() {
2156
+ const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2157
+ return assetElement.asset;
2158
+ }
2159
+ _loadModel() {
2160
+ const asset = this.getAsset();
2161
+ if (!asset) {
2162
+ return;
2163
+ }
2164
+ const entity = asset.resource.instantiateRenderEntity();
2165
+ const parentEntityElement = this.closest('pc-entity');
2166
+ if (parentEntityElement) {
2167
+ parentEntityElement.entity.addChild(entity);
2168
+ }
2169
+ else {
2170
+ const appElement = this.closest('pc-app');
2171
+ appElement.app.root.addChild(entity);
2172
+ }
2173
+ }
2174
+ /**
2175
+ * Sets the asset ID of the model.
2176
+ * @param value - The asset ID.
2177
+ */
2178
+ set asset(value) {
2179
+ this._asset = value;
2180
+ this._loadModel();
2181
+ }
2182
+ /**
2183
+ * Gets the source URL of the model.
2184
+ * @returns The source URL of the model.
2185
+ */
2186
+ get asset() {
2187
+ return this._asset;
2188
+ }
2189
+ static get observedAttributes() {
2190
+ return ['asset'];
2191
+ }
2192
+ attributeChangedCallback(name, _oldValue, newValue) {
2193
+ switch (name) {
2194
+ case 'asset':
2195
+ this.asset = newValue;
2196
+ break;
2197
+ }
2198
+ }
2199
+ }
2200
+ customElements.define('pc-model', ModelElement);
2201
+
2202
+ /**
2203
+ * Represents a scene in the PlayCanvas engine.
2204
+ */
2205
+ class SceneElement extends HTMLElement {
2206
+ constructor() {
2207
+ super(...arguments);
2208
+ /**
2209
+ * The fog type of the scene.
2210
+ */
2211
+ this._fog = 'none'; // possible values: 'none', 'linear', 'exp', 'exp2'
2212
+ /**
2213
+ * The color of the fog.
2214
+ */
2215
+ this._fogColor = new playcanvas.Color(1, 1, 1);
2216
+ /**
2217
+ * The density of the fog.
2218
+ */
2219
+ this._fogDensity = 0;
2220
+ /**
2221
+ * The start distance of the fog.
2222
+ */
2223
+ this._fogStart = 0;
2224
+ /**
2225
+ * The end distance of the fog.
2226
+ */
2227
+ this._fogEnd = 1000;
2228
+ /**
2229
+ * The PlayCanvas scene instance.
2230
+ */
2231
+ this.scene = null;
2232
+ }
2233
+ async connectedCallback() {
2234
+ // Get the application
2235
+ const appElement = this.closest('pc-app');
2236
+ if (!appElement) {
2237
+ console.warn(`${this.tagName} must be a child of pc-app`);
2238
+ return;
2239
+ }
2240
+ const app = await appElement.getApplication();
2241
+ this.scene = app.scene;
2242
+ this.updateSceneSettings();
2243
+ }
2244
+ updateSceneSettings() {
2245
+ if (this.scene) {
2246
+ this.scene.rendering.fog = this._fog;
2247
+ this.scene.rendering.fogColor = this._fogColor;
2248
+ this.scene.rendering.fogDensity = this._fogDensity;
2249
+ this.scene.rendering.fogStart = this._fogStart;
2250
+ this.scene.rendering.fogEnd = this._fogEnd;
2251
+ // ... set other properties on the scene as well
2252
+ }
2253
+ }
2254
+ /**
2255
+ * Sets the fog type of the scene.
2256
+ * @param value - The fog type.
2257
+ */
2258
+ set fog(value) {
2259
+ this._fog = value;
2260
+ if (this.scene) {
2261
+ this.scene.rendering.fog = value;
2262
+ }
2263
+ }
2264
+ /**
2265
+ * Gets the fog type of the scene.
2266
+ * @returns The fog type.
2267
+ */
2268
+ get fog() {
2269
+ return this._fog;
2270
+ }
2271
+ /**
2272
+ * Sets the fog color of the scene.
2273
+ * @param value - The fog color.
2274
+ */
2275
+ set fogColor(value) {
2276
+ this._fogColor = value;
2277
+ if (this.scene) {
2278
+ this.scene.rendering.fogColor = value;
2279
+ }
2280
+ }
2281
+ /**
2282
+ * Gets the fog color of the scene.
2283
+ * @returns The fog color.
2284
+ */
2285
+ get fogColor() {
2286
+ return this._fogColor;
2287
+ }
2288
+ /**
2289
+ * Sets the fog density of the scene.
2290
+ * @param value - The fog density.
2291
+ */
2292
+ set fogDensity(value) {
2293
+ this._fogDensity = value;
2294
+ if (this.scene) {
2295
+ this.scene.rendering.fogDensity = value;
2296
+ }
2297
+ }
2298
+ /**
2299
+ * Gets the fog density of the scene.
2300
+ * @returns The fog density.
2301
+ */
2302
+ get fogDensity() {
2303
+ return this._fogDensity;
2304
+ }
2305
+ /**
2306
+ * Sets the fog start distance of the scene.
2307
+ * @param value - The fog start distance.
2308
+ */
2309
+ set fogStart(value) {
2310
+ this._fogStart = value;
2311
+ if (this.scene) {
2312
+ this.scene.rendering.fogStart = value;
2313
+ }
2314
+ }
2315
+ /**
2316
+ * Gets the fog start distance of the scene.
2317
+ * @returns The fog start distance.
2318
+ */
2319
+ get fogStart() {
2320
+ return this._fogStart;
2321
+ }
2322
+ /**
2323
+ * Sets the fog end distance of the scene.
2324
+ * @param value - The fog end distance.
2325
+ */
2326
+ set fogEnd(value) {
2327
+ this._fogEnd = value;
2328
+ if (this.scene) {
2329
+ this.scene.rendering.fogEnd = value;
2330
+ }
2331
+ }
2332
+ /**
2333
+ * Gets the fog end distance of the scene.
2334
+ * @returns The fog end distance.
2335
+ */
2336
+ get fogEnd() {
2337
+ return this._fogEnd;
2338
+ }
2339
+ static get observedAttributes() {
2340
+ return ['fog', 'fog-color', 'fog-density', 'fog-start', 'fog-end'];
2341
+ }
2342
+ attributeChangedCallback(name, _oldValue, newValue) {
2343
+ switch (name) {
2344
+ case 'fog':
2345
+ this.fog = newValue;
2346
+ break;
2347
+ case 'fog-color':
2348
+ this.fogColor = parseColor(newValue);
2349
+ break;
2350
+ case 'fog-density':
2351
+ this.fogDensity = parseFloat(newValue);
2352
+ break;
2353
+ case 'fog-start':
2354
+ this.fogStart = parseFloat(newValue);
2355
+ break;
2356
+ case 'fog-end':
2357
+ this.fogEnd = parseFloat(newValue);
2358
+ break;
2359
+ // ... handle other attributes as well
2360
+ }
2361
+ }
2362
+ }
2363
+ customElements.define('pc-scene', SceneElement);
2364
+
2365
+ /**
2366
+ * Represents a sky in the PlayCanvas engine.
2367
+ */
2368
+ class SkyElement extends HTMLElement {
2369
+ constructor() {
2370
+ super(...arguments);
2371
+ this._asset = '';
2372
+ this._intensity = 1;
2373
+ this._rotation = [0, 0, 0];
2374
+ this._level = 0;
2375
+ this._solidColor = false;
2376
+ }
2377
+ async connectedCallback() {
2378
+ // Get the application
2379
+ const appElement = this.closest('pc-app');
2380
+ if (!appElement) {
2381
+ console.warn(`${this.tagName} must be a child of pc-app`);
2382
+ return;
2383
+ }
2384
+ await appElement.getApplication();
2385
+ this.asset = this.getAttribute('asset') || '';
2386
+ this.solidColor = this.hasAttribute('solid-color');
2387
+ }
2388
+ getAsset() {
2389
+ const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2390
+ return assetElement.asset;
2391
+ }
2392
+ getScene() {
2393
+ const appElement = this.closest('pc-app');
2394
+ if (!appElement) {
2395
+ return;
2396
+ }
2397
+ const app = appElement.app;
2398
+ if (!app) {
2399
+ return;
2400
+ }
2401
+ return app.scene;
2402
+ }
2403
+ set asset(value) {
2404
+ this._asset = value;
2405
+ const scene = this.getScene();
2406
+ if (scene) {
2407
+ const asset = this.getAsset();
2408
+ if (asset) {
2409
+ if (asset.resource) {
2410
+ scene.envAtlas = asset.resource;
2411
+ }
2412
+ else {
2413
+ asset.once('load', () => {
2414
+ scene.envAtlas = asset.resource;
2415
+ });
2416
+ }
2417
+ }
2418
+ }
2419
+ }
2420
+ get asset() {
2421
+ return this._asset;
2422
+ }
2423
+ set intensity(value) {
2424
+ this._intensity = value;
2425
+ const scene = this.getScene();
2426
+ if (scene) {
2427
+ scene.skyboxIntensity = this._intensity;
2428
+ }
2429
+ }
2430
+ get intensity() {
2431
+ return this._intensity;
2432
+ }
2433
+ set rotation(value) {
2434
+ this._rotation = value;
2435
+ const scene = this.getScene();
2436
+ if (scene) {
2437
+ scene.skyboxRotation = new playcanvas.Quat().setFromEulerAngles(this._rotation[0], this._rotation[1], this._rotation[2]);
2438
+ }
2439
+ }
2440
+ get rotation() {
2441
+ return this._rotation;
2442
+ }
2443
+ set solidColor(value) {
2444
+ this._solidColor = value;
2445
+ const scene = this.getScene();
2446
+ if (scene) {
2447
+ const layer = scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
2448
+ if (layer) {
2449
+ layer.enabled = !this._solidColor;
2450
+ }
2451
+ }
2452
+ }
2453
+ get solidColor() {
2454
+ return this._solidColor;
2455
+ }
2456
+ set level(value) {
2457
+ this._level = value;
2458
+ const scene = this.getScene();
2459
+ if (scene) {
2460
+ scene.skyboxMip = this._level;
2461
+ }
2462
+ }
2463
+ get level() {
2464
+ return this._level;
2465
+ }
2466
+ static get observedAttributes() {
2467
+ return ['asset', 'intensity', 'level', 'rotation', 'solid-color'];
2468
+ }
2469
+ attributeChangedCallback(name, _oldValue, newValue) {
2470
+ switch (name) {
2471
+ case 'asset':
2472
+ this.asset = newValue;
2473
+ break;
2474
+ case 'intensity':
2475
+ this.intensity = parseFloat(newValue);
2476
+ break;
2477
+ case 'rotation':
2478
+ this.rotation = newValue.split(',').map(Number);
2479
+ break;
2480
+ case 'level':
2481
+ this.level = parseInt(newValue, 10);
2482
+ break;
2483
+ case 'solid-color':
2484
+ this.solidColor = this.hasAttribute('solid-color');
2485
+ break;
2486
+ }
2487
+ }
2488
+ }
2489
+ customElements.define('pc-sky', SkyElement);
2490
+
2491
+ exports.AppElement = AppElement;
2492
+ exports.AssetElement = AssetElement;
2493
+ exports.CameraComponentElement = CameraComponentElement;
2494
+ exports.CollisionComponentElement = CollisionComponentElement;
2495
+ exports.ComponentElement = ComponentElement;
2496
+ exports.ElementComponentElement = ElementComponentElement;
2497
+ exports.EntityElement = EntityElement;
2498
+ exports.GSplatComponentElement = GSplatComponentElement;
2499
+ exports.LightComponentElement = LightComponentElement;
2500
+ exports.ListenerComponentElement = ListenerComponentElement;
2501
+ exports.ModelElement = ModelElement;
2502
+ exports.ModuleElement = ModuleElement;
2503
+ exports.RenderComponentElement = RenderComponentElement;
2504
+ exports.RigidBodyComponentElement = RigidBodyComponentElement;
2505
+ exports.SceneElement = SceneElement;
2506
+ exports.ScriptComponentElement = ScriptComponentElement;
2507
+ exports.ScriptElement = ScriptElement;
2508
+ exports.SkyElement = SkyElement;
2509
+ exports.SoundComponentElement = SoundComponentElement;
2510
+ exports.SoundSlotElement = SoundSlotElement;
2511
+
2512
+ }));
2513
+ //# sourceMappingURL=pwc.js.map