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