@playcanvas/web-components 0.1.10 → 0.1.11
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 +1 -1
- package/README.md +38 -6
- package/dist/components/camera-component.d.ts +13 -0
- package/dist/pwc.cjs +46 -22
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +46 -22
- 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 +46 -22
- package/dist/pwc.mjs.map +1 -1
- package/package.json +15 -15
- package/src/components/camera-component.ts +27 -0
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
[](https://github.com/playcanvas/web-components/blob/main/LICENSE)
|
|
6
6
|
[](https://github.com/playcanvas/web-components/actions/workflows/deploy.yml)
|
|
7
7
|
|
|
8
|
+
| [Examples](https://playcanvas.github.io/web-components/examples) | [API Reference](https://api.playcanvas.com/modules/EngineWebComponents.html) | [Forum](https://forum.playcanvas.com/) | [Discord](https://discord.gg/RSaMRzg) |
|
|
9
|
+
|
|
8
10
|
PlayCanvas Web Components are a set of custom HTML elements for building 3D interactive web apps. Using the declarative nature of HTML makes it both easy and fun to incorporate 3D into your website.
|
|
9
11
|
|
|
10
12
|
```html
|
|
@@ -32,24 +34,53 @@ See PlayCanvas Web Components in action here: https://playcanvas.github.io/web-c
|
|
|
32
34
|
|
|
33
35
|
## Usage 🚧
|
|
34
36
|
|
|
35
|
-
|
|
37
|
+
### Installing from NPM
|
|
38
|
+
|
|
39
|
+
PlayCanvas Web Components is available as a package on [NPM](https://www.npmjs.com/package/@playcanvas/web-components).
|
|
40
|
+
You can install it (and the PlayCanvas Engine) as follows:
|
|
36
41
|
|
|
37
42
|
```bash
|
|
38
43
|
npm install playcanvas @playcanvas/web-components --save-dev
|
|
39
44
|
```
|
|
40
45
|
|
|
41
|
-
|
|
46
|
+
Next, in your HTML file, you will need an import map because the web components need to be able to find the PlayCanvas Engine (which is an external dependency):
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<script type="importmap">
|
|
50
|
+
{
|
|
51
|
+
"imports": {
|
|
52
|
+
"playcanvas": "/node_modules/playcanvas/build/playcanvas.mjs"
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
</script>
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
You can then import the components as follows:
|
|
59
|
+
|
|
60
|
+
```html
|
|
61
|
+
<script type="module" src="/node_modules/@playcanvas/web-components/dist/pwc.mjs"></script>
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
You can now incorporate any of the PlayCanvas Web Components elements into your HTML!
|
|
65
|
+
|
|
66
|
+
### Using a CDN
|
|
42
67
|
|
|
43
|
-
|
|
68
|
+
Instead of loading the library from a local package, you can instead opt to load it from a CDN (such as jsDelivr). In this case, you would update the import map:
|
|
44
69
|
|
|
45
70
|
```html
|
|
46
|
-
<script type="
|
|
71
|
+
<script type="importmap">
|
|
72
|
+
{
|
|
73
|
+
"imports": {
|
|
74
|
+
"playcanvas": "https://cdn.jsdelivr.net/npm/playcanvas@2.3.3/build/playcanvas.mjs"
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
</script>
|
|
47
78
|
```
|
|
48
79
|
|
|
49
|
-
|
|
80
|
+
And the components would now be imported as follows:
|
|
50
81
|
|
|
51
82
|
```html
|
|
52
|
-
<script src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.
|
|
83
|
+
<script type="module" src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.10/dist/pwc.mjs"></script>
|
|
53
84
|
```
|
|
54
85
|
|
|
55
86
|
## Tag Reference 📖
|
|
@@ -114,6 +145,7 @@ The `pc-camera` tag is used to define a camera component. It must be a direct ch
|
|
|
114
145
|
| `flip-faces` | Boolean attribute. Controls whether the camera flips faces. If unspecified, faces are not flipped. |
|
|
115
146
|
| `fov` | The field of view of the camera. If unspecified, `45` is used. |
|
|
116
147
|
| `frustum-culling` | Boolean attribute. Controls whether the camera uses frustum culling. If unspecified, frustum culling is used. |
|
|
148
|
+
| `horizontal-fov` | Valueless attribute. If present, the camera uses a horizontal field of view. If unspecified, the camera uses a vertical field of view. |
|
|
117
149
|
| `near-clip` | The near clipping plane of the camera. If unspecified, `0.1` is used. |
|
|
118
150
|
| `orthographic` | Valueless attribute. If present, the camera uses an orthographic projection. If unspecified, the camera uses a perspective projection. |
|
|
119
151
|
| `ortho-height` | The height of the orthographic projection. If unspecified, `10` is used. |
|
|
@@ -18,6 +18,7 @@ declare class CameraComponentElement extends ComponentElement {
|
|
|
18
18
|
private _fov;
|
|
19
19
|
private _frustumCulling;
|
|
20
20
|
private _gamma;
|
|
21
|
+
private _horizontalFov;
|
|
21
22
|
private _nearClip;
|
|
22
23
|
private _orthographic;
|
|
23
24
|
private _orthoHeight;
|
|
@@ -38,6 +39,7 @@ declare class CameraComponentElement extends ComponentElement {
|
|
|
38
39
|
fov: number;
|
|
39
40
|
frustumCulling: boolean;
|
|
40
41
|
gammaCorrection: number;
|
|
42
|
+
horizontalFov: boolean;
|
|
41
43
|
nearClip: number;
|
|
42
44
|
orthographic: boolean;
|
|
43
45
|
orthoHeight: number;
|
|
@@ -154,6 +156,17 @@ declare class CameraComponentElement extends ComponentElement {
|
|
|
154
156
|
* @returns The gamma correction.
|
|
155
157
|
*/
|
|
156
158
|
get gamma(): 'none' | 'srgb';
|
|
159
|
+
/**
|
|
160
|
+
* Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
|
|
161
|
+
* (meaning it is vertical be default).
|
|
162
|
+
* @param value - Whether the camera's field of view is horizontal.
|
|
163
|
+
*/
|
|
164
|
+
set horizontalFov(value: boolean);
|
|
165
|
+
/**
|
|
166
|
+
* Gets whether the camera's field of view (fov) is horizontal or vertical.
|
|
167
|
+
* @returns Whether the camera's field of view is horizontal.
|
|
168
|
+
*/
|
|
169
|
+
get horizontalFov(): boolean;
|
|
157
170
|
/**
|
|
158
171
|
* Sets the near clip distance of the camera.
|
|
159
172
|
* @param value - The near clip distance.
|
package/dist/pwc.cjs
CHANGED
|
@@ -15,11 +15,11 @@ class AsyncElement extends HTMLElement {
|
|
|
15
15
|
}
|
|
16
16
|
get closestApp() {
|
|
17
17
|
var _a;
|
|
18
|
-
return (_a = this.parentElement) === null || _a ===
|
|
18
|
+
return (_a = this.parentElement) === null || _a === undefined ? undefined : _a.closest('pc-app');
|
|
19
19
|
}
|
|
20
20
|
get closestEntity() {
|
|
21
21
|
var _a;
|
|
22
|
-
return (_a = this.parentElement) === null || _a ===
|
|
22
|
+
return (_a = this.parentElement) === null || _a === undefined ? undefined : _a.closest('pc-entity');
|
|
23
23
|
}
|
|
24
24
|
/**
|
|
25
25
|
* Called when the element is fully initialized and ready.
|
|
@@ -742,7 +742,7 @@ class EntityElement extends AsyncElement {
|
|
|
742
742
|
if (!this.entity)
|
|
743
743
|
return;
|
|
744
744
|
const closestEntity = this.closestEntity;
|
|
745
|
-
if (closestEntity === null || closestEntity ===
|
|
745
|
+
if (closestEntity === null || closestEntity === undefined ? undefined : closestEntity.entity) {
|
|
746
746
|
closestEntity.entity.addChild(this.entity);
|
|
747
747
|
}
|
|
748
748
|
else {
|
|
@@ -964,7 +964,7 @@ class EntityElement extends AsyncElement {
|
|
|
964
964
|
}
|
|
965
965
|
hasListeners(type) {
|
|
966
966
|
var _a;
|
|
967
|
-
return Boolean((_a = this._listeners[type]) === null || _a ===
|
|
967
|
+
return Boolean((_a = this._listeners[type]) === null || _a === undefined ? undefined : _a.length);
|
|
968
968
|
}
|
|
969
969
|
}
|
|
970
970
|
customElements.define('pc-entity', EntityElement);
|
|
@@ -1013,7 +1013,7 @@ class AssetElement extends HTMLElement {
|
|
|
1013
1013
|
// If no type is specified, try to infer it from the file extension.
|
|
1014
1014
|
if (!type) {
|
|
1015
1015
|
const ext = src.split('.').pop();
|
|
1016
|
-
type = (_a = extToType.get(ext || '')) !== null && _a !==
|
|
1016
|
+
type = (_a = extToType.get(ext || '')) !== null && _a !== undefined ? _a : null;
|
|
1017
1017
|
}
|
|
1018
1018
|
if (!type) {
|
|
1019
1019
|
console.warn(`Unsupported asset type: ${src}`);
|
|
@@ -1047,7 +1047,7 @@ class AssetElement extends HTMLElement {
|
|
|
1047
1047
|
}
|
|
1048
1048
|
static get(id) {
|
|
1049
1049
|
const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
|
|
1050
|
-
return assetElement === null || assetElement ===
|
|
1050
|
+
return assetElement === null || assetElement === undefined ? undefined : assetElement.asset;
|
|
1051
1051
|
}
|
|
1052
1052
|
static get observedAttributes() {
|
|
1053
1053
|
return ['preload'];
|
|
@@ -1094,7 +1094,7 @@ class ComponentElement extends AsyncElement {
|
|
|
1094
1094
|
initComponent() { }
|
|
1095
1095
|
async connectedCallback() {
|
|
1096
1096
|
var _a;
|
|
1097
|
-
await ((_a = this.closestApp) === null || _a ===
|
|
1097
|
+
await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
1098
1098
|
await this.addComponent();
|
|
1099
1099
|
this.initComponent();
|
|
1100
1100
|
this._onReady();
|
|
@@ -1190,6 +1190,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1190
1190
|
this._fov = 45;
|
|
1191
1191
|
this._frustumCulling = true;
|
|
1192
1192
|
this._gamma = 'srgb';
|
|
1193
|
+
this._horizontalFov = false;
|
|
1193
1194
|
this._nearClip = 0.1;
|
|
1194
1195
|
this._orthographic = false;
|
|
1195
1196
|
this._orthoHeight = 10;
|
|
@@ -1210,6 +1211,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1210
1211
|
fov: this._fov,
|
|
1211
1212
|
frustumCulling: this._frustumCulling,
|
|
1212
1213
|
gammaCorrection: this._gamma === 'srgb' ? playcanvas.GAMMA_SRGB : playcanvas.GAMMA_NONE,
|
|
1214
|
+
horizontalFov: this._horizontalFov,
|
|
1213
1215
|
nearClip: this._nearClip,
|
|
1214
1216
|
orthographic: this._orthographic,
|
|
1215
1217
|
orthoHeight: this._orthoHeight,
|
|
@@ -1221,7 +1223,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1221
1223
|
}
|
|
1222
1224
|
get xrAvailable() {
|
|
1223
1225
|
var _a;
|
|
1224
|
-
const xrManager = (_a = this.component) === null || _a ===
|
|
1226
|
+
const xrManager = (_a = this.component) === null || _a === undefined ? undefined : _a.system.app.xr;
|
|
1225
1227
|
return xrManager && xrManager.supported && xrManager.isAvailable(playcanvas.XRTYPE_VR);
|
|
1226
1228
|
}
|
|
1227
1229
|
startXr(type, space) {
|
|
@@ -1416,6 +1418,24 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1416
1418
|
get gamma() {
|
|
1417
1419
|
return this._gamma;
|
|
1418
1420
|
}
|
|
1421
|
+
/**
|
|
1422
|
+
* Sets whether the camera's field of view (fov) is horizontal or vertical. Defaults to false
|
|
1423
|
+
* (meaning it is vertical be default).
|
|
1424
|
+
* @param value - Whether the camera's field of view is horizontal.
|
|
1425
|
+
*/
|
|
1426
|
+
set horizontalFov(value) {
|
|
1427
|
+
this._horizontalFov = value;
|
|
1428
|
+
if (this.component) {
|
|
1429
|
+
this.component.horizontalFov = value;
|
|
1430
|
+
}
|
|
1431
|
+
}
|
|
1432
|
+
/**
|
|
1433
|
+
* Gets whether the camera's field of view (fov) is horizontal or vertical.
|
|
1434
|
+
* @returns Whether the camera's field of view is horizontal.
|
|
1435
|
+
*/
|
|
1436
|
+
get horizontalFov() {
|
|
1437
|
+
return this._horizontalFov;
|
|
1438
|
+
}
|
|
1419
1439
|
/**
|
|
1420
1440
|
* Sets the near clip distance of the camera.
|
|
1421
1441
|
* @param value - The near clip distance.
|
|
@@ -1526,7 +1546,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1526
1546
|
var _a;
|
|
1527
1547
|
this._tonemap = value;
|
|
1528
1548
|
if (this.component) {
|
|
1529
|
-
this.component.toneMapping = (_a = tonemaps.get(value)) !== null && _a !==
|
|
1549
|
+
this.component.toneMapping = (_a = tonemaps.get(value)) !== null && _a !== undefined ? _a : playcanvas.TONEMAP_NONE;
|
|
1530
1550
|
}
|
|
1531
1551
|
}
|
|
1532
1552
|
/**
|
|
@@ -1549,6 +1569,7 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1549
1569
|
'fov',
|
|
1550
1570
|
'frustum-culling',
|
|
1551
1571
|
'gamma',
|
|
1572
|
+
'horizontal-fov',
|
|
1552
1573
|
'near-clip',
|
|
1553
1574
|
'orthographic',
|
|
1554
1575
|
'ortho-height',
|
|
@@ -1591,6 +1612,9 @@ class CameraComponentElement extends ComponentElement {
|
|
|
1591
1612
|
case 'gamma':
|
|
1592
1613
|
this.gamma = newValue;
|
|
1593
1614
|
break;
|
|
1615
|
+
case 'horizontal-fov':
|
|
1616
|
+
this.horizontalFov = this.hasAttribute('horizontal-fov');
|
|
1617
|
+
break;
|
|
1594
1618
|
case 'near-clip':
|
|
1595
1619
|
this.nearClip = parseFloat(newValue);
|
|
1596
1620
|
break;
|
|
@@ -2292,7 +2316,7 @@ class LightComponentElement extends ComponentElement {
|
|
|
2292
2316
|
var _a;
|
|
2293
2317
|
this._shadowType = value;
|
|
2294
2318
|
if (this.component) {
|
|
2295
|
-
this.component.shadowType = (_a = shadowTypes.get(value)) !== null && _a !==
|
|
2319
|
+
this.component.shadowType = (_a = shadowTypes.get(value)) !== null && _a !== undefined ? _a : playcanvas.SHADOW_PCF3_32F;
|
|
2296
2320
|
}
|
|
2297
2321
|
}
|
|
2298
2322
|
/**
|
|
@@ -2498,7 +2522,7 @@ class MaterialElement extends HTMLElement {
|
|
|
2498
2522
|
}
|
|
2499
2523
|
static get(id) {
|
|
2500
2524
|
const materialElement = document.querySelector(`pc-material[id="${id}"]`);
|
|
2501
|
-
return materialElement === null || materialElement ===
|
|
2525
|
+
return materialElement === null || materialElement === undefined ? undefined : materialElement.material;
|
|
2502
2526
|
}
|
|
2503
2527
|
static get observedAttributes() {
|
|
2504
2528
|
return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
|
|
@@ -3110,7 +3134,7 @@ class ScriptComponentElement extends ComponentElement {
|
|
|
3110
3134
|
disconnectedCallback() {
|
|
3111
3135
|
var _a;
|
|
3112
3136
|
this.observer.disconnect();
|
|
3113
|
-
(_a = super.disconnectedCallback) === null || _a ===
|
|
3137
|
+
(_a = super.disconnectedCallback) === null || _a === undefined ? undefined : _a.call(this);
|
|
3114
3138
|
}
|
|
3115
3139
|
/**
|
|
3116
3140
|
* Gets the script component.
|
|
@@ -3424,7 +3448,7 @@ class SoundSlotElement extends AsyncElement {
|
|
|
3424
3448
|
}
|
|
3425
3449
|
async connectedCallback() {
|
|
3426
3450
|
var _a;
|
|
3427
|
-
await ((_a = this.soundElement) === null || _a ===
|
|
3451
|
+
await ((_a = this.soundElement) === null || _a === undefined ? undefined : _a.ready());
|
|
3428
3452
|
const options = {
|
|
3429
3453
|
autoPlay: this._autoPlay,
|
|
3430
3454
|
loop: this._loop,
|
|
@@ -3460,7 +3484,7 @@ class SoundSlotElement extends AsyncElement {
|
|
|
3460
3484
|
var _a;
|
|
3461
3485
|
this._asset = value;
|
|
3462
3486
|
if (this.soundSlot) {
|
|
3463
|
-
const id = (_a = AssetElement.get(value)) === null || _a ===
|
|
3487
|
+
const id = (_a = AssetElement.get(value)) === null || _a === undefined ? undefined : _a.id;
|
|
3464
3488
|
if (id) {
|
|
3465
3489
|
this.soundSlot.asset = id;
|
|
3466
3490
|
}
|
|
@@ -3687,8 +3711,8 @@ class ModelElement extends AsyncElement {
|
|
|
3687
3711
|
async _loadModel() {
|
|
3688
3712
|
var _a;
|
|
3689
3713
|
this._unloadModel();
|
|
3690
|
-
const appElement = await ((_a = this.closestApp) === null || _a ===
|
|
3691
|
-
const app = appElement === null || appElement ===
|
|
3714
|
+
const appElement = await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3715
|
+
const app = appElement === null || appElement === undefined ? undefined : appElement.app;
|
|
3692
3716
|
const asset = AssetElement.get(this._asset);
|
|
3693
3717
|
if (!asset) {
|
|
3694
3718
|
return;
|
|
@@ -3705,7 +3729,7 @@ class ModelElement extends AsyncElement {
|
|
|
3705
3729
|
}
|
|
3706
3730
|
_unloadModel() {
|
|
3707
3731
|
var _a;
|
|
3708
|
-
(_a = this._entity) === null || _a ===
|
|
3732
|
+
(_a = this._entity) === null || _a === undefined ? undefined : _a.destroy();
|
|
3709
3733
|
this._entity = null;
|
|
3710
3734
|
}
|
|
3711
3735
|
/**
|
|
@@ -3773,7 +3797,7 @@ class SceneElement extends AsyncElement {
|
|
|
3773
3797
|
}
|
|
3774
3798
|
async connectedCallback() {
|
|
3775
3799
|
var _a;
|
|
3776
|
-
await ((_a = this.closestApp) === null || _a ===
|
|
3800
|
+
await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3777
3801
|
this.scene = this.closestApp.app.scene;
|
|
3778
3802
|
this.updateSceneSettings();
|
|
3779
3803
|
this._onReady();
|
|
@@ -3947,8 +3971,8 @@ class SkyElement extends AsyncElement {
|
|
|
3947
3971
|
}
|
|
3948
3972
|
async _loadSkybox() {
|
|
3949
3973
|
var _a;
|
|
3950
|
-
const appElement = await ((_a = this.closestApp) === null || _a ===
|
|
3951
|
-
const app = appElement === null || appElement ===
|
|
3974
|
+
const appElement = await ((_a = this.closestApp) === null || _a === undefined ? undefined : _a.ready());
|
|
3975
|
+
const app = appElement === null || appElement === undefined ? undefined : appElement.app;
|
|
3952
3976
|
if (!app) {
|
|
3953
3977
|
return;
|
|
3954
3978
|
}
|
|
@@ -3971,10 +3995,10 @@ class SkyElement extends AsyncElement {
|
|
|
3971
3995
|
var _a, _b;
|
|
3972
3996
|
if (!this._scene)
|
|
3973
3997
|
return;
|
|
3974
|
-
(_a = this._scene.skybox) === null || _a ===
|
|
3998
|
+
(_a = this._scene.skybox) === null || _a === undefined ? undefined : _a.destroy();
|
|
3975
3999
|
// @ts-ignore
|
|
3976
4000
|
this._scene.skybox = null;
|
|
3977
|
-
(_b = this._scene.envAtlas) === null || _b ===
|
|
4001
|
+
(_b = this._scene.envAtlas) === null || _b === undefined ? undefined : _b.destroy();
|
|
3978
4002
|
// @ts-ignore
|
|
3979
4003
|
this._scene.envAtlas = null;
|
|
3980
4004
|
this._scene = null;
|