@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.
- package/CHANGELOG.md +21 -0
- package/dist/needle-engine.d.ts +118 -19
- package/dist/needle-engine.js +352 -352
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +25 -25
- package/dist/needle-engine.min.js.map +4 -4
- 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_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 +11 -4
- package/lib/engine/engine_physics.js +107 -42
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.d.ts +7 -0
- package/lib/engine/engine_physics.types.js +8 -0
- package/lib/engine/engine_physics.types.js.map +1 -1
- package/lib/engine/engine_setup.d.ts +12 -6
- package/lib/engine/engine_setup.js +30 -22
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_types.d.ts +3 -1
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +1 -0
- package/lib/engine-components/Animation.js +7 -0
- 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/Camera.d.ts +2 -0
- package/lib/engine-components/Camera.js +24 -6
- package/lib/engine-components/Camera.js.map +1 -1
- package/lib/engine-components/CharacterController.d.ts +34 -0
- package/lib/engine-components/CharacterController.js +179 -0
- package/lib/engine-components/CharacterController.js.map +1 -0
- package/lib/engine-components/Collider.d.ts +10 -5
- package/lib/engine-components/Collider.js +18 -11
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Joints.d.ts +15 -0
- package/lib/engine-components/Joints.js +42 -0
- package/lib/engine-components/Joints.js.map +1 -0
- 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/OrbitControls.js +1 -1
- package/lib/engine-components/OrbitControls.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 +6 -1
- package/lib/engine-components/RigidBody.js +62 -25
- 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/WebXR.js +3 -4
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +4 -0
- package/lib/engine-components/codegen/components.js +4 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/codegen/register_types.js +16 -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_input.ts +12 -3
- package/src/engine/engine_physics.ts +119 -57
- package/src/engine/engine_physics.types.ts +9 -0
- package/src/engine/engine_setup.ts +53 -45
- package/src/engine/engine_types.ts +4 -1
- package/src/engine-components/Animation.ts +8 -0
- package/src/engine-components/AnimatorController.ts +16 -11
- package/src/engine-components/Camera.ts +25 -5
- package/src/engine-components/CharacterController.ts +185 -0
- package/src/engine-components/Collider.ts +21 -15
- package/src/engine-components/Joints.ts +40 -0
- package/src/engine-components/Light.ts +17 -3
- package/src/engine-components/OrbitControls.ts +1 -1
- package/src/engine-components/Renderer.ts +5 -1
- package/src/engine-components/RigidBody.ts +63 -29
- package/src/engine-components/SmoothFollow.ts +21 -18
- package/src/engine-components/WebXR.ts +3 -4
- package/src/engine-components/codegen/components.ts +4 -0
- package/src/engine-components/dist/CharacterController.js +123 -0
- package/src/engine-components/dist/RigidBody.js +458 -0
- package/src/include/console/ConsoleReroute.js +79 -0
- package/src/include/draco/draco_decoder.js +48 -0
- package/src/include/draco/draco_decoder.wasm +0 -0
- package/src/include/ktx2/basis_transcoder.js +21 -0
- package/src/include/ktx2/basis_transcoder.wasm +0 -0
- package/src/include/three/ARButton.js +208 -0
- package/src/include/three/DragControls.js +232 -0
- package/src/include/three/EXT_mesh_gpu_instancing_exporter.js +67 -0
- package/src/include/three/VRButton.js +196 -0
- package/src/include/three-mesh-ui-assets/backspace.png +0 -0
- package/src/include/three-mesh-ui-assets/enter.png +0 -0
- package/src/include/three-mesh-ui-assets/shift.png +0 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Vector3 } from "three";
|
|
2
|
+
import { serializeable } from "../engine/engine_serialization";
|
|
3
|
+
import { Behaviour } from "./Component";
|
|
4
|
+
import { Rigidbody } from "./RigidBody";
|
|
5
|
+
|
|
6
|
+
export abstract class Joint extends Behaviour {
|
|
7
|
+
@serializeable(Rigidbody)
|
|
8
|
+
connectedBody?: Rigidbody;
|
|
9
|
+
|
|
10
|
+
get rigidBody(): Rigidbody | null {
|
|
11
|
+
return this._rigidBody;
|
|
12
|
+
}
|
|
13
|
+
private _rigidBody: Rigidbody | null = null;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@serializeable(Vector3)
|
|
17
|
+
connectedAnchor?: Vector3;
|
|
18
|
+
|
|
19
|
+
onEnable() {
|
|
20
|
+
if (!this._rigidBody) this._rigidBody = this.gameObject.getComponent(Rigidbody);
|
|
21
|
+
if (this.rigidBody && this.connectedBody)
|
|
22
|
+
this.startCoroutine(this.create());
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
private *create() {
|
|
26
|
+
yield;
|
|
27
|
+
if (this.rigidBody && this.connectedBody)
|
|
28
|
+
this.createJoint(this.rigidBody, this.connectedBody);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
protected abstract createJoint(self: Rigidbody, other: Rigidbody);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export class FixedJoint extends Joint {
|
|
35
|
+
|
|
36
|
+
protected createJoint(self: Rigidbody, other: Rigidbody) {
|
|
37
|
+
if (this.connectedAnchor)
|
|
38
|
+
this.context.physics.addFixedJoint(self, other, this.connectedAnchor);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -130,6 +130,9 @@ export class Light extends Behaviour implements ILight {
|
|
|
130
130
|
get shadowNormalBias(): number { return this._shadowNormalBias; }
|
|
131
131
|
private _shadowNormalBias: number = 1;
|
|
132
132
|
|
|
133
|
+
/** when enabled this will remove the multiplication when setting the shadow bias settings initially */
|
|
134
|
+
private _overrideShadowBiasSettings: boolean = false;
|
|
135
|
+
|
|
133
136
|
@serializeable()
|
|
134
137
|
set shadows(val: LightShadows) {
|
|
135
138
|
this._shadows = val;
|
|
@@ -338,7 +341,7 @@ export class Light extends Behaviour implements ILight {
|
|
|
338
341
|
|
|
339
342
|
if (this.light !== undefined) {
|
|
340
343
|
this._intensity = this.light.intensity;
|
|
341
|
-
|
|
344
|
+
|
|
342
345
|
if (this.shadows !== LightShadows.None) {
|
|
343
346
|
this.light.castShadow = true;
|
|
344
347
|
}
|
|
@@ -353,8 +356,19 @@ export class Light extends Behaviour implements ILight {
|
|
|
353
356
|
this.light.shadow.mapSize.width = 2048;
|
|
354
357
|
this.light.shadow.mapSize.height = 2048;
|
|
355
358
|
}
|
|
356
|
-
|
|
357
|
-
|
|
359
|
+
|
|
360
|
+
if (debug)
|
|
361
|
+
console.log("Override shadow bias?", this._overrideShadowBiasSettings, this.shadowBias, this.shadowNormalBias);
|
|
362
|
+
|
|
363
|
+
// shadow bias settings
|
|
364
|
+
if (this._overrideShadowBiasSettings === true) {
|
|
365
|
+
this.light.shadow.bias = this.shadowBias;
|
|
366
|
+
this.light.shadow.normalBias = this.shadowNormalBias;
|
|
367
|
+
}
|
|
368
|
+
else {
|
|
369
|
+
this.light.shadow.bias = this.shadowBias * 0.00001;
|
|
370
|
+
this.light.shadow.normalBias = this.shadowNormalBias * .0001;
|
|
371
|
+
}
|
|
358
372
|
|
|
359
373
|
// console.log(this.light.shadow, this);
|
|
360
374
|
const cam = this.light.shadow.camera as THREE.OrthographicCamera;
|
|
@@ -213,7 +213,7 @@ export class OrbitControls extends Behaviour {
|
|
|
213
213
|
if (this.lookAtConstraint?.locked) this.setFromTargetPosition(0, this.lookAtConstraint01);
|
|
214
214
|
|
|
215
215
|
|
|
216
|
-
if (this._controls) {
|
|
216
|
+
if (this._controls && !this.context.isInXR) {
|
|
217
217
|
if (this.debugLog)
|
|
218
218
|
this._controls.domElement = this.context.renderer.domElement;
|
|
219
219
|
this._controls.enabled = true;
|
|
@@ -5,7 +5,7 @@ import { RendererLightmap } from "./RendererLightmap";
|
|
|
5
5
|
import { Context } from "../engine/engine_setup";
|
|
6
6
|
import { getParam } from "../engine/engine_utils";
|
|
7
7
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
8
|
-
import { AxesHelper, Material, Mesh, Object3D, Texture, Vector4 } from "three";
|
|
8
|
+
import { AxesHelper, Material, Mesh, Object3D, SkinnedMesh, Texture, Vector4 } from "three";
|
|
9
9
|
import { NEEDLE_render_objects } from "../engine/extensions/NEEDLE_render_objects";
|
|
10
10
|
import { NEEDLE_deferred_texture } from "../engine/extensions/NEEDLE_deferred_texture";
|
|
11
11
|
import { NEED_UPDATE_INSTANCE_KEY } from "../engine/engine_instancing";
|
|
@@ -67,6 +67,7 @@ class SharedMaterialArray implements ISharedMaterials {
|
|
|
67
67
|
case "Group":
|
|
68
68
|
this._targets = [...go.children];
|
|
69
69
|
break;
|
|
70
|
+
case "SkinnedMesh":
|
|
70
71
|
case "Mesh":
|
|
71
72
|
this._targets.push(go);
|
|
72
73
|
break;
|
|
@@ -155,6 +156,9 @@ export class Renderer extends Behaviour implements IRenderer {
|
|
|
155
156
|
if (this.gameObject.type === "Mesh") {
|
|
156
157
|
return this.gameObject as unknown as Mesh
|
|
157
158
|
}
|
|
159
|
+
else if (this.gameObject.type === "SkinnesMesh") {
|
|
160
|
+
return this.gameObject as unknown as SkinnedMesh;
|
|
161
|
+
}
|
|
158
162
|
else if (this.gameObject.type === "Group") {
|
|
159
163
|
return this.gameObject.children[0] as unknown as Mesh;
|
|
160
164
|
}
|
|
@@ -7,7 +7,7 @@ import { Object3D, Vector3 } from "three";
|
|
|
7
7
|
import { IRigidbody } from "../engine/engine_types";
|
|
8
8
|
import { CollisionDetectionMode, RigidbodyConstraints } from "../engine/engine_physics.types";
|
|
9
9
|
import { validate } from "../engine/engine_util_decorator";
|
|
10
|
-
import { Context } from "../engine/engine_setup";
|
|
10
|
+
import { Context, FrameEvent } from "../engine/engine_setup";
|
|
11
11
|
|
|
12
12
|
class TransformWatch {
|
|
13
13
|
|
|
@@ -16,23 +16,48 @@ class TransformWatch {
|
|
|
16
16
|
}
|
|
17
17
|
positionChanged: boolean = false;
|
|
18
18
|
rotationChanged: boolean = false;
|
|
19
|
-
position?: Vector3;
|
|
20
|
-
quaternion?: THREE.Quaternion;
|
|
21
19
|
|
|
22
|
-
|
|
20
|
+
position?: { x?: number, y?: number, z?: number };
|
|
21
|
+
quaternion?: { _x?: number, _y?: number, _z?: number, _w?: number };
|
|
22
|
+
|
|
23
|
+
private _positionKeys: string[] = ["x", "y", "z"];
|
|
24
|
+
private _quaternionKeys: string[] = ["_x", "_y", "_z", "_w"];
|
|
25
|
+
|
|
26
|
+
reset(clearPreviousValues: boolean = false) {
|
|
23
27
|
this.positionChanged = false;
|
|
24
28
|
this.rotationChanged = false;
|
|
25
29
|
this.mute = false;
|
|
30
|
+
|
|
31
|
+
if (clearPreviousValues) {
|
|
32
|
+
if (this.position)
|
|
33
|
+
for (const key of this._positionKeys)
|
|
34
|
+
delete this.position[key];
|
|
35
|
+
if (this.quaternion)
|
|
36
|
+
for (const key of this._quaternionKeys)
|
|
37
|
+
delete this.quaternion[key];
|
|
38
|
+
}
|
|
26
39
|
}
|
|
27
40
|
|
|
28
41
|
mute: boolean = false;
|
|
29
42
|
|
|
30
43
|
applyValues() {
|
|
31
|
-
|
|
32
|
-
|
|
44
|
+
// only apply the values that actually changed
|
|
45
|
+
// since we want to still control all the other values via physics
|
|
46
|
+
if (this.positionChanged && this.position) {
|
|
47
|
+
for (const key of this._positionKeys) {
|
|
48
|
+
const val = this.position[key];
|
|
49
|
+
if (val !== undefined)
|
|
50
|
+
this.obj.position[key] = val;
|
|
51
|
+
}
|
|
33
52
|
}
|
|
34
53
|
if (this.rotationChanged) {
|
|
35
|
-
|
|
54
|
+
if (this.quaternion) {
|
|
55
|
+
for (const key of this._quaternionKeys) {
|
|
56
|
+
const val = this.quaternion[key];
|
|
57
|
+
if (val !== undefined)
|
|
58
|
+
this.obj.quaternion[key] = val;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
36
61
|
}
|
|
37
62
|
}
|
|
38
63
|
|
|
@@ -52,26 +77,28 @@ class TransformWatch {
|
|
|
52
77
|
if (!this._positionWatch)
|
|
53
78
|
this._positionWatch = new Watch(this.obj.position, ["x", "y", "z"]);
|
|
54
79
|
this._positionWatch.apply();
|
|
55
|
-
this.position =
|
|
80
|
+
this.position = {};
|
|
81
|
+
// this.position = this.obj.position.clone();
|
|
56
82
|
this._positionWatch.subscribeWrite((val, prop) => {
|
|
57
83
|
if (this.context.physics.isUpdating || this.mute) return;
|
|
58
|
-
|
|
84
|
+
const prev = this.position![prop];
|
|
85
|
+
if (Math.abs(prev - val) < .00001) return;
|
|
59
86
|
this.position![prop] = val;
|
|
60
87
|
this.positionChanged = true;
|
|
61
|
-
// }
|
|
62
88
|
})
|
|
63
89
|
}
|
|
64
90
|
if (rotation) {
|
|
65
91
|
if (!this._rotationWatch)
|
|
66
92
|
this._rotationWatch = new Watch(this.obj.quaternion, ["_x", "_y", "_z", "_w"]);
|
|
67
93
|
this._rotationWatch.apply();
|
|
68
|
-
this.quaternion =
|
|
94
|
+
this.quaternion = {};
|
|
95
|
+
// this.quaternion = this.obj.quaternion.clone();
|
|
69
96
|
this._rotationWatch.subscribeWrite((val, prop) => {
|
|
70
97
|
if (this.context.physics.isUpdating || this.mute) return;
|
|
71
|
-
|
|
98
|
+
const prev = this.quaternion![prop];
|
|
99
|
+
if (Math.abs(prev - val) < .00001) return;
|
|
72
100
|
this.quaternion![prop] = val;
|
|
73
101
|
this.rotationChanged = true;
|
|
74
|
-
// }
|
|
75
102
|
})
|
|
76
103
|
}
|
|
77
104
|
}
|
|
@@ -188,6 +215,7 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
188
215
|
this._watch = new TransformWatch(this.gameObject, this.context);
|
|
189
216
|
}
|
|
190
217
|
this._watch.start(true, true);
|
|
218
|
+
this.startCoroutine(this.beforePhysics(), FrameEvent.LateUpdate);
|
|
191
219
|
}
|
|
192
220
|
|
|
193
221
|
onDisable() {
|
|
@@ -203,29 +231,35 @@ export class Rigidbody extends Behaviour implements IRigidbody {
|
|
|
203
231
|
this._propertiesChanged = true;
|
|
204
232
|
}
|
|
205
233
|
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
this.
|
|
234
|
+
// need to do this right before updating physics to prevent rendered object glitching through physical bodies
|
|
235
|
+
*beforePhysics() {
|
|
236
|
+
while (true) {
|
|
237
|
+
if (this._propertiesChanged) {
|
|
238
|
+
this._propertiesChanged = false;
|
|
239
|
+
this.context.physics.updateProperties(this);
|
|
240
|
+
}
|
|
241
|
+
if (this._watch?.isDirty) {
|
|
242
|
+
this._watch.mute = true;
|
|
243
|
+
this._watch.applyValues();
|
|
244
|
+
this.context.physics.updateBody(this, this._watch.positionChanged, this._watch.rotationChanged);
|
|
245
|
+
this._watch.reset();
|
|
246
|
+
}
|
|
247
|
+
this.captureVelocity();
|
|
248
|
+
yield;
|
|
210
249
|
}
|
|
211
|
-
if (this._watch?.isDirty) {
|
|
212
|
-
this._watch.mute = true;
|
|
213
|
-
this._watch.applyValues();
|
|
214
|
-
this.context.physics.updateBody(this, this._watch.positionChanged, this._watch.rotationChanged);
|
|
215
|
-
this._watch.reset();
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
this.captureVelocity();
|
|
219
250
|
}
|
|
220
251
|
|
|
221
252
|
private get body() {
|
|
222
253
|
return this.context.physics.internal_getRigidbody(this);
|
|
223
254
|
}
|
|
224
255
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
256
|
+
public teleport(pt: { x: number, y: number, z: number }, localspace:boolean = true) {
|
|
257
|
+
this._watch?.reset(true);
|
|
258
|
+
if(localspace) this.gameObject.position.set(pt.x, pt.y, pt.z);
|
|
259
|
+
else this.setWorldPosition(pt.x, pt.y, pt.z);
|
|
260
|
+
this.resetForcesAndTorques();
|
|
261
|
+
this.resetVelocities();
|
|
262
|
+
}
|
|
229
263
|
|
|
230
264
|
public resetForces() {
|
|
231
265
|
this.body?.resetForces(true);
|
|
@@ -1,53 +1,56 @@
|
|
|
1
1
|
import { Camera } from "./Camera";
|
|
2
2
|
import { Behaviour, GameObject } from "./Component";
|
|
3
|
-
import * as utils from "../engine/engine_three_utils";
|
|
4
3
|
import * as THREE from "three";
|
|
5
4
|
import { Mathf } from "../engine/engine_math";
|
|
6
5
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
7
6
|
import { Object3D } from "three";
|
|
7
|
+
import { getWorldPosition, getWorldQuaternion } from "../engine/engine_three_utils";
|
|
8
|
+
import { Axes } from "../engine/engine_physics.types";
|
|
8
9
|
|
|
9
10
|
export class SmoothFollow extends Behaviour {
|
|
10
11
|
|
|
11
12
|
@serializeable(Object3D)
|
|
12
13
|
target: THREE.Object3D | null = null;
|
|
13
14
|
|
|
15
|
+
@serializeable()
|
|
14
16
|
followFactor = .1;
|
|
17
|
+
@serializeable()
|
|
15
18
|
rotateFactor = .1;
|
|
16
19
|
|
|
17
|
-
|
|
20
|
+
@serializeable()
|
|
21
|
+
positionAxes : Axes = Axes.All;
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
23
|
+
// @serializeable()
|
|
24
|
+
// rotationAxes : Axes = Axes.All;
|
|
21
25
|
|
|
26
|
+
flipForward: boolean = false;
|
|
27
|
+
|
|
28
|
+
private static _invertForward: THREE.Quaternion = new THREE.Quaternion().setFromAxisAngle(new THREE.Vector3(0, 1, 0), Math.PI);
|
|
29
|
+
private _firstUpdate = true;
|
|
22
30
|
|
|
23
|
-
onEnable(): void {
|
|
24
|
-
const cam = GameObject.getComponentInChildren(this.gameObject, Camera) as Camera;
|
|
25
|
-
if (cam && cam.cam) {
|
|
26
|
-
cam.gameObject.position.set(0, 0, 0);
|
|
27
|
-
cam.cam.position.set(0, 0, 0);
|
|
28
|
-
cam.gameObject.quaternion.identity();
|
|
29
|
-
cam.cam.quaternion.setFromEuler(new THREE.Euler(0, Math.PI, 0));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
31
|
|
|
33
32
|
onBeforeRender(): void {
|
|
34
|
-
if (this.followFactor <= 0) return;
|
|
35
33
|
this.updateNow(false);
|
|
36
34
|
}
|
|
37
35
|
|
|
38
36
|
updateNow(hard: boolean) {
|
|
39
37
|
if (!this.target || this.target === this.gameObject) return;
|
|
40
38
|
if (this.followFactor > 0) {
|
|
41
|
-
const wp =
|
|
39
|
+
const wp = getWorldPosition(this.target);
|
|
42
40
|
const fpos = this._firstUpdate || hard ? 1 : Mathf.clamp01(this.context.time.deltaTime * this.followFactor);
|
|
43
|
-
|
|
41
|
+
const currentPosition = this.worldPosition;
|
|
42
|
+
if(this.positionAxes & Axes.X) currentPosition.x = Mathf.lerp(currentPosition.x, wp.x, fpos);
|
|
43
|
+
if(this.positionAxes & Axes.Y) currentPosition.y = Mathf.lerp(currentPosition.y, wp.y, fpos);
|
|
44
|
+
if(this.positionAxes & Axes.Z) currentPosition.z = Mathf.lerp(currentPosition.z, wp.z, fpos);
|
|
45
|
+
this.worldPosition = currentPosition;
|
|
44
46
|
}
|
|
45
47
|
if (this.rotateFactor > 0) {
|
|
46
|
-
const wr =
|
|
47
|
-
if(this.flipForward){
|
|
48
|
+
const wr = getWorldQuaternion(this.target);
|
|
49
|
+
if (this.flipForward) {
|
|
48
50
|
wr.premultiply(SmoothFollow._invertForward);
|
|
49
51
|
}
|
|
50
52
|
const frot = this._firstUpdate || hard ? 1 : Mathf.clamp01(this.context.time.deltaTime * this.rotateFactor);
|
|
53
|
+
|
|
51
54
|
this.worldQuaternion = this.worldQuaternion.slerp(wr, frot);
|
|
52
55
|
}
|
|
53
56
|
this._firstUpdate = false;
|
|
@@ -505,6 +505,7 @@ export class WebAR {
|
|
|
505
505
|
const context = this.webxr.context;
|
|
506
506
|
this.reticleActive = true;
|
|
507
507
|
this.didPlaceARSessionRoot = false;
|
|
508
|
+
this.getAROverlayContainer();
|
|
508
509
|
|
|
509
510
|
const deviceType = navigator.userAgent?.includes("OculusBrowser") ? ControllerType.PhysicalDevice : ControllerType.Touch;
|
|
510
511
|
const controllerCount = deviceType === ControllerType.Touch ? 4 : 2;
|
|
@@ -563,10 +564,8 @@ export class WebAR {
|
|
|
563
564
|
}
|
|
564
565
|
else console.warn("No WebARSessionRoot found in scene")
|
|
565
566
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
el.onEnterAR?.call(el, session, this.arOverlayElement);
|
|
569
|
-
}
|
|
567
|
+
const eng = this.context.domElement as INeedleEngineComponent;
|
|
568
|
+
eng?.onEnterAR?.call(eng, session, this.arOverlayElement!);
|
|
570
569
|
|
|
571
570
|
this.context.mainCameraComponent?.applyClearFlagsIfIsActiveCamera();
|
|
572
571
|
}
|
|
@@ -13,10 +13,13 @@ export { AxesHelper } from "../AxesHelper";
|
|
|
13
13
|
export { BasicIKConstraint } from "../BasicIKConstraint";
|
|
14
14
|
export { BoxHelperComponent } from "../BoxHelperComponent";
|
|
15
15
|
export { Camera } from "../Camera";
|
|
16
|
+
export { CharacterController } from "../CharacterController";
|
|
17
|
+
export { CharacterControllerInput } from "../CharacterController";
|
|
16
18
|
export { Collider } from "../Collider";
|
|
17
19
|
export { SphereCollider } from "../Collider";
|
|
18
20
|
export { BoxCollider } from "../Collider";
|
|
19
21
|
export { MeshCollider } from "../Collider";
|
|
22
|
+
export { CapsuleCollider } from "../Collider";
|
|
20
23
|
export { DeleteBox } from "../DeleteBox";
|
|
21
24
|
export { Deletable } from "../DeleteBox";
|
|
22
25
|
export { DeviceFlag } from "../DeviceFlag";
|
|
@@ -35,6 +38,7 @@ export { GridHelper } from "../GridHelper";
|
|
|
35
38
|
export { GroundProjectedEnv } from "../GroundProjection";
|
|
36
39
|
export { Interactable } from "../Interactable";
|
|
37
40
|
export { UsageMarker } from "../Interactable";
|
|
41
|
+
export { FixedJoint } from "../Joints";
|
|
38
42
|
export { Light } from "../Light";
|
|
39
43
|
export { LODModel } from "../LODGroup";
|
|
40
44
|
export { LODGroup } from "../LODGroup";
|
|
@@ -0,0 +1,123 @@
|
|
|
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;
|