@needle-tools/engine 2.40.0-pre → 2.42.0-pre

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.
Files changed (80) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/needle-engine.d.ts +332 -126
  3. package/dist/needle-engine.js +401 -401
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +53 -53
  6. package/dist/needle-engine.min.js.map +4 -4
  7. package/lib/engine/engine_element.js +1 -1
  8. package/lib/engine/engine_element.js.map +1 -1
  9. package/lib/engine/engine_element_loading.js +6 -1
  10. package/lib/engine/engine_element_loading.js.map +1 -1
  11. package/lib/engine/engine_gizmos.d.ts +8 -21
  12. package/lib/engine/engine_gizmos.js +51 -5
  13. package/lib/engine/engine_gizmos.js.map +1 -1
  14. package/lib/engine/engine_math.d.ts +9 -6
  15. package/lib/engine/engine_math.js +9 -0
  16. package/lib/engine/engine_math.js.map +1 -1
  17. package/lib/engine/engine_physics.js +14 -6
  18. package/lib/engine/engine_physics.js.map +1 -1
  19. package/lib/engine/engine_serialization_core.js +2 -0
  20. package/lib/engine/engine_serialization_core.js.map +1 -1
  21. package/lib/engine/engine_setup.d.ts +3 -0
  22. package/lib/engine/engine_setup.js +15 -0
  23. package/lib/engine/engine_setup.js.map +1 -1
  24. package/lib/engine/engine_three_utils.d.ts +16 -1
  25. package/lib/engine/engine_three_utils.js +94 -54
  26. package/lib/engine/engine_three_utils.js.map +1 -1
  27. package/lib/engine/engine_types.d.ts +6 -0
  28. package/lib/engine/engine_types.js.map +1 -1
  29. package/lib/engine/engine_utils.d.ts +1 -0
  30. package/lib/engine/engine_utils.js +3 -0
  31. package/lib/engine/engine_utils.js.map +1 -1
  32. package/lib/engine-components/AnimationCurve.js +20 -5
  33. package/lib/engine-components/AnimationCurve.js.map +1 -1
  34. package/lib/engine-components/BoxHelperComponent.js +9 -10
  35. package/lib/engine-components/BoxHelperComponent.js.map +1 -1
  36. package/lib/engine-components/Light.d.ts +2 -0
  37. package/lib/engine-components/Light.js +33 -9
  38. package/lib/engine-components/Light.js.map +1 -1
  39. package/lib/engine-components/ParticleSystem.d.ts +29 -26
  40. package/lib/engine-components/ParticleSystem.js +349 -187
  41. package/lib/engine-components/ParticleSystem.js.map +1 -1
  42. package/lib/engine-components/ParticleSystemModules.d.ts +243 -64
  43. package/lib/engine-components/ParticleSystemModules.js +722 -153
  44. package/lib/engine-components/ParticleSystemModules.js.map +1 -1
  45. package/lib/engine-components/ReflectionProbe.js +29 -11
  46. package/lib/engine-components/ReflectionProbe.js.map +1 -1
  47. package/lib/engine-components/Renderer.d.ts +1 -0
  48. package/lib/engine-components/Renderer.js +4 -2
  49. package/lib/engine-components/Renderer.js.map +1 -1
  50. package/lib/engine-components/WebXR.js +8 -3
  51. package/lib/engine-components/WebXR.js.map +1 -1
  52. package/lib/engine-components/codegen/components.d.ts +7 -0
  53. package/lib/engine-components/codegen/components.js +7 -0
  54. package/lib/engine-components/codegen/components.js.map +1 -1
  55. package/package.json +4 -2
  56. package/src/engine/codegen/register_types.js +28 -0
  57. package/src/engine/dist/engine_three_utils.js +279 -0
  58. package/src/engine/engine_element.ts +1 -1
  59. package/src/engine/engine_element_loading.ts +5 -1
  60. package/src/engine/engine_gizmos.ts +58 -6
  61. package/src/engine/engine_math.ts +19 -6
  62. package/src/engine/engine_physics.ts +17 -7
  63. package/src/engine/engine_serialization_core.ts +1 -0
  64. package/src/engine/engine_setup.ts +25 -2
  65. package/src/engine/engine_three_utils.ts +103 -62
  66. package/src/engine/engine_types.ts +8 -1
  67. package/src/engine/engine_utils.ts +5 -0
  68. package/src/engine-components/AnimationCurve.ts +25 -11
  69. package/src/engine-components/BoxHelperComponent.ts +12 -15
  70. package/src/engine-components/Light.ts +39 -8
  71. package/src/engine-components/ParticleSystem.ts +395 -199
  72. package/src/engine-components/ParticleSystemModules.ts +638 -152
  73. package/src/engine-components/ReflectionProbe.ts +37 -13
  74. package/src/engine-components/Renderer.ts +4 -2
  75. package/src/engine-components/WebXR.ts +11 -8
  76. package/src/engine-components/codegen/components.ts +7 -0
  77. package/src/engine/dist/engine_physics.js +0 -739
  78. package/src/engine/dist/engine_setup.js +0 -777
  79. package/src/engine-components/dist/CharacterController.js +0 -123
  80. package/src/engine-components/dist/RigidBody.js +0 -458
@@ -1,123 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
16
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
19
- return c > 3 && r && Object.defineProperty(target, key, r), r;
20
- };
21
- exports.__esModule = true;
22
- exports.CharacterControllerInput = exports.CharacterController = void 0;
23
- var three_1 = require("three");
24
- var engine_math_1 = require("../engine/engine_math");
25
- var engine_serialization_1 = require("../engine/engine_serialization");
26
- var Collider_1 = require("./Collider");
27
- var Component_1 = require("./Component");
28
- var RigidBody_1 = require("./RigidBody");
29
- var CharacterController = /** @class */ (function (_super) {
30
- __extends(CharacterController, _super);
31
- function CharacterController() {
32
- var _this = _super !== null && _super.apply(this, arguments) || this;
33
- _this.center = new three_1.Vector3(0, 0, 0);
34
- _this.radius = .5;
35
- _this.height = 2;
36
- return _this;
37
- }
38
- CharacterController.prototype.onEnable = function () {
39
- var rb = this.gameObject.getComponent(RigidBody_1.Rigidbody);
40
- var collider = this.gameObject.getComponent(Collider_1.CapsuleCollider);
41
- if (!rb)
42
- rb = this.gameObject.addNewComponent(RigidBody_1.Rigidbody);
43
- if (!collider)
44
- collider = this.gameObject.addNewComponent(Collider_1.CapsuleCollider);
45
- // rb.isKinematic = true;
46
- collider.center.copy(this.center);
47
- collider.radius = this.radius;
48
- collider.height = this.height;
49
- this.gameObject.rotation.x = 0;
50
- this.gameObject.rotation.z = 0;
51
- rb.lockRotationX = true;
52
- rb.lockRotationY = true;
53
- rb.lockRotationZ = true;
54
- };
55
- CharacterController.prototype.move = function (vec) {
56
- this.gameObject.position.add(vec);
57
- };
58
- CharacterController.prototype.onCollisionEnter = function (col) {
59
- // console.log(col);
60
- };
61
- CharacterController.prototype.onCollisionExit = function (col) {
62
- };
63
- CharacterController.prototype.isGrounded = function () {
64
- };
65
- __decorate([
66
- engine_serialization_1.serializeable(three_1.Vector3)
67
- ], CharacterController.prototype, "center");
68
- __decorate([
69
- engine_serialization_1.serializeable()
70
- ], CharacterController.prototype, "radius");
71
- __decorate([
72
- engine_serialization_1.serializeable()
73
- ], CharacterController.prototype, "height");
74
- return CharacterController;
75
- }(Component_1.Behaviour));
76
- exports.CharacterController = CharacterController;
77
- var CharacterControllerInput = /** @class */ (function (_super) {
78
- __extends(CharacterControllerInput, _super);
79
- function CharacterControllerInput() {
80
- var _this = _super !== null && _super.apply(this, arguments) || this;
81
- _this.movementSpeed = 2;
82
- _this.rotationSpeed = 2;
83
- _this.jumpHeight = 1;
84
- _this._currentSpeed = new three_1.Vector3(0, 0, 0);
85
- _this._currentAngularSpeed = new three_1.Vector3(0, 0, 0);
86
- _this._temp = new three_1.Vector3(0, 0, 0);
87
- return _this;
88
- }
89
- CharacterControllerInput.prototype.update = function () {
90
- var forward = this.context.input.isKeyPressed("w");
91
- var backward = this.context.input.isKeyPressed("s");
92
- var rotateLeft = this.context.input.isKeyPressed("a");
93
- var rotateRight = this.context.input.isKeyPressed("d");
94
- var jump = this.context.input.isKeyPressed("space");
95
- var step = forward ? 1 : 0 + backward ? -1 : 0;
96
- this._currentSpeed.z += step * this.movementSpeed * this.context.time.deltaTime;
97
- this._temp.copy(this._currentSpeed);
98
- this._temp.applyQuaternion(this.gameObject.quaternion);
99
- if (this.controller)
100
- this.controller.move(this._temp);
101
- else
102
- this.gameObject.position.add(this._temp);
103
- var rotation = rotateLeft ? 1 : 0 + rotateRight ? -1 : 0;
104
- this._currentAngularSpeed.y += engine_math_1.Mathf.toRadians(rotation * this.rotationSpeed) * this.context.time.deltaTime;
105
- this.gameObject.rotateY(this._currentAngularSpeed.y);
106
- this._currentSpeed.multiplyScalar(1 - this.context.time.deltaTime * 10);
107
- this._currentAngularSpeed.y *= 1 - this.context.time.deltaTime * 10;
108
- };
109
- __decorate([
110
- engine_serialization_1.serializeable(CharacterController)
111
- ], CharacterControllerInput.prototype, "controller");
112
- __decorate([
113
- engine_serialization_1.serializeable()
114
- ], CharacterControllerInput.prototype, "movementSpeed");
115
- __decorate([
116
- engine_serialization_1.serializeable()
117
- ], CharacterControllerInput.prototype, "rotationSpeed");
118
- __decorate([
119
- engine_serialization_1.serializeable()
120
- ], CharacterControllerInput.prototype, "jumpHeight");
121
- return CharacterControllerInput;
122
- }(Component_1.Behaviour));
123
- exports.CharacterControllerInput = CharacterControllerInput;
@@ -1,458 +0,0 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
16
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
17
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
18
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
19
- return c > 3 && r && Object.defineProperty(target, key, r), r;
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- exports.__esModule = true;
49
- exports.Rigidbody = void 0;
50
- var Component_1 = require("./Component");
51
- var THREE = require("three");
52
- var engine_three_utils_1 = require("../engine/engine_three_utils");
53
- var engine_serialization_decorator_1 = require("../engine/engine_serialization_decorator");
54
- var engine_utils_1 = require("../engine/engine_utils");
55
- var three_1 = require("three");
56
- var engine_physics_types_1 = require("../engine/engine_physics.types");
57
- var engine_util_decorator_1 = require("../engine/engine_util_decorator");
58
- var engine_setup_1 = require("../engine/engine_setup");
59
- var TransformWatch = /** @class */ (function () {
60
- function TransformWatch(obj, context) {
61
- this.positionChanged = false;
62
- this.rotationChanged = false;
63
- this._positionKeys = ["x", "y", "z"];
64
- this._quaternionKeys = ["_x", "_y", "_z", "_w"];
65
- this.mute = false;
66
- this.context = context;
67
- this.obj = obj;
68
- }
69
- Object.defineProperty(TransformWatch.prototype, "isDirty", {
70
- get: function () {
71
- return this.positionChanged || this.rotationChanged;
72
- },
73
- enumerable: false,
74
- configurable: true
75
- });
76
- TransformWatch.prototype.reset = function () {
77
- this.positionChanged = false;
78
- this.rotationChanged = false;
79
- this.mute = false;
80
- // on reset delete the previously received values
81
- // if (this.position)
82
- // for (const key of this._positionKeys)
83
- // delete this.position[key];
84
- // if (this.quaternion)
85
- // for (const key of this._quaternionKeys)
86
- // delete this.quaternion[key];
87
- };
88
- TransformWatch.prototype.applyValues = function () {
89
- // only apply the values that actually changed
90
- // since we want to still control all the other values via physics
91
- if (this.positionChanged && this.position) {
92
- for (var _i = 0, _a = this._positionKeys; _i < _a.length; _i++) {
93
- var key = _a[_i];
94
- var val = this.position[key];
95
- if (val !== undefined)
96
- this.obj.position[key] = val;
97
- }
98
- }
99
- if (this.rotationChanged) {
100
- if (this.quaternion) {
101
- for (var _b = 0, _c = this._quaternionKeys; _b < _c.length; _b++) {
102
- var key = _c[_b];
103
- var val = this.quaternion[key];
104
- if (val !== undefined)
105
- this.obj.quaternion[key] = val;
106
- }
107
- }
108
- }
109
- };
110
- TransformWatch.prototype.start = function (position, rotation) {
111
- var _this = this;
112
- this.reset();
113
- if (position) {
114
- if (!this._positionWatch)
115
- this._positionWatch = new engine_utils_1.Watch(this.obj.position, ["x", "y", "z"]);
116
- this._positionWatch.apply();
117
- this.position = {};
118
- // this.position = this.obj.position.clone();
119
- this._positionWatch.subscribeWrite(function (val, prop) {
120
- if (_this.context.physics.isUpdating || _this.mute)
121
- return;
122
- var prev = _this.position[prop];
123
- if (Math.abs(prev - val) < .00001)
124
- return;
125
- _this.position[prop] = val;
126
- _this.positionChanged = true;
127
- });
128
- }
129
- if (rotation) {
130
- if (!this._rotationWatch)
131
- this._rotationWatch = new engine_utils_1.Watch(this.obj.quaternion, ["_x", "_y", "_z", "_w"]);
132
- this._rotationWatch.apply();
133
- this.quaternion = {};
134
- // this.quaternion = this.obj.quaternion.clone();
135
- this._rotationWatch.subscribeWrite(function (val, prop) {
136
- if (_this.context.physics.isUpdating || _this.mute)
137
- return;
138
- var prev = _this.quaternion[prop];
139
- if (Math.abs(prev - val) < .00001)
140
- return;
141
- _this.quaternion[prop] = val;
142
- _this.rotationChanged = true;
143
- });
144
- }
145
- };
146
- TransformWatch.prototype.stop = function () {
147
- var _a, _b;
148
- (_a = this._positionWatch) === null || _a === void 0 ? void 0 : _a.revoke();
149
- (_b = this._rotationWatch) === null || _b === void 0 ? void 0 : _b.revoke();
150
- };
151
- return TransformWatch;
152
- }());
153
- var Rigidbody = /** @class */ (function (_super) {
154
- __extends(Rigidbody, _super);
155
- function Rigidbody() {
156
- var _this = _super !== null && _super.apply(this, arguments) || this;
157
- _this.mass = 1;
158
- _this.useGravity = true;
159
- _this.constraints = engine_physics_types_1.RigidbodyConstraints.None;
160
- _this.isKinematic = false;
161
- _this.drag = 0;
162
- _this.angularDrag = 1;
163
- _this.detectCollisions = true;
164
- _this.sleepThreshold = 0.01;
165
- _this.collisionDetectionMode = engine_physics_types_1.CollisionDetectionMode.Discrete;
166
- _this._propertiesChanged = false;
167
- return _this;
168
- }
169
- Object.defineProperty(Rigidbody.prototype, "lockPositionX", {
170
- get: function () {
171
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezePositionX) !== 0;
172
- },
173
- set: function (v) {
174
- if (v)
175
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezePositionX;
176
- else
177
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezePositionX;
178
- },
179
- enumerable: false,
180
- configurable: true
181
- });
182
- Object.defineProperty(Rigidbody.prototype, "lockPositionY", {
183
- get: function () {
184
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezePositionY) !== 0;
185
- },
186
- set: function (v) {
187
- if (v)
188
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezePositionY;
189
- else
190
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezePositionY;
191
- },
192
- enumerable: false,
193
- configurable: true
194
- });
195
- Object.defineProperty(Rigidbody.prototype, "lockPositionZ", {
196
- get: function () {
197
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezePositionZ) !== 0;
198
- },
199
- set: function (v) {
200
- if (v)
201
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezePositionZ;
202
- else
203
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezePositionZ;
204
- },
205
- enumerable: false,
206
- configurable: true
207
- });
208
- Object.defineProperty(Rigidbody.prototype, "lockRotationX", {
209
- get: function () {
210
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezeRotationX) !== 0;
211
- },
212
- set: function (v) {
213
- if (v)
214
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezeRotationX;
215
- else
216
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezeRotationX;
217
- },
218
- enumerable: false,
219
- configurable: true
220
- });
221
- Object.defineProperty(Rigidbody.prototype, "lockRotationY", {
222
- get: function () {
223
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezeRotationY) !== 0;
224
- },
225
- set: function (v) {
226
- if (v)
227
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezeRotationY;
228
- else
229
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezeRotationY;
230
- },
231
- enumerable: false,
232
- configurable: true
233
- });
234
- Object.defineProperty(Rigidbody.prototype, "lockRotationZ", {
235
- get: function () {
236
- return (this.constraints & engine_physics_types_1.RigidbodyConstraints.FreezeRotationZ) !== 0;
237
- },
238
- set: function (v) {
239
- if (v)
240
- this.constraints |= engine_physics_types_1.RigidbodyConstraints.FreezeRotationZ;
241
- else
242
- this.constraints &= ~engine_physics_types_1.RigidbodyConstraints.FreezeRotationZ;
243
- },
244
- enumerable: false,
245
- configurable: true
246
- });
247
- Rigidbody.prototype.awake = function () {
248
- this._watch = undefined;
249
- this._currentVelocity = new THREE.Vector3();
250
- this._smoothedVelocity = new THREE.Vector3();
251
- this._smoothedVelocityGetter = new THREE.Vector3();
252
- this._lastPosition = new THREE.Vector3();
253
- };
254
- Rigidbody.prototype.onEnable = function () {
255
- if (!this._watch) {
256
- this._watch = new TransformWatch(this.gameObject, this.context);
257
- }
258
- this._watch.start(true, true);
259
- this.startCoroutine(this.beforePhysics(), engine_setup_1.FrameEvent.LateUpdate);
260
- };
261
- Rigidbody.prototype.onDisable = function () {
262
- var _a;
263
- (_a = this._watch) === null || _a === void 0 ? void 0 : _a.stop();
264
- this.context.physics.removeBody(this);
265
- };
266
- Rigidbody.prototype.onDestroy = function () {
267
- this.context.physics.removeBody(this);
268
- };
269
- Rigidbody.prototype.onValidate = function () {
270
- this._propertiesChanged = true;
271
- };
272
- // need to do this right before updating physics to prevent rendered object glitching through physical bodies
273
- Rigidbody.prototype.beforePhysics = function () {
274
- var _a;
275
- return __generator(this, function (_b) {
276
- switch (_b.label) {
277
- case 0:
278
- if (!true) return [3 /*break*/, 2];
279
- if (this._propertiesChanged) {
280
- this._propertiesChanged = false;
281
- this.context.physics.updateProperties(this);
282
- }
283
- if ((_a = this._watch) === null || _a === void 0 ? void 0 : _a.isDirty) {
284
- this._watch.mute = true;
285
- this._watch.applyValues();
286
- this.context.physics.updateBody(this, this._watch.positionChanged, this._watch.rotationChanged);
287
- this._watch.reset();
288
- }
289
- this.captureVelocity();
290
- return [4 /*yield*/];
291
- case 1:
292
- _b.sent();
293
- return [3 /*break*/, 0];
294
- case 2: return [2 /*return*/];
295
- }
296
- });
297
- };
298
- Object.defineProperty(Rigidbody.prototype, "body", {
299
- get: function () {
300
- return this.context.physics.internal_getRigidbody(this);
301
- },
302
- enumerable: false,
303
- configurable: true
304
- });
305
- // TODO: we need to differentiate between setting a physics body to a new position and moving it where we also want to affect the velocity
306
- // public teleport(){
307
- // this.context.physics.updateBody(this);
308
- // }
309
- Rigidbody.prototype.resetForces = function () {
310
- var _a;
311
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.resetForces(true);
312
- };
313
- Rigidbody.prototype.resetTorques = function () {
314
- var _a;
315
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.resetTorques(true);
316
- };
317
- Rigidbody.prototype.resetVelocities = function () {
318
- this.setVelocity(0, 0, 0);
319
- this.setAngularVelocity(0, 0, 0);
320
- };
321
- Rigidbody.prototype.resetForcesAndTorques = function () {
322
- this.resetForces();
323
- this.resetTorques();
324
- };
325
- Rigidbody.prototype.wakeUp = function () {
326
- var _a;
327
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.wakeUp();
328
- };
329
- Rigidbody.prototype.applyForce = function (vec, _rel) {
330
- var _a;
331
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.addForce(vec, true);
332
- };
333
- Rigidbody.prototype.applyImpulse = function (vec) {
334
- var _a;
335
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.applyImpulse(vec, true);
336
- };
337
- Rigidbody.prototype.setForce = function (x, y, z) {
338
- var _a, _b;
339
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.resetForces(true);
340
- (_b = this.body) === null || _b === void 0 ? void 0 : _b.addForce({ x: x, y: y, z: z }, true);
341
- };
342
- Rigidbody.prototype.getVelocity = function () {
343
- var _a;
344
- var vel = (_a = this.body) === null || _a === void 0 ? void 0 : _a.linvel();
345
- if (!vel)
346
- return this._currentVelocity.set(0, 0, 0);
347
- this._currentVelocity.x = vel.x;
348
- this._currentVelocity.y = vel.y;
349
- this._currentVelocity.z = vel.z;
350
- return this._currentVelocity;
351
- };
352
- Rigidbody.prototype.setVelocity = function (x, y, z) {
353
- var _a, _b;
354
- if (x instanceof three_1.Vector3) {
355
- var vec = x;
356
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.setLinvel(vec, true);
357
- return;
358
- }
359
- if (y === undefined || z === undefined)
360
- return;
361
- (_b = this.body) === null || _b === void 0 ? void 0 : _b.setLinvel({ x: x, y: y, z: z }, true);
362
- };
363
- Rigidbody.prototype.setAngularVelocity = function (x, y, z) {
364
- var _a, _b;
365
- if (x instanceof three_1.Vector3) {
366
- var vec = x;
367
- (_a = this.body) === null || _a === void 0 ? void 0 : _a.setAngvel(vec, true);
368
- return;
369
- }
370
- if (y === undefined || z === undefined)
371
- return;
372
- (_b = this.body) === null || _b === void 0 ? void 0 : _b.setAngvel({ x: x, y: y, z: z }, true);
373
- };
374
- Rigidbody.prototype.setTorque = function (x, y, z) {
375
- this.setAngularVelocity(x, y, z);
376
- };
377
- Object.defineProperty(Rigidbody.prototype, "smoothedVelocity", {
378
- get: function () {
379
- this._smoothedVelocityGetter.copy(this._smoothedVelocity);
380
- return this._smoothedVelocityGetter.multiplyScalar(1 / this.context.time.deltaTime);
381
- },
382
- enumerable: false,
383
- configurable: true
384
- });
385
- // public get smoothedVelocity() { return this._smoothedVelocity; }
386
- /**d
387
- * @deprecated not used anymore
388
- */
389
- Rigidbody.prototype.setBodyFromGameObject = function (_velocity) {
390
- if (_velocity === void 0) { _velocity = null; }
391
- if (this.gameObject && !this.destroyed) {
392
- // this.context.physics.updateBody(this);
393
- // this._ignoreChange = true;
394
- // const wp = this.worldPosition;
395
- // this.body.position.set(wp.x, wp.y, wp.z);
396
- // const wr = this.worldQuaternion;
397
- // this.body.quaternion.set(wr.x, wr.y, wr.z, wr.w);
398
- // if (velocity) {
399
- // Rigidbody.copyVector3.set(velocity.x, velocity.y, velocity.z);
400
- // this._smoothedVelocity.lerp(Rigidbody.copyVector3, this.context.time.deltaTime / .1);
401
- // const sm = this._smoothedVelocity;
402
- // this.body.velocity.x = sm.x;
403
- // this.body.velocity.y = sm.y;
404
- // this.body.velocity.z = sm.z;
405
- // }
406
- // this._ignoreChange = false;
407
- }
408
- };
409
- Rigidbody.prototype.captureVelocity = function () {
410
- if (this.body) {
411
- var wp = engine_three_utils_1.getWorldPosition(this.gameObject);
412
- Rigidbody.tempPosition.copy(wp);
413
- var vel = wp.sub(this._lastPosition);
414
- this._lastPosition.copy(Rigidbody.tempPosition);
415
- this._smoothedVelocity.lerp(vel, this.context.time.deltaTime / .1);
416
- // this._smoothedVelocity.set(0, 1 / this.context.time.deltaTime, 0);
417
- }
418
- };
419
- Rigidbody.tempPosition = new THREE.Vector3();
420
- __decorate([
421
- engine_util_decorator_1.validate(),
422
- engine_serialization_decorator_1.serializeable()
423
- ], Rigidbody.prototype, "mass");
424
- __decorate([
425
- engine_util_decorator_1.validate(),
426
- engine_serialization_decorator_1.serializeable()
427
- ], Rigidbody.prototype, "useGravity");
428
- __decorate([
429
- engine_util_decorator_1.validate(),
430
- engine_serialization_decorator_1.serializeable()
431
- ], Rigidbody.prototype, "constraints");
432
- __decorate([
433
- engine_util_decorator_1.validate(),
434
- engine_serialization_decorator_1.serializeable()
435
- ], Rigidbody.prototype, "isKinematic");
436
- __decorate([
437
- engine_util_decorator_1.validate(),
438
- engine_serialization_decorator_1.serializeable()
439
- ], Rigidbody.prototype, "drag");
440
- __decorate([
441
- engine_util_decorator_1.validate(),
442
- engine_serialization_decorator_1.serializeable()
443
- ], Rigidbody.prototype, "angularDrag");
444
- __decorate([
445
- engine_util_decorator_1.validate(),
446
- engine_serialization_decorator_1.serializeable()
447
- ], Rigidbody.prototype, "detectCollisions");
448
- __decorate([
449
- engine_util_decorator_1.validate(),
450
- engine_serialization_decorator_1.serializeable()
451
- ], Rigidbody.prototype, "sleepThreshold");
452
- __decorate([
453
- engine_util_decorator_1.validate(),
454
- engine_serialization_decorator_1.serializeable()
455
- ], Rigidbody.prototype, "collisionDetectionMode");
456
- return Rigidbody;
457
- }(Component_1.Behaviour));
458
- exports.Rigidbody = Rigidbody;