@needle-tools/engine 2.36.0-pre → 2.38.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.
- package/CHANGELOG.md +33 -0
- package/dist/needle-engine.d.ts +248 -151
- package/dist/needle-engine.js +451 -437
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +82 -82
- package/dist/needle-engine.min.js.map +4 -4
- package/lib/engine/api.d.ts +1 -0
- package/lib/engine/api.js +1 -0
- package/lib/engine/api.js.map +1 -1
- package/lib/engine/debug/debug.d.ts +1 -0
- package/lib/engine/debug/debug.js +3 -0
- package/lib/engine/debug/debug.js.map +1 -1
- package/lib/engine/engine_addressables.d.ts +3 -1
- package/lib/engine/engine_addressables.js +12 -5
- package/lib/engine/engine_addressables.js.map +1 -1
- package/lib/engine/engine_element.js +3 -2
- package/lib/engine/engine_element.js.map +1 -1
- package/lib/engine/engine_element_overlay.js +4 -3
- package/lib/engine/engine_element_overlay.js.map +1 -1
- package/lib/engine/engine_gameobject.js +2 -1
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_input.d.ts +2 -0
- package/lib/engine/engine_input.js +14 -3
- package/lib/engine/engine_input.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +35 -46
- package/lib/engine/engine_physics.js +479 -386
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.d.ts +23 -0
- package/lib/engine/engine_physics.types.js +27 -0
- package/lib/engine/engine_physics.types.js.map +1 -0
- package/lib/engine/engine_serialization_core.d.ts +3 -0
- package/lib/engine/engine_serialization_core.js +5 -0
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +7 -1
- package/lib/engine/engine_setup.js +13 -3
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_types.d.ts +45 -26
- package/lib/engine/engine_types.js +24 -37
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_util_decorator.d.ts +6 -0
- package/lib/engine/engine_util_decorator.js +54 -0
- package/lib/engine/engine_util_decorator.js.map +1 -0
- package/lib/engine/engine_utils.d.ts +1 -1
- package/lib/engine/engine_utils.js +1 -1
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_gameobject_data.js +2 -0
- package/lib/engine/extensions/NEEDLE_gameobject_data.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +7 -5
- package/lib/engine-components/Animation.js +7 -7
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.js +14 -7
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.js +1 -0
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Camera.d.ts +1 -0
- package/lib/engine-components/Camera.js +20 -5
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +31 -0
- package/lib/engine-components/CharacterController.js +167 -0
- package/lib/engine-components/CharacterController.js.map +1 -0
- package/lib/engine-components/Collider.d.ts +16 -5
- package/lib/engine-components/Collider.js +45 -23
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +6 -15
- package/lib/engine-components/Component.js +7 -112
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/DragControls.js +9 -6
- package/lib/engine-components/DragControls.js.map +1 -1
- package/lib/engine-components/Light.d.ts +2 -0
- package/lib/engine-components/Light.js +13 -2
- package/lib/engine-components/Light.js.map +1 -1
- package/lib/engine-components/NavMesh.d.ts +0 -5
- package/lib/engine-components/NavMesh.js +100 -10
- package/lib/engine-components/NavMesh.js.map +1 -1
- package/lib/engine-components/NestedGltf.js +2 -0
- package/lib/engine-components/NestedGltf.js.map +1 -1
- package/lib/engine-components/Renderer.js +4 -0
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +45 -25
- package/lib/engine-components/RigidBody.js +290 -142
- package/lib/engine-components/RigidBody.js.map +1 -1
- package/lib/engine-components/SmoothFollow.d.ts +2 -1
- package/lib/engine-components/SmoothFollow.js +25 -17
- package/lib/engine-components/SmoothFollow.js.map +1 -1
- package/lib/engine-components/SpatialTrigger.js +1 -1
- package/lib/engine-components/SpatialTrigger.js.map +1 -1
- package/lib/engine-components/SpectatorCamera.d.ts +1 -0
- package/lib/engine-components/SpectatorCamera.js +9 -2
- package/lib/engine-components/SpectatorCamera.js.map +1 -1
- package/lib/engine-components/SpringJoint.d.ts +0 -13
- package/lib/engine-components/SpringJoint.js +42 -41
- package/lib/engine-components/SpringJoint.js.map +1 -1
- package/lib/engine-components/VideoPlayer.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +1 -0
- package/lib/engine-components/WebXR.js +13 -6
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRController.js +12 -6
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +4 -3
- package/lib/engine-components/codegen/components.js +4 -3
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/package.json +3 -4
- package/src/engine/api.ts +2 -1
- package/src/engine/codegen/register_types.js +16 -12
- package/src/engine/debug/debug.ts +4 -0
- package/src/engine/dist/engine_physics.js +739 -0
- package/src/engine/dist/engine_setup.js +777 -0
- package/src/engine/engine_addressables.ts +18 -8
- package/src/engine/engine_element.ts +3 -2
- package/src/engine/engine_element_overlay.ts +4 -3
- package/src/engine/engine_gameobject.ts +4 -4
- package/src/engine/engine_input.ts +12 -3
- package/src/engine/engine_physics.ts +492 -418
- package/src/engine/engine_physics.types.ts +28 -0
- package/src/engine/engine_serialization_core.ts +8 -1
- package/src/engine/engine_setup.ts +31 -18
- package/src/engine/engine_types.ts +83 -56
- package/src/engine/engine_util_decorator.ts +69 -0
- package/src/engine/engine_utils.ts +3 -3
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +2 -0
- package/src/engine-components/Animation.ts +18 -12
- package/src/engine-components/AnimatorController.ts +16 -11
- package/src/engine-components/BoxHelperComponent.ts +1 -0
- package/src/engine-components/Camera.ts +21 -4
- package/src/engine-components/CharacterController.ts +171 -0
- package/src/engine-components/Collider.ts +49 -39
- package/src/engine-components/Component.ts +15 -130
- package/src/engine-components/DragControls.ts +9 -5
- package/src/engine-components/Light.ts +17 -3
- package/src/engine-components/NavMesh.ts +114 -115
- package/src/engine-components/NestedGltf.ts +2 -0
- package/src/engine-components/Renderer.ts +5 -1
- package/src/engine-components/RigidBody.ts +292 -149
- package/src/engine-components/SmoothFollow.ts +21 -18
- package/src/engine-components/SpatialTrigger.ts +1 -1
- package/src/engine-components/SpectatorCamera.ts +10 -2
- package/src/engine-components/SpringJoint.ts +41 -41
- package/src/engine-components/VideoPlayer.ts +1 -2
- package/src/engine-components/WebXR.ts +15 -6
- package/src/engine-components/WebXRController.ts +16 -7
- package/src/engine-components/codegen/components.ts +4 -3
- package/src/engine-components/dist/CharacterController.js +123 -0
- package/src/engine-components/dist/RigidBody.js +458 -0
|
@@ -0,0 +1,458 @@
|
|
|
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;
|