@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.
Files changed (52) hide show
  1. package/components.needle.json +1 -1
  2. package/dist/{needle-engine.bundle-D3t6rco7.umd.cjs → needle-engine.bundle-DHAUN6T_.umd.cjs} +129 -129
  3. package/dist/{needle-engine.bundle-xx2z8elo.min.js → needle-engine.bundle-a5_4RZjH.min.js} +128 -128
  4. package/dist/{needle-engine.bundle-rZjkMCRy.js → needle-engine.bundle-qHhlH-u4.js} +4868 -4718
  5. package/dist/needle-engine.js +556 -552
  6. package/dist/needle-engine.min.js +1 -1
  7. package/dist/needle-engine.umd.cjs +1 -1
  8. package/lib/engine/codegen/register_types.js +8 -0
  9. package/lib/engine/codegen/register_types.js.map +1 -1
  10. package/lib/engine/engine_physics_rapier.js +8 -8
  11. package/lib/engine/engine_physics_rapier.js.map +1 -1
  12. package/lib/engine/engine_serialization_builtin_serializer.d.ts +2 -2
  13. package/lib/engine-components/Animation.d.ts +1 -0
  14. package/lib/engine-components/Animation.js +9 -0
  15. package/lib/engine-components/Animation.js.map +1 -1
  16. package/lib/engine-components/Component.d.ts +1 -0
  17. package/lib/engine-components/Component.js.map +1 -1
  18. package/lib/engine-components/EventTrigger.js.map +1 -1
  19. package/lib/engine-components/api.d.ts +1 -0
  20. package/lib/engine-components/api.js +1 -0
  21. package/lib/engine-components/api.js.map +1 -1
  22. package/lib/engine-components/codegen/components.d.ts +4 -0
  23. package/lib/engine-components/codegen/components.js +4 -0
  24. package/lib/engine-components/codegen/components.js.map +1 -1
  25. package/lib/engine-components/physics/Attractor.d.ts +8 -0
  26. package/lib/engine-components/physics/Attractor.js +42 -0
  27. package/lib/engine-components/physics/Attractor.js.map +1 -0
  28. package/lib/engine-components/web/Clickthrough.d.ts +19 -0
  29. package/lib/engine-components/web/Clickthrough.js +57 -0
  30. package/lib/engine-components/web/Clickthrough.js.map +1 -0
  31. package/lib/engine-components/web/CursorFollow.d.ts +12 -0
  32. package/lib/engine-components/web/CursorFollow.js +46 -0
  33. package/lib/engine-components/web/CursorFollow.js.map +1 -0
  34. package/lib/engine-components/web/ScrollFollow.d.ts +27 -0
  35. package/lib/engine-components/web/ScrollFollow.js +85 -0
  36. package/lib/engine-components/web/ScrollFollow.js.map +1 -0
  37. package/lib/engine-components/web/index.d.ts +3 -0
  38. package/lib/engine-components/web/index.js +4 -0
  39. package/lib/engine-components/web/index.js.map +1 -0
  40. package/package.json +2 -2
  41. package/src/engine/codegen/register_types.ts +8 -0
  42. package/src/engine/engine_physics_rapier.ts +11 -11
  43. package/src/engine-components/Animation.ts +9 -0
  44. package/src/engine-components/Component.ts +1 -0
  45. package/src/engine-components/EventTrigger.ts +0 -1
  46. package/src/engine-components/api.ts +1 -0
  47. package/src/engine-components/codegen/components.ts +4 -0
  48. package/src/engine-components/physics/Attractor.ts +35 -0
  49. package/src/engine-components/web/Clickthrough.ts +60 -0
  50. package/src/engine-components/web/CursorFollow.ts +49 -0
  51. package/src/engine-components/web/ScrollFollow.ts +91 -0
  52. 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
+ }
@@ -0,0 +1,3 @@
1
+ export * from "./Clickthrough.js";
2
+ export * from "./CursorFollow.js";
3
+ export * from "./ScrollFollow.js";