@needle-tools/engine 4.10.0-next.4f9d92a → 4.10.0-next.55c0bf9
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-BeZ_xmJa.js → needle-engine.bundle-CUo74dPe.js} +5431 -5613
- package/dist/{needle-engine.bundle-D4dO0t5I.umd.cjs → needle-engine.bundle-Cf5H9Zy9.umd.cjs} +137 -148
- package/dist/{needle-engine.bundle-C3bpSNYu.min.js → needle-engine.bundle-DlAVTipB.min.js} +153 -164
- package/dist/needle-engine.js +257 -258
- package/dist/needle-engine.min.js +1 -1
- package/dist/needle-engine.umd.cjs +1 -1
- package/lib/engine/codegen/register_types.js +0 -2
- package/lib/engine/codegen/register_types.js.map +1 -1
- package/lib/engine/engine_camera.d.ts +1 -7
- package/lib/engine/engine_camera.fit.d.ts +1 -1
- package/lib/engine/engine_camera.fit.js +30 -3
- package/lib/engine/engine_camera.fit.js.map +1 -1
- package/lib/engine/engine_camera.js +6 -46
- package/lib/engine/engine_camera.js.map +1 -1
- package/lib/engine/engine_context.d.ts +0 -6
- package/lib/engine/engine_context.js +9 -48
- package/lib/engine/engine_context.js.map +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.js +1 -1
- package/lib/engine/extensions/NEEDLE_lightmaps.js.map +1 -1
- package/lib/engine/webcomponents/logo-element.d.ts +1 -1
- package/lib/engine/webcomponents/logo-element.js +5 -29
- package/lib/engine/webcomponents/logo-element.js.map +1 -1
- package/lib/engine/webcomponents/needle menu/needle-menu.js +3 -4
- package/lib/engine/webcomponents/needle menu/needle-menu.js.map +1 -1
- package/lib/engine/webcomponents/needle-engine.loading.d.ts +1 -0
- package/lib/engine/webcomponents/needle-engine.loading.js +36 -3
- package/lib/engine/webcomponents/needle-engine.loading.js.map +1 -1
- package/lib/engine-components/OrbitControls.d.ts +1 -4
- package/lib/engine-components/OrbitControls.js +6 -30
- package/lib/engine-components/OrbitControls.js.map +1 -1
- package/lib/engine-components/Renderer.js +1 -6
- package/lib/engine-components/Renderer.js.map +1 -1
- package/lib/engine-components/codegen/components.d.ts +0 -1
- package/lib/engine-components/codegen/components.js +0 -1
- package/lib/engine-components/codegen/components.js.map +1 -1
- package/lib/engine-components/timeline/PlayableDirector.d.ts +0 -7
- package/lib/engine-components/timeline/PlayableDirector.js +0 -7
- package/lib/engine-components/timeline/PlayableDirector.js.map +1 -1
- package/lib/engine-components/timeline/TimelineModels.d.ts +1 -9
- package/lib/engine-components/timeline/TimelineTracks.js +2 -4
- package/lib/engine-components/timeline/TimelineTracks.js.map +1 -1
- package/lib/engine-components/utils/LookAt.js +1 -5
- package/lib/engine-components/utils/LookAt.js.map +1 -1
- package/lib/engine-components/web/Clickthrough.js +2 -10
- package/lib/engine-components/web/Clickthrough.js.map +1 -1
- package/lib/engine-components/web/ScrollFollow.d.ts +0 -22
- package/lib/engine-components/web/ScrollFollow.js +13 -124
- package/lib/engine-components/web/ScrollFollow.js.map +1 -1
- package/lib/engine-components/web/index.d.ts +0 -1
- package/lib/engine-components/web/index.js +0 -1
- package/lib/engine-components/web/index.js.map +1 -1
- package/package.json +1 -1
- package/src/engine/codegen/register_types.ts +0 -2
- package/src/engine/engine_camera.fit.ts +32 -2
- package/src/engine/engine_camera.ts +8 -62
- package/src/engine/engine_context.ts +10 -50
- package/src/engine/extensions/NEEDLE_lightmaps.ts +1 -1
- package/src/engine/webcomponents/logo-element.ts +4 -29
- package/src/engine/webcomponents/needle menu/needle-menu.ts +3 -4
- package/src/engine/webcomponents/needle-engine.loading.ts +32 -32
- package/src/engine-components/OrbitControls.ts +1 -40
- package/src/engine-components/Renderer.ts +1 -6
- package/src/engine-components/codegen/components.ts +0 -1
- package/src/engine-components/timeline/PlayableDirector.ts +0 -9
- package/src/engine-components/timeline/TimelineModels.ts +1 -9
- package/src/engine-components/timeline/TimelineTracks.ts +2 -4
- package/src/engine-components/utils/LookAt.ts +1 -5
- package/src/engine-components/web/Clickthrough.ts +2 -11
- package/src/engine-components/web/ScrollFollow.ts +15 -149
- package/src/engine-components/web/index.ts +1 -2
- package/lib/engine-components/web/ViewBox.d.ts +0 -16
- package/lib/engine-components/web/ViewBox.js +0 -186
- package/lib/engine-components/web/ViewBox.js.map +0 -1
- package/src/engine-components/web/ViewBox.ts +0 -202
|
@@ -1,202 +0,0 @@
|
|
|
1
|
-
import { Camera, PerspectiveCamera, Vector2, Vector3 } from "three";
|
|
2
|
-
|
|
3
|
-
import { isDevEnvironment } from "../../engine/debug/debug.js";
|
|
4
|
-
import { Gizmos } from "../../engine/engine_gizmos.js";
|
|
5
|
-
import { serializable } from "../../engine/engine_serialization_decorator.js";
|
|
6
|
-
import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
7
|
-
import { registerType } from "../../engine/engine_typestore.js";
|
|
8
|
-
import { getParam } from "../../engine/engine_utils.js";
|
|
9
|
-
import { Behaviour } from "../Component.js";
|
|
10
|
-
|
|
11
|
-
const debugParam = getParam("debugviewbox");
|
|
12
|
-
|
|
13
|
-
@registerType
|
|
14
|
-
export class ViewBox extends Behaviour {
|
|
15
|
-
|
|
16
|
-
static instances: ViewBox[] = [];
|
|
17
|
-
|
|
18
|
-
@serializable()
|
|
19
|
-
referenceFieldOfView: number = 60;
|
|
20
|
-
|
|
21
|
-
@serializable()
|
|
22
|
-
debug: boolean = false;
|
|
23
|
-
|
|
24
|
-
awake() {
|
|
25
|
-
// this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
|
|
26
|
-
// setInterval(()=>{
|
|
27
|
-
// this.enabled = !this.enabled
|
|
28
|
-
// }, 1000)
|
|
29
|
-
}
|
|
30
|
-
onEnable(): void {
|
|
31
|
-
if (debugParam || this.debug || isDevEnvironment()) console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
|
|
32
|
-
ViewBox.instances.push(this);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
onDisable(): void {
|
|
36
|
-
const idx = ViewBox.instances.indexOf(this);
|
|
37
|
-
if (idx !== -1) ViewBox.instances.splice(idx, 1);
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
onBeforeRender() {
|
|
41
|
-
if (this.context.isInXR) return;
|
|
42
|
-
const isActive = ViewBox.instances[ViewBox.instances.length - 1] === this;
|
|
43
|
-
if (!isActive) {
|
|
44
|
-
if (debugParam || this.debug) Gizmos.DrawWireBox(this.gameObject.worldPosition, this.gameObject.worldScale, 0x333333);
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (debugParam || this.debug) Gizmos.DrawWireBox(this.gameObject.worldPosition, this.gameObject.worldScale, 0xdddd00);
|
|
48
|
-
|
|
49
|
-
// calculate box size to fit the camera frustrum size at the current position (just scale)
|
|
50
|
-
const camera = this.context.mainCamera;
|
|
51
|
-
if (!camera) return;
|
|
52
|
-
if (!(camera instanceof PerspectiveCamera)) {
|
|
53
|
-
// TODO: support orthographic camera
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (this.referenceFieldOfView === undefined || this.referenceFieldOfView <= 0) {
|
|
58
|
-
if (debugParam || this.debug) console.warn("[ViewBox] No valid referenceFieldOfView set, cannot adjust box size:", this.referenceFieldOfView);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
const domWidth = this.context.domWidth;
|
|
63
|
-
const domHeight = this.context.domHeight;
|
|
64
|
-
|
|
65
|
-
let rectPosX = 0;
|
|
66
|
-
let rectPosY = 0;
|
|
67
|
-
let rectWidth = domWidth;
|
|
68
|
-
let rectHeight = domHeight;
|
|
69
|
-
let diffWidth = 1;
|
|
70
|
-
let diffHeight = 1;
|
|
71
|
-
// use focus rect if available
|
|
72
|
-
const focusRectSize = this.context.focusRectSize;
|
|
73
|
-
if (focusRectSize) {
|
|
74
|
-
// console.log(focusRectSize)
|
|
75
|
-
rectPosX = focusRectSize.x;
|
|
76
|
-
rectPosY = focusRectSize.y;
|
|
77
|
-
rectWidth = focusRectSize.width;
|
|
78
|
-
rectHeight = focusRectSize.height;
|
|
79
|
-
diffWidth = domWidth / rectWidth;
|
|
80
|
-
diffHeight = domHeight / rectHeight;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// const view = camera.view;
|
|
84
|
-
const view = camera.view;
|
|
85
|
-
const zoom = camera.zoom;
|
|
86
|
-
const aspect = camera.aspect;
|
|
87
|
-
const fov = camera.fov;
|
|
88
|
-
camera.view = null;
|
|
89
|
-
camera.zoom = 1;
|
|
90
|
-
// camera.aspect = rectWidth / rectHeight;
|
|
91
|
-
camera.fov = this.referenceFieldOfView;
|
|
92
|
-
camera.updateProjectionMatrix();
|
|
93
|
-
|
|
94
|
-
const boxPosition = this.gameObject.worldPosition;
|
|
95
|
-
const boxScale = this.gameObject.worldScale;
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
// const fov = this.referenceFieldOfView
|
|
100
|
-
const distance = camera.worldPosition.distanceTo(boxPosition);
|
|
101
|
-
const vFOV = this.referenceFieldOfView * Math.PI / 180; // convert vertical fov to radians
|
|
102
|
-
const height = 2 * Math.tan(vFOV / 2) * distance; // visible height
|
|
103
|
-
const width = height * camera.aspect; // visible width
|
|
104
|
-
|
|
105
|
-
const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, height * .5);
|
|
106
|
-
const boxWidth = (projectedBox.maxX - projectedBox.minX);
|
|
107
|
-
const boxHeight = (projectedBox.maxY - projectedBox.minY);
|
|
108
|
-
|
|
109
|
-
// TODO: take the rect size different into account
|
|
110
|
-
const scale = this.fit(
|
|
111
|
-
boxWidth * camera.aspect,
|
|
112
|
-
boxHeight,
|
|
113
|
-
width / diffWidth,
|
|
114
|
-
height / diffHeight
|
|
115
|
-
);
|
|
116
|
-
const vec = getTempVector(boxPosition);
|
|
117
|
-
vec.project(camera);
|
|
118
|
-
this.context.focusRectSettings.offsetX = vec.x;
|
|
119
|
-
this.context.focusRectSettings.offsetY = vec.y;
|
|
120
|
-
this.context.focusRectSettings.zoom = scale;
|
|
121
|
-
// if we don't have a focus rect yet, set it to the dom element
|
|
122
|
-
if (!this.context.focusRect) this.context.setCameraFocusRect(this.context.domElement);
|
|
123
|
-
|
|
124
|
-
// Reset values
|
|
125
|
-
camera.view = view;
|
|
126
|
-
camera.zoom = zoom;
|
|
127
|
-
camera.aspect = aspect;
|
|
128
|
-
camera.fov = fov;
|
|
129
|
-
// camera.updateProjectionMatrix();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// BACKLOG: some code for box scale of an object (different component)
|
|
133
|
-
// this.gameObject.worldScale = getTempVector(width, height, worldscale.z);
|
|
134
|
-
// this.gameObject.scale.multiplyScalar(.98)
|
|
135
|
-
// const minscale = Math.min(width, height);
|
|
136
|
-
// console.log(width, height);
|
|
137
|
-
// this.gameObject.worldScale = getTempVector(scale, scale, scale);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Cover fit
|
|
143
|
-
*/
|
|
144
|
-
private fit(width1: number, height1: number, width2: number, height2: number) {
|
|
145
|
-
const scaleX = width2 / width1;
|
|
146
|
-
const scaleY = height2 / height1;
|
|
147
|
-
return Math.min(scaleX, scaleY);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
private projectBoxIntoCamera(position: Vector3, scale: Vector3, camera: Camera, diff: number) {
|
|
153
|
-
|
|
154
|
-
const factor = .5 * diff;
|
|
155
|
-
|
|
156
|
-
const corners = [
|
|
157
|
-
getTempVector(-scale.x * factor, -scale.y * factor, -scale.z * factor),
|
|
158
|
-
getTempVector(scale.x * factor, -scale.y * factor, -scale.z * factor),
|
|
159
|
-
getTempVector(-scale.x * factor, scale.y * factor, -scale.z * factor),
|
|
160
|
-
getTempVector(scale.x * factor, scale.y * factor, -scale.z * factor),
|
|
161
|
-
getTempVector(-scale.x * factor, -scale.y * factor, scale.z * factor),
|
|
162
|
-
getTempVector(scale.x * factor, -scale.y * factor, scale.z * factor),
|
|
163
|
-
getTempVector(-scale.x * factor, scale.y * factor, scale.z * factor),
|
|
164
|
-
getTempVector(scale.x * factor, scale.y * factor, scale.z * factor),
|
|
165
|
-
];
|
|
166
|
-
let minX = Number.POSITIVE_INFINITY;
|
|
167
|
-
let maxX = Number.NEGATIVE_INFINITY;
|
|
168
|
-
let minY = Number.POSITIVE_INFINITY;
|
|
169
|
-
let maxY = Number.NEGATIVE_INFINITY;
|
|
170
|
-
for (let i = 0; i < corners.length; i++) {
|
|
171
|
-
const c = corners[i];
|
|
172
|
-
c.add(position);
|
|
173
|
-
c.project(camera);
|
|
174
|
-
if (c.x < minX) minX = c.x;
|
|
175
|
-
if (c.x > maxX) maxX = c.x;
|
|
176
|
-
if (c.y < minY) minY = c.y;
|
|
177
|
-
if (c.y > maxY) maxY = c.y;
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
// if(!this._projectedBoxElement) {
|
|
181
|
-
// this._projectedBoxElement = document.createElement("div");
|
|
182
|
-
// this.context.domElement.appendChild(this._projectedBoxElement);
|
|
183
|
-
// }
|
|
184
|
-
// this._projectedBoxElement.style.position = "fixed";
|
|
185
|
-
// this._projectedBoxElement.style.outline = "10px solid red";
|
|
186
|
-
// this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
|
|
187
|
-
// this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
|
|
188
|
-
// this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
|
|
189
|
-
// this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
|
|
190
|
-
// this._projectedBoxElement.style.pointerEvents = "none";
|
|
191
|
-
// this._projectedBoxElement.style.zIndex = "1000";
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
return { minX, maxX, minY, maxY };
|
|
195
|
-
|
|
196
|
-
}
|
|
197
|
-
private _projectedBoxElement: HTMLElement | null = null;
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
}
|