@playcanvas/web-components 0.1.6 → 0.1.8
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 +22 -22
- package/dist/colors.d.ts +1 -0
- package/dist/components/light-component.d.ts +12 -0
- package/dist/model.d.ts +6 -2
- package/dist/pwc.cjs +358 -97
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +358 -97
- 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 +359 -98
- package/dist/pwc.mjs.map +1 -1
- package/dist/sky.d.ts +12 -6
- package/package.json +12 -10
- package/src/colors.ts +150 -0
- package/src/components/light-component.ts +26 -0
- package/src/components/script-component.ts +40 -13
- package/src/entity.ts +2 -0
- package/src/model.ts +47 -19
- package/src/sky.ts +103 -64
- package/src/utils.ts +13 -5
package/dist/pwc.js
CHANGED
|
@@ -261,6 +261,157 @@
|
|
|
261
261
|
}
|
|
262
262
|
customElements.define('pc-app', AppElement);
|
|
263
263
|
|
|
264
|
+
const CSS_COLORS = {
|
|
265
|
+
aliceblue: '#f0f8ff',
|
|
266
|
+
antiquewhite: '#faebd7',
|
|
267
|
+
aqua: '#00ffff',
|
|
268
|
+
aquamarine: '#7fffd4',
|
|
269
|
+
azure: '#f0ffff',
|
|
270
|
+
beige: '#f5f5dc',
|
|
271
|
+
bisque: '#ffe4c4',
|
|
272
|
+
black: '#000000',
|
|
273
|
+
blanchedalmond: '#ffebcd',
|
|
274
|
+
blue: '#0000ff',
|
|
275
|
+
blueviolet: '#8a2be2',
|
|
276
|
+
brown: '#a52a2a',
|
|
277
|
+
burlywood: '#deb887',
|
|
278
|
+
cadetblue: '#5f9ea0',
|
|
279
|
+
chartreuse: '#7fff00',
|
|
280
|
+
chocolate: '#d2691e',
|
|
281
|
+
coral: '#ff7f50',
|
|
282
|
+
cornflowerblue: '#6495ed',
|
|
283
|
+
cornsilk: '#fff8dc',
|
|
284
|
+
crimson: '#dc143c',
|
|
285
|
+
cyan: '#00ffff',
|
|
286
|
+
darkblue: '#00008b',
|
|
287
|
+
darkcyan: '#008b8b',
|
|
288
|
+
darkgoldenrod: '#b8860b',
|
|
289
|
+
darkgray: '#a9a9a9',
|
|
290
|
+
darkgreen: '#006400',
|
|
291
|
+
darkgrey: '#a9a9a9',
|
|
292
|
+
darkkhaki: '#bdb76b',
|
|
293
|
+
darkmagenta: '#8b008b',
|
|
294
|
+
darkolivegreen: '#556b2f',
|
|
295
|
+
darkorange: '#ff8c00',
|
|
296
|
+
darkorchid: '#9932cc',
|
|
297
|
+
darkred: '#8b0000',
|
|
298
|
+
darksalmon: '#e9967a',
|
|
299
|
+
darkseagreen: '#8fbc8f',
|
|
300
|
+
darkslateblue: '#483d8b',
|
|
301
|
+
darkslategray: '#2f4f4f',
|
|
302
|
+
darkslategrey: '#2f4f4f',
|
|
303
|
+
darkturquoise: '#00ced1',
|
|
304
|
+
darkviolet: '#9400d3',
|
|
305
|
+
deeppink: '#ff1493',
|
|
306
|
+
deepskyblue: '#00bfff',
|
|
307
|
+
dimgray: '#696969',
|
|
308
|
+
dimgrey: '#696969',
|
|
309
|
+
dodgerblue: '#1e90ff',
|
|
310
|
+
firebrick: '#b22222',
|
|
311
|
+
floralwhite: '#fffaf0',
|
|
312
|
+
forestgreen: '#228b22',
|
|
313
|
+
fuchsia: '#ff00ff',
|
|
314
|
+
gainsboro: '#dcdcdc',
|
|
315
|
+
ghostwhite: '#f8f8ff',
|
|
316
|
+
gold: '#ffd700',
|
|
317
|
+
goldenrod: '#daa520',
|
|
318
|
+
gray: '#808080',
|
|
319
|
+
green: '#008000',
|
|
320
|
+
greenyellow: '#adff2f',
|
|
321
|
+
grey: '#808080',
|
|
322
|
+
honeydew: '#f0fff0',
|
|
323
|
+
hotpink: '#ff69b4',
|
|
324
|
+
indianred: '#cd5c5c',
|
|
325
|
+
indigo: '#4b0082',
|
|
326
|
+
ivory: '#fffff0',
|
|
327
|
+
khaki: '#f0e68c',
|
|
328
|
+
lavender: '#e6e6fa',
|
|
329
|
+
lavenderblush: '#fff0f5',
|
|
330
|
+
lawngreen: '#7cfc00',
|
|
331
|
+
lemonchiffon: '#fffacd',
|
|
332
|
+
lightblue: '#add8e6',
|
|
333
|
+
lightcoral: '#f08080',
|
|
334
|
+
lightcyan: '#e0ffff',
|
|
335
|
+
lightgoldenrodyellow: '#fafad2',
|
|
336
|
+
lightgray: '#d3d3d3',
|
|
337
|
+
lightgreen: '#90ee90',
|
|
338
|
+
lightgrey: '#d3d3d3',
|
|
339
|
+
lightpink: '#ffb6c1',
|
|
340
|
+
lightsalmon: '#ffa07a',
|
|
341
|
+
lightseagreen: '#20b2aa',
|
|
342
|
+
lightskyblue: '#87cefa',
|
|
343
|
+
lightslategray: '#778899',
|
|
344
|
+
lightslategrey: '#778899',
|
|
345
|
+
lightsteelblue: '#b0c4de',
|
|
346
|
+
lightyellow: '#ffffe0',
|
|
347
|
+
lime: '#00ff00',
|
|
348
|
+
limegreen: '#32cd32',
|
|
349
|
+
linen: '#faf0e6',
|
|
350
|
+
magenta: '#ff00ff',
|
|
351
|
+
maroon: '#800000',
|
|
352
|
+
mediumaquamarine: '#66cdaa',
|
|
353
|
+
mediumblue: '#0000cd',
|
|
354
|
+
mediumorchid: '#ba55d3',
|
|
355
|
+
mediumpurple: '#9370db',
|
|
356
|
+
mediumseagreen: '#3cb371',
|
|
357
|
+
mediumslateblue: '#7b68ee',
|
|
358
|
+
mediumspringgreen: '#00fa9a',
|
|
359
|
+
mediumturquoise: '#48d1cc',
|
|
360
|
+
mediumvioletred: '#c71585',
|
|
361
|
+
midnightblue: '#191970',
|
|
362
|
+
mintcream: '#f5fffa',
|
|
363
|
+
mistyrose: '#ffe4e1',
|
|
364
|
+
moccasin: '#ffe4b5',
|
|
365
|
+
navajowhite: '#ffdead',
|
|
366
|
+
navy: '#000080',
|
|
367
|
+
oldlace: '#fdf5e6',
|
|
368
|
+
olive: '#808000',
|
|
369
|
+
olivedrab: '#6b8e23',
|
|
370
|
+
orange: '#ffa500',
|
|
371
|
+
orangered: '#ff4500',
|
|
372
|
+
orchid: '#da70d6',
|
|
373
|
+
palegoldenrod: '#eee8aa',
|
|
374
|
+
palegreen: '#98fb98',
|
|
375
|
+
paleturquoise: '#afeeee',
|
|
376
|
+
palevioletred: '#db7093',
|
|
377
|
+
papayawhip: '#ffefd5',
|
|
378
|
+
peachpuff: '#ffdab9',
|
|
379
|
+
peru: '#cd853f',
|
|
380
|
+
pink: '#ffc0cb',
|
|
381
|
+
plum: '#dda0dd',
|
|
382
|
+
powderblue: '#b0e0e6',
|
|
383
|
+
purple: '#800080',
|
|
384
|
+
rebeccapurple: '#663399',
|
|
385
|
+
red: '#ff0000',
|
|
386
|
+
rosybrown: '#bc8f8f',
|
|
387
|
+
royalblue: '#4169e1',
|
|
388
|
+
saddlebrown: '#8b4513',
|
|
389
|
+
salmon: '#fa8072',
|
|
390
|
+
sandybrown: '#f4a460',
|
|
391
|
+
seagreen: '#2e8b57',
|
|
392
|
+
seashell: '#fff5ee',
|
|
393
|
+
sienna: '#a0522d',
|
|
394
|
+
silver: '#c0c0c0',
|
|
395
|
+
skyblue: '#87ceeb',
|
|
396
|
+
slateblue: '#6a5acd',
|
|
397
|
+
slategray: '#708090',
|
|
398
|
+
slategrey: '#708090',
|
|
399
|
+
snow: '#fffafa',
|
|
400
|
+
springgreen: '#00ff7f',
|
|
401
|
+
steelblue: '#4682b4',
|
|
402
|
+
tan: '#d2b48c',
|
|
403
|
+
teal: '#008080',
|
|
404
|
+
thistle: '#d8bfd8',
|
|
405
|
+
tomato: '#ff6347',
|
|
406
|
+
turquoise: '#40e0d0',
|
|
407
|
+
violet: '#ee82ee',
|
|
408
|
+
wheat: '#f5deb3',
|
|
409
|
+
white: '#ffffff',
|
|
410
|
+
whitesmoke: '#f5f5f5',
|
|
411
|
+
yellow: '#ffff00',
|
|
412
|
+
yellowgreen: '#9acd32'
|
|
413
|
+
};
|
|
414
|
+
|
|
264
415
|
/**
|
|
265
416
|
* Parse a color string into a Color object. String can be in the format of '#rgb', '#rgba',
|
|
266
417
|
* '#rrggbb', '#rrggbbaa', or a string of 3 or 4 comma-delimited numbers.
|
|
@@ -269,10 +420,15 @@
|
|
|
269
420
|
* @returns The parsed Color object.
|
|
270
421
|
*/
|
|
271
422
|
const parseColor = (value) => {
|
|
423
|
+
// Check if it's a CSS color name first
|
|
424
|
+
const hexColor = CSS_COLORS[value.toLowerCase()];
|
|
425
|
+
if (hexColor) {
|
|
426
|
+
return new playcanvas.Color().fromString(hexColor);
|
|
427
|
+
}
|
|
272
428
|
if (value.startsWith('#')) {
|
|
273
429
|
return new playcanvas.Color().fromString(value);
|
|
274
430
|
}
|
|
275
|
-
const components = value.split('
|
|
431
|
+
const components = value.split(' ').map(Number);
|
|
276
432
|
return new playcanvas.Color(components);
|
|
277
433
|
};
|
|
278
434
|
/**
|
|
@@ -282,7 +438,7 @@
|
|
|
282
438
|
* @returns The parsed Quat object.
|
|
283
439
|
*/
|
|
284
440
|
const parseQuat = (value) => {
|
|
285
|
-
const [x, y, z] = value.split('
|
|
441
|
+
const [x, y, z] = value.split(' ').map(Number);
|
|
286
442
|
const q = new playcanvas.Quat();
|
|
287
443
|
q.setFromEulerAngles(x, y, z);
|
|
288
444
|
return q;
|
|
@@ -294,7 +450,7 @@
|
|
|
294
450
|
* @returns The parsed Vec2 object.
|
|
295
451
|
*/
|
|
296
452
|
const parseVec2 = (value) => {
|
|
297
|
-
const components = value.split('
|
|
453
|
+
const components = value.split(' ').map(Number);
|
|
298
454
|
return new playcanvas.Vec2(components);
|
|
299
455
|
};
|
|
300
456
|
/**
|
|
@@ -304,7 +460,7 @@
|
|
|
304
460
|
* @returns The parsed Vec3 object.
|
|
305
461
|
*/
|
|
306
462
|
const parseVec3 = (value) => {
|
|
307
|
-
const components = value.split('
|
|
463
|
+
const components = value.split(' ').map(Number);
|
|
308
464
|
return new playcanvas.Vec3(components);
|
|
309
465
|
};
|
|
310
466
|
/**
|
|
@@ -314,7 +470,7 @@
|
|
|
314
470
|
* @returns The parsed Vec4 object.
|
|
315
471
|
*/
|
|
316
472
|
const parseVec4 = (value) => {
|
|
317
|
-
const components = value.split('
|
|
473
|
+
const components = value.split(' ').map(Number);
|
|
318
474
|
return new playcanvas.Vec4(components);
|
|
319
475
|
};
|
|
320
476
|
|
|
@@ -363,11 +519,14 @@
|
|
|
363
519
|
// Create a new entity
|
|
364
520
|
this.entity = new playcanvas.Entity(this._name, app);
|
|
365
521
|
// Initialize from attributes
|
|
522
|
+
const enabledAttr = this.getAttribute('enabled');
|
|
366
523
|
const nameAttr = this.getAttribute('name');
|
|
367
524
|
const positionAttr = this.getAttribute('position');
|
|
368
525
|
const rotationAttr = this.getAttribute('rotation');
|
|
369
526
|
const scaleAttr = this.getAttribute('scale');
|
|
370
527
|
const tagsAttr = this.getAttribute('tags');
|
|
528
|
+
if (enabledAttr)
|
|
529
|
+
this.enabled = enabledAttr !== 'false';
|
|
371
530
|
if (nameAttr)
|
|
372
531
|
this.name = nameAttr;
|
|
373
532
|
if (positionAttr)
|
|
@@ -1539,6 +1698,7 @@
|
|
|
1539
1698
|
this._range = 10;
|
|
1540
1699
|
this._shadowBias = 0.2;
|
|
1541
1700
|
this._shadowDistance = 16;
|
|
1701
|
+
this._shadowResolution = 1024;
|
|
1542
1702
|
this._type = 'directional';
|
|
1543
1703
|
}
|
|
1544
1704
|
getInitialComponentData() {
|
|
@@ -1552,6 +1712,7 @@
|
|
|
1552
1712
|
range: this._range,
|
|
1553
1713
|
shadowBias: this._shadowBias,
|
|
1554
1714
|
shadowDistance: this._shadowDistance,
|
|
1715
|
+
shadowResolution: this._shadowResolution,
|
|
1555
1716
|
type: this._type
|
|
1556
1717
|
};
|
|
1557
1718
|
}
|
|
@@ -1715,6 +1876,23 @@
|
|
|
1715
1876
|
get shadowDistance() {
|
|
1716
1877
|
return this._shadowDistance;
|
|
1717
1878
|
}
|
|
1879
|
+
/**
|
|
1880
|
+
* Sets the shadow resolution of the light.
|
|
1881
|
+
* @param value - The shadow resolution.
|
|
1882
|
+
*/
|
|
1883
|
+
set shadowResolution(value) {
|
|
1884
|
+
this._shadowResolution = value;
|
|
1885
|
+
if (this.component) {
|
|
1886
|
+
this.component.shadowResolution = value;
|
|
1887
|
+
}
|
|
1888
|
+
}
|
|
1889
|
+
/**
|
|
1890
|
+
* Gets the shadow resolution of the light.
|
|
1891
|
+
* @returns The shadow resolution.
|
|
1892
|
+
*/
|
|
1893
|
+
get shadowResolution() {
|
|
1894
|
+
return this._shadowResolution;
|
|
1895
|
+
}
|
|
1718
1896
|
/**
|
|
1719
1897
|
* Sets the type of the light.
|
|
1720
1898
|
* @param value - The type.
|
|
@@ -1748,6 +1926,7 @@
|
|
|
1748
1926
|
'range',
|
|
1749
1927
|
'shadow-bias',
|
|
1750
1928
|
'shadow-distance',
|
|
1929
|
+
'shadow-resolution',
|
|
1751
1930
|
'type'
|
|
1752
1931
|
];
|
|
1753
1932
|
}
|
|
@@ -1781,6 +1960,9 @@
|
|
|
1781
1960
|
case 'shadow-distance':
|
|
1782
1961
|
this.shadowDistance = Number(newValue);
|
|
1783
1962
|
break;
|
|
1963
|
+
case 'shadow-resolution':
|
|
1964
|
+
this.shadowResolution = Number(newValue);
|
|
1965
|
+
break;
|
|
1784
1966
|
case 'type':
|
|
1785
1967
|
this.type = newValue;
|
|
1786
1968
|
break;
|
|
@@ -2364,23 +2546,47 @@
|
|
|
2364
2546
|
}
|
|
2365
2547
|
applyAttributes(script, attributes) {
|
|
2366
2548
|
try {
|
|
2367
|
-
// Parse the attributes string into an object and set them on the script
|
|
2368
2549
|
const attributesObject = attributes ? JSON.parse(attributes) : {};
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
if (
|
|
2372
|
-
|
|
2373
|
-
|
|
2550
|
+
const applyValue = (target, key, value) => {
|
|
2551
|
+
// Handle asset references
|
|
2552
|
+
if (typeof value === 'string' && value.startsWith('asset:')) {
|
|
2553
|
+
const assetId = value.slice(6);
|
|
2554
|
+
const assetElement = document.querySelector(`pc-asset#${assetId}`);
|
|
2555
|
+
if (assetElement) {
|
|
2556
|
+
target[key] = assetElement.asset;
|
|
2557
|
+
return;
|
|
2558
|
+
}
|
|
2559
|
+
}
|
|
2560
|
+
// Handle vectors
|
|
2561
|
+
if (Array.isArray(value)) {
|
|
2562
|
+
if (target[key] instanceof playcanvas.Vec2) {
|
|
2563
|
+
target[key] = tmpV2.set(value[0], value[1]);
|
|
2564
|
+
return;
|
|
2565
|
+
}
|
|
2566
|
+
if (target[key] instanceof playcanvas.Vec3) {
|
|
2567
|
+
target[key] = tmpV3.set(value[0], value[1], value[2]);
|
|
2568
|
+
return;
|
|
2569
|
+
}
|
|
2570
|
+
if (target[key] instanceof playcanvas.Vec4) {
|
|
2571
|
+
target[key] = tmpV4.set(value[0], value[1], value[2], value[3]);
|
|
2572
|
+
return;
|
|
2573
|
+
}
|
|
2374
2574
|
}
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2575
|
+
// Handle nested objects
|
|
2576
|
+
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
2577
|
+
if (!target[key] || typeof target[key] !== 'object') {
|
|
2578
|
+
target[key] = {};
|
|
2579
|
+
}
|
|
2580
|
+
for (const nestedKey in value) {
|
|
2581
|
+
applyValue(target[key], nestedKey, value[nestedKey]);
|
|
2582
|
+
}
|
|
2378
2583
|
}
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
continue;
|
|
2584
|
+
else {
|
|
2585
|
+
target[key] = value;
|
|
2382
2586
|
}
|
|
2383
|
-
|
|
2587
|
+
};
|
|
2588
|
+
for (const key in attributesObject) {
|
|
2589
|
+
applyValue(script, key, attributesObject[key]);
|
|
2384
2590
|
}
|
|
2385
2591
|
}
|
|
2386
2592
|
catch (error) {
|
|
@@ -2979,48 +3185,71 @@
|
|
|
2979
3185
|
constructor() {
|
|
2980
3186
|
super(...arguments);
|
|
2981
3187
|
this._asset = '';
|
|
3188
|
+
this._entity = null;
|
|
2982
3189
|
}
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
2986
|
-
const asset = this.getAttribute('asset');
|
|
2987
|
-
if (asset) {
|
|
2988
|
-
this.asset = asset;
|
|
2989
|
-
}
|
|
3190
|
+
connectedCallback() {
|
|
3191
|
+
this._loadModel();
|
|
2990
3192
|
this._onReady();
|
|
2991
3193
|
}
|
|
2992
|
-
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
if (
|
|
2999
|
-
|
|
3000
|
-
|
|
3194
|
+
disconnectedCallback() {
|
|
3195
|
+
this._unloadModel();
|
|
3196
|
+
}
|
|
3197
|
+
_instantiate(container) {
|
|
3198
|
+
this._entity = container.instantiateRenderEntity();
|
|
3199
|
+
// @ts-ignore
|
|
3200
|
+
if (container.animations.length > 0) {
|
|
3201
|
+
this._entity.addComponent('anim');
|
|
3202
|
+
// @ts-ignore
|
|
3203
|
+
this._entity.anim.assignAnimation('animation', container.animations[0].resource);
|
|
3001
3204
|
}
|
|
3002
3205
|
const parentEntityElement = this.closestEntity;
|
|
3003
3206
|
if (parentEntityElement) {
|
|
3004
3207
|
parentEntityElement.ready().then(() => {
|
|
3005
|
-
parentEntityElement.entity.addChild(
|
|
3208
|
+
parentEntityElement.entity.addChild(this._entity);
|
|
3006
3209
|
});
|
|
3007
3210
|
}
|
|
3008
3211
|
else {
|
|
3009
3212
|
const appElement = this.closestApp;
|
|
3010
3213
|
if (appElement) {
|
|
3011
3214
|
appElement.ready().then(() => {
|
|
3012
|
-
appElement.app.root.addChild(
|
|
3215
|
+
appElement.app.root.addChild(this._entity);
|
|
3013
3216
|
});
|
|
3014
3217
|
}
|
|
3015
3218
|
}
|
|
3016
3219
|
}
|
|
3220
|
+
async _loadModel() {
|
|
3221
|
+
var _a;
|
|
3222
|
+
this._unloadModel();
|
|
3223
|
+
const appElement = await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
3224
|
+
const app = appElement === null || appElement === void 0 ? void 0 : appElement.app;
|
|
3225
|
+
const asset = AssetElement.get(this._asset);
|
|
3226
|
+
if (!asset) {
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
if (asset.loaded) {
|
|
3230
|
+
this._instantiate(asset.resource);
|
|
3231
|
+
}
|
|
3232
|
+
else {
|
|
3233
|
+
asset.once('load', () => {
|
|
3234
|
+
this._instantiate(asset.resource);
|
|
3235
|
+
});
|
|
3236
|
+
app.assets.load(asset);
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
_unloadModel() {
|
|
3240
|
+
var _a;
|
|
3241
|
+
(_a = this._entity) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
3242
|
+
this._entity = null;
|
|
3243
|
+
}
|
|
3017
3244
|
/**
|
|
3018
3245
|
* Sets the asset ID of the model.
|
|
3019
3246
|
* @param value - The asset ID.
|
|
3020
3247
|
*/
|
|
3021
3248
|
set asset(value) {
|
|
3022
3249
|
this._asset = value;
|
|
3023
|
-
this.
|
|
3250
|
+
if (this.isConnected) {
|
|
3251
|
+
this._loadModel();
|
|
3252
|
+
}
|
|
3024
3253
|
}
|
|
3025
3254
|
/**
|
|
3026
3255
|
* Gets the source URL of the model.
|
|
@@ -3212,48 +3441,77 @@
|
|
|
3212
3441
|
this._intensity = 1;
|
|
3213
3442
|
this._rotation = new playcanvas.Vec3();
|
|
3214
3443
|
this._level = 0;
|
|
3444
|
+
this._lighting = false;
|
|
3215
3445
|
this._scale = new playcanvas.Vec3(100, 100, 100);
|
|
3216
3446
|
this._type = 'infinite';
|
|
3447
|
+
this._scene = null;
|
|
3217
3448
|
}
|
|
3218
|
-
|
|
3219
|
-
|
|
3220
|
-
await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
3221
|
-
this.asset = this.getAttribute('asset') || '';
|
|
3449
|
+
connectedCallback() {
|
|
3450
|
+
this._loadSkybox();
|
|
3222
3451
|
this._onReady();
|
|
3223
3452
|
}
|
|
3224
|
-
|
|
3225
|
-
|
|
3453
|
+
disconnectedCallback() {
|
|
3454
|
+
this._unloadSkybox();
|
|
3455
|
+
}
|
|
3456
|
+
_generateSkybox(asset) {
|
|
3457
|
+
if (!this._scene)
|
|
3458
|
+
return;
|
|
3459
|
+
const source = asset.resource;
|
|
3460
|
+
const skybox = playcanvas.EnvLighting.generateSkyboxCubemap(source);
|
|
3461
|
+
skybox.anisotropy = 4;
|
|
3462
|
+
this._scene.skybox = skybox;
|
|
3463
|
+
if (this._lighting) {
|
|
3464
|
+
const lighting = playcanvas.EnvLighting.generateLightingSource(source);
|
|
3465
|
+
const envAtlas = playcanvas.EnvLighting.generateAtlas(lighting);
|
|
3466
|
+
this._scene.envAtlas = envAtlas;
|
|
3467
|
+
}
|
|
3468
|
+
const layer = this._scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
|
|
3469
|
+
if (layer) {
|
|
3470
|
+
layer.enabled = this._type !== 'none';
|
|
3471
|
+
}
|
|
3472
|
+
this._scene.sky.type = this._type;
|
|
3473
|
+
this._scene.sky.node.setLocalScale(this._scale);
|
|
3474
|
+
this._scene.sky.center = this._center;
|
|
3475
|
+
this._scene.skyboxIntensity = this._intensity;
|
|
3476
|
+
}
|
|
3477
|
+
async _loadSkybox() {
|
|
3478
|
+
var _a;
|
|
3479
|
+
const appElement = await ((_a = this.closestApp) === null || _a === void 0 ? void 0 : _a.ready());
|
|
3480
|
+
const app = appElement === null || appElement === void 0 ? void 0 : appElement.app;
|
|
3226
3481
|
if (!app) {
|
|
3227
3482
|
return;
|
|
3228
3483
|
}
|
|
3229
|
-
|
|
3230
|
-
|
|
3231
|
-
|
|
3232
|
-
|
|
3233
|
-
|
|
3234
|
-
|
|
3235
|
-
|
|
3236
|
-
|
|
3237
|
-
|
|
3238
|
-
|
|
3239
|
-
|
|
3240
|
-
|
|
3241
|
-
|
|
3242
|
-
layer.enabled = this._type !== 'none';
|
|
3243
|
-
}
|
|
3244
|
-
app.scene.sky.type = this._type;
|
|
3245
|
-
app.scene.sky.node.setLocalScale(this._scale);
|
|
3246
|
-
app.scene.sky.center = this._center;
|
|
3484
|
+
const asset = AssetElement.get(this._asset);
|
|
3485
|
+
if (!asset) {
|
|
3486
|
+
return;
|
|
3487
|
+
}
|
|
3488
|
+
this._scene = app.scene;
|
|
3489
|
+
if (asset.loaded) {
|
|
3490
|
+
this._generateSkybox(asset);
|
|
3491
|
+
}
|
|
3492
|
+
else {
|
|
3493
|
+
asset.once('load', () => {
|
|
3494
|
+
this._generateSkybox(asset);
|
|
3495
|
+
});
|
|
3496
|
+
app.assets.load(asset);
|
|
3247
3497
|
}
|
|
3248
3498
|
}
|
|
3499
|
+
_unloadSkybox() {
|
|
3500
|
+
var _a, _b;
|
|
3501
|
+
if (!this._scene)
|
|
3502
|
+
return;
|
|
3503
|
+
(_a = this._scene.skybox) === null || _a === void 0 ? void 0 : _a.destroy();
|
|
3504
|
+
// @ts-ignore
|
|
3505
|
+
this._scene.skybox = null;
|
|
3506
|
+
(_b = this._scene.envAtlas) === null || _b === void 0 ? void 0 : _b.destroy();
|
|
3507
|
+
// @ts-ignore
|
|
3508
|
+
this._scene.envAtlas = null;
|
|
3509
|
+
this._scene = null;
|
|
3510
|
+
}
|
|
3249
3511
|
set asset(value) {
|
|
3250
3512
|
this._asset = value;
|
|
3251
|
-
|
|
3252
|
-
|
|
3253
|
-
const asset = AssetElement.get(value);
|
|
3254
|
-
if (asset) {
|
|
3255
|
-
this.initSkybox(asset.resource);
|
|
3256
|
-
}
|
|
3513
|
+
if (this.isConnected) {
|
|
3514
|
+
this._loadSkybox();
|
|
3257
3515
|
}
|
|
3258
3516
|
}
|
|
3259
3517
|
get asset() {
|
|
@@ -3261,9 +3519,8 @@
|
|
|
3261
3519
|
}
|
|
3262
3520
|
set center(value) {
|
|
3263
3521
|
this._center = value;
|
|
3264
|
-
|
|
3265
|
-
|
|
3266
|
-
scene.sky.center = this._center;
|
|
3522
|
+
if (this._scene) {
|
|
3523
|
+
this._scene.sky.center = this._center;
|
|
3267
3524
|
}
|
|
3268
3525
|
}
|
|
3269
3526
|
get center() {
|
|
@@ -3271,19 +3528,32 @@
|
|
|
3271
3528
|
}
|
|
3272
3529
|
set intensity(value) {
|
|
3273
3530
|
this._intensity = value;
|
|
3274
|
-
|
|
3275
|
-
|
|
3276
|
-
scene.skyboxIntensity = this._intensity;
|
|
3531
|
+
if (this._scene) {
|
|
3532
|
+
this._scene.skyboxIntensity = this._intensity;
|
|
3277
3533
|
}
|
|
3278
3534
|
}
|
|
3279
3535
|
get intensity() {
|
|
3280
3536
|
return this._intensity;
|
|
3281
3537
|
}
|
|
3538
|
+
set level(value) {
|
|
3539
|
+
this._level = value;
|
|
3540
|
+
if (this._scene) {
|
|
3541
|
+
this._scene.skyboxMip = this._level;
|
|
3542
|
+
}
|
|
3543
|
+
}
|
|
3544
|
+
get level() {
|
|
3545
|
+
return this._level;
|
|
3546
|
+
}
|
|
3547
|
+
set lighting(value) {
|
|
3548
|
+
this._lighting = value;
|
|
3549
|
+
}
|
|
3550
|
+
get lighting() {
|
|
3551
|
+
return this._lighting;
|
|
3552
|
+
}
|
|
3282
3553
|
set rotation(value) {
|
|
3283
3554
|
this._rotation = value;
|
|
3284
|
-
|
|
3285
|
-
|
|
3286
|
-
scene.skyboxRotation = new playcanvas.Quat().setFromEulerAngles(value);
|
|
3555
|
+
if (this._scene) {
|
|
3556
|
+
this._scene.skyboxRotation = new playcanvas.Quat().setFromEulerAngles(value);
|
|
3287
3557
|
}
|
|
3288
3558
|
}
|
|
3289
3559
|
get rotation() {
|
|
@@ -3291,30 +3561,18 @@
|
|
|
3291
3561
|
}
|
|
3292
3562
|
set scale(value) {
|
|
3293
3563
|
this._scale = value;
|
|
3294
|
-
|
|
3295
|
-
|
|
3296
|
-
scene.sky.node.setLocalScale(this._scale);
|
|
3564
|
+
if (this._scene) {
|
|
3565
|
+
this._scene.sky.node.setLocalScale(this._scale);
|
|
3297
3566
|
}
|
|
3298
3567
|
}
|
|
3299
3568
|
get scale() {
|
|
3300
3569
|
return this._scale;
|
|
3301
3570
|
}
|
|
3302
|
-
set level(value) {
|
|
3303
|
-
this._level = value;
|
|
3304
|
-
const scene = this.getScene();
|
|
3305
|
-
if (scene) {
|
|
3306
|
-
scene.skyboxMip = this._level;
|
|
3307
|
-
}
|
|
3308
|
-
}
|
|
3309
|
-
get level() {
|
|
3310
|
-
return this._level;
|
|
3311
|
-
}
|
|
3312
3571
|
set type(value) {
|
|
3313
3572
|
this._type = value;
|
|
3314
|
-
|
|
3315
|
-
|
|
3316
|
-
|
|
3317
|
-
const layer = scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
|
|
3573
|
+
if (this._scene) {
|
|
3574
|
+
this._scene.sky.type = this._type;
|
|
3575
|
+
const layer = this._scene.layers.getLayerById(playcanvas.LAYERID_SKYBOX);
|
|
3318
3576
|
if (layer) {
|
|
3319
3577
|
layer.enabled = this._type !== 'none';
|
|
3320
3578
|
}
|
|
@@ -3324,7 +3582,7 @@
|
|
|
3324
3582
|
return this._type;
|
|
3325
3583
|
}
|
|
3326
3584
|
static get observedAttributes() {
|
|
3327
|
-
return ['asset', 'center', 'intensity', 'level', 'rotation', 'scale', 'type'];
|
|
3585
|
+
return ['asset', 'center', 'intensity', 'level', 'lighting', 'rotation', 'scale', 'type'];
|
|
3328
3586
|
}
|
|
3329
3587
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
3330
3588
|
switch (name) {
|
|
@@ -3337,12 +3595,15 @@
|
|
|
3337
3595
|
case 'intensity':
|
|
3338
3596
|
this.intensity = parseFloat(newValue);
|
|
3339
3597
|
break;
|
|
3340
|
-
case 'rotation':
|
|
3341
|
-
this.rotation = parseVec3(newValue);
|
|
3342
|
-
break;
|
|
3343
3598
|
case 'level':
|
|
3344
3599
|
this.level = parseInt(newValue, 10);
|
|
3345
3600
|
break;
|
|
3601
|
+
case 'lighting':
|
|
3602
|
+
this.lighting = this.hasAttribute(name);
|
|
3603
|
+
break;
|
|
3604
|
+
case 'rotation':
|
|
3605
|
+
this.rotation = parseVec3(newValue);
|
|
3606
|
+
break;
|
|
3346
3607
|
case 'scale':
|
|
3347
3608
|
this.scale = parseVec3(newValue);
|
|
3348
3609
|
break;
|