@playcanvas/web-components 0.1.4 → 0.1.6
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 +43 -61
- package/dist/app.d.ts +56 -5
- 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-component.d.ts +48 -0
- 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 +426 -141
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +426 -141
- 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 +427 -143
- package/dist/pwc.mjs.map +1 -1
- package/dist/scene.d.ts +2 -1
- package/dist/sky.d.ts +15 -6
- package/package.json +9 -8
- package/src/app.ts +103 -17
- 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 +25 -7
- package/src/components/sound-component.ts +110 -1
- 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/module.ts +18 -10
- package/src/scene.ts +6 -11
- package/src/sky.ts +82 -40
package/src/scene.ts
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Color, Scene } from 'playcanvas';
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import { AsyncElement } from './async-element';
|
|
4
4
|
import { parseColor } from './utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a scene in the PlayCanvas engine.
|
|
8
8
|
*/
|
|
9
|
-
class SceneElement extends
|
|
9
|
+
class SceneElement extends AsyncElement {
|
|
10
10
|
/**
|
|
11
11
|
* The fog type of the scene.
|
|
12
12
|
*/
|
|
@@ -38,17 +38,12 @@ class SceneElement extends HTMLElement {
|
|
|
38
38
|
scene: Scene | null = null;
|
|
39
39
|
|
|
40
40
|
async connectedCallback() {
|
|
41
|
-
|
|
42
|
-
const appElement = this.closest('pc-app') as AppElement;
|
|
43
|
-
if (!appElement) {
|
|
44
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const app = await appElement.getApplication();
|
|
41
|
+
await this.closestApp?.ready();
|
|
49
42
|
|
|
50
|
-
this.scene = app
|
|
43
|
+
this.scene = this.closestApp!.app!.scene;
|
|
51
44
|
this.updateSceneSettings();
|
|
45
|
+
|
|
46
|
+
this._onReady();
|
|
52
47
|
}
|
|
53
48
|
|
|
54
49
|
updateSceneSettings() {
|
package/src/sky.ts
CHANGED
|
@@ -1,61 +1,72 @@
|
|
|
1
|
-
import { LAYERID_SKYBOX, Quat } from 'playcanvas';
|
|
1
|
+
import { EnvLighting, LAYERID_SKYBOX, Quat, Texture, Vec3 } from 'playcanvas';
|
|
2
2
|
|
|
3
|
-
import { AppElement } from './app';
|
|
4
3
|
import { AssetElement } from './asset';
|
|
4
|
+
import { AsyncElement } from './async-element';
|
|
5
|
+
import { parseVec3 } from './utils';
|
|
5
6
|
|
|
6
7
|
/**
|
|
7
8
|
* Represents a sky in the PlayCanvas engine.
|
|
8
9
|
*/
|
|
9
|
-
class SkyElement extends
|
|
10
|
+
class SkyElement extends AsyncElement {
|
|
10
11
|
private _asset = '';
|
|
11
12
|
|
|
13
|
+
private _center = new Vec3(0, 0.01, 0);
|
|
14
|
+
|
|
12
15
|
private _intensity = 1;
|
|
13
16
|
|
|
14
|
-
private _rotation =
|
|
17
|
+
private _rotation = new Vec3();
|
|
15
18
|
|
|
16
19
|
private _level = 0;
|
|
17
20
|
|
|
18
|
-
private
|
|
21
|
+
private _scale = new Vec3(100, 100, 100);
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
// Get the application
|
|
22
|
-
const appElement = this.closest('pc-app') as AppElement;
|
|
23
|
-
if (!appElement) {
|
|
24
|
-
console.warn(`${this.tagName} must be a child of pc-app`);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
23
|
+
private _type: 'box' | 'dome' | 'infinite' | 'none' = 'infinite';
|
|
27
24
|
|
|
28
|
-
|
|
25
|
+
async connectedCallback() {
|
|
26
|
+
await this.closestApp?.ready();
|
|
29
27
|
|
|
30
28
|
this.asset = this.getAttribute('asset') || '';
|
|
31
|
-
|
|
29
|
+
|
|
30
|
+
this._onReady();
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
getScene() {
|
|
35
|
-
const
|
|
36
|
-
if (!appElement) {
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const app = appElement.app;
|
|
34
|
+
const app = this.closestApp!.app;
|
|
40
35
|
if (!app) {
|
|
41
36
|
return;
|
|
42
37
|
}
|
|
43
38
|
return app.scene;
|
|
44
39
|
}
|
|
45
40
|
|
|
41
|
+
private initSkybox(source: Texture) {
|
|
42
|
+
source.anisotropy = 4;
|
|
43
|
+
|
|
44
|
+
const skybox = EnvLighting.generateSkyboxCubemap(source);
|
|
45
|
+
const lighting = EnvLighting.generateLightingSource(source);
|
|
46
|
+
const envAtlas = EnvLighting.generateAtlas(lighting);
|
|
47
|
+
const app = this.closestApp!.app;
|
|
48
|
+
if (app) {
|
|
49
|
+
app.scene.envAtlas = envAtlas;
|
|
50
|
+
app.scene.skybox = skybox;
|
|
51
|
+
|
|
52
|
+
const layer = app.scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
53
|
+
if (layer) {
|
|
54
|
+
layer.enabled = this._type !== 'none';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
app.scene.sky.type = this._type;
|
|
58
|
+
app.scene.sky.node.setLocalScale(this._scale);
|
|
59
|
+
app.scene.sky.center = this._center;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
46
63
|
set asset(value: string) {
|
|
47
64
|
this._asset = value;
|
|
48
65
|
const scene = this.getScene();
|
|
49
66
|
if (scene) {
|
|
50
67
|
const asset = AssetElement.get(value);
|
|
51
68
|
if (asset) {
|
|
52
|
-
|
|
53
|
-
scene.envAtlas = asset.resource;
|
|
54
|
-
} else {
|
|
55
|
-
asset.once('load', () => {
|
|
56
|
-
scene.envAtlas = asset.resource;
|
|
57
|
-
});
|
|
58
|
-
}
|
|
69
|
+
this.initSkybox(asset.resource);
|
|
59
70
|
}
|
|
60
71
|
}
|
|
61
72
|
}
|
|
@@ -64,6 +75,18 @@ class SkyElement extends HTMLElement {
|
|
|
64
75
|
return this._asset;
|
|
65
76
|
}
|
|
66
77
|
|
|
78
|
+
set center(value: Vec3) {
|
|
79
|
+
this._center = value;
|
|
80
|
+
const scene = this.getScene();
|
|
81
|
+
if (scene) {
|
|
82
|
+
scene.sky.center = this._center;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
get center() {
|
|
87
|
+
return this._center;
|
|
88
|
+
}
|
|
89
|
+
|
|
67
90
|
set intensity(value: number) {
|
|
68
91
|
this._intensity = value;
|
|
69
92
|
const scene = this.getScene();
|
|
@@ -76,11 +99,11 @@ class SkyElement extends HTMLElement {
|
|
|
76
99
|
return this._intensity;
|
|
77
100
|
}
|
|
78
101
|
|
|
79
|
-
set rotation(value:
|
|
102
|
+
set rotation(value: Vec3) {
|
|
80
103
|
this._rotation = value;
|
|
81
104
|
const scene = this.getScene();
|
|
82
105
|
if (scene) {
|
|
83
|
-
scene.skyboxRotation = new Quat().setFromEulerAngles(
|
|
106
|
+
scene.skyboxRotation = new Quat().setFromEulerAngles(value);
|
|
84
107
|
}
|
|
85
108
|
}
|
|
86
109
|
|
|
@@ -88,19 +111,16 @@ class SkyElement extends HTMLElement {
|
|
|
88
111
|
return this._rotation;
|
|
89
112
|
}
|
|
90
113
|
|
|
91
|
-
set
|
|
92
|
-
this.
|
|
114
|
+
set scale(value: Vec3) {
|
|
115
|
+
this._scale = value;
|
|
93
116
|
const scene = this.getScene();
|
|
94
117
|
if (scene) {
|
|
95
|
-
|
|
96
|
-
if (layer) {
|
|
97
|
-
layer.enabled = !this._solidColor;
|
|
98
|
-
}
|
|
118
|
+
scene.sky.node.setLocalScale(this._scale);
|
|
99
119
|
}
|
|
100
120
|
}
|
|
101
121
|
|
|
102
|
-
get
|
|
103
|
-
return this.
|
|
122
|
+
get scale() {
|
|
123
|
+
return this._scale;
|
|
104
124
|
}
|
|
105
125
|
|
|
106
126
|
set level(value: number) {
|
|
@@ -115,8 +135,24 @@ class SkyElement extends HTMLElement {
|
|
|
115
135
|
return this._level;
|
|
116
136
|
}
|
|
117
137
|
|
|
138
|
+
set type(value: 'box' | 'dome' | 'infinite' | 'none') {
|
|
139
|
+
this._type = value;
|
|
140
|
+
const scene = this.getScene();
|
|
141
|
+
if (scene) {
|
|
142
|
+
scene.sky.type = this._type;
|
|
143
|
+
const layer = scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
144
|
+
if (layer) {
|
|
145
|
+
layer.enabled = this._type !== 'none';
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
get type() {
|
|
151
|
+
return this._type;
|
|
152
|
+
}
|
|
153
|
+
|
|
118
154
|
static get observedAttributes() {
|
|
119
|
-
return ['asset', 'intensity', 'level', 'rotation', '
|
|
155
|
+
return ['asset', 'center', 'intensity', 'level', 'rotation', 'scale', 'type'];
|
|
120
156
|
}
|
|
121
157
|
|
|
122
158
|
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
@@ -124,17 +160,23 @@ class SkyElement extends HTMLElement {
|
|
|
124
160
|
case 'asset':
|
|
125
161
|
this.asset = newValue;
|
|
126
162
|
break;
|
|
163
|
+
case 'center':
|
|
164
|
+
this.center = parseVec3(newValue);
|
|
165
|
+
break;
|
|
127
166
|
case 'intensity':
|
|
128
167
|
this.intensity = parseFloat(newValue);
|
|
129
168
|
break;
|
|
130
169
|
case 'rotation':
|
|
131
|
-
this.rotation = newValue
|
|
170
|
+
this.rotation = parseVec3(newValue);
|
|
132
171
|
break;
|
|
133
172
|
case 'level':
|
|
134
173
|
this.level = parseInt(newValue, 10);
|
|
135
174
|
break;
|
|
136
|
-
case '
|
|
137
|
-
this.
|
|
175
|
+
case 'scale':
|
|
176
|
+
this.scale = parseVec3(newValue);
|
|
177
|
+
break;
|
|
178
|
+
case 'type':
|
|
179
|
+
this.type = newValue as 'box' | 'dome' | 'infinite' | 'none';
|
|
138
180
|
break;
|
|
139
181
|
}
|
|
140
182
|
}
|