@playcanvas/web-components 0.11.0 → 0.11.1
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 +1 -1
- package/dist/app.d.ts +18 -38
- package/dist/asset.d.ts +8 -7
- package/dist/async-element.d.ts +21 -5
- package/dist/components/button-component.d.ts +3 -7
- package/dist/components/camera-component.d.ts +3 -7
- package/dist/components/collision-component.d.ts +3 -7
- package/dist/components/component.d.ts +22 -4
- package/dist/components/element-component.d.ts +4 -8
- package/dist/components/gsplat-component.d.ts +2 -7
- package/dist/components/layoutchild-component.d.ts +2 -7
- package/dist/components/layoutgroup-component.d.ts +3 -7
- package/dist/components/light-component.d.ts +3 -7
- package/dist/components/listener-component.d.ts +1 -6
- package/dist/components/particlesystem-component.d.ts +2 -7
- package/dist/components/render-component.d.ts +2 -7
- package/dist/components/rigidbody-component.d.ts +3 -7
- package/dist/components/screen-component.d.ts +3 -7
- package/dist/components/script-component.d.ts +8 -20
- package/dist/components/script.d.ts +2 -22
- package/dist/components/scrollbar-component.d.ts +2 -7
- package/dist/components/scrollview-component.d.ts +3 -7
- package/dist/components/sound-component.d.ts +2 -7
- package/dist/components/sound-slot.d.ts +8 -6
- package/dist/custom-elements.json +5049 -10696
- package/dist/entity.d.ts +5 -11
- package/dist/index.d.ts +37 -0
- package/dist/material.d.ts +12 -12
- package/dist/model.d.ts +21 -5
- package/dist/module.d.ts +0 -6
- package/dist/parse.d.ts +2 -1
- package/dist/pwc.cjs +496 -136
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +496 -136
- 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.min.mjs +1 -1
- package/dist/pwc.min.mjs.map +1 -1
- package/dist/pwc.mjs +496 -136
- package/dist/pwc.mjs.map +1 -1
- package/dist/scene.d.ts +4 -7
- package/dist/sky.d.ts +13 -5
- package/dist/vscode.html-custom-data.json +26 -26
- package/dist/web-types.json +545 -536
- package/package.json +8 -7
- package/src/app.ts +142 -70
- package/src/asset.ts +34 -28
- package/src/async-element.ts +34 -8
- package/src/components/button-component.ts +5 -9
- package/src/components/camera-component.ts +24 -10
- package/src/components/collision-component.ts +26 -15
- package/src/components/component.ts +58 -8
- package/src/components/element-component.ts +26 -30
- package/src/components/gsplat-component.ts +4 -9
- package/src/components/layoutchild-component.ts +4 -9
- package/src/components/layoutgroup-component.ts +14 -9
- package/src/components/light-component.ts +42 -12
- package/src/components/listener-component.ts +1 -7
- package/src/components/particlesystem-component.ts +7 -15
- package/src/components/render-component.ts +5 -10
- package/src/components/rigidbody-component.ts +23 -16
- package/src/components/screen-component.ts +5 -9
- package/src/components/script-component.ts +108 -46
- package/src/components/script.ts +38 -33
- package/src/components/scrollbar-component.ts +6 -16
- package/src/components/scrollview-component.ts +16 -11
- package/src/components/sound-component.ts +10 -15
- package/src/components/sound-slot.ts +30 -20
- package/src/entity.ts +42 -19
- package/src/index.ts +45 -1
- package/src/loading-bar.ts +8 -8
- package/src/material.ts +63 -37
- package/src/model.ts +69 -14
- package/src/module.ts +8 -7
- package/src/parse.ts +62 -17
- package/src/scene.ts +12 -9
- package/src/sky.ts +50 -9
package/src/sky.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { Asset,
|
|
1
|
+
import type { Asset, EventHandle, Scene, Texture } from 'playcanvas';
|
|
2
|
+
import { EnvLighting, LAYERID_SKYBOX, Quat, Vec3 } from 'playcanvas';
|
|
2
3
|
|
|
3
|
-
import { AppElement } from './app';
|
|
4
|
+
import type { AppElement } from './app';
|
|
4
5
|
import { AssetElement } from './asset';
|
|
5
6
|
import { AsyncElement } from './async-element';
|
|
6
7
|
import { parseBool, parseEnum, parseNumber, parseVec3 } from './parse';
|
|
@@ -31,14 +32,36 @@ class SkyElement extends AsyncElement {
|
|
|
31
32
|
|
|
32
33
|
private _appElement: AppElement | null = null;
|
|
33
34
|
|
|
35
|
+
/**
|
|
36
|
+
* Incremented on every new load and on disconnect, and captured by a load when it starts. A
|
|
37
|
+
* load that resumes from an await or a load callback abandons itself if the value has moved
|
|
38
|
+
* on, so a superseded load cannot generate a skybox for a scene it no longer configures.
|
|
39
|
+
*/
|
|
40
|
+
private _loadGeneration = 0;
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* The pending asset-load subscription of the current load, if it is waiting for its asset.
|
|
44
|
+
* Held so that whatever supersedes the load can detach the handler from the asset, rather
|
|
45
|
+
* than leave it registered until the asset loads (or forever, if it never does).
|
|
46
|
+
*/
|
|
47
|
+
private _loadHandle: EventHandle | null = null;
|
|
48
|
+
|
|
34
49
|
connectedCallback() {
|
|
35
50
|
this._loadSkybox();
|
|
36
51
|
this._onReady();
|
|
37
52
|
}
|
|
38
53
|
|
|
39
54
|
disconnectedCallback() {
|
|
55
|
+
this._loadGeneration++;
|
|
56
|
+
this._detachLoadHandler();
|
|
40
57
|
this._unloadSkybox();
|
|
41
58
|
this._appElement = null;
|
|
59
|
+
this._resetReady();
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private _detachLoadHandler() {
|
|
63
|
+
this._loadHandle?.off();
|
|
64
|
+
this._loadHandle = null;
|
|
42
65
|
}
|
|
43
66
|
|
|
44
67
|
private _generateSkybox(asset: Asset) {
|
|
@@ -48,11 +71,18 @@ class SkyElement extends AsyncElement {
|
|
|
48
71
|
|
|
49
72
|
const skybox = EnvLighting.generateSkyboxCubemap(source);
|
|
50
73
|
skybox.anisotropy = 4;
|
|
74
|
+
// This element owns what it generated (see _unloadSkybox) - replacing a skybox from an
|
|
75
|
+
// earlier load must release it, not orphan it on the GPU
|
|
76
|
+
this._scene.skybox?.destroy();
|
|
51
77
|
this._scene.skybox = skybox;
|
|
52
78
|
|
|
53
79
|
if (this._lighting) {
|
|
54
80
|
const lighting = EnvLighting.generateLightingSource(source);
|
|
55
81
|
const envAtlas = EnvLighting.generateAtlas(lighting);
|
|
82
|
+
// The lighting source is an intermediate: the atlas is rendered from it and it is
|
|
83
|
+
// not needed afterwards
|
|
84
|
+
lighting.destroy();
|
|
85
|
+
this._scene.envAtlas?.destroy();
|
|
56
86
|
this._scene.envAtlas = envAtlas;
|
|
57
87
|
}
|
|
58
88
|
|
|
@@ -69,7 +99,17 @@ class SkyElement extends AsyncElement {
|
|
|
69
99
|
}
|
|
70
100
|
|
|
71
101
|
private async _loadSkybox() {
|
|
102
|
+
// Supersede any load already in flight - only the newest load may generate the skybox
|
|
103
|
+
const generation = ++this._loadGeneration;
|
|
104
|
+
this._detachLoadHandler();
|
|
105
|
+
|
|
72
106
|
const appElement = await this.closestApp?.ready();
|
|
107
|
+
|
|
108
|
+
// The element may have been removed, or another load started, while we waited
|
|
109
|
+
if (generation !== this._loadGeneration) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
|
|
73
113
|
const app = appElement?.app;
|
|
74
114
|
if (!appElement || !app) {
|
|
75
115
|
return;
|
|
@@ -87,7 +127,14 @@ class SkyElement extends AsyncElement {
|
|
|
87
127
|
if (asset.loaded) {
|
|
88
128
|
this._generateSkybox(asset);
|
|
89
129
|
} else {
|
|
90
|
-
|
|
130
|
+
// The generation is re-checked even though a superseded handler is detached: the
|
|
131
|
+
// detach relies on how the engine's event emitter treats removal, while the check
|
|
132
|
+
// holds on its own.
|
|
133
|
+
this._loadHandle = asset.once('load', () => {
|
|
134
|
+
this._loadHandle = null;
|
|
135
|
+
if (generation !== this._loadGeneration) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
91
138
|
this._generateSkybox(asset);
|
|
92
139
|
});
|
|
93
140
|
app.assets.load(asset);
|
|
@@ -303,10 +350,4 @@ class SkyElement extends AsyncElement {
|
|
|
303
350
|
|
|
304
351
|
customElements.define('pc-sky', SkyElement);
|
|
305
352
|
|
|
306
|
-
declare global {
|
|
307
|
-
interface HTMLElementTagNameMap {
|
|
308
|
-
'pc-sky': SkyElement;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
|
|
312
353
|
export { SkyElement };
|