astro-viewer 2.0.0 → 3.1.0
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/dist/astroviewer.cjs +19832 -16986
- package/dist/astroviewer.js +1 -1
- package/dist/astroviewer.min.js +1 -1
- package/lib-esm/AstroSphere.d.ts +31 -2
- package/lib-esm/AstroSphere.js +267 -16
- package/lib-esm/AstroViewer.d.ts +33 -2
- package/lib-esm/AstroViewer.js +93 -0
- package/lib-esm/Camera.js +24 -8
- package/lib-esm/Config.js +12 -0
- package/lib-esm/Global.js +12 -0
- package/lib-esm/index.d.ts +8 -1
- package/lib-esm/index.js +18 -1
- package/lib-esm/model/AbstractSkyEntity.d.ts +10 -0
- package/lib-esm/model/AbstractSkyEntity.js +12 -0
- package/lib-esm/model/AstroGL.js +12 -0
- package/lib-esm/model/ColorMaps.js +12 -0
- package/lib-esm/model/MetadataColumn.js +12 -0
- package/lib-esm/model/MetadataManager.js +12 -0
- package/lib-esm/model/Point.js +12 -0
- package/lib-esm/model/Point2D.js +12 -0
- package/lib-esm/model/Source.js +12 -0
- package/lib-esm/model/SphereFoV.d.ts +30 -0
- package/lib-esm/model/SphereFoV.js +195 -0
- package/lib-esm/model/catalogues/CatalogueGL.js +12 -0
- package/lib-esm/model/catalogues/CatalogueProps.js +13 -1
- package/lib-esm/model/earth/WMTSAdapter.d.ts +12 -0
- package/lib-esm/model/earth/WMTSAdapter.js +97 -0
- package/lib-esm/model/earth/XYZAnchestorTile.d.ts +17 -0
- package/lib-esm/model/earth/XYZAnchestorTile.js +87 -0
- package/lib-esm/model/earth/XYZConfig.d.ts +72 -0
- package/lib-esm/model/earth/XYZConfig.js +13 -0
- package/lib-esm/model/earth/XYZFoVHelper.d.ts +9 -0
- package/lib-esm/model/earth/XYZFoVHelper.js +101 -0
- package/lib-esm/model/earth/XYZMap.d.ts +31 -0
- package/lib-esm/model/earth/XYZMap.js +208 -0
- package/lib-esm/model/earth/XYZMapDescriptor.d.ts +29 -0
- package/lib-esm/model/earth/XYZMapDescriptor.js +77 -0
- package/lib-esm/model/earth/XYZMeshBuilder.d.ts +6 -0
- package/lib-esm/model/earth/XYZMeshBuilder.js +108 -0
- package/lib-esm/model/earth/XYZTile.d.ts +38 -0
- package/lib-esm/model/earth/XYZTile.js +167 -0
- package/lib-esm/model/earth/XYZTileBuffer.d.ts +37 -0
- package/lib-esm/model/earth/XYZTileBuffer.js +139 -0
- package/lib-esm/model/earth/XYZTileRequestScheduler.d.ts +25 -0
- package/lib-esm/model/earth/XYZTileRequestScheduler.js +172 -0
- package/lib-esm/model/earth/XYZTypes.d.ts +24 -0
- package/lib-esm/model/earth/XYZTypes.js +13 -0
- package/lib-esm/model/earth/XYZVisibleTilesManager.d.ts +19 -0
- package/lib-esm/model/earth/XYZVisibleTilesManager.js +77 -0
- package/lib-esm/model/footprints/Footprint.js +12 -0
- package/lib-esm/model/footprints/FootprintProps.js +13 -1
- package/lib-esm/model/footprints/FootprintSetGL.js +13 -1
- package/lib-esm/model/grid/EquatorialGrid.js +20 -6
- package/lib-esm/model/grid/GridTextHelper.d.ts +10 -19
- package/lib-esm/model/grid/GridTextHelper.js +70 -67
- package/lib-esm/model/grid/HealpixGrid.d.ts +4 -4
- package/lib-esm/model/grid/HealpixGrid.js +19 -6
- package/lib-esm/model/grid/LonLatGrid.d.ts +40 -0
- package/lib-esm/model/grid/LonLatGrid.js +258 -0
- package/lib-esm/model/hips/AllSky.js +12 -0
- package/lib-esm/model/hips/AncestorTile.js +12 -0
- package/lib-esm/model/hips/FoVHelper.js +12 -0
- package/lib-esm/model/hips/HiPS.js +12 -9
- package/lib-esm/model/hips/HiPSDescriptor.js +12 -0
- package/lib-esm/model/hips/Tile.js +12 -0
- package/lib-esm/model/hips/TileBuffer.js +12 -0
- package/lib-esm/model/hips/VisibleTilesManager.js +12 -0
- package/lib-esm/model/tap/TapMetadata.js +12 -0
- package/lib-esm/model/tap/TapMetadataList.js +12 -0
- package/lib-esm/model/tap/TapRepo.js +12 -0
- package/lib-esm/model/terra/TerraFootprintSetGL.d.ts +4 -0
- package/lib-esm/model/terra/TerraFootprintSetGL.js +16 -0
- package/lib-esm/model/terra/TerraPointSetGL.d.ts +4 -0
- package/lib-esm/model/terra/TerraPointSetGL.js +16 -0
- package/lib-esm/services/SesameService.js +11 -3
- package/lib-esm/services/helpers.js +12 -0
- package/lib-esm/services/hipsNodeService.js +12 -0
- package/lib-esm/services/parse-hipslist.js +12 -0
- package/lib-esm/services/queryCatalogueByFoV.js +13 -1
- package/lib-esm/services/queryFootprintSetByFov.js +13 -1
- package/lib-esm/services/tapRepoService.js +13 -1
- package/lib-esm/services/types.js +12 -0
- package/lib-esm/shader/CatalogueShaderProgram.js +12 -0
- package/lib-esm/shader/FootprintShaderProgram.js +12 -0
- package/lib-esm/shader/GridShaderManager.js +12 -0
- package/lib-esm/shader/HiPSShaderProgram.js +12 -0
- package/lib-esm/shader/ShaderManager.js +12 -1
- package/lib-esm/shader/ShaderManagerMutliHiPS.js +12 -1
- package/lib-esm/shader/XYZShaderProgram.d.ts +33 -0
- package/lib-esm/shader/XYZShaderProgram.js +213 -0
- package/lib-esm/utils/CoordsType.js +12 -0
- package/lib-esm/utils/FoVUtils.js +12 -0
- package/lib-esm/utils/GeomUtils.js +12 -0
- package/lib-esm/utils/MouseHelper.js +12 -0
- package/lib-esm/utils/PerspectiveMatrixManager.js +12 -0
- package/lib-esm/utils/RayPickingUtils.js +12 -0
- package/lib-esm/utils/STCSParser.js +12 -0
- package/lib-esm/utils/ShaderUtility.js +13 -1
- package/lib-esm/utils/Utils.js +12 -0
- package/lib-esm/utils/XYZRayPickingUtils.d.ts +27 -0
- package/lib-esm/utils/XYZRayPickingUtils.js +226 -0
- package/package.json +1 -2
- package/lib-esm/model/FoV.d.ts +0 -62
- package/lib-esm/model/FoV.js +0 -274
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* AstroViewer
|
|
3
|
+
* Copyright (C) Fabrizio Giordano
|
|
4
|
+
* SPDX-License-Identifier: LicenseRef-AstroViewer-Dual-License
|
|
5
|
+
*
|
|
6
|
+
* This file is part of AstroViewer.
|
|
7
|
+
* AstroViewer is distributed under a dual-license model.
|
|
8
|
+
* Commercial use requires a separate commercial license.
|
|
9
|
+
* Non-commercial use is governed by LICENSE-NONCOMMERCIAL.md.
|
|
10
|
+
*
|
|
11
|
+
* See LICENSE.md, LICENSE-COMMERCIAL.md, and LICENSE-NONCOMMERCIAL.md for details.
|
|
12
|
+
*/
|
|
13
|
+
/**
|
|
14
|
+
* Ray picking helpers for XYZ/WebMercator maps.
|
|
15
|
+
*
|
|
16
|
+
* Unlike RayPickingUtils, this module has no HEALPix dependency. It intersects
|
|
17
|
+
* screen rays with an XYZ sphere, converts the hit to lon/lat, then maps that
|
|
18
|
+
* position to XYZ z/x/y tile coordinates.
|
|
19
|
+
*/
|
|
20
|
+
'use strict';
|
|
21
|
+
import { mat4, vec3 } from 'gl-matrix';
|
|
22
|
+
const MAX_MERCATOR_LAT = 85.0511287798066;
|
|
23
|
+
class XYZRayPickingUtils {
|
|
24
|
+
static getRayFromMouse(mouseX, mouseY, pMatrix, webgl, vMatrix) {
|
|
25
|
+
const gl = webgl;
|
|
26
|
+
const canvas = gl.canvas;
|
|
27
|
+
const rect = canvas.getBoundingClientRect();
|
|
28
|
+
const x = (2.0 * mouseX) / rect.width - 1.0;
|
|
29
|
+
const y = 1.0 - (2.0 * mouseY) / rect.height;
|
|
30
|
+
const rayClip = [x, y, -1.0, 1.0];
|
|
31
|
+
const pInv = mat4.create();
|
|
32
|
+
mat4.invert(pInv, pMatrix);
|
|
33
|
+
const rayEye4 = [0, 0, 0, 0];
|
|
34
|
+
XYZRayPickingUtils.mat4MultiplyVec4(pInv, rayClip, rayEye4);
|
|
35
|
+
const rayEye = [rayEye4[0], rayEye4[1], -1.0, 0.0];
|
|
36
|
+
const vInv = mat4.create();
|
|
37
|
+
mat4.invert(vInv, vMatrix);
|
|
38
|
+
const rayWorld4 = [0, 0, 0, 0];
|
|
39
|
+
XYZRayPickingUtils.mat4MultiplyVec4(vInv, rayEye, rayWorld4);
|
|
40
|
+
const rayWorld = vec3.fromValues(rayWorld4[0], rayWorld4[1], rayWorld4[2]);
|
|
41
|
+
vec3.normalize(rayWorld, rayWorld);
|
|
42
|
+
return rayWorld;
|
|
43
|
+
}
|
|
44
|
+
static raySphere(rayOrigWorld, rayDirectionWorld, sphere) {
|
|
45
|
+
let intersectionDistance = -1;
|
|
46
|
+
const L = vec3.create();
|
|
47
|
+
vec3.subtract(L, rayOrigWorld, sphere.center);
|
|
48
|
+
const b = vec3.dot(rayDirectionWorld, L);
|
|
49
|
+
const c = vec3.dot(L, L) - sphere.radius * sphere.radius;
|
|
50
|
+
const disc = b * b - c;
|
|
51
|
+
if (disc > 0.0) {
|
|
52
|
+
const s = Math.sqrt(disc);
|
|
53
|
+
const ta = -b + s;
|
|
54
|
+
const tb = -b - s;
|
|
55
|
+
if (ta >= 0.0 || tb >= 0.0) {
|
|
56
|
+
intersectionDistance = tb < 0.0 ? ta : Math.min(ta, tb);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (disc === 0.0) {
|
|
60
|
+
const t = -b;
|
|
61
|
+
if (t >= 0.0) {
|
|
62
|
+
intersectionDistance = t;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return intersectionDistance;
|
|
66
|
+
}
|
|
67
|
+
static getIntersectionPointWithModel(mouseX, mouseY, xyzModel, webgl, camera, pMatrix) {
|
|
68
|
+
const vMatrix = camera.getCameraMatrix();
|
|
69
|
+
const rayWorld = XYZRayPickingUtils.getRayFromMouse(mouseX, mouseY, pMatrix, webgl, vMatrix);
|
|
70
|
+
const t = XYZRayPickingUtils.raySphere(camera.getCameraPosition(), rayWorld, xyzModel);
|
|
71
|
+
if (t < 0) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
const worldHit = vec3.create();
|
|
75
|
+
vec3.scale(worldHit, rayWorld, t);
|
|
76
|
+
vec3.add(worldHit, camera.getCameraPosition(), worldHit);
|
|
77
|
+
const worldHit4 = [worldHit[0], worldHit[1], worldHit[2], 1.0];
|
|
78
|
+
const modelHit4 = [0, 0, 0, 0];
|
|
79
|
+
XYZRayPickingUtils.mat4MultiplyVec4(xyzModel.getModelMatrixInverse(), worldHit4, modelHit4);
|
|
80
|
+
return [modelHit4[0], modelHit4[1], modelHit4[2]];
|
|
81
|
+
}
|
|
82
|
+
static getLonLatFromMouse(mouseX, mouseY, xyzModel, webgl, camera, pMatrix) {
|
|
83
|
+
const hit = XYZRayPickingUtils.getIntersectionPointWithModel(mouseX, mouseY, xyzModel, webgl, camera, pMatrix);
|
|
84
|
+
return hit ? XYZRayPickingUtils.modelPointToLonLat(hit) : null;
|
|
85
|
+
}
|
|
86
|
+
static getTileFromMouse(mouseX, mouseY, z, xyzModel, webgl, camera, pMatrix) {
|
|
87
|
+
const lonLat = XYZRayPickingUtils.getLonLatFromMouse(mouseX, mouseY, xyzModel, webgl, camera, pMatrix);
|
|
88
|
+
if (!lonLat || !XYZRayPickingUtils.isMercatorLatitude(lonLat.latDeg)) {
|
|
89
|
+
return null;
|
|
90
|
+
}
|
|
91
|
+
return XYZRayPickingUtils.lonLatToTile(lonLat.lonDeg, lonLat.latDeg, z);
|
|
92
|
+
}
|
|
93
|
+
static getVisibleTilesFromViewport(z, xyzModel, webgl, camera, pMatrix, sampleCount = 9, padding = 2) {
|
|
94
|
+
const gl = webgl;
|
|
95
|
+
const canvas = gl.canvas;
|
|
96
|
+
const rect = canvas.getBoundingClientRect();
|
|
97
|
+
const samples = Math.max(2, Math.floor(sampleCount));
|
|
98
|
+
const edgeSamples = Math.max(samples * 2 + 1, 21);
|
|
99
|
+
const safePadding = Math.max(0, Math.floor(padding));
|
|
100
|
+
const tiles = [];
|
|
101
|
+
const addSample = (x, y) => {
|
|
102
|
+
const tile = XYZRayPickingUtils.getTileFromMouse(x, y, z, xyzModel, webgl, camera, pMatrix);
|
|
103
|
+
if (!tile)
|
|
104
|
+
return;
|
|
105
|
+
tiles.push(tile);
|
|
106
|
+
tiles.push(...XYZRayPickingUtils.getNeighborTiles(tile, safePadding));
|
|
107
|
+
};
|
|
108
|
+
for (let iy = 0; iy < samples; iy++) {
|
|
109
|
+
const y = samples === 1 ? rect.height / 2 : (iy / (samples - 1)) * rect.height;
|
|
110
|
+
for (let ix = 0; ix < samples; ix++) {
|
|
111
|
+
const x = samples === 1 ? rect.width / 2 : (ix / (samples - 1)) * rect.width;
|
|
112
|
+
addSample(x, y);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
for (let i = 0; i < edgeSamples; i++) {
|
|
116
|
+
const t = edgeSamples === 1 ? 0.5 : i / (edgeSamples - 1);
|
|
117
|
+
const x = t * rect.width;
|
|
118
|
+
const y = t * rect.height;
|
|
119
|
+
addSample(x, 0);
|
|
120
|
+
addSample(x, rect.height);
|
|
121
|
+
addSample(0, y);
|
|
122
|
+
addSample(rect.width, y);
|
|
123
|
+
}
|
|
124
|
+
return XYZRayPickingUtils.fillSmallTileGaps(XYZRayPickingUtils.deduplicateTiles(tiles));
|
|
125
|
+
}
|
|
126
|
+
static modelPointToLonLat(point) {
|
|
127
|
+
const [x, y, z] = point;
|
|
128
|
+
const len = Math.hypot(x, y, z);
|
|
129
|
+
if (!Number.isFinite(len) || len === 0) {
|
|
130
|
+
return { lonDeg: 0, latDeg: 0 };
|
|
131
|
+
}
|
|
132
|
+
const lonDeg = (Math.atan2(y, x) * 180) / Math.PI;
|
|
133
|
+
const latDeg = (Math.asin(Math.max(-1, Math.min(1, z / len))) * 180) / Math.PI;
|
|
134
|
+
return { lonDeg, latDeg };
|
|
135
|
+
}
|
|
136
|
+
static lonLatToTile(lonDeg, latDeg, z) {
|
|
137
|
+
const zoom = Math.max(0, Math.floor(z));
|
|
138
|
+
const dim = 2 ** zoom;
|
|
139
|
+
const x = Math.floor(((lonDeg + 180) / 360) * dim);
|
|
140
|
+
const y = Math.floor(XYZRayPickingUtils.latToTileY(latDeg, zoom));
|
|
141
|
+
return {
|
|
142
|
+
z: zoom,
|
|
143
|
+
x: XYZRayPickingUtils.wrapTileX(x, dim),
|
|
144
|
+
y: XYZRayPickingUtils.clampTileY(y, dim),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
static getNeighborTiles(tile, ring = 1) {
|
|
148
|
+
const dim = 2 ** tile.z;
|
|
149
|
+
const tiles = [];
|
|
150
|
+
const safeRing = Math.max(0, Math.floor(ring));
|
|
151
|
+
for (let dx = -safeRing; dx <= safeRing; dx++) {
|
|
152
|
+
for (let dy = -safeRing; dy <= safeRing; dy++) {
|
|
153
|
+
tiles.push({
|
|
154
|
+
z: tile.z,
|
|
155
|
+
x: XYZRayPickingUtils.wrapTileX(tile.x + dx, dim),
|
|
156
|
+
y: XYZRayPickingUtils.clampTileY(tile.y + dy, dim),
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return XYZRayPickingUtils.deduplicateTiles(tiles);
|
|
161
|
+
}
|
|
162
|
+
static deduplicateTiles(tiles) {
|
|
163
|
+
const map = new Map();
|
|
164
|
+
for (const tile of tiles) {
|
|
165
|
+
map.set(`${tile.z}/${tile.x}/${tile.y}`, tile);
|
|
166
|
+
}
|
|
167
|
+
return Array.from(map.values());
|
|
168
|
+
}
|
|
169
|
+
static fillSmallTileGaps(tiles) {
|
|
170
|
+
if (tiles.length === 0) {
|
|
171
|
+
return tiles;
|
|
172
|
+
}
|
|
173
|
+
const zoom = tiles[0].z;
|
|
174
|
+
const dim = 2 ** zoom;
|
|
175
|
+
const map = new Map();
|
|
176
|
+
const key = (tile) => `${tile.z}/${tile.x}/${tile.y}`;
|
|
177
|
+
const add = (tile) => {
|
|
178
|
+
map.set(key(tile), tile);
|
|
179
|
+
};
|
|
180
|
+
const has = (x, y) => (y >= 0 && y < dim && map.has(`${zoom}/${XYZRayPickingUtils.wrapTileX(x, dim)}/${y}`));
|
|
181
|
+
for (const tile of tiles) {
|
|
182
|
+
add(tile);
|
|
183
|
+
}
|
|
184
|
+
for (const tile of tiles) {
|
|
185
|
+
const x = tile.x;
|
|
186
|
+
const y = tile.y;
|
|
187
|
+
if (has(x - 2, y) && !has(x - 1, y)) {
|
|
188
|
+
add({ z: zoom, x: XYZRayPickingUtils.wrapTileX(x - 1, dim), y });
|
|
189
|
+
}
|
|
190
|
+
if (has(x + 2, y) && !has(x + 1, y)) {
|
|
191
|
+
add({ z: zoom, x: XYZRayPickingUtils.wrapTileX(x + 1, dim), y });
|
|
192
|
+
}
|
|
193
|
+
if (has(x, y - 2) && !has(x, y - 1)) {
|
|
194
|
+
add({ z: zoom, x, y: y - 1 });
|
|
195
|
+
}
|
|
196
|
+
if (has(x, y + 2) && !has(x, y + 1)) {
|
|
197
|
+
add({ z: zoom, x, y: y + 1 });
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return Array.from(map.values());
|
|
201
|
+
}
|
|
202
|
+
static latToTileY(latDeg, z) {
|
|
203
|
+
const lat = Math.max(-MAX_MERCATOR_LAT, Math.min(MAX_MERCATOR_LAT, latDeg));
|
|
204
|
+
const latRad = (lat * Math.PI) / 180;
|
|
205
|
+
const dim = 2 ** z;
|
|
206
|
+
return ((1 - Math.asinh(Math.tan(latRad)) / Math.PI) / 2) * dim;
|
|
207
|
+
}
|
|
208
|
+
static isMercatorLatitude(latDeg) {
|
|
209
|
+
return Math.abs(latDeg) <= MAX_MERCATOR_LAT;
|
|
210
|
+
}
|
|
211
|
+
static wrapTileX(x, dim) {
|
|
212
|
+
return ((x % dim) + dim) % dim;
|
|
213
|
+
}
|
|
214
|
+
static clampTileY(y, dim) {
|
|
215
|
+
return Math.max(0, Math.min(dim - 1, y));
|
|
216
|
+
}
|
|
217
|
+
static mat4MultiplyVec4(a, b, out) {
|
|
218
|
+
const d = b[0], e = b[1], g = b[2], w = b[3];
|
|
219
|
+
out[0] = a[0] * d + a[4] * e + a[8] * g + a[12] * w;
|
|
220
|
+
out[1] = a[1] * d + a[5] * e + a[9] * g + a[13] * w;
|
|
221
|
+
out[2] = a[2] * d + a[6] * e + a[10] * g + a[14] * w;
|
|
222
|
+
out[3] = a[3] * d + a[7] * e + a[11] * g + a[15] * w;
|
|
223
|
+
return out;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
export default XYZRayPickingUtils;
|
package/package.json
CHANGED
package/lib-esm/model/FoV.d.ts
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* FoV singleton (TypeScript)
|
|
3
|
-
* - Uses computePerspectiveMatrixSingleton.pMatrix
|
|
4
|
-
* - Guards acos domain (numeric safety)
|
|
5
|
-
* - Uses vec3.transformMat4 instead of custom mat4*vec3
|
|
6
|
-
* - Keeps original “insideSphere ? 360 - angle : angle” behavior
|
|
7
|
-
*/
|
|
8
|
-
import { ReadonlyMat4 } from 'gl-matrix';
|
|
9
|
-
import { HealpixGrid } from './grid/HealpixGrid.js';
|
|
10
|
-
import Camera from '../Camera.js';
|
|
11
|
-
export declare class FoV {
|
|
12
|
-
private static readonly MIN_FOV_DEG;
|
|
13
|
-
private fovXDeg;
|
|
14
|
-
private fovYDeg;
|
|
15
|
-
private ratio;
|
|
16
|
-
private _minFoV;
|
|
17
|
-
private _webgl;
|
|
18
|
-
constructor(webgl: WebGL2RenderingContext);
|
|
19
|
-
/** Recomputes FoV for current camera + projection */
|
|
20
|
-
getFoV(insideSphere: boolean, healpixGridSingleton: HealpixGrid, camera: Camera, pMatrix: ReadonlyMat4): FoV;
|
|
21
|
-
private computeRatio;
|
|
22
|
-
changeMinFov(deg: number): void;
|
|
23
|
-
get minFoV(): number;
|
|
24
|
-
get xFoV(): number;
|
|
25
|
-
get yFoV(): number;
|
|
26
|
-
computeDistanceFromAngle(angleDeg: number): number;
|
|
27
|
-
/** FoV half-screen chord angle doubled (deg) along a given canvas axis */
|
|
28
|
-
private computeAngle;
|
|
29
|
-
/**
|
|
30
|
-
* Computes the camera position (x,y,z) along the current view direction that would
|
|
31
|
-
* yield the requested minFoV (in degrees), assuming the camera is OUTSIDE the sphere.
|
|
32
|
-
* This method does NOT mutate the camera; it only returns the suggested position.
|
|
33
|
-
*
|
|
34
|
-
* Geometry: for a sphere of radius R observed from distance d (from center),
|
|
35
|
-
* the apparent angular diameter is 2*arcsin(R/d). Our minFoV is that angular diameter
|
|
36
|
-
* along the tighter axis; we solve for d and place the camera on the current
|
|
37
|
-
* center→camera direction with that distance.
|
|
38
|
-
*
|
|
39
|
-
* @param targetMinFoVDeg Desired min FoV in degrees, 0 < targetMinFoVDeg < 180
|
|
40
|
-
* @returns Tuple [x, y, z] for the recommended camera position in world coordinates.
|
|
41
|
-
*/
|
|
42
|
-
computeCameraPositionForMinFoV(targetMinFoVDeg: number): [number, number, number];
|
|
43
|
-
/**
|
|
44
|
-
* Computes the camera world-space position required to achieve a target FoV (deg),
|
|
45
|
-
* keeping the same viewing direction. Acts as the inverse of computeAngle().
|
|
46
|
-
*
|
|
47
|
-
* @param targetFoVDeg desired full FoV angle in degrees (0 < FoV < 180)
|
|
48
|
-
* @param canvasWidth canvas width in pixels
|
|
49
|
-
* @param canvasHeight canvas height in pixels
|
|
50
|
-
* @returns [x, y, z] coordinates for the new camera position
|
|
51
|
-
*/
|
|
52
|
-
computeCameraPositionForFoV(targetFoVDeg: number): [number, number, number];
|
|
53
|
-
/**
|
|
54
|
-
* Return a camera position such that the sphere's apparent angular diameter
|
|
55
|
-
* (the silhouette, not the surface coverage) equals targetAngularDiameterDeg.
|
|
56
|
-
* Keeps current view direction; does not mutate the camera.
|
|
57
|
-
*
|
|
58
|
-
* @param targetAngularDiameterDeg desired apparent diameter in degrees (0<α<180)
|
|
59
|
-
* @returns [x,y,z] world position
|
|
60
|
-
*/
|
|
61
|
-
computeCameraPositionForAngularDiameter(targetAngularDiameterDeg: number): [number, number, number];
|
|
62
|
-
}
|
package/lib-esm/model/FoV.js
DELETED
|
@@ -1,274 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
/**
|
|
3
|
-
* FoV singleton (TypeScript)
|
|
4
|
-
* - Uses computePerspectiveMatrixSingleton.pMatrix
|
|
5
|
-
* - Guards acos domain (numeric safety)
|
|
6
|
-
* - Uses vec3.transformMat4 instead of custom mat4*vec3
|
|
7
|
-
* - Keeps original “insideSphere ? 360 - angle : angle” behavior
|
|
8
|
-
*/
|
|
9
|
-
import { vec3, mat4 } from 'gl-matrix';
|
|
10
|
-
import RayPickingUtils from '../utils/RayPickingUtils.js';
|
|
11
|
-
import { radToDeg } from '../utils/Utils.js';
|
|
12
|
-
export class FoV {
|
|
13
|
-
static MIN_FOV_DEG = 1e-6;
|
|
14
|
-
fovXDeg = 180;
|
|
15
|
-
fovYDeg = 180;
|
|
16
|
-
ratio = +0;
|
|
17
|
-
_minFoV = 180;
|
|
18
|
-
_webgl;
|
|
19
|
-
constructor(webgl) {
|
|
20
|
-
this._webgl = webgl;
|
|
21
|
-
}
|
|
22
|
-
/** Recomputes FoV for current camera + projection */
|
|
23
|
-
getFoV(insideSphere, healpixGridSingleton, camera, pMatrix) {
|
|
24
|
-
// const gl = webgl
|
|
25
|
-
const gl = this._webgl;
|
|
26
|
-
if (!gl || !gl.canvas) {
|
|
27
|
-
// Handle the error or assign default values
|
|
28
|
-
this.fovXDeg = 180;
|
|
29
|
-
this.fovYDeg = 180;
|
|
30
|
-
this._minFoV = this.minFoV;
|
|
31
|
-
return this;
|
|
32
|
-
}
|
|
33
|
-
// horizontal FoV: ray through (centerY)
|
|
34
|
-
// const xFoVComputed = this.computeAngle(0, gl.canvas.height / 2, insideSphere, healpixGridSingleton, camera)
|
|
35
|
-
const canvas = gl.canvas;
|
|
36
|
-
const rect = canvas.getBoundingClientRect();
|
|
37
|
-
const canvasWidth = rect.width;
|
|
38
|
-
const canvasHeight = rect.height;
|
|
39
|
-
// const xFoVComputed = this.computeAngle(0, gl.canvas.height / 2, insideSphere, healpixGridSingleton, camera, pMatrix)
|
|
40
|
-
const xFoVComputed = this.computeAngle(0, canvasHeight / 2, insideSphere, healpixGridSingleton, camera, pMatrix);
|
|
41
|
-
this.fovXDeg = xFoVComputed.angleDeg;
|
|
42
|
-
// vertical FoV: ray through (centerX)
|
|
43
|
-
// const yFoVComputed = this.computeAngle(gl.canvas.width / 2, 0, insideSphere, healpixGridSingleton, camera, pMatrix)
|
|
44
|
-
const yFoVComputed = this.computeAngle(canvasWidth / 2, 0, insideSphere, healpixGridSingleton, camera, pMatrix);
|
|
45
|
-
this.fovYDeg = yFoVComputed.angleDeg;
|
|
46
|
-
this._minFoV = this.minFoV;
|
|
47
|
-
this.ratio = this.computeRatio(camera);
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
computeRatio(camera) {
|
|
51
|
-
// const camera = global.camera
|
|
52
|
-
if (!camera)
|
|
53
|
-
throw Error("Camera not defined");
|
|
54
|
-
const pos = camera.getCameraPosition();
|
|
55
|
-
const distanceFromCenter = Math.sqrt(pos[0] * pos[0] + pos[1] * pos[1] + pos[2] * pos[2]);
|
|
56
|
-
// const distanceFromSphere = distanceFromCenter - healpixGridSingleton.RADIUS
|
|
57
|
-
const ratio = distanceFromCenter / this.fovYDeg;
|
|
58
|
-
return ratio;
|
|
59
|
-
}
|
|
60
|
-
changeMinFov(deg) {
|
|
61
|
-
console.log("inside changeMinFov");
|
|
62
|
-
if (this.fovYDeg <= this.fovXDeg) {
|
|
63
|
-
this.fovYDeg = deg;
|
|
64
|
-
}
|
|
65
|
-
else {
|
|
66
|
-
this.fovXDeg = deg;
|
|
67
|
-
}
|
|
68
|
-
console.log("changeMinFov: ping");
|
|
69
|
-
this.minFoV;
|
|
70
|
-
// this.fovYDeg <= this.fovXDeg ? this.fovYDeg = deg : this.fovXDeg = deg
|
|
71
|
-
}
|
|
72
|
-
get minFoV() {
|
|
73
|
-
const minFov = this.fovYDeg <= this.fovXDeg ? this.fovYDeg : this.fovXDeg;
|
|
74
|
-
this._minFoV = Math.max(minFov, FoV.MIN_FOV_DEG);
|
|
75
|
-
return this._minFoV;
|
|
76
|
-
}
|
|
77
|
-
get xFoV() {
|
|
78
|
-
return this.fovXDeg;
|
|
79
|
-
}
|
|
80
|
-
get yFoV() {
|
|
81
|
-
return this.fovYDeg;
|
|
82
|
-
}
|
|
83
|
-
computeDistanceFromAngle(angleDeg) {
|
|
84
|
-
const desiredFoV = angleDeg;
|
|
85
|
-
const distance = desiredFoV * this.ratio;
|
|
86
|
-
// return Math.abs(distance)
|
|
87
|
-
return distance;
|
|
88
|
-
}
|
|
89
|
-
/** FoV half-screen chord angle doubled (deg) along a given canvas axis */
|
|
90
|
-
computeAngle(canvasX, canvasY, insideSphere, healpixGridSingleton, camera, pMatrix) {
|
|
91
|
-
// const pMatrix = computePerspectiveMatrixSingleton.pMatrix
|
|
92
|
-
if (!pMatrix) {
|
|
93
|
-
// Handle the error or assign a default value
|
|
94
|
-
console.warn('FoV: projection matrix is null');
|
|
95
|
-
return { angleDeg: 180, distance: 1 };
|
|
96
|
-
}
|
|
97
|
-
const vMatrix = camera.getCameraMatrix();
|
|
98
|
-
if (!camera) {
|
|
99
|
-
// Handle the error or assign a default value
|
|
100
|
-
console.warn('FoV: camera is null');
|
|
101
|
-
return { angleDeg: 180, distance: 1 };
|
|
102
|
-
}
|
|
103
|
-
const rayWorld = RayPickingUtils.getRayFromMouse(canvasX, canvasY, pMatrix, this._webgl, vMatrix);
|
|
104
|
-
const intersectionDistance = RayPickingUtils.raySphere(camera.getCameraPosition(), rayWorld, healpixGridSingleton);
|
|
105
|
-
let angleDeg;
|
|
106
|
-
if (intersectionDistance > 0) {
|
|
107
|
-
// world-space intersection point on the sphere
|
|
108
|
-
const hit = vec3.create();
|
|
109
|
-
vec3.scale(hit, rayWorld, intersectionDistance);
|
|
110
|
-
vec3.add(hit, camera.getCameraPosition(), hit);
|
|
111
|
-
const center = healpixGridSingleton.center;
|
|
112
|
-
// vectors from sphere center
|
|
113
|
-
const vHit = vec3.create();
|
|
114
|
-
vec3.subtract(vHit, hit, center);
|
|
115
|
-
// reference vector: rotate world +Z into current camera orientation, then from center
|
|
116
|
-
const refWorldZ = vec3.fromValues(center[0], center[1], center[2] + healpixGridSingleton.radius);
|
|
117
|
-
const vInv = mat4.create();
|
|
118
|
-
mat4.invert(vInv, camera.getCameraMatrix());
|
|
119
|
-
const refCamZ = vec3.create();
|
|
120
|
-
vec3.transformMat4(refCamZ, refWorldZ, vInv);
|
|
121
|
-
const vRef = vec3.create();
|
|
122
|
-
vec3.subtract(vRef, refCamZ, center);
|
|
123
|
-
// angle between vHit and vRef, doubled
|
|
124
|
-
const dot = vec3.dot(vHit, vRef);
|
|
125
|
-
const n1 = vec3.length(vHit);
|
|
126
|
-
const n2 = vec3.length(vRef);
|
|
127
|
-
// numeric safety for acos
|
|
128
|
-
const c = Math.min(1, Math.max(-1, dot / (n1 * n2)));
|
|
129
|
-
const angleRad = Math.acos(c);
|
|
130
|
-
angleDeg = 2 * radToDeg(angleRad);
|
|
131
|
-
}
|
|
132
|
-
else {
|
|
133
|
-
angleDeg = 180;
|
|
134
|
-
}
|
|
135
|
-
const finalAngle = insideSphere ? 360 - angleDeg : angleDeg;
|
|
136
|
-
// return insideSphere ? 360 - angleDeg : angleDeg
|
|
137
|
-
return { angleDeg: finalAngle, distance: intersectionDistance };
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Computes the camera position (x,y,z) along the current view direction that would
|
|
141
|
-
* yield the requested minFoV (in degrees), assuming the camera is OUTSIDE the sphere.
|
|
142
|
-
* This method does NOT mutate the camera; it only returns the suggested position.
|
|
143
|
-
*
|
|
144
|
-
* Geometry: for a sphere of radius R observed from distance d (from center),
|
|
145
|
-
* the apparent angular diameter is 2*arcsin(R/d). Our minFoV is that angular diameter
|
|
146
|
-
* along the tighter axis; we solve for d and place the camera on the current
|
|
147
|
-
* center→camera direction with that distance.
|
|
148
|
-
*
|
|
149
|
-
* @param targetMinFoVDeg Desired min FoV in degrees, 0 < targetMinFoVDeg < 180
|
|
150
|
-
* @returns Tuple [x, y, z] for the recommended camera position in world coordinates.
|
|
151
|
-
*/
|
|
152
|
-
computeCameraPositionForMinFoV(targetMinFoVDeg) {
|
|
153
|
-
// const camera = global.camera
|
|
154
|
-
// const center = healpixGridSingleton.center
|
|
155
|
-
// const R = healpixGridSingleton.radius
|
|
156
|
-
// if (!camera) {
|
|
157
|
-
// console.warn('FoV.computeCameraPositionForMinFoV: camera not available; returning a sensible default.')
|
|
158
|
-
// return [center[0], center[1], center[2] + 2 * R]
|
|
159
|
-
// }
|
|
160
|
-
// // Clamp and validate input
|
|
161
|
-
// const eps = 1e-6
|
|
162
|
-
// const clamped = Math.max(eps, Math.min(180 - eps, targetMinFoVDeg))
|
|
163
|
-
// const halfRad = (clamped * Math.PI / 180) * 0.5
|
|
164
|
-
// // Distance from center needed to achieve the angular diameter
|
|
165
|
-
// // minFoV = 2 * arcsin(R / d) => d = R / sin(minFoV/2)
|
|
166
|
-
// const sinHalf = Math.sin(halfRad)
|
|
167
|
-
// if (sinHalf <= 0) {
|
|
168
|
-
// console.warn('FoV.computeCameraPositionForMinFoV: invalid targetMinFoVDeg, using fallback.')
|
|
169
|
-
// return [center[0], center[1], center[2] + 2 * R]
|
|
170
|
-
// }
|
|
171
|
-
// let d = R / sinHalf
|
|
172
|
-
// // Ensure we remain strictly outside the sphere
|
|
173
|
-
// d = Math.max(d, R + 1e-4)
|
|
174
|
-
// // Use the current center→camera direction to keep orientation
|
|
175
|
-
// const camPos = camera.getCameraPosition()
|
|
176
|
-
// let dirX = camPos[0] - center[0]
|
|
177
|
-
// let dirY = camPos[1] - center[1]
|
|
178
|
-
// let dirZ = camPos[2] - center[2]
|
|
179
|
-
// const len = Math.hypot(dirX, dirY, dirZ)
|
|
180
|
-
// if (len < eps) {
|
|
181
|
-
// // If somehow at the center, use +Z as a default direction
|
|
182
|
-
// dirX = 0; dirY = 0; dirZ = 1;
|
|
183
|
-
// } else {
|
|
184
|
-
// dirX /= len
|
|
185
|
-
// dirY /= len
|
|
186
|
-
// dirZ /= len
|
|
187
|
-
// }
|
|
188
|
-
// const newX = center[0] + dirX * d
|
|
189
|
-
// const newY = center[1] + dirY * d
|
|
190
|
-
// const newZ = center[2] + dirZ * d
|
|
191
|
-
// return [newX, newY, newZ]
|
|
192
|
-
return [0, 0, 0];
|
|
193
|
-
}
|
|
194
|
-
/**
|
|
195
|
-
* Computes the camera world-space position required to achieve a target FoV (deg),
|
|
196
|
-
* keeping the same viewing direction. Acts as the inverse of computeAngle().
|
|
197
|
-
*
|
|
198
|
-
* @param targetFoVDeg desired full FoV angle in degrees (0 < FoV < 180)
|
|
199
|
-
* @param canvasWidth canvas width in pixels
|
|
200
|
-
* @param canvasHeight canvas height in pixels
|
|
201
|
-
* @returns [x, y, z] coordinates for the new camera position
|
|
202
|
-
*/
|
|
203
|
-
computeCameraPositionForFoV(targetFoVDeg) {
|
|
204
|
-
// const camera = global.camera;
|
|
205
|
-
// const center = healpixGridSingleton.center;
|
|
206
|
-
// const R = healpixGridSingleton.radius;
|
|
207
|
-
// if (!camera) {
|
|
208
|
-
// console.warn("FoV.computeCameraPositionForFoV: camera missing.");
|
|
209
|
-
// return [center[0], center[1], center[2] + 2 * R];
|
|
210
|
-
// }
|
|
211
|
-
// const eps = 1e-6;
|
|
212
|
-
// const clamped = Math.max(eps, Math.min(180 - eps, targetFoVDeg));
|
|
213
|
-
// const halfRad = (clamped * Math.PI) / 360.0; // half-angle in radians
|
|
214
|
-
// // Distance from center that yields this FoV
|
|
215
|
-
// const sinHalf = Math.sin(halfRad);
|
|
216
|
-
// if (sinHalf <= 0) {
|
|
217
|
-
// console.warn("FoV.computeCameraPositionForFoV: invalid FoV.");
|
|
218
|
-
// return [center[0], center[1], center[2] + 2 * R];
|
|
219
|
-
// }
|
|
220
|
-
// let d = R / sinHalf;
|
|
221
|
-
// // Slightly outside sphere to avoid clipping
|
|
222
|
-
// d = Math.max(d, R + 1e-4);
|
|
223
|
-
// // Get current viewing direction
|
|
224
|
-
// const camPos = camera.getCameraPosition();
|
|
225
|
-
// let dirX = camPos[0] - center[0];
|
|
226
|
-
// let dirY = camPos[1] - center[1];
|
|
227
|
-
// let dirZ = camPos[2] - center[2];
|
|
228
|
-
// const len = Math.hypot(dirX, dirY, dirZ);
|
|
229
|
-
// if (len < eps) {
|
|
230
|
-
// dirX = 0; dirY = 0; dirZ = 1;
|
|
231
|
-
// } else {
|
|
232
|
-
// dirX /= len;
|
|
233
|
-
// dirY /= len;
|
|
234
|
-
// dirZ /= len;
|
|
235
|
-
// }
|
|
236
|
-
// const newX = center[0] + dirX * d;
|
|
237
|
-
// const newY = center[1] + dirY * d;
|
|
238
|
-
// const newZ = center[2] + dirZ * d;
|
|
239
|
-
// return [newX, newY, newZ];
|
|
240
|
-
return [0, 0, 0];
|
|
241
|
-
}
|
|
242
|
-
/**
|
|
243
|
-
* Return a camera position such that the sphere's apparent angular diameter
|
|
244
|
-
* (the silhouette, not the surface coverage) equals targetAngularDiameterDeg.
|
|
245
|
-
* Keeps current view direction; does not mutate the camera.
|
|
246
|
-
*
|
|
247
|
-
* @param targetAngularDiameterDeg desired apparent diameter in degrees (0<α<180)
|
|
248
|
-
* @returns [x,y,z] world position
|
|
249
|
-
*/
|
|
250
|
-
computeCameraPositionForAngularDiameter(targetAngularDiameterDeg) {
|
|
251
|
-
// const camera = global.camera;
|
|
252
|
-
// const center = healpixGridSingleton.center;
|
|
253
|
-
// const R = healpixGridSingleton.radius;
|
|
254
|
-
// if (!camera) {
|
|
255
|
-
// console.warn('computeCameraPositionForAngularDiameter: camera missing.');
|
|
256
|
-
// return [center[0], center[1], center[2] + 2 * R];
|
|
257
|
-
// }
|
|
258
|
-
// const eps = 1e-6;
|
|
259
|
-
// const α = Math.max(eps, Math.min(180 - eps, targetAngularDiameterDeg));
|
|
260
|
-
// const half = (α * Math.PI) / 360.0;
|
|
261
|
-
// const sinHalf = Math.sin(half);
|
|
262
|
-
// // d = R / sin(α/2)
|
|
263
|
-
// let d = R / sinHalf;
|
|
264
|
-
// d = Math.max(d, R + 1e-4); // stay outside
|
|
265
|
-
// // project along current center→camera direction
|
|
266
|
-
// const [cx, cy, cz] = center as [number, number, number];
|
|
267
|
-
// const [px, py, pz] = camera.getCameraPosition();
|
|
268
|
-
// let dx = px - cx, dy = py - cy, dz = pz - cz;
|
|
269
|
-
// const L = Math.hypot(dx, dy, dz);
|
|
270
|
-
// if (L < eps) { dx = 0; dy = 0; dz = 1; } else { dx /= L; dy /= L; dz /= L; }
|
|
271
|
-
// return [cx + dx * d, cy + dy * d, cz + dz * d];
|
|
272
|
-
return [0, 0, 0];
|
|
273
|
-
}
|
|
274
|
-
}
|