@playcanvas/web-components 0.2.6 → 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 +1 -1
  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 +1 -1
  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 +1 -1
  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 +1 -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 +120 -31
  21. package/dist/pwc.cjs.map +1 -1
  22. package/dist/pwc.js +120 -31
  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 +121 -32
  27. package/dist/pwc.mjs.map +1 -1
  28. package/dist/scene.d.ts +1 -1
  29. package/package.json +14 -14
  30. package/src/app.ts +170 -15
  31. package/src/asset.ts +1 -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 +1 -1
  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 +1 -1
  49. package/src/scene.ts +1 -1
package/dist/pwc.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { basisInitialize, WasmModule, Application, Mouse, Keyboard, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Picker, Vec3, Vec4, Color, Quat, Vec2, Entity, Asset, GAMMA_SRGB, GAMMA_NONE, XRTYPE_VR, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, TONEMAP_NONE, TONEMAP_LINEAR, TONEMAP_FILMIC, TONEMAP_HEJL, TONEMAP_ACES, TONEMAP_ACES2, TONEMAP_NEUTRAL, SHADOW_PCF3_32F, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_VSM_16F, SHADOW_VSM_32F, SHADOW_PCSS_32F, StandardMaterial, SCALEMODE_BLEND, SCALEMODE_NONE, EnvLighting, LAYERID_SKYBOX } from 'playcanvas';
1
+ import { basisInitialize, WasmModule, createGraphicsDevice, AppOptions, Keyboard, Mouse, AnimComponentSystem, AnimationComponentSystem, AudioListenerComponentSystem, ButtonComponentSystem, CameraComponentSystem, CollisionComponentSystem, ElementComponentSystem, GSplatComponentSystem, JointComponentSystem, LayoutChildComponentSystem, LayoutGroupComponentSystem, LightComponentSystem, ModelComponentSystem, ParticleSystemComponentSystem, RenderComponentSystem, RigidBodyComponentSystem, ScreenComponentSystem, ScriptComponentSystem, ScrollbarComponentSystem, ScrollViewComponentSystem, SoundComponentSystem, SpriteComponentSystem, ZoneComponentSystem, AnimClipHandler, AnimationHandler, AnimStateGraphHandler, AudioHandler, BinaryHandler, CssHandler, ContainerHandler, CubemapHandler, FolderHandler, FontHandler, GSplatHandler, HierarchyHandler, HtmlHandler, JsonHandler, MaterialHandler, ModelHandler, RenderHandler, ScriptHandler, SceneHandler, ShaderHandler, SpriteHandler, TemplateHandler, TextHandler, TextureAtlasHandler, TextureHandler, SoundManager, Lightmapper, BatchManager, XrManager, AppBase, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Picker, Vec3, Vec4, Color, Quat, Vec2, Entity, Asset, GAMMA_SRGB, GAMMA_NONE, XRTYPE_VR, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, TONEMAP_NONE, TONEMAP_LINEAR, TONEMAP_FILMIC, TONEMAP_HEJL, TONEMAP_ACES, TONEMAP_ACES2, TONEMAP_NEUTRAL, SHADOW_PCF3_32F, SHADOW_PCF1_16F, SHADOW_PCF1_32F, SHADOW_PCF3_16F, SHADOW_PCF5_16F, SHADOW_PCF5_32F, SHADOW_VSM_16F, SHADOW_VSM_32F, SHADOW_PCSS_32F, StandardMaterial, SCALEMODE_BLEND, SCALEMODE_NONE, EnvLighting, LAYERID_SKYBOX } from 'playcanvas';
2
2
 
3
3
  /**
4
4
  * Base class for all PlayCanvas Web Components that initialize asynchronously.
@@ -38,7 +38,7 @@ class AsyncElement extends HTMLElement {
38
38
 
39
39
  /**
40
40
  * The ModuleElement interface provides properties and methods for manipulating
41
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-module/ | `<pc-module>`} elements.
41
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-module/ | `<pc-module>`} elements.
42
42
  * The ModuleElement interface also inherits the properties and methods of the
43
43
  * {@link HTMLElement} interface.
44
44
  */
@@ -72,7 +72,7 @@ customElements.define('pc-module', ModuleElement);
72
72
 
73
73
  /**
74
74
  * The AppElement interface provides properties and methods for manipulating
75
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-app/ | `<pc-app>`} elements.
75
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-app/ | `<pc-app>`} elements.
76
76
  * The AppElement interface also inherits the properties and methods of the
77
77
  * {@link HTMLElement} interface.
78
78
  */
@@ -89,6 +89,7 @@ class AppElement extends AsyncElement {
89
89
  */
90
90
  this._canvas = null;
91
91
  this._alpha = true;
92
+ this._backend = 'webgl2';
92
93
  this._antialias = true;
93
94
  this._depth = true;
94
95
  this._stencil = true;
@@ -123,18 +124,84 @@ class AppElement extends AsyncElement {
123
124
  // Create and append the canvas to the element
124
125
  this._canvas = document.createElement('canvas');
125
126
  this.appendChild(this._canvas);
126
- // Initialize the PlayCanvas application
127
- this.app = new Application(this._canvas, {
128
- graphicsDeviceOptions: {
129
- alpha: this._alpha,
130
- antialias: this._antialias,
131
- depth: this._depth,
132
- stencil: this._stencil
133
- },
134
- keyboard: new Keyboard(window),
135
- mouse: new Mouse(this._canvas)
127
+ // Configure device types based on backend selection
128
+ const backendToDeviceTypes = {
129
+ webgpu: ['webgpu', 'webgl2'], // fallback to webgl2 if webgpu not available
130
+ webgl2: ['webgl2'],
131
+ null: ['null']
132
+ };
133
+ const deviceTypes = backendToDeviceTypes[this._backend] || [];
134
+ const device = await createGraphicsDevice(this._canvas, {
135
+ // @ts-ignore - alpha needs to be documented
136
+ alpha: this._alpha,
137
+ antialias: this._antialias,
138
+ depth: this._depth,
139
+ deviceTypes: deviceTypes,
140
+ stencil: this._stencil
136
141
  });
137
- this.app.graphicsDevice.maxPixelRatio = this._highResolution ? window.devicePixelRatio : 1;
142
+ device.maxPixelRatio = this._highResolution ? window.devicePixelRatio : 1;
143
+ const createOptions = new AppOptions();
144
+ createOptions.graphicsDevice = device;
145
+ createOptions.keyboard = new Keyboard(window);
146
+ createOptions.mouse = new Mouse(this._canvas);
147
+ createOptions.componentSystems = [
148
+ AnimComponentSystem,
149
+ AnimationComponentSystem,
150
+ AudioListenerComponentSystem,
151
+ ButtonComponentSystem,
152
+ CameraComponentSystem,
153
+ CollisionComponentSystem,
154
+ ElementComponentSystem,
155
+ GSplatComponentSystem,
156
+ JointComponentSystem,
157
+ LayoutChildComponentSystem,
158
+ LayoutGroupComponentSystem,
159
+ LightComponentSystem,
160
+ ModelComponentSystem,
161
+ ParticleSystemComponentSystem,
162
+ RenderComponentSystem,
163
+ RigidBodyComponentSystem,
164
+ ScreenComponentSystem,
165
+ ScriptComponentSystem,
166
+ ScrollbarComponentSystem,
167
+ ScrollViewComponentSystem,
168
+ SoundComponentSystem,
169
+ SpriteComponentSystem,
170
+ ZoneComponentSystem
171
+ ];
172
+ createOptions.resourceHandlers = [
173
+ AnimClipHandler,
174
+ AnimationHandler,
175
+ AnimStateGraphHandler,
176
+ AudioHandler,
177
+ BinaryHandler,
178
+ CssHandler,
179
+ ContainerHandler,
180
+ CubemapHandler,
181
+ FolderHandler,
182
+ FontHandler,
183
+ GSplatHandler,
184
+ HierarchyHandler,
185
+ HtmlHandler,
186
+ JsonHandler,
187
+ MaterialHandler,
188
+ ModelHandler,
189
+ RenderHandler,
190
+ ScriptHandler,
191
+ SceneHandler,
192
+ ShaderHandler,
193
+ SpriteHandler,
194
+ TemplateHandler,
195
+ TextHandler,
196
+ TextureAtlasHandler,
197
+ TextureHandler
198
+ ];
199
+ createOptions.soundManager = new SoundManager();
200
+ createOptions.lightmapper = Lightmapper;
201
+ createOptions.batchManager = BatchManager;
202
+ createOptions.xr = XrManager;
203
+ this.app = new AppBase(this._canvas);
204
+ this.app.init(createOptions);
138
205
  this.app.setCanvasFillMode(FILLMODE_FILL_WINDOW);
139
206
  this.app.setCanvasResolution(RESOLUTION_AUTO);
140
207
  this._pickerCreate();
@@ -362,6 +429,20 @@ class AppElement extends AsyncElement {
362
429
  get antialias() {
363
430
  return this._antialias;
364
431
  }
432
+ /**
433
+ * Sets the graphics backend.
434
+ * @param value - The graphics backend ('webgpu', 'webgl2', or 'null').
435
+ */
436
+ set backend(value) {
437
+ this._backend = value;
438
+ }
439
+ /**
440
+ * Gets the graphics backend.
441
+ * @returns The graphics backend.
442
+ */
443
+ get backend() {
444
+ return this._backend;
445
+ }
365
446
  /**
366
447
  * Sets the depth flag.
367
448
  * @param value - The depth flag.
@@ -417,7 +498,7 @@ class AppElement extends AsyncElement {
417
498
  return this._stencil;
418
499
  }
419
500
  static get observedAttributes() {
420
- return ['alpha', 'antialias', 'depth', 'stencil', 'high-resolution'];
501
+ return ['alpha', 'antialias', 'backend', 'depth', 'stencil', 'high-resolution'];
421
502
  }
422
503
  attributeChangedCallback(name, _oldValue, newValue) {
423
504
  switch (name) {
@@ -427,6 +508,11 @@ class AppElement extends AsyncElement {
427
508
  case 'antialias':
428
509
  this.antialias = newValue !== 'false';
429
510
  break;
511
+ case 'backend':
512
+ if (newValue === 'webgpu' || newValue === 'webgl2' || newValue === 'null') {
513
+ this.backend = newValue;
514
+ }
515
+ break;
430
516
  case 'depth':
431
517
  this.depth = newValue !== 'false';
432
518
  break;
@@ -656,7 +742,7 @@ const parseVec4 = (value) => {
656
742
 
657
743
  /**
658
744
  * The EntityElement interface provides properties and methods for manipulating
659
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
745
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-entity/ | `<pc-entity>`} elements.
660
746
  * The EntityElement interface also inherits the properties and methods of the
661
747
  * {@link HTMLElement} interface.
662
748
  */
@@ -1193,7 +1279,7 @@ const processBufferView = (gltfBuffer, buffers, continuation) => {
1193
1279
  };
1194
1280
  /**
1195
1281
  * The AssetElement interface provides properties and methods for manipulating
1196
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-asset/ | `<pc-asset>`} elements.
1282
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-asset/ | `<pc-asset>`} elements.
1197
1283
  * The AssetElement interface also inherits the properties and methods of the
1198
1284
  * {@link HTMLElement} interface.
1199
1285
  */
@@ -1355,7 +1441,7 @@ class ComponentElement extends AsyncElement {
1355
1441
 
1356
1442
  /**
1357
1443
  * The ListenerComponentElement interface provides properties and methods for manipulating
1358
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
1444
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-listener/ | `<pc-listener>`} elements.
1359
1445
  * The ListenerComponentElement interface also inherits the properties and methods of the
1360
1446
  * {@link HTMLElement} interface.
1361
1447
  *
@@ -1387,7 +1473,7 @@ const tonemaps = new Map([
1387
1473
  ]);
1388
1474
  /**
1389
1475
  * The CameraComponentElement interface provides properties and methods for manipulating
1390
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
1476
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-camera/ | `<pc-camera>`} elements.
1391
1477
  * The CameraComponentElement interface also inherits the properties and methods of the
1392
1478
  * {@link HTMLElement} interface.
1393
1479
  *
@@ -1868,7 +1954,7 @@ customElements.define('pc-camera', CameraComponentElement);
1868
1954
 
1869
1955
  /**
1870
1956
  * The CollisionComponentElement interface provides properties and methods for manipulating
1871
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-collision/ | `<pc-collision>`} elements.
1957
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-collision/ | `<pc-collision>`} elements.
1872
1958
  * The CollisionComponentElement interface also inherits the properties and methods of the
1873
1959
  * {@link HTMLElement} interface.
1874
1960
  *
@@ -2015,7 +2101,7 @@ customElements.define('pc-collision', CollisionComponentElement);
2015
2101
 
2016
2102
  /**
2017
2103
  * The ElementComponentElement interface provides properties and methods for manipulating
2018
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-element/ | `<pc-element>`} elements.
2104
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-element/ | `<pc-element>`} elements.
2019
2105
  * The ElementComponentElement interface also inherits the properties and methods of the
2020
2106
  * {@link HTMLElement} interface.
2021
2107
  *
@@ -2320,7 +2406,7 @@ const shadowTypes = new Map([
2320
2406
  ]);
2321
2407
  /**
2322
2408
  * The LightComponentElement interface provides properties and methods for manipulating
2323
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-light/ | `<pc-light>`} elements.
2409
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-light/ | `<pc-light>`} elements.
2324
2410
  * The LightComponentElement interface also inherits the properties and methods of the
2325
2411
  * {@link HTMLElement} interface.
2326
2412
  *
@@ -2717,7 +2803,7 @@ customElements.define('pc-light', LightComponentElement);
2717
2803
 
2718
2804
  /**
2719
2805
  * The ParticleSystemComponentElement interface provides properties and methods for manipulating
2720
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
2806
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-particles/ | `<pc-particles>`} elements.
2721
2807
  * The ParticleSystemComponentElement interface also inherits the properties and methods of the
2722
2808
  * {@link HTMLElement} interface.
2723
2809
  *
@@ -2849,7 +2935,7 @@ customElements.define('pc-particles', ParticleSystemComponentElement);
2849
2935
 
2850
2936
  /**
2851
2937
  * The MaterialElement interface provides properties and methods for manipulating
2852
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-material/ | `<pc-material>`} elements.
2938
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-material/ | `<pc-material>`} elements.
2853
2939
  * The MaterialElement interface also inherits the properties and methods of the
2854
2940
  * {@link HTMLElement} interface.
2855
2941
  */
@@ -2966,7 +3052,7 @@ customElements.define('pc-material', MaterialElement);
2966
3052
 
2967
3053
  /**
2968
3054
  * The RenderComponentElement interface provides properties and methods for manipulating
2969
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-render/ | `<pc-render>`} elements.
3055
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-render/ | `<pc-render>`} elements.
2970
3056
  * The RenderComponentElement interface also inherits the properties and methods of the
2971
3057
  * {@link HTMLElement} interface.
2972
3058
  *
@@ -3089,7 +3175,7 @@ customElements.define('pc-render', RenderComponentElement);
3089
3175
 
3090
3176
  /**
3091
3177
  * The RigidBodyComponentElement interface provides properties and methods for manipulating
3092
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-rigidbody/ | `<pc-rigidbody>`} elements.
3178
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-rigidbody/ | `<pc-rigidbody>`} elements.
3093
3179
  * The RigidBodyComponentElement interface also inherits the properties and methods of the
3094
3180
  * {@link HTMLElement} interface.
3095
3181
  *
@@ -3277,7 +3363,7 @@ customElements.define('pc-rigidbody', RigidBodyComponentElement);
3277
3363
 
3278
3364
  /**
3279
3365
  * The ScreenComponentElement interface provides properties and methods for manipulating
3280
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-screen/ | `<pc-screen>`} elements.
3366
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-screen/ | `<pc-screen>`} elements.
3281
3367
  * The ScreenComponentElement interface also inherits the properties and methods of the
3282
3368
  * {@link HTMLElement} interface.
3283
3369
  *
@@ -3404,7 +3490,7 @@ customElements.define('pc-screen', ScreenComponentElement);
3404
3490
 
3405
3491
  /**
3406
3492
  * The ScriptComponentElement interface provides properties and methods for manipulating
3407
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-scripts/ | `<pc-scripts>`} elements.
3493
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scripts/ | `<pc-scripts>`} elements.
3408
3494
  * The ScriptComponentElement interface also inherits the properties and methods of the
3409
3495
  * {@link HTMLElement} interface.
3410
3496
  *
@@ -3712,7 +3798,7 @@ customElements.define('pc-script', ScriptElement);
3712
3798
 
3713
3799
  /**
3714
3800
  * The SoundComponentElement interface provides properties and methods for manipulating
3715
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-sounds/ | `<pc-sounds>`} elements.
3801
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-sounds/ | `<pc-sounds>`} elements.
3716
3802
  * The SoundComponentElement interface also inherits the properties and methods of the
3717
3803
  * {@link HTMLElement} interface.
3718
3804
  *
@@ -3946,6 +4032,9 @@ class SoundSlotElement extends AsyncElement {
3946
4032
  }
3947
4033
  this.soundSlot = this.soundElement.component.addSlot(this._name, options);
3948
4034
  this.asset = this._asset;
4035
+ if (this._autoPlay) {
4036
+ this.soundSlot.play();
4037
+ }
3949
4038
  this._onReady();
3950
4039
  }
3951
4040
  disconnectedCallback() {
@@ -4155,7 +4244,7 @@ customElements.define('pc-sound', SoundSlotElement);
4155
4244
 
4156
4245
  /**
4157
4246
  * The SplatComponentElement interface provides properties and methods for manipulating
4158
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
4247
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-splat/ | `<pc-splat>`} elements.
4159
4248
  * The SplatComponentElement interface also inherits the properties and methods of the
4160
4249
  * {@link HTMLElement} interface.
4161
4250
  *
@@ -4239,7 +4328,7 @@ customElements.define('pc-splat', SplatComponentElement);
4239
4328
 
4240
4329
  /**
4241
4330
  * The ModelElement interface provides properties and methods for manipulating
4242
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-model/ | `<pc-model>`} elements.
4331
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-model/ | `<pc-model>`} elements.
4243
4332
  * The ModelElement interface also inherits the properties and methods of the
4244
4333
  * {@link HTMLElement} interface.
4245
4334
  */
@@ -4335,7 +4424,7 @@ customElements.define('pc-model', ModelElement);
4335
4424
 
4336
4425
  /**
4337
4426
  * The SceneElement interface provides properties and methods for manipulating
4338
- * {@link https://developer.playcanvas.com/user-manual/engine/web-components/tags/pc-scene/ | `<pc-scene>`} elements.
4427
+ * {@link https://developer.playcanvas.com/user-manual/web-components/tags/pc-scene/ | `<pc-scene>`} elements.
4339
4428
  * The SceneElement interface also inherits the properties and methods of the
4340
4429
  * {@link HTMLElement} interface.
4341
4430
  */