@playcanvas/web-components 0.1.5 → 0.1.7

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 CHANGED
@@ -1,6 +1,34 @@
1
1
  # PlayCanvas Web Components
2
2
 
3
- Unleash the power of PlayCanvas in your HTML. PlayCanvas Web Components allows you to write PlayCanvas scenes using only HTML, enabling a clear and concise structure, and making it easier than ever to integrate with other web technologies. Just add tags for entities, components, and assets, and watch your 3D scene come to life!
3
+ [![NPM Version](https://img.shields.io/npm/v/@playcanvas/web-components.svg)](https://www.npmjs.com/package/@playcanvas/web-components)
4
+ [![NPM Downloads](https://img.shields.io/npm/dw/@playcanvas/web-components)](https://npmtrends.com/@playcanvas/web-components)
5
+ [![License](https://img.shields.io/npm/l/@playcanvas/web-components.svg)](https://github.com/playcanvas/web-components/blob/main/LICENSE)
6
+ [![GitHub Actions Build Status](https://github.com/playcanvas/web-components/actions/workflows/deploy.yml/badge.svg)](https://github.com/playcanvas/web-components/actions/workflows/deploy.yml)
7
+
8
+ 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
+
10
+ ```html
11
+ <!-- A lit sphere -->
12
+ <pc-app>
13
+ <pc-scene>
14
+ <pc-entity name="camera" position="0 0 3">
15
+ <pc-camera></pc-camera>
16
+ </pc-entity>
17
+ <pc-entity name="light" rotation="45 45 0">
18
+ <pc-light></pc-light>
19
+ </pc-entity>
20
+ <pc-entity name="ball">
21
+ <pc-render type="sphere"></pc-render>
22
+ </pc-entity>
23
+ </pc-scene>
24
+ </pc-app>
25
+ ```
26
+
27
+ ## Examples
28
+
29
+ [![image](https://github.com/user-attachments/assets/6106ec23-30ab-4662-8370-c3b286386ce9)](https://playcanvas.github.io/web-components/examples)
30
+
31
+ See PlayCanvas Web Components in action here: https://playcanvas.github.io/web-components/examples
4
32
 
5
33
  ## Usage 🚧
6
34
 
@@ -15,13 +43,13 @@ Or you can include it directly in your HTML file from a CDN.
15
43
  ES Modules:
16
44
 
17
45
  ```html
18
- <script type="module" src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.4/dist/pwc.mjs"></script>
46
+ <script type="module" src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.5/dist/pwc.mjs"></script>
19
47
  ```
20
48
 
21
49
  UMD:
22
50
 
23
51
  ```html
24
- <script src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.4"></script>
52
+ <script src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.5"></script>
25
53
  ```
26
54
 
27
55
  ## Tag Reference 📖
@@ -54,7 +82,11 @@ The `pc-app` tag is the root element for your PlayCanvas application. It is used
54
82
 
55
83
  | Attribute | Description |
56
84
  | --- | --- |
57
- | `high-resolution` | Valueless attribute. If present, enables high-resolution mode. |
85
+ | `alpha` | Boolean attribute. Determines whether the application allocates an alpha channel in the frame buffer. Defaults to `true`. |
86
+ | `antialias` | Boolean attribute. Determines whether the application uses anti-aliasing. Defaults to `true`. |
87
+ | `depth` | Boolean attribute. Determines whether the application allocates a depth buffer. Defaults to `true`. |
88
+ | `high-resolution` | Boolean attribute. Determines whether the application renders using physical resolution or CSS resolution. Defaults to `true`. |
89
+ | `stencil` | Boolean attribute. Determines whether the application allocates a stencil buffer. Defaults to `true`. |
58
90
 
59
91
  ### pc-asset
60
92
 
@@ -73,7 +105,7 @@ The `pc-camera` tag is used to define a camera component. It must be a direct ch
73
105
 
74
106
  | Attribute | Description |
75
107
  | --- | --- |
76
- | `clear-color` | The background color of the camera. Can be a comma-separated list of R, G, B, and A values or a hex color code. If unspecified, `0.75,0.75,0.75,1` is used. |
108
+ | `clear-color` | The background color of the camera. Can be a space-separated list of R, G, B, and A values or a hex color code. If unspecified, `0.75,0.75,0.75,1` is used. |
77
109
  | `clear-color-buffer` | Boolean attribute. Controls whether the camera clears the color buffer. If unspecified, the color buffer is cleared. |
78
110
  | `clear-depth-buffer` | Boolean attribute. Controls whether the camera clears the depth buffer. If unspecified, the depth buffer is cleared. |
79
111
  | `clear-stencil-buffer` | Boolean attribute. Controls whether the camera clears the stencil buffer. If unspecified, the stencil buffer is cleared. |
@@ -86,8 +118,8 @@ The `pc-camera` tag is used to define a camera component. It must be a direct ch
86
118
  | `orthographic` | Valueless attribute. If present, the camera uses an orthographic projection. If unspecified, the camera uses a perspective projection. |
87
119
  | `ortho-height` | The height of the orthographic projection. If unspecified, `10` is used. |
88
120
  | `priority` | The priority of the camera. If unspecified, `0` is used. |
89
- | `rect` | The viewport rectangle of the camera. Specified as a comma-separated list of X, Y, Width, and Height values. If unspecified, `0,0,1,1` is used. |
90
- | `scissor-rect` | The scissor rectangle of the camera. Specified as a comma-separated list of X, Y, Width, and Height values. If not specified, `0,0,1,1` is used. |
121
+ | `rect` | The viewport rectangle of the camera. Specified as a space-separated list of X, Y, Width, and Height values. If unspecified, `0 0 1 1` is used. |
122
+ | `scissor-rect` | The scissor rectangle of the camera. Specified as a space-separated list of X, Y, Width, and Height values. If not specified, `0 0 1 1` is used. |
91
123
 
92
124
  ### pc-collision
93
125
 
@@ -98,7 +130,7 @@ The `pc-collision` tag is used to define a collision component. It must be a dir
98
130
  | `axis` | The axis of the collision component. If not specified, `1` is used (Y-axis). |
99
131
  | `convex-hull` | Valueless attribute. If present, the collision component uses a convex hull. |
100
132
  | `enabled` | Enabled state of the collision component. If not specified, `true` is used. |
101
- | `half-extents` | The half-extents of the collision component. Specified as a comma-separated list of X, Y, and Z values. If not specified, `0.5,0.5,0.5` is used. |
133
+ | `half-extents` | The half-extents of the collision component. Specified as a space-separated list of X, Y, and Z values. If not specified, `0.5 0.5 0.5` is used. |
102
134
  | `height` | The height of the collision component. If not specified, `2` is used. |
103
135
  | `radius` | The radius of the collision component. If not specified, `0.5` is used. |
104
136
  | `type` | The type of collision component. Can be `box`, `capsule`, `cone`, `cylinder` or `sphere`. |
@@ -109,13 +141,13 @@ The `pc-element` tag is used to define an element component. It must be a direct
109
141
 
110
142
  | Attribute | Description |
111
143
  | --- | --- |
112
- | `anchor` | The anchor of the element component. Specified as a comma-separated list of X, Y, Z, and W values. If not specified, `0,0,0,1` is used. |
144
+ | `anchor` | The anchor of the element component. Specified as a space-separated list of X, Y, Z, and W values. If not specified, `0 0 0 1` is used. |
113
145
  | `asset` | A string that should match the `id` of a `pc-asset` tag that has a type of `font`. |
114
146
  | `auto-width` | Valueless attribute. If present, the element component automatically adjusts its width. |
115
- | `color` | The color of the element component. Can be a comma-separated list of R, G, B, and A values or a hex color code. If not specified, `1,1,1,1` is used. |
147
+ | `color` | The color of the element component. Can be a space-separated list of R, G, B, and A values or a hex color code. If not specified, `1 1 1 1` is used. |
116
148
  | `font-size` | The font size of the element component. If not specified, `16` is used. |
117
149
  | `line-height` | The line height of the element component. If not specified, `1.2` is used. |
118
- | `pivot` | The pivot of the element component. Specified as a comma-separated list of X and Y values. If not specified, `0.5,0.5` is used. |
150
+ | `pivot` | The pivot of the element component. Specified as a space-separated list of X and Y values. If not specified, `0.5 0.5` is used. |
119
151
  | `text` | The text of the element component. |
120
152
  | `type` | The type of element component. Can be `group`, `image` or `text`. If not specified, `group` is used. |
121
153
  | `width` | The width of the element component. If not specified, `0` is used. |
@@ -129,10 +161,10 @@ The `pc-entity` tag is used to define an entity. It must be a direct child of `p
129
161
  | --- | --- |
130
162
  | `enabled` | Enabled state of the entity. If not specified, `true` is used. |
131
163
  | `name` | The name of the entity. |
132
- | `position` | The position of the entity. Specified as a comma-separated list of X, Y, and Z values. If not specified, `0,0,0` is used. |
133
- | `rotation` | The rotation of the entity. Specified as a comma-separated list of X, Y, and Z Euler angles in degrees. If not specified, `0,0,0` is used. |
134
- | `scale` | The scale of the entity. Specified as a comma-separated list of X, Y, and Z values. If not specified, `1,1,1` is used. |
135
- | `tags` | A comma-separated list of tags for the entity. |
164
+ | `position` | The position of the entity. Specified as a space-separated list of X, Y, and Z values. If not specified, `0 0 0` is used. |
165
+ | `rotation` | The rotation of the entity. Specified as a space-separated list of X, Y, and Z Euler angles in degrees. If not specified, `0 0 0` is used. |
166
+ | `scale` | The scale of the entity. Specified as a space-separated list of X, Y, and Z values. If not specified, `1 1 1` is used. |
167
+ | `tags` | A space-separated list of tags for the entity. |
136
168
 
137
169
  ### pc-light
138
170
 
@@ -140,7 +172,7 @@ The `pc-light` tag is used to define a light component. It must be a direct chil
140
172
 
141
173
  | Attribute | Description |
142
174
  | --- | --- |
143
- | `color` | The color of the light. Can be a comma-separated list of R, G, B values or a hex color code. If not specified, `1,1,1` is used. |
175
+ | `color` | The color of the light. Can be a space-separated list of R, G, B values or a hex color code. If not specified, `1 1 1` is used. |
144
176
  | `cast-shadows` | Valueless attribute. If present, the light casts shadows. |
145
177
  | `inner-cone-angle` | The angle of the light's inner cone. If not specified, `40` is used. |
146
178
  | `intensity` | The intensity of the light. If not specified, `1` is used. |
@@ -183,10 +215,10 @@ The `pc-rigidbody` tag is used to define a rigidbody component. It must be a dir
183
215
  | Attribute | Description |
184
216
  | --- | --- |
185
217
  | `angular-damping` | The angular damping of the rigidbody. If not specified, `0` is used. |
186
- | `angular-factor` | The angular factor of the rigidbody. Specified as a comma-separated list of X, Y, and Z values. If not specified, `1,1,1` is used. |
218
+ | `angular-factor` | The angular factor of the rigidbody. Specified as a space-separated list of X, Y, and Z values. If not specified, `1 1 1` is used. |
187
219
  | `friction` | The friction of the rigidbody. If not specified, `0.5` is used. |
188
220
  | `linear-damping` | The linear damping of the rigidbody. If not specified, `0` is used. |
189
- | `linear-factor` | The linear factor of the rigidbody. Specified as a comma-separated list of X, Y, and Z values. If not specified, `1,1,1` is used. |
221
+ | `linear-factor` | The linear factor of the rigidbody. Specified as a space-separated list of X, Y, and Z values. If not specified, `1 1 1` is used. |
190
222
  | `mass` | The mass of the rigidbody. If not specified, `1` is used. |
191
223
  | `restitution` | The restitution of the rigidbody. If not specified, `0` is used. |
192
224
  | `rolling-friction` | The rolling friction of the rigidbody. If not specified, `0` is used. |
@@ -212,8 +244,8 @@ The `pc-screen` tag is used to define a screen component. It must be a direct ch
212
244
  | --- | --- |
213
245
  | `blend` | Valueless attribute. If present, the screen component blends. |
214
246
  | `priority` | The priority of the screen component. Must be an integer between `0` and `255`. If not specified, `0` is used. |
215
- | `reference-resolution` | The reference resolution of the screen component. Specified as a comma-separated list of Width and Height values. If not specified, `640,320` is used. |
216
- | `resolution` | The resolution of the screen component. Specified as a comma-separated list of Width and Height values. If not specified, `640,320` is used. |
247
+ | `reference-resolution` | The reference resolution of the screen component. Specified as a space-separated list of Width and Height values. If not specified, `640 320` is used. |
248
+ | `resolution` | The resolution of the screen component. Specified as a space-separated list of Width and Height values. If not specified, `640 320` is used. |
217
249
  | `scale-blend` | The scale blend of the screen component. Must be a number between `0` and `1`. If not specified, `0.5` is used. |
218
250
  | `screen-space` | Valueless attribute. If present, the screen component is in screen space. |
219
251
 
@@ -243,11 +275,11 @@ The `pc-sky` tag is used to define a sky component. It must be a direct child of
243
275
  | Attribute | Description |
244
276
  | --- | --- |
245
277
  | `asset` | A string that should match the `id` of a `pc-asset` tag that has a type of `texture`. |
246
- | `center` | The center of the sky. Specified as a comma-separated list of X, Y, and Z values in the range 0 to 1. If not specified, `0,0.01,0` is used. |
278
+ | `center` | The center of the sky. Specified as a space-separated list of X, Y, and Z values in the range 0 to 1. If not specified, `0 0.01 0` is used. |
247
279
  | `intensity` | The intensity of the sky. If not specified, `1` is used. |
248
280
  | `level` | The mipmap level used to render the sky. If not specified, `0` is used (base mip level). |
249
- | `rotation` | The rotation of the sky. Specified as a comma-separated list of X, Y, and Z values. If not specified, `0,0,0` is used. |
250
- | `scale` | The scale of the sky. Specified as a comma-separated list of X, Y, and Z values. If not specified, `100,100,100` is used. |
281
+ | `rotation` | The rotation of the sky. Specified as a space-separated list of X, Y, and Z values. If not specified, `0 0 0` is used. |
282
+ | `scale` | The scale of the sky. Specified as a space-separated list of X, Y, and Z values. If not specified, `100 100 100` is used. |
251
283
  | `type` | The type of sky component. Can be `box`, `dome`, `infinite` or `none`. |
252
284
 
253
285
  ### pc-sound
@@ -272,8 +304,12 @@ The `pc-sounds` tag is used to define a sound component. It must be a direct chi
272
304
 
273
305
  | Attribute | Description |
274
306
  | --- | --- |
307
+ | `distance-model` | The distance model of the sound. Can be `exponential`, `inverse` or `linear`. If not specified, `linear` is used. |
275
308
  | `pitch` | The pitch of the sound. If not specified, `1` is used. |
309
+ | `max-distance` | The maximum distance from the listener at which audio falloff stops. If not specified, `10000` is used. |
276
310
  | `positional` | Valueless attribute. If present, the sound is positional. |
311
+ | `ref-distance` | The distance from the listener at which the volume will be at full volume. If not specified, `1` is used. |
312
+ | `roll-off-factor` | The factor used in the falloff equation. If not specified, `1` is used. |
277
313
  | `volume` | The volume of the sound. If not specified, `1` is used. |
278
314
 
279
315
  ### pc-splat
@@ -284,45 +320,3 @@ The `pc-splat` tag is used to define a splat component. It must be a direct chil
284
320
  | --- | --- |
285
321
  | `asset` | A string that should match the `id` of a `pc-asset` tag that has a type of `gsplat`. |
286
322
  | `enabled` | Enabled state of the splat component. If not specified, `true` is used. |
287
-
288
- ## Example
289
-
290
- Below is a basic example of how to use PlayCanvas Web Components to create a simple 3D scene (a humble sphere):
291
-
292
- ```html
293
- <!DOCTYPE html>
294
- <html lang="en">
295
- <head>
296
- <meta charset="UTF-8">
297
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
298
- <title>PlayCanvas Web Components - Sphere</title>
299
- <script type="importmap">
300
- {
301
- "imports": {
302
- "playcanvas": "https://esm.run/playcanvas@2.2.2"
303
- }
304
- }
305
- </script>
306
- <script type="module" src="https://cdn.jsdelivr.net/npm/@playcanvas/web-components@0.1.4/dist/pwc.mjs"></script>
307
- <link rel="stylesheet" href="styles.css">
308
- </head>
309
- <body>
310
- <pc-app>
311
- <pc-scene>
312
- <!-- Camera -->
313
- <pc-entity name="camera" position="0,0,3">
314
- <pc-camera clear-color="#8099e6"></pc-camera>
315
- </pc-entity>
316
- <!-- Light -->
317
- <pc-entity name="light" rotation="45,0,0">
318
- <pc-light></pc-light>
319
- </pc-entity>
320
- <!-- Sphere -->
321
- <pc-entity name="sphere">
322
- <pc-render type="sphere"></pc-render>
323
- </pc-entity>
324
- </pc-scene>
325
- </pc-app>
326
- </body>
327
- </html>
328
- ```
package/dist/app.d.ts CHANGED
@@ -8,6 +8,10 @@ declare class AppElement extends AsyncElement {
8
8
  * The canvas element.
9
9
  */
10
10
  private _canvas;
11
+ private _alpha;
12
+ private _antialias;
13
+ private _depth;
14
+ private _stencil;
11
15
  private _highResolution;
12
16
  /**
13
17
  * The PlayCanvas application instance.
@@ -20,6 +24,36 @@ declare class AppElement extends AsyncElement {
20
24
  connectedCallback(): Promise<void>;
21
25
  disconnectedCallback(): void;
22
26
  _onWindowResize(): void;
27
+ /**
28
+ * Sets the alpha flag.
29
+ * @param value - The alpha flag.
30
+ */
31
+ set alpha(value: boolean);
32
+ /**
33
+ * Gets the alpha flag.
34
+ * @returns The alpha flag.
35
+ */
36
+ get alpha(): boolean;
37
+ /**
38
+ * Sets the antialias flag.
39
+ * @param value - The antialias flag.
40
+ */
41
+ set antialias(value: boolean);
42
+ /**
43
+ * Gets the antialias flag.
44
+ * @returns The antialias flag.
45
+ */
46
+ get antialias(): boolean;
47
+ /**
48
+ * Sets the depth flag.
49
+ * @param value - The depth flag.
50
+ */
51
+ set depth(value: boolean);
52
+ /**
53
+ * Gets the depth flag.
54
+ * @returns The depth flag.
55
+ */
56
+ get depth(): boolean;
23
57
  /**
24
58
  * Sets the high resolution flag. When true, the application will render at the device's
25
59
  * physical resolution. When false, the application will render at CSS resolution.
@@ -31,7 +65,17 @@ declare class AppElement extends AsyncElement {
31
65
  * @returns The high resolution flag.
32
66
  */
33
67
  get highResolution(): boolean;
68
+ /**
69
+ * Sets the stencil flag.
70
+ * @param value - The stencil flag.
71
+ */
72
+ set stencil(value: boolean);
73
+ /**
74
+ * Gets the stencil flag.
75
+ * @returns The stencil flag.
76
+ */
77
+ get stencil(): boolean;
34
78
  static get observedAttributes(): string[];
35
- attributeChangedCallback(name: string, _oldValue: string, _newValue: string): void;
79
+ attributeChangedCallback(name: string, _oldValue: string, newValue: string): void;
36
80
  }
37
81
  export { AppElement };
@@ -0,0 +1 @@
1
+ export declare const CSS_COLORS: Record<string, string>;
@@ -6,13 +6,21 @@ import { ComponentElement } from './component';
6
6
  * @category Components
7
7
  */
8
8
  declare class SoundComponentElement extends ComponentElement {
9
+ private _distanceModel;
10
+ private _maxDistance;
9
11
  private _pitch;
10
12
  private _positional;
13
+ private _refDistance;
14
+ private _rollOffFactor;
11
15
  private _volume;
12
16
  constructor();
13
17
  getInitialComponentData(): {
18
+ distanceModel: "exponential" | "inverse" | "linear";
19
+ maxDistance: number;
14
20
  pitch: number;
15
21
  positional: boolean;
22
+ refDistance: number;
23
+ rollOffFactor: number;
16
24
  volume: number;
17
25
  };
18
26
  /**
@@ -20,6 +28,26 @@ declare class SoundComponentElement extends ComponentElement {
20
28
  * @returns The sound component.
21
29
  */
22
30
  get component(): SoundComponent | null;
31
+ /**
32
+ * Sets which algorithm to use to reduce the volume of the sound as it moves away from the listener.
33
+ * @param value - The distance model.
34
+ */
35
+ set distanceModel(value: 'exponential' | 'inverse' | 'linear');
36
+ /**
37
+ * Gets which algorithm to use to reduce the volume of the sound as it moves away from the listener.
38
+ * @returns The distance model.
39
+ */
40
+ get distanceModel(): 'exponential' | 'inverse' | 'linear';
41
+ /**
42
+ * Sets the maximum distance from the listener at which audio falloff stops.
43
+ * @param value - The max distance.
44
+ */
45
+ set maxDistance(value: number);
46
+ /**
47
+ * Gets the maximum distance from the listener at which audio falloff stops.
48
+ * @returns The max distance.
49
+ */
50
+ get maxDistance(): number;
23
51
  /**
24
52
  * Sets the pitch of the sound.
25
53
  * @param value - The pitch.
@@ -40,6 +68,26 @@ declare class SoundComponentElement extends ComponentElement {
40
68
  * @returns The positional flag.
41
69
  */
42
70
  get positional(): boolean;
71
+ /**
72
+ * Sets the reference distance for reducing volume as the sound source moves further from the listener. Defaults to 1.
73
+ * @param value - The ref distance.
74
+ */
75
+ set refDistance(value: number);
76
+ /**
77
+ * Gets the reference distance for reducing volume as the sound source moves further from the listener.
78
+ * @returns The ref distance.
79
+ */
80
+ get refDistance(): number;
81
+ /**
82
+ * Sets the factor used in the falloff equation. Defaults to 1.
83
+ * @param value - The roll-off factor.
84
+ */
85
+ set rollOffFactor(value: number);
86
+ /**
87
+ * Gets the factor used in the falloff equation.
88
+ * @returns The roll-off factor.
89
+ */
90
+ get rollOffFactor(): number;
43
91
  /**
44
92
  * Sets the volume of the sound.
45
93
  * @param value - The volume.
package/dist/model.d.ts CHANGED
@@ -4,8 +4,12 @@ import { AsyncElement } from './async-element';
4
4
  */
5
5
  declare class ModelElement extends AsyncElement {
6
6
  private _asset;
7
- connectedCallback(): Promise<void>;
8
- _loadModel(): void;
7
+ private _entity;
8
+ connectedCallback(): void;
9
+ disconnectedCallback(): void;
10
+ private _instantiate;
11
+ private _loadModel;
12
+ private _unloadModel;
9
13
  /**
10
14
  * Sets the asset ID of the model.
11
15
  * @param value - The asset ID.