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