@playcanvas/web-components 0.1.2 → 0.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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(1, 1, 1, 1);
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
- projection: this._orthographic ? PROJECTION_ORTHOGRAPHIC : PROJECTION_PERSPECTIVE,
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 [...super.observedAttributes, 'clear-color', 'near-clip', 'far-clip', 'fov', 'orthographic', 'ortho-height'];
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
  }
@@ -1,7 +1,7 @@
1
- import { CollisionComponent, Vec3 } from 'playcanvas';
1
+ import { CollisionComponent, Quat, Vec3 } from 'playcanvas';
2
2
 
3
3
  import { ComponentElement } from './component';
4
- import { parseVec3 } from '../utils';
4
+ import { parseQuat, parseVec3 } from '../utils';
5
5
 
6
6
  /**
7
7
  * Represents a collision component in the PlayCanvas engine.
@@ -9,6 +9,8 @@ import { parseVec3 } from '../utils';
9
9
  * @category Components
10
10
  */
11
11
  class CollisionComponentElement extends ComponentElement {
12
+ private _angularOffset: Quat = new Quat();
13
+
12
14
  private _axis: number = 1;
13
15
 
14
16
  private _convexHull: boolean = false;
@@ -17,6 +19,8 @@ class CollisionComponentElement extends ComponentElement {
17
19
 
18
20
  private _height: number = 2;
19
21
 
22
+ private _linearOffset: Vec3 = new Vec3();
23
+
20
24
  private _radius: number = 0.5;
21
25
 
22
26
  private _type: string = 'box';
@@ -31,9 +35,11 @@ class CollisionComponentElement extends ComponentElement {
31
35
  getInitialComponentData() {
32
36
  return {
33
37
  axis: this._axis,
38
+ angularOffset: this._angularOffset,
34
39
  convexHull: this._convexHull,
35
40
  halfExtents: this._halfExtents,
36
41
  height: this._height,
42
+ linearOffset: this._linearOffset,
37
43
  radius: this._radius,
38
44
  type: this._type
39
45
  };
@@ -47,6 +53,17 @@ class CollisionComponentElement extends ComponentElement {
47
53
  return super.component as CollisionComponent | null;
48
54
  }
49
55
 
56
+ set angularOffset(value: Quat) {
57
+ this._angularOffset = value;
58
+ if (this.component) {
59
+ this.component.angularOffset = value;
60
+ }
61
+ }
62
+
63
+ get angularOffset() {
64
+ return this._angularOffset;
65
+ }
66
+
50
67
  set axis(value: number) {
51
68
  this._axis = value;
52
69
  if (this.component) {
@@ -91,6 +108,17 @@ class CollisionComponentElement extends ComponentElement {
91
108
  return this._height;
92
109
  }
93
110
 
111
+ set linearOffset(value: Vec3) {
112
+ this._linearOffset = value;
113
+ if (this.component) {
114
+ this.component.linearOffset = value;
115
+ }
116
+ }
117
+
118
+ get linearOffset() {
119
+ return this._linearOffset;
120
+ }
121
+
94
122
  set radius(value: number) {
95
123
  this._radius = value;
96
124
  if (this.component) {
@@ -114,13 +142,16 @@ class CollisionComponentElement extends ComponentElement {
114
142
  }
115
143
 
116
144
  static get observedAttributes() {
117
- return [...super.observedAttributes, 'axis', 'convex-hull', 'half-extents', 'height', 'radius', 'type'];
145
+ return [...super.observedAttributes, 'angular-offset', 'axis', 'convex-hull', 'half-extents', 'height', 'linear-offset', 'radius', 'type'];
118
146
  }
119
147
 
120
148
  attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
121
149
  super.attributeChangedCallback(name, _oldValue, newValue);
122
150
 
123
151
  switch (name) {
152
+ case 'angular-offset':
153
+ this.angularOffset = parseQuat(newValue);
154
+ break;
124
155
  case 'axis':
125
156
  this.axis = parseInt(newValue, 10);
126
157
  break;
@@ -133,6 +164,9 @@ class CollisionComponentElement extends ComponentElement {
133
164
  case 'height':
134
165
  this.height = parseFloat(newValue);
135
166
  break;
167
+ case 'linear-offset':
168
+ this.linearOffset = parseVec3(newValue);
169
+ break;
136
170
  case 'radius':
137
171
  this.radius = parseFloat(newValue);
138
172
  break;
@@ -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.getAsset()!.id,
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 = this.getAsset();
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.getAsset()
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 = this.getAsset();
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
  }