@loaders.gl/tiles 3.1.0-alpha.2 → 3.1.0-beta.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/dist/bundle.d.ts +2 -0
- package/dist/bundle.d.ts.map +1 -0
- package/dist/bundle.js +8134 -5
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +29 -26
- package/dist/es5/bundle.js +7 -0
- package/dist/es5/bundle.js.map +1 -0
- package/dist/es5/constants.js +44 -0
- package/dist/es5/constants.js.map +1 -0
- package/dist/es5/index.js +104 -0
- package/dist/es5/index.js.map +1 -0
- package/dist/es5/tileset/helpers/3d-tiles-options.js +13 -0
- package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -0
- package/dist/es5/tileset/helpers/bounding-volume.js +102 -0
- package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -0
- package/dist/es5/tileset/helpers/frame-state.js +69 -0
- package/dist/es5/tileset/helpers/frame-state.js.map +1 -0
- package/dist/es5/tileset/helpers/i3s-lod.js +84 -0
- package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -0
- package/dist/es5/tileset/helpers/tiles-3d-lod.js +123 -0
- package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -0
- package/dist/es5/tileset/helpers/transform-utils.js +71 -0
- package/dist/es5/tileset/helpers/transform-utils.js.map +1 -0
- package/dist/es5/tileset/helpers/zoom.js +45 -0
- package/dist/es5/tileset/helpers/zoom.js.map +1 -0
- package/dist/es5/tileset/tile-3d.js +510 -0
- package/dist/es5/tileset/tile-3d.js.map +1 -0
- package/dist/es5/tileset/tileset-3d.js +656 -0
- package/dist/es5/tileset/tileset-3d.js.map +1 -0
- package/dist/es5/tileset/tileset-cache.js +88 -0
- package/dist/es5/tileset/tileset-cache.js.map +1 -0
- package/dist/es5/tileset/traversers/i3s-tile-manager.js +57 -0
- package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +1 -0
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +95 -0
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +1 -0
- package/dist/es5/tileset/traversers/tileset-3d-traverser.js +66 -0
- package/dist/es5/tileset/traversers/tileset-3d-traverser.js.map +1 -0
- package/dist/es5/tileset/traversers/tileset-traverser.js +304 -0
- package/dist/es5/tileset/traversers/tileset-traverser.js.map +1 -0
- package/dist/es5/utils/doubly-linked-list-node.js +25 -0
- package/dist/es5/utils/doubly-linked-list-node.js.map +1 -0
- package/dist/es5/utils/doubly-linked-list.js +92 -0
- package/dist/es5/utils/doubly-linked-list.js.map +1 -0
- package/dist/es5/utils/managed-array.js +127 -0
- package/dist/es5/utils/managed-array.js.map +1 -0
- package/dist/esm/bundle.js +5 -0
- package/dist/esm/bundle.js.map +1 -0
- package/dist/esm/constants.js +32 -0
- package/dist/esm/constants.js.map +1 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/tileset/helpers/3d-tiles-options.js +6 -0
- package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -0
- package/dist/esm/tileset/helpers/bounding-volume.js +88 -0
- package/dist/esm/tileset/helpers/bounding-volume.js.map +1 -0
- package/dist/esm/tileset/helpers/frame-state.js +51 -0
- package/dist/esm/tileset/helpers/frame-state.js.map +1 -0
- package/dist/esm/tileset/helpers/i3s-lod.js +67 -0
- package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -0
- package/dist/esm/tileset/helpers/tiles-3d-lod.js +105 -0
- package/dist/esm/tileset/helpers/tiles-3d-lod.js.map +1 -0
- package/dist/esm/tileset/helpers/transform-utils.js +58 -0
- package/dist/esm/tileset/helpers/transform-utils.js.map +1 -0
- package/dist/esm/tileset/helpers/zoom.js +36 -0
- package/dist/esm/tileset/helpers/zoom.js.map +1 -0
- package/dist/esm/tileset/tile-3d.js +534 -0
- package/dist/esm/tileset/tile-3d.js.map +1 -0
- package/dist/esm/tileset/tileset-3d.js +674 -0
- package/dist/esm/tileset/tileset-3d.js.map +1 -0
- package/dist/esm/tileset/tileset-cache.js +79 -0
- package/dist/esm/tileset/tileset-cache.js.map +1 -0
- package/dist/esm/tileset/traversers/i3s-tile-manager.js +45 -0
- package/dist/esm/tileset/traversers/i3s-tile-manager.js.map +1 -0
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js +80 -0
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +1 -0
- package/dist/esm/tileset/traversers/tileset-3d-traverser.js +53 -0
- package/dist/esm/tileset/traversers/tileset-3d-traverser.js.map +1 -0
- package/dist/esm/tileset/traversers/tileset-traverser.js +296 -0
- package/dist/esm/tileset/traversers/tileset-traverser.js.map +1 -0
- package/dist/esm/utils/doubly-linked-list-node.js +16 -0
- package/dist/esm/utils/doubly-linked-list-node.js.map +1 -0
- package/dist/esm/utils/doubly-linked-list.js +81 -0
- package/dist/esm/utils/doubly-linked-list.js.map +1 -0
- package/dist/esm/utils/managed-array.js +117 -0
- package/dist/esm/utils/managed-array.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -9
- package/dist/tileset/helpers/3d-tiles-options.d.ts +4 -0
- package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -0
- package/dist/tileset/helpers/3d-tiles-options.js +8 -5
- package/dist/tileset/helpers/bounding-volume.d.ts +9 -0
- package/dist/tileset/helpers/bounding-volume.d.ts.map +1 -0
- package/dist/tileset/helpers/bounding-volume.js +159 -70
- package/dist/tileset/helpers/frame-state.d.ts +17 -0
- package/dist/tileset/helpers/frame-state.d.ts.map +1 -0
- package/dist/tileset/helpers/frame-state.js +67 -48
- package/dist/tileset/helpers/i3s-lod.d.ts +20 -0
- package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -0
- package/dist/tileset/helpers/i3s-lod.js +80 -105
- package/dist/tileset/helpers/tiles-3d-lod.d.ts +8 -0
- package/dist/tileset/helpers/tiles-3d-lod.d.ts.map +1 -0
- package/dist/tileset/helpers/tiles-3d-lod.js +111 -100
- package/dist/tileset/helpers/transform-utils.d.ts +2 -0
- package/dist/tileset/helpers/transform-utils.d.ts.map +1 -0
- package/dist/tileset/helpers/transform-utils.js +50 -53
- package/dist/tileset/helpers/zoom.d.ts +7 -0
- package/dist/tileset/helpers/zoom.d.ts.map +1 -0
- package/dist/tileset/helpers/zoom.js +36 -30
- package/dist/tileset/tile-3d.d.ts +174 -0
- package/dist/tileset/tile-3d.d.ts.map +1 -0
- package/dist/tileset/tile-3d.js +550 -530
- package/dist/tileset/tileset-3d.d.ts +172 -0
- package/dist/tileset/tileset-3d.d.ts.map +1 -0
- package/dist/tileset/tileset-3d.js +576 -649
- package/dist/tileset/tileset-cache.d.ts +18 -0
- package/dist/tileset/tileset-cache.d.ts.map +1 -0
- package/dist/tileset/tileset-cache.js +71 -71
- package/dist/tileset/traversers/i3s-tile-manager.d.ts +8 -0
- package/dist/tileset/traversers/i3s-tile-manager.d.ts.map +1 -0
- package/dist/tileset/traversers/i3s-tile-manager.js +31 -40
- package/dist/tileset/traversers/i3s-tileset-traverser.d.ts +18 -0
- package/dist/tileset/traversers/i3s-tileset-traverser.d.ts.map +1 -0
- package/dist/tileset/traversers/i3s-tileset-traverser.js +81 -76
- package/dist/tileset/traversers/tileset-3d-traverser.d.ts +7 -0
- package/dist/tileset/traversers/tileset-3d-traverser.d.ts.map +1 -0
- package/dist/tileset/traversers/tileset-3d-traverser.js +51 -49
- package/dist/tileset/traversers/tileset-traverser.d.ts +52 -0
- package/dist/tileset/traversers/tileset-traverser.d.ts.map +1 -0
- package/dist/tileset/traversers/tileset-traverser.js +274 -276
- package/dist/utils/doubly-linked-list-node.d.ts +12 -0
- package/dist/utils/doubly-linked-list-node.d.ts.map +1 -0
- package/dist/utils/doubly-linked-list-node.js +16 -8
- package/dist/utils/doubly-linked-list.d.ts +31 -0
- package/dist/utils/doubly-linked-list.d.ts.map +1 -0
- package/dist/utils/doubly-linked-list.js +94 -72
- package/dist/utils/managed-array.d.ts +85 -0
- package/dist/utils/managed-array.d.ts.map +1 -0
- package/dist/utils/managed-array.js +143 -103
- package/package.json +11 -9
- package/src/bundle.ts +2 -3
- package/src/index.ts +1 -0
- package/src/tileset/helpers/i3s-lod.ts +72 -96
- package/src/tileset/helpers/transform-utils.ts +3 -1
- package/src/tileset/tile-3d.ts +2 -2
- package/src/tileset/tileset-cache.ts +2 -0
- package/src/tileset/traversers/i3s-tileset-traverser.ts +2 -3
- package/src/utils/{doubly-linked-list-node.js → doubly-linked-list-node.ts} +4 -0
- package/src/utils/{doubly-linked-list.js → doubly-linked-list.ts} +3 -5
- package/src/utils/{managed-array.js → managed-array.ts} +4 -1
- package/dist/bundle.js.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
- package/dist/tileset/helpers/bounding-volume.js.map +0 -1
- package/dist/tileset/helpers/frame-state.js.map +0 -1
- package/dist/tileset/helpers/i3s-lod.js.map +0 -1
- package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
- package/dist/tileset/helpers/transform-utils.js.map +0 -1
- package/dist/tileset/helpers/zoom.js.map +0 -1
- package/dist/tileset/tile-3d.js.map +0 -1
- package/dist/tileset/tileset-3d.js.map +0 -1
- package/dist/tileset/tileset-cache.js.map +0 -1
- package/dist/tileset/traversers/i3s-tile-manager.js.map +0 -1
- package/dist/tileset/traversers/i3s-tileset-traverser.js.map +0 -1
- package/dist/tileset/traversers/tileset-3d-traverser.js.map +0 -1
- package/dist/tileset/traversers/tileset-traverser.js.map +0 -1
- package/dist/utils/doubly-linked-list-node.js.map +0 -1
- package/dist/utils/doubly-linked-list.js.map +0 -1
- package/dist/utils/managed-array.js.map +0 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { default as Tileset3D } from './tileset/tileset-3d';
|
|
2
|
+
export { default as Tile3D } from './tileset/tile-3d';
|
|
3
|
+
export { default as TilesetTraverser } from './tileset/traversers/tileset-traverser';
|
|
4
|
+
export { default as TilesetCache } from './tileset/tileset-cache';
|
|
5
|
+
export { createBoundingVolume } from './tileset/helpers/bounding-volume';
|
|
6
|
+
export { calculateTransformProps } from './tileset/helpers/transform-utils';
|
|
7
|
+
export { getFrameState } from './tileset/helpers/frame-state';
|
|
8
|
+
export { getLodStatus } from './tileset/helpers/i3s-lod';
|
|
9
|
+
export { TILE_CONTENT_STATE, TILE_REFINEMENT, TILE_TYPE, TILESET_TYPE, LOD_METRIC_TYPE } from './constants';
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["default","Tileset3D","Tile3D","TilesetTraverser","TilesetCache","createBoundingVolume","calculateTransformProps","getFrameState","getLodStatus","TILE_CONTENT_STATE","TILE_REFINEMENT","TILE_TYPE","TILESET_TYPE","LOD_METRIC_TYPE"],"mappings":"AACA,SAAQA,OAAO,IAAIC,SAAnB,QAAmC,sBAAnC;AACA,SAAQD,OAAO,IAAIE,MAAnB,QAAgC,mBAAhC;AAEA,SAAQF,OAAO,IAAIG,gBAAnB,QAA0C,wCAA1C;AACA,SAAQH,OAAO,IAAII,YAAnB,QAAsC,yBAAtC;AAEA,SAAQC,oBAAR,QAAmC,mCAAnC;AACA,SAAQC,uBAAR,QAAsC,mCAAtC;AAEA,SAAQC,aAAR,QAA4B,+BAA5B;AACA,SAAQC,YAAR,QAA2B,2BAA3B;AAEA,SACEC,kBADF,EAEEC,eAFF,EAGEC,SAHF,EAIEC,YAJF,EAKEC,eALF,QAMO,aANP","sourcesContent":["export type {Tileset3DProps} from './tileset/tileset-3d';\nexport {default as Tileset3D} from './tileset/tileset-3d';\nexport {default as Tile3D} from './tileset/tile-3d';\n\nexport {default as TilesetTraverser} from './tileset/traversers/tileset-traverser';\nexport {default as TilesetCache} from './tileset/tileset-cache';\n\nexport {createBoundingVolume} from './tileset/helpers/bounding-volume';\nexport {calculateTransformProps} from './tileset/helpers/transform-utils';\n\nexport {getFrameState} from './tileset/helpers/frame-state';\nexport {getLodStatus} from './tileset/helpers/i3s-lod';\n\nexport {\n TILE_CONTENT_STATE,\n TILE_REFINEMENT,\n TILE_TYPE,\n TILESET_TYPE,\n LOD_METRIC_TYPE\n} from './constants';\n"],"file":"index.js"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/3d-tiles-options.ts"],"names":["get3dTilesOptions","tileset","assetGltfUpAxis","asset","gltfUpAxis"],"mappings":"AAAA,OAAO,SAASA,iBAAT,CAA2BC,OAA3B,EAAoC;AACzC,SAAO;AACLC,IAAAA,eAAe,EAAGD,OAAO,CAACE,KAAR,IAAiBF,OAAO,CAACE,KAAR,CAAcC,UAAhC,IAA+C;AAD3D,GAAP;AAGD","sourcesContent":["export function get3dTilesOptions(tileset) {\n return {\n assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'\n };\n}\n"],"file":"3d-tiles-options.js"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { Quaternion, Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core';
|
|
2
|
+
import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
|
|
3
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
+
import { assert } from '@loaders.gl/loader-utils';
|
|
5
|
+
|
|
6
|
+
function defined(x) {
|
|
7
|
+
return x !== undefined && x !== null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const scratchScale = new Vector3();
|
|
11
|
+
const scratchNorthWest = new Vector3();
|
|
12
|
+
const scratchSouthEast = new Vector3();
|
|
13
|
+
export function createBoundingVolume(boundingVolumeHeader, transform, result) {
|
|
14
|
+
assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
|
|
15
|
+
|
|
16
|
+
if (boundingVolumeHeader.box) {
|
|
17
|
+
return createBox(boundingVolumeHeader.box, transform, result);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (boundingVolumeHeader.region) {
|
|
21
|
+
const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
|
|
22
|
+
const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
|
|
23
|
+
const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
|
|
24
|
+
const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
|
|
25
|
+
const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;
|
|
26
|
+
return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4());
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (boundingVolumeHeader.sphere) {
|
|
30
|
+
return createSphere(boundingVolumeHeader.sphere, transform, result);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function createBox(box, transform, result) {
|
|
37
|
+
const center = new Vector3(box[0], box[1], box[2]);
|
|
38
|
+
transform.transform(center, center);
|
|
39
|
+
let origin = [];
|
|
40
|
+
|
|
41
|
+
if (box.length === 10) {
|
|
42
|
+
const halfSize = box.slice(3, 6);
|
|
43
|
+
const quaternion = new Quaternion();
|
|
44
|
+
quaternion.fromArray(box, 6);
|
|
45
|
+
const x = new Vector3([1, 0, 0]);
|
|
46
|
+
const y = new Vector3([0, 1, 0]);
|
|
47
|
+
const z = new Vector3([0, 0, 1]);
|
|
48
|
+
x.transformByQuaternion(quaternion);
|
|
49
|
+
x.scale(halfSize[0]);
|
|
50
|
+
y.transformByQuaternion(quaternion);
|
|
51
|
+
y.scale(halfSize[1]);
|
|
52
|
+
z.transformByQuaternion(quaternion);
|
|
53
|
+
z.scale(halfSize[2]);
|
|
54
|
+
origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];
|
|
55
|
+
} else {
|
|
56
|
+
origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const xAxis = transform.transformAsVector(origin.slice(0, 3));
|
|
60
|
+
const yAxis = transform.transformAsVector(origin.slice(3, 6));
|
|
61
|
+
const zAxis = transform.transformAsVector(origin.slice(6, 9));
|
|
62
|
+
const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
|
|
63
|
+
|
|
64
|
+
if (defined(result)) {
|
|
65
|
+
result.center = center;
|
|
66
|
+
result.halfAxes = halfAxes;
|
|
67
|
+
return result;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
return new OrientedBoundingBox(center, halfAxes);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function createSphere(sphere, transform, result) {
|
|
74
|
+
const center = new Vector3(sphere[0], sphere[1], sphere[2]);
|
|
75
|
+
transform.transform(center, center);
|
|
76
|
+
const scale = transform.getScale(scratchScale);
|
|
77
|
+
const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);
|
|
78
|
+
const radius = sphere[3] * uniformScale;
|
|
79
|
+
|
|
80
|
+
if (defined(result)) {
|
|
81
|
+
result.center = center;
|
|
82
|
+
result.radius = radius;
|
|
83
|
+
return result;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return new BoundingSphere(center, radius);
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=bounding-volume.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/bounding-volume.ts"],"names":["Quaternion","Vector3","Matrix3","Matrix4","degrees","BoundingSphere","OrientedBoundingBox","Ellipsoid","assert","defined","x","undefined","scratchScale","scratchNorthWest","scratchSouthEast","createBoundingVolume","boundingVolumeHeader","transform","result","box","createBox","region","west","south","east","north","minHeight","maxHeight","northWest","WGS84","cartographicToCartesian","southEast","centerInCartesian","addVectors","multiplyScalar","radius","subVectors","len","createSphere","sphere","Error","center","origin","length","halfSize","slice","quaternion","fromArray","y","z","transformByQuaternion","scale","toArray","xAxis","transformAsVector","yAxis","zAxis","halfAxes","getScale","uniformScale","Math","max"],"mappings":"AAIA,SAAQA,UAAR,EAAoBC,OAApB,EAA6BC,OAA7B,EAAsCC,OAAtC,EAA+CC,OAA/C,QAA6D,eAA7D;AACA,SAAQC,cAAR,EAAwBC,mBAAxB,QAAkD,kBAAlD;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AACA,SAAQC,MAAR,QAAqB,0BAArB;;AAIA,SAASC,OAAT,CAAiBC,CAAjB,EAAoB;AAClB,SAAOA,CAAC,KAAKC,SAAN,IAAmBD,CAAC,KAAK,IAAhC;AACD;;AAGD,MAAME,YAAY,GAAG,IAAIX,OAAJ,EAArB;AACA,MAAMY,gBAAgB,GAAG,IAAIZ,OAAJ,EAAzB;AACA,MAAMa,gBAAgB,GAAG,IAAIb,OAAJ,EAAzB;AAYA,OAAO,SAASc,oBAAT,CAA8BC,oBAA9B,EAAoDC,SAApD,EAA+DC,MAA/D,EAAuE;AAC5EV,EAAAA,MAAM,CAACQ,oBAAD,EAAuB,yCAAvB,CAAN;;AAIA,MAAIA,oBAAoB,CAACG,GAAzB,EAA8B;AAC5B,WAAOC,SAAS,CAACJ,oBAAoB,CAACG,GAAtB,EAA2BF,SAA3B,EAAsCC,MAAtC,CAAhB;AACD;;AACD,MAAIF,oBAAoB,CAACK,MAAzB,EAAiC;AAI/B,UAAM,CAACC,IAAD,EAAOC,KAAP,EAAcC,IAAd,EAAoBC,KAApB,EAA2BC,SAA3B,EAAsCC,SAAtC,IAAmDX,oBAAoB,CAACK,MAA9E;AAEA,UAAMO,SAAS,GAAGrB,SAAS,CAACsB,KAAV,CAAgBC,uBAAhB,CAChB,CAAC1B,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,CAAf;AACAtB,EAAAA,SAAS,CAACA,SAAV,CAAoBwB,MAApB,EAA4BA,MAA5B;AACA,QAAMU,KAAK,GAAGlC,SAAS,CAACyC,QAAV,CAAmB9C,YAAnB,CAAd;AAEA,QAAM+C,YAAY,GAAGC,IAAI,CAACC,GAAL,CAASD,IAAI,CAACC,GAAL,CAASV,KAAK,CAAC,CAAD,CAAd,EAAmBA,KAAK,CAAC,CAAD,CAAxB,CAAT,EAAuCA,KAAK,CAAC,CAAD,CAA5C,CAArB;AACA,QAAMhB,MAAM,GAAGI,MAAM,CAAC,CAAD,CAAN,GAAYoB,YAA3B;;AAEA,MAAIlD,OAAO,CAACS,MAAD,CAAX,EAAqB;AACnBA,IAAAA,MAAM,CAACuB,MAAP,GAAgBA,MAAhB;AACAvB,IAAAA,MAAM,CAACiB,MAAP,GAAgBA,MAAhB;AACA,WAAOjB,MAAP;AACD;;AAED,SAAO,IAAIb,cAAJ,CAAmBoC,MAAnB,EAA2BN,MAA3B,CAAP;AACD","sourcesContent":["// This file is derived from the Cesium code base under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n/* eslint-disable */\nimport {Quaternion, Vector3, Matrix3, Matrix4, degrees} from '@math.gl/core';\nimport {BoundingSphere, OrientedBoundingBox} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {assert} from '@loaders.gl/loader-utils';\n\n// const scratchProjectedBoundingSphere = new BoundingSphere();\n\nfunction defined(x) {\n return x !== undefined && x !== null;\n}\n\n// const scratchMatrix = new Matrix3();\nconst scratchScale = new Vector3();\nconst scratchNorthWest = new Vector3();\nconst scratchSouthEast = new Vector3();\n// const scratchRectangle = new Rectangle();\n// const scratchOrientedBoundingBox = new OrientedBoundingBox();\n// const scratchTransform = new Matrix4();\n\n/**\n * Create a bounding volume from the tile's bounding volume header.\n * @param {Object} boundingVolumeHeader The tile's bounding volume header.\n * @param {Matrix4} transform The transform to apply to the bounding volume.\n * @param [result] The object onto which to store the result.\n * @returns The modified result parameter or a new TileBoundingVolume instance if none was provided.\n */\nexport function createBoundingVolume(boundingVolumeHeader, transform, result) {\n assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');\n\n // boundingVolume schema:\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json\n if (boundingVolumeHeader.box) {\n return createBox(boundingVolumeHeader.box, transform, result);\n }\n if (boundingVolumeHeader.region) {\n // [west, south, east, north, minimum height, maximum height]\n // Latitudes and longitudes are in the WGS 84 datum as defined in EPSG 4979 and are in radians.\n // Heights are in meters above (or below) the WGS 84 ellipsoid.\n const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;\n\n const northWest = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(west), degrees(north), minHeight],\n scratchNorthWest\n );\n const southEast = Ellipsoid.WGS84.cartographicToCartesian(\n [degrees(east), degrees(south), maxHeight],\n scratchSouthEast\n );\n const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);\n const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;\n\n // TODO improve region boundingVolume\n // for now, create a sphere as the boundingVolume instead of box\n return createSphere(\n [centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius],\n new Matrix4()\n );\n }\n\n if (boundingVolumeHeader.sphere) {\n return createSphere(boundingVolumeHeader.sphere, transform, result);\n }\n\n throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');\n}\n\nfunction createBox(box, transform, result) {\n // https://math.gl/modules/culling/docs/api-reference/oriented-bounding-box\n // 1. A half-axes based representation.\n // box: An array of 12 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box.\n // The next three elements (with indices 3, 4, and 5) define the x axis direction and half-length.\n // The next three elements (indices 6, 7, and 8) define the y axis direction and half-length.\n // The last three elements (indices 9, 10, and 11) define the z axis direction and half-length.\n // 2. A half-size-quaternion based representation.\n // box: An array of 10 numbers that define an oriented bounding box.\n // The first three elements define the x, y, and z values for the center of the box in a right-handed 3-axis (x, y, z) Cartesian coordinate system where the z-axis is up.\n // The next three elements (with indices 3, 4, and 5) define the halfSize.\n // The last four elements (indices 6, 7, 8 and 10) define the quaternion.\n const center = new Vector3(box[0], box[1], box[2]);\n transform.transform(center, center);\n let origin: number[] = [];\n if (box.length === 10) {\n const halfSize = box.slice(3, 6);\n const quaternion = new Quaternion();\n quaternion.fromArray(box, 6);\n const x = new Vector3([1, 0, 0]);\n const y = new Vector3([0, 1, 0]);\n const z = new Vector3([0, 0, 1]);\n x.transformByQuaternion(quaternion);\n x.scale(halfSize[0]);\n y.transformByQuaternion(quaternion);\n y.scale(halfSize[1]);\n z.transformByQuaternion(quaternion);\n z.scale(halfSize[2]);\n origin = [...x.toArray(), ...y.toArray(), ...z.toArray()];\n } else {\n origin = [...box.slice(3, 6), ...box.slice(6, 9), ...box.slice(9, 12)];\n }\n const xAxis = transform.transformAsVector(origin.slice(0, 3));\n const yAxis = transform.transformAsVector(origin.slice(3, 6));\n const zAxis = transform.transformAsVector(origin.slice(6, 9));\n const halfAxes = new Matrix3([\n xAxis[0],\n xAxis[1],\n xAxis[2],\n yAxis[0],\n yAxis[1],\n yAxis[2],\n zAxis[0],\n zAxis[1],\n zAxis[2]\n ]);\n\n if (defined(result)) {\n result.center = center;\n result.halfAxes = halfAxes;\n return result;\n }\n\n return new OrientedBoundingBox(center, halfAxes);\n}\n\n/*\nfunction createBoxFromTransformedRegion(region, transform, initialTransform, result) {\n const rectangle = Rectangle.unpack(region, 0, scratchRectangle);\n const minimumHeight = region[4];\n const maximumHeight = region[5];\n\n const orientedBoundingBox = OrientedBoundingBox.fromRectangle(\n rectangle,\n minimumHeight,\n maximumHeight,\n Ellipsoid.WGS84,\n scratchOrientedBoundingBox\n );\n const center = orientedBoundingBox.center;\n const halfAxes = orientedBoundingBox.halfAxes;\n\n // A region bounding volume is not transformed by the transform in the tileset JSON,\n // but may be transformed by additional transforms applied in Cesium.\n // This is why the transform is calculated as the difference between the initial transform and the current transform.\n transform = Matrix4.multiplyTransformation(\n transform,\n Matrix4.inverseTransformation(initialTransform, scratchTransform),\n scratchTransform\n );\n center = Matrix4.multiplyByPoint(transform, center, center);\n const rotationScale = Matrix4.getRotation(transform, scratchMatrix);\n halfAxes = Matrix3.multiply(rotationScale, halfAxes, halfAxes);\n\n if (defined(result) && result instanceof TileOrientedBoundingBox) {\n result.update(center, halfAxes);\n return result;\n }\n\n return new TileOrientedBoundingBox(center, halfAxes);\n}\n\nfunction createRegion(region, transform, initialTransform, result) {\n if (!Matrix4.equalsEpsilon(transform, initialTransform, CesiumMath.EPSILON8)) {\n return createBoxFromTransformedRegion(region, transform, initialTransform, result);\n }\n\n if (defined(result)) {\n return result;\n }\n\n const rectangleRegion = Rectangle.unpack(region, 0, scratchRectangle);\n\n return new TileBoundingRegion({\n rectangle: rectangleRegion,\n minimumHeight: region[4],\n maximumHeight: region[5]\n });\n}\n*/\n\nfunction createSphere(sphere, transform, result?) {\n // Find the transformed center\n const center = new Vector3(sphere[0], sphere[1], sphere[2]);\n transform.transform(center, center);\n const scale = transform.getScale(scratchScale);\n\n const uniformScale = Math.max(Math.max(scale[0], scale[1]), scale[2]);\n const radius = sphere[3] * uniformScale;\n\n if (defined(result)) {\n result.center = center;\n result.radius = radius;\n return result;\n }\n\n return new BoundingSphere(center, radius);\n}\n"],"file":"bounding-volume.js"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Vector3 } from '@math.gl/core';
|
|
2
|
+
import { CullingVolume, Plane } from '@math.gl/culling';
|
|
3
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
4
|
+
const scratchVector = new Vector3();
|
|
5
|
+
const scratchPosition = new Vector3();
|
|
6
|
+
const cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
|
|
7
|
+
export function getFrameState(viewport, frameNumber) {
|
|
8
|
+
const {
|
|
9
|
+
cameraDirection,
|
|
10
|
+
cameraUp,
|
|
11
|
+
height
|
|
12
|
+
} = viewport;
|
|
13
|
+
const {
|
|
14
|
+
metersPerUnit
|
|
15
|
+
} = viewport.distanceScales;
|
|
16
|
+
const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0];
|
|
17
|
+
const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(viewportCenterCartographic, new Vector3());
|
|
18
|
+
const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
|
|
19
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
20
|
+
const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
|
|
21
|
+
const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
|
|
22
|
+
const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
|
|
23
|
+
commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);
|
|
24
|
+
return {
|
|
25
|
+
camera: {
|
|
26
|
+
position: cameraPositionCartesian,
|
|
27
|
+
direction: cameraDirectionCartesian,
|
|
28
|
+
up: cameraUpCartesian
|
|
29
|
+
},
|
|
30
|
+
viewport,
|
|
31
|
+
height,
|
|
32
|
+
cullingVolume,
|
|
33
|
+
frameNumber,
|
|
34
|
+
sseDenominator: 1.15
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {
|
|
39
|
+
const frustumPlanes = viewport.getFrustumPlanes();
|
|
40
|
+
let i = 0;
|
|
41
|
+
|
|
42
|
+
for (const dir in frustumPlanes) {
|
|
43
|
+
const plane = frustumPlanes[dir];
|
|
44
|
+
const distanceToCenter = plane.normal.dot(viewport.center);
|
|
45
|
+
scratchPosition.copy(plane.normal).scale(plane.distance - distanceToCenter).add(viewport.center);
|
|
46
|
+
const cartographicPos = viewport.unprojectPosition(scratchPosition);
|
|
47
|
+
const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());
|
|
48
|
+
cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=frame-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/frame-state.ts"],"names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartographic","longitude","latitude","viewportCenterCartesian","WGS84","cartographicToCartesian","enuToFixedTransform","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","camera","position","direction","up","sseDenominator","frustumPlanes","getFrustumPlanes","i","dir","plane","distanceToCenter","normal","dot","center","copy","distance","add","cartographicPos","cartesianPos","planes","fromPointNormal","subtract"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AACA,SAAQC,aAAR,EAAuBC,KAAvB,QAAmC,kBAAnC;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAeA,MAAMC,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AACA,MAAMK,eAAe,GAAG,IAAIL,OAAJ,EAAxB;AACA,MAAMM,aAAa,GAAG,IAAIL,aAAJ,CAAkB,CACtC,IAAIC,KAAJ,EADsC,EAEtC,IAAIA,KAAJ,EAFsC,EAGtC,IAAIA,KAAJ,EAHsC,EAItC,IAAIA,KAAJ,EAJsC,EAKtC,IAAIA,KAAJ,EALsC,EAMtC,IAAIA,KAAJ,EANsC,CAAlB,CAAtB;AAWA,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S,MAAAA,SAAS,EAAER,wBAFL;AAGNS,MAAAA,EAAE,EAAEL;AAHE,KADH;AAMLvB,IAAAA,QANK;AAOLI,IAAAA,MAPK;AAQLN,IAAAA,aARK;AASLG,IAAAA,WATK;AAUL4B,IAAAA,cAAc,EAAE;AAVX,GAAP;AAYD;;AAED,SAASL,wBAAT,CAAkCxB,QAAlC,EAA4CU,uBAA5C,EAAqE;AAEnE,QAAMoB,aAAa,GAAG9B,QAAQ,CAAC+B,gBAAT,EAAtB;AACA,MAAIC,CAAC,GAAG,CAAR;;AACA,OAAK,MAAMC,GAAX,IAAkBH,aAAlB,EAAiC;AAC/B,UAAMI,KAAK,GAAGJ,aAAa,CAACG,GAAD,CAA3B;AACA,UAAME,gBAAgB,GAAGD,KAAK,CAACE,MAAN,CAAaC,GAAb,CAAiBrC,QAAQ,CAACsC,MAA1B,CAAzB;AACAzC,IAAAA,eAAe,CACZ0C,IADH,CACQL,KAAK,CAACE,MADd,EAEGf,KAFH,CAESa,KAAK,CAACM,QAAN,GAAiBL,gBAF1B,EAGGM,GAHH,CAGOzC,QAAQ,CAACsC,MAHhB;AAIA,UAAMI,eAAe,GAAG1C,QAAQ,CAACgB,iBAAT,CAA2BnB,eAA3B,CAAxB;AAEA,UAAM8C,YAAY,GAAGhD,SAAS,CAACgB,KAAV,CAAgBC,uBAAhB,CAAwC8B,eAAxC,EAAyD,IAAIlD,OAAJ,EAAzD,CAArB;AAEAM,IAAAA,aAAa,CAAC8C,MAAd,CAAqBZ,CAAC,EAAtB,EAA0Ba,eAA1B,CACEF,YADF,EAGE/C,aAAa,CAAC2C,IAAd,CAAmB7B,uBAAnB,EAA4CoC,QAA5C,CAAqDH,YAArD,CAHF;AAKD;AACF","sourcesContent":["import {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: {[key: string]: any};\n height: number;\n cullingVolume: CullingVolume;\n frameNumber: number; // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: number; // Assumes fovy = 60 degrees\n};\n\nconst scratchVector = new Vector3();\nconst scratchPosition = new Vector3();\nconst cullingVolume = new CullingVolume([\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane(),\n new Plane()\n]);\n\n// Extracts a frame state appropriate for tile culling from a deck.gl viewport\n// TODO - this could likely be generalized and merged back into deck.gl for other culling scenarios\nexport function getFrameState(viewport, frameNumber: number): FrameState {\n // Traverse and and request. Update _selectedTiles so that we know what to render.\n const {cameraDirection, cameraUp, height} = viewport;\n const {metersPerUnit} = viewport.distanceScales;\n\n const viewportCenterCartographic = [viewport.longitude, viewport.latitude, 0];\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n viewportCenterCartographic,\n new Vector3()\n );\n const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);\n\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n cameraPositionCartographic,\n new Vector3()\n );\n\n // These should still be normalized as the transform has scale 1 (goes from meters to meters)\n const cameraDirectionCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))\n ).normalize();\n const cameraUpCartesian = new Vector3(\n // @ts-ignore\n enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))\n ).normalize();\n\n commonSpacePlanesToWGS84(viewport, viewportCenterCartesian);\n\n // TODO: make a file/class for frameState and document what needs to be attached to this so that traversal can function\n return {\n camera: {\n position: cameraPositionCartesian,\n direction: cameraDirectionCartesian,\n up: cameraUpCartesian\n },\n viewport,\n height,\n cullingVolume,\n frameNumber, // TODO: This can be the same between updates, what number is unique for between updates?\n sseDenominator: 1.15 // Assumes fovy = 60 degrees\n };\n}\n\nfunction commonSpacePlanesToWGS84(viewport, viewportCenterCartesian) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n let i = 0;\n for (const dir in frustumPlanes) {\n const plane = frustumPlanes[dir];\n const distanceToCenter = plane.normal.dot(viewport.center);\n scratchPosition\n .copy(plane.normal)\n .scale(plane.distance - distanceToCenter)\n .add(viewport.center);\n const cartographicPos = viewport.unprojectPosition(scratchPosition);\n\n const cartesianPos = Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, new Vector3());\n\n cullingVolume.planes[i++].fromPointNormal(\n cartesianPos,\n // Want the normal to point into the frustum since that's what culling expects\n scratchVector.copy(viewportCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n"],"file":"frame-state.js"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
2
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
3
|
+
export function getLodStatus(tile, frameState) {
|
|
4
|
+
if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
|
|
5
|
+
return 'DIG';
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const screenSize = 2 * getProjectedRadius(tile, frameState);
|
|
9
|
+
|
|
10
|
+
if (screenSize < 2) {
|
|
11
|
+
return 'OUT';
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!tile.header.children || screenSize <= tile.lodMetricValue) {
|
|
15
|
+
return 'DRAW';
|
|
16
|
+
} else if (tile.header.children) {
|
|
17
|
+
return 'DIG';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return 'OUT';
|
|
21
|
+
}
|
|
22
|
+
export function getProjectedRadius(tile, frameState) {
|
|
23
|
+
const originalViewport = frameState.viewport;
|
|
24
|
+
const ViewportClass = originalViewport.constructor;
|
|
25
|
+
const {
|
|
26
|
+
longitude,
|
|
27
|
+
latitude,
|
|
28
|
+
height,
|
|
29
|
+
width,
|
|
30
|
+
bearing,
|
|
31
|
+
zoom
|
|
32
|
+
} = originalViewport;
|
|
33
|
+
const viewport = new ViewportClass({
|
|
34
|
+
longitude,
|
|
35
|
+
latitude,
|
|
36
|
+
height,
|
|
37
|
+
width,
|
|
38
|
+
bearing,
|
|
39
|
+
zoom,
|
|
40
|
+
pitch: 0
|
|
41
|
+
});
|
|
42
|
+
const mbsLat = tile.header.mbs[1];
|
|
43
|
+
const mbsLon = tile.header.mbs[0];
|
|
44
|
+
const mbsZ = tile.header.mbs[2];
|
|
45
|
+
const mbsR = tile.header.mbs[3];
|
|
46
|
+
const mbsCenterCartesian = [...tile.boundingVolume.center];
|
|
47
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
48
|
+
const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
|
|
49
|
+
const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
|
|
50
|
+
const enuToCartesianMatrix = new Matrix4();
|
|
51
|
+
Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
|
|
52
|
+
const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();
|
|
53
|
+
const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
|
|
54
|
+
const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
|
|
55
|
+
const extraZ = projection * projection / cameraPositionEnu[2];
|
|
56
|
+
const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
|
|
57
|
+
const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
|
|
58
|
+
const extraVectorCartesian = new Vector3(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
|
|
59
|
+
const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
|
|
60
|
+
const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);
|
|
61
|
+
const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
|
|
62
|
+
const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
|
|
63
|
+
const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
|
|
64
|
+
const projectedRadius = new Vector3(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
|
|
65
|
+
return projectedRadius;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=i3s-lod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"names":["Matrix4","Vector3","Ellipsoid","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","originalViewport","viewport","ViewportClass","constructor","longitude","latitude","height","width","bearing","zoom","pitch","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","WGS84","cartographicToCartesian","toEye","subtract","normalize","enuToCartesianMatrix","eastNorthUpToFixedFrame","cartesianToEnuMatrix","invert","cameraPositionEnu","transform","projection","Math","sqrt","extraZ","extraVertexEnu","extraVertexCartesian","extraVectorCartesian","radiusVector","cross","scale","sphereMbsBorderVertexCartesian","add","sphereMbsBorderVertexCartographic","cartesianToCartographic","projectedOrigin","project","projectedMbsBorderVertex","projectedRadius","magnitude"],"mappings":"AAAA,SAAQA,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AACA,SAAQC,SAAR,QAAwB,qBAAxB;AAaA,OAAO,SAASC,YAAT,CAAsBC,IAAtB,EAAoCC,UAApC,EAAoF;AACzF,MAAID,IAAI,CAACE,cAAL,KA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,oBAAoB,GAAGD,cAAc,CAACL,SAAf,CAAyBL,oBAAzB,CAA7B;AACA,QAAMY,oBAAoB,GAAG,IAAInD,OAAJ,CAAYkD,oBAAZ,EAC1Bb,QAD0B,CACjBV,kBADiB,EAE1BW,SAF0B,EAA7B;AAIA,QAAMc,YAAY,GAAGhB,KAAK,CAACiB,KAAN,CAAYF,oBAAZ,EAAkCb,SAAlC,GAA8CgB,KAA9C,CAAoD5B,IAApD,CAArB;AACA,QAAM6B,8BAA8B,GAAG,IAAIvD,OAAJ,CAAY2B,kBAAZ,EAAgC6B,GAAhC,CAAoCJ,YAApC,CAAvC;AACA,QAAMK,iCAAiC,GAAGxD,SAAS,CAACiC,KAAV,CAAgBwB,uBAAhB,CACxCH,8BADwC,CAA1C;AAMA,QAAMI,eAAe,GAAG/C,QAAQ,CAACgD,OAAT,CAAiB,CAACpC,MAAD,EAASF,MAAT,EAAiBG,IAAjB,CAAjB,CAAxB;AACA,QAAMoC,wBAAwB,GAAGjD,QAAQ,CAACgD,OAAT,CAAiBH,iCAAjB,CAAjC;AACA,QAAMK,eAAe,GAAG,IAAI9D,OAAJ,CAAY2D,eAAZ,EACrBtB,QADqB,CACZwB,wBADY,EAErBE,SAFqB,EAAxB;AAGA,SAAOD,eAAP;AACD","sourcesContent":["import {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport Tile3D from '../tile-3d';\nimport {FrameState} from './frame-state';\n\n/**\n * For the maxScreenThreshold error metric, maxError means that you should replace the node with it's children\n as soon as the nodes bounding sphere has a screen radius larger than maxError pixels.\n In this sense a value of 0 means you should always load it's children,\n or if it's a leaf node, you should always display it.\n * @param tile \n * @param frameState \n * @returns \n */\nexport function getLodStatus(tile: Tile3D, frameState: FrameState): 'DIG' | 'OUT' | 'DRAW' {\n if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {\n return 'DIG';\n }\n const screenSize = 2 * getProjectedRadius(tile, frameState);\n if (screenSize < 2) {\n return 'OUT';\n }\n if (!tile.header.children || screenSize <= tile.lodMetricValue) {\n return 'DRAW';\n } else if (tile.header.children) {\n return 'DIG';\n }\n return 'OUT';\n}\n\n/**\n * Calculate size of MBS radius projected on the screen plane\n * @param tile\n * @param frameState\n * @returns\n */\n// eslint-disable-next-line max-statements\nexport function getProjectedRadius(tile: Tile3D, frameState: FrameState): number {\n const originalViewport = frameState.viewport;\n const ViewportClass = originalViewport.constructor;\n const {longitude, latitude, height, width, bearing, zoom} = originalViewport;\n // @ts-ignore\n const viewport = new ViewportClass({longitude, latitude, height, width, bearing, zoom, pitch: 0});\n const mbsLat = tile.header.mbs[1];\n const mbsLon = tile.header.mbs[0];\n const mbsZ = tile.header.mbs[2];\n const mbsR = tile.header.mbs[3];\n const mbsCenterCartesian = [...tile.boundingVolume.center];\n const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);\n const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(\n cameraPositionCartographic,\n new Vector3()\n );\n\n // ---------------------------\n // Calculate mbs border vertex\n // ---------------------------\n const toEye = new Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();\n // Add extra vector to form plane\n const enuToCartesianMatrix = new Matrix4();\n Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);\n const cartesianToEnuMatrix = new Matrix4(enuToCartesianMatrix).invert();\n const cameraPositionEnu = new Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);\n // Mean Proportionals in Right Triangles - Altitude rule\n // https://mathbitsnotebook.com/Geometry/RightTriangles/RTmeanRight.html\n const projection = Math.sqrt(\n cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]\n );\n const extraZ = (projection * projection) / cameraPositionEnu[2];\n const extraVertexEnu = new Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);\n const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);\n const extraVectorCartesian = new Vector3(extraVertexCartesian)\n .subtract(mbsCenterCartesian)\n .normalize();\n // We need radius vector orthogonal to toEye vector\n const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);\n const sphereMbsBorderVertexCartesian = new Vector3(mbsCenterCartesian).add(radiusVector);\n const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(\n sphereMbsBorderVertexCartesian\n );\n // ---------------------------\n\n // Project center vertex and border vertex and calculate projected radius of MBS\n const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);\n const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);\n const projectedRadius = new Vector3(projectedOrigin)\n .subtract(projectedMbsBorderVertex)\n .magnitude();\n return projectedRadius;\n}\n"],"file":"i3s-lod.js"}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { Matrix4, Vector3, clamp } from '@math.gl/core';
|
|
2
|
+
const scratchPositionNormal = new Vector3();
|
|
3
|
+
const scratchCartographic = new Vector3();
|
|
4
|
+
const scratchMatrix = new Matrix4();
|
|
5
|
+
const scratchCenter = new Vector3();
|
|
6
|
+
const scratchPosition = new Vector3();
|
|
7
|
+
const scratchDirection = new Vector3();
|
|
8
|
+
export function calculateDynamicScreenSpaceError(root, {
|
|
9
|
+
camera,
|
|
10
|
+
mapProjection
|
|
11
|
+
}, options = {}) {
|
|
12
|
+
const {
|
|
13
|
+
dynamicScreenSpaceErrorHeightFalloff = 0.25,
|
|
14
|
+
dynamicScreenSpaceErrorDensity = 0.00278
|
|
15
|
+
} = options;
|
|
16
|
+
let up;
|
|
17
|
+
let direction;
|
|
18
|
+
let height;
|
|
19
|
+
let minimumHeight;
|
|
20
|
+
let maximumHeight;
|
|
21
|
+
const tileBoundingVolume = root.contentBoundingVolume;
|
|
22
|
+
|
|
23
|
+
if (tileBoundingVolume instanceof TileBoundingRegion) {
|
|
24
|
+
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
25
|
+
direction = camera.directionWC;
|
|
26
|
+
height = camera.positionCartographic.height;
|
|
27
|
+
minimumHeight = tileBoundingVolume.minimumHeight;
|
|
28
|
+
maximumHeight = tileBoundingVolume.maximumHeight;
|
|
29
|
+
} else {
|
|
30
|
+
const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
|
|
31
|
+
const ellipsoid = mapProjection.ellipsoid;
|
|
32
|
+
const boundingVolume = tileBoundingVolume.boundingVolume;
|
|
33
|
+
const centerLocal = Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
|
|
34
|
+
|
|
35
|
+
if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
|
|
36
|
+
const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
|
|
37
|
+
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
38
|
+
direction = camera.directionWC;
|
|
39
|
+
height = camera.positionCartographic.height;
|
|
40
|
+
minimumHeight = 0.0;
|
|
41
|
+
maximumHeight = centerCartographic.height * 2.0;
|
|
42
|
+
} else {
|
|
43
|
+
const positionLocal = Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
|
|
44
|
+
up = Cartesian3.UNIT_Z;
|
|
45
|
+
direction = Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
|
|
46
|
+
direction = Cartesian3.normalize(direction, direction);
|
|
47
|
+
height = positionLocal.z;
|
|
48
|
+
|
|
49
|
+
if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
|
|
50
|
+
const boxHeight = root._header.boundingVolume.box[11];
|
|
51
|
+
minimumHeight = centerLocal.z - boxHeight;
|
|
52
|
+
maximumHeight = centerLocal.z + boxHeight;
|
|
53
|
+
} else if (tileBoundingVolume instanceof TileBoundingSphere) {
|
|
54
|
+
const radius = boundingVolume.radius;
|
|
55
|
+
minimumHeight = centerLocal.z - radius;
|
|
56
|
+
maximumHeight = centerLocal.z + radius;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
|
|
62
|
+
const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
|
|
63
|
+
const heightFar = maximumHeight;
|
|
64
|
+
const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
|
|
65
|
+
const dot = Math.abs(Cartesian3.dot(direction, up));
|
|
66
|
+
let horizonFactor = 1.0 - dot;
|
|
67
|
+
horizonFactor = horizonFactor * (1.0 - t);
|
|
68
|
+
return dynamicScreenSpaceErrorDensity * horizonFactor;
|
|
69
|
+
}
|
|
70
|
+
export function fog(distanceToCamera, density) {
|
|
71
|
+
const scalar = distanceToCamera * density;
|
|
72
|
+
return 1.0 - Math.exp(-(scalar * scalar));
|
|
73
|
+
}
|
|
74
|
+
export function getDynamicScreenSpaceError(tileset, distanceToCamera) {
|
|
75
|
+
if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
|
|
76
|
+
const density = tileset.dynamicScreenSpaceErrorComputedDensity;
|
|
77
|
+
const factor = tileset.dynamicScreenSpaceErrorFactor;
|
|
78
|
+
const dynamicError = fog(distanceToCamera, density) * factor;
|
|
79
|
+
return dynamicError;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return 0;
|
|
83
|
+
}
|
|
84
|
+
export function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
|
|
85
|
+
const tileset = tile.tileset;
|
|
86
|
+
const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
|
|
87
|
+
const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
|
|
88
|
+
|
|
89
|
+
if (lodMetricValue === 0.0) {
|
|
90
|
+
return 0.0;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const distance = Math.max(tile._distanceToCamera, 1e-7);
|
|
94
|
+
const {
|
|
95
|
+
height,
|
|
96
|
+
sseDenominator
|
|
97
|
+
} = frameState;
|
|
98
|
+
const {
|
|
99
|
+
viewDistanceScale
|
|
100
|
+
} = tileset.options;
|
|
101
|
+
let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
|
|
102
|
+
error -= getDynamicScreenSpaceError(tileset, distance);
|
|
103
|
+
return error;
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=tiles-3d-lod.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":["Matrix4","Vector3","clamp","scratchPositionNormal","scratchCartographic","scratchMatrix","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","camera","mapProjection","options","dynamicScreenSpaceErrorHeightFalloff","dynamicScreenSpaceErrorDensity","up","direction","height","minimumHeight","maximumHeight","tileBoundingVolume","contentBoundingVolume","TileBoundingRegion","Cartesian3","normalize","positionWC","directionWC","positionCartographic","transformLocal","inverseTransformation","computedTransform","ellipsoid","boundingVolume","centerLocal","multiplyByPoint","center","magnitude","minimumRadius","centerCartographic","Cartographic","fromCartesian","positionLocal","UNIT_Z","multiplyByPointAsVector","z","TileOrientedBoundingBox","boxHeight","_header","box","TileBoundingSphere","radius","heightFalloff","heightClose","heightFar","t","dot","Math","abs","horizonFactor","fog","distanceToCamera","density","scalar","exp","getDynamicScreenSpaceError","tileset","dynamicScreenSpaceError","dynamicScreenSpaceErrorComputedDensity","factor","dynamicScreenSpaceErrorFactor","dynamicError","getTiles3DScreenSpaceError","tile","frameState","useParentLodMetric","parentLodMetricValue","parent","lodMetricValue","distance","max","_distanceToCamera","sseDenominator","viewDistanceScale","error"],"mappings":"AAQA,SAAQA,OAAR,EAAiBC,OAAjB,EAA0BC,KAA1B,QAAsC,eAAtC;AAEA,MAAMC,qBAAqB,GAAG,IAAIF,OAAJ,EAA9B;AACA,MAAMG,mBAAmB,GAAG,IAAIH,OAAJ,EAA5B;AACA,M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AtD;AACA,WAAOE,YAAP;AACD;;AAED,SAAO,CAAP;AACD;AAED,OAAO,SAASC,0BAAT,CAAoCC,IAApC,EAA0CC,UAA1C,EAAsDC,kBAAtD,EAA0E;AAC/E,QAAMT,OAAO,GAAGO,IAAI,CAACP,OAArB;AACA,QAAMU,oBAAoB,GAAIH,IAAI,CAACI,MAAL,IAAeJ,IAAI,CAACI,MAAL,CAAYC,cAA5B,IAA+CL,IAAI,CAACK,cAAjF;AACA,QAAMA,cAAc,GAAGH,kBAAkB,GAAGC,oBAAH,GAA0BH,IAAI,CAACK,cAAxE;;AAGA,MAAIA,cAAc,KAAK,GAAvB,EAA4B;AAC1B,WAAO,GAAP;AACD;;AAMD,QAAMC,QAAQ,GAAGtB,IAAI,CAACuB,GAAL,CAASP,IAAI,CAACQ,iBAAd,EAAiC,IAAjC,CAAjB;AACA,QAAM;AAAC/D,IAAAA,MAAD;AAASgE,IAAAA;AAAT,MAA2BR,UAAjC;AACA,QAAM;AAACS,IAAAA;AAAD,MAAsBjB,OAAO,CAACrD,OAApC;AACA,MAAIuE,KAAK,GAAIN,cAAc,GAAG5D,MAAjB,IAA2BiE,iBAAiB,IAAI,GAAhD,CAAD,IAA0DJ,QAAQ,GAAGG,cAArE,CAAZ;AAEAE,EAAAA,KAAK,IAAInB,0BAA0B,CAACC,OAAD,EAAUa,QAAV,CAAnC;AAEA,SAAOK,KAAP;AACD","sourcesContent":["// This file is derived from the Cesium code base under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\n// TODO - Dynamic screen space error provides an optimization when looking at\n// tilesets from above\n\n/* eslint-disable */\n// @ts-nocheck\nimport {Matrix4, Vector3, clamp} from '@math.gl/core';\n\nconst scratchPositionNormal = new Vector3();\nconst scratchCartographic = new Vector3();\nconst scratchMatrix = new Matrix4();\nconst scratchCenter = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchDirection = new Vector3();\n\n// eslint-disable-next-line max-statements, complexity\nexport function calculateDynamicScreenSpaceError(root, {camera, mapProjection}, options = {}) {\n const {dynamicScreenSpaceErrorHeightFalloff = 0.25, dynamicScreenSpaceErrorDensity = 0.00278} =\n options;\n\n let up;\n let direction;\n let height;\n let minimumHeight;\n let maximumHeight;\n\n const tileBoundingVolume = root.contentBoundingVolume;\n\n if (tileBoundingVolume instanceof TileBoundingRegion) {\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = tileBoundingVolume.minimumHeight;\n maximumHeight = tileBoundingVolume.maximumHeight;\n } else {\n // Transform camera position and direction into the local coordinate system of the tileset\n const transformLocal = Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);\n const ellipsoid = mapProjection.ellipsoid;\n const boundingVolume = tileBoundingVolume.boundingVolume;\n const centerLocal = Matrix4.multiplyByPoint(\n transformLocal,\n boundingVolume.center,\n scratchCenter\n );\n if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {\n // The tileset is defined in WGS84. Approximate the minimum and maximum height.\n const centerCartographic = Cartographic.fromCartesian(\n centerLocal,\n ellipsoid,\n scratchCartographic\n );\n up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);\n direction = camera.directionWC;\n height = camera.positionCartographic.height;\n minimumHeight = 0.0;\n maximumHeight = centerCartographic.height * 2.0;\n } else {\n // The tileset is defined in local coordinates (z-up)\n const positionLocal = Matrix4.multiplyByPoint(\n transformLocal,\n camera.positionWC,\n scratchPosition\n );\n up = Cartesian3.UNIT_Z;\n direction = Matrix4.multiplyByPointAsVector(\n transformLocal,\n camera.directionWC,\n scratchDirection\n );\n direction = Cartesian3.normalize(direction, direction);\n height = positionLocal.z;\n if (tileBoundingVolume instanceof TileOrientedBoundingBox) {\n // Assuming z-up, the last component stores the half-height of the box\n const boxHeight = root._header.boundingVolume.box[11];\n minimumHeight = centerLocal.z - boxHeight;\n maximumHeight = centerLocal.z + boxHeight;\n } else if (tileBoundingVolume instanceof TileBoundingSphere) {\n const radius = boundingVolume.radius;\n minimumHeight = centerLocal.z - radius;\n maximumHeight = centerLocal.z + radius;\n }\n }\n }\n\n // The range where the density starts to lessen. Start at the quarter height of the tileset.\n const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;\n const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;\n const heightFar = maximumHeight;\n\n const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);\n\n // Increase density as the camera tilts towards the horizon\n const dot = Math.abs(Cartesian3.dot(direction, up));\n\n let horizonFactor = 1.0 - dot;\n\n // Weaken the horizon factor as the camera height increases, implying the camera is further away from the tileset.\n // The goal is to increase density for the \"street view\", not when viewing the tileset from a distance.\n horizonFactor = horizonFactor * (1.0 - t);\n\n return dynamicScreenSpaceErrorDensity * horizonFactor;\n}\n\nexport function fog(distanceToCamera, density) {\n const scalar = distanceToCamera * density;\n return 1.0 - Math.exp(-(scalar * scalar));\n}\n\nexport function getDynamicScreenSpaceError(tileset, distanceToCamera) {\n if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {\n const density = tileset.dynamicScreenSpaceErrorComputedDensity;\n const factor = tileset.dynamicScreenSpaceErrorFactor;\n // TODO: Refined screen space error that minimizes tiles in non-first-person\n const dynamicError = fog(distanceToCamera, density) * factor;\n return dynamicError;\n }\n\n return 0;\n}\n\nexport function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {\n const tileset = tile.tileset;\n const parentLodMetricValue = (tile.parent && tile.parent.lodMetricValue) || tile.lodMetricValue;\n const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;\n\n // Leaf tiles do not have any error so save the computation\n if (lodMetricValue === 0.0) {\n return 0.0;\n }\n\n // TODO: Orthographic Frustum needs special treatment?\n // this._getOrthograhicScreenSpaceError();\n\n // Avoid divide by zero when viewer is inside the tile\n const distance = Math.max(tile._distanceToCamera, 1e-7);\n const {height, sseDenominator} = frameState;\n const {viewDistanceScale} = tileset.options;\n let error = (lodMetricValue * height * (viewDistanceScale || 1.0)) / (distance * sseDenominator);\n\n error -= getDynamicScreenSpaceError(tileset, distance);\n\n return error;\n}\n"],"file":"tiles-3d-lod.js"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { Ellipsoid } from '@math.gl/geospatial';
|
|
2
|
+
import { Matrix4, Vector3 } from '@math.gl/core';
|
|
3
|
+
import { assert } from '@loaders.gl/loader-utils';
|
|
4
|
+
export function calculateTransformProps(tileHeader, tile) {
|
|
5
|
+
assert(tileHeader);
|
|
6
|
+
assert(tile);
|
|
7
|
+
const {
|
|
8
|
+
rtcCenter,
|
|
9
|
+
gltfUpAxis
|
|
10
|
+
} = tile;
|
|
11
|
+
const {
|
|
12
|
+
computedTransform,
|
|
13
|
+
boundingVolume: {
|
|
14
|
+
center
|
|
15
|
+
}
|
|
16
|
+
} = tileHeader;
|
|
17
|
+
let modelMatrix = new Matrix4(computedTransform);
|
|
18
|
+
|
|
19
|
+
if (rtcCenter) {
|
|
20
|
+
modelMatrix.translate(rtcCenter);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
switch (gltfUpAxis) {
|
|
24
|
+
case 'Z':
|
|
25
|
+
break;
|
|
26
|
+
|
|
27
|
+
case 'Y':
|
|
28
|
+
const rotationY = new Matrix4().rotateX(Math.PI / 2);
|
|
29
|
+
modelMatrix = modelMatrix.multiplyRight(rotationY);
|
|
30
|
+
break;
|
|
31
|
+
|
|
32
|
+
case 'X':
|
|
33
|
+
const rotationX = new Matrix4().rotateY(-Math.PI / 2);
|
|
34
|
+
modelMatrix = modelMatrix.multiplyRight(rotationX);
|
|
35
|
+
break;
|
|
36
|
+
|
|
37
|
+
default:
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (tile.isQuantized) {
|
|
42
|
+
modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
const cartesianOrigin = new Vector3(center);
|
|
46
|
+
tile.cartesianModelMatrix = modelMatrix;
|
|
47
|
+
tile.cartesianOrigin = cartesianOrigin;
|
|
48
|
+
const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
|
|
49
|
+
const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
|
|
50
|
+
const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
|
|
51
|
+
tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
|
|
52
|
+
tile.cartographicOrigin = cartographicOrigin;
|
|
53
|
+
|
|
54
|
+
if (!tile.coordinateSystem) {
|
|
55
|
+
tile.modelMatrix = tile.cartographicModelMatrix;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=transform-utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/transform-utils.ts"],"names":["Ellipsoid","Matrix4","Vector3","assert","calculateTransformProps","tileHeader","tile","rtcCenter","gltfUpAxis","computedTransform","boundingVolume","center","modelMatrix","translate","rotationY","rotateX","Math","PI","multiplyRight","rotationX","rotateY","isQuantized","quantizedVolumeOffset","scale","quantizedVolumeScale","cartesianOrigin","cartesianModelMatrix","cartographicOrigin","WGS84","cartesianToCartographic","fromFixedFrameMatrix","eastNorthUpToFixedFrame","toFixedFrameMatrix","invert","cartographicModelMatrix","coordinateSystem"],"mappings":"AAAA,SAAQA,SAAR,QAAwB,qBAAxB;AACA,SAAQC,OAAR,EAAiBC,OAAjB,QAA+B,eAA/B;AACA,SAAQC,MAAR,QAAqB,0BAArB;AAEA,OAAO,SAASC,uBAAT,CAAiCC,UAAjC,EAA6CC,IAA7C,EAAmD;AACxDH,EAAAA,MAAM,CAACE,UAAD,CAAN;AACAF,EAAAA,MAAM,CAACG,IAAD,CAAN;AAEA,QAAM;AAACC,IAA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,uBAAhB,CAAwCN,eAAxC,CAA7B;AACA,QAAMO,kBAAkB,GAAGF,oBAAoB,CAACG,MAArB,EAA3B;AAEA3B,EAAAA,IAAI,CAAC4B,uBAAL,GAA+BF,kBAAkB,CAACd,aAAnB,CAAiCN,WAAjC,CAA/B;AACAN,EAAAA,IAAI,CAACqB,kBAAL,GAA0BA,kBAA1B;;AAGA,MAAI,CAACrB,IAAI,CAAC6B,gBAAV,EAA4B;AAC1B7B,IAAAA,IAAI,CAACM,WAAL,GAAmBN,IAAI,CAAC4B,uBAAxB;AACD;AACF","sourcesContent":["import {Ellipsoid} from '@math.gl/geospatial';\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {assert} from '@loaders.gl/loader-utils';\n\nexport function calculateTransformProps(tileHeader, tile) {\n assert(tileHeader);\n assert(tile);\n\n const {rtcCenter, gltfUpAxis} = tile;\n const {\n computedTransform,\n boundingVolume: {center}\n } = tileHeader;\n\n let modelMatrix = new Matrix4(computedTransform);\n\n // Translate if appropriate\n if (rtcCenter) {\n modelMatrix.translate(rtcCenter);\n }\n\n // glTF models need to be rotated from Y to Z up\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/tree/master/specification#y-up-to-z-up\n switch (gltfUpAxis) {\n case 'Z':\n break;\n case 'Y':\n const rotationY = new Matrix4().rotateX(Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationY);\n break;\n case 'X':\n const rotationX = new Matrix4().rotateY(-Math.PI / 2);\n modelMatrix = modelMatrix.multiplyRight(rotationX);\n break;\n default:\n break;\n }\n\n // Scale/offset positions if normalized integers\n if (tile.isQuantized) {\n modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);\n }\n\n // Option 1: Cartesian matrix and origin\n const cartesianOrigin = new Vector3(center);\n\n tile.cartesianModelMatrix = modelMatrix;\n tile.cartesianOrigin = cartesianOrigin;\n\n // Option 2: Cartographic matrix and origin\n const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(\n cartesianOrigin,\n new Vector3()\n );\n const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);\n const toFixedFrameMatrix = fromFixedFrameMatrix.invert();\n\n tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);\n tile.cartographicOrigin = cartographicOrigin;\n\n // Deprecated, drop\n if (!tile.coordinateSystem) {\n tile.modelMatrix = tile.cartographicModelMatrix;\n }\n}\n"],"file":"transform-utils.js"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Vector3 } from '@math.gl/core';
|
|
2
|
+
const WGS84_RADIUS_X = 6378137.0;
|
|
3
|
+
const WGS84_RADIUS_Y = 6378137.0;
|
|
4
|
+
const WGS84_RADIUS_Z = 6356752.3142451793;
|
|
5
|
+
const scratchVector = new Vector3();
|
|
6
|
+
export function getZoomFromBoundingVolume(boundingVolume) {
|
|
7
|
+
const {
|
|
8
|
+
halfAxes,
|
|
9
|
+
radius,
|
|
10
|
+
width,
|
|
11
|
+
height
|
|
12
|
+
} = boundingVolume;
|
|
13
|
+
|
|
14
|
+
if (halfAxes) {
|
|
15
|
+
const obbSize = getObbSize(halfAxes);
|
|
16
|
+
return Math.log2(WGS84_RADIUS_Z / obbSize);
|
|
17
|
+
} else if (radius) {
|
|
18
|
+
return Math.log2(WGS84_RADIUS_Z / radius);
|
|
19
|
+
} else if (height && width) {
|
|
20
|
+
const zoomX = Math.log2(WGS84_RADIUS_X / width);
|
|
21
|
+
const zoomY = Math.log2(WGS84_RADIUS_Y / height);
|
|
22
|
+
return (zoomX + zoomY) / 2;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function getObbSize(halfAxes) {
|
|
29
|
+
halfAxes.getColumn(0, scratchVector);
|
|
30
|
+
const axeY = halfAxes.getColumn(1);
|
|
31
|
+
const axeZ = halfAxes.getColumn(2);
|
|
32
|
+
const farthestVertex = scratchVector.add(axeY).add(axeZ);
|
|
33
|
+
const size = farthestVertex.len();
|
|
34
|
+
return size;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=zoom.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/zoom.ts"],"names":["Vector3","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","scratchVector","getZoomFromBoundingVolume","boundingVolume","halfAxes","radius","width","height","obbSize","getObbSize","Math","log2","zoomX","zoomY","getColumn","axeY","axeZ","farthestVertex","add","size","len"],"mappings":"AAAA,SAAQA,OAAR,QAAsB,eAAtB;AAEA,MAAMC,cAAc,GAAG,SAAvB;AACA,MAAMC,cAAc,GAAG,SAAvB;AACA,MAAMC,cAAc,GAAG,kBAAvB;AAEA,MAAMC,aAAa,GAAG,IAAIJ,OAAJ,EAAtB;AAOA,OAAO,SAASK,yBAAT,CAAmCC,cAAnC,EAAmD;AACxD,QAAM;AAACC,IAAAA,QAAD;AAAWC,IAAAA,MAAX;AAAmBC,IAAAA,KAAnB;AAA0BC,IAAAA;AAA1B,MAAoCJ,cAA1C;;AAEA,MAAIC,QAAJ,EAAc;AAEZ,UAAMI,OAAO,GAAGC,UAAU,CAACL,QAAD,CAA1B;AAEA,WAAOM,IAAI,CAACC,IAAL,CAAUX,cAAc,GAAGQ,OAA3B,CAAP;AACD,GALD,MAKO,IAAIH,MAAJ,EAAY;AAEjB,WAAOK,IAAI,CAACC,IAAL,CAAUX,cAAc,GAAGK,MAA3B,CAAP;AACD,GAHM,MAGA,IAAIE,MAAM,IAAID,KAAd,EAAqB;AAE1B,UAAMM,KAAK,GAAGF,IAAI,CAACC,IAAL,CAAUb,cAAc,GAAGQ,KAA3B,CAAd;AACA,UAAMO,KAAK,GAAGH,IAAI,CAACC,IAAL,CAAUZ,cAAc,GAAGQ,MAA3B,CAAd;AAEA,WAAO,CAACK,KAAK,GAAGC,KAAT,IAAkB,CAAzB;AACD;;AAED,SAAO,CAAP;AACD;;AAED,SAASJ,UAAT,CAAoBL,QAApB,EAA8B;AAC5BA,EAAAA,QAAQ,CAACU,SAAT,CAAmB,CAAnB,EAAsBb,aAAtB;AACA,QAAMc,IAAI,GAAGX,QAAQ,CAACU,SAAT,CAAmB,CAAnB,CAAb;AACA,QAAME,IAAI,GAAGZ,QAAQ,CAACU,SAAT,CAAmB,CAAnB,CAAb;AACA,QAAMG,cAAc,GAAGhB,aAAa,CAACiB,GAAd,CAAkBH,IAAlB,EAAwBG,GAAxB,CAA4BF,IAA5B,CAAvB;AACA,QAAMG,IAAI,GAAGF,cAAc,CAACG,GAAf,EAAb;AACA,SAAOD,IAAP;AACD","sourcesContent":["import {Vector3} from '@math.gl/core';\n\nconst WGS84_RADIUS_X = 6378137.0;\nconst WGS84_RADIUS_Y = 6378137.0;\nconst WGS84_RADIUS_Z = 6356752.3142451793;\n\nconst scratchVector = new Vector3();\n\n/**\n * Calculate appropriate zoom value for a particular boundingVolume\n * @param {BoundingSphere, OrientedBoundingBox} boundingVolume - the instance of bounding volume\n * @returns {number} - zoom value\n */\nexport function getZoomFromBoundingVolume(boundingVolume) {\n const {halfAxes, radius, width, height} = boundingVolume;\n\n if (halfAxes) {\n // OrientedBoundingBox\n const obbSize = getObbSize(halfAxes);\n // Use WGS84_RADIUS_Z to allign with BoundingSphere algorithm\n return Math.log2(WGS84_RADIUS_Z / obbSize);\n } else if (radius) {\n // BoundingSphere\n return Math.log2(WGS84_RADIUS_Z / radius);\n } else if (height && width) {\n // BoundingRectangle\n const zoomX = Math.log2(WGS84_RADIUS_X / width);\n const zoomY = Math.log2(WGS84_RADIUS_Y / height);\n\n return (zoomX + zoomY) / 2;\n }\n\n return 1;\n}\n\nfunction getObbSize(halfAxes) {\n halfAxes.getColumn(0, scratchVector);\n const axeY = halfAxes.getColumn(1);\n const axeZ = halfAxes.getColumn(2);\n const farthestVertex = scratchVector.add(axeY).add(axeZ);\n const size = farthestVertex.len();\n return size;\n}\n"],"file":"zoom.js"}
|