@playcanvas/web-components 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -6
- package/dist/asset.d.ts +1 -0
- package/dist/components/camera-component.d.ts +110 -2
- package/dist/components/element-component.d.ts +0 -1
- package/dist/components/gsplat-component.d.ts +1 -2
- package/dist/components/render-component.d.ts +13 -1
- package/dist/components/screen-component.d.ts +44 -0
- package/dist/components/sound-slot.d.ts +0 -1
- package/dist/index.d.ts +3 -1
- package/dist/material.d.ts +29 -0
- package/dist/model.d.ts +0 -1
- package/dist/pwc.cjs +505 -37
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +505 -37
- package/dist/pwc.js.map +1 -1
- package/dist/pwc.min.js +1 -1
- package/dist/pwc.min.js.map +1 -1
- package/dist/pwc.mjs +505 -39
- package/dist/pwc.mjs.map +1 -1
- package/dist/sky.d.ts +0 -1
- package/package.json +4 -4
- package/src/app.ts +7 -0
- package/src/asset.ts +5 -0
- package/src/components/camera-component.ts +248 -6
- package/src/components/element-component.ts +2 -7
- package/src/components/gsplat-component.ts +2 -7
- package/src/components/render-component.ts +38 -7
- package/src/components/screen-component.ts +153 -0
- package/src/components/sound-slot.ts +1 -6
- package/src/entity.ts +1 -1
- package/src/index.ts +4 -0
- package/src/material.ts +138 -0
- package/src/model.ts +1 -6
- package/src/sky.ts +1 -6
package/dist/pwc.cjs
CHANGED
|
@@ -78,6 +78,11 @@ class AppElement extends HTMLElement {
|
|
|
78
78
|
this.app.assets.add(asset);
|
|
79
79
|
}
|
|
80
80
|
});
|
|
81
|
+
// Get all pc-material elements that are direct children of the pc-app element
|
|
82
|
+
const materialElements = this.querySelectorAll(':scope > pc-material');
|
|
83
|
+
Array.from(materialElements).forEach((materialElement) => {
|
|
84
|
+
materialElement.createMaterial();
|
|
85
|
+
});
|
|
81
86
|
// Load assets before starting the application
|
|
82
87
|
this.app.preload(() => {
|
|
83
88
|
// Start the application
|
|
@@ -222,7 +227,7 @@ class EntityElement extends HTMLElement {
|
|
|
222
227
|
const app = await appElement.getApplication();
|
|
223
228
|
// Create a new entity
|
|
224
229
|
this.entity = new playcanvas.Entity(this._name, app);
|
|
225
|
-
if (this.parentElement && this.parentElement.tagName === 'pc-entity' && this.parentElement.entity) {
|
|
230
|
+
if (this.parentElement && this.parentElement.tagName.toLowerCase() === 'pc-entity' && this.parentElement.entity) {
|
|
226
231
|
this.parentElement.entity.addChild(this.entity);
|
|
227
232
|
}
|
|
228
233
|
else {
|
|
@@ -457,6 +462,10 @@ class AssetElement extends HTMLElement {
|
|
|
457
462
|
get preload() {
|
|
458
463
|
return this._preload;
|
|
459
464
|
}
|
|
465
|
+
static get(id) {
|
|
466
|
+
const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
|
|
467
|
+
return assetElement === null || assetElement === void 0 ? void 0 : assetElement.asset;
|
|
468
|
+
}
|
|
460
469
|
static get observedAttributes() {
|
|
461
470
|
return ['preload'];
|
|
462
471
|
}
|
|
@@ -578,21 +587,39 @@ class CameraComponentElement extends ComponentElement {
|
|
|
578
587
|
*/
|
|
579
588
|
constructor() {
|
|
580
589
|
super('camera');
|
|
581
|
-
this._clearColor = new playcanvas.Color(
|
|
590
|
+
this._clearColor = new playcanvas.Color(0.75, 0.75, 0.75, 1);
|
|
591
|
+
this._clearColorBuffer = true;
|
|
592
|
+
this._clearDepthBuffer = true;
|
|
593
|
+
this._clearStencilBuffer = false;
|
|
594
|
+
this._cullFaces = true;
|
|
582
595
|
this._farClip = 1000;
|
|
596
|
+
this._flipFaces = false;
|
|
583
597
|
this._fov = 45;
|
|
598
|
+
this._frustumCulling = true;
|
|
584
599
|
this._nearClip = 0.1;
|
|
585
600
|
this._orthographic = false;
|
|
586
601
|
this._orthoHeight = 10;
|
|
602
|
+
this._priority = 0;
|
|
603
|
+
this._rect = new playcanvas.Vec4(0, 0, 1, 1);
|
|
604
|
+
this._scissorRect = new playcanvas.Vec4(0, 0, 1, 1);
|
|
587
605
|
}
|
|
588
606
|
getInitialComponentData() {
|
|
589
607
|
return {
|
|
590
608
|
clearColor: this._clearColor,
|
|
609
|
+
clearColorBuffer: this._clearColorBuffer,
|
|
610
|
+
clearDepthBuffer: this._clearDepthBuffer,
|
|
611
|
+
clearStencilBuffer: this._clearStencilBuffer,
|
|
612
|
+
cullFaces: this._cullFaces,
|
|
591
613
|
farClip: this._farClip,
|
|
614
|
+
flipFaces: this._flipFaces,
|
|
592
615
|
fov: this._fov,
|
|
616
|
+
frustumCulling: this._frustumCulling,
|
|
593
617
|
nearClip: this._nearClip,
|
|
594
|
-
|
|
595
|
-
orthoHeight: this._orthoHeight
|
|
618
|
+
orthographic: this._orthographic,
|
|
619
|
+
orthoHeight: this._orthoHeight,
|
|
620
|
+
priority: this._priority,
|
|
621
|
+
rect: this._rect,
|
|
622
|
+
scissorRect: this._scissorRect
|
|
596
623
|
};
|
|
597
624
|
}
|
|
598
625
|
/**
|
|
@@ -619,6 +646,74 @@ class CameraComponentElement extends ComponentElement {
|
|
|
619
646
|
get clearColor() {
|
|
620
647
|
return this._clearColor;
|
|
621
648
|
}
|
|
649
|
+
/**
|
|
650
|
+
* Sets the clear color buffer of the camera.
|
|
651
|
+
* @param value - The clear color buffer.
|
|
652
|
+
*/
|
|
653
|
+
set clearColorBuffer(value) {
|
|
654
|
+
this._clearColorBuffer = value;
|
|
655
|
+
if (this.component) {
|
|
656
|
+
this.component.clearColorBuffer = value;
|
|
657
|
+
}
|
|
658
|
+
}
|
|
659
|
+
/**
|
|
660
|
+
* Gets the clear color buffer of the camera.
|
|
661
|
+
* @returns The clear color buffer.
|
|
662
|
+
*/
|
|
663
|
+
get clearColorBuffer() {
|
|
664
|
+
return this._clearColorBuffer;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* Sets the clear depth buffer of the camera.
|
|
668
|
+
* @param value - The clear depth buffer.
|
|
669
|
+
*/
|
|
670
|
+
set clearDepthBuffer(value) {
|
|
671
|
+
this._clearDepthBuffer = value;
|
|
672
|
+
if (this.component) {
|
|
673
|
+
this.component.clearDepthBuffer = value;
|
|
674
|
+
}
|
|
675
|
+
}
|
|
676
|
+
/**
|
|
677
|
+
* Gets the clear depth buffer of the camera.
|
|
678
|
+
* @returns The clear depth buffer.
|
|
679
|
+
*/
|
|
680
|
+
get clearDepthBuffer() {
|
|
681
|
+
return this._clearDepthBuffer;
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
684
|
+
* Sets the clear stencil buffer of the camera.
|
|
685
|
+
* @param value - The clear stencil buffer.
|
|
686
|
+
*/
|
|
687
|
+
set clearStencilBuffer(value) {
|
|
688
|
+
this._clearStencilBuffer = value;
|
|
689
|
+
if (this.component) {
|
|
690
|
+
this.component.clearStencilBuffer = value;
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
/**
|
|
694
|
+
* Gets the clear stencil buffer of the camera.
|
|
695
|
+
* @returns The clear stencil buffer.
|
|
696
|
+
*/
|
|
697
|
+
get clearStencilBuffer() {
|
|
698
|
+
return this._clearStencilBuffer;
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* Sets the cull faces of the camera.
|
|
702
|
+
* @param value - The cull faces.
|
|
703
|
+
*/
|
|
704
|
+
set cullFaces(value) {
|
|
705
|
+
this._cullFaces = value;
|
|
706
|
+
if (this.component) {
|
|
707
|
+
this.component.cullFaces = value;
|
|
708
|
+
}
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
711
|
+
* Gets the cull faces of the camera.
|
|
712
|
+
* @returns The cull faces.
|
|
713
|
+
*/
|
|
714
|
+
get cullFaces() {
|
|
715
|
+
return this._cullFaces;
|
|
716
|
+
}
|
|
622
717
|
/**
|
|
623
718
|
* Sets the far clip distance of the camera.
|
|
624
719
|
* @param value - The far clip distance.
|
|
@@ -636,6 +731,23 @@ class CameraComponentElement extends ComponentElement {
|
|
|
636
731
|
get farClip() {
|
|
637
732
|
return this._farClip;
|
|
638
733
|
}
|
|
734
|
+
/**
|
|
735
|
+
* Sets the flip faces of the camera.
|
|
736
|
+
* @param value - The flip faces.
|
|
737
|
+
*/
|
|
738
|
+
set flipFaces(value) {
|
|
739
|
+
this._flipFaces = value;
|
|
740
|
+
if (this.component) {
|
|
741
|
+
this.component.flipFaces = value;
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
/**
|
|
745
|
+
* Gets the flip faces of the camera.
|
|
746
|
+
* @returns The flip faces.
|
|
747
|
+
*/
|
|
748
|
+
get flipFaces() {
|
|
749
|
+
return this._flipFaces;
|
|
750
|
+
}
|
|
639
751
|
/**
|
|
640
752
|
* Sets the field of view of the camera.
|
|
641
753
|
* @param value - The field of view.
|
|
@@ -653,6 +765,23 @@ class CameraComponentElement extends ComponentElement {
|
|
|
653
765
|
get fov() {
|
|
654
766
|
return this._fov;
|
|
655
767
|
}
|
|
768
|
+
/**
|
|
769
|
+
* Sets the frustum culling of the camera.
|
|
770
|
+
* @param value - The frustum culling.
|
|
771
|
+
*/
|
|
772
|
+
set frustumCulling(value) {
|
|
773
|
+
this._frustumCulling = value;
|
|
774
|
+
if (this.component) {
|
|
775
|
+
this.component.frustumCulling = value;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Gets the frustum culling of the camera.
|
|
780
|
+
* @returns The frustum culling.
|
|
781
|
+
*/
|
|
782
|
+
get frustumCulling() {
|
|
783
|
+
return this._frustumCulling;
|
|
784
|
+
}
|
|
656
785
|
/**
|
|
657
786
|
* Sets the near clip distance of the camera.
|
|
658
787
|
* @param value - The near clip distance.
|
|
@@ -704,8 +833,76 @@ class CameraComponentElement extends ComponentElement {
|
|
|
704
833
|
get orthoHeight() {
|
|
705
834
|
return this._orthoHeight;
|
|
706
835
|
}
|
|
836
|
+
/**
|
|
837
|
+
* Sets the priority of the camera.
|
|
838
|
+
* @param value - The priority.
|
|
839
|
+
*/
|
|
840
|
+
set priority(value) {
|
|
841
|
+
this._priority = value;
|
|
842
|
+
if (this.component) {
|
|
843
|
+
this.component.priority = value;
|
|
844
|
+
}
|
|
845
|
+
}
|
|
846
|
+
/**
|
|
847
|
+
* Gets the priority of the camera.
|
|
848
|
+
* @returns The priority.
|
|
849
|
+
*/
|
|
850
|
+
get priority() {
|
|
851
|
+
return this._priority;
|
|
852
|
+
}
|
|
853
|
+
/**
|
|
854
|
+
* Sets the rect of the camera.
|
|
855
|
+
* @param value - The rect.
|
|
856
|
+
*/
|
|
857
|
+
set rect(value) {
|
|
858
|
+
this._rect = value;
|
|
859
|
+
if (this.component) {
|
|
860
|
+
this.component.rect = value;
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
/**
|
|
864
|
+
* Gets the rect of the camera.
|
|
865
|
+
* @returns The rect.
|
|
866
|
+
*/
|
|
867
|
+
get rect() {
|
|
868
|
+
return this._rect;
|
|
869
|
+
}
|
|
870
|
+
/**
|
|
871
|
+
* Sets the scissor rect of the camera.
|
|
872
|
+
* @param value - The scissor rect.
|
|
873
|
+
*/
|
|
874
|
+
set scissorRect(value) {
|
|
875
|
+
this._scissorRect = value;
|
|
876
|
+
if (this.component) {
|
|
877
|
+
this.component.scissorRect = value;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
/**
|
|
881
|
+
* Gets the scissor rect of the camera.
|
|
882
|
+
* @returns The scissor rect.
|
|
883
|
+
*/
|
|
884
|
+
get scissorRect() {
|
|
885
|
+
return this._scissorRect;
|
|
886
|
+
}
|
|
707
887
|
static get observedAttributes() {
|
|
708
|
-
return [
|
|
888
|
+
return [
|
|
889
|
+
...super.observedAttributes,
|
|
890
|
+
'clear-color',
|
|
891
|
+
'clear-color-buffer',
|
|
892
|
+
'clear-depth-buffer',
|
|
893
|
+
'clear-stencil-buffer',
|
|
894
|
+
'cull-faces',
|
|
895
|
+
'far-clip',
|
|
896
|
+
'flip-faces',
|
|
897
|
+
'fov',
|
|
898
|
+
'frustum-culling',
|
|
899
|
+
'near-clip',
|
|
900
|
+
'orthographic',
|
|
901
|
+
'ortho-height',
|
|
902
|
+
'priority',
|
|
903
|
+
'rect',
|
|
904
|
+
'scissor-rect'
|
|
905
|
+
];
|
|
709
906
|
}
|
|
710
907
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
711
908
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
@@ -713,12 +910,30 @@ class CameraComponentElement extends ComponentElement {
|
|
|
713
910
|
case 'clear-color':
|
|
714
911
|
this.clearColor = parseColor(newValue);
|
|
715
912
|
break;
|
|
913
|
+
case 'clear-color-buffer':
|
|
914
|
+
this.clearColorBuffer = newValue !== 'false';
|
|
915
|
+
break;
|
|
916
|
+
case 'clear-depth-buffer':
|
|
917
|
+
this.clearDepthBuffer = newValue !== 'false';
|
|
918
|
+
break;
|
|
919
|
+
case 'clear-stencil-buffer':
|
|
920
|
+
this.clearStencilBuffer = newValue !== 'false';
|
|
921
|
+
break;
|
|
922
|
+
case 'cull-faces':
|
|
923
|
+
this.cullFaces = newValue !== 'false';
|
|
924
|
+
break;
|
|
716
925
|
case 'far-clip':
|
|
717
926
|
this.farClip = parseFloat(newValue);
|
|
718
927
|
break;
|
|
928
|
+
case 'flip-faces':
|
|
929
|
+
this.flipFaces = newValue !== 'true';
|
|
930
|
+
break;
|
|
719
931
|
case 'fov':
|
|
720
932
|
this.fov = parseFloat(newValue);
|
|
721
933
|
break;
|
|
934
|
+
case 'frustum-culling':
|
|
935
|
+
this.frustumCulling = newValue !== 'false';
|
|
936
|
+
break;
|
|
722
937
|
case 'near-clip':
|
|
723
938
|
this.nearClip = parseFloat(newValue);
|
|
724
939
|
break;
|
|
@@ -728,6 +943,15 @@ class CameraComponentElement extends ComponentElement {
|
|
|
728
943
|
case 'ortho-height':
|
|
729
944
|
this.orthoHeight = parseFloat(newValue);
|
|
730
945
|
break;
|
|
946
|
+
case 'priority':
|
|
947
|
+
this.priority = parseFloat(newValue);
|
|
948
|
+
break;
|
|
949
|
+
case 'rect':
|
|
950
|
+
this.rect = parseVec4(newValue);
|
|
951
|
+
break;
|
|
952
|
+
case 'scissor-rect':
|
|
953
|
+
this.scissorRect = parseVec4(newValue);
|
|
954
|
+
break;
|
|
731
955
|
}
|
|
732
956
|
}
|
|
733
957
|
}
|
|
@@ -875,16 +1099,12 @@ class ElementComponentElement extends ComponentElement {
|
|
|
875
1099
|
await super.connectedCallback();
|
|
876
1100
|
this.component._text._material.useFog = true;
|
|
877
1101
|
}
|
|
878
|
-
getAsset() {
|
|
879
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
880
|
-
return assetElement.asset;
|
|
881
|
-
}
|
|
882
1102
|
getInitialComponentData() {
|
|
883
1103
|
return {
|
|
884
1104
|
anchor: this._anchor,
|
|
885
1105
|
autoWidth: this._autoWidth,
|
|
886
1106
|
color: this._color,
|
|
887
|
-
fontAsset: this.
|
|
1107
|
+
fontAsset: AssetElement.get(this._asset).id,
|
|
888
1108
|
fontSize: this._fontSize,
|
|
889
1109
|
lineHeight: this._lineHeight,
|
|
890
1110
|
pivot: this._pivot,
|
|
@@ -912,7 +1132,7 @@ class ElementComponentElement extends ComponentElement {
|
|
|
912
1132
|
}
|
|
913
1133
|
set asset(value) {
|
|
914
1134
|
this._asset = value;
|
|
915
|
-
const asset =
|
|
1135
|
+
const asset = AssetElement.get(value);
|
|
916
1136
|
if (this.component && asset) {
|
|
917
1137
|
this.component.fontAsset = asset.id;
|
|
918
1138
|
}
|
|
@@ -1063,13 +1283,9 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
1063
1283
|
super('gsplat');
|
|
1064
1284
|
this._asset = '';
|
|
1065
1285
|
}
|
|
1066
|
-
getAsset() {
|
|
1067
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
1068
|
-
return assetElement.asset;
|
|
1069
|
-
}
|
|
1070
1286
|
getInitialComponentData() {
|
|
1071
1287
|
return {
|
|
1072
|
-
asset: this.
|
|
1288
|
+
asset: AssetElement.get(this._asset)
|
|
1073
1289
|
};
|
|
1074
1290
|
}
|
|
1075
1291
|
/**
|
|
@@ -1081,7 +1297,7 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
1081
1297
|
}
|
|
1082
1298
|
set asset(value) {
|
|
1083
1299
|
this._asset = value;
|
|
1084
|
-
const asset =
|
|
1300
|
+
const asset = AssetElement.get(value);
|
|
1085
1301
|
if (this.component && asset) {
|
|
1086
1302
|
this.component.asset = asset;
|
|
1087
1303
|
}
|
|
@@ -1373,6 +1589,120 @@ class LightComponentElement extends ComponentElement {
|
|
|
1373
1589
|
}
|
|
1374
1590
|
customElements.define('pc-light', LightComponentElement);
|
|
1375
1591
|
|
|
1592
|
+
/**
|
|
1593
|
+
* Represents a material in the PlayCanvas engine.
|
|
1594
|
+
*/
|
|
1595
|
+
class MaterialElement extends HTMLElement {
|
|
1596
|
+
constructor() {
|
|
1597
|
+
super(...arguments);
|
|
1598
|
+
this._diffuse = new playcanvas.Color(1, 1, 1);
|
|
1599
|
+
this._diffuseMap = '';
|
|
1600
|
+
this._metalnessMap = '';
|
|
1601
|
+
this._normalMap = '';
|
|
1602
|
+
this._roughnessMap = '';
|
|
1603
|
+
this.material = null;
|
|
1604
|
+
}
|
|
1605
|
+
createMaterial() {
|
|
1606
|
+
this.material = new playcanvas.StandardMaterial();
|
|
1607
|
+
this.material.glossInvert = true;
|
|
1608
|
+
this.material.useMetalness = true;
|
|
1609
|
+
this.material.diffuse = this._diffuse;
|
|
1610
|
+
this.diffuseMap = this._diffuseMap;
|
|
1611
|
+
this.metalnessMap = this._metalnessMap;
|
|
1612
|
+
this.normalMap = this._normalMap;
|
|
1613
|
+
this.roughnessMap = this._roughnessMap;
|
|
1614
|
+
this.material.update();
|
|
1615
|
+
}
|
|
1616
|
+
disconnectedCallback() {
|
|
1617
|
+
if (this.material) {
|
|
1618
|
+
this.material.destroy();
|
|
1619
|
+
this.material = null;
|
|
1620
|
+
}
|
|
1621
|
+
}
|
|
1622
|
+
setMap(map, property) {
|
|
1623
|
+
if (this.material) {
|
|
1624
|
+
const asset = AssetElement.get(map);
|
|
1625
|
+
if (asset) {
|
|
1626
|
+
if (asset.loaded) {
|
|
1627
|
+
this.material[property] = asset.resource;
|
|
1628
|
+
this.material[property].anisotropy = 4;
|
|
1629
|
+
}
|
|
1630
|
+
else {
|
|
1631
|
+
asset.once('load', () => {
|
|
1632
|
+
this.material[property] = asset.resource;
|
|
1633
|
+
this.material[property].anisotropy = 4;
|
|
1634
|
+
this.material.update();
|
|
1635
|
+
});
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
}
|
|
1639
|
+
}
|
|
1640
|
+
set diffuse(value) {
|
|
1641
|
+
this._diffuse = value;
|
|
1642
|
+
if (this.material) {
|
|
1643
|
+
this.material.diffuse = value;
|
|
1644
|
+
}
|
|
1645
|
+
}
|
|
1646
|
+
get diffuse() {
|
|
1647
|
+
return this._diffuse;
|
|
1648
|
+
}
|
|
1649
|
+
set diffuseMap(value) {
|
|
1650
|
+
this._diffuseMap = value;
|
|
1651
|
+
this.setMap(value, 'diffuseMap');
|
|
1652
|
+
}
|
|
1653
|
+
get diffuseMap() {
|
|
1654
|
+
return this._diffuseMap;
|
|
1655
|
+
}
|
|
1656
|
+
set metalnessMap(value) {
|
|
1657
|
+
this._metalnessMap = value;
|
|
1658
|
+
this.setMap(value, 'metalnessMap');
|
|
1659
|
+
}
|
|
1660
|
+
get metalnessMap() {
|
|
1661
|
+
return this._metalnessMap;
|
|
1662
|
+
}
|
|
1663
|
+
set normalMap(value) {
|
|
1664
|
+
this._normalMap = value;
|
|
1665
|
+
this.setMap(value, 'normalMap');
|
|
1666
|
+
}
|
|
1667
|
+
get normalMap() {
|
|
1668
|
+
return this._normalMap;
|
|
1669
|
+
}
|
|
1670
|
+
set roughnessMap(value) {
|
|
1671
|
+
this._roughnessMap = value;
|
|
1672
|
+
this.setMap(value, 'glossMap');
|
|
1673
|
+
}
|
|
1674
|
+
get roughnessMap() {
|
|
1675
|
+
return this._roughnessMap;
|
|
1676
|
+
}
|
|
1677
|
+
static get(id) {
|
|
1678
|
+
const materialElement = document.querySelector(`pc-material[id="${id}"]`);
|
|
1679
|
+
return materialElement === null || materialElement === void 0 ? void 0 : materialElement.material;
|
|
1680
|
+
}
|
|
1681
|
+
static get observedAttributes() {
|
|
1682
|
+
return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
|
|
1683
|
+
}
|
|
1684
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1685
|
+
switch (name) {
|
|
1686
|
+
case 'diffuse':
|
|
1687
|
+
this.diffuse = parseColor(newValue);
|
|
1688
|
+
break;
|
|
1689
|
+
case 'diffuse-map':
|
|
1690
|
+
this.diffuseMap = newValue;
|
|
1691
|
+
break;
|
|
1692
|
+
case 'metalness-map':
|
|
1693
|
+
this.metalnessMap = newValue;
|
|
1694
|
+
break;
|
|
1695
|
+
case 'normal-map':
|
|
1696
|
+
this.normalMap = newValue;
|
|
1697
|
+
break;
|
|
1698
|
+
case 'roughness-map':
|
|
1699
|
+
this.roughnessMap = newValue;
|
|
1700
|
+
break;
|
|
1701
|
+
}
|
|
1702
|
+
}
|
|
1703
|
+
}
|
|
1704
|
+
customElements.define('pc-material', MaterialElement);
|
|
1705
|
+
|
|
1376
1706
|
/**
|
|
1377
1707
|
* Represents a render component in the PlayCanvas engine.
|
|
1378
1708
|
*
|
|
@@ -1381,9 +1711,14 @@ customElements.define('pc-light', LightComponentElement);
|
|
|
1381
1711
|
class RenderComponentElement extends ComponentElement {
|
|
1382
1712
|
constructor() {
|
|
1383
1713
|
super('render');
|
|
1384
|
-
this._type = 'asset';
|
|
1385
1714
|
this._castShadows = true;
|
|
1715
|
+
this._material = '';
|
|
1386
1716
|
this._receiveShadows = true;
|
|
1717
|
+
this._type = 'asset';
|
|
1718
|
+
}
|
|
1719
|
+
async connectedCallback() {
|
|
1720
|
+
await super.connectedCallback();
|
|
1721
|
+
this.material = this._material;
|
|
1387
1722
|
}
|
|
1388
1723
|
getInitialComponentData() {
|
|
1389
1724
|
return {
|
|
@@ -1433,6 +1768,23 @@ class RenderComponentElement extends ComponentElement {
|
|
|
1433
1768
|
get castShadows() {
|
|
1434
1769
|
return this._castShadows;
|
|
1435
1770
|
}
|
|
1771
|
+
/**
|
|
1772
|
+
* Sets the material of the render component.
|
|
1773
|
+
* @param value - The id of the material asset to use.
|
|
1774
|
+
*/
|
|
1775
|
+
set material(value) {
|
|
1776
|
+
this._material = value;
|
|
1777
|
+
if (this.component) {
|
|
1778
|
+
this.component.material = MaterialElement.get(value);
|
|
1779
|
+
}
|
|
1780
|
+
}
|
|
1781
|
+
/**
|
|
1782
|
+
* Gets the id of the material asset used by the render component.
|
|
1783
|
+
* @returns The id of the material asset.
|
|
1784
|
+
*/
|
|
1785
|
+
get material() {
|
|
1786
|
+
return this._material;
|
|
1787
|
+
}
|
|
1436
1788
|
/**
|
|
1437
1789
|
* Sets the receive shadows flag of the render component.
|
|
1438
1790
|
* @param value - The receive shadows flag.
|
|
@@ -1451,20 +1803,23 @@ class RenderComponentElement extends ComponentElement {
|
|
|
1451
1803
|
return this._receiveShadows;
|
|
1452
1804
|
}
|
|
1453
1805
|
static get observedAttributes() {
|
|
1454
|
-
return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
|
|
1806
|
+
return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
|
|
1455
1807
|
}
|
|
1456
1808
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1457
1809
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
1458
1810
|
switch (name) {
|
|
1459
|
-
case 'type':
|
|
1460
|
-
this.type = newValue;
|
|
1461
|
-
break;
|
|
1462
1811
|
case 'cast-shadows':
|
|
1463
1812
|
this.castShadows = newValue !== 'false';
|
|
1464
1813
|
break;
|
|
1814
|
+
case 'material':
|
|
1815
|
+
this.material = newValue;
|
|
1816
|
+
break;
|
|
1465
1817
|
case 'receive-shadows':
|
|
1466
1818
|
this.receiveShadows = newValue !== 'false';
|
|
1467
1819
|
break;
|
|
1820
|
+
case 'type':
|
|
1821
|
+
this.type = newValue;
|
|
1822
|
+
break;
|
|
1468
1823
|
}
|
|
1469
1824
|
}
|
|
1470
1825
|
}
|
|
@@ -1657,6 +2012,129 @@ class RigidBodyComponentElement extends ComponentElement {
|
|
|
1657
2012
|
}
|
|
1658
2013
|
customElements.define('pc-rigidbody', RigidBodyComponentElement);
|
|
1659
2014
|
|
|
2015
|
+
/**
|
|
2016
|
+
* Represents a screen component in the PlayCanvas engine.
|
|
2017
|
+
*
|
|
2018
|
+
* @category Components
|
|
2019
|
+
*/
|
|
2020
|
+
class ScreenComponentElement extends ComponentElement {
|
|
2021
|
+
constructor() {
|
|
2022
|
+
super('screen');
|
|
2023
|
+
this._screenSpace = false;
|
|
2024
|
+
this._resolution = new playcanvas.Vec2(640, 320);
|
|
2025
|
+
this._referenceResolution = new playcanvas.Vec2(640, 320);
|
|
2026
|
+
this._priority = 0;
|
|
2027
|
+
this._blend = false;
|
|
2028
|
+
this._scaleBlend = 0.5;
|
|
2029
|
+
}
|
|
2030
|
+
getInitialComponentData() {
|
|
2031
|
+
return {
|
|
2032
|
+
priority: this._priority,
|
|
2033
|
+
referenceResolution: this._referenceResolution,
|
|
2034
|
+
resolution: this._resolution,
|
|
2035
|
+
scaleBlend: this._scaleBlend,
|
|
2036
|
+
scaleMode: this._blend ? playcanvas.SCALEMODE_BLEND : playcanvas.SCALEMODE_NONE,
|
|
2037
|
+
screenSpace: this._screenSpace
|
|
2038
|
+
};
|
|
2039
|
+
}
|
|
2040
|
+
/**
|
|
2041
|
+
* Gets the screen component.
|
|
2042
|
+
* @returns The screen component.
|
|
2043
|
+
*/
|
|
2044
|
+
get component() {
|
|
2045
|
+
return super.component;
|
|
2046
|
+
}
|
|
2047
|
+
set priority(value) {
|
|
2048
|
+
this._priority = value;
|
|
2049
|
+
if (this.component) {
|
|
2050
|
+
this.component.priority = this._priority;
|
|
2051
|
+
}
|
|
2052
|
+
}
|
|
2053
|
+
get priority() {
|
|
2054
|
+
return this._priority;
|
|
2055
|
+
}
|
|
2056
|
+
set referenceResolution(value) {
|
|
2057
|
+
this._referenceResolution = value;
|
|
2058
|
+
if (this.component) {
|
|
2059
|
+
this.component.referenceResolution = this._referenceResolution;
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
get referenceResolution() {
|
|
2063
|
+
return this._referenceResolution;
|
|
2064
|
+
}
|
|
2065
|
+
set resolution(value) {
|
|
2066
|
+
this._resolution = value;
|
|
2067
|
+
if (this.component) {
|
|
2068
|
+
this.component.resolution = this._resolution;
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
get resolution() {
|
|
2072
|
+
return this._resolution;
|
|
2073
|
+
}
|
|
2074
|
+
set scaleBlend(value) {
|
|
2075
|
+
this._scaleBlend = value;
|
|
2076
|
+
if (this.component) {
|
|
2077
|
+
this.component.scaleBlend = this._scaleBlend;
|
|
2078
|
+
}
|
|
2079
|
+
}
|
|
2080
|
+
get scaleBlend() {
|
|
2081
|
+
return this._scaleBlend;
|
|
2082
|
+
}
|
|
2083
|
+
set blend(value) {
|
|
2084
|
+
this._blend = value;
|
|
2085
|
+
if (this.component) {
|
|
2086
|
+
this.component.scaleMode = this._blend ? playcanvas.SCALEMODE_BLEND : playcanvas.SCALEMODE_NONE;
|
|
2087
|
+
}
|
|
2088
|
+
}
|
|
2089
|
+
get blend() {
|
|
2090
|
+
return this._blend;
|
|
2091
|
+
}
|
|
2092
|
+
set screenSpace(value) {
|
|
2093
|
+
this._screenSpace = value;
|
|
2094
|
+
if (this.component) {
|
|
2095
|
+
this.component.screenSpace = this._screenSpace;
|
|
2096
|
+
}
|
|
2097
|
+
}
|
|
2098
|
+
get screenSpace() {
|
|
2099
|
+
return this._screenSpace;
|
|
2100
|
+
}
|
|
2101
|
+
static get observedAttributes() {
|
|
2102
|
+
return [
|
|
2103
|
+
...super.observedAttributes,
|
|
2104
|
+
'blend',
|
|
2105
|
+
'screen-space',
|
|
2106
|
+
'resolution',
|
|
2107
|
+
'reference-resolution',
|
|
2108
|
+
'priority',
|
|
2109
|
+
'scale-blend'
|
|
2110
|
+
];
|
|
2111
|
+
}
|
|
2112
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
2113
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
2114
|
+
switch (name) {
|
|
2115
|
+
case 'priority':
|
|
2116
|
+
this.priority = parseInt(newValue);
|
|
2117
|
+
break;
|
|
2118
|
+
case 'reference-resolution':
|
|
2119
|
+
this.referenceResolution = parseVec2(newValue);
|
|
2120
|
+
break;
|
|
2121
|
+
case 'resolution':
|
|
2122
|
+
this.resolution = parseVec2(newValue);
|
|
2123
|
+
break;
|
|
2124
|
+
case 'scale-blend':
|
|
2125
|
+
this.scaleBlend = parseFloat(newValue);
|
|
2126
|
+
break;
|
|
2127
|
+
case 'blend':
|
|
2128
|
+
this.blend = this.hasAttribute('blend');
|
|
2129
|
+
break;
|
|
2130
|
+
case 'screen-space':
|
|
2131
|
+
this.screenSpace = this.hasAttribute('screen-space');
|
|
2132
|
+
break;
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
}
|
|
2136
|
+
customElements.define('pc-screen', ScreenComponentElement);
|
|
2137
|
+
|
|
1660
2138
|
/**
|
|
1661
2139
|
* Represents a script component in the PlayCanvas engine.
|
|
1662
2140
|
*
|
|
@@ -1962,10 +2440,6 @@ class SoundSlotElement extends HTMLElement {
|
|
|
1962
2440
|
*/
|
|
1963
2441
|
this.soundSlot = null;
|
|
1964
2442
|
}
|
|
1965
|
-
getAsset() {
|
|
1966
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
1967
|
-
return assetElement.asset;
|
|
1968
|
-
}
|
|
1969
2443
|
async connectedCallback() {
|
|
1970
2444
|
const appElement = this.closest('pc-app');
|
|
1971
2445
|
if (!appElement) {
|
|
@@ -2007,7 +2481,7 @@ class SoundSlotElement extends HTMLElement {
|
|
|
2007
2481
|
var _a;
|
|
2008
2482
|
this._asset = value;
|
|
2009
2483
|
if (this.soundSlot) {
|
|
2010
|
-
const id = (_a =
|
|
2484
|
+
const id = (_a = AssetElement.get(value)) === null || _a === void 0 ? void 0 : _a.id;
|
|
2011
2485
|
if (id) {
|
|
2012
2486
|
this.soundSlot.asset = id;
|
|
2013
2487
|
}
|
|
@@ -2211,12 +2685,8 @@ class ModelElement extends HTMLElement {
|
|
|
2211
2685
|
this.asset = asset;
|
|
2212
2686
|
}
|
|
2213
2687
|
}
|
|
2214
|
-
getAsset() {
|
|
2215
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
2216
|
-
return assetElement.asset;
|
|
2217
|
-
}
|
|
2218
2688
|
_loadModel() {
|
|
2219
|
-
const asset = this.
|
|
2689
|
+
const asset = AssetElement.get(this._asset);
|
|
2220
2690
|
if (!asset) {
|
|
2221
2691
|
return;
|
|
2222
2692
|
}
|
|
@@ -2444,10 +2914,6 @@ class SkyElement extends HTMLElement {
|
|
|
2444
2914
|
this.asset = this.getAttribute('asset') || '';
|
|
2445
2915
|
this.solidColor = this.hasAttribute('solid-color');
|
|
2446
2916
|
}
|
|
2447
|
-
getAsset() {
|
|
2448
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
2449
|
-
return assetElement.asset;
|
|
2450
|
-
}
|
|
2451
2917
|
getScene() {
|
|
2452
2918
|
const appElement = this.closest('pc-app');
|
|
2453
2919
|
if (!appElement) {
|
|
@@ -2463,7 +2929,7 @@ class SkyElement extends HTMLElement {
|
|
|
2463
2929
|
this._asset = value;
|
|
2464
2930
|
const scene = this.getScene();
|
|
2465
2931
|
if (scene) {
|
|
2466
|
-
const asset =
|
|
2932
|
+
const asset = AssetElement.get(value);
|
|
2467
2933
|
if (asset) {
|
|
2468
2934
|
if (asset.resource) {
|
|
2469
2935
|
scene.envAtlas = asset.resource;
|
|
@@ -2557,11 +3023,13 @@ exports.EntityElement = EntityElement;
|
|
|
2557
3023
|
exports.GSplatComponentElement = GSplatComponentElement;
|
|
2558
3024
|
exports.LightComponentElement = LightComponentElement;
|
|
2559
3025
|
exports.ListenerComponentElement = ListenerComponentElement;
|
|
3026
|
+
exports.MaterialElement = MaterialElement;
|
|
2560
3027
|
exports.ModelElement = ModelElement;
|
|
2561
3028
|
exports.ModuleElement = ModuleElement;
|
|
2562
3029
|
exports.RenderComponentElement = RenderComponentElement;
|
|
2563
3030
|
exports.RigidBodyComponentElement = RigidBodyComponentElement;
|
|
2564
3031
|
exports.SceneElement = SceneElement;
|
|
3032
|
+
exports.ScreenComponentElement = ScreenComponentElement;
|
|
2565
3033
|
exports.ScriptComponentElement = ScriptComponentElement;
|
|
2566
3034
|
exports.ScriptElement = ScriptElement;
|
|
2567
3035
|
exports.SkyElement = SkyElement;
|