@playcanvas/web-components 0.1.2 → 0.1.4

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/dist/pwc.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { WasmModule, Application, Keyboard, Mouse, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Color, Vec2, Vec3, Vec4, Entity, Asset, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, Quat, LAYERID_SKYBOX } from 'playcanvas';
1
+ import { WasmModule, Application, Keyboard, Mouse, FILLMODE_FILL_WINDOW, RESOLUTION_AUTO, Color, Quat, Vec2, Vec3, Vec4, Entity, Asset, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, StandardMaterial, SCALEMODE_BLEND, SCALEMODE_NONE, LAYERID_SKYBOX } from 'playcanvas';
2
2
 
3
3
  class ModuleElement extends HTMLElement {
4
4
  constructor() {
@@ -76,6 +76,11 @@ class AppElement extends HTMLElement {
76
76
  this.app.assets.add(asset);
77
77
  }
78
78
  });
79
+ // Get all pc-material elements that are direct children of the pc-app element
80
+ const materialElements = this.querySelectorAll(':scope > pc-material');
81
+ Array.from(materialElements).forEach((materialElement) => {
82
+ materialElement.createMaterial();
83
+ });
79
84
  // Load assets before starting the application
80
85
  this.app.preload(() => {
81
86
  // Start the application
@@ -144,6 +149,18 @@ const parseColor = (value) => {
144
149
  const components = value.split(',').map(Number);
145
150
  return new Color(components);
146
151
  };
152
+ /**
153
+ * Parse an Euler angles string into a Quat object. String can be in the format of 'x,y,z'.
154
+ *
155
+ * @param value - The Euler angles string to parse.
156
+ * @returns The parsed Quat object.
157
+ */
158
+ const parseQuat = (value) => {
159
+ const [x, y, z] = value.split(',').map(Number);
160
+ const q = new Quat();
161
+ q.setFromEulerAngles(x, y, z);
162
+ return q;
163
+ };
147
164
  /**
148
165
  * Parse a Vec2 string into a Vec2 object. String can be in the format of 'x,y'.
149
166
  *
@@ -205,6 +222,9 @@ class EntityElement extends HTMLElement {
205
222
  * The tags of the entity.
206
223
  */
207
224
  this._tags = [];
225
+ this._entityReady = new Promise((resolve) => {
226
+ this._resolveEntity = resolve;
227
+ });
208
228
  /**
209
229
  * The PlayCanvas entity instance.
210
230
  */
@@ -220,8 +240,11 @@ class EntityElement extends HTMLElement {
220
240
  const app = await appElement.getApplication();
221
241
  // Create a new entity
222
242
  this.entity = new Entity(this._name, app);
223
- if (this.parentElement && this.parentElement.tagName === 'pc-entity' && this.parentElement.entity) {
224
- this.parentElement.entity.addChild(this.entity);
243
+ this._resolveEntity(this.entity);
244
+ if (this.parentElement &&
245
+ this.parentElement.tagName.toLowerCase() === 'pc-entity') {
246
+ const parentEntity = await this.parentElement._entityReady;
247
+ parentEntity.addChild(this.entity);
225
248
  }
226
249
  else {
227
250
  app.root.addChild(this.entity);
@@ -245,9 +268,18 @@ class EntityElement extends HTMLElement {
245
268
  }
246
269
  disconnectedCallback() {
247
270
  if (this.entity) {
271
+ // Notify all children that their entities are about to become invalid
272
+ const children = this.querySelectorAll('pc-entity');
273
+ children.forEach((child) => {
274
+ child.entity = null;
275
+ });
248
276
  this.entity.destroy();
249
277
  this.entity = null;
250
278
  }
279
+ // Reset the promise for potential reconnection
280
+ this._entityReady = new Promise((resolve) => {
281
+ this._resolveEntity = resolve;
282
+ });
251
283
  }
252
284
  /**
253
285
  * Sets the enabled state of the entity.
@@ -455,6 +487,10 @@ class AssetElement extends HTMLElement {
455
487
  get preload() {
456
488
  return this._preload;
457
489
  }
490
+ static get(id) {
491
+ const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
492
+ return assetElement === null || assetElement === void 0 ? void 0 : assetElement.asset;
493
+ }
458
494
  static get observedAttributes() {
459
495
  return ['preload'];
460
496
  }
@@ -576,21 +612,39 @@ class CameraComponentElement extends ComponentElement {
576
612
  */
577
613
  constructor() {
578
614
  super('camera');
579
- this._clearColor = new Color(1, 1, 1, 1);
615
+ this._clearColor = new Color(0.75, 0.75, 0.75, 1);
616
+ this._clearColorBuffer = true;
617
+ this._clearDepthBuffer = true;
618
+ this._clearStencilBuffer = false;
619
+ this._cullFaces = true;
580
620
  this._farClip = 1000;
621
+ this._flipFaces = false;
581
622
  this._fov = 45;
623
+ this._frustumCulling = true;
582
624
  this._nearClip = 0.1;
583
625
  this._orthographic = false;
584
626
  this._orthoHeight = 10;
627
+ this._priority = 0;
628
+ this._rect = new Vec4(0, 0, 1, 1);
629
+ this._scissorRect = new Vec4(0, 0, 1, 1);
585
630
  }
586
631
  getInitialComponentData() {
587
632
  return {
588
633
  clearColor: this._clearColor,
634
+ clearColorBuffer: this._clearColorBuffer,
635
+ clearDepthBuffer: this._clearDepthBuffer,
636
+ clearStencilBuffer: this._clearStencilBuffer,
637
+ cullFaces: this._cullFaces,
589
638
  farClip: this._farClip,
639
+ flipFaces: this._flipFaces,
590
640
  fov: this._fov,
641
+ frustumCulling: this._frustumCulling,
591
642
  nearClip: this._nearClip,
592
- projection: this._orthographic ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE,
593
- orthoHeight: this._orthoHeight
643
+ orthographic: this._orthographic,
644
+ orthoHeight: this._orthoHeight,
645
+ priority: this._priority,
646
+ rect: this._rect,
647
+ scissorRect: this._scissorRect
594
648
  };
595
649
  }
596
650
  /**
@@ -617,6 +671,74 @@ class CameraComponentElement extends ComponentElement {
617
671
  get clearColor() {
618
672
  return this._clearColor;
619
673
  }
674
+ /**
675
+ * Sets the clear color buffer of the camera.
676
+ * @param value - The clear color buffer.
677
+ */
678
+ set clearColorBuffer(value) {
679
+ this._clearColorBuffer = value;
680
+ if (this.component) {
681
+ this.component.clearColorBuffer = value;
682
+ }
683
+ }
684
+ /**
685
+ * Gets the clear color buffer of the camera.
686
+ * @returns The clear color buffer.
687
+ */
688
+ get clearColorBuffer() {
689
+ return this._clearColorBuffer;
690
+ }
691
+ /**
692
+ * Sets the clear depth buffer of the camera.
693
+ * @param value - The clear depth buffer.
694
+ */
695
+ set clearDepthBuffer(value) {
696
+ this._clearDepthBuffer = value;
697
+ if (this.component) {
698
+ this.component.clearDepthBuffer = value;
699
+ }
700
+ }
701
+ /**
702
+ * Gets the clear depth buffer of the camera.
703
+ * @returns The clear depth buffer.
704
+ */
705
+ get clearDepthBuffer() {
706
+ return this._clearDepthBuffer;
707
+ }
708
+ /**
709
+ * Sets the clear stencil buffer of the camera.
710
+ * @param value - The clear stencil buffer.
711
+ */
712
+ set clearStencilBuffer(value) {
713
+ this._clearStencilBuffer = value;
714
+ if (this.component) {
715
+ this.component.clearStencilBuffer = value;
716
+ }
717
+ }
718
+ /**
719
+ * Gets the clear stencil buffer of the camera.
720
+ * @returns The clear stencil buffer.
721
+ */
722
+ get clearStencilBuffer() {
723
+ return this._clearStencilBuffer;
724
+ }
725
+ /**
726
+ * Sets the cull faces of the camera.
727
+ * @param value - The cull faces.
728
+ */
729
+ set cullFaces(value) {
730
+ this._cullFaces = value;
731
+ if (this.component) {
732
+ this.component.cullFaces = value;
733
+ }
734
+ }
735
+ /**
736
+ * Gets the cull faces of the camera.
737
+ * @returns The cull faces.
738
+ */
739
+ get cullFaces() {
740
+ return this._cullFaces;
741
+ }
620
742
  /**
621
743
  * Sets the far clip distance of the camera.
622
744
  * @param value - The far clip distance.
@@ -634,6 +756,23 @@ class CameraComponentElement extends ComponentElement {
634
756
  get farClip() {
635
757
  return this._farClip;
636
758
  }
759
+ /**
760
+ * Sets the flip faces of the camera.
761
+ * @param value - The flip faces.
762
+ */
763
+ set flipFaces(value) {
764
+ this._flipFaces = value;
765
+ if (this.component) {
766
+ this.component.flipFaces = value;
767
+ }
768
+ }
769
+ /**
770
+ * Gets the flip faces of the camera.
771
+ * @returns The flip faces.
772
+ */
773
+ get flipFaces() {
774
+ return this._flipFaces;
775
+ }
637
776
  /**
638
777
  * Sets the field of view of the camera.
639
778
  * @param value - The field of view.
@@ -651,6 +790,23 @@ class CameraComponentElement extends ComponentElement {
651
790
  get fov() {
652
791
  return this._fov;
653
792
  }
793
+ /**
794
+ * Sets the frustum culling of the camera.
795
+ * @param value - The frustum culling.
796
+ */
797
+ set frustumCulling(value) {
798
+ this._frustumCulling = value;
799
+ if (this.component) {
800
+ this.component.frustumCulling = value;
801
+ }
802
+ }
803
+ /**
804
+ * Gets the frustum culling of the camera.
805
+ * @returns The frustum culling.
806
+ */
807
+ get frustumCulling() {
808
+ return this._frustumCulling;
809
+ }
654
810
  /**
655
811
  * Sets the near clip distance of the camera.
656
812
  * @param value - The near clip distance.
@@ -702,8 +858,76 @@ class CameraComponentElement extends ComponentElement {
702
858
  get orthoHeight() {
703
859
  return this._orthoHeight;
704
860
  }
861
+ /**
862
+ * Sets the priority of the camera.
863
+ * @param value - The priority.
864
+ */
865
+ set priority(value) {
866
+ this._priority = value;
867
+ if (this.component) {
868
+ this.component.priority = value;
869
+ }
870
+ }
871
+ /**
872
+ * Gets the priority of the camera.
873
+ * @returns The priority.
874
+ */
875
+ get priority() {
876
+ return this._priority;
877
+ }
878
+ /**
879
+ * Sets the rect of the camera.
880
+ * @param value - The rect.
881
+ */
882
+ set rect(value) {
883
+ this._rect = value;
884
+ if (this.component) {
885
+ this.component.rect = value;
886
+ }
887
+ }
888
+ /**
889
+ * Gets the rect of the camera.
890
+ * @returns The rect.
891
+ */
892
+ get rect() {
893
+ return this._rect;
894
+ }
895
+ /**
896
+ * Sets the scissor rect of the camera.
897
+ * @param value - The scissor rect.
898
+ */
899
+ set scissorRect(value) {
900
+ this._scissorRect = value;
901
+ if (this.component) {
902
+ this.component.scissorRect = value;
903
+ }
904
+ }
905
+ /**
906
+ * Gets the scissor rect of the camera.
907
+ * @returns The scissor rect.
908
+ */
909
+ get scissorRect() {
910
+ return this._scissorRect;
911
+ }
705
912
  static get observedAttributes() {
706
- return [...super.observedAttributes, 'clear-color', 'near-clip', 'far-clip', 'fov', 'orthographic', 'ortho-height'];
913
+ return [
914
+ ...super.observedAttributes,
915
+ 'clear-color',
916
+ 'clear-color-buffer',
917
+ 'clear-depth-buffer',
918
+ 'clear-stencil-buffer',
919
+ 'cull-faces',
920
+ 'far-clip',
921
+ 'flip-faces',
922
+ 'fov',
923
+ 'frustum-culling',
924
+ 'near-clip',
925
+ 'orthographic',
926
+ 'ortho-height',
927
+ 'priority',
928
+ 'rect',
929
+ 'scissor-rect'
930
+ ];
707
931
  }
708
932
  attributeChangedCallback(name, _oldValue, newValue) {
709
933
  super.attributeChangedCallback(name, _oldValue, newValue);
@@ -711,12 +935,30 @@ class CameraComponentElement extends ComponentElement {
711
935
  case 'clear-color':
712
936
  this.clearColor = parseColor(newValue);
713
937
  break;
938
+ case 'clear-color-buffer':
939
+ this.clearColorBuffer = newValue !== 'false';
940
+ break;
941
+ case 'clear-depth-buffer':
942
+ this.clearDepthBuffer = newValue !== 'false';
943
+ break;
944
+ case 'clear-stencil-buffer':
945
+ this.clearStencilBuffer = newValue !== 'false';
946
+ break;
947
+ case 'cull-faces':
948
+ this.cullFaces = newValue !== 'false';
949
+ break;
714
950
  case 'far-clip':
715
951
  this.farClip = parseFloat(newValue);
716
952
  break;
953
+ case 'flip-faces':
954
+ this.flipFaces = newValue !== 'true';
955
+ break;
717
956
  case 'fov':
718
957
  this.fov = parseFloat(newValue);
719
958
  break;
959
+ case 'frustum-culling':
960
+ this.frustumCulling = newValue !== 'false';
961
+ break;
720
962
  case 'near-clip':
721
963
  this.nearClip = parseFloat(newValue);
722
964
  break;
@@ -726,6 +968,15 @@ class CameraComponentElement extends ComponentElement {
726
968
  case 'ortho-height':
727
969
  this.orthoHeight = parseFloat(newValue);
728
970
  break;
971
+ case 'priority':
972
+ this.priority = parseFloat(newValue);
973
+ break;
974
+ case 'rect':
975
+ this.rect = parseVec4(newValue);
976
+ break;
977
+ case 'scissor-rect':
978
+ this.scissorRect = parseVec4(newValue);
979
+ break;
729
980
  }
730
981
  }
731
982
  }
@@ -742,19 +993,23 @@ class CollisionComponentElement extends ComponentElement {
742
993
  */
743
994
  constructor() {
744
995
  super('collision');
996
+ this._angularOffset = new Quat();
745
997
  this._axis = 1;
746
998
  this._convexHull = false;
747
999
  this._halfExtents = new Vec3(0.5, 0.5, 0.5);
748
1000
  this._height = 2;
1001
+ this._linearOffset = new Vec3();
749
1002
  this._radius = 0.5;
750
1003
  this._type = 'box';
751
1004
  }
752
1005
  getInitialComponentData() {
753
1006
  return {
754
1007
  axis: this._axis,
1008
+ angularOffset: this._angularOffset,
755
1009
  convexHull: this._convexHull,
756
1010
  halfExtents: this._halfExtents,
757
1011
  height: this._height,
1012
+ linearOffset: this._linearOffset,
758
1013
  radius: this._radius,
759
1014
  type: this._type
760
1015
  };
@@ -766,6 +1021,15 @@ class CollisionComponentElement extends ComponentElement {
766
1021
  get component() {
767
1022
  return super.component;
768
1023
  }
1024
+ set angularOffset(value) {
1025
+ this._angularOffset = value;
1026
+ if (this.component) {
1027
+ this.component.angularOffset = value;
1028
+ }
1029
+ }
1030
+ get angularOffset() {
1031
+ return this._angularOffset;
1032
+ }
769
1033
  set axis(value) {
770
1034
  this._axis = value;
771
1035
  if (this.component) {
@@ -802,6 +1066,15 @@ class CollisionComponentElement extends ComponentElement {
802
1066
  get height() {
803
1067
  return this._height;
804
1068
  }
1069
+ set linearOffset(value) {
1070
+ this._linearOffset = value;
1071
+ if (this.component) {
1072
+ this.component.linearOffset = value;
1073
+ }
1074
+ }
1075
+ get linearOffset() {
1076
+ return this._linearOffset;
1077
+ }
805
1078
  set radius(value) {
806
1079
  this._radius = value;
807
1080
  if (this.component) {
@@ -821,11 +1094,14 @@ class CollisionComponentElement extends ComponentElement {
821
1094
  return this._type;
822
1095
  }
823
1096
  static get observedAttributes() {
824
- return [...super.observedAttributes, 'axis', 'convex-hull', 'half-extents', 'height', 'radius', 'type'];
1097
+ return [...super.observedAttributes, 'angular-offset', 'axis', 'convex-hull', 'half-extents', 'height', 'linear-offset', 'radius', 'type'];
825
1098
  }
826
1099
  attributeChangedCallback(name, _oldValue, newValue) {
827
1100
  super.attributeChangedCallback(name, _oldValue, newValue);
828
1101
  switch (name) {
1102
+ case 'angular-offset':
1103
+ this.angularOffset = parseQuat(newValue);
1104
+ break;
829
1105
  case 'axis':
830
1106
  this.axis = parseInt(newValue, 10);
831
1107
  break;
@@ -838,6 +1114,9 @@ class CollisionComponentElement extends ComponentElement {
838
1114
  case 'height':
839
1115
  this.height = parseFloat(newValue);
840
1116
  break;
1117
+ case 'linear-offset':
1118
+ this.linearOffset = parseVec3(newValue);
1119
+ break;
841
1120
  case 'radius':
842
1121
  this.radius = parseFloat(newValue);
843
1122
  break;
@@ -873,16 +1152,12 @@ class ElementComponentElement extends ComponentElement {
873
1152
  await super.connectedCallback();
874
1153
  this.component._text._material.useFog = true;
875
1154
  }
876
- getAsset() {
877
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
878
- return assetElement.asset;
879
- }
880
1155
  getInitialComponentData() {
881
1156
  return {
882
1157
  anchor: this._anchor,
883
1158
  autoWidth: this._autoWidth,
884
1159
  color: this._color,
885
- fontAsset: this.getAsset().id,
1160
+ fontAsset: AssetElement.get(this._asset).id,
886
1161
  fontSize: this._fontSize,
887
1162
  lineHeight: this._lineHeight,
888
1163
  pivot: this._pivot,
@@ -910,7 +1185,7 @@ class ElementComponentElement extends ComponentElement {
910
1185
  }
911
1186
  set asset(value) {
912
1187
  this._asset = value;
913
- const asset = this.getAsset();
1188
+ const asset = AssetElement.get(value);
914
1189
  if (this.component && asset) {
915
1190
  this.component.fontAsset = asset.id;
916
1191
  }
@@ -1061,13 +1336,9 @@ class GSplatComponentElement extends ComponentElement {
1061
1336
  super('gsplat');
1062
1337
  this._asset = '';
1063
1338
  }
1064
- getAsset() {
1065
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1066
- return assetElement.asset;
1067
- }
1068
1339
  getInitialComponentData() {
1069
1340
  return {
1070
- asset: this.getAsset()
1341
+ asset: AssetElement.get(this._asset)
1071
1342
  };
1072
1343
  }
1073
1344
  /**
@@ -1079,7 +1350,7 @@ class GSplatComponentElement extends ComponentElement {
1079
1350
  }
1080
1351
  set asset(value) {
1081
1352
  this._asset = value;
1082
- const asset = this.getAsset();
1353
+ const asset = AssetElement.get(value);
1083
1354
  if (this.component && asset) {
1084
1355
  this.component.asset = asset;
1085
1356
  }
@@ -1371,6 +1642,120 @@ class LightComponentElement extends ComponentElement {
1371
1642
  }
1372
1643
  customElements.define('pc-light', LightComponentElement);
1373
1644
 
1645
+ /**
1646
+ * Represents a material in the PlayCanvas engine.
1647
+ */
1648
+ class MaterialElement extends HTMLElement {
1649
+ constructor() {
1650
+ super(...arguments);
1651
+ this._diffuse = new Color(1, 1, 1);
1652
+ this._diffuseMap = '';
1653
+ this._metalnessMap = '';
1654
+ this._normalMap = '';
1655
+ this._roughnessMap = '';
1656
+ this.material = null;
1657
+ }
1658
+ createMaterial() {
1659
+ this.material = new StandardMaterial();
1660
+ this.material.glossInvert = true;
1661
+ this.material.useMetalness = true;
1662
+ this.material.diffuse = this._diffuse;
1663
+ this.diffuseMap = this._diffuseMap;
1664
+ this.metalnessMap = this._metalnessMap;
1665
+ this.normalMap = this._normalMap;
1666
+ this.roughnessMap = this._roughnessMap;
1667
+ this.material.update();
1668
+ }
1669
+ disconnectedCallback() {
1670
+ if (this.material) {
1671
+ this.material.destroy();
1672
+ this.material = null;
1673
+ }
1674
+ }
1675
+ setMap(map, property) {
1676
+ if (this.material) {
1677
+ const asset = AssetElement.get(map);
1678
+ if (asset) {
1679
+ if (asset.loaded) {
1680
+ this.material[property] = asset.resource;
1681
+ this.material[property].anisotropy = 4;
1682
+ }
1683
+ else {
1684
+ asset.once('load', () => {
1685
+ this.material[property] = asset.resource;
1686
+ this.material[property].anisotropy = 4;
1687
+ this.material.update();
1688
+ });
1689
+ }
1690
+ }
1691
+ }
1692
+ }
1693
+ set diffuse(value) {
1694
+ this._diffuse = value;
1695
+ if (this.material) {
1696
+ this.material.diffuse = value;
1697
+ }
1698
+ }
1699
+ get diffuse() {
1700
+ return this._diffuse;
1701
+ }
1702
+ set diffuseMap(value) {
1703
+ this._diffuseMap = value;
1704
+ this.setMap(value, 'diffuseMap');
1705
+ }
1706
+ get diffuseMap() {
1707
+ return this._diffuseMap;
1708
+ }
1709
+ set metalnessMap(value) {
1710
+ this._metalnessMap = value;
1711
+ this.setMap(value, 'metalnessMap');
1712
+ }
1713
+ get metalnessMap() {
1714
+ return this._metalnessMap;
1715
+ }
1716
+ set normalMap(value) {
1717
+ this._normalMap = value;
1718
+ this.setMap(value, 'normalMap');
1719
+ }
1720
+ get normalMap() {
1721
+ return this._normalMap;
1722
+ }
1723
+ set roughnessMap(value) {
1724
+ this._roughnessMap = value;
1725
+ this.setMap(value, 'glossMap');
1726
+ }
1727
+ get roughnessMap() {
1728
+ return this._roughnessMap;
1729
+ }
1730
+ static get(id) {
1731
+ const materialElement = document.querySelector(`pc-material[id="${id}"]`);
1732
+ return materialElement === null || materialElement === void 0 ? void 0 : materialElement.material;
1733
+ }
1734
+ static get observedAttributes() {
1735
+ return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
1736
+ }
1737
+ attributeChangedCallback(name, _oldValue, newValue) {
1738
+ switch (name) {
1739
+ case 'diffuse':
1740
+ this.diffuse = parseColor(newValue);
1741
+ break;
1742
+ case 'diffuse-map':
1743
+ this.diffuseMap = newValue;
1744
+ break;
1745
+ case 'metalness-map':
1746
+ this.metalnessMap = newValue;
1747
+ break;
1748
+ case 'normal-map':
1749
+ this.normalMap = newValue;
1750
+ break;
1751
+ case 'roughness-map':
1752
+ this.roughnessMap = newValue;
1753
+ break;
1754
+ }
1755
+ }
1756
+ }
1757
+ customElements.define('pc-material', MaterialElement);
1758
+
1374
1759
  /**
1375
1760
  * Represents a render component in the PlayCanvas engine.
1376
1761
  *
@@ -1379,9 +1764,14 @@ customElements.define('pc-light', LightComponentElement);
1379
1764
  class RenderComponentElement extends ComponentElement {
1380
1765
  constructor() {
1381
1766
  super('render');
1382
- this._type = 'asset';
1383
1767
  this._castShadows = true;
1768
+ this._material = '';
1384
1769
  this._receiveShadows = true;
1770
+ this._type = 'asset';
1771
+ }
1772
+ async connectedCallback() {
1773
+ await super.connectedCallback();
1774
+ this.material = this._material;
1385
1775
  }
1386
1776
  getInitialComponentData() {
1387
1777
  return {
@@ -1431,6 +1821,23 @@ class RenderComponentElement extends ComponentElement {
1431
1821
  get castShadows() {
1432
1822
  return this._castShadows;
1433
1823
  }
1824
+ /**
1825
+ * Sets the material of the render component.
1826
+ * @param value - The id of the material asset to use.
1827
+ */
1828
+ set material(value) {
1829
+ this._material = value;
1830
+ if (this.component) {
1831
+ this.component.material = MaterialElement.get(value);
1832
+ }
1833
+ }
1834
+ /**
1835
+ * Gets the id of the material asset used by the render component.
1836
+ * @returns The id of the material asset.
1837
+ */
1838
+ get material() {
1839
+ return this._material;
1840
+ }
1434
1841
  /**
1435
1842
  * Sets the receive shadows flag of the render component.
1436
1843
  * @param value - The receive shadows flag.
@@ -1449,20 +1856,23 @@ class RenderComponentElement extends ComponentElement {
1449
1856
  return this._receiveShadows;
1450
1857
  }
1451
1858
  static get observedAttributes() {
1452
- return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
1859
+ return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
1453
1860
  }
1454
1861
  attributeChangedCallback(name, _oldValue, newValue) {
1455
1862
  super.attributeChangedCallback(name, _oldValue, newValue);
1456
1863
  switch (name) {
1457
- case 'type':
1458
- this.type = newValue;
1459
- break;
1460
1864
  case 'cast-shadows':
1461
1865
  this.castShadows = newValue !== 'false';
1462
1866
  break;
1867
+ case 'material':
1868
+ this.material = newValue;
1869
+ break;
1463
1870
  case 'receive-shadows':
1464
1871
  this.receiveShadows = newValue !== 'false';
1465
1872
  break;
1873
+ case 'type':
1874
+ this.type = newValue;
1875
+ break;
1466
1876
  }
1467
1877
  }
1468
1878
  }
@@ -1655,6 +2065,129 @@ class RigidBodyComponentElement extends ComponentElement {
1655
2065
  }
1656
2066
  customElements.define('pc-rigidbody', RigidBodyComponentElement);
1657
2067
 
2068
+ /**
2069
+ * Represents a screen component in the PlayCanvas engine.
2070
+ *
2071
+ * @category Components
2072
+ */
2073
+ class ScreenComponentElement extends ComponentElement {
2074
+ constructor() {
2075
+ super('screen');
2076
+ this._screenSpace = false;
2077
+ this._resolution = new Vec2(640, 320);
2078
+ this._referenceResolution = new Vec2(640, 320);
2079
+ this._priority = 0;
2080
+ this._blend = false;
2081
+ this._scaleBlend = 0.5;
2082
+ }
2083
+ getInitialComponentData() {
2084
+ return {
2085
+ priority: this._priority,
2086
+ referenceResolution: this._referenceResolution,
2087
+ resolution: this._resolution,
2088
+ scaleBlend: this._scaleBlend,
2089
+ scaleMode: this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE,
2090
+ screenSpace: this._screenSpace
2091
+ };
2092
+ }
2093
+ /**
2094
+ * Gets the screen component.
2095
+ * @returns The screen component.
2096
+ */
2097
+ get component() {
2098
+ return super.component;
2099
+ }
2100
+ set priority(value) {
2101
+ this._priority = value;
2102
+ if (this.component) {
2103
+ this.component.priority = this._priority;
2104
+ }
2105
+ }
2106
+ get priority() {
2107
+ return this._priority;
2108
+ }
2109
+ set referenceResolution(value) {
2110
+ this._referenceResolution = value;
2111
+ if (this.component) {
2112
+ this.component.referenceResolution = this._referenceResolution;
2113
+ }
2114
+ }
2115
+ get referenceResolution() {
2116
+ return this._referenceResolution;
2117
+ }
2118
+ set resolution(value) {
2119
+ this._resolution = value;
2120
+ if (this.component) {
2121
+ this.component.resolution = this._resolution;
2122
+ }
2123
+ }
2124
+ get resolution() {
2125
+ return this._resolution;
2126
+ }
2127
+ set scaleBlend(value) {
2128
+ this._scaleBlend = value;
2129
+ if (this.component) {
2130
+ this.component.scaleBlend = this._scaleBlend;
2131
+ }
2132
+ }
2133
+ get scaleBlend() {
2134
+ return this._scaleBlend;
2135
+ }
2136
+ set blend(value) {
2137
+ this._blend = value;
2138
+ if (this.component) {
2139
+ this.component.scaleMode = this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE;
2140
+ }
2141
+ }
2142
+ get blend() {
2143
+ return this._blend;
2144
+ }
2145
+ set screenSpace(value) {
2146
+ this._screenSpace = value;
2147
+ if (this.component) {
2148
+ this.component.screenSpace = this._screenSpace;
2149
+ }
2150
+ }
2151
+ get screenSpace() {
2152
+ return this._screenSpace;
2153
+ }
2154
+ static get observedAttributes() {
2155
+ return [
2156
+ ...super.observedAttributes,
2157
+ 'blend',
2158
+ 'screen-space',
2159
+ 'resolution',
2160
+ 'reference-resolution',
2161
+ 'priority',
2162
+ 'scale-blend'
2163
+ ];
2164
+ }
2165
+ attributeChangedCallback(name, _oldValue, newValue) {
2166
+ super.attributeChangedCallback(name, _oldValue, newValue);
2167
+ switch (name) {
2168
+ case 'priority':
2169
+ this.priority = parseInt(newValue, 10);
2170
+ break;
2171
+ case 'reference-resolution':
2172
+ this.referenceResolution = parseVec2(newValue);
2173
+ break;
2174
+ case 'resolution':
2175
+ this.resolution = parseVec2(newValue);
2176
+ break;
2177
+ case 'scale-blend':
2178
+ this.scaleBlend = parseFloat(newValue);
2179
+ break;
2180
+ case 'blend':
2181
+ this.blend = this.hasAttribute('blend');
2182
+ break;
2183
+ case 'screen-space':
2184
+ this.screenSpace = this.hasAttribute('screen-space');
2185
+ break;
2186
+ }
2187
+ }
2188
+ }
2189
+ customElements.define('pc-screen', ScreenComponentElement);
2190
+
1658
2191
  /**
1659
2192
  * Represents a script component in the PlayCanvas engine.
1660
2193
  *
@@ -1960,10 +2493,6 @@ class SoundSlotElement extends HTMLElement {
1960
2493
  */
1961
2494
  this.soundSlot = null;
1962
2495
  }
1963
- getAsset() {
1964
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1965
- return assetElement.asset;
1966
- }
1967
2496
  async connectedCallback() {
1968
2497
  const appElement = this.closest('pc-app');
1969
2498
  if (!appElement) {
@@ -2005,7 +2534,7 @@ class SoundSlotElement extends HTMLElement {
2005
2534
  var _a;
2006
2535
  this._asset = value;
2007
2536
  if (this.soundSlot) {
2008
- const id = (_a = this.getAsset()) === null || _a === void 0 ? void 0 : _a.id;
2537
+ const id = (_a = AssetElement.get(value)) === null || _a === void 0 ? void 0 : _a.id;
2009
2538
  if (id) {
2010
2539
  this.soundSlot.asset = id;
2011
2540
  }
@@ -2209,12 +2738,8 @@ class ModelElement extends HTMLElement {
2209
2738
  this.asset = asset;
2210
2739
  }
2211
2740
  }
2212
- getAsset() {
2213
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2214
- return assetElement.asset;
2215
- }
2216
2741
  _loadModel() {
2217
- const asset = this.getAsset();
2742
+ const asset = AssetElement.get(this._asset);
2218
2743
  if (!asset) {
2219
2744
  return;
2220
2745
  }
@@ -2442,10 +2967,6 @@ class SkyElement extends HTMLElement {
2442
2967
  this.asset = this.getAttribute('asset') || '';
2443
2968
  this.solidColor = this.hasAttribute('solid-color');
2444
2969
  }
2445
- getAsset() {
2446
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2447
- return assetElement.asset;
2448
- }
2449
2970
  getScene() {
2450
2971
  const appElement = this.closest('pc-app');
2451
2972
  if (!appElement) {
@@ -2461,7 +2982,7 @@ class SkyElement extends HTMLElement {
2461
2982
  this._asset = value;
2462
2983
  const scene = this.getScene();
2463
2984
  if (scene) {
2464
- const asset = this.getAsset();
2985
+ const asset = AssetElement.get(value);
2465
2986
  if (asset) {
2466
2987
  if (asset.resource) {
2467
2988
  scene.envAtlas = asset.resource;
@@ -2545,5 +3066,5 @@ class SkyElement extends HTMLElement {
2545
3066
  }
2546
3067
  customElements.define('pc-sky', SkyElement);
2547
3068
 
2548
- export { AppElement, AssetElement, CameraComponentElement, CollisionComponentElement, ComponentElement, ElementComponentElement, EntityElement, GSplatComponentElement, LightComponentElement, ListenerComponentElement, ModelElement, ModuleElement, RenderComponentElement, RigidBodyComponentElement, SceneElement, ScriptComponentElement, ScriptElement, SkyElement, SoundComponentElement, SoundSlotElement };
3069
+ export { AppElement, AssetElement, CameraComponentElement, CollisionComponentElement, ComponentElement, ElementComponentElement, EntityElement, GSplatComponentElement, LightComponentElement, ListenerComponentElement, MaterialElement, ModelElement, ModuleElement, RenderComponentElement, RigidBodyComponentElement, SceneElement, ScreenComponentElement, ScriptComponentElement, ScriptElement, SkyElement, SoundComponentElement, SoundSlotElement };
2549
3070
  //# sourceMappingURL=pwc.mjs.map