@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
|
@@ -7,6 +7,7 @@ import { RGBAColor } from "./js-extensions/RGBAColor";
|
|
|
7
7
|
import { PerspectiveCamera } from "three";
|
|
8
8
|
import { XRSessionMode } from "../engine/engine_setup";
|
|
9
9
|
import { ICamera } from "../engine/engine_types"
|
|
10
|
+
import { showBalloonMessage } from "../engine/debug/debug";
|
|
10
11
|
|
|
11
12
|
export enum ClearFlags {
|
|
12
13
|
Skybox = 1,
|
|
@@ -127,6 +128,10 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
127
128
|
this.applyClearFlagsIfIsActiveCamera();
|
|
128
129
|
}
|
|
129
130
|
|
|
131
|
+
onDisable() {
|
|
132
|
+
this.context.removeCamera(this);
|
|
133
|
+
}
|
|
134
|
+
|
|
130
135
|
buildCamera() {
|
|
131
136
|
if (this._cam) return;
|
|
132
137
|
|
|
@@ -168,6 +173,8 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
168
173
|
}
|
|
169
174
|
|
|
170
175
|
applyClearFlagsIfIsActiveCamera() {
|
|
176
|
+
if (debug)
|
|
177
|
+
showBalloonMessage("apply Camera clear flags");
|
|
171
178
|
if (this._cam && this.context.mainCameraComponent === this) {
|
|
172
179
|
switch (this._clearFlags) {
|
|
173
180
|
case ClearFlags.Skybox:
|
|
@@ -203,12 +210,22 @@ export class Camera extends Behaviour implements ICamera {
|
|
|
203
210
|
const session = this.context.renderer.xr?.getSession();
|
|
204
211
|
if (!session) return false;
|
|
205
212
|
const environmentBlendMode = session.environmentBlendMode;
|
|
213
|
+
if (debug)
|
|
214
|
+
showBalloonMessage("Environment blend mode: " + environmentBlendMode + " on " + navigator.userAgent);
|
|
206
215
|
const transparent = environmentBlendMode === 'additive' || environmentBlendMode === 'alpha-blend';
|
|
207
|
-
// workaround for Quest 2 returning opaque when it should be alpha-blend
|
|
208
|
-
// check user agent if this is the Quest browser and return true if so
|
|
209
216
|
|
|
210
|
-
if (
|
|
211
|
-
if (
|
|
217
|
+
if (this.context.xrSessionMode === XRSessionMode.ImmersiveAR) {
|
|
218
|
+
if (environmentBlendMode === "opaque") {
|
|
219
|
+
// workaround for Quest 2 returning opaque when it should be alpha-blend
|
|
220
|
+
// check user agent if this is the Quest browser and return true if so
|
|
221
|
+
if (navigator.userAgent?.includes("OculusBrowser")) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
// Mozilla WebXR Viewer
|
|
225
|
+
else if (navigator.userAgent?.includes("Mozilla") && navigator.userAgent?.includes("Mobile WebXRViewer/v2")) {
|
|
226
|
+
return true;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
212
229
|
}
|
|
213
230
|
return transparent;
|
|
214
231
|
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import { Ray, Vector3 } from "three";
|
|
2
|
+
import { Mathf } from "../engine/engine_math";
|
|
3
|
+
import { serializeable } from "../engine/engine_serialization";
|
|
4
|
+
import { Collision } from "../engine/engine_types";
|
|
5
|
+
import { CapsuleCollider } from "./Collider";
|
|
6
|
+
import { Behaviour, GameObject } from "./Component";
|
|
7
|
+
import { Rigidbody } from "./RigidBody";
|
|
8
|
+
import { Animator } from "./Animator"
|
|
9
|
+
import { RaycastOptions } from "../engine/engine_physics";
|
|
10
|
+
import { getWorldPosition } from "../engine/engine_three_utils";
|
|
11
|
+
|
|
12
|
+
export class CharacterController extends Behaviour {
|
|
13
|
+
|
|
14
|
+
@serializeable(Vector3)
|
|
15
|
+
center: Vector3 = new Vector3(0, 0, 0);
|
|
16
|
+
@serializeable()
|
|
17
|
+
radius: number = .5;
|
|
18
|
+
@serializeable()
|
|
19
|
+
height: number = 2;
|
|
20
|
+
|
|
21
|
+
private _rigidbody: Rigidbody | null = null;
|
|
22
|
+
get rigidbody(): Rigidbody {
|
|
23
|
+
if (this._rigidbody) return this._rigidbody;
|
|
24
|
+
this._rigidbody = this.gameObject.getComponent(Rigidbody);
|
|
25
|
+
if (!this._rigidbody)
|
|
26
|
+
this._rigidbody = this.gameObject.addNewComponent(Rigidbody) as Rigidbody;
|
|
27
|
+
return this.rigidbody;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onEnable() {
|
|
31
|
+
let rb = this.rigidbody;
|
|
32
|
+
let collider = this.gameObject.getComponent(CapsuleCollider);
|
|
33
|
+
if (!collider)
|
|
34
|
+
collider = this.gameObject.addNewComponent(CapsuleCollider) as CapsuleCollider;
|
|
35
|
+
// rb.isKinematic = true;
|
|
36
|
+
collider.center.copy(this.center);
|
|
37
|
+
collider.radius = this.radius;
|
|
38
|
+
collider.height = this.height;
|
|
39
|
+
this.gameObject.rotation.x = 0;
|
|
40
|
+
this.gameObject.rotation.z = 0;
|
|
41
|
+
rb.lockRotationX = true;
|
|
42
|
+
rb.lockRotationY = true;
|
|
43
|
+
rb.lockRotationZ = true;
|
|
44
|
+
|
|
45
|
+
// TODO: this doesnt work yet
|
|
46
|
+
// setInterval(()=>{
|
|
47
|
+
// this.rigidbody.isKinematic = !this.rigidbody.isKinematic;
|
|
48
|
+
// console.log(this.rigidbody.isKinematic);
|
|
49
|
+
// }, 1000)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
move(vec: Vector3) {
|
|
53
|
+
this.gameObject.position.add(vec);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
private _activeGroundCollisions: Set<Collision> = new Set();
|
|
57
|
+
|
|
58
|
+
onCollisionEnter(col: Collision) {
|
|
59
|
+
for (const contact of col.contacts) {
|
|
60
|
+
// console.log(contact.normal);
|
|
61
|
+
if (contact.normal.y > .1) {
|
|
62
|
+
this._activeGroundCollisions.add(col);
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
onCollisionExit(col: Collision) {
|
|
69
|
+
this._activeGroundCollisions.delete(col);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get isGrounded(): boolean { return this._activeGroundCollisions.size > 0; }
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export class CharacterControllerInput extends Behaviour {
|
|
76
|
+
|
|
77
|
+
@serializeable(CharacterController)
|
|
78
|
+
controller?: CharacterController;
|
|
79
|
+
|
|
80
|
+
@serializeable()
|
|
81
|
+
movementSpeed: number = 2;
|
|
82
|
+
|
|
83
|
+
@serializeable()
|
|
84
|
+
rotationSpeed: number = 2;
|
|
85
|
+
|
|
86
|
+
@serializeable()
|
|
87
|
+
jumpForce: number = 1;
|
|
88
|
+
|
|
89
|
+
@serializeable(Animator)
|
|
90
|
+
animator?: Animator;
|
|
91
|
+
|
|
92
|
+
private _currentSpeed: Vector3 = new Vector3(0, 0, 0);
|
|
93
|
+
private _currentAngularSpeed: Vector3 = new Vector3(0, 0, 0);
|
|
94
|
+
|
|
95
|
+
private _temp: Vector3 = new Vector3(0, 0, 0);
|
|
96
|
+
private _jumpCount: number = 0;
|
|
97
|
+
|
|
98
|
+
update() {
|
|
99
|
+
|
|
100
|
+
if (this.controller?.isGrounded) {
|
|
101
|
+
this._jumpCount = 0;
|
|
102
|
+
this.animator?.SetBool("doubleJump", false);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
const forward = this.context.input.isKeyPressed("w");
|
|
106
|
+
const backward = this.context.input.isKeyPressed("s");
|
|
107
|
+
const rotateLeft = this.context.input.isKeyPressed("a");
|
|
108
|
+
const rotateRight = this.context.input.isKeyPressed("d");
|
|
109
|
+
const jump = this.context.input.isKeyDown(" ");
|
|
110
|
+
// if (jumpDown) this._jumpDownTime = this.context.time.time;
|
|
111
|
+
// const jumpUp = this.context.input.isKeyUp(" ");
|
|
112
|
+
|
|
113
|
+
const step = forward ? 1 : 0 + backward ? -1 : 0;
|
|
114
|
+
this._currentSpeed.z += step * this.movementSpeed * this.context.time.deltaTime;
|
|
115
|
+
|
|
116
|
+
// if (!this.controller || this.controller.isGrounded)
|
|
117
|
+
this.animator?.SetBool("running", step != 0);
|
|
118
|
+
this.animator?.SetBool("jumping", this.controller?.isGrounded === true && jump);
|
|
119
|
+
|
|
120
|
+
this._temp.copy(this._currentSpeed);
|
|
121
|
+
this._temp.applyQuaternion(this.gameObject.quaternion);
|
|
122
|
+
if (this.controller) this.controller.move(this._temp);
|
|
123
|
+
else this.gameObject.position.add(this._temp);
|
|
124
|
+
|
|
125
|
+
const rotation = rotateLeft ? 1 : 0 + rotateRight ? -1 : 0;
|
|
126
|
+
this._currentAngularSpeed.y += Mathf.toRadians(rotation * this.rotationSpeed) * this.context.time.deltaTime;
|
|
127
|
+
this.gameObject.rotateY(this._currentAngularSpeed.y);
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
this._currentSpeed.multiplyScalar(1 - this.context.time.deltaTime * 10);
|
|
131
|
+
this._currentAngularSpeed.y *= 1 - this.context.time.deltaTime * 10;
|
|
132
|
+
|
|
133
|
+
if (this.controller && jump && this.jumpForce > 0) {
|
|
134
|
+
let canJump = this.controller?.isGrounded;
|
|
135
|
+
if (!this.controller?.isGrounded && this._jumpCount === 1) {
|
|
136
|
+
canJump = true;
|
|
137
|
+
this.animator?.SetBool("doubleJump", true);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (canJump) {
|
|
141
|
+
this._jumpCount += 1;
|
|
142
|
+
// TODO: factor in mass
|
|
143
|
+
const rb = this.controller.rigidbody;
|
|
144
|
+
// const fullJumpHoldLength = .1;
|
|
145
|
+
const factor = this._jumpCount === 2 ? 2 : 1;// Mathf.clamp((this.context.time.time - this._jumpDownTime), 0, fullJumpHoldLength) / fullJumpHoldLength;
|
|
146
|
+
rb.applyImpulse(new Vector3(0, 1, 0).multiplyScalar(this.jumpForce * factor));
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
if (this.controller) {
|
|
151
|
+
// TODO: should probably raycast to the ground or check if we're still in the jump animation
|
|
152
|
+
const verticalSpeed = this.controller?.rigidbody.getVelocity().y;
|
|
153
|
+
if (verticalSpeed < -1) {
|
|
154
|
+
if (!this._raycastOptions.ray) this._raycastOptions.ray = new Ray();
|
|
155
|
+
this._raycastOptions.ray.origin.copy(getWorldPosition(this.gameObject));
|
|
156
|
+
this._raycastOptions.ray.direction.set(0, -1, 0);
|
|
157
|
+
const currentLayer = this.layer;
|
|
158
|
+
this.gameObject.layers.disableAll();
|
|
159
|
+
this.gameObject.layers.set(2);
|
|
160
|
+
const hits = this.context.physics.raycast(this._raycastOptions);
|
|
161
|
+
this.gameObject.layers.set(currentLayer);
|
|
162
|
+
if ((hits.length && hits[0].distance > 2 || verticalSpeed < -10)) {
|
|
163
|
+
this.animator?.SetBool("falling", true);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
else this.animator?.SetBool("falling", false);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
private _raycastOptions = new RaycastOptions();
|
|
171
|
+
}
|
|
@@ -1,18 +1,10 @@
|
|
|
1
1
|
import { Behaviour } from "./Component";
|
|
2
2
|
import { Rigidbody } from "./RigidBody";
|
|
3
3
|
import { serializeable } from "../engine/engine_serialization_decorator";
|
|
4
|
-
import { Event, Object3D, Vector3 } from "three"
|
|
5
|
-
import {
|
|
6
|
-
import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
|
|
4
|
+
import { Event, Mesh, Object3D, Vector3 } from "three"
|
|
5
|
+
// import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
|
|
7
6
|
import { ICollider } from "../engine/engine_types";
|
|
8
|
-
import { getComponentInChildren } from "../engine/engine_components";
|
|
9
7
|
|
|
10
|
-
class ColliderProvider implements IColliderProvider {
|
|
11
|
-
getCollider(obj: Object3D): ICollider {
|
|
12
|
-
return getComponentInChildren<Collider>(obj, Collider);
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
registerColliderProvider(new ColliderProvider());
|
|
16
8
|
|
|
17
9
|
export class Collider extends Behaviour implements ICollider {
|
|
18
10
|
|
|
@@ -25,14 +17,14 @@ export class Collider extends Behaviour implements ICollider {
|
|
|
25
17
|
@serializeable()
|
|
26
18
|
isTrigger: boolean = false;
|
|
27
19
|
|
|
28
|
-
protected _shape: Shape | null = null;
|
|
29
20
|
|
|
30
21
|
awake() {
|
|
31
22
|
super.awake();
|
|
32
|
-
this.
|
|
23
|
+
if (!this.attachedRigidbody)
|
|
24
|
+
this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
|
|
33
25
|
}
|
|
34
26
|
|
|
35
|
-
start(){
|
|
27
|
+
start() {
|
|
36
28
|
if (!this.attachedRigidbody)
|
|
37
29
|
this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
|
|
38
30
|
}
|
|
@@ -44,9 +36,7 @@ export class Collider extends Behaviour implements ICollider {
|
|
|
44
36
|
}
|
|
45
37
|
|
|
46
38
|
onDisable() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
39
|
+
this.context.physics.removeBody(this);
|
|
50
40
|
}
|
|
51
41
|
|
|
52
42
|
}
|
|
@@ -57,45 +47,65 @@ export class SphereCollider extends Collider {
|
|
|
57
47
|
@serializeable()
|
|
58
48
|
radius: number = .5;
|
|
59
49
|
@serializeable(Vector3)
|
|
60
|
-
center:
|
|
50
|
+
center: Vector3 = new Vector3(0, 0, 0);
|
|
61
51
|
|
|
62
52
|
onEnable() {
|
|
63
53
|
super.onEnable();
|
|
64
|
-
|
|
65
|
-
this._shape = this.context.physics.addSphereCollider(this.gameObject, this.center, this.radius, this.attachedRigidbody);
|
|
54
|
+
this.context.physics.addSphereCollider(this, this.center, this.radius);
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
// onDisable() {
|
|
69
|
-
// // if (this._shape)
|
|
70
|
-
// // this.context.physics.removeShape(this.gameObject, this._shape);
|
|
71
|
-
// }
|
|
72
56
|
}
|
|
73
57
|
|
|
74
58
|
export class BoxCollider extends Collider {
|
|
75
59
|
|
|
76
60
|
@serializeable(Vector3)
|
|
77
|
-
size:
|
|
61
|
+
size: Vector3 = new Vector3(1, 1, 1);
|
|
78
62
|
@serializeable(Vector3)
|
|
79
|
-
center:
|
|
63
|
+
center: Vector3 = new Vector3(0, 0, 0);
|
|
80
64
|
|
|
81
65
|
onEnable() {
|
|
82
66
|
super.onEnable();
|
|
83
|
-
|
|
84
|
-
this._shape = this.context.physics.addBoxCollider(this.gameObject, this.isTrigger, this.center, this.size, this.attachedRigidbody);
|
|
67
|
+
this.context.physics.addBoxCollider(this, this.center, this.size);
|
|
85
68
|
}
|
|
69
|
+
}
|
|
86
70
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
71
|
+
|
|
72
|
+
export class MeshCollider extends Collider {
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
sharedMesh?: Mesh;
|
|
76
|
+
@serializeable()
|
|
77
|
+
convex: boolean = false;
|
|
78
|
+
|
|
79
|
+
awake() {
|
|
80
|
+
console.log(this);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
onEnable() {
|
|
84
|
+
super.onEnable();
|
|
85
|
+
if (!this.sharedMesh?.isMesh) {
|
|
86
|
+
// HACK using the renderer mesh
|
|
87
|
+
if (this.gameObject instanceof Mesh) {
|
|
88
|
+
this.sharedMesh = this.gameObject;
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (this.sharedMesh?.isMesh)
|
|
92
|
+
this.context.physics.addMeshCollider(this, this.sharedMesh, this.convex);
|
|
93
|
+
}
|
|
92
94
|
}
|
|
93
95
|
|
|
94
96
|
|
|
95
|
-
|
|
97
|
+
export class CapsuleCollider extends Collider {
|
|
98
|
+
@serializeable(Vector3)
|
|
99
|
+
center: Vector3 = new Vector3(0, 0, 0);
|
|
100
|
+
|
|
101
|
+
@serializeable()
|
|
102
|
+
radius: number = .5;
|
|
103
|
+
@serializeable()
|
|
104
|
+
height: number = 2;
|
|
105
|
+
|
|
106
|
+
onEnable() {
|
|
107
|
+
super.onEnable();
|
|
108
|
+
this.context.physics.addCapsuleCollider(this, this.center, this.height, this.radius);
|
|
109
|
+
}
|
|
96
110
|
|
|
97
|
-
|
|
98
|
-
// if (this.enabled)
|
|
99
|
-
// this.context.physics.addMeshCollider(this.gameObject);
|
|
100
|
-
// }
|
|
101
|
-
// }
|
|
111
|
+
}
|
|
@@ -6,7 +6,7 @@ import { Context, FrameEvent } from "../engine/engine_setup";
|
|
|
6
6
|
import * as main from "../engine/engine_mainloop_utils";
|
|
7
7
|
import { Object3D } from "three";
|
|
8
8
|
import { syncDestroy, syncInstantiate } from "../engine/engine_networking_instantiate";
|
|
9
|
-
import { ConstructorConcrete, SourceIdentifier, IComponent, IGameObject, Constructor, GuidsMap, UIDProvider, Collision } from "../engine/engine_types";
|
|
9
|
+
import { ConstructorConcrete, SourceIdentifier, IComponent, IGameObject, Constructor, GuidsMap, UIDProvider, Collision, ICollider } from "../engine/engine_types";
|
|
10
10
|
import { addNewComponentInstance, destroyComponentInstance, findObjectOfType, findObjectsOfType, getComponent, getComponentInChildren, getComponentInParent, getComponents, getComponentsInChildren, getComponentsInParent, getOrAddComponent, moveComponentInstance, removeComponent } from "../engine/engine_components";
|
|
11
11
|
import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreachComponent, markAsInstancedRendered, isActiveInHierarchy, isActiveSelf, isUsingInstancing, setActive } from "../engine/engine_gameobject";
|
|
12
12
|
|
|
@@ -317,9 +317,8 @@ class Component implements IComponent, EventTarget {
|
|
|
317
317
|
onDestroy() {
|
|
318
318
|
this.__destroyed = true;
|
|
319
319
|
}
|
|
320
|
+
onValidate?(prop?: string): void;
|
|
320
321
|
start?(): void;
|
|
321
|
-
// available update loop events:
|
|
322
|
-
// earlyUpdate, update, lateUpdate, onBeforeRender, onAfterRender
|
|
323
322
|
earlyUpdate?(): void;
|
|
324
323
|
update?(): void;
|
|
325
324
|
lateUpdate?(): void;
|
|
@@ -328,12 +327,11 @@ class Component implements IComponent, EventTarget {
|
|
|
328
327
|
|
|
329
328
|
onCollisionEnter?(col: Collision);
|
|
330
329
|
onCollisionExit?(col: Collision);
|
|
331
|
-
onCollisionExitRaw?(col: Collision);
|
|
332
330
|
onCollisionStay?(col: Collision);
|
|
333
|
-
|
|
334
|
-
onTriggerEnter?(col:
|
|
335
|
-
onTriggerStay?(col:
|
|
336
|
-
onTriggerExit?(col:
|
|
331
|
+
|
|
332
|
+
onTriggerEnter?(col: ICollider);
|
|
333
|
+
onTriggerStay?(col: ICollider);
|
|
334
|
+
onTriggerExit?(col: ICollider);
|
|
337
335
|
|
|
338
336
|
startCoroutine(routine: Generator, evt: FrameEvent = FrameEvent.Update): Generator {
|
|
339
337
|
return this.context.registerCoroutineUpdate(this, routine, evt);
|
|
@@ -360,13 +358,19 @@ class Component implements IComponent, EventTarget {
|
|
|
360
358
|
|
|
361
359
|
get __internalDidAwakeAndStart() { return this.__didAwake && this.__didStart; }
|
|
362
360
|
|
|
361
|
+
|
|
362
|
+
constructor() {
|
|
363
|
+
// super();
|
|
364
|
+
this.__internalNewInstanceCreated();
|
|
365
|
+
}
|
|
366
|
+
|
|
363
367
|
__internalNewInstanceCreated() {
|
|
364
368
|
this.__didAwake = false;
|
|
365
369
|
this.__didStart = false;
|
|
366
370
|
this.__didEnable = false;
|
|
367
371
|
this.__isEnabled = undefined;
|
|
368
372
|
this.__destroyed = false;
|
|
369
|
-
this.__internalResetsCachedPhysicsData();
|
|
373
|
+
// this.__internalResetsCachedPhysicsData();
|
|
370
374
|
}
|
|
371
375
|
|
|
372
376
|
__internalAwake() {
|
|
@@ -397,9 +401,9 @@ class Component implements IComponent, EventTarget {
|
|
|
397
401
|
__internalDisable() {
|
|
398
402
|
if (!this.__didEnable) return;
|
|
399
403
|
this.__didEnable = false;
|
|
400
|
-
this._collisionExitRoutine = undefined;
|
|
404
|
+
// this._collisionExitRoutine = undefined;
|
|
401
405
|
this.onDisable();
|
|
402
|
-
this._collisions?.clear();
|
|
406
|
+
// this._collisions?.clear();
|
|
403
407
|
// if we do this after processing the callback
|
|
404
408
|
this.__isEnabled = false;
|
|
405
409
|
}
|
|
@@ -437,126 +441,7 @@ class Component implements IComponent, EventTarget {
|
|
|
437
441
|
}
|
|
438
442
|
}
|
|
439
443
|
|
|
440
|
-
constructor() {
|
|
441
|
-
// super();
|
|
442
|
-
this.__internalNewInstanceCreated();
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
private _collisionExitRoutine: any;
|
|
446
|
-
private _collisions: Map<Object3D, { col: Collision, frame: number, exitFrame?: number }> | null = null;
|
|
447
|
-
|
|
448
|
-
private _triggerExitRoutine: any;
|
|
449
|
-
private _triggerCollisions: Map<Object3D, { col: Collision, frame: number, exitFrame?: number }> | null = null;
|
|
450
|
-
|
|
451
|
-
get collisionsCount() { return this._collisions?.size ?? 0; }
|
|
452
|
-
|
|
453
|
-
private __internalResetsCachedPhysicsData() {
|
|
454
|
-
this._collisionExitRoutine = null;
|
|
455
|
-
this._collisions = null;
|
|
456
|
-
this._triggerExitRoutine = null;
|
|
457
|
-
this._triggerCollisions = null;
|
|
458
|
-
}
|
|
459
|
-
|
|
460
|
-
__internalHandleCollision(col: Collision, isTriggerCollision: boolean) {
|
|
461
|
-
if (isTriggerCollision) {
|
|
462
|
-
if (!this.onTriggerEnter && !this.onTriggerStay && !this.onTriggerExit) return;
|
|
463
|
-
}
|
|
464
|
-
else {
|
|
465
|
-
if (!this.onCollisionEnter && !this.onCollisionStay && !this.onCollisionExit) return;
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
const otherObject = col.gameObject;
|
|
469
|
-
|
|
470
|
-
// lazily create the maps
|
|
471
|
-
if (isTriggerCollision && !this._triggerCollisions) this._triggerCollisions = new Map();
|
|
472
|
-
else if (!this._collisions) this._collisions = new Map();
|
|
473
|
-
|
|
474
|
-
// select the correct map
|
|
475
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
476
|
-
|
|
477
|
-
if (collection.has(otherObject)) {
|
|
478
|
-
const cur = collection.get(otherObject)!;
|
|
479
|
-
// console.log("STAY", this.name, this.context.time.frameCount)
|
|
480
|
-
// cur.exitFrame = undefined;
|
|
481
|
-
cur.frame = this.context.time.frameCount;
|
|
482
|
-
cur.col = col;
|
|
483
|
-
if (isTriggerCollision)
|
|
484
|
-
this.onTriggerStay?.(col);
|
|
485
|
-
else
|
|
486
|
-
this.onCollisionStay?.call(this, col);
|
|
487
|
-
}
|
|
488
|
-
else {
|
|
489
|
-
// console.log("START", this.name);
|
|
490
|
-
const entry = { col, frame: this.context.time.frameCount };
|
|
491
|
-
collection.set(otherObject, entry);
|
|
492
|
-
if (isTriggerCollision)
|
|
493
|
-
this.onTriggerEnter?.(col);
|
|
494
|
-
else
|
|
495
|
-
this.onCollisionEnter?.call(this, col);
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
|
|
499
|
-
__internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean) {
|
|
500
|
-
if (isTriggerCollision) {
|
|
501
|
-
if (!this._triggerCollisions) return;
|
|
502
|
-
}
|
|
503
|
-
else {
|
|
504
|
-
if (!this._collisions) return;
|
|
505
|
-
}
|
|
506
|
-
|
|
507
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
508
|
-
|
|
509
|
-
const collision = collection.get(obj);
|
|
510
|
-
if (!collision) return;
|
|
511
|
-
collision.exitFrame = this.context.time.frameCount;
|
|
512
|
-
// console.log("EXIT col", this.name, this.context.time.frameCount);
|
|
513
|
-
// if (this.onCollisionExit !== undefined)
|
|
514
|
-
this.__waitForCollisionExit(isTriggerCollision);
|
|
515
|
-
if (!isTriggerCollision)
|
|
516
|
-
this.onCollisionExitRaw?.call(this, collision.col);
|
|
517
|
-
// this._collisions.delete(obj);
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
private __waitForCollisionExit(isTriggerCollision: boolean) {
|
|
521
|
-
const routine = isTriggerCollision ? this._triggerExitRoutine : this._collisionExitRoutine;
|
|
522
|
-
if (routine) return;
|
|
523
|
-
|
|
524
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
525
|
-
const self = this;
|
|
526
|
-
const frames = 10;
|
|
527
|
-
function* delayedExitRoutine() {
|
|
528
|
-
while (collection && collection.size > 0) {
|
|
529
|
-
for (let other of collection.keys()) {
|
|
530
|
-
const entry = collection!.get(other)!;
|
|
531
|
-
if (entry.frame !== undefined && self.context.time.frameCount - entry.frame >= frames) {
|
|
532
|
-
// console.log("EXIT real", self.name, entry.col.gameObject.name, collection);
|
|
533
|
-
collection!.delete(other);
|
|
534
|
-
if (isTriggerCollision)
|
|
535
|
-
self.onTriggerExit?.(entry.col);
|
|
536
|
-
else
|
|
537
|
-
self.onCollisionExit?.call(self, entry.col);
|
|
538
|
-
}
|
|
539
|
-
}
|
|
540
|
-
for (let i = 0; i < frames; i++)
|
|
541
|
-
yield;
|
|
542
|
-
}
|
|
543
|
-
if (isTriggerCollision)
|
|
544
|
-
self._triggerExitRoutine = undefined;
|
|
545
|
-
else
|
|
546
|
-
self._collisionExitRoutine = null;
|
|
547
|
-
// console.log("DONE", self.name);
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
const newRoutine = this.startCoroutine(delayedExitRoutine(), FrameEvent.OnAfterRender);
|
|
551
|
-
if (isTriggerCollision)
|
|
552
|
-
this._triggerExitRoutine = newRoutine;
|
|
553
|
-
else
|
|
554
|
-
this._collisionExitRoutine = newRoutine
|
|
555
|
-
}
|
|
556
|
-
|
|
557
|
-
|
|
558
444
|
// TODO move this to threeutils
|
|
559
|
-
|
|
560
445
|
// we need a copy for modifying the values to local space
|
|
561
446
|
private static _worldPositionBuffer: THREE.Vector3 = new THREE.Vector3();
|
|
562
447
|
private static _worldQuaternionBuffer: THREE.Quaternion = new THREE.Quaternion();
|
|
@@ -230,7 +230,7 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
230
230
|
this._dragHelper.onUpdate(this.context);
|
|
231
231
|
for (const rb of this._draggingRigidbodies) {
|
|
232
232
|
rb.wakeUp();
|
|
233
|
-
rb.
|
|
233
|
+
rb.resetVelocities();
|
|
234
234
|
}
|
|
235
235
|
}
|
|
236
236
|
|
|
@@ -238,6 +238,9 @@ export class DragControls extends Interactable implements IPointerDownHandler, I
|
|
|
238
238
|
if (!this || !this._isDragging) return;
|
|
239
239
|
this._isDragging = false;
|
|
240
240
|
if (!this._dragHelper) return;
|
|
241
|
+
for(const rb of this._draggingRigidbodies){
|
|
242
|
+
rb.setVelocity(rb.smoothedVelocity);
|
|
243
|
+
}
|
|
241
244
|
this._draggingRigidbodies.length = 0;
|
|
242
245
|
const selected = this._dragHelper.selected;
|
|
243
246
|
if (debug)
|
|
@@ -323,8 +326,8 @@ class DragHelper {
|
|
|
323
326
|
if (this._selected && context) {
|
|
324
327
|
for (const rb of this._rbs) {
|
|
325
328
|
rb.wakeUp();
|
|
326
|
-
if (!rb.smoothedVelocity) continue;
|
|
327
|
-
rb.setVelocity(
|
|
329
|
+
// if (!rb.smoothedVelocity) continue;
|
|
330
|
+
rb.setVelocity(0,0,0);
|
|
328
331
|
}
|
|
329
332
|
}
|
|
330
333
|
|
|
@@ -358,7 +361,7 @@ class DragHelper {
|
|
|
358
361
|
this._groundOffset.set(0, 0, 0);
|
|
359
362
|
this._requireUpdateGroundPlane = true;
|
|
360
363
|
|
|
361
|
-
this._rbs = GameObject.getComponentsInChildren(this._selected, Rigidbody);
|
|
364
|
+
// this._rbs = GameObject.getComponentsInChildren(this._selected, Rigidbody);
|
|
362
365
|
this.onUpdateScreenSpacePlane();
|
|
363
366
|
}
|
|
364
367
|
}
|
|
@@ -518,7 +521,8 @@ class DragHelper {
|
|
|
518
521
|
|
|
519
522
|
for (const rb of this._rbs) {
|
|
520
523
|
rb.wakeUp();
|
|
521
|
-
rb.
|
|
524
|
+
rb.resetForcesAndTorques();
|
|
525
|
+
// rb.setBodyFromGameObject({ x: 0, y: 0, z: 0 });
|
|
522
526
|
rb.setAngularVelocity(0, 0, 0);
|
|
523
527
|
}
|
|
524
528
|
}
|
|
@@ -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;
|