@needle-tools/engine 4.9.0-alpha.3 → 4.9.0-next.ce04b9f
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/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-D3t6rco7.umd.cjs → needle-engine.bundle-DHAUN6T_.umd.cjs} +129 -129
- package/dist/{needle-engine.bundle-xx2z8elo.min.js → needle-engine.bundle-a5_4RZjH.min.js} +128 -128
- package/dist/{needle-engine.bundle-rZjkMCRy.js → needle-engine.bundle-qHhlH-u4.js} +4868 -4718
- package/dist/needle-engine.js +556 -552
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/codegen/register_types.js +8 -0
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +8 -8
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_serialization_builtin_serializer.d.ts +2 -2
- package/lib/engine-components/Animation.d.ts +1 -0
- package/lib/engine-components/Animation.js +9 -0
- package/lib/engine-components/Animation.js.map +1 -1
- package/lib/engine-components/Component.d.ts +1 -0
- package/lib/engine-components/Component.js.map +1 -1
- package/lib/engine-components/EventTrigger.js.map +1 -1
- package/lib/engine-components/api.d.ts +1 -0
- package/lib/engine-components/api.js +1 -0
- package/lib/engine-components/api.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +4 -0
- package/lib/engine-components/codegen/components.js +4 -0
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/physics/Attractor.d.ts +8 -0
- package/lib/engine-components/physics/Attractor.js +42 -0
- package/lib/engine-components/physics/Attractor.js.map +1 -0
- package/lib/engine-components/web/Clickthrough.d.ts +19 -0
- package/lib/engine-components/web/Clickthrough.js +57 -0
- package/lib/engine-components/web/Clickthrough.js.map +1 -0
- package/lib/engine-components/web/CursorFollow.d.ts +12 -0
- package/lib/engine-components/web/CursorFollow.js +46 -0
- package/lib/engine-components/web/CursorFollow.js.map +1 -0
- package/lib/engine-components/web/ScrollFollow.d.ts +27 -0
- package/lib/engine-components/web/ScrollFollow.js +85 -0
- package/lib/engine-components/web/ScrollFollow.js.map +1 -0
- package/lib/engine-components/web/index.d.ts +3 -0
- package/lib/engine-components/web/index.js +4 -0
- package/lib/engine-components/web/index.js.map +1 -0
- package/package.json +2 -2
- package/src/engine/codegen/register_types.ts +8 -0
- package/src/engine/engine_physics_rapier.ts +11 -11
- package/src/engine-components/Animation.ts +9 -0
- package/src/engine-components/Component.ts +1 -0
- package/src/engine-components/EventTrigger.ts +0 -1
- package/src/engine-components/api.ts +1 -0
- package/src/engine-components/codegen/components.ts +4 -0
- package/src/engine-components/physics/Attractor.ts +35 -0
- package/src/engine-components/web/Clickthrough.ts +60 -0
- package/src/engine-components/web/CursorFollow.ts +49 -0
- package/src/engine-components/web/ScrollFollow.ts +91 -0
- package/src/engine-components/web/index.ts +3 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { serializable } from "../../engine/engine_serialization_decorator.js";
|
|
2
|
+
import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
3
|
+
import { Behaviour } from "../Component.js";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export class CursorFollow extends Behaviour {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Damping for the movement, set to 0 for instant movement
|
|
10
|
+
* @default 0
|
|
11
|
+
*/
|
|
12
|
+
@serializable()
|
|
13
|
+
damping: number = 0;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
private _distance: number = -1;
|
|
17
|
+
updateDistance() {
|
|
18
|
+
this._distance = this.gameObject.worldPosition.distanceTo(this.context.mainCamera.worldPosition);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
/** @internal */
|
|
23
|
+
update() {
|
|
24
|
+
// continuously update distance in case camera or object moves
|
|
25
|
+
this.updateDistance();
|
|
26
|
+
|
|
27
|
+
// follow cursor in screenspace but maintain initial distance from camera
|
|
28
|
+
const cursor = this.context.input.mousePositionRC;
|
|
29
|
+
const camera = this.context.mainCamera;
|
|
30
|
+
const cameraPosition = camera.worldPosition;
|
|
31
|
+
|
|
32
|
+
// create ray from camera through cursor position
|
|
33
|
+
const rayDirection = getTempVector(cursor.x, cursor.y, 1).unproject(camera);
|
|
34
|
+
rayDirection.sub(cameraPosition).normalize();
|
|
35
|
+
|
|
36
|
+
// position object at initial distance along the ray
|
|
37
|
+
const newPosition = rayDirection.multiplyScalar(this._distance).add(cameraPosition);
|
|
38
|
+
if (this.damping > 0) {
|
|
39
|
+
const pos = this.gameObject.worldPosition;
|
|
40
|
+
pos.lerp(newPosition, this.context.time.deltaTime / this.damping);
|
|
41
|
+
this.gameObject.worldPosition = pos;
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
this.gameObject.worldPosition = newPosition;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Object3D } from "three";
|
|
2
|
+
import { serializable } from "../../engine/engine_serialization.js";
|
|
3
|
+
import { Mathf } from "../../engine/engine_math.js";
|
|
4
|
+
import { Behaviour } from "../Component.js";
|
|
5
|
+
import { Animation, PlayableDirector } from "../api.js";
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
export class ScrollFollow extends Behaviour {
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Target object(s) to follow the scroll position of the page. If null, the main camera is used.
|
|
13
|
+
*/
|
|
14
|
+
@serializable([Behaviour, Object3D])
|
|
15
|
+
target: object[] | object | null = null;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Damping for the movement, set to 0 for instant movement
|
|
19
|
+
* @default 0
|
|
20
|
+
*/
|
|
21
|
+
@serializable()
|
|
22
|
+
damping: number = 0;
|
|
23
|
+
|
|
24
|
+
@serializable()
|
|
25
|
+
mode: "window" = "window";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Current scroll value in "pages" (0 = top of page, 1 = bottom of page)
|
|
29
|
+
*/
|
|
30
|
+
get currentValue() {
|
|
31
|
+
return this.current_value;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
private current_value: number = 0;
|
|
35
|
+
private target_value: number = 0;
|
|
36
|
+
|
|
37
|
+
/** @internal */
|
|
38
|
+
onEnable() {
|
|
39
|
+
window.addEventListener("wheel", this.updateCurrentScroll, { passive: true });
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** @internal */
|
|
43
|
+
onDisable() {
|
|
44
|
+
window.removeEventListener("wheel", this.updateCurrentScroll);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** @internal */
|
|
48
|
+
lateUpdate() {
|
|
49
|
+
|
|
50
|
+
// apply damping if any
|
|
51
|
+
if (this.damping > 0) {
|
|
52
|
+
this.current_value = Mathf.lerp(this.current_value, this.target_value, this.context.time.deltaTime / this.damping);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// apply scroll to target(s)
|
|
56
|
+
if (Array.isArray(this.target)) {
|
|
57
|
+
this.target.forEach(t => t && this.applyScroll(t));
|
|
58
|
+
}
|
|
59
|
+
else if (this.target) {
|
|
60
|
+
this.applyScroll(this.target);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
private updateCurrentScroll = () => {
|
|
67
|
+
|
|
68
|
+
switch (this.mode) {
|
|
69
|
+
case "window":
|
|
70
|
+
this.target_value = window.scrollY / (document.body.scrollHeight - window.innerHeight);
|
|
71
|
+
if (isNaN(this.target_value) || !isFinite(this.target_value)) this.target_value = 0;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (this.damping <= 0) {
|
|
76
|
+
this.current_value = this.target_value;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
private applyScroll(target: object) {
|
|
82
|
+
if (target instanceof PlayableDirector) {
|
|
83
|
+
target.time = this.current_value * target.duration;
|
|
84
|
+
if (!target.isPlaying) target.evaluate();
|
|
85
|
+
}
|
|
86
|
+
else if (target instanceof Animation) {
|
|
87
|
+
target.time = this.current_value * target.duration;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|