@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.js CHANGED
@@ -80,6 +80,11 @@
80
80
  this.app.assets.add(asset);
81
81
  }
82
82
  });
83
+ // Get all pc-material elements that are direct children of the pc-app element
84
+ const materialElements = this.querySelectorAll(':scope > pc-material');
85
+ Array.from(materialElements).forEach((materialElement) => {
86
+ materialElement.createMaterial();
87
+ });
83
88
  // Load assets before starting the application
84
89
  this.app.preload(() => {
85
90
  // Start the application
@@ -148,6 +153,18 @@
148
153
  const components = value.split(',').map(Number);
149
154
  return new playcanvas.Color(components);
150
155
  };
156
+ /**
157
+ * Parse an Euler angles string into a Quat object. String can be in the format of 'x,y,z'.
158
+ *
159
+ * @param value - The Euler angles string to parse.
160
+ * @returns The parsed Quat object.
161
+ */
162
+ const parseQuat = (value) => {
163
+ const [x, y, z] = value.split(',').map(Number);
164
+ const q = new playcanvas.Quat();
165
+ q.setFromEulerAngles(x, y, z);
166
+ return q;
167
+ };
151
168
  /**
152
169
  * Parse a Vec2 string into a Vec2 object. String can be in the format of 'x,y'.
153
170
  *
@@ -209,6 +226,9 @@
209
226
  * The tags of the entity.
210
227
  */
211
228
  this._tags = [];
229
+ this._entityReady = new Promise((resolve) => {
230
+ this._resolveEntity = resolve;
231
+ });
212
232
  /**
213
233
  * The PlayCanvas entity instance.
214
234
  */
@@ -224,8 +244,11 @@
224
244
  const app = await appElement.getApplication();
225
245
  // Create a new entity
226
246
  this.entity = new playcanvas.Entity(this._name, app);
227
- if (this.parentElement && this.parentElement.tagName === 'pc-entity' && this.parentElement.entity) {
228
- this.parentElement.entity.addChild(this.entity);
247
+ this._resolveEntity(this.entity);
248
+ if (this.parentElement &&
249
+ this.parentElement.tagName.toLowerCase() === 'pc-entity') {
250
+ const parentEntity = await this.parentElement._entityReady;
251
+ parentEntity.addChild(this.entity);
229
252
  }
230
253
  else {
231
254
  app.root.addChild(this.entity);
@@ -249,9 +272,18 @@
249
272
  }
250
273
  disconnectedCallback() {
251
274
  if (this.entity) {
275
+ // Notify all children that their entities are about to become invalid
276
+ const children = this.querySelectorAll('pc-entity');
277
+ children.forEach((child) => {
278
+ child.entity = null;
279
+ });
252
280
  this.entity.destroy();
253
281
  this.entity = null;
254
282
  }
283
+ // Reset the promise for potential reconnection
284
+ this._entityReady = new Promise((resolve) => {
285
+ this._resolveEntity = resolve;
286
+ });
255
287
  }
256
288
  /**
257
289
  * Sets the enabled state of the entity.
@@ -459,6 +491,10 @@
459
491
  get preload() {
460
492
  return this._preload;
461
493
  }
494
+ static get(id) {
495
+ const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
496
+ return assetElement === null || assetElement === void 0 ? void 0 : assetElement.asset;
497
+ }
462
498
  static get observedAttributes() {
463
499
  return ['preload'];
464
500
  }
@@ -580,21 +616,39 @@
580
616
  */
581
617
  constructor() {
582
618
  super('camera');
583
- this._clearColor = new playcanvas.Color(1, 1, 1, 1);
619
+ this._clearColor = new playcanvas.Color(0.75, 0.75, 0.75, 1);
620
+ this._clearColorBuffer = true;
621
+ this._clearDepthBuffer = true;
622
+ this._clearStencilBuffer = false;
623
+ this._cullFaces = true;
584
624
  this._farClip = 1000;
625
+ this._flipFaces = false;
585
626
  this._fov = 45;
627
+ this._frustumCulling = true;
586
628
  this._nearClip = 0.1;
587
629
  this._orthographic = false;
588
630
  this._orthoHeight = 10;
631
+ this._priority = 0;
632
+ this._rect = new playcanvas.Vec4(0, 0, 1, 1);
633
+ this._scissorRect = new playcanvas.Vec4(0, 0, 1, 1);
589
634
  }
590
635
  getInitialComponentData() {
591
636
  return {
592
637
  clearColor: this._clearColor,
638
+ clearColorBuffer: this._clearColorBuffer,
639
+ clearDepthBuffer: this._clearDepthBuffer,
640
+ clearStencilBuffer: this._clearStencilBuffer,
641
+ cullFaces: this._cullFaces,
593
642
  farClip: this._farClip,
643
+ flipFaces: this._flipFaces,
594
644
  fov: this._fov,
645
+ frustumCulling: this._frustumCulling,
595
646
  nearClip: this._nearClip,
596
- projection: this._orthographic ? playcanvas.PROJECTION_ORTHOGRAPHIC : playcanvas.PROJECTION_PERSPECTIVE,
597
- orthoHeight: this._orthoHeight
647
+ orthographic: this._orthographic,
648
+ orthoHeight: this._orthoHeight,
649
+ priority: this._priority,
650
+ rect: this._rect,
651
+ scissorRect: this._scissorRect
598
652
  };
599
653
  }
600
654
  /**
@@ -621,6 +675,74 @@
621
675
  get clearColor() {
622
676
  return this._clearColor;
623
677
  }
678
+ /**
679
+ * Sets the clear color buffer of the camera.
680
+ * @param value - The clear color buffer.
681
+ */
682
+ set clearColorBuffer(value) {
683
+ this._clearColorBuffer = value;
684
+ if (this.component) {
685
+ this.component.clearColorBuffer = value;
686
+ }
687
+ }
688
+ /**
689
+ * Gets the clear color buffer of the camera.
690
+ * @returns The clear color buffer.
691
+ */
692
+ get clearColorBuffer() {
693
+ return this._clearColorBuffer;
694
+ }
695
+ /**
696
+ * Sets the clear depth buffer of the camera.
697
+ * @param value - The clear depth buffer.
698
+ */
699
+ set clearDepthBuffer(value) {
700
+ this._clearDepthBuffer = value;
701
+ if (this.component) {
702
+ this.component.clearDepthBuffer = value;
703
+ }
704
+ }
705
+ /**
706
+ * Gets the clear depth buffer of the camera.
707
+ * @returns The clear depth buffer.
708
+ */
709
+ get clearDepthBuffer() {
710
+ return this._clearDepthBuffer;
711
+ }
712
+ /**
713
+ * Sets the clear stencil buffer of the camera.
714
+ * @param value - The clear stencil buffer.
715
+ */
716
+ set clearStencilBuffer(value) {
717
+ this._clearStencilBuffer = value;
718
+ if (this.component) {
719
+ this.component.clearStencilBuffer = value;
720
+ }
721
+ }
722
+ /**
723
+ * Gets the clear stencil buffer of the camera.
724
+ * @returns The clear stencil buffer.
725
+ */
726
+ get clearStencilBuffer() {
727
+ return this._clearStencilBuffer;
728
+ }
729
+ /**
730
+ * Sets the cull faces of the camera.
731
+ * @param value - The cull faces.
732
+ */
733
+ set cullFaces(value) {
734
+ this._cullFaces = value;
735
+ if (this.component) {
736
+ this.component.cullFaces = value;
737
+ }
738
+ }
739
+ /**
740
+ * Gets the cull faces of the camera.
741
+ * @returns The cull faces.
742
+ */
743
+ get cullFaces() {
744
+ return this._cullFaces;
745
+ }
624
746
  /**
625
747
  * Sets the far clip distance of the camera.
626
748
  * @param value - The far clip distance.
@@ -638,6 +760,23 @@
638
760
  get farClip() {
639
761
  return this._farClip;
640
762
  }
763
+ /**
764
+ * Sets the flip faces of the camera.
765
+ * @param value - The flip faces.
766
+ */
767
+ set flipFaces(value) {
768
+ this._flipFaces = value;
769
+ if (this.component) {
770
+ this.component.flipFaces = value;
771
+ }
772
+ }
773
+ /**
774
+ * Gets the flip faces of the camera.
775
+ * @returns The flip faces.
776
+ */
777
+ get flipFaces() {
778
+ return this._flipFaces;
779
+ }
641
780
  /**
642
781
  * Sets the field of view of the camera.
643
782
  * @param value - The field of view.
@@ -655,6 +794,23 @@
655
794
  get fov() {
656
795
  return this._fov;
657
796
  }
797
+ /**
798
+ * Sets the frustum culling of the camera.
799
+ * @param value - The frustum culling.
800
+ */
801
+ set frustumCulling(value) {
802
+ this._frustumCulling = value;
803
+ if (this.component) {
804
+ this.component.frustumCulling = value;
805
+ }
806
+ }
807
+ /**
808
+ * Gets the frustum culling of the camera.
809
+ * @returns The frustum culling.
810
+ */
811
+ get frustumCulling() {
812
+ return this._frustumCulling;
813
+ }
658
814
  /**
659
815
  * Sets the near clip distance of the camera.
660
816
  * @param value - The near clip distance.
@@ -706,8 +862,76 @@
706
862
  get orthoHeight() {
707
863
  return this._orthoHeight;
708
864
  }
865
+ /**
866
+ * Sets the priority of the camera.
867
+ * @param value - The priority.
868
+ */
869
+ set priority(value) {
870
+ this._priority = value;
871
+ if (this.component) {
872
+ this.component.priority = value;
873
+ }
874
+ }
875
+ /**
876
+ * Gets the priority of the camera.
877
+ * @returns The priority.
878
+ */
879
+ get priority() {
880
+ return this._priority;
881
+ }
882
+ /**
883
+ * Sets the rect of the camera.
884
+ * @param value - The rect.
885
+ */
886
+ set rect(value) {
887
+ this._rect = value;
888
+ if (this.component) {
889
+ this.component.rect = value;
890
+ }
891
+ }
892
+ /**
893
+ * Gets the rect of the camera.
894
+ * @returns The rect.
895
+ */
896
+ get rect() {
897
+ return this._rect;
898
+ }
899
+ /**
900
+ * Sets the scissor rect of the camera.
901
+ * @param value - The scissor rect.
902
+ */
903
+ set scissorRect(value) {
904
+ this._scissorRect = value;
905
+ if (this.component) {
906
+ this.component.scissorRect = value;
907
+ }
908
+ }
909
+ /**
910
+ * Gets the scissor rect of the camera.
911
+ * @returns The scissor rect.
912
+ */
913
+ get scissorRect() {
914
+ return this._scissorRect;
915
+ }
709
916
  static get observedAttributes() {
710
- return [...super.observedAttributes, 'clear-color', 'near-clip', 'far-clip', 'fov', 'orthographic', 'ortho-height'];
917
+ return [
918
+ ...super.observedAttributes,
919
+ 'clear-color',
920
+ 'clear-color-buffer',
921
+ 'clear-depth-buffer',
922
+ 'clear-stencil-buffer',
923
+ 'cull-faces',
924
+ 'far-clip',
925
+ 'flip-faces',
926
+ 'fov',
927
+ 'frustum-culling',
928
+ 'near-clip',
929
+ 'orthographic',
930
+ 'ortho-height',
931
+ 'priority',
932
+ 'rect',
933
+ 'scissor-rect'
934
+ ];
711
935
  }
712
936
  attributeChangedCallback(name, _oldValue, newValue) {
713
937
  super.attributeChangedCallback(name, _oldValue, newValue);
@@ -715,12 +939,30 @@
715
939
  case 'clear-color':
716
940
  this.clearColor = parseColor(newValue);
717
941
  break;
942
+ case 'clear-color-buffer':
943
+ this.clearColorBuffer = newValue !== 'false';
944
+ break;
945
+ case 'clear-depth-buffer':
946
+ this.clearDepthBuffer = newValue !== 'false';
947
+ break;
948
+ case 'clear-stencil-buffer':
949
+ this.clearStencilBuffer = newValue !== 'false';
950
+ break;
951
+ case 'cull-faces':
952
+ this.cullFaces = newValue !== 'false';
953
+ break;
718
954
  case 'far-clip':
719
955
  this.farClip = parseFloat(newValue);
720
956
  break;
957
+ case 'flip-faces':
958
+ this.flipFaces = newValue !== 'true';
959
+ break;
721
960
  case 'fov':
722
961
  this.fov = parseFloat(newValue);
723
962
  break;
963
+ case 'frustum-culling':
964
+ this.frustumCulling = newValue !== 'false';
965
+ break;
724
966
  case 'near-clip':
725
967
  this.nearClip = parseFloat(newValue);
726
968
  break;
@@ -730,6 +972,15 @@
730
972
  case 'ortho-height':
731
973
  this.orthoHeight = parseFloat(newValue);
732
974
  break;
975
+ case 'priority':
976
+ this.priority = parseFloat(newValue);
977
+ break;
978
+ case 'rect':
979
+ this.rect = parseVec4(newValue);
980
+ break;
981
+ case 'scissor-rect':
982
+ this.scissorRect = parseVec4(newValue);
983
+ break;
733
984
  }
734
985
  }
735
986
  }
@@ -746,19 +997,23 @@
746
997
  */
747
998
  constructor() {
748
999
  super('collision');
1000
+ this._angularOffset = new playcanvas.Quat();
749
1001
  this._axis = 1;
750
1002
  this._convexHull = false;
751
1003
  this._halfExtents = new playcanvas.Vec3(0.5, 0.5, 0.5);
752
1004
  this._height = 2;
1005
+ this._linearOffset = new playcanvas.Vec3();
753
1006
  this._radius = 0.5;
754
1007
  this._type = 'box';
755
1008
  }
756
1009
  getInitialComponentData() {
757
1010
  return {
758
1011
  axis: this._axis,
1012
+ angularOffset: this._angularOffset,
759
1013
  convexHull: this._convexHull,
760
1014
  halfExtents: this._halfExtents,
761
1015
  height: this._height,
1016
+ linearOffset: this._linearOffset,
762
1017
  radius: this._radius,
763
1018
  type: this._type
764
1019
  };
@@ -770,6 +1025,15 @@
770
1025
  get component() {
771
1026
  return super.component;
772
1027
  }
1028
+ set angularOffset(value) {
1029
+ this._angularOffset = value;
1030
+ if (this.component) {
1031
+ this.component.angularOffset = value;
1032
+ }
1033
+ }
1034
+ get angularOffset() {
1035
+ return this._angularOffset;
1036
+ }
773
1037
  set axis(value) {
774
1038
  this._axis = value;
775
1039
  if (this.component) {
@@ -806,6 +1070,15 @@
806
1070
  get height() {
807
1071
  return this._height;
808
1072
  }
1073
+ set linearOffset(value) {
1074
+ this._linearOffset = value;
1075
+ if (this.component) {
1076
+ this.component.linearOffset = value;
1077
+ }
1078
+ }
1079
+ get linearOffset() {
1080
+ return this._linearOffset;
1081
+ }
809
1082
  set radius(value) {
810
1083
  this._radius = value;
811
1084
  if (this.component) {
@@ -825,11 +1098,14 @@
825
1098
  return this._type;
826
1099
  }
827
1100
  static get observedAttributes() {
828
- return [...super.observedAttributes, 'axis', 'convex-hull', 'half-extents', 'height', 'radius', 'type'];
1101
+ return [...super.observedAttributes, 'angular-offset', 'axis', 'convex-hull', 'half-extents', 'height', 'linear-offset', 'radius', 'type'];
829
1102
  }
830
1103
  attributeChangedCallback(name, _oldValue, newValue) {
831
1104
  super.attributeChangedCallback(name, _oldValue, newValue);
832
1105
  switch (name) {
1106
+ case 'angular-offset':
1107
+ this.angularOffset = parseQuat(newValue);
1108
+ break;
833
1109
  case 'axis':
834
1110
  this.axis = parseInt(newValue, 10);
835
1111
  break;
@@ -842,6 +1118,9 @@
842
1118
  case 'height':
843
1119
  this.height = parseFloat(newValue);
844
1120
  break;
1121
+ case 'linear-offset':
1122
+ this.linearOffset = parseVec3(newValue);
1123
+ break;
845
1124
  case 'radius':
846
1125
  this.radius = parseFloat(newValue);
847
1126
  break;
@@ -877,16 +1156,12 @@
877
1156
  await super.connectedCallback();
878
1157
  this.component._text._material.useFog = true;
879
1158
  }
880
- getAsset() {
881
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
882
- return assetElement.asset;
883
- }
884
1159
  getInitialComponentData() {
885
1160
  return {
886
1161
  anchor: this._anchor,
887
1162
  autoWidth: this._autoWidth,
888
1163
  color: this._color,
889
- fontAsset: this.getAsset().id,
1164
+ fontAsset: AssetElement.get(this._asset).id,
890
1165
  fontSize: this._fontSize,
891
1166
  lineHeight: this._lineHeight,
892
1167
  pivot: this._pivot,
@@ -914,7 +1189,7 @@
914
1189
  }
915
1190
  set asset(value) {
916
1191
  this._asset = value;
917
- const asset = this.getAsset();
1192
+ const asset = AssetElement.get(value);
918
1193
  if (this.component && asset) {
919
1194
  this.component.fontAsset = asset.id;
920
1195
  }
@@ -1065,13 +1340,9 @@
1065
1340
  super('gsplat');
1066
1341
  this._asset = '';
1067
1342
  }
1068
- getAsset() {
1069
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1070
- return assetElement.asset;
1071
- }
1072
1343
  getInitialComponentData() {
1073
1344
  return {
1074
- asset: this.getAsset()
1345
+ asset: AssetElement.get(this._asset)
1075
1346
  };
1076
1347
  }
1077
1348
  /**
@@ -1083,7 +1354,7 @@
1083
1354
  }
1084
1355
  set asset(value) {
1085
1356
  this._asset = value;
1086
- const asset = this.getAsset();
1357
+ const asset = AssetElement.get(value);
1087
1358
  if (this.component && asset) {
1088
1359
  this.component.asset = asset;
1089
1360
  }
@@ -1375,6 +1646,120 @@
1375
1646
  }
1376
1647
  customElements.define('pc-light', LightComponentElement);
1377
1648
 
1649
+ /**
1650
+ * Represents a material in the PlayCanvas engine.
1651
+ */
1652
+ class MaterialElement extends HTMLElement {
1653
+ constructor() {
1654
+ super(...arguments);
1655
+ this._diffuse = new playcanvas.Color(1, 1, 1);
1656
+ this._diffuseMap = '';
1657
+ this._metalnessMap = '';
1658
+ this._normalMap = '';
1659
+ this._roughnessMap = '';
1660
+ this.material = null;
1661
+ }
1662
+ createMaterial() {
1663
+ this.material = new playcanvas.StandardMaterial();
1664
+ this.material.glossInvert = true;
1665
+ this.material.useMetalness = true;
1666
+ this.material.diffuse = this._diffuse;
1667
+ this.diffuseMap = this._diffuseMap;
1668
+ this.metalnessMap = this._metalnessMap;
1669
+ this.normalMap = this._normalMap;
1670
+ this.roughnessMap = this._roughnessMap;
1671
+ this.material.update();
1672
+ }
1673
+ disconnectedCallback() {
1674
+ if (this.material) {
1675
+ this.material.destroy();
1676
+ this.material = null;
1677
+ }
1678
+ }
1679
+ setMap(map, property) {
1680
+ if (this.material) {
1681
+ const asset = AssetElement.get(map);
1682
+ if (asset) {
1683
+ if (asset.loaded) {
1684
+ this.material[property] = asset.resource;
1685
+ this.material[property].anisotropy = 4;
1686
+ }
1687
+ else {
1688
+ asset.once('load', () => {
1689
+ this.material[property] = asset.resource;
1690
+ this.material[property].anisotropy = 4;
1691
+ this.material.update();
1692
+ });
1693
+ }
1694
+ }
1695
+ }
1696
+ }
1697
+ set diffuse(value) {
1698
+ this._diffuse = value;
1699
+ if (this.material) {
1700
+ this.material.diffuse = value;
1701
+ }
1702
+ }
1703
+ get diffuse() {
1704
+ return this._diffuse;
1705
+ }
1706
+ set diffuseMap(value) {
1707
+ this._diffuseMap = value;
1708
+ this.setMap(value, 'diffuseMap');
1709
+ }
1710
+ get diffuseMap() {
1711
+ return this._diffuseMap;
1712
+ }
1713
+ set metalnessMap(value) {
1714
+ this._metalnessMap = value;
1715
+ this.setMap(value, 'metalnessMap');
1716
+ }
1717
+ get metalnessMap() {
1718
+ return this._metalnessMap;
1719
+ }
1720
+ set normalMap(value) {
1721
+ this._normalMap = value;
1722
+ this.setMap(value, 'normalMap');
1723
+ }
1724
+ get normalMap() {
1725
+ return this._normalMap;
1726
+ }
1727
+ set roughnessMap(value) {
1728
+ this._roughnessMap = value;
1729
+ this.setMap(value, 'glossMap');
1730
+ }
1731
+ get roughnessMap() {
1732
+ return this._roughnessMap;
1733
+ }
1734
+ static get(id) {
1735
+ const materialElement = document.querySelector(`pc-material[id="${id}"]`);
1736
+ return materialElement === null || materialElement === void 0 ? void 0 : materialElement.material;
1737
+ }
1738
+ static get observedAttributes() {
1739
+ return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
1740
+ }
1741
+ attributeChangedCallback(name, _oldValue, newValue) {
1742
+ switch (name) {
1743
+ case 'diffuse':
1744
+ this.diffuse = parseColor(newValue);
1745
+ break;
1746
+ case 'diffuse-map':
1747
+ this.diffuseMap = newValue;
1748
+ break;
1749
+ case 'metalness-map':
1750
+ this.metalnessMap = newValue;
1751
+ break;
1752
+ case 'normal-map':
1753
+ this.normalMap = newValue;
1754
+ break;
1755
+ case 'roughness-map':
1756
+ this.roughnessMap = newValue;
1757
+ break;
1758
+ }
1759
+ }
1760
+ }
1761
+ customElements.define('pc-material', MaterialElement);
1762
+
1378
1763
  /**
1379
1764
  * Represents a render component in the PlayCanvas engine.
1380
1765
  *
@@ -1383,9 +1768,14 @@
1383
1768
  class RenderComponentElement extends ComponentElement {
1384
1769
  constructor() {
1385
1770
  super('render');
1386
- this._type = 'asset';
1387
1771
  this._castShadows = true;
1772
+ this._material = '';
1388
1773
  this._receiveShadows = true;
1774
+ this._type = 'asset';
1775
+ }
1776
+ async connectedCallback() {
1777
+ await super.connectedCallback();
1778
+ this.material = this._material;
1389
1779
  }
1390
1780
  getInitialComponentData() {
1391
1781
  return {
@@ -1435,6 +1825,23 @@
1435
1825
  get castShadows() {
1436
1826
  return this._castShadows;
1437
1827
  }
1828
+ /**
1829
+ * Sets the material of the render component.
1830
+ * @param value - The id of the material asset to use.
1831
+ */
1832
+ set material(value) {
1833
+ this._material = value;
1834
+ if (this.component) {
1835
+ this.component.material = MaterialElement.get(value);
1836
+ }
1837
+ }
1838
+ /**
1839
+ * Gets the id of the material asset used by the render component.
1840
+ * @returns The id of the material asset.
1841
+ */
1842
+ get material() {
1843
+ return this._material;
1844
+ }
1438
1845
  /**
1439
1846
  * Sets the receive shadows flag of the render component.
1440
1847
  * @param value - The receive shadows flag.
@@ -1453,20 +1860,23 @@
1453
1860
  return this._receiveShadows;
1454
1861
  }
1455
1862
  static get observedAttributes() {
1456
- return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
1863
+ return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
1457
1864
  }
1458
1865
  attributeChangedCallback(name, _oldValue, newValue) {
1459
1866
  super.attributeChangedCallback(name, _oldValue, newValue);
1460
1867
  switch (name) {
1461
- case 'type':
1462
- this.type = newValue;
1463
- break;
1464
1868
  case 'cast-shadows':
1465
1869
  this.castShadows = newValue !== 'false';
1466
1870
  break;
1871
+ case 'material':
1872
+ this.material = newValue;
1873
+ break;
1467
1874
  case 'receive-shadows':
1468
1875
  this.receiveShadows = newValue !== 'false';
1469
1876
  break;
1877
+ case 'type':
1878
+ this.type = newValue;
1879
+ break;
1470
1880
  }
1471
1881
  }
1472
1882
  }
@@ -1659,6 +2069,129 @@
1659
2069
  }
1660
2070
  customElements.define('pc-rigidbody', RigidBodyComponentElement);
1661
2071
 
2072
+ /**
2073
+ * Represents a screen component in the PlayCanvas engine.
2074
+ *
2075
+ * @category Components
2076
+ */
2077
+ class ScreenComponentElement extends ComponentElement {
2078
+ constructor() {
2079
+ super('screen');
2080
+ this._screenSpace = false;
2081
+ this._resolution = new playcanvas.Vec2(640, 320);
2082
+ this._referenceResolution = new playcanvas.Vec2(640, 320);
2083
+ this._priority = 0;
2084
+ this._blend = false;
2085
+ this._scaleBlend = 0.5;
2086
+ }
2087
+ getInitialComponentData() {
2088
+ return {
2089
+ priority: this._priority,
2090
+ referenceResolution: this._referenceResolution,
2091
+ resolution: this._resolution,
2092
+ scaleBlend: this._scaleBlend,
2093
+ scaleMode: this._blend ? playcanvas.SCALEMODE_BLEND : playcanvas.SCALEMODE_NONE,
2094
+ screenSpace: this._screenSpace
2095
+ };
2096
+ }
2097
+ /**
2098
+ * Gets the screen component.
2099
+ * @returns The screen component.
2100
+ */
2101
+ get component() {
2102
+ return super.component;
2103
+ }
2104
+ set priority(value) {
2105
+ this._priority = value;
2106
+ if (this.component) {
2107
+ this.component.priority = this._priority;
2108
+ }
2109
+ }
2110
+ get priority() {
2111
+ return this._priority;
2112
+ }
2113
+ set referenceResolution(value) {
2114
+ this._referenceResolution = value;
2115
+ if (this.component) {
2116
+ this.component.referenceResolution = this._referenceResolution;
2117
+ }
2118
+ }
2119
+ get referenceResolution() {
2120
+ return this._referenceResolution;
2121
+ }
2122
+ set resolution(value) {
2123
+ this._resolution = value;
2124
+ if (this.component) {
2125
+ this.component.resolution = this._resolution;
2126
+ }
2127
+ }
2128
+ get resolution() {
2129
+ return this._resolution;
2130
+ }
2131
+ set scaleBlend(value) {
2132
+ this._scaleBlend = value;
2133
+ if (this.component) {
2134
+ this.component.scaleBlend = this._scaleBlend;
2135
+ }
2136
+ }
2137
+ get scaleBlend() {
2138
+ return this._scaleBlend;
2139
+ }
2140
+ set blend(value) {
2141
+ this._blend = value;
2142
+ if (this.component) {
2143
+ this.component.scaleMode = this._blend ? playcanvas.SCALEMODE_BLEND : playcanvas.SCALEMODE_NONE;
2144
+ }
2145
+ }
2146
+ get blend() {
2147
+ return this._blend;
2148
+ }
2149
+ set screenSpace(value) {
2150
+ this._screenSpace = value;
2151
+ if (this.component) {
2152
+ this.component.screenSpace = this._screenSpace;
2153
+ }
2154
+ }
2155
+ get screenSpace() {
2156
+ return this._screenSpace;
2157
+ }
2158
+ static get observedAttributes() {
2159
+ return [
2160
+ ...super.observedAttributes,
2161
+ 'blend',
2162
+ 'screen-space',
2163
+ 'resolution',
2164
+ 'reference-resolution',
2165
+ 'priority',
2166
+ 'scale-blend'
2167
+ ];
2168
+ }
2169
+ attributeChangedCallback(name, _oldValue, newValue) {
2170
+ super.attributeChangedCallback(name, _oldValue, newValue);
2171
+ switch (name) {
2172
+ case 'priority':
2173
+ this.priority = parseInt(newValue, 10);
2174
+ break;
2175
+ case 'reference-resolution':
2176
+ this.referenceResolution = parseVec2(newValue);
2177
+ break;
2178
+ case 'resolution':
2179
+ this.resolution = parseVec2(newValue);
2180
+ break;
2181
+ case 'scale-blend':
2182
+ this.scaleBlend = parseFloat(newValue);
2183
+ break;
2184
+ case 'blend':
2185
+ this.blend = this.hasAttribute('blend');
2186
+ break;
2187
+ case 'screen-space':
2188
+ this.screenSpace = this.hasAttribute('screen-space');
2189
+ break;
2190
+ }
2191
+ }
2192
+ }
2193
+ customElements.define('pc-screen', ScreenComponentElement);
2194
+
1662
2195
  /**
1663
2196
  * Represents a script component in the PlayCanvas engine.
1664
2197
  *
@@ -1964,10 +2497,6 @@
1964
2497
  */
1965
2498
  this.soundSlot = null;
1966
2499
  }
1967
- getAsset() {
1968
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
1969
- return assetElement.asset;
1970
- }
1971
2500
  async connectedCallback() {
1972
2501
  const appElement = this.closest('pc-app');
1973
2502
  if (!appElement) {
@@ -2009,7 +2538,7 @@
2009
2538
  var _a;
2010
2539
  this._asset = value;
2011
2540
  if (this.soundSlot) {
2012
- const id = (_a = this.getAsset()) === null || _a === void 0 ? void 0 : _a.id;
2541
+ const id = (_a = AssetElement.get(value)) === null || _a === void 0 ? void 0 : _a.id;
2013
2542
  if (id) {
2014
2543
  this.soundSlot.asset = id;
2015
2544
  }
@@ -2213,12 +2742,8 @@
2213
2742
  this.asset = asset;
2214
2743
  }
2215
2744
  }
2216
- getAsset() {
2217
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2218
- return assetElement.asset;
2219
- }
2220
2745
  _loadModel() {
2221
- const asset = this.getAsset();
2746
+ const asset = AssetElement.get(this._asset);
2222
2747
  if (!asset) {
2223
2748
  return;
2224
2749
  }
@@ -2446,10 +2971,6 @@
2446
2971
  this.asset = this.getAttribute('asset') || '';
2447
2972
  this.solidColor = this.hasAttribute('solid-color');
2448
2973
  }
2449
- getAsset() {
2450
- const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
2451
- return assetElement.asset;
2452
- }
2453
2974
  getScene() {
2454
2975
  const appElement = this.closest('pc-app');
2455
2976
  if (!appElement) {
@@ -2465,7 +2986,7 @@
2465
2986
  this._asset = value;
2466
2987
  const scene = this.getScene();
2467
2988
  if (scene) {
2468
- const asset = this.getAsset();
2989
+ const asset = AssetElement.get(value);
2469
2990
  if (asset) {
2470
2991
  if (asset.resource) {
2471
2992
  scene.envAtlas = asset.resource;
@@ -2559,11 +3080,13 @@
2559
3080
  exports.GSplatComponentElement = GSplatComponentElement;
2560
3081
  exports.LightComponentElement = LightComponentElement;
2561
3082
  exports.ListenerComponentElement = ListenerComponentElement;
3083
+ exports.MaterialElement = MaterialElement;
2562
3084
  exports.ModelElement = ModelElement;
2563
3085
  exports.ModuleElement = ModuleElement;
2564
3086
  exports.RenderComponentElement = RenderComponentElement;
2565
3087
  exports.RigidBodyComponentElement = RigidBodyComponentElement;
2566
3088
  exports.SceneElement = SceneElement;
3089
+ exports.ScreenComponentElement = ScreenComponentElement;
2567
3090
  exports.ScriptComponentElement = ScriptComponentElement;
2568
3091
  exports.ScriptElement = ScriptElement;
2569
3092
  exports.SkyElement = SkyElement;