@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.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, Vec2, Vec3, Vec4, Entity, Asset, PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, StandardMaterial, SCALEMODE_BLEND, SCALEMODE_NONE, Quat, 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
|
|
@@ -220,7 +225,7 @@ class EntityElement extends HTMLElement {
|
|
|
220
225
|
const app = await appElement.getApplication();
|
|
221
226
|
// Create a new entity
|
|
222
227
|
this.entity = new Entity(this._name, app);
|
|
223
|
-
if (this.parentElement && this.parentElement.tagName === 'pc-entity' && this.parentElement.entity) {
|
|
228
|
+
if (this.parentElement && this.parentElement.tagName.toLowerCase() === 'pc-entity' && this.parentElement.entity) {
|
|
224
229
|
this.parentElement.entity.addChild(this.entity);
|
|
225
230
|
}
|
|
226
231
|
else {
|
|
@@ -455,6 +460,10 @@ class AssetElement extends HTMLElement {
|
|
|
455
460
|
get preload() {
|
|
456
461
|
return this._preload;
|
|
457
462
|
}
|
|
463
|
+
static get(id) {
|
|
464
|
+
const assetElement = document.querySelector(`pc-asset[id="${id}"]`);
|
|
465
|
+
return assetElement === null || assetElement === void 0 ? void 0 : assetElement.asset;
|
|
466
|
+
}
|
|
458
467
|
static get observedAttributes() {
|
|
459
468
|
return ['preload'];
|
|
460
469
|
}
|
|
@@ -576,21 +585,39 @@ class CameraComponentElement extends ComponentElement {
|
|
|
576
585
|
*/
|
|
577
586
|
constructor() {
|
|
578
587
|
super('camera');
|
|
579
|
-
this._clearColor = new Color(
|
|
588
|
+
this._clearColor = new Color(0.75, 0.75, 0.75, 1);
|
|
589
|
+
this._clearColorBuffer = true;
|
|
590
|
+
this._clearDepthBuffer = true;
|
|
591
|
+
this._clearStencilBuffer = false;
|
|
592
|
+
this._cullFaces = true;
|
|
580
593
|
this._farClip = 1000;
|
|
594
|
+
this._flipFaces = false;
|
|
581
595
|
this._fov = 45;
|
|
596
|
+
this._frustumCulling = true;
|
|
582
597
|
this._nearClip = 0.1;
|
|
583
598
|
this._orthographic = false;
|
|
584
599
|
this._orthoHeight = 10;
|
|
600
|
+
this._priority = 0;
|
|
601
|
+
this._rect = new Vec4(0, 0, 1, 1);
|
|
602
|
+
this._scissorRect = new Vec4(0, 0, 1, 1);
|
|
585
603
|
}
|
|
586
604
|
getInitialComponentData() {
|
|
587
605
|
return {
|
|
588
606
|
clearColor: this._clearColor,
|
|
607
|
+
clearColorBuffer: this._clearColorBuffer,
|
|
608
|
+
clearDepthBuffer: this._clearDepthBuffer,
|
|
609
|
+
clearStencilBuffer: this._clearStencilBuffer,
|
|
610
|
+
cullFaces: this._cullFaces,
|
|
589
611
|
farClip: this._farClip,
|
|
612
|
+
flipFaces: this._flipFaces,
|
|
590
613
|
fov: this._fov,
|
|
614
|
+
frustumCulling: this._frustumCulling,
|
|
591
615
|
nearClip: this._nearClip,
|
|
592
|
-
|
|
593
|
-
orthoHeight: this._orthoHeight
|
|
616
|
+
orthographic: this._orthographic,
|
|
617
|
+
orthoHeight: this._orthoHeight,
|
|
618
|
+
priority: this._priority,
|
|
619
|
+
rect: this._rect,
|
|
620
|
+
scissorRect: this._scissorRect
|
|
594
621
|
};
|
|
595
622
|
}
|
|
596
623
|
/**
|
|
@@ -617,6 +644,74 @@ class CameraComponentElement extends ComponentElement {
|
|
|
617
644
|
get clearColor() {
|
|
618
645
|
return this._clearColor;
|
|
619
646
|
}
|
|
647
|
+
/**
|
|
648
|
+
* Sets the clear color buffer of the camera.
|
|
649
|
+
* @param value - The clear color buffer.
|
|
650
|
+
*/
|
|
651
|
+
set clearColorBuffer(value) {
|
|
652
|
+
this._clearColorBuffer = value;
|
|
653
|
+
if (this.component) {
|
|
654
|
+
this.component.clearColorBuffer = value;
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
/**
|
|
658
|
+
* Gets the clear color buffer of the camera.
|
|
659
|
+
* @returns The clear color buffer.
|
|
660
|
+
*/
|
|
661
|
+
get clearColorBuffer() {
|
|
662
|
+
return this._clearColorBuffer;
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Sets the clear depth buffer of the camera.
|
|
666
|
+
* @param value - The clear depth buffer.
|
|
667
|
+
*/
|
|
668
|
+
set clearDepthBuffer(value) {
|
|
669
|
+
this._clearDepthBuffer = value;
|
|
670
|
+
if (this.component) {
|
|
671
|
+
this.component.clearDepthBuffer = value;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Gets the clear depth buffer of the camera.
|
|
676
|
+
* @returns The clear depth buffer.
|
|
677
|
+
*/
|
|
678
|
+
get clearDepthBuffer() {
|
|
679
|
+
return this._clearDepthBuffer;
|
|
680
|
+
}
|
|
681
|
+
/**
|
|
682
|
+
* Sets the clear stencil buffer of the camera.
|
|
683
|
+
* @param value - The clear stencil buffer.
|
|
684
|
+
*/
|
|
685
|
+
set clearStencilBuffer(value) {
|
|
686
|
+
this._clearStencilBuffer = value;
|
|
687
|
+
if (this.component) {
|
|
688
|
+
this.component.clearStencilBuffer = value;
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Gets the clear stencil buffer of the camera.
|
|
693
|
+
* @returns The clear stencil buffer.
|
|
694
|
+
*/
|
|
695
|
+
get clearStencilBuffer() {
|
|
696
|
+
return this._clearStencilBuffer;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Sets the cull faces of the camera.
|
|
700
|
+
* @param value - The cull faces.
|
|
701
|
+
*/
|
|
702
|
+
set cullFaces(value) {
|
|
703
|
+
this._cullFaces = value;
|
|
704
|
+
if (this.component) {
|
|
705
|
+
this.component.cullFaces = value;
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
/**
|
|
709
|
+
* Gets the cull faces of the camera.
|
|
710
|
+
* @returns The cull faces.
|
|
711
|
+
*/
|
|
712
|
+
get cullFaces() {
|
|
713
|
+
return this._cullFaces;
|
|
714
|
+
}
|
|
620
715
|
/**
|
|
621
716
|
* Sets the far clip distance of the camera.
|
|
622
717
|
* @param value - The far clip distance.
|
|
@@ -634,6 +729,23 @@ class CameraComponentElement extends ComponentElement {
|
|
|
634
729
|
get farClip() {
|
|
635
730
|
return this._farClip;
|
|
636
731
|
}
|
|
732
|
+
/**
|
|
733
|
+
* Sets the flip faces of the camera.
|
|
734
|
+
* @param value - The flip faces.
|
|
735
|
+
*/
|
|
736
|
+
set flipFaces(value) {
|
|
737
|
+
this._flipFaces = value;
|
|
738
|
+
if (this.component) {
|
|
739
|
+
this.component.flipFaces = value;
|
|
740
|
+
}
|
|
741
|
+
}
|
|
742
|
+
/**
|
|
743
|
+
* Gets the flip faces of the camera.
|
|
744
|
+
* @returns The flip faces.
|
|
745
|
+
*/
|
|
746
|
+
get flipFaces() {
|
|
747
|
+
return this._flipFaces;
|
|
748
|
+
}
|
|
637
749
|
/**
|
|
638
750
|
* Sets the field of view of the camera.
|
|
639
751
|
* @param value - The field of view.
|
|
@@ -651,6 +763,23 @@ class CameraComponentElement extends ComponentElement {
|
|
|
651
763
|
get fov() {
|
|
652
764
|
return this._fov;
|
|
653
765
|
}
|
|
766
|
+
/**
|
|
767
|
+
* Sets the frustum culling of the camera.
|
|
768
|
+
* @param value - The frustum culling.
|
|
769
|
+
*/
|
|
770
|
+
set frustumCulling(value) {
|
|
771
|
+
this._frustumCulling = value;
|
|
772
|
+
if (this.component) {
|
|
773
|
+
this.component.frustumCulling = value;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
/**
|
|
777
|
+
* Gets the frustum culling of the camera.
|
|
778
|
+
* @returns The frustum culling.
|
|
779
|
+
*/
|
|
780
|
+
get frustumCulling() {
|
|
781
|
+
return this._frustumCulling;
|
|
782
|
+
}
|
|
654
783
|
/**
|
|
655
784
|
* Sets the near clip distance of the camera.
|
|
656
785
|
* @param value - The near clip distance.
|
|
@@ -702,8 +831,76 @@ class CameraComponentElement extends ComponentElement {
|
|
|
702
831
|
get orthoHeight() {
|
|
703
832
|
return this._orthoHeight;
|
|
704
833
|
}
|
|
834
|
+
/**
|
|
835
|
+
* Sets the priority of the camera.
|
|
836
|
+
* @param value - The priority.
|
|
837
|
+
*/
|
|
838
|
+
set priority(value) {
|
|
839
|
+
this._priority = value;
|
|
840
|
+
if (this.component) {
|
|
841
|
+
this.component.priority = value;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
/**
|
|
845
|
+
* Gets the priority of the camera.
|
|
846
|
+
* @returns The priority.
|
|
847
|
+
*/
|
|
848
|
+
get priority() {
|
|
849
|
+
return this._priority;
|
|
850
|
+
}
|
|
851
|
+
/**
|
|
852
|
+
* Sets the rect of the camera.
|
|
853
|
+
* @param value - The rect.
|
|
854
|
+
*/
|
|
855
|
+
set rect(value) {
|
|
856
|
+
this._rect = value;
|
|
857
|
+
if (this.component) {
|
|
858
|
+
this.component.rect = value;
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
/**
|
|
862
|
+
* Gets the rect of the camera.
|
|
863
|
+
* @returns The rect.
|
|
864
|
+
*/
|
|
865
|
+
get rect() {
|
|
866
|
+
return this._rect;
|
|
867
|
+
}
|
|
868
|
+
/**
|
|
869
|
+
* Sets the scissor rect of the camera.
|
|
870
|
+
* @param value - The scissor rect.
|
|
871
|
+
*/
|
|
872
|
+
set scissorRect(value) {
|
|
873
|
+
this._scissorRect = value;
|
|
874
|
+
if (this.component) {
|
|
875
|
+
this.component.scissorRect = value;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Gets the scissor rect of the camera.
|
|
880
|
+
* @returns The scissor rect.
|
|
881
|
+
*/
|
|
882
|
+
get scissorRect() {
|
|
883
|
+
return this._scissorRect;
|
|
884
|
+
}
|
|
705
885
|
static get observedAttributes() {
|
|
706
|
-
return [
|
|
886
|
+
return [
|
|
887
|
+
...super.observedAttributes,
|
|
888
|
+
'clear-color',
|
|
889
|
+
'clear-color-buffer',
|
|
890
|
+
'clear-depth-buffer',
|
|
891
|
+
'clear-stencil-buffer',
|
|
892
|
+
'cull-faces',
|
|
893
|
+
'far-clip',
|
|
894
|
+
'flip-faces',
|
|
895
|
+
'fov',
|
|
896
|
+
'frustum-culling',
|
|
897
|
+
'near-clip',
|
|
898
|
+
'orthographic',
|
|
899
|
+
'ortho-height',
|
|
900
|
+
'priority',
|
|
901
|
+
'rect',
|
|
902
|
+
'scissor-rect'
|
|
903
|
+
];
|
|
707
904
|
}
|
|
708
905
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
709
906
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
@@ -711,12 +908,30 @@ class CameraComponentElement extends ComponentElement {
|
|
|
711
908
|
case 'clear-color':
|
|
712
909
|
this.clearColor = parseColor(newValue);
|
|
713
910
|
break;
|
|
911
|
+
case 'clear-color-buffer':
|
|
912
|
+
this.clearColorBuffer = newValue !== 'false';
|
|
913
|
+
break;
|
|
914
|
+
case 'clear-depth-buffer':
|
|
915
|
+
this.clearDepthBuffer = newValue !== 'false';
|
|
916
|
+
break;
|
|
917
|
+
case 'clear-stencil-buffer':
|
|
918
|
+
this.clearStencilBuffer = newValue !== 'false';
|
|
919
|
+
break;
|
|
920
|
+
case 'cull-faces':
|
|
921
|
+
this.cullFaces = newValue !== 'false';
|
|
922
|
+
break;
|
|
714
923
|
case 'far-clip':
|
|
715
924
|
this.farClip = parseFloat(newValue);
|
|
716
925
|
break;
|
|
926
|
+
case 'flip-faces':
|
|
927
|
+
this.flipFaces = newValue !== 'true';
|
|
928
|
+
break;
|
|
717
929
|
case 'fov':
|
|
718
930
|
this.fov = parseFloat(newValue);
|
|
719
931
|
break;
|
|
932
|
+
case 'frustum-culling':
|
|
933
|
+
this.frustumCulling = newValue !== 'false';
|
|
934
|
+
break;
|
|
720
935
|
case 'near-clip':
|
|
721
936
|
this.nearClip = parseFloat(newValue);
|
|
722
937
|
break;
|
|
@@ -726,6 +941,15 @@ class CameraComponentElement extends ComponentElement {
|
|
|
726
941
|
case 'ortho-height':
|
|
727
942
|
this.orthoHeight = parseFloat(newValue);
|
|
728
943
|
break;
|
|
944
|
+
case 'priority':
|
|
945
|
+
this.priority = parseFloat(newValue);
|
|
946
|
+
break;
|
|
947
|
+
case 'rect':
|
|
948
|
+
this.rect = parseVec4(newValue);
|
|
949
|
+
break;
|
|
950
|
+
case 'scissor-rect':
|
|
951
|
+
this.scissorRect = parseVec4(newValue);
|
|
952
|
+
break;
|
|
729
953
|
}
|
|
730
954
|
}
|
|
731
955
|
}
|
|
@@ -873,16 +1097,12 @@ class ElementComponentElement extends ComponentElement {
|
|
|
873
1097
|
await super.connectedCallback();
|
|
874
1098
|
this.component._text._material.useFog = true;
|
|
875
1099
|
}
|
|
876
|
-
getAsset() {
|
|
877
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
878
|
-
return assetElement.asset;
|
|
879
|
-
}
|
|
880
1100
|
getInitialComponentData() {
|
|
881
1101
|
return {
|
|
882
1102
|
anchor: this._anchor,
|
|
883
1103
|
autoWidth: this._autoWidth,
|
|
884
1104
|
color: this._color,
|
|
885
|
-
fontAsset: this.
|
|
1105
|
+
fontAsset: AssetElement.get(this._asset).id,
|
|
886
1106
|
fontSize: this._fontSize,
|
|
887
1107
|
lineHeight: this._lineHeight,
|
|
888
1108
|
pivot: this._pivot,
|
|
@@ -910,7 +1130,7 @@ class ElementComponentElement extends ComponentElement {
|
|
|
910
1130
|
}
|
|
911
1131
|
set asset(value) {
|
|
912
1132
|
this._asset = value;
|
|
913
|
-
const asset =
|
|
1133
|
+
const asset = AssetElement.get(value);
|
|
914
1134
|
if (this.component && asset) {
|
|
915
1135
|
this.component.fontAsset = asset.id;
|
|
916
1136
|
}
|
|
@@ -1061,13 +1281,9 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
1061
1281
|
super('gsplat');
|
|
1062
1282
|
this._asset = '';
|
|
1063
1283
|
}
|
|
1064
|
-
getAsset() {
|
|
1065
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
1066
|
-
return assetElement.asset;
|
|
1067
|
-
}
|
|
1068
1284
|
getInitialComponentData() {
|
|
1069
1285
|
return {
|
|
1070
|
-
asset: this.
|
|
1286
|
+
asset: AssetElement.get(this._asset)
|
|
1071
1287
|
};
|
|
1072
1288
|
}
|
|
1073
1289
|
/**
|
|
@@ -1079,7 +1295,7 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
1079
1295
|
}
|
|
1080
1296
|
set asset(value) {
|
|
1081
1297
|
this._asset = value;
|
|
1082
|
-
const asset =
|
|
1298
|
+
const asset = AssetElement.get(value);
|
|
1083
1299
|
if (this.component && asset) {
|
|
1084
1300
|
this.component.asset = asset;
|
|
1085
1301
|
}
|
|
@@ -1371,6 +1587,120 @@ class LightComponentElement extends ComponentElement {
|
|
|
1371
1587
|
}
|
|
1372
1588
|
customElements.define('pc-light', LightComponentElement);
|
|
1373
1589
|
|
|
1590
|
+
/**
|
|
1591
|
+
* Represents a material in the PlayCanvas engine.
|
|
1592
|
+
*/
|
|
1593
|
+
class MaterialElement extends HTMLElement {
|
|
1594
|
+
constructor() {
|
|
1595
|
+
super(...arguments);
|
|
1596
|
+
this._diffuse = new Color(1, 1, 1);
|
|
1597
|
+
this._diffuseMap = '';
|
|
1598
|
+
this._metalnessMap = '';
|
|
1599
|
+
this._normalMap = '';
|
|
1600
|
+
this._roughnessMap = '';
|
|
1601
|
+
this.material = null;
|
|
1602
|
+
}
|
|
1603
|
+
createMaterial() {
|
|
1604
|
+
this.material = new StandardMaterial();
|
|
1605
|
+
this.material.glossInvert = true;
|
|
1606
|
+
this.material.useMetalness = true;
|
|
1607
|
+
this.material.diffuse = this._diffuse;
|
|
1608
|
+
this.diffuseMap = this._diffuseMap;
|
|
1609
|
+
this.metalnessMap = this._metalnessMap;
|
|
1610
|
+
this.normalMap = this._normalMap;
|
|
1611
|
+
this.roughnessMap = this._roughnessMap;
|
|
1612
|
+
this.material.update();
|
|
1613
|
+
}
|
|
1614
|
+
disconnectedCallback() {
|
|
1615
|
+
if (this.material) {
|
|
1616
|
+
this.material.destroy();
|
|
1617
|
+
this.material = null;
|
|
1618
|
+
}
|
|
1619
|
+
}
|
|
1620
|
+
setMap(map, property) {
|
|
1621
|
+
if (this.material) {
|
|
1622
|
+
const asset = AssetElement.get(map);
|
|
1623
|
+
if (asset) {
|
|
1624
|
+
if (asset.loaded) {
|
|
1625
|
+
this.material[property] = asset.resource;
|
|
1626
|
+
this.material[property].anisotropy = 4;
|
|
1627
|
+
}
|
|
1628
|
+
else {
|
|
1629
|
+
asset.once('load', () => {
|
|
1630
|
+
this.material[property] = asset.resource;
|
|
1631
|
+
this.material[property].anisotropy = 4;
|
|
1632
|
+
this.material.update();
|
|
1633
|
+
});
|
|
1634
|
+
}
|
|
1635
|
+
}
|
|
1636
|
+
}
|
|
1637
|
+
}
|
|
1638
|
+
set diffuse(value) {
|
|
1639
|
+
this._diffuse = value;
|
|
1640
|
+
if (this.material) {
|
|
1641
|
+
this.material.diffuse = value;
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
get diffuse() {
|
|
1645
|
+
return this._diffuse;
|
|
1646
|
+
}
|
|
1647
|
+
set diffuseMap(value) {
|
|
1648
|
+
this._diffuseMap = value;
|
|
1649
|
+
this.setMap(value, 'diffuseMap');
|
|
1650
|
+
}
|
|
1651
|
+
get diffuseMap() {
|
|
1652
|
+
return this._diffuseMap;
|
|
1653
|
+
}
|
|
1654
|
+
set metalnessMap(value) {
|
|
1655
|
+
this._metalnessMap = value;
|
|
1656
|
+
this.setMap(value, 'metalnessMap');
|
|
1657
|
+
}
|
|
1658
|
+
get metalnessMap() {
|
|
1659
|
+
return this._metalnessMap;
|
|
1660
|
+
}
|
|
1661
|
+
set normalMap(value) {
|
|
1662
|
+
this._normalMap = value;
|
|
1663
|
+
this.setMap(value, 'normalMap');
|
|
1664
|
+
}
|
|
1665
|
+
get normalMap() {
|
|
1666
|
+
return this._normalMap;
|
|
1667
|
+
}
|
|
1668
|
+
set roughnessMap(value) {
|
|
1669
|
+
this._roughnessMap = value;
|
|
1670
|
+
this.setMap(value, 'glossMap');
|
|
1671
|
+
}
|
|
1672
|
+
get roughnessMap() {
|
|
1673
|
+
return this._roughnessMap;
|
|
1674
|
+
}
|
|
1675
|
+
static get(id) {
|
|
1676
|
+
const materialElement = document.querySelector(`pc-material[id="${id}"]`);
|
|
1677
|
+
return materialElement === null || materialElement === void 0 ? void 0 : materialElement.material;
|
|
1678
|
+
}
|
|
1679
|
+
static get observedAttributes() {
|
|
1680
|
+
return ['diffuse', 'diffuse-map', 'metalness-map', 'normal-map', 'roughness-map'];
|
|
1681
|
+
}
|
|
1682
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1683
|
+
switch (name) {
|
|
1684
|
+
case 'diffuse':
|
|
1685
|
+
this.diffuse = parseColor(newValue);
|
|
1686
|
+
break;
|
|
1687
|
+
case 'diffuse-map':
|
|
1688
|
+
this.diffuseMap = newValue;
|
|
1689
|
+
break;
|
|
1690
|
+
case 'metalness-map':
|
|
1691
|
+
this.metalnessMap = newValue;
|
|
1692
|
+
break;
|
|
1693
|
+
case 'normal-map':
|
|
1694
|
+
this.normalMap = newValue;
|
|
1695
|
+
break;
|
|
1696
|
+
case 'roughness-map':
|
|
1697
|
+
this.roughnessMap = newValue;
|
|
1698
|
+
break;
|
|
1699
|
+
}
|
|
1700
|
+
}
|
|
1701
|
+
}
|
|
1702
|
+
customElements.define('pc-material', MaterialElement);
|
|
1703
|
+
|
|
1374
1704
|
/**
|
|
1375
1705
|
* Represents a render component in the PlayCanvas engine.
|
|
1376
1706
|
*
|
|
@@ -1379,9 +1709,14 @@ customElements.define('pc-light', LightComponentElement);
|
|
|
1379
1709
|
class RenderComponentElement extends ComponentElement {
|
|
1380
1710
|
constructor() {
|
|
1381
1711
|
super('render');
|
|
1382
|
-
this._type = 'asset';
|
|
1383
1712
|
this._castShadows = true;
|
|
1713
|
+
this._material = '';
|
|
1384
1714
|
this._receiveShadows = true;
|
|
1715
|
+
this._type = 'asset';
|
|
1716
|
+
}
|
|
1717
|
+
async connectedCallback() {
|
|
1718
|
+
await super.connectedCallback();
|
|
1719
|
+
this.material = this._material;
|
|
1385
1720
|
}
|
|
1386
1721
|
getInitialComponentData() {
|
|
1387
1722
|
return {
|
|
@@ -1431,6 +1766,23 @@ class RenderComponentElement extends ComponentElement {
|
|
|
1431
1766
|
get castShadows() {
|
|
1432
1767
|
return this._castShadows;
|
|
1433
1768
|
}
|
|
1769
|
+
/**
|
|
1770
|
+
* Sets the material of the render component.
|
|
1771
|
+
* @param value - The id of the material asset to use.
|
|
1772
|
+
*/
|
|
1773
|
+
set material(value) {
|
|
1774
|
+
this._material = value;
|
|
1775
|
+
if (this.component) {
|
|
1776
|
+
this.component.material = MaterialElement.get(value);
|
|
1777
|
+
}
|
|
1778
|
+
}
|
|
1779
|
+
/**
|
|
1780
|
+
* Gets the id of the material asset used by the render component.
|
|
1781
|
+
* @returns The id of the material asset.
|
|
1782
|
+
*/
|
|
1783
|
+
get material() {
|
|
1784
|
+
return this._material;
|
|
1785
|
+
}
|
|
1434
1786
|
/**
|
|
1435
1787
|
* Sets the receive shadows flag of the render component.
|
|
1436
1788
|
* @param value - The receive shadows flag.
|
|
@@ -1449,20 +1801,23 @@ class RenderComponentElement extends ComponentElement {
|
|
|
1449
1801
|
return this._receiveShadows;
|
|
1450
1802
|
}
|
|
1451
1803
|
static get observedAttributes() {
|
|
1452
|
-
return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
|
|
1804
|
+
return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
|
|
1453
1805
|
}
|
|
1454
1806
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
1455
1807
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
1456
1808
|
switch (name) {
|
|
1457
|
-
case 'type':
|
|
1458
|
-
this.type = newValue;
|
|
1459
|
-
break;
|
|
1460
1809
|
case 'cast-shadows':
|
|
1461
1810
|
this.castShadows = newValue !== 'false';
|
|
1462
1811
|
break;
|
|
1812
|
+
case 'material':
|
|
1813
|
+
this.material = newValue;
|
|
1814
|
+
break;
|
|
1463
1815
|
case 'receive-shadows':
|
|
1464
1816
|
this.receiveShadows = newValue !== 'false';
|
|
1465
1817
|
break;
|
|
1818
|
+
case 'type':
|
|
1819
|
+
this.type = newValue;
|
|
1820
|
+
break;
|
|
1466
1821
|
}
|
|
1467
1822
|
}
|
|
1468
1823
|
}
|
|
@@ -1655,6 +2010,129 @@ class RigidBodyComponentElement extends ComponentElement {
|
|
|
1655
2010
|
}
|
|
1656
2011
|
customElements.define('pc-rigidbody', RigidBodyComponentElement);
|
|
1657
2012
|
|
|
2013
|
+
/**
|
|
2014
|
+
* Represents a screen component in the PlayCanvas engine.
|
|
2015
|
+
*
|
|
2016
|
+
* @category Components
|
|
2017
|
+
*/
|
|
2018
|
+
class ScreenComponentElement extends ComponentElement {
|
|
2019
|
+
constructor() {
|
|
2020
|
+
super('screen');
|
|
2021
|
+
this._screenSpace = false;
|
|
2022
|
+
this._resolution = new Vec2(640, 320);
|
|
2023
|
+
this._referenceResolution = new Vec2(640, 320);
|
|
2024
|
+
this._priority = 0;
|
|
2025
|
+
this._blend = false;
|
|
2026
|
+
this._scaleBlend = 0.5;
|
|
2027
|
+
}
|
|
2028
|
+
getInitialComponentData() {
|
|
2029
|
+
return {
|
|
2030
|
+
priority: this._priority,
|
|
2031
|
+
referenceResolution: this._referenceResolution,
|
|
2032
|
+
resolution: this._resolution,
|
|
2033
|
+
scaleBlend: this._scaleBlend,
|
|
2034
|
+
scaleMode: this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE,
|
|
2035
|
+
screenSpace: this._screenSpace
|
|
2036
|
+
};
|
|
2037
|
+
}
|
|
2038
|
+
/**
|
|
2039
|
+
* Gets the screen component.
|
|
2040
|
+
* @returns The screen component.
|
|
2041
|
+
*/
|
|
2042
|
+
get component() {
|
|
2043
|
+
return super.component;
|
|
2044
|
+
}
|
|
2045
|
+
set priority(value) {
|
|
2046
|
+
this._priority = value;
|
|
2047
|
+
if (this.component) {
|
|
2048
|
+
this.component.priority = this._priority;
|
|
2049
|
+
}
|
|
2050
|
+
}
|
|
2051
|
+
get priority() {
|
|
2052
|
+
return this._priority;
|
|
2053
|
+
}
|
|
2054
|
+
set referenceResolution(value) {
|
|
2055
|
+
this._referenceResolution = value;
|
|
2056
|
+
if (this.component) {
|
|
2057
|
+
this.component.referenceResolution = this._referenceResolution;
|
|
2058
|
+
}
|
|
2059
|
+
}
|
|
2060
|
+
get referenceResolution() {
|
|
2061
|
+
return this._referenceResolution;
|
|
2062
|
+
}
|
|
2063
|
+
set resolution(value) {
|
|
2064
|
+
this._resolution = value;
|
|
2065
|
+
if (this.component) {
|
|
2066
|
+
this.component.resolution = this._resolution;
|
|
2067
|
+
}
|
|
2068
|
+
}
|
|
2069
|
+
get resolution() {
|
|
2070
|
+
return this._resolution;
|
|
2071
|
+
}
|
|
2072
|
+
set scaleBlend(value) {
|
|
2073
|
+
this._scaleBlend = value;
|
|
2074
|
+
if (this.component) {
|
|
2075
|
+
this.component.scaleBlend = this._scaleBlend;
|
|
2076
|
+
}
|
|
2077
|
+
}
|
|
2078
|
+
get scaleBlend() {
|
|
2079
|
+
return this._scaleBlend;
|
|
2080
|
+
}
|
|
2081
|
+
set blend(value) {
|
|
2082
|
+
this._blend = value;
|
|
2083
|
+
if (this.component) {
|
|
2084
|
+
this.component.scaleMode = this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE;
|
|
2085
|
+
}
|
|
2086
|
+
}
|
|
2087
|
+
get blend() {
|
|
2088
|
+
return this._blend;
|
|
2089
|
+
}
|
|
2090
|
+
set screenSpace(value) {
|
|
2091
|
+
this._screenSpace = value;
|
|
2092
|
+
if (this.component) {
|
|
2093
|
+
this.component.screenSpace = this._screenSpace;
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
get screenSpace() {
|
|
2097
|
+
return this._screenSpace;
|
|
2098
|
+
}
|
|
2099
|
+
static get observedAttributes() {
|
|
2100
|
+
return [
|
|
2101
|
+
...super.observedAttributes,
|
|
2102
|
+
'blend',
|
|
2103
|
+
'screen-space',
|
|
2104
|
+
'resolution',
|
|
2105
|
+
'reference-resolution',
|
|
2106
|
+
'priority',
|
|
2107
|
+
'scale-blend'
|
|
2108
|
+
];
|
|
2109
|
+
}
|
|
2110
|
+
attributeChangedCallback(name, _oldValue, newValue) {
|
|
2111
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
2112
|
+
switch (name) {
|
|
2113
|
+
case 'priority':
|
|
2114
|
+
this.priority = parseInt(newValue);
|
|
2115
|
+
break;
|
|
2116
|
+
case 'reference-resolution':
|
|
2117
|
+
this.referenceResolution = parseVec2(newValue);
|
|
2118
|
+
break;
|
|
2119
|
+
case 'resolution':
|
|
2120
|
+
this.resolution = parseVec2(newValue);
|
|
2121
|
+
break;
|
|
2122
|
+
case 'scale-blend':
|
|
2123
|
+
this.scaleBlend = parseFloat(newValue);
|
|
2124
|
+
break;
|
|
2125
|
+
case 'blend':
|
|
2126
|
+
this.blend = this.hasAttribute('blend');
|
|
2127
|
+
break;
|
|
2128
|
+
case 'screen-space':
|
|
2129
|
+
this.screenSpace = this.hasAttribute('screen-space');
|
|
2130
|
+
break;
|
|
2131
|
+
}
|
|
2132
|
+
}
|
|
2133
|
+
}
|
|
2134
|
+
customElements.define('pc-screen', ScreenComponentElement);
|
|
2135
|
+
|
|
1658
2136
|
/**
|
|
1659
2137
|
* Represents a script component in the PlayCanvas engine.
|
|
1660
2138
|
*
|
|
@@ -1960,10 +2438,6 @@ class SoundSlotElement extends HTMLElement {
|
|
|
1960
2438
|
*/
|
|
1961
2439
|
this.soundSlot = null;
|
|
1962
2440
|
}
|
|
1963
|
-
getAsset() {
|
|
1964
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
1965
|
-
return assetElement.asset;
|
|
1966
|
-
}
|
|
1967
2441
|
async connectedCallback() {
|
|
1968
2442
|
const appElement = this.closest('pc-app');
|
|
1969
2443
|
if (!appElement) {
|
|
@@ -2005,7 +2479,7 @@ class SoundSlotElement extends HTMLElement {
|
|
|
2005
2479
|
var _a;
|
|
2006
2480
|
this._asset = value;
|
|
2007
2481
|
if (this.soundSlot) {
|
|
2008
|
-
const id = (_a =
|
|
2482
|
+
const id = (_a = AssetElement.get(value)) === null || _a === void 0 ? void 0 : _a.id;
|
|
2009
2483
|
if (id) {
|
|
2010
2484
|
this.soundSlot.asset = id;
|
|
2011
2485
|
}
|
|
@@ -2209,12 +2683,8 @@ class ModelElement extends HTMLElement {
|
|
|
2209
2683
|
this.asset = asset;
|
|
2210
2684
|
}
|
|
2211
2685
|
}
|
|
2212
|
-
getAsset() {
|
|
2213
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
2214
|
-
return assetElement.asset;
|
|
2215
|
-
}
|
|
2216
2686
|
_loadModel() {
|
|
2217
|
-
const asset = this.
|
|
2687
|
+
const asset = AssetElement.get(this._asset);
|
|
2218
2688
|
if (!asset) {
|
|
2219
2689
|
return;
|
|
2220
2690
|
}
|
|
@@ -2442,10 +2912,6 @@ class SkyElement extends HTMLElement {
|
|
|
2442
2912
|
this.asset = this.getAttribute('asset') || '';
|
|
2443
2913
|
this.solidColor = this.hasAttribute('solid-color');
|
|
2444
2914
|
}
|
|
2445
|
-
getAsset() {
|
|
2446
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`);
|
|
2447
|
-
return assetElement.asset;
|
|
2448
|
-
}
|
|
2449
2915
|
getScene() {
|
|
2450
2916
|
const appElement = this.closest('pc-app');
|
|
2451
2917
|
if (!appElement) {
|
|
@@ -2461,7 +2927,7 @@ class SkyElement extends HTMLElement {
|
|
|
2461
2927
|
this._asset = value;
|
|
2462
2928
|
const scene = this.getScene();
|
|
2463
2929
|
if (scene) {
|
|
2464
|
-
const asset =
|
|
2930
|
+
const asset = AssetElement.get(value);
|
|
2465
2931
|
if (asset) {
|
|
2466
2932
|
if (asset.resource) {
|
|
2467
2933
|
scene.envAtlas = asset.resource;
|
|
@@ -2545,5 +3011,5 @@ class SkyElement extends HTMLElement {
|
|
|
2545
3011
|
}
|
|
2546
3012
|
customElements.define('pc-sky', SkyElement);
|
|
2547
3013
|
|
|
2548
|
-
export { AppElement, AssetElement, CameraComponentElement, CollisionComponentElement, ComponentElement, ElementComponentElement, EntityElement, GSplatComponentElement, LightComponentElement, ListenerComponentElement, ModelElement, ModuleElement, RenderComponentElement, RigidBodyComponentElement, SceneElement, ScriptComponentElement, ScriptElement, SkyElement, SoundComponentElement, SoundSlotElement };
|
|
3014
|
+
export { AppElement, AssetElement, CameraComponentElement, CollisionComponentElement, ComponentElement, ElementComponentElement, EntityElement, GSplatComponentElement, LightComponentElement, ListenerComponentElement, MaterialElement, ModelElement, ModuleElement, RenderComponentElement, RigidBodyComponentElement, SceneElement, ScreenComponentElement, ScriptComponentElement, ScriptElement, SkyElement, SoundComponentElement, SoundSlotElement };
|
|
2549
3015
|
//# sourceMappingURL=pwc.mjs.map
|