@needle-tools/engine 2.35.5-pre → 2.37.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 +31 -0
- package/dist/needle-engine.d.ts +312 -232
- package/dist/needle-engine.js +456 -437
- package/dist/needle-engine.js.map +4 -4
- package/dist/needle-engine.min.js +81 -76
- 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/debug/debug_overlay.js +12 -1
- package/lib/engine/debug/debug_overlay.js.map +1 -1
- package/lib/engine/engine_element_loading.js +1 -1
- package/lib/engine/engine_element_loading.js.map +1 -1
- package/lib/engine/engine_gameobject.d.ts +1 -0
- package/lib/engine/engine_gameobject.js +15 -2
- package/lib/engine/engine_gameobject.js.map +1 -1
- package/lib/engine/engine_gltf_builtin_components.js +4 -0
- package/lib/engine/engine_gltf_builtin_components.js.map +1 -1
- package/lib/engine/engine_mainloop_utils.d.ts +1 -1
- package/lib/engine/engine_mainloop_utils.js +7 -3
- package/lib/engine/engine_mainloop_utils.js.map +1 -1
- package/lib/engine/engine_physics.d.ts +49 -57
- package/lib/engine/engine_physics.js +464 -417
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine/engine_physics.types.d.ts +16 -0
- package/lib/engine/engine_physics.types.js +19 -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 +19 -6
- package/lib/engine/engine_serialization_core.js.map +1 -1
- package/lib/engine/engine_setup.js +4 -2
- package/lib/engine/engine_setup.js.map +1 -1
- package/lib/engine/engine_time.d.ts +1 -0
- package/lib/engine/engine_time.js +1 -0
- package/lib/engine/engine_time.js.map +1 -1
- package/lib/engine/engine_types.d.ts +46 -26
- package/lib/engine/engine_types.js +24 -37
- package/lib/engine/engine_types.js.map +1 -1
- package/lib/engine/engine_typestore.d.ts +1 -0
- package/lib/engine/engine_typestore.js +1 -0
- package/lib/engine/engine_typestore.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 +2 -2
- package/lib/engine/engine_utils.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_animator_controller_model.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/extensions/NEEDLE_techniques_webgl.js +5 -0
- package/lib/engine/extensions/NEEDLE_techniques_webgl.js.map +1 -1
- package/lib/engine-components/Animation.d.ts +5 -0
- package/lib/engine-components/Animation.js +14 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/AnimatorController.d.ts +1 -0
- package/lib/engine-components/AnimatorController.js +14 -7
- package/lib/engine-components/AnimatorController.js.map +1 -1
- package/lib/engine-components/BoxHelperComponent.d.ts +2 -2
- package/lib/engine-components/BoxHelperComponent.js +28 -9
- package/lib/engine-components/BoxHelperComponent.js.map +1 -1
- package/lib/engine-components/Collider.d.ts +7 -2
- package/lib/engine-components/Collider.js +27 -15
- package/lib/engine-components/Collider.js.map +1 -1
- package/lib/engine-components/Component.d.ts +8 -16
- package/lib/engine-components/Component.js +18 -117
- 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/GroundProjection.d.ts +2 -0
- package/lib/engine-components/GroundProjection.js +18 -6
- package/lib/engine-components/GroundProjection.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/ReflectionProbe.d.ts +22 -0
- package/lib/engine-components/ReflectionProbe.js +134 -0
- package/lib/engine-components/ReflectionProbe.js.map +1 -0
- package/lib/engine-components/Renderer.d.ts +13 -2
- package/lib/engine-components/Renderer.js +96 -45
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/RigidBody.d.ts +40 -25
- package/lib/engine-components/RigidBody.js +253 -142
- package/lib/engine-components/RigidBody.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/WebARSessionRoot.d.ts +7 -7
- package/lib/engine-components/WebARSessionRoot.js +7 -7
- package/lib/engine-components/WebARSessionRoot.js.map +1 -1
- package/lib/engine-components/WebXR.d.ts +10 -8
- package/lib/engine-components/WebXR.js +50 -26
- package/lib/engine-components/WebXR.js.map +1 -1
- package/lib/engine-components/WebXRAvatar.d.ts +4 -5
- package/lib/engine-components/WebXRAvatar.js +9 -8
- package/lib/engine-components/WebXRAvatar.js.map +1 -1
- package/lib/engine-components/WebXRController.d.ts +21 -21
- package/lib/engine-components/WebXRController.js +90 -68
- package/lib/engine-components/WebXRController.js.map +1 -1
- package/lib/engine-components/WebXRGrabRendering.d.ts +3 -3
- package/lib/engine-components/WebXRGrabRendering.js +2 -2
- package/lib/engine-components/WebXRGrabRendering.js.map +1 -1
- package/lib/engine-components/WebXRSync.d.ts +8 -8
- package/lib/engine-components/WebXRSync.js +15 -15
- package/lib/engine-components/WebXRSync.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +2 -3
- package/lib/engine-components/codegen/components.js +2 -3
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/ui/EventSystem.d.ts +1 -0
- package/lib/engine-components/ui/EventSystem.js +21 -1
- package/lib/engine-components/ui/EventSystem.js.map +1 -1
- package/package.json +3 -4
- package/src/engine/api.ts +2 -1
- package/src/engine/codegen/register_types.js +291 -6
- package/src/engine/debug/debug.ts +4 -0
- package/src/engine/debug/debug_overlay.ts +9 -2
- package/src/engine/engine_element_loading.ts +1 -1
- package/src/engine/engine_gameobject.ts +19 -6
- package/src/engine/engine_gltf_builtin_components.ts +5 -1
- package/src/engine/engine_mainloop_utils.ts +7 -3
- package/src/engine/engine_physics.ts +508 -469
- package/src/engine/engine_physics.types.ts +19 -0
- package/src/engine/engine_serialization_core.ts +22 -8
- package/src/engine/engine_setup.ts +6 -2
- package/src/engine/engine_time.ts +2 -0
- package/src/engine/engine_types.ts +82 -55
- package/src/engine/engine_typestore.ts +2 -0
- package/src/engine/engine_util_decorator.ts +69 -0
- package/src/engine/engine_utils.ts +6 -5
- package/src/engine/extensions/EXT_texture_exr.js +1 -1
- package/src/engine/extensions/NEEDLE_animator_controller_model.ts +2 -1
- package/src/engine/extensions/NEEDLE_gameobject_data.ts +2 -0
- package/src/engine/extensions/NEEDLE_techniques_webgl.ts +7 -0
- package/src/engine-components/Animation.ts +14 -1
- package/src/engine-components/AnimatorController.ts +19 -9
- package/src/engine-components/BoxHelperComponent.ts +30 -9
- package/src/engine-components/Collider.ts +29 -29
- package/src/engine-components/Component.ts +26 -135
- package/src/engine-components/DragControls.ts +9 -5
- package/src/engine-components/GroundProjection.ts +22 -7
- package/src/engine-components/NavMesh.ts +114 -115
- package/src/engine-components/NestedGltf.ts +2 -0
- package/src/engine-components/ReflectionProbe.ts +141 -0
- package/src/engine-components/Renderer.ts +796 -737
- package/src/engine-components/RigidBody.ts +258 -149
- 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/WebARSessionRoot.ts +16 -16
- package/src/engine-components/WebXR.ts +65 -50
- package/src/engine-components/WebXRAvatar.ts +16 -16
- package/src/engine-components/WebXRController.ts +143 -112
- package/src/engine-components/WebXRGrabRendering.ts +6 -6
- package/src/engine-components/WebXRSync.ts +20 -20
- package/src/engine-components/codegen/components.ts +2 -3
- package/src/engine-components/ui/EventSystem.ts +26 -3
|
@@ -9,12 +9,12 @@ const gizmos = getParam("gizmos");
|
|
|
9
9
|
export class BoxHelperComponent extends Behaviour {
|
|
10
10
|
|
|
11
11
|
private box: THREE.Box3 | null = null;
|
|
12
|
-
private testBox: THREE.Box3 = new THREE.Box3();
|
|
12
|
+
private static testBox: THREE.Box3 = new THREE.Box3();
|
|
13
13
|
private _lastMatrixUpdateFrame: number = -1;
|
|
14
14
|
private static _position: THREE.Vector3 = new THREE.Vector3();
|
|
15
15
|
private static _size: THREE.Vector3 = new THREE.Vector3(.01, .01, .01);
|
|
16
16
|
|
|
17
|
-
public isInBox(obj: THREE.Object3D): boolean | undefined {
|
|
17
|
+
public isInBox(obj: THREE.Object3D, scaleFactor? : number): boolean | undefined {
|
|
18
18
|
if (!obj) return undefined;
|
|
19
19
|
|
|
20
20
|
// if (!obj.geometry.boundingBox) obj.geometry.computeBoundingBox();
|
|
@@ -23,22 +23,40 @@ export class BoxHelperComponent extends Behaviour {
|
|
|
23
23
|
if (!this.box) {
|
|
24
24
|
this.box = new THREE.Box3();
|
|
25
25
|
}
|
|
26
|
-
this.updateBox(false);
|
|
27
26
|
|
|
28
|
-
if (obj.type === "Mesh")
|
|
29
|
-
|
|
27
|
+
if (obj.type === "Mesh") {
|
|
28
|
+
BoxHelperComponent.testBox.setFromObject(obj);
|
|
29
|
+
}
|
|
30
|
+
else if (obj.type === "Group") {
|
|
31
|
+
if (obj.children.length > 0) {
|
|
32
|
+
BoxHelperComponent.testBox.setFromCenterAndSize(
|
|
33
|
+
BoxHelperComponent._position.set(0, 0, 0),
|
|
34
|
+
BoxHelperComponent._size.set(0, 0, 0)
|
|
35
|
+
);
|
|
36
|
+
for (let i = 0; i < obj.children.length; i++) {
|
|
37
|
+
const ch = obj.children[i];
|
|
38
|
+
if (ch.type === "Mesh") {
|
|
39
|
+
BoxHelperComponent.testBox.expandByObject(obj);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
30
44
|
else {
|
|
31
45
|
const wp = getWorldPosition(obj, BoxHelperComponent._position);
|
|
32
46
|
const size = getWorldScale(obj, BoxHelperComponent._size);
|
|
33
|
-
|
|
47
|
+
if(scaleFactor !== undefined) size.multiplyScalar(scaleFactor);
|
|
48
|
+
BoxHelperComponent.testBox.setFromCenterAndSize(wp, size);
|
|
34
49
|
}
|
|
35
50
|
|
|
51
|
+
// console.log("Obj box:", obj.name, obj.uuid, BoxHelperComponent.testBox.getCenter(new THREE.Vector3()), BoxHelperComponent.testBox.getSize(new THREE.Vector3()),
|
|
52
|
+
// "\nTest box:", this.box.getCenter(new THREE.Vector3()), this.box.getSize(new THREE.Vector3()), this.context.time.frameCount);
|
|
36
53
|
// this.tp.copy(obj.geometry.boundingBox);
|
|
37
54
|
// // this.tp.setFromCenterAndSize(obj.position, obj.scale);
|
|
38
55
|
// this.tp.applyMatrix4(obj.matrixWorld);
|
|
39
56
|
// console.log(this.tp);
|
|
40
57
|
// console.log(this.box?.min, this.box?.max, this.tp.min, this.tp.max);
|
|
41
|
-
|
|
58
|
+
this.updateBox();
|
|
59
|
+
return this.box?.intersectsBox(BoxHelperComponent.testBox);
|
|
42
60
|
}
|
|
43
61
|
|
|
44
62
|
public intersects(box: THREE.Box3): boolean {
|
|
@@ -51,9 +69,12 @@ export class BoxHelperComponent extends Behaviour {
|
|
|
51
69
|
this.box = new THREE.Box3();
|
|
52
70
|
}
|
|
53
71
|
if (force || this.context.time.frameCount != this._lastMatrixUpdateFrame) {
|
|
72
|
+
const firstUpdate = this._lastMatrixUpdateFrame < 0;
|
|
54
73
|
this._lastMatrixUpdateFrame = this.context.time.frameCount;
|
|
55
|
-
|
|
56
|
-
|
|
74
|
+
const updateParents: boolean = firstUpdate; // updating parents seems to cause falsely calculated positions sometimes?
|
|
75
|
+
const wp = getWorldPosition(this.gameObject, BoxHelperComponent._position, updateParents);
|
|
76
|
+
const size = getWorldScale(this.gameObject, BoxHelperComponent._size);
|
|
77
|
+
this.box.setFromCenterAndSize(wp, size);
|
|
57
78
|
}
|
|
58
79
|
return this.box;
|
|
59
80
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
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 { Shape } from "cannon-es";
|
|
4
|
+
import { Event, Mesh, Object3D, Vector3 } from "three"
|
|
6
5
|
import { IColliderProvider, registerColliderProvider } from "../engine/engine_physics";
|
|
7
6
|
import { ICollider } from "../engine/engine_types";
|
|
8
7
|
import { getComponentInChildren } from "../engine/engine_components";
|
|
@@ -25,14 +24,14 @@ export class Collider extends Behaviour implements ICollider {
|
|
|
25
24
|
@serializeable()
|
|
26
25
|
isTrigger: boolean = false;
|
|
27
26
|
|
|
28
|
-
protected _shape: Shape | null = null;
|
|
29
27
|
|
|
30
28
|
awake() {
|
|
31
29
|
super.awake();
|
|
32
|
-
this.
|
|
30
|
+
if (!this.attachedRigidbody)
|
|
31
|
+
this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
|
|
33
32
|
}
|
|
34
33
|
|
|
35
|
-
start(){
|
|
34
|
+
start() {
|
|
36
35
|
if (!this.attachedRigidbody)
|
|
37
36
|
this.attachedRigidbody = this.gameObject.getComponentInParent(Rigidbody);
|
|
38
37
|
}
|
|
@@ -44,9 +43,7 @@ export class Collider extends Behaviour implements ICollider {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
onDisable() {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
46
|
+
this.context.physics.removeBody(this);
|
|
50
47
|
}
|
|
51
48
|
|
|
52
49
|
}
|
|
@@ -61,14 +58,8 @@ export class SphereCollider extends Collider {
|
|
|
61
58
|
|
|
62
59
|
onEnable() {
|
|
63
60
|
super.onEnable();
|
|
64
|
-
|
|
65
|
-
this._shape = this.context.physics.addSphereCollider(this.gameObject, this.center, this.radius, this.attachedRigidbody);
|
|
61
|
+
this.context.physics.addSphereCollider(this, this.center, this.radius);
|
|
66
62
|
}
|
|
67
|
-
|
|
68
|
-
// onDisable() {
|
|
69
|
-
// // if (this._shape)
|
|
70
|
-
// // this.context.physics.removeShape(this.gameObject, this._shape);
|
|
71
|
-
// }
|
|
72
63
|
}
|
|
73
64
|
|
|
74
65
|
export class BoxCollider extends Collider {
|
|
@@ -80,22 +71,31 @@ export class BoxCollider extends Collider {
|
|
|
80
71
|
|
|
81
72
|
onEnable() {
|
|
82
73
|
super.onEnable();
|
|
83
|
-
|
|
84
|
-
this._shape = this.context.physics.addBoxCollider(this.gameObject, this.isTrigger, this.center, this.size, this.attachedRigidbody);
|
|
74
|
+
this.context.physics.addBoxCollider(this, this.center, this.size);
|
|
85
75
|
}
|
|
86
|
-
|
|
87
|
-
// onDisable() {
|
|
88
|
-
// // if (this._shape) {
|
|
89
|
-
// // this.context.physics.removeShape(this.gameObject, this._shape);
|
|
90
|
-
// // }
|
|
91
|
-
// }
|
|
92
76
|
}
|
|
93
77
|
|
|
94
78
|
|
|
95
|
-
|
|
79
|
+
export class MeshCollider extends Collider {
|
|
96
80
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
81
|
+
|
|
82
|
+
sharedMesh?: Mesh;
|
|
83
|
+
@serializeable()
|
|
84
|
+
convex: boolean = false;
|
|
85
|
+
|
|
86
|
+
awake(){
|
|
87
|
+
console.log(this);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
onEnable() {
|
|
91
|
+
super.onEnable();
|
|
92
|
+
if (!this.sharedMesh?.isMesh) {
|
|
93
|
+
// HACK using the renderer mesh
|
|
94
|
+
if (this.gameObject instanceof Mesh) {
|
|
95
|
+
this.sharedMesh = this.gameObject;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (this.sharedMesh?.isMesh)
|
|
99
|
+
this.context.physics.addMeshCollider(this, this.sharedMesh, this.convex);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
@@ -6,9 +6,9 @@ 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
|
-
import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreachComponent, markAsInstancedRendered, isActiveInHierarchy, isActiveSelf, isUsingInstancing } from "../engine/engine_gameobject";
|
|
11
|
+
import { findByGuid, destroy, InstantiateOptions, instantiate, HideFlags, foreachComponent, markAsInstancedRendered, isActiveInHierarchy, isActiveSelf, isUsingInstancing, setActive } from "../engine/engine_gameobject";
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
// export interface ISerializationCallbackReceiver {
|
|
@@ -23,10 +23,10 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
23
23
|
|
|
24
24
|
guid: string | undefined;
|
|
25
25
|
|
|
26
|
-
public static setActive(go: THREE.Object3D, active: boolean, processStart: boolean = true) {
|
|
26
|
+
public static setActive(go: THREE.Object3D, active: boolean, processStart: boolean = true, setVisible: boolean = true) {
|
|
27
27
|
if (!go) return;
|
|
28
|
-
go
|
|
29
|
-
main.
|
|
28
|
+
setActive(go, active, setVisible);
|
|
29
|
+
main.updateIsActive(go);
|
|
30
30
|
if (active && processStart)
|
|
31
31
|
main.processStart(Context.Current, go);
|
|
32
32
|
}
|
|
@@ -82,10 +82,12 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
82
82
|
context = Context.Current;
|
|
83
83
|
}
|
|
84
84
|
parent.add(instance);
|
|
85
|
-
|
|
85
|
+
setActive(instance, true);
|
|
86
|
+
main.updateIsActive(instance);
|
|
86
87
|
if (context) {
|
|
87
88
|
GameObject.foreachComponent(instance, (comp: Component) => {
|
|
88
89
|
main.addScriptToArrays(comp, context!);
|
|
90
|
+
if(comp.__internalDidAwakeAndStart) return;
|
|
89
91
|
if (context!.new_script_start.includes(comp) === false) {
|
|
90
92
|
context!.new_script_start.push(comp as Behaviour);
|
|
91
93
|
}
|
|
@@ -102,6 +104,8 @@ abstract class GameObject extends THREE.Object3D implements THREE.Object3D, IGam
|
|
|
102
104
|
public static remove(instance: THREE.Object3D | null | undefined) {
|
|
103
105
|
if (!instance) return;
|
|
104
106
|
instance.parent?.remove(instance);
|
|
107
|
+
setActive(instance, false);
|
|
108
|
+
main.updateIsActive(instance);
|
|
105
109
|
GameObject.foreachComponent(instance, (comp) => {
|
|
106
110
|
main.processRemoveFromScene(comp);
|
|
107
111
|
}, true);
|
|
@@ -313,9 +317,8 @@ class Component implements IComponent, EventTarget {
|
|
|
313
317
|
onDestroy() {
|
|
314
318
|
this.__destroyed = true;
|
|
315
319
|
}
|
|
320
|
+
onValidate?(prop?: string): void;
|
|
316
321
|
start?(): void;
|
|
317
|
-
// available update loop events:
|
|
318
|
-
// earlyUpdate, update, lateUpdate, onBeforeRender, onAfterRender
|
|
319
322
|
earlyUpdate?(): void;
|
|
320
323
|
update?(): void;
|
|
321
324
|
lateUpdate?(): void;
|
|
@@ -324,12 +327,11 @@ class Component implements IComponent, EventTarget {
|
|
|
324
327
|
|
|
325
328
|
onCollisionEnter?(col: Collision);
|
|
326
329
|
onCollisionExit?(col: Collision);
|
|
327
|
-
onCollisionExitRaw?(col: Collision);
|
|
328
330
|
onCollisionStay?(col: Collision);
|
|
329
|
-
|
|
330
|
-
onTriggerEnter?(col:
|
|
331
|
-
onTriggerStay?(col:
|
|
332
|
-
onTriggerExit?(col:
|
|
331
|
+
|
|
332
|
+
onTriggerEnter?(col: ICollider);
|
|
333
|
+
onTriggerStay?(col: ICollider);
|
|
334
|
+
onTriggerExit?(col: ICollider);
|
|
333
335
|
|
|
334
336
|
startCoroutine(routine: Generator, evt: FrameEvent = FrameEvent.Update): Generator {
|
|
335
337
|
return this.context.registerCoroutineUpdate(this, routine, evt);
|
|
@@ -354,13 +356,21 @@ class Component implements IComponent, EventTarget {
|
|
|
354
356
|
protected __isEnabled: boolean | undefined = undefined;
|
|
355
357
|
private __destroyed: boolean = false;
|
|
356
358
|
|
|
359
|
+
get __internalDidAwakeAndStart() { return this.__didAwake && this.__didStart; }
|
|
360
|
+
|
|
361
|
+
|
|
362
|
+
constructor() {
|
|
363
|
+
// super();
|
|
364
|
+
this.__internalNewInstanceCreated();
|
|
365
|
+
}
|
|
366
|
+
|
|
357
367
|
__internalNewInstanceCreated() {
|
|
358
368
|
this.__didAwake = false;
|
|
359
369
|
this.__didStart = false;
|
|
360
370
|
this.__didEnable = false;
|
|
361
371
|
this.__isEnabled = undefined;
|
|
362
372
|
this.__destroyed = false;
|
|
363
|
-
this.__internalResetsCachedPhysicsData();
|
|
373
|
+
// this.__internalResetsCachedPhysicsData();
|
|
364
374
|
}
|
|
365
375
|
|
|
366
376
|
__internalAwake() {
|
|
@@ -391,9 +401,9 @@ class Component implements IComponent, EventTarget {
|
|
|
391
401
|
__internalDisable() {
|
|
392
402
|
if (!this.__didEnable) return;
|
|
393
403
|
this.__didEnable = false;
|
|
394
|
-
this._collisionExitRoutine = undefined;
|
|
404
|
+
// this._collisionExitRoutine = undefined;
|
|
395
405
|
this.onDisable();
|
|
396
|
-
this._collisions?.clear();
|
|
406
|
+
// this._collisions?.clear();
|
|
397
407
|
// if we do this after processing the callback
|
|
398
408
|
this.__isEnabled = false;
|
|
399
409
|
}
|
|
@@ -431,126 +441,7 @@ class Component implements IComponent, EventTarget {
|
|
|
431
441
|
}
|
|
432
442
|
}
|
|
433
443
|
|
|
434
|
-
constructor() {
|
|
435
|
-
// super();
|
|
436
|
-
this.__internalNewInstanceCreated();
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
private _collisionExitRoutine: any;
|
|
440
|
-
private _collisions: Map<Object3D, { col: Collision, frame: number, exitFrame?: number }> | null = null;
|
|
441
|
-
|
|
442
|
-
private _triggerExitRoutine: any;
|
|
443
|
-
private _triggerCollisions: Map<Object3D, { col: Collision, frame: number, exitFrame?: number }> | null = null;
|
|
444
|
-
|
|
445
|
-
get collisionsCount() { return this._collisions?.size ?? 0; }
|
|
446
|
-
|
|
447
|
-
private __internalResetsCachedPhysicsData() {
|
|
448
|
-
this._collisionExitRoutine = null;
|
|
449
|
-
this._collisions = null;
|
|
450
|
-
this._triggerExitRoutine = null;
|
|
451
|
-
this._triggerCollisions = null;
|
|
452
|
-
}
|
|
453
|
-
|
|
454
|
-
__internalHandleCollision(col: Collision, isTriggerCollision: boolean) {
|
|
455
|
-
if (isTriggerCollision) {
|
|
456
|
-
if (!this.onTriggerEnter && !this.onTriggerStay && !this.onTriggerExit) return;
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
if (!this.onCollisionEnter && !this.onCollisionStay && !this.onCollisionExit) return;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
const otherObject = col.gameObject;
|
|
463
|
-
|
|
464
|
-
// lazily create the maps
|
|
465
|
-
if (isTriggerCollision && !this._triggerCollisions) this._triggerCollisions = new Map();
|
|
466
|
-
else if (!this._collisions) this._collisions = new Map();
|
|
467
|
-
|
|
468
|
-
// select the correct map
|
|
469
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
470
|
-
|
|
471
|
-
if (collection.has(otherObject)) {
|
|
472
|
-
const cur = collection.get(otherObject)!;
|
|
473
|
-
// console.log("STAY", this.name, this.context.time.frameCount)
|
|
474
|
-
// cur.exitFrame = undefined;
|
|
475
|
-
cur.frame = this.context.time.frameCount;
|
|
476
|
-
cur.col = col;
|
|
477
|
-
if (isTriggerCollision)
|
|
478
|
-
this.onTriggerStay?.(col);
|
|
479
|
-
else
|
|
480
|
-
this.onCollisionStay?.call(this, col);
|
|
481
|
-
}
|
|
482
|
-
else {
|
|
483
|
-
// console.log("START", this.name);
|
|
484
|
-
const entry = { col, frame: this.context.time.frameCount };
|
|
485
|
-
collection.set(otherObject, entry);
|
|
486
|
-
if (isTriggerCollision)
|
|
487
|
-
this.onTriggerEnter?.(col);
|
|
488
|
-
else
|
|
489
|
-
this.onCollisionEnter?.call(this, col);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
__internalHandleExitCollisionEvent(obj: Object3D, isTriggerCollision: boolean) {
|
|
494
|
-
if (isTriggerCollision) {
|
|
495
|
-
if (!this._triggerCollisions) return;
|
|
496
|
-
}
|
|
497
|
-
else {
|
|
498
|
-
if (!this._collisions) return;
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
502
|
-
|
|
503
|
-
const collision = collection.get(obj);
|
|
504
|
-
if (!collision) return;
|
|
505
|
-
collision.exitFrame = this.context.time.frameCount;
|
|
506
|
-
// console.log("EXIT col", this.name, this.context.time.frameCount);
|
|
507
|
-
// if (this.onCollisionExit !== undefined)
|
|
508
|
-
this.__waitForCollisionExit(isTriggerCollision);
|
|
509
|
-
if (!isTriggerCollision)
|
|
510
|
-
this.onCollisionExitRaw?.call(this, collision.col);
|
|
511
|
-
// this._collisions.delete(obj);
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
private __waitForCollisionExit(isTriggerCollision: boolean) {
|
|
515
|
-
const routine = isTriggerCollision ? this._triggerExitRoutine : this._collisionExitRoutine;
|
|
516
|
-
if (routine) return;
|
|
517
|
-
|
|
518
|
-
const collection = isTriggerCollision ? this._triggerCollisions! : this._collisions!;
|
|
519
|
-
const self = this;
|
|
520
|
-
const frames = 10;
|
|
521
|
-
function* delayedExitRoutine() {
|
|
522
|
-
while (collection && collection.size > 0) {
|
|
523
|
-
for (let other of collection.keys()) {
|
|
524
|
-
const entry = collection!.get(other)!;
|
|
525
|
-
if (entry.frame !== undefined && self.context.time.frameCount - entry.frame >= frames) {
|
|
526
|
-
// console.log("EXIT real", self.name, entry.col.gameObject.name, collection);
|
|
527
|
-
collection!.delete(other);
|
|
528
|
-
if (isTriggerCollision)
|
|
529
|
-
self.onTriggerExit?.(entry.col);
|
|
530
|
-
else
|
|
531
|
-
self.onCollisionExit?.call(self, entry.col);
|
|
532
|
-
}
|
|
533
|
-
}
|
|
534
|
-
for (let i = 0; i < frames; i++)
|
|
535
|
-
yield;
|
|
536
|
-
}
|
|
537
|
-
if (isTriggerCollision)
|
|
538
|
-
self._triggerExitRoutine = undefined;
|
|
539
|
-
else
|
|
540
|
-
self._collisionExitRoutine = null;
|
|
541
|
-
// console.log("DONE", self.name);
|
|
542
|
-
}
|
|
543
|
-
|
|
544
|
-
const newRoutine = this.startCoroutine(delayedExitRoutine(), FrameEvent.OnAfterRender);
|
|
545
|
-
if (isTriggerCollision)
|
|
546
|
-
this._triggerExitRoutine = newRoutine;
|
|
547
|
-
else
|
|
548
|
-
this._collisionExitRoutine = newRoutine
|
|
549
|
-
}
|
|
550
|
-
|
|
551
|
-
|
|
552
444
|
// TODO move this to threeutils
|
|
553
|
-
|
|
554
445
|
// we need a copy for modifying the values to local space
|
|
555
446
|
private static _worldPositionBuffer: THREE.Vector3 = new THREE.Vector3();
|
|
556
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
|
}
|
|
@@ -41,12 +41,13 @@ export class GroundProjectedEnv extends Behaviour {
|
|
|
41
41
|
|
|
42
42
|
|
|
43
43
|
onEnable() {
|
|
44
|
-
this.
|
|
45
|
-
if (
|
|
46
|
-
this.
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
// TODO: if we do this in the first frame we can not disable it again. Something buggy with the watch?!
|
|
45
|
+
if (this.context.time.frameCount > 0)
|
|
46
|
+
this.updateAndCreate();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
start() {
|
|
50
|
+
this.updateAndCreate();
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
onDisable() {
|
|
@@ -54,8 +55,22 @@ export class GroundProjectedEnv extends Behaviour {
|
|
|
54
55
|
this.env?.removeFromParent();
|
|
55
56
|
}
|
|
56
57
|
|
|
58
|
+
private updateAndCreate() {
|
|
59
|
+
this.updateProjection();
|
|
60
|
+
if (!this._watcher) {
|
|
61
|
+
this._watcher = new Watch(this.context.scene, "environment");
|
|
62
|
+
this._watcher.subscribeWrite(_ => {
|
|
63
|
+
this.updateProjection();
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
this._watcher.apply();
|
|
67
|
+
}
|
|
68
|
+
|
|
57
69
|
updateProjection() {
|
|
58
|
-
if (!this.context.scene.environment)
|
|
70
|
+
if (!this.context.scene.environment) {
|
|
71
|
+
this.env?.removeFromParent();
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
59
74
|
if (!this.env || this.context.scene.environment !== this._lastEnvironment) {
|
|
60
75
|
console.log("Create/Update Ground Projection", this.context.scene.environment.name);
|
|
61
76
|
this.env = new GroundProjection(this.context.scene.environment);
|