@playcanvas/web-components 0.1.1 → 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 +260 -1
- 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/script-component.d.ts +25 -0
- package/dist/components/script.d.ts +12 -6
- 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 +620 -91
- package/dist/pwc.cjs.map +1 -1
- package/dist/pwc.js +620 -91
- 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 +620 -93
- 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/script-component.ts +120 -1
- package/src/components/script.ts +23 -65
- package/src/components/sound-component.ts +1 -1
- package/src/components/sound-slot.ts +2 -7
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, CameraComponent, Color } from 'playcanvas';
|
|
1
|
+
import { PROJECTION_ORTHOGRAPHIC, PROJECTION_PERSPECTIVE, CameraComponent, Color, Vec4 } from 'playcanvas';
|
|
2
2
|
|
|
3
3
|
import { ComponentElement } from './component';
|
|
4
|
-
import { parseColor } from '../utils';
|
|
4
|
+
import { parseColor, parseVec4 } from '../utils';
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* Represents a camera component in the PlayCanvas engine.
|
|
@@ -9,18 +9,36 @@ import { parseColor } from '../utils';
|
|
|
9
9
|
* @category Components
|
|
10
10
|
*/
|
|
11
11
|
class CameraComponentElement extends ComponentElement {
|
|
12
|
-
private _clearColor = new Color(
|
|
12
|
+
private _clearColor = new Color(0.75, 0.75, 0.75, 1);
|
|
13
|
+
|
|
14
|
+
private _clearColorBuffer = true;
|
|
15
|
+
|
|
16
|
+
private _clearDepthBuffer = true;
|
|
17
|
+
|
|
18
|
+
private _clearStencilBuffer = false;
|
|
19
|
+
|
|
20
|
+
private _cullFaces = true;
|
|
13
21
|
|
|
14
22
|
private _farClip = 1000;
|
|
15
23
|
|
|
24
|
+
private _flipFaces = false;
|
|
25
|
+
|
|
16
26
|
private _fov = 45;
|
|
17
27
|
|
|
28
|
+
private _frustumCulling = true;
|
|
29
|
+
|
|
18
30
|
private _nearClip = 0.1;
|
|
19
31
|
|
|
20
32
|
private _orthographic = false;
|
|
21
33
|
|
|
22
34
|
private _orthoHeight = 10;
|
|
23
35
|
|
|
36
|
+
private _priority = 0;
|
|
37
|
+
|
|
38
|
+
private _rect = new Vec4(0, 0, 1, 1);
|
|
39
|
+
|
|
40
|
+
private _scissorRect = new Vec4(0, 0, 1, 1);
|
|
41
|
+
|
|
24
42
|
/**
|
|
25
43
|
* Creates a new CameraComponentElement.
|
|
26
44
|
*/
|
|
@@ -31,11 +49,20 @@ class CameraComponentElement extends ComponentElement {
|
|
|
31
49
|
getInitialComponentData() {
|
|
32
50
|
return {
|
|
33
51
|
clearColor: this._clearColor,
|
|
52
|
+
clearColorBuffer: this._clearColorBuffer,
|
|
53
|
+
clearDepthBuffer: this._clearDepthBuffer,
|
|
54
|
+
clearStencilBuffer: this._clearStencilBuffer,
|
|
55
|
+
cullFaces: this._cullFaces,
|
|
34
56
|
farClip: this._farClip,
|
|
57
|
+
flipFaces: this._flipFaces,
|
|
35
58
|
fov: this._fov,
|
|
59
|
+
frustumCulling: this._frustumCulling,
|
|
36
60
|
nearClip: this._nearClip,
|
|
37
|
-
|
|
38
|
-
orthoHeight: this._orthoHeight
|
|
61
|
+
orthographic: this._orthographic,
|
|
62
|
+
orthoHeight: this._orthoHeight,
|
|
63
|
+
priority: this._priority,
|
|
64
|
+
rect: this._rect,
|
|
65
|
+
scissorRect: this._scissorRect
|
|
39
66
|
};
|
|
40
67
|
}
|
|
41
68
|
|
|
@@ -66,6 +93,82 @@ class CameraComponentElement extends ComponentElement {
|
|
|
66
93
|
return this._clearColor;
|
|
67
94
|
}
|
|
68
95
|
|
|
96
|
+
/**
|
|
97
|
+
* Sets the clear color buffer of the camera.
|
|
98
|
+
* @param value - The clear color buffer.
|
|
99
|
+
*/
|
|
100
|
+
set clearColorBuffer(value: boolean) {
|
|
101
|
+
this._clearColorBuffer = value;
|
|
102
|
+
if (this.component) {
|
|
103
|
+
this.component.clearColorBuffer = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Gets the clear color buffer of the camera.
|
|
109
|
+
* @returns The clear color buffer.
|
|
110
|
+
*/
|
|
111
|
+
get clearColorBuffer(): boolean {
|
|
112
|
+
return this._clearColorBuffer;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Sets the clear depth buffer of the camera.
|
|
117
|
+
* @param value - The clear depth buffer.
|
|
118
|
+
*/
|
|
119
|
+
set clearDepthBuffer(value: boolean) {
|
|
120
|
+
this._clearDepthBuffer = value;
|
|
121
|
+
if (this.component) {
|
|
122
|
+
this.component.clearDepthBuffer = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Gets the clear depth buffer of the camera.
|
|
128
|
+
* @returns The clear depth buffer.
|
|
129
|
+
*/
|
|
130
|
+
get clearDepthBuffer(): boolean {
|
|
131
|
+
return this._clearDepthBuffer;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Sets the clear stencil buffer of the camera.
|
|
136
|
+
* @param value - The clear stencil buffer.
|
|
137
|
+
*/
|
|
138
|
+
set clearStencilBuffer(value: boolean) {
|
|
139
|
+
this._clearStencilBuffer = value;
|
|
140
|
+
if (this.component) {
|
|
141
|
+
this.component.clearStencilBuffer = value;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* Gets the clear stencil buffer of the camera.
|
|
147
|
+
* @returns The clear stencil buffer.
|
|
148
|
+
*/
|
|
149
|
+
get clearStencilBuffer(): boolean {
|
|
150
|
+
return this._clearStencilBuffer;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Sets the cull faces of the camera.
|
|
155
|
+
* @param value - The cull faces.
|
|
156
|
+
*/
|
|
157
|
+
set cullFaces(value: boolean) {
|
|
158
|
+
this._cullFaces = value;
|
|
159
|
+
if (this.component) {
|
|
160
|
+
this.component.cullFaces = value;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Gets the cull faces of the camera.
|
|
166
|
+
* @returns The cull faces.
|
|
167
|
+
*/
|
|
168
|
+
get cullFaces(): boolean {
|
|
169
|
+
return this._cullFaces;
|
|
170
|
+
}
|
|
171
|
+
|
|
69
172
|
/**
|
|
70
173
|
* Sets the far clip distance of the camera.
|
|
71
174
|
* @param value - The far clip distance.
|
|
@@ -85,6 +188,25 @@ class CameraComponentElement extends ComponentElement {
|
|
|
85
188
|
return this._farClip;
|
|
86
189
|
}
|
|
87
190
|
|
|
191
|
+
/**
|
|
192
|
+
* Sets the flip faces of the camera.
|
|
193
|
+
* @param value - The flip faces.
|
|
194
|
+
*/
|
|
195
|
+
set flipFaces(value: boolean) {
|
|
196
|
+
this._flipFaces = value;
|
|
197
|
+
if (this.component) {
|
|
198
|
+
this.component.flipFaces = value;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Gets the flip faces of the camera.
|
|
204
|
+
* @returns The flip faces.
|
|
205
|
+
*/
|
|
206
|
+
get flipFaces(): boolean {
|
|
207
|
+
return this._flipFaces;
|
|
208
|
+
}
|
|
209
|
+
|
|
88
210
|
/**
|
|
89
211
|
* Sets the field of view of the camera.
|
|
90
212
|
* @param value - The field of view.
|
|
@@ -104,6 +226,25 @@ class CameraComponentElement extends ComponentElement {
|
|
|
104
226
|
return this._fov;
|
|
105
227
|
}
|
|
106
228
|
|
|
229
|
+
/**
|
|
230
|
+
* Sets the frustum culling of the camera.
|
|
231
|
+
* @param value - The frustum culling.
|
|
232
|
+
*/
|
|
233
|
+
set frustumCulling(value: boolean) {
|
|
234
|
+
this._frustumCulling = value;
|
|
235
|
+
if (this.component) {
|
|
236
|
+
this.component.frustumCulling = value;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Gets the frustum culling of the camera.
|
|
242
|
+
* @returns The frustum culling.
|
|
243
|
+
*/
|
|
244
|
+
get frustumCulling(): boolean {
|
|
245
|
+
return this._frustumCulling;
|
|
246
|
+
}
|
|
247
|
+
|
|
107
248
|
/**
|
|
108
249
|
* Sets the near clip distance of the camera.
|
|
109
250
|
* @param value - The near clip distance.
|
|
@@ -161,8 +302,82 @@ class CameraComponentElement extends ComponentElement {
|
|
|
161
302
|
return this._orthoHeight;
|
|
162
303
|
}
|
|
163
304
|
|
|
305
|
+
/**
|
|
306
|
+
* Sets the priority of the camera.
|
|
307
|
+
* @param value - The priority.
|
|
308
|
+
*/
|
|
309
|
+
set priority(value: number) {
|
|
310
|
+
this._priority = value;
|
|
311
|
+
if (this.component) {
|
|
312
|
+
this.component.priority = value;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/**
|
|
317
|
+
* Gets the priority of the camera.
|
|
318
|
+
* @returns The priority.
|
|
319
|
+
*/
|
|
320
|
+
get priority(): number {
|
|
321
|
+
return this._priority;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
/**
|
|
325
|
+
* Sets the rect of the camera.
|
|
326
|
+
* @param value - The rect.
|
|
327
|
+
*/
|
|
328
|
+
set rect(value: Vec4) {
|
|
329
|
+
this._rect = value;
|
|
330
|
+
if (this.component) {
|
|
331
|
+
this.component.rect = value;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Gets the rect of the camera.
|
|
337
|
+
* @returns The rect.
|
|
338
|
+
*/
|
|
339
|
+
get rect(): Vec4 {
|
|
340
|
+
return this._rect;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Sets the scissor rect of the camera.
|
|
345
|
+
* @param value - The scissor rect.
|
|
346
|
+
*/
|
|
347
|
+
set scissorRect(value: Vec4) {
|
|
348
|
+
this._scissorRect = value;
|
|
349
|
+
if (this.component) {
|
|
350
|
+
this.component.scissorRect = value;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Gets the scissor rect of the camera.
|
|
356
|
+
* @returns The scissor rect.
|
|
357
|
+
*/
|
|
358
|
+
get scissorRect(): Vec4 {
|
|
359
|
+
return this._scissorRect;
|
|
360
|
+
}
|
|
361
|
+
|
|
164
362
|
static get observedAttributes() {
|
|
165
|
-
return [
|
|
363
|
+
return [
|
|
364
|
+
...super.observedAttributes,
|
|
365
|
+
'clear-color',
|
|
366
|
+
'clear-color-buffer',
|
|
367
|
+
'clear-depth-buffer',
|
|
368
|
+
'clear-stencil-buffer',
|
|
369
|
+
'cull-faces',
|
|
370
|
+
'far-clip',
|
|
371
|
+
'flip-faces',
|
|
372
|
+
'fov',
|
|
373
|
+
'frustum-culling',
|
|
374
|
+
'near-clip',
|
|
375
|
+
'orthographic',
|
|
376
|
+
'ortho-height',
|
|
377
|
+
'priority',
|
|
378
|
+
'rect',
|
|
379
|
+
'scissor-rect'
|
|
380
|
+
];
|
|
166
381
|
}
|
|
167
382
|
|
|
168
383
|
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
@@ -172,12 +387,30 @@ class CameraComponentElement extends ComponentElement {
|
|
|
172
387
|
case 'clear-color':
|
|
173
388
|
this.clearColor = parseColor(newValue);
|
|
174
389
|
break;
|
|
390
|
+
case 'clear-color-buffer':
|
|
391
|
+
this.clearColorBuffer = newValue !== 'false';
|
|
392
|
+
break;
|
|
393
|
+
case 'clear-depth-buffer':
|
|
394
|
+
this.clearDepthBuffer = newValue !== 'false';
|
|
395
|
+
break;
|
|
396
|
+
case 'clear-stencil-buffer':
|
|
397
|
+
this.clearStencilBuffer = newValue !== 'false';
|
|
398
|
+
break;
|
|
399
|
+
case 'cull-faces':
|
|
400
|
+
this.cullFaces = newValue !== 'false';
|
|
401
|
+
break;
|
|
175
402
|
case 'far-clip':
|
|
176
403
|
this.farClip = parseFloat(newValue);
|
|
177
404
|
break;
|
|
405
|
+
case 'flip-faces':
|
|
406
|
+
this.flipFaces = newValue !== 'true';
|
|
407
|
+
break;
|
|
178
408
|
case 'fov':
|
|
179
409
|
this.fov = parseFloat(newValue);
|
|
180
410
|
break;
|
|
411
|
+
case 'frustum-culling':
|
|
412
|
+
this.frustumCulling = newValue !== 'false';
|
|
413
|
+
break;
|
|
181
414
|
case 'near-clip':
|
|
182
415
|
this.nearClip = parseFloat(newValue);
|
|
183
416
|
break;
|
|
@@ -187,6 +420,15 @@ class CameraComponentElement extends ComponentElement {
|
|
|
187
420
|
case 'ortho-height':
|
|
188
421
|
this.orthoHeight = parseFloat(newValue);
|
|
189
422
|
break;
|
|
423
|
+
case 'priority':
|
|
424
|
+
this.priority = parseFloat(newValue);
|
|
425
|
+
break;
|
|
426
|
+
case 'rect':
|
|
427
|
+
this.rect = parseVec4(newValue);
|
|
428
|
+
break;
|
|
429
|
+
case 'scissor-rect':
|
|
430
|
+
this.scissorRect = parseVec4(newValue);
|
|
431
|
+
break;
|
|
190
432
|
}
|
|
191
433
|
}
|
|
192
434
|
}
|
|
@@ -43,17 +43,12 @@ class ElementComponentElement extends ComponentElement {
|
|
|
43
43
|
this.component!._text._material.useFog = true;
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
getAsset() {
|
|
47
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`) as AssetElement;
|
|
48
|
-
return assetElement!.asset;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
46
|
getInitialComponentData() {
|
|
52
47
|
return {
|
|
53
48
|
anchor: this._anchor,
|
|
54
49
|
autoWidth: this._autoWidth,
|
|
55
50
|
color: this._color,
|
|
56
|
-
fontAsset: this.
|
|
51
|
+
fontAsset: AssetElement.get(this._asset)!.id,
|
|
57
52
|
fontSize: this._fontSize,
|
|
58
53
|
lineHeight: this._lineHeight,
|
|
59
54
|
pivot: this._pivot,
|
|
@@ -85,7 +80,7 @@ class ElementComponentElement extends ComponentElement {
|
|
|
85
80
|
|
|
86
81
|
set asset(value: string) {
|
|
87
82
|
this._asset = value;
|
|
88
|
-
const asset =
|
|
83
|
+
const asset = AssetElement.get(value);
|
|
89
84
|
if (this.component && asset) {
|
|
90
85
|
this.component.fontAsset = asset.id;
|
|
91
86
|
}
|
|
@@ -15,14 +15,9 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
15
15
|
super('gsplat');
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
getAsset() {
|
|
19
|
-
const assetElement = document.querySelector(`pc-asset[id="${this._asset}"]`) as AssetElement;
|
|
20
|
-
return assetElement!.asset;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
18
|
getInitialComponentData() {
|
|
24
19
|
return {
|
|
25
|
-
asset: this.
|
|
20
|
+
asset: AssetElement.get(this._asset)
|
|
26
21
|
};
|
|
27
22
|
}
|
|
28
23
|
|
|
@@ -36,7 +31,7 @@ class GSplatComponentElement extends ComponentElement {
|
|
|
36
31
|
|
|
37
32
|
set asset(value: string) {
|
|
38
33
|
this._asset = value;
|
|
39
|
-
const asset =
|
|
34
|
+
const asset = AssetElement.get(value);
|
|
40
35
|
if (this.component && asset) {
|
|
41
36
|
this.component.asset = asset;
|
|
42
37
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { RenderComponent } from 'playcanvas';
|
|
1
|
+
import { RenderComponent, StandardMaterial } from 'playcanvas';
|
|
2
2
|
|
|
3
3
|
import { ComponentElement } from './component';
|
|
4
|
+
import { MaterialElement } from '../material';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Represents a render component in the PlayCanvas engine.
|
|
@@ -8,16 +9,24 @@ import { ComponentElement } from './component';
|
|
|
8
9
|
* @category Components
|
|
9
10
|
*/
|
|
10
11
|
class RenderComponentElement extends ComponentElement {
|
|
11
|
-
private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
|
|
12
|
-
|
|
13
12
|
private _castShadows = true;
|
|
14
13
|
|
|
14
|
+
private _material: string = '';
|
|
15
|
+
|
|
15
16
|
private _receiveShadows = true;
|
|
16
17
|
|
|
18
|
+
private _type: 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere' = 'asset';
|
|
19
|
+
|
|
17
20
|
constructor() {
|
|
18
21
|
super('render');
|
|
19
22
|
}
|
|
20
23
|
|
|
24
|
+
async connectedCallback() {
|
|
25
|
+
await super.connectedCallback();
|
|
26
|
+
|
|
27
|
+
this.material = this._material;
|
|
28
|
+
}
|
|
29
|
+
|
|
21
30
|
getInitialComponentData() {
|
|
22
31
|
return {
|
|
23
32
|
type: this._type,
|
|
@@ -72,6 +81,25 @@ class RenderComponentElement extends ComponentElement {
|
|
|
72
81
|
return this._castShadows;
|
|
73
82
|
}
|
|
74
83
|
|
|
84
|
+
/**
|
|
85
|
+
* Sets the material of the render component.
|
|
86
|
+
* @param value - The id of the material asset to use.
|
|
87
|
+
*/
|
|
88
|
+
set material(value: string) {
|
|
89
|
+
this._material = value;
|
|
90
|
+
if (this.component) {
|
|
91
|
+
this.component.material = MaterialElement.get(value) as StandardMaterial;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Gets the id of the material asset used by the render component.
|
|
97
|
+
* @returns The id of the material asset.
|
|
98
|
+
*/
|
|
99
|
+
get material() {
|
|
100
|
+
return this._material;
|
|
101
|
+
}
|
|
102
|
+
|
|
75
103
|
/**
|
|
76
104
|
* Sets the receive shadows flag of the render component.
|
|
77
105
|
* @param value - The receive shadows flag.
|
|
@@ -92,22 +120,25 @@ class RenderComponentElement extends ComponentElement {
|
|
|
92
120
|
}
|
|
93
121
|
|
|
94
122
|
static get observedAttributes() {
|
|
95
|
-
return [...super.observedAttributes, 'cast-shadows', 'receive-shadows', 'type'];
|
|
123
|
+
return [...super.observedAttributes, 'cast-shadows', 'material', 'receive-shadows', 'type'];
|
|
96
124
|
}
|
|
97
125
|
|
|
98
126
|
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
99
127
|
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
100
128
|
|
|
101
129
|
switch (name) {
|
|
102
|
-
case 'type':
|
|
103
|
-
this.type = newValue as 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
|
|
104
|
-
break;
|
|
105
130
|
case 'cast-shadows':
|
|
106
131
|
this.castShadows = newValue !== 'false';
|
|
107
132
|
break;
|
|
133
|
+
case 'material':
|
|
134
|
+
this.material = newValue;
|
|
135
|
+
break;
|
|
108
136
|
case 'receive-shadows':
|
|
109
137
|
this.receiveShadows = newValue !== 'false';
|
|
110
138
|
break;
|
|
139
|
+
case 'type':
|
|
140
|
+
this.type = newValue as 'asset' | 'box' | 'capsule' | 'cone' | 'cylinder' | 'plane' | 'sphere';
|
|
141
|
+
break;
|
|
111
142
|
}
|
|
112
143
|
}
|
|
113
144
|
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { SCALEMODE_BLEND, SCALEMODE_NONE, ScreenComponent, Vec2 } from 'playcanvas';
|
|
2
|
+
|
|
3
|
+
import { ComponentElement } from './component';
|
|
4
|
+
import { parseVec2 } from '../utils';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Represents a screen component in the PlayCanvas engine.
|
|
8
|
+
*
|
|
9
|
+
* @category Components
|
|
10
|
+
*/
|
|
11
|
+
class ScreenComponentElement extends ComponentElement {
|
|
12
|
+
private _screenSpace = false;
|
|
13
|
+
|
|
14
|
+
private _resolution: Vec2 = new Vec2(640, 320);
|
|
15
|
+
|
|
16
|
+
private _referenceResolution: Vec2 = new Vec2(640, 320);
|
|
17
|
+
|
|
18
|
+
private _priority = 0;
|
|
19
|
+
|
|
20
|
+
private _blend = false;
|
|
21
|
+
|
|
22
|
+
private _scaleBlend = 0.5;
|
|
23
|
+
|
|
24
|
+
constructor() {
|
|
25
|
+
super('screen');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getInitialComponentData() {
|
|
29
|
+
return {
|
|
30
|
+
priority: this._priority,
|
|
31
|
+
referenceResolution: this._referenceResolution,
|
|
32
|
+
resolution: this._resolution,
|
|
33
|
+
scaleBlend: this._scaleBlend,
|
|
34
|
+
scaleMode: this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE,
|
|
35
|
+
screenSpace: this._screenSpace
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Gets the screen component.
|
|
41
|
+
* @returns The screen component.
|
|
42
|
+
*/
|
|
43
|
+
get component(): ScreenComponent | null {
|
|
44
|
+
return super.component as ScreenComponent | null;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
set priority(value: number) {
|
|
48
|
+
this._priority = value;
|
|
49
|
+
if (this.component) {
|
|
50
|
+
this.component.priority = this._priority;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get priority() {
|
|
55
|
+
return this._priority;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
set referenceResolution(value: Vec2) {
|
|
59
|
+
this._referenceResolution = value;
|
|
60
|
+
if (this.component) {
|
|
61
|
+
this.component.referenceResolution = this._referenceResolution;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get referenceResolution() {
|
|
66
|
+
return this._referenceResolution;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set resolution(value: Vec2) {
|
|
70
|
+
this._resolution = value;
|
|
71
|
+
if (this.component) {
|
|
72
|
+
this.component.resolution = this._resolution;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
get resolution() {
|
|
77
|
+
return this._resolution;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
set scaleBlend(value: number) {
|
|
81
|
+
this._scaleBlend = value;
|
|
82
|
+
if (this.component) {
|
|
83
|
+
this.component.scaleBlend = this._scaleBlend;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get scaleBlend() {
|
|
88
|
+
return this._scaleBlend;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
set blend(value: boolean) {
|
|
92
|
+
this._blend = value;
|
|
93
|
+
if (this.component) {
|
|
94
|
+
this.component.scaleMode = this._blend ? SCALEMODE_BLEND : SCALEMODE_NONE;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
get blend() {
|
|
99
|
+
return this._blend;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
set screenSpace(value: boolean) {
|
|
103
|
+
this._screenSpace = value;
|
|
104
|
+
if (this.component) {
|
|
105
|
+
this.component.screenSpace = this._screenSpace;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
get screenSpace() {
|
|
110
|
+
return this._screenSpace;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
static get observedAttributes() {
|
|
114
|
+
return [
|
|
115
|
+
...super.observedAttributes,
|
|
116
|
+
'blend',
|
|
117
|
+
'screen-space',
|
|
118
|
+
'resolution',
|
|
119
|
+
'reference-resolution',
|
|
120
|
+
'priority',
|
|
121
|
+
'scale-blend'
|
|
122
|
+
];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
|
|
126
|
+
super.attributeChangedCallback(name, _oldValue, newValue);
|
|
127
|
+
|
|
128
|
+
switch (name) {
|
|
129
|
+
case 'priority':
|
|
130
|
+
this.priority = parseInt(newValue);
|
|
131
|
+
break;
|
|
132
|
+
case 'reference-resolution':
|
|
133
|
+
this.referenceResolution = parseVec2(newValue);
|
|
134
|
+
break;
|
|
135
|
+
case 'resolution':
|
|
136
|
+
this.resolution = parseVec2(newValue);
|
|
137
|
+
break;
|
|
138
|
+
case 'scale-blend':
|
|
139
|
+
this.scaleBlend = parseFloat(newValue);
|
|
140
|
+
break;
|
|
141
|
+
case 'blend':
|
|
142
|
+
this.blend = this.hasAttribute('blend');
|
|
143
|
+
break;
|
|
144
|
+
case 'screen-space':
|
|
145
|
+
this.screenSpace = this.hasAttribute('screen-space');
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
customElements.define('pc-screen', ScreenComponentElement);
|
|
152
|
+
|
|
153
|
+
export { ScreenComponentElement };
|