@loaders.gl/tiles 3.1.0-alpha.4 → 3.1.0-beta.3
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 +8136 -0
- package/dist/constants.d.ts +32 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +35 -0
- package/dist/es5/bundle.js +1 -1
- package/dist/es5/bundle.js.map +1 -1
- package/dist/es5/constants.js +6 -6
- package/dist/es5/constants.js.map +1 -1
- package/dist/es5/index.js +20 -12
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/tileset/helpers/bounding-volume.js +25 -37
- package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -1
- package/dist/es5/tileset/helpers/frame-state.js +29 -25
- package/dist/es5/tileset/helpers/frame-state.js.map +1 -1
- package/dist/es5/tileset/helpers/i3s-lod.js +57 -106
- package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
- package/dist/es5/tileset/helpers/tiles-3d-lod.js +51 -47
- package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -1
- package/dist/es5/tileset/helpers/transform-utils.js +21 -12
- package/dist/es5/tileset/helpers/transform-utils.js.map +1 -1
- package/dist/es5/tileset/helpers/zoom.js +17 -15
- package/dist/es5/tileset/helpers/zoom.js.map +1 -1
- package/dist/es5/tileset/tile-3d.js +328 -421
- package/dist/es5/tileset/tile-3d.js.map +1 -1
- package/dist/es5/tileset/tileset-3d.js +381 -563
- package/dist/es5/tileset/tileset-3d.js.map +1 -1
- package/dist/es5/tileset/tileset-cache.js +50 -63
- package/dist/es5/tileset/tileset-cache.js.map +1 -1
- package/dist/es5/tileset/traversers/i3s-tile-manager.js +32 -44
- package/dist/es5/tileset/traversers/i3s-tile-manager.js.map +1 -1
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js +53 -143
- package/dist/es5/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
- package/dist/es5/tileset/traversers/tileset-3d-traverser.js +34 -62
- package/dist/es5/tileset/traversers/tileset-3d-traverser.js.map +1 -1
- package/dist/es5/tileset/traversers/tileset-traverser.js +209 -282
- package/dist/es5/tileset/traversers/tileset-traverser.js.map +1 -1
- package/dist/es5/utils/doubly-linked-list-node.js +12 -7
- package/dist/es5/utils/doubly-linked-list-node.js.map +1 -1
- package/dist/es5/utils/doubly-linked-list.js +68 -78
- package/dist/es5/utils/doubly-linked-list.js.map +1 -1
- package/dist/es5/utils/managed-array.js +90 -106
- package/dist/es5/utils/managed-array.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/tileset/helpers/i3s-lod.js +45 -86
- package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -1
- package/dist/esm/tileset/helpers/transform-utils.js +4 -1
- package/dist/esm/tileset/helpers/transform-utils.js.map +1 -1
- package/dist/esm/tileset/tile-3d.js +3 -3
- package/dist/esm/tileset/tile-3d.js.map +1 -1
- package/dist/esm/tileset/tileset-3d.js +5 -5
- package/dist/esm/tileset/tileset-3d.js.map +1 -1
- package/dist/esm/tileset/tileset-cache.js.map +1 -1
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js +4 -4
- package/dist/esm/tileset/traversers/i3s-tileset-traverser.js.map +1 -1
- package/dist/esm/utils/doubly-linked-list-node.js +7 -0
- package/dist/esm/utils/doubly-linked-list-node.js.map +1 -1
- package/dist/esm/utils/doubly-linked-list.js +6 -3
- package/dist/esm/utils/doubly-linked-list.js.map +1 -1
- package/dist/esm/utils/managed-array.js +7 -1
- package/dist/esm/utils/managed-array.js.map +1 -1
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- 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 +9 -0
- 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 +177 -0
- 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 +70 -0
- 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 +83 -0
- 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 +116 -0
- 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 +52 -0
- 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 +42 -0
- 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 +554 -0
- 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 +601 -0
- 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 +79 -0
- 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 +36 -0
- 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 +85 -0
- 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 +55 -0
- 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 +294 -0
- 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 +17 -0
- 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 +100 -0
- 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 +151 -0
- package/package.json +9 -7
- 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/dist.min.js +0 -2
- package/dist/dist.min.js.map +0 -1
|
@@ -1,60 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
|
-
exports.
|
|
9
|
-
exports.
|
|
10
|
-
|
|
11
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
6
|
+
exports.getLodStatus = getLodStatus;
|
|
7
|
+
exports.getProjectedRadius = getProjectedRadius;
|
|
12
8
|
|
|
13
9
|
var _core = require("@math.gl/core");
|
|
14
10
|
|
|
15
|
-
var
|
|
16
|
-
var qualityFactor = Math.PI / 2;
|
|
17
|
-
|
|
18
|
-
function lodJudge(tile, frameState) {
|
|
19
|
-
var viewport = frameState.viewport;
|
|
20
|
-
var metersPerPixel = viewport.metersPerPixel;
|
|
21
|
-
var mbsLat = tile.header.mbs[1];
|
|
22
|
-
var mbsLon = tile.header.mbs[0];
|
|
23
|
-
var mbsZ = tile.header.mbs[2];
|
|
24
|
-
var mbsR = tile.header.mbs[3];
|
|
25
|
-
var height = viewport.height,
|
|
26
|
-
width = viewport.width,
|
|
27
|
-
latitude = viewport.latitude,
|
|
28
|
-
longitude = viewport.longitude;
|
|
29
|
-
var viewportCenter = [longitude, latitude];
|
|
30
|
-
var mbsCenter = [mbsLon, mbsLat, mbsZ];
|
|
31
|
-
var mbsLatProjected = [longitude, mbsLat];
|
|
32
|
-
var mbsLonProjected = [mbsLon, latitude];
|
|
33
|
-
var diagonalInMeters = Math.sqrt(height * height + width * width) * metersPerPixel[0];
|
|
34
|
-
var distanceInMeters = getDistanceFromLatLon(viewportCenter, mbsCenter);
|
|
35
|
-
var visibleHeight = height * 0.5 + mbsR / WGS84_RADIUS_X;
|
|
36
|
-
var visibleWidth = width * 0.5 + mbsR / WGS84_RADIUS_X;
|
|
37
|
-
|
|
38
|
-
if (distanceInMeters > diagonalInMeters + mbsR / WGS84_RADIUS_X) {
|
|
39
|
-
return 'OUT';
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
if (getDistanceFromLatLon(viewportCenter, mbsLatProjected) > visibleHeight) {
|
|
43
|
-
return 'OUT';
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
if (getDistanceFromLatLon(viewportCenter, mbsLonProjected) > visibleWidth) {
|
|
47
|
-
return 'OUT';
|
|
48
|
-
}
|
|
11
|
+
var _geospatial = require("@math.gl/geospatial");
|
|
49
12
|
|
|
50
|
-
|
|
13
|
+
function getLodStatus(tile, frameState) {
|
|
14
|
+
if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
|
|
51
15
|
return 'DIG';
|
|
52
16
|
}
|
|
53
17
|
|
|
54
|
-
|
|
55
|
-
screenSize *= qualityFactor;
|
|
18
|
+
const screenSize = 2 * getProjectedRadius(tile, frameState);
|
|
56
19
|
|
|
57
|
-
if (screenSize <
|
|
20
|
+
if (screenSize < 2) {
|
|
58
21
|
return 'OUT';
|
|
59
22
|
}
|
|
60
23
|
|
|
@@ -67,67 +30,55 @@ function lodJudge(tile, frameState) {
|
|
|
67
30
|
return 'OUT';
|
|
68
31
|
}
|
|
69
32
|
|
|
70
|
-
function
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
if (d <= 0.0) {
|
|
121
|
-
return 0.5 * fltMax;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
var screenSizeFactor = getTanOfHalfVFAngle(frameState) * mbsRNormalized / Math.sqrt(d) * 300;
|
|
125
|
-
return screenSizeFactor;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function getTanOfHalfVFAngle(frameState) {
|
|
129
|
-
var projectionMatrix = frameState.viewport.projectionMatrix;
|
|
130
|
-
var t = projectionMatrix[5];
|
|
131
|
-
return t;
|
|
33
|
+
function getProjectedRadius(tile, frameState) {
|
|
34
|
+
const originalViewport = frameState.viewport;
|
|
35
|
+
const ViewportClass = originalViewport.constructor;
|
|
36
|
+
const {
|
|
37
|
+
longitude,
|
|
38
|
+
latitude,
|
|
39
|
+
height,
|
|
40
|
+
width,
|
|
41
|
+
bearing,
|
|
42
|
+
zoom
|
|
43
|
+
} = originalViewport;
|
|
44
|
+
const viewport = new ViewportClass({
|
|
45
|
+
longitude,
|
|
46
|
+
latitude,
|
|
47
|
+
height,
|
|
48
|
+
width,
|
|
49
|
+
bearing,
|
|
50
|
+
zoom,
|
|
51
|
+
pitch: 0
|
|
52
|
+
});
|
|
53
|
+
const mbsLat = tile.header.mbs[1];
|
|
54
|
+
const mbsLon = tile.header.mbs[0];
|
|
55
|
+
const mbsZ = tile.header.mbs[2];
|
|
56
|
+
const mbsR = tile.header.mbs[3];
|
|
57
|
+
const mbsCenterCartesian = [...tile.boundingVolume.center];
|
|
58
|
+
const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
|
|
59
|
+
|
|
60
|
+
const cameraPositionCartesian = _geospatial.Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new _core.Vector3());
|
|
61
|
+
|
|
62
|
+
const toEye = new _core.Vector3(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
|
|
63
|
+
const enuToCartesianMatrix = new _core.Matrix4();
|
|
64
|
+
|
|
65
|
+
_geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
|
|
66
|
+
|
|
67
|
+
const cartesianToEnuMatrix = new _core.Matrix4(enuToCartesianMatrix).invert();
|
|
68
|
+
const cameraPositionEnu = new _core.Vector3(cameraPositionCartesian).transform(cartesianToEnuMatrix);
|
|
69
|
+
const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
|
|
70
|
+
const extraZ = projection * projection / cameraPositionEnu[2];
|
|
71
|
+
const extraVertexEnu = new _core.Vector3([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
|
|
72
|
+
const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
|
|
73
|
+
const extraVectorCartesian = new _core.Vector3(extraVertexCartesian).subtract(mbsCenterCartesian).normalize();
|
|
74
|
+
const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
|
|
75
|
+
const sphereMbsBorderVertexCartesian = new _core.Vector3(mbsCenterCartesian).add(radiusVector);
|
|
76
|
+
|
|
77
|
+
const sphereMbsBorderVertexCartographic = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
|
|
78
|
+
|
|
79
|
+
const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
|
|
80
|
+
const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
|
|
81
|
+
const projectedRadius = new _core.Vector3(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
|
|
82
|
+
return projectedRadius;
|
|
132
83
|
}
|
|
133
84
|
//# sourceMappingURL=i3s-lod.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"names":["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","Ellipsoid","WGS84","cartographicToCartesian","Vector3","toEye","subtract","normalize","enuToCartesianMatrix","Matrix4","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;;AACA;;AAaO,SAASA,YAAT,CAAsBC,IAAtB,EAAoCC,UAApC,EAAoF;AACzF,MAAID,IAAI,CAACE,cAAL,KAAwB,CAAxB,IAA6BC,KAAK,CAACH,IAAI,CAACE,cAAN,CAAtC,EAA6D;AAC3D,WAAO,KAAP;AACD;;AACD,QAAME,UAAU,GAAG,IAAIC,kBAAkB,CAACL,IAAD,EAAOC,UAAP,CAAzC;;AACA,MAAIG,UAAU,GAAG,CAAjB,EAAoB;AAClB,WAAO,KAAP;AACD;;AACD,MAAI,CAACJ,IAAI,CAACM,MAAL,CAAYC,QAAb,IAAyBH,UAAU,IAAIJ,IAAI,CAACE,cAAhD,EAAgE;AAC9D,WAAO,MAAP;AACD,GAFD,MAEO,IAAIF,IAAI,CAACM,MAAL,CAAYC,QAAhB,EAA0B;AAC/B,WAAO,KAAP;AACD;;AACD,SAAO,KAAP;AACD;;AASM,SAASF,kBAAT,CAA4BL,IAA5B,EAA0CC,UAA1C,EAA0E;AAC/E,QAAMO,gBAAgB,GAAGP,UAAU,CAACQ,QAApC;AACA,QAAMC,aAAa,GAAGF,gBAAgB,CAACG,WAAvC;AACA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,MAAtB;AAA8BC,IAAAA,KAA9B;AAAqCC,IAAAA,OAArC;AAA8CC,IAAAA;AAA9C,MAAsDT,gBAA5D;AAEA,QAAMC,QAAQ,GAAG,IAAIC,aAAJ,CAAkB;AAACE,IAAAA,SAAD;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,MAAtB;AAA8BC,IAAAA,KAA9B;AAAq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B,CAAC,CAAD,CAAjB,GAAuBA,iBAAiB,CAAC,CAAD,CADrE,CAAnB;AAGA,QAAMK,MAAM,GAAIH,UAAU,GAAGA,UAAd,GAA4BF,iBAAiB,CAAC,CAAD,CAA5D;AACA,QAAMM,cAAc,GAAG,IAAIf,aAAJ,CAAY,CAACS,iBAAiB,CAAC,CAAD,CAAlB,EAAuBA,iBAAiB,CAAC,CAAD,CAAxC,EAA6CK,MAA7C,CAAZ,CAAvB;AACA,QAAME,oBAAoB,GAAGD,cAAc,CAACL,SAAf,CAAyBN,oBAAzB,CAA7B;AACA,QAAMa,oBAAoB,GAAG,IAAIjB,aAAJ,CAAYgB,oBAAZ,EAC1Bd,QAD0B,CACjBZ,kBADiB,EAE1Ba,SAF0B,EAA7B;AAIA,QAAMe,YAAY,GAAGjB,KAAK,CAACkB,KAAN,CAAYF,oBAAZ,EAAkCd,SAAlC,GAA8CiB,KAA9C,CAAoD/B,IAApD,CAArB;AACA,QAAMgC,8BAA8B,GAAG,IAAIrB,aAAJ,CAAYV,kBAAZ,EAAgCgC,GAAhC,CAAoCJ,YAApC,CAAvC;;AACA,QAAMK,iCAAiC,GAAG1B,sBAAUC,KAAV,CAAgB0B,uBAAhB,CACxCH,8BADwC,CAA1C;;AAMA,QAAMI,eAAe,GAAGlD,QAAQ,CAACmD,OAAT,CAAiB,CAACvC,MAAD,EAASF,MAAT,EAAiBG,IAAjB,CAAjB,CAAxB;AACA,QAAMuC,wBAAwB,GAAGpD,QAAQ,CAACmD,OAAT,CAAiBH,iCAAjB,CAAjC;AACA,QAAMK,eAAe,GAAG,IAAI5B,aAAJ,CAAYyB,eAAZ,EACrBvB,QADqB,CACZyB,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"}
|
|
@@ -10,27 +10,27 @@ exports.getTiles3DScreenSpaceError = getTiles3DScreenSpaceError;
|
|
|
10
10
|
|
|
11
11
|
var _core = require("@math.gl/core");
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
function calculateDynamicScreenSpaceError(root,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
13
|
+
const scratchPositionNormal = new _core.Vector3();
|
|
14
|
+
const scratchCartographic = new _core.Vector3();
|
|
15
|
+
const scratchMatrix = new _core.Matrix4();
|
|
16
|
+
const scratchCenter = new _core.Vector3();
|
|
17
|
+
const scratchPosition = new _core.Vector3();
|
|
18
|
+
const scratchDirection = new _core.Vector3();
|
|
19
|
+
|
|
20
|
+
function calculateDynamicScreenSpaceError(root, {
|
|
21
|
+
camera,
|
|
22
|
+
mapProjection
|
|
23
|
+
}, options = {}) {
|
|
24
|
+
const {
|
|
25
|
+
dynamicScreenSpaceErrorHeightFalloff = 0.25,
|
|
26
|
+
dynamicScreenSpaceErrorDensity = 0.00278
|
|
27
|
+
} = options;
|
|
28
|
+
let up;
|
|
29
|
+
let direction;
|
|
30
|
+
let height;
|
|
31
|
+
let minimumHeight;
|
|
32
|
+
let maximumHeight;
|
|
33
|
+
const tileBoundingVolume = root.contentBoundingVolume;
|
|
34
34
|
|
|
35
35
|
if (tileBoundingVolume instanceof TileBoundingRegion) {
|
|
36
36
|
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
@@ -39,22 +39,22 @@ function calculateDynamicScreenSpaceError(root, _ref) {
|
|
|
39
39
|
minimumHeight = tileBoundingVolume.minimumHeight;
|
|
40
40
|
maximumHeight = tileBoundingVolume.maximumHeight;
|
|
41
41
|
} else {
|
|
42
|
-
|
|
42
|
+
const transformLocal = _core.Matrix4.inverseTransformation(root.computedTransform, scratchMatrix);
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
const ellipsoid = mapProjection.ellipsoid;
|
|
45
|
+
const boundingVolume = tileBoundingVolume.boundingVolume;
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
const centerLocal = _core.Matrix4.multiplyByPoint(transformLocal, boundingVolume.center, scratchCenter);
|
|
48
48
|
|
|
49
49
|
if (Cartesian3.magnitude(centerLocal) > ellipsoid.minimumRadius) {
|
|
50
|
-
|
|
50
|
+
const centerCartographic = Cartographic.fromCartesian(centerLocal, ellipsoid, scratchCartographic);
|
|
51
51
|
up = Cartesian3.normalize(camera.positionWC, scratchPositionNormal);
|
|
52
52
|
direction = camera.directionWC;
|
|
53
53
|
height = camera.positionCartographic.height;
|
|
54
54
|
minimumHeight = 0.0;
|
|
55
55
|
maximumHeight = centerCartographic.height * 2.0;
|
|
56
56
|
} else {
|
|
57
|
-
|
|
57
|
+
const positionLocal = _core.Matrix4.multiplyByPoint(transformLocal, camera.positionWC, scratchPosition);
|
|
58
58
|
|
|
59
59
|
up = Cartesian3.UNIT_Z;
|
|
60
60
|
direction = _core.Matrix4.multiplyByPointAsVector(transformLocal, camera.directionWC, scratchDirection);
|
|
@@ -62,37 +62,37 @@ function calculateDynamicScreenSpaceError(root, _ref) {
|
|
|
62
62
|
height = positionLocal.z;
|
|
63
63
|
|
|
64
64
|
if (tileBoundingVolume instanceof TileOrientedBoundingBox) {
|
|
65
|
-
|
|
65
|
+
const boxHeight = root._header.boundingVolume.box[11];
|
|
66
66
|
minimumHeight = centerLocal.z - boxHeight;
|
|
67
67
|
maximumHeight = centerLocal.z + boxHeight;
|
|
68
68
|
} else if (tileBoundingVolume instanceof TileBoundingSphere) {
|
|
69
|
-
|
|
69
|
+
const radius = boundingVolume.radius;
|
|
70
70
|
minimumHeight = centerLocal.z - radius;
|
|
71
71
|
maximumHeight = centerLocal.z + radius;
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
76
|
+
const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
|
|
77
|
+
const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
|
|
78
|
+
const heightFar = maximumHeight;
|
|
79
|
+
const t = (0, _core.clamp)((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
|
|
80
|
+
const dot = Math.abs(Cartesian3.dot(direction, up));
|
|
81
|
+
let horizonFactor = 1.0 - dot;
|
|
82
82
|
horizonFactor = horizonFactor * (1.0 - t);
|
|
83
83
|
return dynamicScreenSpaceErrorDensity * horizonFactor;
|
|
84
84
|
}
|
|
85
85
|
|
|
86
86
|
function fog(distanceToCamera, density) {
|
|
87
|
-
|
|
87
|
+
const scalar = distanceToCamera * density;
|
|
88
88
|
return 1.0 - Math.exp(-(scalar * scalar));
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
function getDynamicScreenSpaceError(tileset, distanceToCamera) {
|
|
92
92
|
if (tileset.dynamicScreenSpaceError && tileset.dynamicScreenSpaceErrorComputedDensity) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
93
|
+
const density = tileset.dynamicScreenSpaceErrorComputedDensity;
|
|
94
|
+
const factor = tileset.dynamicScreenSpaceErrorFactor;
|
|
95
|
+
const dynamicError = fog(distanceToCamera, density) * factor;
|
|
96
96
|
return dynamicError;
|
|
97
97
|
}
|
|
98
98
|
|
|
@@ -100,19 +100,23 @@ function getDynamicScreenSpaceError(tileset, distanceToCamera) {
|
|
|
100
100
|
}
|
|
101
101
|
|
|
102
102
|
function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
103
|
+
const tileset = tile.tileset;
|
|
104
|
+
const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
|
|
105
|
+
const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
|
|
106
106
|
|
|
107
107
|
if (lodMetricValue === 0.0) {
|
|
108
108
|
return 0.0;
|
|
109
109
|
}
|
|
110
110
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
111
|
+
const distance = Math.max(tile._distanceToCamera, 1e-7);
|
|
112
|
+
const {
|
|
113
|
+
height,
|
|
114
|
+
sseDenominator
|
|
115
|
+
} = frameState;
|
|
116
|
+
const {
|
|
117
|
+
viewDistanceScale
|
|
118
|
+
} = tileset.options;
|
|
119
|
+
let error = lodMetricValue * height * (viewDistanceScale || 1.0) / (distance * sseDenominator);
|
|
116
120
|
error -= getDynamicScreenSpaceError(tileset, distance);
|
|
117
121
|
return error;
|
|
118
122
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":["scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","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;;AAEA,IAAMA,qBAAqB,GAAG,IAAIC,aAAJ,EAA9B;AACA,IAAMC,mBAAmB,GAAG,IAAID,aAAJ,EAA5B;AACA,IAAME,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAIJ,aAAJ,EAAtB;AACA,IAAMK,eAAe,GAAG,IAAIL,aAAJ,EAAxB;AACA,IAAMM,gBAAgB,GAAG,IAAIN,aAAJ,EAAzB;;AAGO,SAASO,gCAAT,CAA0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ArB;AACA,MAAMU,oBAAoB,GAAIH,IAAI,CAACI,MAAL,IAAeJ,IAAI,CAACI,MAAL,CAAYC,cAA5B,IAA+CL,IAAI,CAACK,cAAjF;AACA,MAAMA,cAAc,GAAGH,kBAAkB,GAAGC,oBAAH,GAA0BH,IAAI,CAACK,cAAxE;;AAGA,MAAIA,cAAc,KAAK,GAAvB,EAA4B;AAC1B,WAAO,GAAP;AACD;;AAMD,MAAMC,QAAQ,GAAGtB,IAAI,CAACuB,GAAL,CAASP,IAAI,CAACQ,iBAAd,EAAiC,IAAjC,CAAjB;AACA,MAAO/D,MAAP,GAAiCwD,UAAjC,CAAOxD,MAAP;AAAA,MAAegE,cAAf,GAAiCR,UAAjC,CAAeQ,cAAf;AACA,MAAOC,iBAAP,GAA4BjB,OAAO,CAACrD,OAApC,CAAOsE,iBAAP;AACA,MAAIC,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"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"names":["scratchPositionNormal","Vector3","scratchCartographic","scratchMatrix","Matrix4","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;;AAEA,MAAMA,qBAAqB,GAAG,IAAIC,aAAJ,EAA9B;AACA,MAAMC,mBAAmB,GAAG,IAAID,aAAJ,EAA5B;AACA,MAAME,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,MAAMC,aAAa,GAAG,IAAIJ,aAAJ,EAAtB;AACA,MAAMK,eAAe,GAAG,IAAIL,aAAJ,EAAxB;AACA,MAAMM,gBAAgB,GAAG,IAAIN,aAAJ,EAAzB;;AAGO,SAASO,gCAAT,CAA0CC,IAA1C,EAAgD;AAACC,EAAAA,MAAD;AAASC,EAAAA;AAAT,CAAhD,EAAyEC,OAAO,GAAG,EAAnF,EAAuF;AAC5F,QAAM;AAACC,IAAAA,oCAAoC,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AIA,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"}
|
|
@@ -14,11 +14,17 @@ var _loaderUtils = require("@loaders.gl/loader-utils");
|
|
|
14
14
|
function calculateTransformProps(tileHeader, tile) {
|
|
15
15
|
(0, _loaderUtils.assert)(tileHeader);
|
|
16
16
|
(0, _loaderUtils.assert)(tile);
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
const {
|
|
18
|
+
rtcCenter,
|
|
19
|
+
gltfUpAxis
|
|
20
|
+
} = tile;
|
|
21
|
+
const {
|
|
22
|
+
computedTransform,
|
|
23
|
+
boundingVolume: {
|
|
24
|
+
center
|
|
25
|
+
}
|
|
26
|
+
} = tileHeader;
|
|
27
|
+
let modelMatrix = new _core.Matrix4(computedTransform);
|
|
22
28
|
|
|
23
29
|
if (rtcCenter) {
|
|
24
30
|
modelMatrix.translate(rtcCenter);
|
|
@@ -29,12 +35,12 @@ function calculateTransformProps(tileHeader, tile) {
|
|
|
29
35
|
break;
|
|
30
36
|
|
|
31
37
|
case 'Y':
|
|
32
|
-
|
|
38
|
+
const rotationY = new _core.Matrix4().rotateX(Math.PI / 2);
|
|
33
39
|
modelMatrix = modelMatrix.multiplyRight(rotationY);
|
|
34
40
|
break;
|
|
35
41
|
|
|
36
42
|
case 'X':
|
|
37
|
-
|
|
43
|
+
const rotationX = new _core.Matrix4().rotateY(-Math.PI / 2);
|
|
38
44
|
modelMatrix = modelMatrix.multiplyRight(rotationX);
|
|
39
45
|
break;
|
|
40
46
|
|
|
@@ -46,17 +52,20 @@ function calculateTransformProps(tileHeader, tile) {
|
|
|
46
52
|
modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
|
|
47
53
|
}
|
|
48
54
|
|
|
49
|
-
|
|
55
|
+
const cartesianOrigin = new _core.Vector3(center);
|
|
50
56
|
tile.cartesianModelMatrix = modelMatrix;
|
|
51
57
|
tile.cartesianOrigin = cartesianOrigin;
|
|
52
58
|
|
|
53
|
-
|
|
59
|
+
const cartographicOrigin = _geospatial.Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new _core.Vector3());
|
|
54
60
|
|
|
55
|
-
|
|
61
|
+
const fromFixedFrameMatrix = _geospatial.Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
|
|
56
62
|
|
|
57
|
-
|
|
63
|
+
const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
|
|
58
64
|
tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
|
|
59
65
|
tile.cartographicOrigin = cartographicOrigin;
|
|
60
|
-
|
|
66
|
+
|
|
67
|
+
if (!tile.coordinateSystem) {
|
|
68
|
+
tile.modelMatrix = tile.cartographicModelMatrix;
|
|
69
|
+
}
|
|
61
70
|
}
|
|
62
71
|
//# sourceMappingURL=transform-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/tileset/helpers/transform-utils.ts"],"names":["calculateTransformProps","tileHeader","tile","rtcCenter","gltfUpAxis","computedTransform","
|
|
1
|
+
{"version":3,"sources":["../../../../src/tileset/helpers/transform-utils.ts"],"names":["calculateTransformProps","tileHeader","tile","rtcCenter","gltfUpAxis","computedTransform","boundingVolume","center","modelMatrix","Matrix4","translate","rotationY","rotateX","Math","PI","multiplyRight","rotationX","rotateY","isQuantized","quantizedVolumeOffset","scale","quantizedVolumeScale","cartesianOrigin","Vector3","cartesianModelMatrix","cartographicOrigin","Ellipsoid","WGS84","cartesianToCartographic","fromFixedFrameMatrix","eastNorthUpToFixedFrame","toFixedFrameMatrix","invert","cartographicModelMatrix","coordinateSystem"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AAEO,SAASA,uBAAT,CAAiCC,UAAjC,EAA6CC,IAA7C,EAAmD;AACxD,2BAAOD,UAAP;AACA,2BAAOC,IAAP;AAEA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA;AAAZ,MAA0BF,IAAhC;AACA,QAAM;AACJG,IAAAA,iBADI;AAEJC,IAAAA,cAAc,EAAE;AAACC,MAAAA;AAAD;AAFZ,MAGFN,UAHJ;AAKA,MAAIO,WAAW,GAAG,IAAIC,aAAJ,CAAYJ,iBAAZ,CAAlB;;AAGA,MAAIF,SAAJ,EAAe;AACbK,IAAAA,WAAW,CAACE,SAAZ,CAAsBP,SAAtB;AACD;;AAID,UAAQC,UAAR;AAC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I,CAAC+B,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"}
|
|
@@ -7,25 +7,27 @@ exports.getZoomFromBoundingVolume = getZoomFromBoundingVolume;
|
|
|
7
7
|
|
|
8
8
|
var _core = require("@math.gl/core");
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
const WGS84_RADIUS_X = 6378137.0;
|
|
11
|
+
const WGS84_RADIUS_Y = 6378137.0;
|
|
12
|
+
const WGS84_RADIUS_Z = 6356752.3142451793;
|
|
13
|
+
const scratchVector = new _core.Vector3();
|
|
14
14
|
|
|
15
15
|
function getZoomFromBoundingVolume(boundingVolume) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
const {
|
|
17
|
+
halfAxes,
|
|
18
|
+
radius,
|
|
19
|
+
width,
|
|
20
|
+
height
|
|
21
|
+
} = boundingVolume;
|
|
20
22
|
|
|
21
23
|
if (halfAxes) {
|
|
22
|
-
|
|
24
|
+
const obbSize = getObbSize(halfAxes);
|
|
23
25
|
return Math.log2(WGS84_RADIUS_Z / obbSize);
|
|
24
26
|
} else if (radius) {
|
|
25
27
|
return Math.log2(WGS84_RADIUS_Z / radius);
|
|
26
28
|
} else if (height && width) {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const zoomX = Math.log2(WGS84_RADIUS_X / width);
|
|
30
|
+
const zoomY = Math.log2(WGS84_RADIUS_Y / height);
|
|
29
31
|
return (zoomX + zoomY) / 2;
|
|
30
32
|
}
|
|
31
33
|
|
|
@@ -34,10 +36,10 @@ function getZoomFromBoundingVolume(boundingVolume) {
|
|
|
34
36
|
|
|
35
37
|
function getObbSize(halfAxes) {
|
|
36
38
|
halfAxes.getColumn(0, scratchVector);
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
const axeY = halfAxes.getColumn(1);
|
|
40
|
+
const axeZ = halfAxes.getColumn(2);
|
|
41
|
+
const farthestVertex = scratchVector.add(axeY).add(axeZ);
|
|
42
|
+
const size = farthestVertex.len();
|
|
41
43
|
return size;
|
|
42
44
|
}
|
|
43
45
|
//# sourceMappingURL=zoom.js.map
|