@playcanvas/web-components 0.3.0 → 0.5.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/LICENSE +21 -21
- package/README.md +84 -84
- package/dist/components/light-component.d.ts +48 -0
- package/dist/components/splat-component.d.ts +0 -13
- package/dist/pwc.cjs +275 -207
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +275 -207
- 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 +276 -208
- package/dist/pwc.mjs.map +1 -1
- package/package.json +76 -66
- package/src/app.ts +612 -606
- package/src/asset.ts +159 -159
- package/src/async-element.ts +46 -46
- package/src/colors.ts +150 -150
- package/src/components/camera-component.ts +557 -557
- package/src/components/collision-component.ts +183 -183
- package/src/components/component.ts +97 -97
- package/src/components/element-component.ts +367 -367
- package/src/components/light-component.ts +570 -466
- package/src/components/listener-component.ts +30 -30
- package/src/components/particlesystem-component.ts +155 -155
- package/src/components/render-component.ts +147 -147
- package/src/components/rigidbody-component.ts +227 -227
- package/src/components/screen-component.ts +157 -157
- package/src/components/script-component.ts +270 -270
- package/src/components/script.ts +90 -90
- package/src/components/sound-component.ts +230 -230
- package/src/components/sound-slot.ts +288 -288
- package/src/components/splat-component.ts +102 -133
- package/src/entity.ts +360 -360
- package/src/index.ts +63 -63
- package/src/material.ts +141 -141
- package/src/model.ts +111 -111
- package/src/module.ts +43 -43
- package/src/scene.ts +217 -217
- package/src/sky.ts +293 -293
- package/src/utils.ts +71 -71
package/src/sky.ts
CHANGED
|
@@ -1,293 +1,293 @@
|
|
|
1
|
-
import { Asset, EnvLighting, LAYERID_SKYBOX, Quat, Scene, Texture, Vec3 } from 'playcanvas';
|
|
2
|
-
|
|
3
|
-
import { AssetElement } from './asset';
|
|
4
|
-
import { AsyncElement } from './async-element';
|
|
5
|
-
import { parseVec3 } from './utils';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* The SkyElement interface provides properties and methods for manipulating
|
|
9
|
-
* `<pc-sky>` elements. The SkyElement interface also inherits the properties and
|
|
10
|
-
* methods of the {@link HTMLElement} interface.
|
|
11
|
-
*/
|
|
12
|
-
class SkyElement extends AsyncElement {
|
|
13
|
-
private _asset = '';
|
|
14
|
-
|
|
15
|
-
private _center = new Vec3(0, 0.01, 0);
|
|
16
|
-
|
|
17
|
-
private _intensity = 1;
|
|
18
|
-
|
|
19
|
-
private _rotation = new Vec3();
|
|
20
|
-
|
|
21
|
-
private _level = 0;
|
|
22
|
-
|
|
23
|
-
private _lighting = false;
|
|
24
|
-
|
|
25
|
-
private _scale = new Vec3(100, 100, 100);
|
|
26
|
-
|
|
27
|
-
private _type: 'box' | 'dome' | 'infinite' | 'none' = 'infinite';
|
|
28
|
-
|
|
29
|
-
private _scene: Scene | null = null;
|
|
30
|
-
|
|
31
|
-
connectedCallback() {
|
|
32
|
-
this._loadSkybox();
|
|
33
|
-
this._onReady();
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
disconnectedCallback() {
|
|
37
|
-
this._unloadSkybox();
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
private _generateSkybox(asset: Asset) {
|
|
41
|
-
if (!this._scene) return;
|
|
42
|
-
|
|
43
|
-
const source = asset.resource as Texture;
|
|
44
|
-
|
|
45
|
-
const skybox = EnvLighting.generateSkyboxCubemap(source);
|
|
46
|
-
skybox.anisotropy = 4;
|
|
47
|
-
this._scene.skybox = skybox;
|
|
48
|
-
|
|
49
|
-
if (this._lighting) {
|
|
50
|
-
const lighting = EnvLighting.generateLightingSource(source);
|
|
51
|
-
const envAtlas = EnvLighting.generateAtlas(lighting);
|
|
52
|
-
this._scene.envAtlas = envAtlas;
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const layer = this._scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
56
|
-
if (layer) {
|
|
57
|
-
layer.enabled = this._type !== 'none';
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
this._scene.sky.type = this._type;
|
|
61
|
-
this._scene.sky.node.setLocalScale(this._scale);
|
|
62
|
-
this._scene.sky.center = this._center;
|
|
63
|
-
this._scene.skyboxIntensity = this._intensity;
|
|
64
|
-
this._scene.skyboxMip = this._level;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
private async _loadSkybox() {
|
|
68
|
-
const appElement = await this.closestApp?.ready();
|
|
69
|
-
const app = appElement?.app;
|
|
70
|
-
if (!app) {
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const asset = AssetElement.get(this._asset);
|
|
75
|
-
if (!asset) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
this._scene = app.scene;
|
|
80
|
-
|
|
81
|
-
if (asset.loaded) {
|
|
82
|
-
this._generateSkybox(asset);
|
|
83
|
-
} else {
|
|
84
|
-
asset.once('load', () => {
|
|
85
|
-
this._generateSkybox(asset);
|
|
86
|
-
});
|
|
87
|
-
app.assets.load(asset);
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
private _unloadSkybox() {
|
|
92
|
-
if (!this._scene) return;
|
|
93
|
-
|
|
94
|
-
this._scene.skybox?.destroy();
|
|
95
|
-
// @ts-ignore
|
|
96
|
-
this._scene.skybox = null;
|
|
97
|
-
this._scene.envAtlas?.destroy();
|
|
98
|
-
// @ts-ignore
|
|
99
|
-
this._scene.envAtlas = null;
|
|
100
|
-
|
|
101
|
-
this._scene = null;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Sets the id of the `pc-asset` to use for the skybox.
|
|
106
|
-
* @param value - The asset ID.
|
|
107
|
-
*/
|
|
108
|
-
set asset(value: string) {
|
|
109
|
-
this._asset = value;
|
|
110
|
-
if (this.isConnected) {
|
|
111
|
-
this._loadSkybox();
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Gets the id of the `pc-asset` to use for the skybox.
|
|
117
|
-
* @returns The asset ID.
|
|
118
|
-
*/
|
|
119
|
-
get asset() {
|
|
120
|
-
return this._asset;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* Sets the center of the skybox.
|
|
125
|
-
* @param value - The center.
|
|
126
|
-
*/
|
|
127
|
-
set center(value: Vec3) {
|
|
128
|
-
this._center = value;
|
|
129
|
-
if (this._scene) {
|
|
130
|
-
this._scene.sky.center = this._center;
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Gets the center of the skybox.
|
|
136
|
-
* @returns The center.
|
|
137
|
-
*/
|
|
138
|
-
get center() {
|
|
139
|
-
return this._center;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
/**
|
|
143
|
-
* Sets the intensity of the skybox.
|
|
144
|
-
* @param value - The intensity.
|
|
145
|
-
*/
|
|
146
|
-
set intensity(value: number) {
|
|
147
|
-
this._intensity = value;
|
|
148
|
-
if (this._scene) {
|
|
149
|
-
this._scene.skyboxIntensity = this._intensity;
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
/**
|
|
154
|
-
* Gets the intensity of the skybox.
|
|
155
|
-
* @returns The intensity.
|
|
156
|
-
*/
|
|
157
|
-
get intensity() {
|
|
158
|
-
return this._intensity;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Sets the mip level of the skybox.
|
|
163
|
-
* @param value - The mip level.
|
|
164
|
-
*/
|
|
165
|
-
set level(value: number) {
|
|
166
|
-
this._level = value;
|
|
167
|
-
if (this._scene) {
|
|
168
|
-
this._scene.skyboxMip = this._level;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Gets the mip level of the skybox.
|
|
174
|
-
* @returns The mip level.
|
|
175
|
-
*/
|
|
176
|
-
get level() {
|
|
177
|
-
return this._level;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Sets whether the skybox is used as a light source.
|
|
182
|
-
* @param value - Whether to use lighting.
|
|
183
|
-
*/
|
|
184
|
-
set lighting(value: boolean) {
|
|
185
|
-
this._lighting = value;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* Gets whether the skybox is used as a light source.
|
|
190
|
-
* @returns Whether to use lighting.
|
|
191
|
-
*/
|
|
192
|
-
get lighting() {
|
|
193
|
-
return this._lighting;
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
/**
|
|
197
|
-
* Sets the Euler rotation of the skybox.
|
|
198
|
-
* @param value - The rotation.
|
|
199
|
-
*/
|
|
200
|
-
set rotation(value: Vec3) {
|
|
201
|
-
this._rotation = value;
|
|
202
|
-
if (this._scene) {
|
|
203
|
-
this._scene.skyboxRotation = new Quat().setFromEulerAngles(value);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Gets the Euler rotation of the skybox.
|
|
209
|
-
* @returns The rotation.
|
|
210
|
-
*/
|
|
211
|
-
get rotation() {
|
|
212
|
-
return this._rotation;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Sets the scale of the skybox.
|
|
217
|
-
* @param value - The scale.
|
|
218
|
-
*/
|
|
219
|
-
set scale(value: Vec3) {
|
|
220
|
-
this._scale = value;
|
|
221
|
-
if (this._scene) {
|
|
222
|
-
this._scene.sky.node.setLocalScale(this._scale);
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
* Gets the scale of the skybox.
|
|
228
|
-
* @returns The scale.
|
|
229
|
-
*/
|
|
230
|
-
get scale() {
|
|
231
|
-
return this._scale;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* Sets the type of the skybox.
|
|
236
|
-
* @param value - The type.
|
|
237
|
-
*/
|
|
238
|
-
set type(value: 'box' | 'dome' | 'infinite' | 'none') {
|
|
239
|
-
this._type = value;
|
|
240
|
-
if (this._scene) {
|
|
241
|
-
this._scene.sky.type = this._type;
|
|
242
|
-
const layer = this._scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
243
|
-
if (layer) {
|
|
244
|
-
layer.enabled = this._type !== 'none';
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/**
|
|
250
|
-
* Gets the type of the skybox.
|
|
251
|
-
* @returns The type.
|
|
252
|
-
*/
|
|
253
|
-
get type() {
|
|
254
|
-
return this._type;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
static get observedAttributes() {
|
|
258
|
-
return ['asset', 'center', 'intensity', 'level', 'lighting', 'rotation', 'scale', 'type'];
|
|
259
|
-
}
|
|
260
|
-
|
|
261
|
-
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
262
|
-
switch (name) {
|
|
263
|
-
case 'asset':
|
|
264
|
-
this.asset = newValue;
|
|
265
|
-
break;
|
|
266
|
-
case 'center':
|
|
267
|
-
this.center = parseVec3(newValue);
|
|
268
|
-
break;
|
|
269
|
-
case 'intensity':
|
|
270
|
-
this.intensity = parseFloat(newValue);
|
|
271
|
-
break;
|
|
272
|
-
case 'level':
|
|
273
|
-
this.level = parseInt(newValue, 10);
|
|
274
|
-
break;
|
|
275
|
-
case 'lighting':
|
|
276
|
-
this.lighting = this.hasAttribute(name);
|
|
277
|
-
break;
|
|
278
|
-
case 'rotation':
|
|
279
|
-
this.rotation = parseVec3(newValue);
|
|
280
|
-
break;
|
|
281
|
-
case 'scale':
|
|
282
|
-
this.scale = parseVec3(newValue);
|
|
283
|
-
break;
|
|
284
|
-
case 'type':
|
|
285
|
-
this.type = newValue as 'box' | 'dome' | 'infinite' | 'none';
|
|
286
|
-
break;
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
customElements.define('pc-sky', SkyElement);
|
|
292
|
-
|
|
293
|
-
export { SkyElement };
|
|
1
|
+
import { Asset, EnvLighting, LAYERID_SKYBOX, Quat, Scene, Texture, Vec3 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { AssetElement } from './asset';
|
|
4
|
+
import { AsyncElement } from './async-element';
|
|
5
|
+
import { parseVec3 } from './utils';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The SkyElement interface provides properties and methods for manipulating
|
|
9
|
+
* `<pc-sky>` elements. The SkyElement interface also inherits the properties and
|
|
10
|
+
* methods of the {@link HTMLElement} interface.
|
|
11
|
+
*/
|
|
12
|
+
class SkyElement extends AsyncElement {
|
|
13
|
+
private _asset = '';
|
|
14
|
+
|
|
15
|
+
private _center = new Vec3(0, 0.01, 0);
|
|
16
|
+
|
|
17
|
+
private _intensity = 1;
|
|
18
|
+
|
|
19
|
+
private _rotation = new Vec3();
|
|
20
|
+
|
|
21
|
+
private _level = 0;
|
|
22
|
+
|
|
23
|
+
private _lighting = false;
|
|
24
|
+
|
|
25
|
+
private _scale = new Vec3(100, 100, 100);
|
|
26
|
+
|
|
27
|
+
private _type: 'box' | 'dome' | 'infinite' | 'none' = 'infinite';
|
|
28
|
+
|
|
29
|
+
private _scene: Scene | null = null;
|
|
30
|
+
|
|
31
|
+
connectedCallback() {
|
|
32
|
+
this._loadSkybox();
|
|
33
|
+
this._onReady();
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
disconnectedCallback() {
|
|
37
|
+
this._unloadSkybox();
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private _generateSkybox(asset: Asset) {
|
|
41
|
+
if (!this._scene) return;
|
|
42
|
+
|
|
43
|
+
const source = asset.resource as Texture;
|
|
44
|
+
|
|
45
|
+
const skybox = EnvLighting.generateSkyboxCubemap(source);
|
|
46
|
+
skybox.anisotropy = 4;
|
|
47
|
+
this._scene.skybox = skybox;
|
|
48
|
+
|
|
49
|
+
if (this._lighting) {
|
|
50
|
+
const lighting = EnvLighting.generateLightingSource(source);
|
|
51
|
+
const envAtlas = EnvLighting.generateAtlas(lighting);
|
|
52
|
+
this._scene.envAtlas = envAtlas;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
const layer = this._scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
56
|
+
if (layer) {
|
|
57
|
+
layer.enabled = this._type !== 'none';
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
this._scene.sky.type = this._type;
|
|
61
|
+
this._scene.sky.node.setLocalScale(this._scale);
|
|
62
|
+
this._scene.sky.center = this._center;
|
|
63
|
+
this._scene.skyboxIntensity = this._intensity;
|
|
64
|
+
this._scene.skyboxMip = this._level;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private async _loadSkybox() {
|
|
68
|
+
const appElement = await this.closestApp?.ready();
|
|
69
|
+
const app = appElement?.app;
|
|
70
|
+
if (!app) {
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const asset = AssetElement.get(this._asset);
|
|
75
|
+
if (!asset) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
this._scene = app.scene;
|
|
80
|
+
|
|
81
|
+
if (asset.loaded) {
|
|
82
|
+
this._generateSkybox(asset);
|
|
83
|
+
} else {
|
|
84
|
+
asset.once('load', () => {
|
|
85
|
+
this._generateSkybox(asset);
|
|
86
|
+
});
|
|
87
|
+
app.assets.load(asset);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private _unloadSkybox() {
|
|
92
|
+
if (!this._scene) return;
|
|
93
|
+
|
|
94
|
+
this._scene.skybox?.destroy();
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
this._scene.skybox = null;
|
|
97
|
+
this._scene.envAtlas?.destroy();
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
this._scene.envAtlas = null;
|
|
100
|
+
|
|
101
|
+
this._scene = null;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Sets the id of the `pc-asset` to use for the skybox.
|
|
106
|
+
* @param value - The asset ID.
|
|
107
|
+
*/
|
|
108
|
+
set asset(value: string) {
|
|
109
|
+
this._asset = value;
|
|
110
|
+
if (this.isConnected) {
|
|
111
|
+
this._loadSkybox();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Gets the id of the `pc-asset` to use for the skybox.
|
|
117
|
+
* @returns The asset ID.
|
|
118
|
+
*/
|
|
119
|
+
get asset() {
|
|
120
|
+
return this._asset;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Sets the center of the skybox.
|
|
125
|
+
* @param value - The center.
|
|
126
|
+
*/
|
|
127
|
+
set center(value: Vec3) {
|
|
128
|
+
this._center = value;
|
|
129
|
+
if (this._scene) {
|
|
130
|
+
this._scene.sky.center = this._center;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Gets the center of the skybox.
|
|
136
|
+
* @returns The center.
|
|
137
|
+
*/
|
|
138
|
+
get center() {
|
|
139
|
+
return this._center;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Sets the intensity of the skybox.
|
|
144
|
+
* @param value - The intensity.
|
|
145
|
+
*/
|
|
146
|
+
set intensity(value: number) {
|
|
147
|
+
this._intensity = value;
|
|
148
|
+
if (this._scene) {
|
|
149
|
+
this._scene.skyboxIntensity = this._intensity;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Gets the intensity of the skybox.
|
|
155
|
+
* @returns The intensity.
|
|
156
|
+
*/
|
|
157
|
+
get intensity() {
|
|
158
|
+
return this._intensity;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Sets the mip level of the skybox.
|
|
163
|
+
* @param value - The mip level.
|
|
164
|
+
*/
|
|
165
|
+
set level(value: number) {
|
|
166
|
+
this._level = value;
|
|
167
|
+
if (this._scene) {
|
|
168
|
+
this._scene.skyboxMip = this._level;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Gets the mip level of the skybox.
|
|
174
|
+
* @returns The mip level.
|
|
175
|
+
*/
|
|
176
|
+
get level() {
|
|
177
|
+
return this._level;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Sets whether the skybox is used as a light source.
|
|
182
|
+
* @param value - Whether to use lighting.
|
|
183
|
+
*/
|
|
184
|
+
set lighting(value: boolean) {
|
|
185
|
+
this._lighting = value;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* Gets whether the skybox is used as a light source.
|
|
190
|
+
* @returns Whether to use lighting.
|
|
191
|
+
*/
|
|
192
|
+
get lighting() {
|
|
193
|
+
return this._lighting;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Sets the Euler rotation of the skybox.
|
|
198
|
+
* @param value - The rotation.
|
|
199
|
+
*/
|
|
200
|
+
set rotation(value: Vec3) {
|
|
201
|
+
this._rotation = value;
|
|
202
|
+
if (this._scene) {
|
|
203
|
+
this._scene.skyboxRotation = new Quat().setFromEulerAngles(value);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Gets the Euler rotation of the skybox.
|
|
209
|
+
* @returns The rotation.
|
|
210
|
+
*/
|
|
211
|
+
get rotation() {
|
|
212
|
+
return this._rotation;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Sets the scale of the skybox.
|
|
217
|
+
* @param value - The scale.
|
|
218
|
+
*/
|
|
219
|
+
set scale(value: Vec3) {
|
|
220
|
+
this._scale = value;
|
|
221
|
+
if (this._scene) {
|
|
222
|
+
this._scene.sky.node.setLocalScale(this._scale);
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
/**
|
|
227
|
+
* Gets the scale of the skybox.
|
|
228
|
+
* @returns The scale.
|
|
229
|
+
*/
|
|
230
|
+
get scale() {
|
|
231
|
+
return this._scale;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Sets the type of the skybox.
|
|
236
|
+
* @param value - The type.
|
|
237
|
+
*/
|
|
238
|
+
set type(value: 'box' | 'dome' | 'infinite' | 'none') {
|
|
239
|
+
this._type = value;
|
|
240
|
+
if (this._scene) {
|
|
241
|
+
this._scene.sky.type = this._type;
|
|
242
|
+
const layer = this._scene.layers.getLayerById(LAYERID_SKYBOX);
|
|
243
|
+
if (layer) {
|
|
244
|
+
layer.enabled = this._type !== 'none';
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Gets the type of the skybox.
|
|
251
|
+
* @returns The type.
|
|
252
|
+
*/
|
|
253
|
+
get type() {
|
|
254
|
+
return this._type;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
static get observedAttributes() {
|
|
258
|
+
return ['asset', 'center', 'intensity', 'level', 'lighting', 'rotation', 'scale', 'type'];
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
262
|
+
switch (name) {
|
|
263
|
+
case 'asset':
|
|
264
|
+
this.asset = newValue;
|
|
265
|
+
break;
|
|
266
|
+
case 'center':
|
|
267
|
+
this.center = parseVec3(newValue);
|
|
268
|
+
break;
|
|
269
|
+
case 'intensity':
|
|
270
|
+
this.intensity = parseFloat(newValue);
|
|
271
|
+
break;
|
|
272
|
+
case 'level':
|
|
273
|
+
this.level = parseInt(newValue, 10);
|
|
274
|
+
break;
|
|
275
|
+
case 'lighting':
|
|
276
|
+
this.lighting = this.hasAttribute(name);
|
|
277
|
+
break;
|
|
278
|
+
case 'rotation':
|
|
279
|
+
this.rotation = parseVec3(newValue);
|
|
280
|
+
break;
|
|
281
|
+
case 'scale':
|
|
282
|
+
this.scale = parseVec3(newValue);
|
|
283
|
+
break;
|
|
284
|
+
case 'type':
|
|
285
|
+
this.type = newValue as 'box' | 'dome' | 'infinite' | 'none';
|
|
286
|
+
break;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
customElements.define('pc-sky', SkyElement);
|
|
292
|
+
|
|
293
|
+
export { SkyElement };
|