@needle-tools/engine 4.10.0-next.2abafea → 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-p_i5rc9e.js → needle-engine.bundle-CUo74dPe.js} +7011 -7222
- package/dist/{needle-engine.bundle-7QhMyR9L.umd.cjs → needle-engine.bundle-Cf5H9Zy9.umd.cjs} +141 -152
- package/dist/{needle-engine.bundle-COzW_KEf.min.js → needle-engine.bundle-DlAVTipB.min.js} +159 -170
- package/dist/needle-engine.js +257 -259
- 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/engine_lightdata.d.ts +3 -3
- package/lib/engine/engine_lightdata.js +10 -10
- package/lib/engine/engine_lightdata.js.map +1 -1
- package/lib/engine/engine_physics_rapier.js +0 -4
- package/lib/engine/engine_physics_rapier.js.map +1 -1
- package/lib/engine/engine_scenelighting.d.ts +1 -1
- package/lib/engine/engine_scenelighting.js +5 -4
- package/lib/engine/engine_scenelighting.js.map +1 -1
- package/lib/engine/engine_utils.d.ts +1 -3
- package/lib/engine/engine_utils.js +0 -11
- package/lib/engine/engine_utils.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.js +0 -4
- package/lib/engine/webcomponents/needle-engine.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/Skybox.js +4 -22
- package/lib/engine-components/Skybox.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 +38 -159
- 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/engine_lightdata.ts +11 -11
- package/src/engine/engine_physics_rapier.ts +0 -3
- package/src/engine/engine_scenelighting.ts +6 -5
- package/src/engine/engine_utils.ts +0 -12
- 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/webcomponents/needle-engine.ts +0 -4
- package/src/engine-components/OrbitControls.ts +1 -40
- package/src/engine-components/Renderer.ts +1 -6
- package/src/engine-components/Skybox.ts +7 -26
- 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 +44 -190
- 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,186 +0,0 @@
|
|
|
1
|
-
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
2
|
-
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
3
|
-
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
4
|
-
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
5
|
-
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
6
|
-
};
|
|
7
|
-
var ViewBox_1;
|
|
8
|
-
import { PerspectiveCamera } from "three";
|
|
9
|
-
import { isDevEnvironment } from "../../engine/debug/debug.js";
|
|
10
|
-
import { Gizmos } from "../../engine/engine_gizmos.js";
|
|
11
|
-
import { serializable } from "../../engine/engine_serialization_decorator.js";
|
|
12
|
-
import { getTempVector } from "../../engine/engine_three_utils.js";
|
|
13
|
-
import { registerType } from "../../engine/engine_typestore.js";
|
|
14
|
-
import { getParam } from "../../engine/engine_utils.js";
|
|
15
|
-
import { Behaviour } from "../Component.js";
|
|
16
|
-
const debugParam = getParam("debugviewbox");
|
|
17
|
-
let ViewBox = ViewBox_1 = class ViewBox extends Behaviour {
|
|
18
|
-
static instances = [];
|
|
19
|
-
referenceFieldOfView = 60;
|
|
20
|
-
debug = false;
|
|
21
|
-
awake() {
|
|
22
|
-
// this.referenceFieldOfView = (this.context.mainCamera as PerspectiveCamera)?.fov || 60;
|
|
23
|
-
// setInterval(()=>{
|
|
24
|
-
// this.enabled = !this.enabled
|
|
25
|
-
// }, 1000)
|
|
26
|
-
}
|
|
27
|
-
onEnable() {
|
|
28
|
-
if (debugParam || this.debug || isDevEnvironment())
|
|
29
|
-
console.debug("[ViewBox] Using camera fov:", this.referenceFieldOfView);
|
|
30
|
-
ViewBox_1.instances.push(this);
|
|
31
|
-
}
|
|
32
|
-
onDisable() {
|
|
33
|
-
const idx = ViewBox_1.instances.indexOf(this);
|
|
34
|
-
if (idx !== -1)
|
|
35
|
-
ViewBox_1.instances.splice(idx, 1);
|
|
36
|
-
}
|
|
37
|
-
onBeforeRender() {
|
|
38
|
-
if (this.context.isInXR)
|
|
39
|
-
return;
|
|
40
|
-
const isActive = ViewBox_1.instances[ViewBox_1.instances.length - 1] === this;
|
|
41
|
-
if (!isActive) {
|
|
42
|
-
if (debugParam || this.debug)
|
|
43
|
-
Gizmos.DrawWireBox(this.gameObject.worldPosition, this.gameObject.worldScale, 0x333333);
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
if (debugParam || this.debug)
|
|
47
|
-
Gizmos.DrawWireBox(this.gameObject.worldPosition, this.gameObject.worldScale, 0xdddd00);
|
|
48
|
-
// calculate box size to fit the camera frustrum size at the current position (just scale)
|
|
49
|
-
const camera = this.context.mainCamera;
|
|
50
|
-
if (!camera)
|
|
51
|
-
return;
|
|
52
|
-
if (!(camera instanceof PerspectiveCamera)) {
|
|
53
|
-
// TODO: support orthographic camera
|
|
54
|
-
return;
|
|
55
|
-
}
|
|
56
|
-
if (this.referenceFieldOfView === undefined || this.referenceFieldOfView <= 0) {
|
|
57
|
-
if (debugParam || this.debug)
|
|
58
|
-
console.warn("[ViewBox] No valid referenceFieldOfView set, cannot adjust box size:", this.referenceFieldOfView);
|
|
59
|
-
return;
|
|
60
|
-
}
|
|
61
|
-
const domWidth = this.context.domWidth;
|
|
62
|
-
const domHeight = this.context.domHeight;
|
|
63
|
-
let rectPosX = 0;
|
|
64
|
-
let rectPosY = 0;
|
|
65
|
-
let rectWidth = domWidth;
|
|
66
|
-
let rectHeight = domHeight;
|
|
67
|
-
let diffWidth = 1;
|
|
68
|
-
let diffHeight = 1;
|
|
69
|
-
// use focus rect if available
|
|
70
|
-
const focusRectSize = this.context.focusRectSize;
|
|
71
|
-
if (focusRectSize) {
|
|
72
|
-
// console.log(focusRectSize)
|
|
73
|
-
rectPosX = focusRectSize.x;
|
|
74
|
-
rectPosY = focusRectSize.y;
|
|
75
|
-
rectWidth = focusRectSize.width;
|
|
76
|
-
rectHeight = focusRectSize.height;
|
|
77
|
-
diffWidth = domWidth / rectWidth;
|
|
78
|
-
diffHeight = domHeight / rectHeight;
|
|
79
|
-
}
|
|
80
|
-
// const view = camera.view;
|
|
81
|
-
const view = camera.view;
|
|
82
|
-
const zoom = camera.zoom;
|
|
83
|
-
const aspect = camera.aspect;
|
|
84
|
-
const fov = camera.fov;
|
|
85
|
-
camera.view = null;
|
|
86
|
-
camera.zoom = 1;
|
|
87
|
-
// camera.aspect = rectWidth / rectHeight;
|
|
88
|
-
camera.fov = this.referenceFieldOfView;
|
|
89
|
-
camera.updateProjectionMatrix();
|
|
90
|
-
const boxPosition = this.gameObject.worldPosition;
|
|
91
|
-
const boxScale = this.gameObject.worldScale;
|
|
92
|
-
// const fov = this.referenceFieldOfView
|
|
93
|
-
const distance = camera.worldPosition.distanceTo(boxPosition);
|
|
94
|
-
const vFOV = this.referenceFieldOfView * Math.PI / 180; // convert vertical fov to radians
|
|
95
|
-
const height = 2 * Math.tan(vFOV / 2) * distance; // visible height
|
|
96
|
-
const width = height * camera.aspect; // visible width
|
|
97
|
-
const projectedBox = this.projectBoxIntoCamera(boxPosition, boxScale, camera, height * .5);
|
|
98
|
-
const boxWidth = (projectedBox.maxX - projectedBox.minX);
|
|
99
|
-
const boxHeight = (projectedBox.maxY - projectedBox.minY);
|
|
100
|
-
// TODO: take the rect size different into account
|
|
101
|
-
const scale = this.fit(boxWidth * camera.aspect, boxHeight, width / diffWidth, height / diffHeight);
|
|
102
|
-
const vec = getTempVector(boxPosition);
|
|
103
|
-
vec.project(camera);
|
|
104
|
-
this.context.focusRectSettings.offsetX = vec.x;
|
|
105
|
-
this.context.focusRectSettings.offsetY = vec.y;
|
|
106
|
-
this.context.focusRectSettings.zoom = scale;
|
|
107
|
-
// if we don't have a focus rect yet, set it to the dom element
|
|
108
|
-
if (!this.context.focusRect)
|
|
109
|
-
this.context.setCameraFocusRect(this.context.domElement);
|
|
110
|
-
// Reset values
|
|
111
|
-
camera.view = view;
|
|
112
|
-
camera.zoom = zoom;
|
|
113
|
-
camera.aspect = aspect;
|
|
114
|
-
camera.fov = fov;
|
|
115
|
-
// camera.updateProjectionMatrix();
|
|
116
|
-
// BACKLOG: some code for box scale of an object (different component)
|
|
117
|
-
// this.gameObject.worldScale = getTempVector(width, height, worldscale.z);
|
|
118
|
-
// this.gameObject.scale.multiplyScalar(.98)
|
|
119
|
-
// const minscale = Math.min(width, height);
|
|
120
|
-
// console.log(width, height);
|
|
121
|
-
// this.gameObject.worldScale = getTempVector(scale, scale, scale);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Cover fit
|
|
125
|
-
*/
|
|
126
|
-
fit(width1, height1, width2, height2) {
|
|
127
|
-
const scaleX = width2 / width1;
|
|
128
|
-
const scaleY = height2 / height1;
|
|
129
|
-
return Math.min(scaleX, scaleY);
|
|
130
|
-
}
|
|
131
|
-
projectBoxIntoCamera(position, scale, camera, diff) {
|
|
132
|
-
const factor = .5 * diff;
|
|
133
|
-
const corners = [
|
|
134
|
-
getTempVector(-scale.x * factor, -scale.y * factor, -scale.z * factor),
|
|
135
|
-
getTempVector(scale.x * factor, -scale.y * factor, -scale.z * factor),
|
|
136
|
-
getTempVector(-scale.x * factor, scale.y * factor, -scale.z * factor),
|
|
137
|
-
getTempVector(scale.x * factor, scale.y * factor, -scale.z * factor),
|
|
138
|
-
getTempVector(-scale.x * factor, -scale.y * factor, scale.z * factor),
|
|
139
|
-
getTempVector(scale.x * factor, -scale.y * factor, scale.z * factor),
|
|
140
|
-
getTempVector(-scale.x * factor, scale.y * factor, scale.z * factor),
|
|
141
|
-
getTempVector(scale.x * factor, scale.y * factor, scale.z * factor),
|
|
142
|
-
];
|
|
143
|
-
let minX = Number.POSITIVE_INFINITY;
|
|
144
|
-
let maxX = Number.NEGATIVE_INFINITY;
|
|
145
|
-
let minY = Number.POSITIVE_INFINITY;
|
|
146
|
-
let maxY = Number.NEGATIVE_INFINITY;
|
|
147
|
-
for (let i = 0; i < corners.length; i++) {
|
|
148
|
-
const c = corners[i];
|
|
149
|
-
c.add(position);
|
|
150
|
-
c.project(camera);
|
|
151
|
-
if (c.x < minX)
|
|
152
|
-
minX = c.x;
|
|
153
|
-
if (c.x > maxX)
|
|
154
|
-
maxX = c.x;
|
|
155
|
-
if (c.y < minY)
|
|
156
|
-
minY = c.y;
|
|
157
|
-
if (c.y > maxY)
|
|
158
|
-
maxY = c.y;
|
|
159
|
-
}
|
|
160
|
-
// if(!this._projectedBoxElement) {
|
|
161
|
-
// this._projectedBoxElement = document.createElement("div");
|
|
162
|
-
// this.context.domElement.appendChild(this._projectedBoxElement);
|
|
163
|
-
// }
|
|
164
|
-
// this._projectedBoxElement.style.position = "fixed";
|
|
165
|
-
// this._projectedBoxElement.style.outline = "10px solid red";
|
|
166
|
-
// this._projectedBoxElement.style.left = ((minX * .5 + .5) * this.context.domWidth) + "px";
|
|
167
|
-
// this._projectedBoxElement.style.top = ((-maxY * .5 + .5) * this.context.domHeight) + "px";
|
|
168
|
-
// this._projectedBoxElement.style.width = ((maxX - minX) * .5 * this.context.domWidth) + "px";
|
|
169
|
-
// this._projectedBoxElement.style.height = ((maxY - minY) * .5 * this.context.domHeight) + "px";
|
|
170
|
-
// this._projectedBoxElement.style.pointerEvents = "none";
|
|
171
|
-
// this._projectedBoxElement.style.zIndex = "1000";
|
|
172
|
-
return { minX, maxX, minY, maxY };
|
|
173
|
-
}
|
|
174
|
-
_projectedBoxElement = null;
|
|
175
|
-
};
|
|
176
|
-
__decorate([
|
|
177
|
-
serializable()
|
|
178
|
-
], ViewBox.prototype, "referenceFieldOfView", void 0);
|
|
179
|
-
__decorate([
|
|
180
|
-
serializable()
|
|
181
|
-
], ViewBox.prototype, "debug", void 0);
|
|
182
|
-
ViewBox = ViewBox_1 = __decorate([
|
|
183
|
-
registerType
|
|
184
|
-
], ViewBox);
|
|
185
|
-
export { ViewBox };
|
|
186
|
-
//# sourceMappingURL=ViewBox.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ViewBox.js","sourceRoot":"","sources":["../../../src/engine-components/web/ViewBox.ts"],"names":[],"mappings":";;;;;;;AAAA,OAAO,EAAU,iBAAiB,EAAoB,MAAM,OAAO,CAAC;AAEpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAC;AAC/D,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;AACvD,OAAO,EAAE,YAAY,EAAE,MAAM,gDA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IADC,YAAY,EAAE;qDACmB;AAGlC;IADC,YAAY,EAAE;sCACQ;AARd,OAAO;IADnB,YAAY;GACA,OAAO,CA4LnB;SA5LY,OAAO"}
|
|
@@ -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
|
-
}
|