@needle-tools/engine 4.11.0 → 4.11.1
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 +6 -0
- package/README.md +3 -1
- package/dist/{needle-engine.bundle-Dh4X0Qy5.js → needle-engine.bundle-6yF8G5KJ.js} +2646 -2575
- package/dist/{needle-engine.bundle-IPerDSpg.min.js → needle-engine.bundle-BSk8yk3v.min.js} +100 -100
- package/dist/{needle-engine.bundle-DhRclTK5.umd.cjs → needle-engine.bundle-DPVYipMl.umd.cjs} +97 -97
- package/dist/needle-engine.js +2 -2
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/engine_physics.js +2 -1
- package/lib/engine/engine_physics.js.map +1 -1
- package/lib/engine-components/OrbitControls.js +2 -0
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/splines/SplineWalker.d.ts +43 -4
- package/lib/engine-components/splines/SplineWalker.js +88 -12
- package/lib/engine-components/splines/SplineWalker.js.map +1 -1
- package/lib/engine-components/web/Clickthrough.d.ts +2 -0
- package/lib/engine-components/web/Clickthrough.js +23 -1
- package/lib/engine-components/web/Clickthrough.js.map +1 -1
- package/lib/engine-components/web/ScrollFollow.d.ts +4 -9
- package/lib/engine-components/web/ScrollFollow.js +26 -30
- package/lib/engine-components/web/ScrollFollow.js.map +1 -1
- package/lib/engine-components/web/ViewBox.d.ts +16 -0
- package/lib/engine-components/web/ViewBox.js +35 -3
- package/lib/engine-components/web/ViewBox.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/engine_physics.ts +3 -3
- package/src/engine-components/OrbitControls.ts +5 -2
- package/src/engine-components/splines/SplineWalker.ts +99 -14
- package/src/engine-components/web/Clickthrough.ts +28 -1
- package/src/engine-components/web/ScrollFollow.ts +31 -33
- package/src/engine-components/web/ViewBox.ts +35 -5
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Camera, Matrix4, PerspectiveCamera,
|
|
1
|
+
import { Camera, Matrix4, PerspectiveCamera, Vector3 } from "three";
|
|
2
2
|
|
|
3
3
|
import { isDevEnvironment } from "../../engine/debug/debug.js";
|
|
4
4
|
import { Gizmos } from "../../engine/engine_gizmos.js";
|
|
@@ -13,6 +13,8 @@ import { Behaviour } from "../Component.js";
|
|
|
13
13
|
const debugParam = getParam("debugviewbox");
|
|
14
14
|
const disabledGizmoColor = new RGBAColor(.5, .5, .5, .5);
|
|
15
15
|
|
|
16
|
+
export type ViewBoxMode = "continuous" | "once";
|
|
17
|
+
|
|
16
18
|
/**
|
|
17
19
|
* This component can be used to automatically fit a certain box area into the camera view - no matter your screen size or aspect ratio.
|
|
18
20
|
* This is useful for example to frame a character or object in the center of the screen and ensure it is always fully visible. You can also animate or scale the viewbox to create zoom or framing effects.
|
|
@@ -36,6 +38,9 @@ const disabledGizmoColor = new RGBAColor(.5, .5, .5, .5);
|
|
|
36
38
|
@registerType
|
|
37
39
|
export class ViewBox extends Behaviour {
|
|
38
40
|
|
|
41
|
+
/**
|
|
42
|
+
* All active ViewBox instances. The last one in the array is the currently active one.
|
|
43
|
+
*/
|
|
39
44
|
static readonly instances: ViewBox[] = [];
|
|
40
45
|
|
|
41
46
|
/**
|
|
@@ -45,21 +50,39 @@ export class ViewBox extends Behaviour {
|
|
|
45
50
|
@serializable()
|
|
46
51
|
referenceFieldOfView: number = -1;
|
|
47
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The mode determines if the viewbox should be applied once or continuously while it is the active viewbox.
|
|
55
|
+
* Options:
|
|
56
|
+
* - "once": The viewbox will be applied once when it becomes the active viewbox. This is useful if you want to fit the view once and then allow the user to zoom or pan freely.
|
|
57
|
+
* - "continuous": The viewbox will be applied continuously while it is the active viewbox. This is useful if you animate or scale the viewbox over time.
|
|
58
|
+
*/
|
|
59
|
+
@serializable()
|
|
60
|
+
get mode() { return this._mode; }
|
|
61
|
+
set mode(v: ViewBoxMode) {
|
|
62
|
+
if (v === this._mode) return;
|
|
63
|
+
this._mode = v;
|
|
64
|
+
if (v === "once") this._applyCount = 0;
|
|
65
|
+
if (debugParam || this.debug) console.debug("[ViewBox] Set mode:", v);
|
|
66
|
+
}
|
|
67
|
+
private _mode: ViewBoxMode = "continuous";
|
|
68
|
+
|
|
48
69
|
/**
|
|
49
70
|
* Enable debug logs and rendering for this component instance
|
|
50
71
|
*/
|
|
51
72
|
@serializable()
|
|
52
73
|
debug: boolean = false;
|
|
53
74
|
|
|
75
|
+
/** @internal */
|
|
54
76
|
onEnable(): void {
|
|
55
77
|
if (debugParam || this.debug || isDevEnvironment()) console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
|
|
56
78
|
// register instance
|
|
57
79
|
ViewBox.instances.push(this);
|
|
58
|
-
|
|
80
|
+
this._applyCount = 0;
|
|
59
81
|
this.removeUpdateCallback();
|
|
60
82
|
this.context.pre_render_callbacks.push(this.internalUpdate);
|
|
61
83
|
}
|
|
62
84
|
|
|
85
|
+
/** @internal */
|
|
63
86
|
onDisable(): void {
|
|
64
87
|
if (debugParam || this.debug) console.debug("[ViewBox] Disabled");
|
|
65
88
|
// unregister instance
|
|
@@ -77,6 +100,7 @@ export class ViewBox extends Behaviour {
|
|
|
77
100
|
|
|
78
101
|
private static readonly _tempProjectionMatrix: Matrix4 = new Matrix4();
|
|
79
102
|
private static readonly _tempProjectionMatrixInverse: Matrix4 = new Matrix4();
|
|
103
|
+
private _applyCount = 0;
|
|
80
104
|
|
|
81
105
|
private internalUpdate = () => {
|
|
82
106
|
if (this.context.isInXR) return;
|
|
@@ -108,6 +132,11 @@ export class ViewBox extends Behaviour {
|
|
|
108
132
|
return;
|
|
109
133
|
}
|
|
110
134
|
|
|
135
|
+
if (this._applyCount >= 1 && this.mode === "once") {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
this._applyCount++;
|
|
139
|
+
|
|
111
140
|
const domWidth = this.context.domWidth;
|
|
112
141
|
const domHeight = this.context.domHeight;
|
|
113
142
|
|
|
@@ -129,7 +158,7 @@ export class ViewBox extends Behaviour {
|
|
|
129
158
|
ViewBox._tempProjectionMatrix.copy(camera.projectionMatrix);
|
|
130
159
|
ViewBox._tempProjectionMatrixInverse.copy(camera.projectionMatrixInverse);
|
|
131
160
|
const view = camera.view;
|
|
132
|
-
const
|
|
161
|
+
const cameraZoom = camera.zoom;
|
|
133
162
|
const aspect = camera.aspect;
|
|
134
163
|
const fov = camera.fov;
|
|
135
164
|
// Set values to default so we can calculate the box size correctly
|
|
@@ -194,6 +223,7 @@ export class ViewBox extends Behaviour {
|
|
|
194
223
|
width / diffWidth,
|
|
195
224
|
height / diffHeight
|
|
196
225
|
);
|
|
226
|
+
const zoom = scale / (height * .5);
|
|
197
227
|
// console.log({ scale, width, height, boxWidth: boxWidth * camera.aspect, boxHeight, diffWidth, diffHeight, aspect: camera.aspect, distance })
|
|
198
228
|
// this.context.focusRectSettings.zoom = 1.39;
|
|
199
229
|
// if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
|
|
@@ -202,13 +232,13 @@ export class ViewBox extends Behaviour {
|
|
|
202
232
|
vec.project(camera);
|
|
203
233
|
this.context.focusRectSettings.offsetX = vec.x;
|
|
204
234
|
this.context.focusRectSettings.offsetY = vec.y;
|
|
205
|
-
this.context.focusRectSettings.zoom =
|
|
235
|
+
this.context.focusRectSettings.zoom = zoom;
|
|
206
236
|
// if we don't have a focus rect yet, set it to the dom element
|
|
207
237
|
if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
|
|
208
238
|
|
|
209
239
|
// Reset values
|
|
210
240
|
camera.view = view;
|
|
211
|
-
camera.zoom =
|
|
241
|
+
camera.zoom = cameraZoom;
|
|
212
242
|
camera.aspect = aspect;
|
|
213
243
|
camera.fov = fov;
|
|
214
244
|
camera.projectionMatrix.copy(ViewBox._tempProjectionMatrix);
|