@needle-tools/engine 2.37.0-pre → 2.38.0-pre.1

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 (101) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/needle-engine.d.ts +118 -19
  3. package/dist/needle-engine.js +352 -352
  4. package/dist/needle-engine.js.map +4 -4
  5. package/dist/needle-engine.min.js +25 -25
  6. package/dist/needle-engine.min.js.map +4 -4
  7. package/lib/engine/engine_addressables.d.ts +3 -1
  8. package/lib/engine/engine_addressables.js +12 -5
  9. package/lib/engine/engine_addressables.js.map +1 -1
  10. package/lib/engine/engine_element.js +3 -2
  11. package/lib/engine/engine_element.js.map +1 -1
  12. package/lib/engine/engine_element_overlay.js +4 -3
  13. package/lib/engine/engine_element_overlay.js.map +1 -1
  14. package/lib/engine/engine_input.d.ts +2 -0
  15. package/lib/engine/engine_input.js +14 -3
  16. package/lib/engine/engine_input.js.map +1 -1
  17. package/lib/engine/engine_physics.d.ts +11 -4
  18. package/lib/engine/engine_physics.js +107 -42
  19. package/lib/engine/engine_physics.js.map +1 -1
  20. package/lib/engine/engine_physics.types.d.ts +7 -0
  21. package/lib/engine/engine_physics.types.js +8 -0
  22. package/lib/engine/engine_physics.types.js.map +1 -1
  23. package/lib/engine/engine_setup.d.ts +12 -6
  24. package/lib/engine/engine_setup.js +30 -22
  25. package/lib/engine/engine_setup.js.map +1 -1
  26. package/lib/engine/engine_types.d.ts +3 -1
  27. package/lib/engine/engine_types.js.map +1 -1
  28. package/lib/engine-components/Animation.d.ts +1 -0
  29. package/lib/engine-components/Animation.js +7 -0
  30. package/lib/engine-components/Animation.js.map +1 -1
  31. package/lib/engine-components/AnimatorController.js +14 -7
  32. package/lib/engine-components/AnimatorController.js.map +1 -1
  33. package/lib/engine-components/Camera.d.ts +2 -0
  34. package/lib/engine-components/Camera.js +24 -6
  35. package/lib/engine-components/Camera.js.map +1 -1
  36. package/lib/engine-components/CharacterController.d.ts +34 -0
  37. package/lib/engine-components/CharacterController.js +179 -0
  38. package/lib/engine-components/CharacterController.js.map +1 -0
  39. package/lib/engine-components/Collider.d.ts +10 -5
  40. package/lib/engine-components/Collider.js +18 -11
  41. package/lib/engine-components/Collider.js.map +1 -1
  42. package/lib/engine-components/Joints.d.ts +15 -0
  43. package/lib/engine-components/Joints.js +42 -0
  44. package/lib/engine-components/Joints.js.map +1 -0
  45. package/lib/engine-components/Light.d.ts +2 -0
  46. package/lib/engine-components/Light.js +13 -2
  47. package/lib/engine-components/Light.js.map +1 -1
  48. package/lib/engine-components/OrbitControls.js +1 -1
  49. package/lib/engine-components/OrbitControls.js.map +1 -1
  50. package/lib/engine-components/Renderer.js +4 -0
  51. package/lib/engine-components/Renderer.js.map +1 -1
  52. package/lib/engine-components/RigidBody.d.ts +6 -1
  53. package/lib/engine-components/RigidBody.js +62 -25
  54. package/lib/engine-components/RigidBody.js.map +1 -1
  55. package/lib/engine-components/SmoothFollow.d.ts +2 -1
  56. package/lib/engine-components/SmoothFollow.js +25 -17
  57. package/lib/engine-components/SmoothFollow.js.map +1 -1
  58. package/lib/engine-components/WebXR.js +3 -4
  59. package/lib/engine-components/WebXR.js.map +1 -1
  60. package/lib/engine-components/codegen/components.d.ts +4 -0
  61. package/lib/engine-components/codegen/components.js +4 -0
  62. package/lib/engine-components/codegen/components.js.map +1 -1
  63. package/package.json +1 -1
  64. package/src/engine/codegen/register_types.js +16 -0
  65. package/src/engine/dist/engine_physics.js +739 -0
  66. package/src/engine/dist/engine_setup.js +777 -0
  67. package/src/engine/engine_addressables.ts +18 -8
  68. package/src/engine/engine_element.ts +3 -2
  69. package/src/engine/engine_element_overlay.ts +4 -3
  70. package/src/engine/engine_input.ts +12 -3
  71. package/src/engine/engine_physics.ts +119 -57
  72. package/src/engine/engine_physics.types.ts +9 -0
  73. package/src/engine/engine_setup.ts +53 -45
  74. package/src/engine/engine_types.ts +4 -1
  75. package/src/engine-components/Animation.ts +8 -0
  76. package/src/engine-components/AnimatorController.ts +16 -11
  77. package/src/engine-components/Camera.ts +25 -5
  78. package/src/engine-components/CharacterController.ts +185 -0
  79. package/src/engine-components/Collider.ts +21 -15
  80. package/src/engine-components/Joints.ts +40 -0
  81. package/src/engine-components/Light.ts +17 -3
  82. package/src/engine-components/OrbitControls.ts +1 -1
  83. package/src/engine-components/Renderer.ts +5 -1
  84. package/src/engine-components/RigidBody.ts +63 -29
  85. package/src/engine-components/SmoothFollow.ts +21 -18
  86. package/src/engine-components/WebXR.ts +3 -4
  87. package/src/engine-components/codegen/components.ts +4 -0
  88. package/src/engine-components/dist/CharacterController.js +123 -0
  89. package/src/engine-components/dist/RigidBody.js +458 -0
  90. package/src/include/console/ConsoleReroute.js +79 -0
  91. package/src/include/draco/draco_decoder.js +48 -0
  92. package/src/include/draco/draco_decoder.wasm +0 -0
  93. package/src/include/ktx2/basis_transcoder.js +21 -0
  94. package/src/include/ktx2/basis_transcoder.wasm +0 -0
  95. package/src/include/three/ARButton.js +208 -0
  96. package/src/include/three/DragControls.js +232 -0
  97. package/src/include/three/EXT_mesh_gpu_instancing_exporter.js +67 -0
  98. package/src/include/three/VRButton.js +196 -0
  99. package/src/include/three-mesh-ui-assets/backspace.png +0 -0
  100. package/src/include/three-mesh-ui-assets/enter.png +0 -0
  101. package/src/include/three-mesh-ui-assets/shift.png +0 -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;
@@ -0,0 +1,79 @@
1
+ (function() {
2
+ const url = window.location.search;
3
+ const urlParams = new URLSearchParams(url);
4
+ if (!urlParams.has('debugconsole')) return;
5
+
6
+ const logNode = document.createElement("pre");
7
+ logNode.id = "log";
8
+ const logContainer = document.createElement("div");
9
+ logContainer.id = "log-container";
10
+ logContainer.appendChild(logNode);
11
+
12
+ window.addEventListener('DOMContentLoaded', (_) => {
13
+ const arOverlay = document.querySelector('.ar.overlay');
14
+ if(arOverlay)
15
+ arOverlay.appendChild(logContainer);
16
+ else
17
+ document.body.appendChild(logContainer);
18
+ });
19
+
20
+ rewireLoggingToElement(
21
+ () => logNode,
22
+ () => logContainer, true);
23
+
24
+ window.onError = function(message, source, lineno, colno, error) {
25
+ console.error(message, source, lineno, colno, error);
26
+ }
27
+
28
+ console.info("rewired console output");
29
+ console.info("User Agent: " + navigator.userAgent);
30
+
31
+ function rewireLoggingToElement(eleLocator, eleOverflowLocator, autoScroll) {
32
+ fixLoggingFunc('log');
33
+ fixLoggingFunc('debug');
34
+ fixLoggingFunc('warn');
35
+ fixLoggingFunc('error');
36
+ fixLoggingFunc('info');
37
+
38
+ function fixLoggingFunc(name) {
39
+ console['old' + name] = console[name];
40
+ console[name] = function(...args) {
41
+ const output = produceOutput(name, args);
42
+ const eleLog = eleLocator();
43
+
44
+ if (autoScroll) {
45
+ const eleContainerLog = eleOverflowLocator();
46
+ const isScrolledToBottom = eleContainerLog.scrollHeight - eleContainerLog.clientHeight <= eleContainerLog.scrollTop + 1;
47
+ eleLog.innerHTML += output + "<br>";
48
+ if (isScrolledToBottom) {
49
+ eleContainerLog.scrollTop = eleContainerLog.scrollHeight - eleContainerLog.clientHeight;
50
+ }
51
+ } else {
52
+ eleLog.innerHTML += output + "<br>";
53
+ }
54
+
55
+ console['old' + name].apply(undefined, args);
56
+ };
57
+ }
58
+
59
+ function produceOutput(name, args) {
60
+ return args.reduce((output, arg) => {
61
+ try {
62
+ return output +
63
+ "<span class=\"log-" + (typeof arg) + " log-" + name + "\">" +
64
+ (typeof arg === "object" && (JSON || {}).stringify ? JSON.stringify(arg) : arg) +
65
+ "</span>&nbsp;";
66
+ }
67
+ catch(ex) {
68
+ console.error("exception when logging: " + ex);
69
+ }
70
+ }, '');
71
+ }
72
+ }
73
+ /*
74
+ setInterval(() => {
75
+ const method = (['log', 'debug', 'warn', 'error', 'info'][Math.floor(Math.random() * 5)]);
76
+ console[method](method, 'logging something...');
77
+ }, 200);
78
+ */
79
+ })();