@playcanvas/web-components 0.1.4 → 0.1.5
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/README.md +12 -24
- package/dist/app.d.ts +11 -4
- package/dist/asset.d.ts +0 -1
- package/dist/async-element.d.ts +23 -0
- package/dist/components/camera-component.d.ts +3 -0
- package/dist/components/component.d.ts +4 -2
- package/dist/components/element-component.d.ts +1 -1
- package/dist/components/render-component.d.ts +2 -2
- package/dist/components/script-component.d.ts +1 -1
- package/dist/components/sound-slot.d.ts +2 -1
- package/dist/entity.d.ts +2 -3
- package/dist/index.d.ts +10 -1
- package/dist/model.d.ts +2 -1
- package/dist/pwc.cjs +212 -127
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +212 -127
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.mjs +213 -129
- package/dist/pwc.mjs.map +1 -1
- package/dist/scene.d.ts +2 -1
- package/dist/sky.d.ts +15 -6
- package/package.json +7 -6
- package/src/app.ts +12 -15
- package/src/asset.ts +1 -3
- package/src/async-element.ts +45 -0
- package/src/components/camera-component.ts +22 -1
- package/src/components/component.ts +15 -26
- package/src/components/element-component.ts +15 -4
- package/src/components/render-component.ts +1 -6
- package/src/components/script-component.ts +1 -3
- package/src/components/sound-slot.ts +7 -10
- package/src/entity.ts +19 -29
- package/src/index.ts +11 -0
- package/src/model.ts +20 -15
- package/src/scene.ts +6 -11
- package/src/sky.ts +82 -40
package/dist/pwc.cjs
CHANGED
|
@@ -2,6 +2,41 @@
|
|
|
2
2
|
|
|
3
3
|
var playcanvas = require('playcanvas');
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* Base class for all PlayCanvas web components that initialize asynchronously.
|
|
7
|
+
*/
|
|
8
|
+
class AsyncElement extends HTMLElement {
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
this._readyPromise = new Promise((resolve) => {
|
|
12
|
+
this._readyResolve = resolve;
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
get closestApp() {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.closest('pc-app');
|
|
18
|
+
}
|
|
19
|
+
get closestEntity() {
|
|
20
|
+
var _a;
|
|
21
|
+
return (_a = this.parentElement) === null || _a === void 0 ? void 0 : _a.closest('pc-entity');
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Called when the element is fully initialized and ready.
|
|
25
|
+
* Subclasses should call this when they're ready.
|
|
26
|
+
*/
|
|
27
|
+
_onReady() {
|
|
28
|
+
this._readyResolve();
|
|
29
|
+
this.dispatchEvent(new CustomEvent('ready'));
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Returns a promise that resolves with this element when it's ready.
|
|
33
|
+
* @returns A promise that resolves with this element when it's ready.
|
|
34
|
+
*/
|
|
35
|
+
ready() {
|
|
36
|
+
return this._readyPromise.then(() => this);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
5
40
|
class ModuleElement extends HTMLElement {
|
|
6
41
|
constructor() {
|
|
7
42
|
super();
|
|
@@ -30,7 +65,7 @@ customElements.define('pc-module', ModuleElement);
|
|
|
30
65
|
/**
|
|
31
66
|
* The main application element.
|
|
32
67
|
*/
|
|
33
|
-
class AppElement extends
|
|
68
|
+
class AppElement extends AsyncElement {
|
|
34
69
|
/**
|
|
35
70
|
* Creates a new AppElement.
|
|
36
71
|
*/
|
|
@@ -47,9 +82,6 @@ class AppElement extends HTMLElement {
|
|
|
47
82
|
this.app = null;
|
|
48
83
|
// Bind methods to maintain 'this' context
|
|
49
84
|
this._onWindowResize = this._onWindowResize.bind(this);
|
|
50
|
-
this.appReadyPromise = new Promise((resolve) => {
|
|
51
|
-
this.appReadyResolve = resolve;
|
|
52
|
-
});
|
|
53
85
|
}
|
|
54
86
|
async connectedCallback() {
|
|
55
87
|
// Get all pc-module elements that are direct children of the pc-app element
|
|
@@ -89,7 +121,7 @@ class AppElement extends HTMLElement {
|
|
|
89
121
|
this.app.start();
|
|
90
122
|
// Handle window resize to keep the canvas responsive
|
|
91
123
|
window.addEventListener('resize', this._onWindowResize);
|
|
92
|
-
this.
|
|
124
|
+
this._onReady();
|
|
93
125
|
});
|
|
94
126
|
}
|
|
95
127
|
disconnectedCallback() {
|
|
@@ -106,21 +138,26 @@ class AppElement extends HTMLElement {
|
|
|
106
138
|
this._canvas = null;
|
|
107
139
|
}
|
|
108
140
|
}
|
|
109
|
-
async getApplication() {
|
|
110
|
-
await this.appReadyPromise;
|
|
111
|
-
return this.app;
|
|
112
|
-
}
|
|
113
141
|
_onWindowResize() {
|
|
114
142
|
if (this.app) {
|
|
115
143
|
this.app.resizeCanvas();
|
|
116
144
|
}
|
|
117
145
|
}
|
|
146
|
+
/**
|
|
147
|
+
* Sets the high resolution flag. When true, the application will render at the device's
|
|
148
|
+
* physical resolution. When false, the application will render at CSS resolution.
|
|
149
|
+
* @param value - The high resolution flag.
|
|
150
|
+
*/
|
|
118
151
|
set highResolution(value) {
|
|
119
152
|
this._highResolution = value;
|
|
120
153
|
if (this.app) {
|
|
121
154
|
this.app.graphicsDevice.maxPixelRatio = value ? window.devicePixelRatio : 1;
|
|
122
155
|
}
|
|
123
156
|
}
|
|
157
|
+
/**
|
|
158
|
+
* Gets the high resolution flag.
|
|
159
|
+
* @returns The high resolution flag.
|
|
160
|
+
*/
|
|
124
161
|
get highResolution() {
|
|
125
162
|
return this._highResolution;
|
|
126
163
|
}
|
|
@@ -197,7 +234,7 @@ const parseVec4 = (value) => {
|
|
|
197
234
|
/**
|
|
198
235
|
* Represents an entity in the PlayCanvas engine.
|
|
199
236
|
*/
|
|
200
|
-
class EntityElement extends
|
|
237
|
+
class EntityElement extends AsyncElement {
|
|
201
238
|
constructor() {
|
|
202
239
|
super(...arguments);
|
|
203
240
|
/**
|
|
@@ -224,33 +261,20 @@ class EntityElement extends HTMLElement {
|
|
|
224
261
|
* The tags of the entity.
|
|
225
262
|
*/
|
|
226
263
|
this._tags = [];
|
|
227
|
-
this._entityReady = new Promise((resolve) => {
|
|
228
|
-
this._resolveEntity = resolve;
|
|
229
|
-
});
|
|
230
264
|
/**
|
|
231
265
|
* The PlayCanvas entity instance.
|
|
232
266
|
*/
|
|
233
267
|
this.entity = null;
|
|
234
268
|
}
|
|
235
269
|
async connectedCallback() {
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
if (!appElement) {
|
|
239
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
270
|
+
const closestApp = this.closestApp;
|
|
271
|
+
if (!closestApp)
|
|
240
272
|
return;
|
|
241
|
-
|
|
242
|
-
|
|
273
|
+
// Wait for the app to complete initialization
|
|
274
|
+
await closestApp.ready();
|
|
275
|
+
const app = closestApp.app;
|
|
243
276
|
// Create a new entity
|
|
244
277
|
this.entity = new playcanvas.Entity(this._name, app);
|
|
245
|
-
this._resolveEntity(this.entity);
|
|
246
|
-
if (this.parentElement &&
|
|
247
|
-
this.parentElement.tagName.toLowerCase() === 'pc-entity') {
|
|
248
|
-
const parentEntity = await this.parentElement._entityReady;
|
|
249
|
-
parentEntity.addChild(this.entity);
|
|
250
|
-
}
|
|
251
|
-
else {
|
|
252
|
-
app.root.addChild(this.entity);
|
|
253
|
-
}
|
|
254
278
|
// Initialize from attributes
|
|
255
279
|
const nameAttr = this.getAttribute('name');
|
|
256
280
|
const positionAttr = this.getAttribute('position');
|
|
@@ -267,6 +291,17 @@ class EntityElement extends HTMLElement {
|
|
|
267
291
|
this.scale = parseVec3(scaleAttr);
|
|
268
292
|
if (tagsAttr)
|
|
269
293
|
this.tags = tagsAttr.split(',').map(tag => tag.trim());
|
|
294
|
+
const closestEntity = this.closestEntity;
|
|
295
|
+
if (closestEntity) {
|
|
296
|
+
closestEntity.ready().then(() => {
|
|
297
|
+
closestEntity.entity.addChild(this.entity);
|
|
298
|
+
this._onReady();
|
|
299
|
+
});
|
|
300
|
+
}
|
|
301
|
+
else {
|
|
302
|
+
app.root.addChild(this.entity);
|
|
303
|
+
this._onReady();
|
|
304
|
+
}
|
|
270
305
|
}
|
|
271
306
|
disconnectedCallback() {
|
|
272
307
|
if (this.entity) {
|
|
@@ -278,10 +313,6 @@ class EntityElement extends HTMLElement {
|
|
|
278
313
|
this.entity.destroy();
|
|
279
314
|
this.entity = null;
|
|
280
315
|
}
|
|
281
|
-
// Reset the promise for potential reconnection
|
|
282
|
-
this._entityReady = new Promise((resolve) => {
|
|
283
|
-
this._resolveEntity = resolve;
|
|
284
|
-
});
|
|
285
316
|
}
|
|
286
317
|
/**
|
|
287
318
|
* Sets the enabled state of the entity.
|
|
@@ -420,6 +451,7 @@ const extToType = new Map([
|
|
|
420
451
|
['frag', 'shader'],
|
|
421
452
|
['glb', 'container'],
|
|
422
453
|
['glsl', 'shader'],
|
|
454
|
+
['hdr', 'texture'],
|
|
423
455
|
['html', 'html'],
|
|
424
456
|
['jpg', 'texture'],
|
|
425
457
|
['js', 'script'],
|
|
@@ -444,8 +476,6 @@ class AssetElement extends HTMLElement {
|
|
|
444
476
|
*/
|
|
445
477
|
this.asset = null;
|
|
446
478
|
}
|
|
447
|
-
async connectedCallback() {
|
|
448
|
-
}
|
|
449
479
|
disconnectedCallback() {
|
|
450
480
|
this.destroyAsset();
|
|
451
481
|
}
|
|
@@ -509,7 +539,7 @@ customElements.define('pc-asset', AssetElement);
|
|
|
509
539
|
*
|
|
510
540
|
* @category Components
|
|
511
541
|
*/
|
|
512
|
-
class ComponentElement extends
|
|
542
|
+
class ComponentElement extends AsyncElement {
|
|
513
543
|
/**
|
|
514
544
|
* Constructor for the ComponentElement.
|
|
515
545
|
* @param componentName - The name of the component.
|
|
@@ -524,27 +554,23 @@ class ComponentElement extends HTMLElement {
|
|
|
524
554
|
getInitialComponentData() {
|
|
525
555
|
return {};
|
|
526
556
|
}
|
|
527
|
-
async
|
|
528
|
-
const
|
|
529
|
-
if (
|
|
530
|
-
|
|
531
|
-
return;
|
|
532
|
-
}
|
|
533
|
-
await appElement.getApplication();
|
|
534
|
-
this.addComponent();
|
|
535
|
-
}
|
|
536
|
-
addComponent() {
|
|
537
|
-
// Access the parent pc-entity's 'entity' property
|
|
538
|
-
const entityElement = this.closest('pc-entity');
|
|
539
|
-
if (!entityElement) {
|
|
540
|
-
console.error(`${this.tagName.toLowerCase()} should be a child of pc-entity`);
|
|
541
|
-
return;
|
|
542
|
-
}
|
|
543
|
-
if (entityElement && entityElement.entity) {
|
|
557
|
+
async addComponent() {
|
|
558
|
+
const entityElement = this.closestEntity;
|
|
559
|
+
if (entityElement) {
|
|
560
|
+
await entityElement.ready();
|
|
544
561
|
// Add the component to the entity
|
|
545
|
-
|
|
562
|
+
const data = this.getInitialComponentData();
|
|
563
|
+
this._component = entityElement.entity.addComponent(this._componentName, data);
|
|
546
564
|
}
|
|
547
565
|
}
|
|
566
|
+
initComponent() { }
|
|
567
|
+
async connectedCallback() {
|
|
568
|
+
var _a;
|
|
569
|
+
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
570
|
+
await this.addComponent();
|
|
571
|
+
this.initComponent();
|
|
572
|
+
this._onReady();
|
|
573
|
+
}
|
|
548
574
|
disconnectedCallback() {
|
|
549
575
|
// Remove the component when the element is disconnected
|
|
550
576
|
if (this.component && this.component.entity) {
|
|
@@ -649,6 +675,26 @@ class CameraComponentElement extends ComponentElement {
|
|
|
649
675
|
scissorRect: this._scissorRect
|
|
650
676
|
};
|
|
651
677
|
}
|
|
678
|
+
get xrAvailable() {
|
|
679
|
+
var _a;
|
|
680
|
+
const xrManager = (_a = this.component) === null || _a === void 0 ? void 0 : _a.system.app.xr;
|
|
681
|
+
return xrManager && xrManager.supported && xrManager.isAvailable(playcanvas.XRTYPE_VR);
|
|
682
|
+
}
|
|
683
|
+
startXr(type, space) {
|
|
684
|
+
if (this.component && this.xrAvailable) {
|
|
685
|
+
this.component.startXr(type, space, {
|
|
686
|
+
callback: (err) => {
|
|
687
|
+
if (err)
|
|
688
|
+
console.error(`WebXR Immersive VR failed to start: ${err.message}`);
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
endXr() {
|
|
694
|
+
if (this.component) {
|
|
695
|
+
this.component.endXr();
|
|
696
|
+
}
|
|
697
|
+
}
|
|
652
698
|
/**
|
|
653
699
|
* Gets the camera component.
|
|
654
700
|
* @returns The camera component.
|
|
@@ -1150,8 +1196,7 @@ class ElementComponentElement extends ComponentElement {
|
|
|
1150
1196
|
this._width = 0;
|
|
1151
1197
|
this._wrapLines = false;
|
|
1152
1198
|
}
|
|
1153
|
-
|
|
1154
|
-
await super.connectedCallback();
|
|
1199
|
+
initComponent() {
|
|
1155
1200
|
this.component._text._material.useFog = true;
|
|
1156
1201
|
}
|
|
1157
1202
|
getInitialComponentData() {
|
|
@@ -1285,7 +1330,20 @@ class ElementComponentElement extends ComponentElement {
|
|
|
1285
1330
|
return this._wrapLines;
|
|
1286
1331
|
}
|
|
1287
1332
|
static get observedAttributes() {
|
|
1288
|
-
return [
|
|
1333
|
+
return [
|
|
1334
|
+
...super.observedAttributes,
|
|
1335
|
+
'anchor',
|
|
1336
|
+
'asset',
|
|
1337
|
+
'auto-width',
|
|
1338
|
+
'color',
|
|
1339
|
+
'font-size',
|
|
1340
|
+
'line-height',
|
|
1341
|
+
'pivot',
|
|
1342
|
+
'text',
|
|
1343
|
+
'type',
|
|
1344
|
+
'width',
|
|
1345
|
+
'wrap-lines'
|
|
1346
|
+
];
|
|
1289
1347
|
}
|
|
1290
1348
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1291
1349
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
@@ -1771,14 +1829,11 @@ class RenderComponentElement extends ComponentElement {
|
|
|
1771
1829
|
this._receiveShadows = true;
|
|
1772
1830
|
this._type = 'asset';
|
|
1773
1831
|
}
|
|
1774
|
-
async connectedCallback() {
|
|
1775
|
-
await super.connectedCallback();
|
|
1776
|
-
this.material = this._material;
|
|
1777
|
-
}
|
|
1778
1832
|
getInitialComponentData() {
|
|
1779
1833
|
return {
|
|
1780
1834
|
type: this._type,
|
|
1781
1835
|
castShadows: this._castShadows,
|
|
1836
|
+
material: MaterialElement.get(this._material),
|
|
1782
1837
|
receiveShadows: this._receiveShadows
|
|
1783
1838
|
};
|
|
1784
1839
|
}
|
|
@@ -2207,8 +2262,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
2207
2262
|
this.addEventListener('scriptattributeschange', this.handleScriptAttributesChange.bind(this));
|
|
2208
2263
|
this.addEventListener('scriptenablechange', this.handleScriptEnableChange.bind(this));
|
|
2209
2264
|
}
|
|
2210
|
-
|
|
2211
|
-
await super.connectedCallback();
|
|
2265
|
+
initComponent() {
|
|
2212
2266
|
// Handle initial script elements
|
|
2213
2267
|
this.querySelectorAll(':scope > pc-script').forEach((scriptElement) => {
|
|
2214
2268
|
const scriptName = scriptElement.getAttribute('name');
|
|
@@ -2478,7 +2532,7 @@ customElements.define('pc-sounds', SoundComponentElement);
|
|
|
2478
2532
|
/**
|
|
2479
2533
|
* Represents a sound slot in the PlayCanvas engine.
|
|
2480
2534
|
*/
|
|
2481
|
-
class SoundSlotElement extends
|
|
2535
|
+
class SoundSlotElement extends AsyncElement {
|
|
2482
2536
|
constructor() {
|
|
2483
2537
|
super(...arguments);
|
|
2484
2538
|
this._asset = '';
|
|
@@ -2496,12 +2550,8 @@ class SoundSlotElement extends HTMLElement {
|
|
|
2496
2550
|
this.soundSlot = null;
|
|
2497
2551
|
}
|
|
2498
2552
|
async connectedCallback() {
|
|
2499
|
-
|
|
2500
|
-
|
|
2501
|
-
console.error(`${this.tagName.toLowerCase()} should be a descendant of pc-app`);
|
|
2502
|
-
return;
|
|
2503
|
-
}
|
|
2504
|
-
await appElement.getApplication();
|
|
2553
|
+
var _a;
|
|
2554
|
+
await ((_a = this.soundElement) === null || _a === void 0 ? void 0 : _a.ready());
|
|
2505
2555
|
const options = {
|
|
2506
2556
|
autoPlay: this._autoPlay,
|
|
2507
2557
|
loop: this._loop,
|
|
@@ -2516,6 +2566,7 @@ class SoundSlotElement extends HTMLElement {
|
|
|
2516
2566
|
this.soundSlot = this.soundElement.component.addSlot(this._name, options);
|
|
2517
2567
|
this.asset = this._asset;
|
|
2518
2568
|
this.soundSlot.play();
|
|
2569
|
+
this._onReady();
|
|
2519
2570
|
}
|
|
2520
2571
|
disconnectedCallback() {
|
|
2521
2572
|
this.soundElement.component.removeSlot(this._name);
|
|
@@ -2722,23 +2773,19 @@ customElements.define('pc-sound', SoundSlotElement);
|
|
|
2722
2773
|
/**
|
|
2723
2774
|
* Represents a model in the PlayCanvas engine.
|
|
2724
2775
|
*/
|
|
2725
|
-
class ModelElement extends
|
|
2776
|
+
class ModelElement extends AsyncElement {
|
|
2726
2777
|
constructor() {
|
|
2727
2778
|
super(...arguments);
|
|
2728
2779
|
this._asset = '';
|
|
2729
2780
|
}
|
|
2730
2781
|
async connectedCallback() {
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
if (!appElement) {
|
|
2734
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
2735
|
-
return;
|
|
2736
|
-
}
|
|
2737
|
-
await appElement.getApplication();
|
|
2782
|
+
var _a;
|
|
2783
|
+
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
2738
2784
|
const asset = this.getAttribute('asset');
|
|
2739
2785
|
if (asset) {
|
|
2740
2786
|
this.asset = asset;
|
|
2741
2787
|
}
|
|
2788
|
+
this._onReady();
|
|
2742
2789
|
}
|
|
2743
2790
|
_loadModel() {
|
|
2744
2791
|
const asset = AssetElement.get(this._asset);
|
|
@@ -2746,13 +2793,23 @@ class ModelElement extends HTMLElement {
|
|
|
2746
2793
|
return;
|
|
2747
2794
|
}
|
|
2748
2795
|
const entity = asset.resource.instantiateRenderEntity();
|
|
2749
|
-
|
|
2796
|
+
if (asset.resource.animations.length > 0) {
|
|
2797
|
+
entity.addComponent('anim');
|
|
2798
|
+
entity.anim.assignAnimation('animation', asset.resource.animations[0].resource);
|
|
2799
|
+
}
|
|
2800
|
+
const parentEntityElement = this.closestEntity;
|
|
2750
2801
|
if (parentEntityElement) {
|
|
2751
|
-
parentEntityElement.
|
|
2802
|
+
parentEntityElement.ready().then(() => {
|
|
2803
|
+
parentEntityElement.entity.addChild(entity);
|
|
2804
|
+
});
|
|
2752
2805
|
}
|
|
2753
2806
|
else {
|
|
2754
|
-
const appElement = this.
|
|
2755
|
-
appElement
|
|
2807
|
+
const appElement = this.closestApp;
|
|
2808
|
+
if (appElement) {
|
|
2809
|
+
appElement.ready().then(() => {
|
|
2810
|
+
appElement.app.root.addChild(entity);
|
|
2811
|
+
});
|
|
2812
|
+
}
|
|
2756
2813
|
}
|
|
2757
2814
|
}
|
|
2758
2815
|
/**
|
|
@@ -2786,7 +2843,7 @@ customElements.define('pc-model', ModelElement);
|
|
|
2786
2843
|
/**
|
|
2787
2844
|
* Represents a scene in the PlayCanvas engine.
|
|
2788
2845
|
*/
|
|
2789
|
-
class SceneElement extends
|
|
2846
|
+
class SceneElement extends AsyncElement {
|
|
2790
2847
|
constructor() {
|
|
2791
2848
|
super(...arguments);
|
|
2792
2849
|
/**
|
|
@@ -2815,15 +2872,11 @@ class SceneElement extends HTMLElement {
|
|
|
2815
2872
|
this.scene = null;
|
|
2816
2873
|
}
|
|
2817
2874
|
async connectedCallback() {
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
|
|
2821
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
2822
|
-
return;
|
|
2823
|
-
}
|
|
2824
|
-
const app = await appElement.getApplication();
|
|
2825
|
-
this.scene = app.scene;
|
|
2875
|
+
var _a;
|
|
2876
|
+
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
2877
|
+
this.scene = this.closestApp.app.scene;
|
|
2826
2878
|
this.updateSceneSettings();
|
|
2879
|
+
this._onReady();
|
|
2827
2880
|
}
|
|
2828
2881
|
updateSceneSettings() {
|
|
2829
2882
|
if (this.scene) {
|
|
@@ -2949,57 +3002,71 @@ customElements.define('pc-scene', SceneElement);
|
|
|
2949
3002
|
/**
|
|
2950
3003
|
* Represents a sky in the PlayCanvas engine.
|
|
2951
3004
|
*/
|
|
2952
|
-
class SkyElement extends
|
|
3005
|
+
class SkyElement extends AsyncElement {
|
|
2953
3006
|
constructor() {
|
|
2954
3007
|
super(...arguments);
|
|
2955
3008
|
this._asset = '';
|
|
3009
|
+
this._center = new playcanvas.Vec3(0, 0.01, 0);
|
|
2956
3010
|
this._intensity = 1;
|
|
2957
|
-
this._rotation =
|
|
3011
|
+
this._rotation = new playcanvas.Vec3();
|
|
2958
3012
|
this._level = 0;
|
|
2959
|
-
this.
|
|
3013
|
+
this._scale = new playcanvas.Vec3(100, 100, 100);
|
|
3014
|
+
this._type = 'infinite';
|
|
2960
3015
|
}
|
|
2961
3016
|
async connectedCallback() {
|
|
2962
|
-
|
|
2963
|
-
|
|
2964
|
-
if (!appElement) {
|
|
2965
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
2966
|
-
return;
|
|
2967
|
-
}
|
|
2968
|
-
await appElement.getApplication();
|
|
3017
|
+
var _a;
|
|
3018
|
+
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
2969
3019
|
this.asset = this.getAttribute('asset') || '';
|
|
2970
|
-
this.
|
|
3020
|
+
this._onReady();
|
|
2971
3021
|
}
|
|
2972
3022
|
getScene() {
|
|
2973
|
-
const
|
|
2974
|
-
if (!appElement) {
|
|
2975
|
-
return;
|
|
2976
|
-
}
|
|
2977
|
-
const app = appElement.app;
|
|
3023
|
+
const app = this.closestApp.app;
|
|
2978
3024
|
if (!app) {
|
|
2979
3025
|
return;
|
|
2980
3026
|
}
|
|
2981
3027
|
return app.scene;
|
|
2982
3028
|
}
|
|
3029
|
+
initSkybox(source) {
|
|
3030
|
+
source.anisotropy = 4;
|
|
3031
|
+
const skybox = playcanvas.EnvLighting.generateSkyboxCubemap(source);
|
|
3032
|
+
const lighting = playcanvas.EnvLighting.generateLightingSource(source);
|
|
3033
|
+
const envAtlas = playcanvas.EnvLighting.generateAtlas(lighting);
|
|
3034
|
+
const app = this.closestApp.app;
|
|
3035
|
+
if (app) {
|
|
3036
|
+
app.scene.envAtlas = envAtlas;
|
|
3037
|
+
app.scene.skybox = skybox;
|
|
3038
|
+
const layer = app.scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
|
|
3039
|
+
if (layer) {
|
|
3040
|
+
layer.enabled = this._type !== 'none';
|
|
3041
|
+
}
|
|
3042
|
+
app.scene.sky.type = this._type;
|
|
3043
|
+
app.scene.sky.node.setLocalScale(this._scale);
|
|
3044
|
+
app.scene.sky.center = this._center;
|
|
3045
|
+
}
|
|
3046
|
+
}
|
|
2983
3047
|
set asset(value) {
|
|
2984
3048
|
this._asset = value;
|
|
2985
3049
|
const scene = this.getScene();
|
|
2986
3050
|
if (scene) {
|
|
2987
3051
|
const asset = AssetElement.get(value);
|
|
2988
3052
|
if (asset) {
|
|
2989
|
-
|
|
2990
|
-
scene.envAtlas = asset.resource;
|
|
2991
|
-
}
|
|
2992
|
-
else {
|
|
2993
|
-
asset.once('load', () => {
|
|
2994
|
-
scene.envAtlas = asset.resource;
|
|
2995
|
-
});
|
|
2996
|
-
}
|
|
3053
|
+
this.initSkybox(asset.resource);
|
|
2997
3054
|
}
|
|
2998
3055
|
}
|
|
2999
3056
|
}
|
|
3000
3057
|
get asset() {
|
|
3001
3058
|
return this._asset;
|
|
3002
3059
|
}
|
|
3060
|
+
set center(value) {
|
|
3061
|
+
this._center = value;
|
|
3062
|
+
const scene = this.getScene();
|
|
3063
|
+
if (scene) {
|
|
3064
|
+
scene.sky.center = this._center;
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
get center() {
|
|
3068
|
+
return this._center;
|
|
3069
|
+
}
|
|
3003
3070
|
set intensity(value) {
|
|
3004
3071
|
this._intensity = value;
|
|
3005
3072
|
const scene = this.getScene();
|
|
@@ -3014,24 +3081,21 @@ class SkyElement extends HTMLElement {
|
|
|
3014
3081
|
this._rotation = value;
|
|
3015
3082
|
const scene = this.getScene();
|
|
3016
3083
|
if (scene) {
|
|
3017
|
-
scene.skyboxRotation = new playcanvas.Quat().setFromEulerAngles(
|
|
3084
|
+
scene.skyboxRotation = new playcanvas.Quat().setFromEulerAngles(value);
|
|
3018
3085
|
}
|
|
3019
3086
|
}
|
|
3020
3087
|
get rotation() {
|
|
3021
3088
|
return this._rotation;
|
|
3022
3089
|
}
|
|
3023
|
-
set
|
|
3024
|
-
this.
|
|
3090
|
+
set scale(value) {
|
|
3091
|
+
this._scale = value;
|
|
3025
3092
|
const scene = this.getScene();
|
|
3026
3093
|
if (scene) {
|
|
3027
|
-
|
|
3028
|
-
if (layer) {
|
|
3029
|
-
layer.enabled = !this._solidColor;
|
|
3030
|
-
}
|
|
3094
|
+
scene.sky.node.setLocalScale(this._scale);
|
|
3031
3095
|
}
|
|
3032
3096
|
}
|
|
3033
|
-
get
|
|
3034
|
-
return this.
|
|
3097
|
+
get scale() {
|
|
3098
|
+
return this._scale;
|
|
3035
3099
|
}
|
|
3036
3100
|
set level(value) {
|
|
3037
3101
|
this._level = value;
|
|
@@ -3043,25 +3107,45 @@ class SkyElement extends HTMLElement {
|
|
|
3043
3107
|
get level() {
|
|
3044
3108
|
return this._level;
|
|
3045
3109
|
}
|
|
3110
|
+
set type(value) {
|
|
3111
|
+
this._type = value;
|
|
3112
|
+
const scene = this.getScene();
|
|
3113
|
+
if (scene) {
|
|
3114
|
+
scene.sky.type = this._type;
|
|
3115
|
+
const layer = scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
|
|
3116
|
+
if (layer) {
|
|
3117
|
+
layer.enabled = this._type !== 'none';
|
|
3118
|
+
}
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
get type() {
|
|
3122
|
+
return this._type;
|
|
3123
|
+
}
|
|
3046
3124
|
static get observedAttributes() {
|
|
3047
|
-
return ['asset', 'intensity', 'level', 'rotation', '
|
|
3125
|
+
return ['asset', 'center', 'intensity', 'level', 'rotation', 'scale', 'type'];
|
|
3048
3126
|
}
|
|
3049
3127
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
3050
3128
|
switch (name) {
|
|
3051
3129
|
case 'asset':
|
|
3052
3130
|
this.asset = newValue;
|
|
3053
3131
|
break;
|
|
3132
|
+
case 'center':
|
|
3133
|
+
this.center = parseVec3(newValue);
|
|
3134
|
+
break;
|
|
3054
3135
|
case 'intensity':
|
|
3055
3136
|
this.intensity = parseFloat(newValue);
|
|
3056
3137
|
break;
|
|
3057
3138
|
case 'rotation':
|
|
3058
|
-
this.rotation = newValue
|
|
3139
|
+
this.rotation = parseVec3(newValue);
|
|
3059
3140
|
break;
|
|
3060
3141
|
case 'level':
|
|
3061
3142
|
this.level = parseInt(newValue, 10);
|
|
3062
3143
|
break;
|
|
3063
|
-
case '
|
|
3064
|
-
this.
|
|
3144
|
+
case 'scale':
|
|
3145
|
+
this.scale = parseVec3(newValue);
|
|
3146
|
+
break;
|
|
3147
|
+
case 'type':
|
|
3148
|
+
this.type = newValue;
|
|
3065
3149
|
break;
|
|
3066
3150
|
}
|
|
3067
3151
|
}
|
|
@@ -3070,6 +3154,7 @@ customElements.define('pc-sky', SkyElement);
|
|
|
3070
3154
|
|
|
3071
3155
|
exports.AppElement = AppElement;
|
|
3072
3156
|
exports.AssetElement = AssetElement;
|
|
3157
|
+
exports.AsyncElement = AsyncElement;
|
|
3073
3158
|
exports.CameraComponentElement = CameraComponentElement;
|
|
3074
3159
|
exports.CollisionComponentElement = CollisionComponentElement;
|
|
3075
3160
|
exports.ComponentElement = ComponentElement;
|