@needle-tools/engine 4.10.0-next.f5ce0ae → 4.10.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 +12 -3
- package/README.md +2 -1
- package/components.needle.json +1 -1
- package/dist/{needle-engine.bundle-VqrrECGF.umd.cjs → needle-engine.bundle-BtblaOL-.umd.cjs} +105 -105
- package/dist/{needle-engine.bundle-pI8o_eru.min.js → needle-engine.bundle-D7m4Nz6G.min.js} +116 -116
- package/dist/{needle-engine.bundle-DSzlnhCs.js → needle-engine.bundle-DzZhd0uq.js} +3194 -3188
- 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-components/Camera.d.ts +1 -1
- package/lib/engine-components/Camera.js +1 -1
- package/lib/engine-components/CharacterController.d.ts +2 -2
- package/lib/engine-components/CharacterController.js +2 -2
- package/lib/engine-components/OrbitControls.d.ts +1 -1
- package/lib/engine-components/OrbitControls.js +1 -1
- package/lib/engine-components/timeline/TimelineModels.d.ts +37 -2
- package/lib/engine-components/timeline/TimelineModels.js +6 -0
- package/lib/engine-components/timeline/TimelineModels.js.map +1 -1
- package/lib/engine-components/web/ScrollFollow.d.ts +1 -0
- package/lib/engine-components/web/ScrollFollow.js +1 -0
- package/lib/engine-components/web/ScrollFollow.js.map +1 -1
- package/lib/engine-components/web/ViewBox.d.ts +22 -3
- package/lib/engine-components/web/ViewBox.js +41 -13
- package/lib/engine-components/web/ViewBox.js.map +1 -1
- package/lib/engine-components/webxr/WebARSessionRoot.js +1 -0
- package/lib/engine-components/webxr/WebARSessionRoot.js.map +1 -1
- package/package.json +2 -2
- package/src/engine-components/Camera.ts +1 -1
- package/src/engine-components/CharacterController.ts +2 -2
- package/src/engine-components/OrbitControls.ts +1 -1
- package/src/engine-components/timeline/TimelineModels.ts +37 -3
- package/src/engine-components/web/ScrollFollow.ts +1 -0
- package/src/engine-components/web/ViewBox.ts +43 -13
- package/src/engine-components/webxr/WebARSessionRoot.ts +1 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Camera, PerspectiveCamera, Quaternion, Scene, Vector2, Vector3 } from "three";
|
|
1
|
+
import { Camera, Matrix4, PerspectiveCamera, Quaternion, Scene, Vector2, Vector3 } from "three";
|
|
2
2
|
|
|
3
3
|
import { isDevEnvironment } from "../../engine/debug/debug.js";
|
|
4
4
|
import { Gizmos } from "../../engine/engine_gizmos.js";
|
|
@@ -17,6 +17,22 @@ const disabledGizmoColor = new RGBAColor(.5, .5, .5, .5);
|
|
|
17
17
|
* 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
18
|
*
|
|
19
19
|
* Add the ViewBox to an object into your scene
|
|
20
|
+
*
|
|
21
|
+
* @link [Example on needle.run](https://viewbox-demo-z23hmxbz2gkayo-z1nyzm6.needle.run/)
|
|
22
|
+
* @link [Scrollytelling Demo using animated Viewbox](https://scrollytelling-bike-z23hmxb2gnu5a.needle.run/)
|
|
23
|
+
* @link [Example on Stackblitz](https://stackblitz.com/edit/needle-engine-view-box-example)
|
|
24
|
+
*
|
|
25
|
+
* @example Add a Viewbox component to an object in your scene
|
|
26
|
+
* ```ts
|
|
27
|
+
const viewBox = new Object3D();
|
|
28
|
+
viewBox.scale.set(0, 0, 0);
|
|
29
|
+
viewBox.addComponent(ViewBox, { debug: true });
|
|
30
|
+
scene.add(viewBox);
|
|
31
|
+
* ```
|
|
32
|
+
|
|
33
|
+
* @category Camera
|
|
34
|
+
* @group Components
|
|
35
|
+
* @component
|
|
20
36
|
*/
|
|
21
37
|
@registerType
|
|
22
38
|
export class ViewBox extends Behaviour {
|
|
@@ -25,10 +41,10 @@ export class ViewBox extends Behaviour {
|
|
|
25
41
|
|
|
26
42
|
/**
|
|
27
43
|
* The reference field of view is used to calculate the box size. This should usually be the same as your camera's fov.
|
|
28
|
-
* @default
|
|
44
|
+
* @default -1 (meaning it will use the camera fov on the first frame)
|
|
29
45
|
*/
|
|
30
46
|
@serializable()
|
|
31
|
-
referenceFieldOfView: number
|
|
47
|
+
referenceFieldOfView: number = -1;
|
|
32
48
|
|
|
33
49
|
/**
|
|
34
50
|
* Enable debug logs and rendering for this component instance
|
|
@@ -40,6 +56,9 @@ export class ViewBox extends Behaviour {
|
|
|
40
56
|
if (debugParam || this.debug || isDevEnvironment()) console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
|
|
41
57
|
// register instance
|
|
42
58
|
ViewBox.instances.push(this);
|
|
59
|
+
|
|
60
|
+
this.removeUpdateCallback();
|
|
61
|
+
this.context.pre_render_callbacks.push(this.internalUpdate);
|
|
43
62
|
}
|
|
44
63
|
|
|
45
64
|
onDisable(): void {
|
|
@@ -48,11 +67,21 @@ export class ViewBox extends Behaviour {
|
|
|
48
67
|
const idx = ViewBox.instances.indexOf(this);
|
|
49
68
|
if (idx !== -1) ViewBox.instances.splice(idx, 1);
|
|
50
69
|
this._projectedBoxElement?.remove();
|
|
70
|
+
this.removeUpdateCallback();
|
|
51
71
|
}
|
|
52
72
|
|
|
53
|
-
|
|
73
|
+
private removeUpdateCallback() {
|
|
74
|
+
// remove prerender callback
|
|
75
|
+
const cbIdx = this.context.pre_render_callbacks.indexOf(this.internalUpdate);
|
|
76
|
+
if (cbIdx !== -1) this.context.pre_render_callbacks.splice(cbIdx, 1);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
private static readonly _tempProjectionMatrix: Matrix4 = new Matrix4();
|
|
80
|
+
private static readonly _tempProjectionMatrixInverse: Matrix4 = new Matrix4();
|
|
81
|
+
|
|
82
|
+
private internalUpdate = () => {
|
|
54
83
|
if (this.context.isInXR) return;
|
|
55
|
-
if (this.destroyed) return;
|
|
84
|
+
if (this.destroyed || !this.activeAndEnabled) return;
|
|
56
85
|
const isActive = ViewBox.instances[ViewBox.instances.length - 1] === this;
|
|
57
86
|
if (!isActive) {
|
|
58
87
|
if (debugParam || this.debug) {
|
|
@@ -70,8 +99,9 @@ export class ViewBox extends Behaviour {
|
|
|
70
99
|
return;
|
|
71
100
|
}
|
|
72
101
|
|
|
73
|
-
if (this.referenceFieldOfView === undefined) {
|
|
102
|
+
if (this.referenceFieldOfView === undefined || this.referenceFieldOfView === -1) {
|
|
74
103
|
this.referenceFieldOfView = camera.fov;
|
|
104
|
+
console.debug("[ViewBox] No referenceFieldOfView set, using camera fov:", this.referenceFieldOfView);
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
if (this.referenceFieldOfView === undefined || this.referenceFieldOfView <= 0) {
|
|
@@ -82,8 +112,6 @@ export class ViewBox extends Behaviour {
|
|
|
82
112
|
const domWidth = this.context.domWidth;
|
|
83
113
|
const domHeight = this.context.domHeight;
|
|
84
114
|
|
|
85
|
-
let rectPosX = 0;
|
|
86
|
-
let rectPosY = 0;
|
|
87
115
|
let rectWidth = domWidth;
|
|
88
116
|
let rectHeight = domHeight;
|
|
89
117
|
let diffWidth = 1;
|
|
@@ -91,9 +119,6 @@ export class ViewBox extends Behaviour {
|
|
|
91
119
|
// use focus rect if available
|
|
92
120
|
const focusRectSize = this.context.focusRectSize;
|
|
93
121
|
if (focusRectSize) {
|
|
94
|
-
// console.log(focusRectSize)
|
|
95
|
-
rectPosX = focusRectSize.x;
|
|
96
|
-
rectPosY = focusRectSize.y;
|
|
97
122
|
rectWidth = focusRectSize.width;
|
|
98
123
|
rectHeight = focusRectSize.height;
|
|
99
124
|
diffWidth = domWidth / rectWidth;
|
|
@@ -101,10 +126,14 @@ export class ViewBox extends Behaviour {
|
|
|
101
126
|
}
|
|
102
127
|
|
|
103
128
|
|
|
129
|
+
// Copy the projection matrix and restore values so we can reset it later
|
|
130
|
+
ViewBox._tempProjectionMatrix.copy(camera.projectionMatrix);
|
|
131
|
+
ViewBox._tempProjectionMatrixInverse.copy(camera.projectionMatrixInverse);
|
|
104
132
|
const view = camera.view;
|
|
105
133
|
const zoom = camera.zoom;
|
|
106
134
|
const aspect = camera.aspect;
|
|
107
135
|
const fov = camera.fov;
|
|
136
|
+
// Set values to default so we can calculate the box size correctly
|
|
108
137
|
camera.view = null;
|
|
109
138
|
camera.zoom = 1;
|
|
110
139
|
camera.fov = this.referenceFieldOfView;
|
|
@@ -128,7 +157,7 @@ export class ViewBox extends Behaviour {
|
|
|
128
157
|
const positionDirection = getTempVector(direction);
|
|
129
158
|
positionDirection.y *= .00000001; // stay on horizontal plane mostly
|
|
130
159
|
positionDirection.normalize();
|
|
131
|
-
const lengthToMove = (boxSizeMax - distance);
|
|
160
|
+
const lengthToMove = (boxSizeMax - distance);
|
|
132
161
|
const newPosition = cameraPosition.add(positionDirection.multiplyScalar(lengthToMove));
|
|
133
162
|
camera.worldPosition = newPosition.lerp(cameraPosition, 1 - this.context.time.deltaTime);
|
|
134
163
|
}
|
|
@@ -183,7 +212,8 @@ export class ViewBox extends Behaviour {
|
|
|
183
212
|
camera.zoom = zoom;
|
|
184
213
|
camera.aspect = aspect;
|
|
185
214
|
camera.fov = fov;
|
|
186
|
-
|
|
215
|
+
camera.projectionMatrix.copy(ViewBox._tempProjectionMatrix);
|
|
216
|
+
camera.projectionMatrixInverse.copy(ViewBox._tempProjectionMatrixInverse);
|
|
187
217
|
|
|
188
218
|
|
|
189
219
|
// BACKLOG: some code for box scale of an object (different component)
|