@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
|
@@ -1,45 +1,45 @@
|
|
|
1
|
-
import { Behaviour, GameObject } from "./Component";
|
|
2
|
-
import { Rigidbody } from "./RigidBody";
|
|
3
|
-
import * as CANNON from 'cannon-es'
|
|
4
|
-
import { Vector3 } from "three";
|
|
1
|
+
// import { Behaviour, GameObject } from "./Component";
|
|
2
|
+
// import { Rigidbody } from "./RigidBody";
|
|
3
|
+
// import * as CANNON from 'cannon-es'
|
|
4
|
+
// import { Vector3 } from "three";
|
|
5
5
|
|
|
6
|
-
export class SpringJoint extends Behaviour {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
// export class SpringJoint extends Behaviour {
|
|
7
|
+
// anchor: Vector3 | null = null;
|
|
8
|
+
// connectedBody: Rigidbody | null = null;
|
|
9
|
+
// connectedAnchor: Vector3 | null = null;
|
|
10
|
+
// spring: number = 10;
|
|
11
|
+
// damper: number = .2;
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
// private rb : Rigidbody | null = null;
|
|
14
14
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
15
|
+
// awake(): void {
|
|
16
|
+
// this.rb = GameObject.getComponent(this.gameObject, Rigidbody);
|
|
17
|
+
// if(!this.connectedBody || !this.connectedBody.body || !this.rb || !this.rb.body) return;
|
|
18
|
+
// this.connectedBody.body.mass = Math.min(this.rb.body.mass*.99, this.connectedBody.body.mass);
|
|
19
|
+
// const spring = new CANNON.Spring(this.rb.body, this.connectedBody.body, {
|
|
20
|
+
// // localAnchorA: new CANNON.Vec3(-1, 1, 0),
|
|
21
|
+
// // localAnchorB: new CANNON.Vec3(0, 0, 0),
|
|
22
|
+
// // restLength: -.1,
|
|
23
|
+
// // stiffness: 10,
|
|
24
|
+
// // damping: .2,
|
|
25
|
+
// restLength: 0.01,
|
|
26
|
+
// stiffness: this.spring*.5,
|
|
27
|
+
// damping: this.damper,
|
|
28
|
+
// // localAnchorA: new CANNON.Vec3(this.anchor.x, this.anchor.y, this.anchor.z),
|
|
29
|
+
// // localAnchorB: new CANNON.Vec3(
|
|
30
|
+
// // this.connectedAnchor.x,
|
|
31
|
+
// // this.connectedAnchor.y,
|
|
32
|
+
// // this.connectedAnchor.z
|
|
33
|
+
// // ),
|
|
34
|
+
// });
|
|
35
|
+
// this.context.physics.addPostStepListener(_ => {
|
|
36
|
+
// // const wp = this.connectedBody.worldPosition;
|
|
37
|
+
// // console.log(wp.y, this.connectedBody.body.position.y, this.rb.body.position.y);
|
|
38
|
+
// spring.applyForce();
|
|
39
|
+
// });
|
|
40
|
+
// }
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
42
|
+
// update(): void {
|
|
43
|
+
// // console.log(this.worldPosition.y)
|
|
44
|
+
// }
|
|
45
|
+
// }
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Behaviour, GameObject } from "./Component";
|
|
2
2
|
import * as THREE from "three";
|
|
3
|
-
import { Material } from "material/Material";
|
|
4
3
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
5
|
-
import { LinearFilter, Mesh, Object3D, RawShaderMaterial, ShaderMaterial, Texture, TextureLoader, Vector2, Vector4, VideoTexture } from "three";
|
|
4
|
+
import { LinearFilter, Material, Mesh, Object3D, RawShaderMaterial, ShaderMaterial, Texture, TextureLoader, Vector2, Vector4, VideoTexture } from "three";
|
|
6
5
|
import { awaitInput } from "../engine/engine_input_utils";
|
|
7
6
|
import { getParam } from "../engine/engine_utils";
|
|
8
7
|
import { Renderer } from "./Renderer";
|
|
@@ -461,6 +461,7 @@ export class WebAR {
|
|
|
461
461
|
private _webxr: WebXR;
|
|
462
462
|
|
|
463
463
|
private reticle: Object3D | null = null;
|
|
464
|
+
private reticleParent: Object3D | null = null;
|
|
464
465
|
private hitTestSource: XRHitTestSource | null = null;
|
|
465
466
|
private reticleActive: boolean = true;
|
|
466
467
|
|
|
@@ -504,6 +505,7 @@ export class WebAR {
|
|
|
504
505
|
const context = this.webxr.context;
|
|
505
506
|
this.reticleActive = true;
|
|
506
507
|
this.didPlaceARSessionRoot = false;
|
|
508
|
+
this.getAROverlayContainer();
|
|
507
509
|
|
|
508
510
|
const deviceType = navigator.userAgent?.includes("OculusBrowser") ? ControllerType.PhysicalDevice : ControllerType.Touch;
|
|
509
511
|
const controllerCount = deviceType === ControllerType.Touch ? 4 : 2;
|
|
@@ -535,9 +537,18 @@ export class WebAR {
|
|
|
535
537
|
this.reticle.name = "AR Placement reticle";
|
|
536
538
|
this.reticle.matrixAutoUpdate = false;
|
|
537
539
|
this.reticle.visible = false;
|
|
540
|
+
|
|
541
|
+
// create AR reticle parent to allow WebXRSessionRoot to be translated, rotated or scaled
|
|
542
|
+
this.reticleParent = new Object3D();
|
|
543
|
+
this.reticleParent.name = "AR Reticle Parent";
|
|
544
|
+
this.reticleParent.matrixAutoUpdate = false;
|
|
545
|
+
this.reticleParent.add(this.reticle);
|
|
546
|
+
this.reticleParent.matrix.copy(this.sessionRoot.gameObject.matrixWorld);
|
|
547
|
+
|
|
538
548
|
if (this.webxr.scene) {
|
|
539
|
-
this.
|
|
540
|
-
this.
|
|
549
|
+
this.context.scene.add(this.reticleParent);
|
|
550
|
+
// this.context.scene.add(this.reticle);
|
|
551
|
+
this.context.scene.visible = true;
|
|
541
552
|
}
|
|
542
553
|
else console.warn("Could not found WebXR Rig");
|
|
543
554
|
}
|
|
@@ -553,10 +564,8 @@ export class WebAR {
|
|
|
553
564
|
}
|
|
554
565
|
else console.warn("No WebARSessionRoot found in scene")
|
|
555
566
|
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
el.onEnterAR?.call(el, session, this.arOverlayElement);
|
|
559
|
-
}
|
|
567
|
+
const eng = this.context.domElement as INeedleEngineComponent;
|
|
568
|
+
eng?.onEnterAR?.call(eng, session, this.arOverlayElement!);
|
|
560
569
|
|
|
561
570
|
this.context.mainCameraComponent?.applyClearFlagsIfIsActiveCamera();
|
|
562
571
|
}
|
|
@@ -2,12 +2,14 @@ import { BoxHelper, BufferGeometry, Color, Euler, Group, Intersection, Layers, L
|
|
|
2
2
|
import { OculusHandModel } from 'three/examples/jsm/webxr/OculusHandModel.js';
|
|
3
3
|
import { OculusHandPointerModel } from 'three/examples/jsm/webxr/OculusHandPointerModel.js';
|
|
4
4
|
import { XRControllerModel, XRControllerModelFactory } from 'three/examples/jsm/webxr/XRControllerModelFactory.js';
|
|
5
|
+
import { GLTFLoader } from 'three/examples/jsm/loaders/GLTFLoader.js'
|
|
5
6
|
|
|
6
7
|
import { InstancingUtil } from "../engine/engine_instancing";
|
|
7
8
|
import { Mathf } from "../engine/engine_math";
|
|
8
9
|
import { RaycastOptions } from "../engine/engine_physics";
|
|
9
10
|
import { getWorldPosition, getWorldQuaternion, setWorldPosition, setWorldQuaternion } from "../engine/engine_three_utils";
|
|
10
11
|
import { getParam, getPath } from "../engine/engine_utils";
|
|
12
|
+
import { addDracoAndKTX2Loaders } from "../engine/engine_loaders";
|
|
11
13
|
|
|
12
14
|
import { Avatar_POI } from "./avatar/Avatar_Brain_LookAt";
|
|
13
15
|
import { Behaviour, GameObject } from "./Component";
|
|
@@ -79,9 +81,14 @@ export class WebXRController extends Behaviour {
|
|
|
79
81
|
ctrl.controllerGrip.add(ctrl.controllerModel);
|
|
80
82
|
|
|
81
83
|
ctrl.hand = context.renderer.xr.getHand(index);
|
|
82
|
-
|
|
84
|
+
|
|
85
|
+
const loader = new GLTFLoader();
|
|
86
|
+
addDracoAndKTX2Loaders(loader, context);
|
|
83
87
|
if (ctrl.webXR.handModelPath && ctrl.webXR.handModelPath !== "")
|
|
84
|
-
|
|
88
|
+
loader.setPath("/" + getPath(owner.sourceId, ctrl.webXR.handModelPath));
|
|
89
|
+
//@ts-ignore
|
|
90
|
+
const hand = new OculusHandModel(ctrl.hand, loader);
|
|
91
|
+
|
|
85
92
|
ctrl.hand.add(hand);
|
|
86
93
|
ctrl.hand.traverse(x => x.layers.set(2));
|
|
87
94
|
|
|
@@ -738,7 +745,7 @@ export class WebXRController extends Behaviour {
|
|
|
738
745
|
|
|
739
746
|
if (debug) {
|
|
740
747
|
if (!this.closeGrabBoundingBoxHelper && overlapCenter) {
|
|
741
|
-
this.closeGrabBoundingBoxHelper = new BoxHelper(
|
|
748
|
+
this.closeGrabBoundingBoxHelper = new BoxHelper(overlapCenter, 0xffff00);
|
|
742
749
|
this.scene.add(this.closeGrabBoundingBoxHelper);
|
|
743
750
|
}
|
|
744
751
|
|
|
@@ -825,7 +832,7 @@ export class AttachedObject {
|
|
|
825
832
|
return null;
|
|
826
833
|
}
|
|
827
834
|
else candidate = interactable.gameObject;
|
|
828
|
-
|
|
835
|
+
|
|
829
836
|
|
|
830
837
|
let objectToAttach = candidate;
|
|
831
838
|
const sync = GameObject.getComponentInParent(candidate, SyncedTransform);
|
|
@@ -981,12 +988,11 @@ export class AttachedObject {
|
|
|
981
988
|
this.sync = null;
|
|
982
989
|
|
|
983
990
|
|
|
984
|
-
// TODO:
|
|
991
|
+
// TODO: make throwing work again
|
|
985
992
|
if (this.rigidbodies) {
|
|
986
993
|
for (const rb of this.rigidbodies) {
|
|
987
994
|
rb.wakeUp();
|
|
988
|
-
|
|
989
|
-
rb.setVelocity(rb.smoothedVelocity.x, rb.smoothedVelocity.y, rb.smoothedVelocity.z);
|
|
995
|
+
rb.setVelocity(rb.smoothedVelocity);
|
|
990
996
|
}
|
|
991
997
|
}
|
|
992
998
|
this.rigidbodies = null;
|
|
@@ -1039,6 +1045,9 @@ export class AttachedObject {
|
|
|
1039
1045
|
}
|
|
1040
1046
|
|
|
1041
1047
|
public update() {
|
|
1048
|
+
if (this.rigidbodies)
|
|
1049
|
+
for (const rb of this.rigidbodies)
|
|
1050
|
+
rb.resetVelocities();
|
|
1042
1051
|
// TODO: add/use sync lost ownership event
|
|
1043
1052
|
if (this.sync && this.controller && this.controller.context.connection.isInRoom) {
|
|
1044
1053
|
const td = this.controller.context.time.time - this.grabTime;
|
|
@@ -13,9 +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";
|
|
21
|
+
export { MeshCollider } from "../Collider";
|
|
22
|
+
export { CapsuleCollider } from "../Collider";
|
|
19
23
|
export { DeleteBox } from "../DeleteBox";
|
|
20
24
|
export { Deletable } from "../DeleteBox";
|
|
21
25
|
export { DeviceFlag } from "../DeviceFlag";
|
|
@@ -38,8 +42,6 @@ export { Light } from "../Light";
|
|
|
38
42
|
export { LODModel } from "../LODGroup";
|
|
39
43
|
export { LODGroup } from "../LODGroup";
|
|
40
44
|
export { LookAtConstraint } from "../LookAtConstraint";
|
|
41
|
-
export { NavMesh } from "../NavMesh";
|
|
42
|
-
export { NavMeshAgent } from "../NavMesh";
|
|
43
45
|
export { NestedGltf } from "../NestedGltf";
|
|
44
46
|
export { Networking } from "../Networking";
|
|
45
47
|
export { OffsetConstraint } from "../OffsetConstraint";
|
|
@@ -64,7 +66,6 @@ export { SmoothFollow } from "../SmoothFollow";
|
|
|
64
66
|
export { SpatialTriggerReceiver } from "../SpatialTrigger";
|
|
65
67
|
export { SpatialTrigger } from "../SpatialTrigger";
|
|
66
68
|
export { SpectatorCamera } from "../SpectatorCamera";
|
|
67
|
-
export { SpringJoint } from "../SpringJoint";
|
|
68
69
|
export { Sprite } from "../SpriteRenderer";
|
|
69
70
|
export { SpriteRenderer } from "../SpriteRenderer";
|
|
70
71
|
export { SyncedCamera } from "../SyncedCamera";
|
|
@@ -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;
|