@playcanvas/web-components 0.2.5 → 0.2.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.
Files changed (49) hide show
  1. package/README.md +1 -1
  2. package/dist/app.d.ts +14 -3
  3. package/dist/asset.d.ts +1 -1
  4. package/dist/components/camera-component.d.ts +3 -3
  5. package/dist/components/collision-component.d.ts +1 -1
  6. package/dist/components/element-component.d.ts +1 -1
  7. package/dist/components/light-component.d.ts +2 -2
  8. package/dist/components/listener-component.d.ts +1 -1
  9. package/dist/components/particlesystem-component.d.ts +1 -1
  10. package/dist/components/render-component.d.ts +1 -1
  11. package/dist/components/rigidbody-component.d.ts +1 -1
  12. package/dist/components/screen-component.d.ts +2 -2
  13. package/dist/components/script-component.d.ts +1 -1
  14. package/dist/components/sound-component.d.ts +1 -1
  15. package/dist/components/splat-component.d.ts +13 -1
  16. package/dist/entity.d.ts +4 -4
  17. package/dist/material.d.ts +1 -1
  18. package/dist/model.d.ts +1 -1
  19. package/dist/module.d.ts +1 -1
  20. package/dist/pwc.cjs +155 -46
  21. package/dist/pwc.cjs.map +1 -1
  22. package/dist/pwc.js +155 -46
  23. package/dist/pwc.js.map +1 -1
  24. package/dist/pwc.min.js +1 -1
  25. package/dist/pwc.min.js.map +1 -1
  26. package/dist/pwc.mjs +156 -47
  27. package/dist/pwc.mjs.map +1 -1
  28. package/dist/scene.d.ts +1 -1
  29. package/package.json +16 -16
  30. package/src/app.ts +170 -15
  31. package/src/asset.ts +2 -1
  32. package/src/components/camera-component.ts +1 -1
  33. package/src/components/collision-component.ts +1 -1
  34. package/src/components/element-component.ts +1 -1
  35. package/src/components/light-component.ts +1 -1
  36. package/src/components/listener-component.ts +1 -1
  37. package/src/components/particlesystem-component.ts +1 -1
  38. package/src/components/render-component.ts +1 -1
  39. package/src/components/rigidbody-component.ts +1 -1
  40. package/src/components/screen-component.ts +1 -1
  41. package/src/components/script-component.ts +1 -1
  42. package/src/components/sound-component.ts +1 -1
  43. package/src/components/sound-slot.ts +3 -0
  44. package/src/components/splat-component.ts +33 -4
  45. package/src/entity.ts +4 -4
  46. package/src/material.ts +1 -1
  47. package/src/model.ts +1 -1
  48. package/src/module.ts +7 -14
  49. package/src/scene.ts +1 -1
package/dist/pwc.js CHANGED
@@ -42,7 +42,7 @@
42
42
 
43
43
  /**
44
44
  * The ModuleElement interface provides properties and methods for manipulating
45
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-module/ | `<pc-module>`} elements.
45
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`} elements.
46
46
  * The ModuleElement interface also inherits the properties and methods of the
47
47
  * {@link HTMLElement} interface.
48
48
  */
@@ -54,22 +54,15 @@
54
54
  }
55
55
  async loadModule() {
56
56
  const name = this.getAttribute('name');
57
- const glue = this.getAttribute('glue');
58
- const wasm = this.getAttribute('wasm');
59
- const fallback = this.getAttribute('fallback');
57
+ const glueUrl = this.getAttribute('glue');
58
+ const wasmUrl = this.getAttribute('wasm');
59
+ const fallbackUrl = this.getAttribute('fallback');
60
+ const config = { glueUrl, wasmUrl, fallbackUrl };
60
61
  if (name === 'Basis') {
61
- playcanvas.basisInitialize({
62
- glueUrl: glue,
63
- wasmUrl: wasm,
64
- fallbackUrl: fallback
65
- });
62
+ playcanvas.basisInitialize(config);
66
63
  }
67
64
  else {
68
- playcanvas.WasmModule.setConfig(name, {
69
- glueUrl: glue,
70
- wasmUrl: wasm,
71
- fallbackUrl: fallback
72
- });
65
+ playcanvas.WasmModule.setConfig(name, config);
73
66
  await new Promise((resolve) => {
74
67
  playcanvas.WasmModule.getInstance(name, () => resolve());
75
68
  });
@@ -83,7 +76,7 @@
83
76
 
84
77
  /**
85
78
  * The AppElement interface provides properties and methods for manipulating
86
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-app/ | `<pc-app>`} elements.
79
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
87
80
  * The AppElement interface also inherits the properties and methods of the
88
81
  * {@link HTMLElement} interface.
89
82
  */
@@ -100,6 +93,7 @@
100
93
  */
101
94
  this._canvas = null;
102
95
  this._alpha = true;
96
+ this._backend = 'webgl2';
103
97
  this._antialias = true;
104
98
  this._depth = true;
105
99
  this._stencil = true;
@@ -134,18 +128,84 @@
134
128
  // Create and append the canvas to the element
135
129
  this._canvas = document.createElement('canvas');
136
130
  this.appendChild(this._canvas);
137
- // Initialize the PlayCanvas application
138
- this.app = new playcanvas.Application(this._canvas, {
139
- graphicsDeviceOptions: {
140
- alpha: this._alpha,
141
- antialias: this._antialias,
142
- depth: this._depth,
143
- stencil: this._stencil
144
- },
145
- keyboard: new playcanvas.Keyboard(window),
146
- mouse: new playcanvas.Mouse(this._canvas)
131
+ // Configure device types based on backend selection
132
+ const backendToDeviceTypes = {
133
+ webgpu: ['webgpu', 'webgl2'], // fallback to webgl2 if webgpu not available
134
+ webgl2: ['webgl2'],
135
+ null: ['null']
136
+ };
137
+ const deviceTypes = backendToDeviceTypes[this._backend] || [];
138
+ const device = await playcanvas.createGraphicsDevice(this._canvas, {
139
+ // @ts-ignore - alpha needs to be documented
140
+ alpha: this._alpha,
141
+ antialias: this._antialias,
142
+ depth: this._depth,
143
+ deviceTypes: deviceTypes,
144
+ stencil: this._stencil
147
145
  });
148
- this.app.graphicsDevice.maxPixelRatio = this._highResolution ? window.devicePixelRatio : 1;
146
+ device.maxPixelRatio = this._highResolution ? window.devicePixelRatio : 1;
147
+ const createOptions = new playcanvas.AppOptions();
148
+ createOptions.graphicsDevice = device;
149
+ createOptions.keyboard = new playcanvas.Keyboard(window);
150
+ createOptions.mouse = new playcanvas.Mouse(this._canvas);
151
+ createOptions.componentSystems = [
152
+ playcanvas.AnimComponentSystem,
153
+ playcanvas.AnimationComponentSystem,
154
+ playcanvas.AudioListenerComponentSystem,
155
+ playcanvas.ButtonComponentSystem,
156
+ playcanvas.CameraComponentSystem,
157
+ playcanvas.CollisionComponentSystem,
158
+ playcanvas.ElementComponentSystem,
159
+ playcanvas.GSplatComponentSystem,
160
+ playcanvas.JointComponentSystem,
161
+ playcanvas.LayoutChildComponentSystem,
162
+ playcanvas.LayoutGroupComponentSystem,
163
+ playcanvas.LightComponentSystem,
164
+ playcanvas.ModelComponentSystem,
165
+ playcanvas.ParticleSystemComponentSystem,
166
+ playcanvas.RenderComponentSystem,
167
+ playcanvas.RigidBodyComponentSystem,
168
+ playcanvas.ScreenComponentSystem,
169
+ playcanvas.ScriptComponentSystem,
170
+ playcanvas.ScrollbarComponentSystem,
171
+ playcanvas.ScrollViewComponentSystem,
172
+ playcanvas.SoundComponentSystem,
173
+ playcanvas.SpriteComponentSystem,
174
+ playcanvas.ZoneComponentSystem
175
+ ];
176
+ createOptions.resourceHandlers = [
177
+ playcanvas.AnimClipHandler,
178
+ playcanvas.AnimationHandler,
179
+ playcanvas.AnimStateGraphHandler,
180
+ playcanvas.AudioHandler,
181
+ playcanvas.BinaryHandler,
182
+ playcanvas.CssHandler,
183
+ playcanvas.ContainerHandler,
184
+ playcanvas.CubemapHandler,
185
+ playcanvas.FolderHandler,
186
+ playcanvas.FontHandler,
187
+ playcanvas.GSplatHandler,
188
+ playcanvas.HierarchyHandler,
189
+ playcanvas.HtmlHandler,
190
+ playcanvas.JsonHandler,
191
+ playcanvas.MaterialHandler,
192
+ playcanvas.ModelHandler,
193
+ playcanvas.RenderHandler,
194
+ playcanvas.ScriptHandler,
195
+ playcanvas.SceneHandler,
196
+ playcanvas.ShaderHandler,
197
+ playcanvas.SpriteHandler,
198
+ playcanvas.TemplateHandler,
199
+ playcanvas.TextHandler,
200
+ playcanvas.TextureAtlasHandler,
201
+ playcanvas.TextureHandler
202
+ ];
203
+ createOptions.soundManager = new playcanvas.SoundManager();
204
+ createOptions.lightmapper = playcanvas.Lightmapper;
205
+ createOptions.batchManager = playcanvas.BatchManager;
206
+ createOptions.xr = playcanvas.XrManager;
207
+ this.app = new playcanvas.AppBase(this._canvas);
208
+ this.app.init(createOptions);
149
209
  this.app.setCanvasFillMode(playcanvas.FILLMODE_FILL_WINDOW);
150
210
  this.app.setCanvasResolution(playcanvas.RESOLUTION_AUTO);
151
211
  this._pickerCreate();
@@ -373,6 +433,20 @@
373
433
  get antialias() {
374
434
  return this._antialias;
375
435
  }
436
+ /**
437
+ * Sets the graphics backend.
438
+ * @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
439
+ */
440
+ set backend(value) {
441
+ this._backend = value;
442
+ }
443
+ /**
444
+ * Gets the graphics backend.
445
+ * @returns The graphics backend.
446
+ */
447
+ get backend() {
448
+ return this._backend;
449
+ }
376
450
  /**
377
451
  * Sets the depth flag.
378
452
  * @param value - The depth flag.
@@ -428,7 +502,7 @@
428
502
  return this._stencil;
429
503
  }
430
504
  static get observedAttributes() {
431
- return ['alpha', 'antialias', 'depth', 'stencil', 'high-resolution'];
505
+ return ['alpha', 'antialias', 'backend', 'depth', 'stencil', 'high-resolution'];
432
506
  }
433
507
  attributeChangedCallback(name, _oldValue, newValue) {
434
508
  switch (name) {
@@ -438,6 +512,11 @@
438
512
  case 'antialias':
439
513
  this.antialias = newValue !== 'false';
440
514
  break;
515
+ case 'backend':
516
+ if (newValue === 'webgpu' || newValue === 'webgl2' || newValue === 'null') {
517
+ this.backend = newValue;
518
+ }
519
+ break;
441
520
  case 'depth':
442
521
  this.depth = newValue !== 'false';
443
522
  break;
@@ -667,7 +746,7 @@
667
746
 
668
747
  /**
669
748
  * The EntityElement interface provides properties and methods for manipulating
670
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
749
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
671
750
  * The EntityElement interface also inherits the properties and methods of the
672
751
  * {@link HTMLElement} interface.
673
752
  */
@@ -1204,7 +1283,7 @@
1204
1283
  };
1205
1284
  /**
1206
1285
  * The AssetElement interface provides properties and methods for manipulating
1207
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-asset/ | `<pc-asset>`} elements.
1286
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-asset/ | `<pc-asset>`} elements.
1208
1287
  * The AssetElement interface also inherits the properties and methods of the
1209
1288
  * {@link HTMLElement} interface.
1210
1289
  */
@@ -1243,6 +1322,7 @@
1243
1322
  });
1244
1323
  }
1245
1324
  else {
1325
+ // @ts-ignore
1246
1326
  this.asset = new playcanvas.Asset(id, type, { url: src });
1247
1327
  }
1248
1328
  this.asset.preload = !this._lazy;
@@ -1365,7 +1445,7 @@
1365
1445
 
1366
1446
  /**
1367
1447
  * The ListenerComponentElement interface provides properties and methods for manipulating
1368
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
1448
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
1369
1449
  * The ListenerComponentElement interface also inherits the properties and methods of the
1370
1450
  * {@link HTMLElement} interface.
1371
1451
  *
@@ -1397,7 +1477,7 @@
1397
1477
  ]);
1398
1478
  /**
1399
1479
  * The CameraComponentElement interface provides properties and methods for manipulating
1400
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
1480
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
1401
1481
  * The CameraComponentElement interface also inherits the properties and methods of the
1402
1482
  * {@link HTMLElement} interface.
1403
1483
  *
@@ -1878,7 +1958,7 @@
1878
1958
 
1879
1959
  /**
1880
1960
  * The CollisionComponentElement interface provides properties and methods for manipulating
1881
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-collision/ | `<pc-collision>`} elements.
1961
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-collision/ | `<pc-collision>`} elements.
1882
1962
  * The CollisionComponentElement interface also inherits the properties and methods of the
1883
1963
  * {@link HTMLElement} interface.
1884
1964
  *
@@ -2025,7 +2105,7 @@
2025
2105
 
2026
2106
  /**
2027
2107
  * The ElementComponentElement interface provides properties and methods for manipulating
2028
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-element/ | `<pc-element>`} elements.
2108
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-element/ | `<pc-element>`} elements.
2029
2109
  * The ElementComponentElement interface also inherits the properties and methods of the
2030
2110
  * {@link HTMLElement} interface.
2031
2111
  *
@@ -2330,7 +2410,7 @@
2330
2410
  ]);
2331
2411
  /**
2332
2412
  * The LightComponentElement interface provides properties and methods for manipulating
2333
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-light/ | `<pc-light>`} elements.
2413
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-light/ | `<pc-light>`} elements.
2334
2414
  * The LightComponentElement interface also inherits the properties and methods of the
2335
2415
  * {@link HTMLElement} interface.
2336
2416
  *
@@ -2727,7 +2807,7 @@
2727
2807
 
2728
2808
  /**
2729
2809
  * The ParticleSystemComponentElement interface provides properties and methods for manipulating
2730
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
2810
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
2731
2811
  * The ParticleSystemComponentElement interface also inherits the properties and methods of the
2732
2812
  * {@link HTMLElement} interface.
2733
2813
  *
@@ -2859,7 +2939,7 @@
2859
2939
 
2860
2940
  /**
2861
2941
  * The MaterialElement interface provides properties and methods for manipulating
2862
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-material/ | `<pc-material>`} elements.
2942
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-material/ | `<pc-material>`} elements.
2863
2943
  * The MaterialElement interface also inherits the properties and methods of the
2864
2944
  * {@link HTMLElement} interface.
2865
2945
  */
@@ -2976,7 +3056,7 @@
2976
3056
 
2977
3057
  /**
2978
3058
  * The RenderComponentElement interface provides properties and methods for manipulating
2979
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-render/ | `<pc-render>`} elements.
3059
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-render/ | `<pc-render>`} elements.
2980
3060
  * The RenderComponentElement interface also inherits the properties and methods of the
2981
3061
  * {@link HTMLElement} interface.
2982
3062
  *
@@ -3099,7 +3179,7 @@
3099
3179
 
3100
3180
  /**
3101
3181
  * The RigidBodyComponentElement interface provides properties and methods for manipulating
3102
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-rigidbody/ | `<pc-rigidbody>`} elements.
3182
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-rigidbody/ | `<pc-rigidbody>`} elements.
3103
3183
  * The RigidBodyComponentElement interface also inherits the properties and methods of the
3104
3184
  * {@link HTMLElement} interface.
3105
3185
  *
@@ -3287,7 +3367,7 @@
3287
3367
 
3288
3368
  /**
3289
3369
  * The ScreenComponentElement interface provides properties and methods for manipulating
3290
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-screen/ | `<pc-screen>`} elements.
3370
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-screen/ | `<pc-screen>`} elements.
3291
3371
  * The ScreenComponentElement interface also inherits the properties and methods of the
3292
3372
  * {@link HTMLElement} interface.
3293
3373
  *
@@ -3414,7 +3494,7 @@
3414
3494
 
3415
3495
  /**
3416
3496
  * The ScriptComponentElement interface provides properties and methods for manipulating
3417
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-scripts/ | `<pc-scripts>`} elements.
3497
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scripts/ | `<pc-scripts>`} elements.
3418
3498
  * The ScriptComponentElement interface also inherits the properties and methods of the
3419
3499
  * {@link HTMLElement} interface.
3420
3500
  *
@@ -3722,7 +3802,7 @@
3722
3802
 
3723
3803
  /**
3724
3804
  * The SoundComponentElement interface provides properties and methods for manipulating
3725
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-sounds/ | `<pc-sounds>`} elements.
3805
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-sounds/ | `<pc-sounds>`} elements.
3726
3806
  * The SoundComponentElement interface also inherits the properties and methods of the
3727
3807
  * {@link HTMLElement} interface.
3728
3808
  *
@@ -3956,6 +4036,9 @@
3956
4036
  }
3957
4037
  this.soundSlot = this.soundElement.component.addSlot(this._name, options);
3958
4038
  this.asset = this._asset;
4039
+ if (this._autoPlay) {
4040
+ this.soundSlot.play();
4041
+ }
3959
4042
  this._onReady();
3960
4043
  }
3961
4044
  disconnectedCallback() {
@@ -4165,7 +4248,7 @@
4165
4248
 
4166
4249
  /**
4167
4250
  * The SplatComponentElement interface provides properties and methods for manipulating
4168
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
4251
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
4169
4252
  * The SplatComponentElement interface also inherits the properties and methods of the
4170
4253
  * {@link HTMLElement} interface.
4171
4254
  *
@@ -4176,10 +4259,12 @@
4176
4259
  constructor() {
4177
4260
  super('gsplat');
4178
4261
  this._asset = '';
4262
+ this._castShadows = false;
4179
4263
  }
4180
4264
  getInitialComponentData() {
4181
4265
  return {
4182
- asset: AssetElement.get(this._asset)
4266
+ asset: AssetElement.get(this._asset),
4267
+ castShadows: this._castShadows
4183
4268
  };
4184
4269
  }
4185
4270
  /**
@@ -4207,8 +4292,29 @@
4207
4292
  get asset() {
4208
4293
  return this._asset;
4209
4294
  }
4295
+ /**
4296
+ * Sets whether the splat casts shadows.
4297
+ * @param value - Whether the splat casts shadows.
4298
+ */
4299
+ set castShadows(value) {
4300
+ this._castShadows = value;
4301
+ if (this.component) {
4302
+ this.component.castShadows = value;
4303
+ }
4304
+ }
4305
+ /**
4306
+ * Gets whether the splat casts shadows.
4307
+ * @returns Whether the splat casts shadows.
4308
+ */
4309
+ get castShadows() {
4310
+ return this._castShadows;
4311
+ }
4210
4312
  static get observedAttributes() {
4211
- return [...super.observedAttributes, 'asset'];
4313
+ return [
4314
+ ...super.observedAttributes,
4315
+ 'asset',
4316
+ 'cast-shadows'
4317
+ ];
4212
4318
  }
4213
4319
  attributeChangedCallback(name, _oldValue, newValue) {
4214
4320
  super.attributeChangedCallback(name, _oldValue, newValue);
@@ -4216,6 +4322,9 @@
4216
4322
  case 'asset':
4217
4323
  this.asset = newValue;
4218
4324
  break;
4325
+ case 'cast-shadows':
4326
+ this.castShadows = this.hasAttribute('cast-shadows');
4327
+ break;
4219
4328
  }
4220
4329
  }
4221
4330
  }
@@ -4223,7 +4332,7 @@
4223
4332
 
4224
4333
  /**
4225
4334
  * The ModelElement interface provides properties and methods for manipulating
4226
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-model/ | `<pc-model>`} elements.
4335
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-model/ | `<pc-model>`} elements.
4227
4336
  * The ModelElement interface also inherits the properties and methods of the
4228
4337
  * {@link HTMLElement} interface.
4229
4338
  */
@@ -4319,7 +4428,7 @@
4319
4428
 
4320
4429
  /**
4321
4430
  * The SceneElement interface provides properties and methods for manipulating
4322
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-scene/ | `<pc-scene>`} elements.
4431
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scene/ | `<pc-scene>`} elements.
4323
4432
  * The SceneElement interface also inherits the properties and methods of the
4324
4433
  * {@link HTMLElement} interface.
4325
4434
  */