@playcanvas/web-components 0.2.0 → 0.2.2

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/src/scene.ts CHANGED
@@ -1,7 +1,8 @@
1
- import { Color, Scene } from 'playcanvas';
1
+ import { Color, Scene, Vec3 } from 'playcanvas';
2
2
 
3
+ import { AppElement } from './app';
3
4
  import { AsyncElement } from './async-element';
4
- import { parseColor } from './utils';
5
+ import { parseColor, parseVec3 } from './utils';
5
6
 
6
7
  /**
7
8
  * The SceneElement interface provides properties and methods for manipulating
@@ -35,6 +36,11 @@ class SceneElement extends AsyncElement {
35
36
  */
36
37
  private _fogEnd = 1000;
37
38
 
39
+ /**
40
+ * The gravity of the scene.
41
+ */
42
+ private _gravity = new Vec3(0, -9.81, 0);
43
+
38
44
  /**
39
45
  * The PlayCanvas scene instance.
40
46
  */
@@ -56,7 +62,9 @@ class SceneElement extends AsyncElement {
56
62
  this.scene.fog.density = this._fogDensity;
57
63
  this.scene.fog.start = this._fogStart;
58
64
  this.scene.fog.end = this._fogEnd;
59
- // ... set other properties on the scene as well
65
+
66
+ const appElement = this.parentElement as AppElement;
67
+ appElement.app!.systems.rigidbody!.gravity.copy(this._gravity);
60
68
  }
61
69
  }
62
70
 
@@ -155,8 +163,28 @@ class SceneElement extends AsyncElement {
155
163
  return this._fogEnd;
156
164
  }
157
165
 
166
+ /**
167
+ * Sets the gravity of the scene.
168
+ * @param value - The gravity.
169
+ */
170
+ set gravity(value: Vec3) {
171
+ this._gravity = value;
172
+ if (this.scene) {
173
+ const appElement = this.parentElement as AppElement;
174
+ appElement.app!.systems.rigidbody!.gravity.copy(value);
175
+ }
176
+ }
177
+
178
+ /**
179
+ * Gets the gravity of the scene.
180
+ * @returns The gravity.
181
+ */
182
+ get gravity() {
183
+ return this._gravity;
184
+ }
185
+
158
186
  static get observedAttributes() {
159
- return ['fog', 'fog-color', 'fog-density', 'fog-start', 'fog-end'];
187
+ return ['fog', 'fog-color', 'fog-density', 'fog-start', 'fog-end', 'gravity'];
160
188
  }
161
189
 
162
190
  attributeChangedCallback(name: string, _oldValue: string, newValue: string) {
@@ -176,6 +204,9 @@ class SceneElement extends AsyncElement {
176
204
  case 'fog-end':
177
205
  this.fogEnd = parseFloat(newValue);
178
206
  break;
207
+ case 'gravity':
208
+ this.gravity = parseVec3(newValue);
209
+ break;
179
210
  // ... handle other attributes as well
180
211
  }
181
212
  }