@loaders.gl/tiles 3.4.0-alpha.2 → 3.4.0-alpha.4

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.
Files changed (88) hide show
  1. package/dist/dist.min.js +340 -307
  2. package/dist/es5/constants.js +0 -2
  3. package/dist/es5/constants.js.map +1 -1
  4. package/dist/es5/index.js.map +1 -1
  5. package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -2
  6. package/dist/es5/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -1
  7. package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js +3 -8
  8. package/dist/es5/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -1
  9. package/dist/es5/tileset/format-i3s/i3s-tile-manager.js +4 -14
  10. package/dist/es5/tileset/format-i3s/i3s-tile-manager.js.map +1 -1
  11. package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js +19 -25
  12. package/dist/es5/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -1
  13. package/dist/es5/tileset/helpers/3d-tiles-options.js.map +1 -1
  14. package/dist/es5/tileset/helpers/bounding-volume.js +87 -6
  15. package/dist/es5/tileset/helpers/bounding-volume.js.map +1 -1
  16. package/dist/es5/tileset/helpers/frame-state.js +4 -14
  17. package/dist/es5/tileset/helpers/frame-state.js.map +1 -1
  18. package/dist/es5/tileset/helpers/i3s-lod.js +0 -5
  19. package/dist/es5/tileset/helpers/i3s-lod.js.map +1 -1
  20. package/dist/es5/tileset/helpers/tiles-3d-lod.js +0 -7
  21. package/dist/es5/tileset/helpers/tiles-3d-lod.js.map +1 -1
  22. package/dist/es5/tileset/helpers/transform-utils.js +0 -7
  23. package/dist/es5/tileset/helpers/transform-utils.js.map +1 -1
  24. package/dist/es5/tileset/helpers/zoom.js +0 -4
  25. package/dist/es5/tileset/helpers/zoom.js.map +1 -1
  26. package/dist/es5/tileset/tile-3d.js +98 -166
  27. package/dist/es5/tileset/tile-3d.js.map +1 -1
  28. package/dist/es5/tileset/tileset-3d.js +86 -142
  29. package/dist/es5/tileset/tileset-3d.js.map +1 -1
  30. package/dist/es5/tileset/tileset-cache.js +0 -3
  31. package/dist/es5/tileset/tileset-cache.js.map +1 -1
  32. package/dist/es5/tileset/tileset-traverser.js +12 -51
  33. package/dist/es5/tileset/tileset-traverser.js.map +1 -1
  34. package/dist/es5/utils/doubly-linked-list-node.js.map +1 -1
  35. package/dist/es5/utils/doubly-linked-list.js +3 -11
  36. package/dist/es5/utils/doubly-linked-list.js.map +1 -1
  37. package/dist/es5/utils/managed-array.js +10 -30
  38. package/dist/es5/utils/managed-array.js.map +1 -1
  39. package/dist/esm/bundle.js +0 -1
  40. package/dist/esm/bundle.js.map +1 -1
  41. package/dist/esm/constants.js +0 -5
  42. package/dist/esm/constants.js.map +1 -1
  43. package/dist/esm/index.js +0 -2
  44. package/dist/esm/index.js.map +1 -1
  45. package/dist/esm/tileset/format-3d-tiles/tileset-3d-traverser.js +0 -4
  46. package/dist/esm/tileset/format-3d-tiles/tileset-3d-traverser.js.map +1 -1
  47. package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js +0 -2
  48. package/dist/esm/tileset/format-i3s/i3s-pending-tiles-register.js.map +1 -1
  49. package/dist/esm/tileset/format-i3s/i3s-tile-manager.js +0 -6
  50. package/dist/esm/tileset/format-i3s/i3s-tile-manager.js.map +1 -1
  51. package/dist/esm/tileset/format-i3s/i3s-tileset-traverser.js +0 -3
  52. package/dist/esm/tileset/format-i3s/i3s-tileset-traverser.js.map +1 -1
  53. package/dist/esm/tileset/helpers/3d-tiles-options.js.map +1 -1
  54. package/dist/esm/tileset/helpers/bounding-volume.js +81 -8
  55. package/dist/esm/tileset/helpers/bounding-volume.js.map +1 -1
  56. package/dist/esm/tileset/helpers/frame-state.js +3 -13
  57. package/dist/esm/tileset/helpers/frame-state.js.map +1 -1
  58. package/dist/esm/tileset/helpers/i3s-lod.js +0 -6
  59. package/dist/esm/tileset/helpers/i3s-lod.js.map +1 -1
  60. package/dist/esm/tileset/helpers/tiles-3d-lod.js +0 -8
  61. package/dist/esm/tileset/helpers/tiles-3d-lod.js.map +1 -1
  62. package/dist/esm/tileset/helpers/transform-utils.js +0 -8
  63. package/dist/esm/tileset/helpers/transform-utils.js.map +1 -1
  64. package/dist/esm/tileset/helpers/zoom.js +0 -5
  65. package/dist/esm/tileset/helpers/zoom.js.map +1 -1
  66. package/dist/esm/tileset/tile-3d.js +8 -52
  67. package/dist/esm/tileset/tile-3d.js.map +1 -1
  68. package/dist/esm/tileset/tileset-3d.js +0 -38
  69. package/dist/esm/tileset/tileset-3d.js.map +1 -1
  70. package/dist/esm/tileset/tileset-cache.js +0 -3
  71. package/dist/esm/tileset/tileset-cache.js.map +1 -1
  72. package/dist/esm/tileset/tileset-traverser.js +0 -27
  73. package/dist/esm/tileset/tileset-traverser.js.map +1 -1
  74. package/dist/esm/utils/doubly-linked-list-node.js +0 -1
  75. package/dist/esm/utils/doubly-linked-list-node.js.map +1 -1
  76. package/dist/esm/utils/doubly-linked-list.js +0 -7
  77. package/dist/esm/utils/doubly-linked-list.js.map +1 -1
  78. package/dist/esm/utils/managed-array.js +0 -12
  79. package/dist/esm/utils/managed-array.js.map +1 -1
  80. package/dist/tileset/helpers/bounding-volume.d.ts +10 -0
  81. package/dist/tileset/helpers/bounding-volume.d.ts.map +1 -1
  82. package/dist/tileset/helpers/bounding-volume.js +117 -1
  83. package/dist/tileset/tile-3d.d.ts +7 -0
  84. package/dist/tileset/tile-3d.d.ts.map +1 -1
  85. package/dist/tileset/tile-3d.js +10 -0
  86. package/package.json +4 -4
  87. package/src/tileset/helpers/bounding-volume.ts +136 -0
  88. package/src/tileset/tile-3d.ts +18 -1
@@ -1 +1 @@
1
- {"version":3,"file":"i3s-tileset-traverser.js","names":["load","TilesetTraverser","getLodStatus","Tile3D","I3STileManager","I3STilesetTraverser","constructor","options","_tileManager","traversalFinished","frameState","hasPendingTiles","viewport","id","_frameNumber","shouldRefine","tile","_lodJudge","updateChildTiles","children","header","childTiles","tileset","child","extendedId","childTile","find","t","request","_loadTile","cachedRequest","nodePages","nodePagesTile","formTileFromNodePages","add","_onTileLoad","update","updateTile","nodeId","loader","nodeUrl","getTileUrl","url","loadOptions","i3s","isTileHeader","push","frameNumber","Date","getTime","lastUpdate","updateDebounceTime","executeTraversal"],"sources":["../../../../src/tileset/format-i3s/i3s-tileset-traverser.ts"],"sourcesContent":["import {load} from '@loaders.gl/core';\nimport {TilesetTraverser} from '../tileset-traverser';\n\nimport {getLodStatus} from '../helpers/i3s-lod';\nimport {Tile3D} from '../tile-3d';\nimport {I3STileManager} from './i3s-tile-manager';\nimport {FrameState} from '../helpers/frame-state';\n\nexport class I3STilesetTraverser extends TilesetTraverser {\n private _tileManager: I3STileManager;\n\n constructor(options) {\n super(options);\n this._tileManager = new I3STileManager();\n }\n\n /**\n * Check if there are no penging tile header requests,\n * that means the traversal is finished and we can call\n * following-up callbacks.\n */\n traversalFinished(frameState: FrameState): boolean {\n return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);\n }\n\n shouldRefine(tile, frameState: FrameState) {\n tile._lodJudge = getLodStatus(tile, frameState);\n return tile._lodJudge === 'DIG';\n }\n\n updateChildTiles(tile, frameState: FrameState): boolean {\n const children = tile.header.children || [];\n // children which are already fetched and constructed as Tile3D instances\n const childTiles = tile.children;\n const tileset = tile.tileset;\n\n for (const child of children) {\n const extendedId = `${child.id}-${frameState.viewport.id}`;\n // if child tile is not fetched\n const childTile = childTiles && childTiles.find((t) => t.id === extendedId);\n if (!childTile) {\n let request = () => this._loadTile(child.id, tileset);\n const cachedRequest = this._tileManager.find(extendedId);\n if (!cachedRequest) {\n // eslint-disable-next-line max-depth\n if (tileset.tileset.nodePages) {\n request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);\n }\n this._tileManager.add(\n request,\n extendedId,\n (header) => this._onTileLoad(header, tile, extendedId),\n frameState\n );\n } else {\n // update frameNumber since it is still needed in current frame\n this._tileManager.update(extendedId, frameState);\n }\n } else if (childTile) {\n // if child tile is fetched and available\n this.updateTile(childTile, frameState);\n }\n }\n return false;\n }\n\n async _loadTile(nodeId, tileset) {\n const {loader} = tileset;\n const nodeUrl = tileset.getTileUrl(`${tileset.url}/nodes/${nodeId}`);\n // load metadata\n const options = {\n ...tileset.loadOptions,\n i3s: {\n ...tileset.loadOptions.i3s,\n isTileHeader: true\n }\n };\n\n return await load(nodeUrl, loader, options);\n }\n\n /**\n * The callback to init Tile3D instance after loading the tile JSON\n * @param {Object} header - the tile JSON from a dataset\n * @param {Tile3D} tile - the parent Tile3D instance\n * @param {string} extendedId - optional ID to separate copies of a tile for different viewports.\n * const extendedId = `${tile.id}-${frameState.viewport.id}`;\n * @return {void}\n */\n _onTileLoad(header, tile, extendedId) {\n // after child tile is fetched\n const childTile = new Tile3D(tile.tileset, header, tile, extendedId);\n tile.children.push(childTile);\n const frameState = this._tileManager.find(childTile.id).frameState;\n this.updateTile(childTile, frameState);\n\n // after tile fetched, resume traversal if still in current update/traversal frame\n if (\n this._frameNumber === frameState.frameNumber &&\n (this.traversalFinished(frameState) ||\n new Date().getTime() - this.lastUpdate > this.updateDebounceTime)\n ) {\n this.executeTraversal(childTile, frameState);\n }\n }\n}\n"],"mappings":";AAAA,SAAQA,IAAI,QAAO,kBAAkB;AACrC,SAAQC,gBAAgB,QAAO,sBAAsB;AAErD,SAAQC,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,MAAM,QAAO,YAAY;AACjC,SAAQC,cAAc,QAAO,oBAAoB;AAGjD,OAAO,MAAMC,mBAAmB,SAASJ,gBAAgB,CAAC;EAGxDK,WAAW,CAACC,OAAO,EAAE;IACnB,KAAK,CAACA,OAAO,CAAC;IAAC;IACf,IAAI,CAACC,YAAY,GAAG,IAAIJ,cAAc,EAAE;EAC1C;;EAOAK,iBAAiB,CAACC,UAAsB,EAAW;IACjD,OAAO,CAAC,IAAI,CAACF,YAAY,CAACG,eAAe,CAACD,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GAAG,IAAI,CAACC,UAAU,GAAG,IAAI,CAACC,kBAAkB,CAAC,EACnE;MACA,IAAI,CAACC,gBAAgB,CAAC3B,SAAS,EAAEf,UAAU,CAAC;IAC9C;EACF;AACF"}
1
+ {"version":3,"file":"i3s-tileset-traverser.js","names":["load","TilesetTraverser","getLodStatus","Tile3D","I3STileManager","I3STilesetTraverser","constructor","options","_defineProperty","_tileManager","traversalFinished","frameState","hasPendingTiles","viewport","id","_frameNumber","shouldRefine","tile","_lodJudge","updateChildTiles","children","header","childTiles","tileset","child","extendedId","concat","childTile","find","t","request","_loadTile","cachedRequest","nodePages","nodePagesTile","formTileFromNodePages","add","_onTileLoad","update","updateTile","nodeId","loader","nodeUrl","getTileUrl","url","loadOptions","i3s","isTileHeader","push","frameNumber","Date","getTime","lastUpdate","updateDebounceTime","executeTraversal"],"sources":["../../../../src/tileset/format-i3s/i3s-tileset-traverser.ts"],"sourcesContent":["import {load} from '@loaders.gl/core';\nimport {TilesetTraverser} from '../tileset-traverser';\n\nimport {getLodStatus} from '../helpers/i3s-lod';\nimport {Tile3D} from '../tile-3d';\nimport {I3STileManager} from './i3s-tile-manager';\nimport {FrameState} from '../helpers/frame-state';\n\nexport class I3STilesetTraverser extends TilesetTraverser {\n private _tileManager: I3STileManager;\n\n constructor(options) {\n super(options);\n this._tileManager = new I3STileManager();\n }\n\n /**\n * Check if there are no penging tile header requests,\n * that means the traversal is finished and we can call\n * following-up callbacks.\n */\n traversalFinished(frameState: FrameState): boolean {\n return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);\n }\n\n shouldRefine(tile, frameState: FrameState) {\n tile._lodJudge = getLodStatus(tile, frameState);\n return tile._lodJudge === 'DIG';\n }\n\n updateChildTiles(tile, frameState: FrameState): boolean {\n const children = tile.header.children || [];\n // children which are already fetched and constructed as Tile3D instances\n const childTiles = tile.children;\n const tileset = tile.tileset;\n\n for (const child of children) {\n const extendedId = `${child.id}-${frameState.viewport.id}`;\n // if child tile is not fetched\n const childTile = childTiles && childTiles.find((t) => t.id === extendedId);\n if (!childTile) {\n let request = () => this._loadTile(child.id, tileset);\n const cachedRequest = this._tileManager.find(extendedId);\n if (!cachedRequest) {\n // eslint-disable-next-line max-depth\n if (tileset.tileset.nodePages) {\n request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);\n }\n this._tileManager.add(\n request,\n extendedId,\n (header) => this._onTileLoad(header, tile, extendedId),\n frameState\n );\n } else {\n // update frameNumber since it is still needed in current frame\n this._tileManager.update(extendedId, frameState);\n }\n } else if (childTile) {\n // if child tile is fetched and available\n this.updateTile(childTile, frameState);\n }\n }\n return false;\n }\n\n async _loadTile(nodeId, tileset) {\n const {loader} = tileset;\n const nodeUrl = tileset.getTileUrl(`${tileset.url}/nodes/${nodeId}`);\n // load metadata\n const options = {\n ...tileset.loadOptions,\n i3s: {\n ...tileset.loadOptions.i3s,\n isTileHeader: true\n }\n };\n\n return await load(nodeUrl, loader, options);\n }\n\n /**\n * The callback to init Tile3D instance after loading the tile JSON\n * @param {Object} header - the tile JSON from a dataset\n * @param {Tile3D} tile - the parent Tile3D instance\n * @param {string} extendedId - optional ID to separate copies of a tile for different viewports.\n * const extendedId = `${tile.id}-${frameState.viewport.id}`;\n * @return {void}\n */\n _onTileLoad(header, tile, extendedId) {\n // after child tile is fetched\n const childTile = new Tile3D(tile.tileset, header, tile, extendedId);\n tile.children.push(childTile);\n const frameState = this._tileManager.find(childTile.id).frameState;\n this.updateTile(childTile, frameState);\n\n // after tile fetched, resume traversal if still in current update/traversal frame\n if (\n this._frameNumber === frameState.frameNumber &&\n (this.traversalFinished(frameState) ||\n new Date().getTime() - this.lastUpdate > this.updateDebounceTime)\n ) {\n this.executeTraversal(childTile, frameState);\n }\n }\n}\n"],"mappings":";AAAA,SAAQA,IAAI,QAAO,kBAAkB;AACrC,SAAQC,gBAAgB,QAAO,sBAAsB;AAErD,SAAQC,YAAY,QAAO,oBAAoB;AAC/C,SAAQC,MAAM,QAAO,YA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AAI,EAAEQ,UAAU,CAAC;IACpER,IAAI,CAACG,QAAQ,CAAC4B,IAAI,CAACrB,SAAS,CAAC;IAC7B,MAAMhB,UAAU,GAAG,IAAI,CAACF,YAAY,CAACmB,IAAI,CAACD,SAAS,CAACb,EAAE,CAAC,CAACH,UAAU;IAClE,IAAI,CAAC4B,UAAU,CAACZ,SAAS,EAAEhB,UAAU,CAAC;IAGtC,IACE,IAAI,CAACI,YAAY,KAAKJ,UAAU,CAACsC,WAAW,KAC3C,IAAI,CAACvC,iBAAiB,CAACC,UAAU,CAAC,IACjC,IAAIuC,IAAI,CAAC,CAAC,CAACC,OAAO,CAAC,CAAC,GAAG,IAAI,CAACC,UAAU,GAAG,IAAI,CAACC,kBAAkB,CAAC,EACnE;MACA,IAAI,CAACC,gBAAgB,CAAC3B,SAAS,EAAEhB,UAAU,CAAC;IAC9C;EACF;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"3d-tiles-options.js","names":["get3dTilesOptions","tileset","assetGltfUpAxis","asset","gltfUpAxis"],"sources":["../../../../src/tileset/helpers/3d-tiles-options.ts"],"sourcesContent":["export function get3dTilesOptions(tileset) {\n return {\n assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'\n };\n}\n"],"mappings":"AAAA,OAAO,SAASA,iBAAiB,CAACC,OAAO,EAAE;EACzC,OAAO;IACLC,eAAe,EAAGD,OAAO,CAACE,KAAK,IAAIF,OAAO,CAACE,KAAK,CAACC,UAAU,IAAK;EAClE,CAAC;AACH"}
1
+ {"version":3,"file":"3d-tiles-options.js","names":["get3dTilesOptions","tileset","assetGltfUpAxis","asset","gltfUpAxis"],"sources":["../../../../src/tileset/helpers/3d-tiles-options.ts"],"sourcesContent":["export function get3dTilesOptions(tileset) {\n return {\n assetGltfUpAxis: (tileset.asset && tileset.asset.gltfUpAxis) || 'Y'\n };\n}\n"],"mappings":"AAAA,OAAO,SAASA,iBAAiBA,CAACC,OAAO,EAAE;EACzC,OAAO;IACLC,eAAe,EAAGD,OAAO,CAACE,KAAK,IAAIF,OAAO,CAACE,KAAK,CAACC,UAAU,IAAK;EAClE,CAAC;AACH"}
@@ -1,21 +1,16 @@
1
-
2
-
3
1
  import { Quaternion, Vector3, Matrix3, Matrix4, degrees } from '@math.gl/core';
4
2
  import { BoundingSphere, OrientedBoundingBox } from '@math.gl/culling';
5
3
  import { Ellipsoid } from '@math.gl/geospatial';
6
4
  import { assert } from '@loaders.gl/loader-utils';
7
-
8
5
  function defined(x) {
9
6
  return x !== undefined && x !== null;
10
7
  }
11
-
8
+ const scratchPoint = new Vector3();
12
9
  const scratchScale = new Vector3();
13
10
  const scratchNorthWest = new Vector3();
14
11
  const scratchSouthEast = new Vector3();
15
-
16
12
  export function createBoundingVolume(boundingVolumeHeader, transform, result) {
17
13
  assert(boundingVolumeHeader, '3D Tile: boundingVolume must be defined');
18
-
19
14
  if (boundingVolumeHeader.box) {
20
15
  return createBox(boundingVolumeHeader.box, transform, result);
21
16
  }
@@ -25,7 +20,6 @@ export function createBoundingVolume(boundingVolumeHeader, transform, result) {
25
20
  const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
26
21
  const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyScalar(0.5);
27
22
  const radius = new Vector3().subVectors(northWest, southEast).len() / 2.0;
28
-
29
23
  return createSphere([centerInCartesian[0], centerInCartesian[1], centerInCartesian[2], radius], new Matrix4());
30
24
  }
31
25
  if (boundingVolumeHeader.sphere) {
@@ -33,6 +27,19 @@ export function createBoundingVolume(boundingVolumeHeader, transform, result) {
33
27
  }
34
28
  throw new Error('3D Tile: boundingVolume must contain a sphere, region, or box');
35
29
  }
30
+ export function getCartographicBounds(boundingVolumeHeader, boundingVolume) {
31
+ if (boundingVolumeHeader.box) {
32
+ return orientedBoundingBoxToCartographicBounds(boundingVolume);
33
+ }
34
+ if (boundingVolumeHeader.region) {
35
+ const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
36
+ return [[degrees(west), degrees(south), minHeight], [degrees(east), degrees(north), maxHeight]];
37
+ }
38
+ if (boundingVolumeHeader.sphere) {
39
+ return boundingSphereToCartographicBounds(boundingVolume);
40
+ }
41
+ throw new Error('Unkown boundingVolume type');
42
+ }
36
43
  function createBox(box, transform, result) {
37
44
  const center = new Vector3(box[0], box[1], box[2]);
38
45
  transform.transform(center, center);
@@ -65,7 +72,6 @@ function createBox(box, transform, result) {
65
72
  }
66
73
  return new OrientedBoundingBox(center, halfAxes);
67
74
  }
68
-
69
75
  function createSphere(sphere, transform, result) {
70
76
  const center = new Vector3(sphere[0], sphere[1], sphere[2]);
71
77
  transform.transform(center, center);
@@ -79,4 +85,71 @@ function createSphere(sphere, transform, result) {
79
85
  }
80
86
  return new BoundingSphere(center, radius);
81
87
  }
88
+ function orientedBoundingBoxToCartographicBounds(boundingVolume) {
89
+ const result = emptyCartographicBounds();
90
+ const {
91
+ halfAxes
92
+ } = boundingVolume;
93
+ const xAxis = new Vector3(halfAxes.getColumn(0));
94
+ const yAxis = new Vector3(halfAxes.getColumn(1));
95
+ const zAxis = new Vector3(halfAxes.getColumn(2));
96
+ for (let x = 0; x < 2; x++) {
97
+ for (let y = 0; y < 2; y++) {
98
+ for (let z = 0; z < 2; z++) {
99
+ scratchPoint.copy(boundingVolume.center);
100
+ scratchPoint.add(xAxis);
101
+ scratchPoint.add(yAxis);
102
+ scratchPoint.add(zAxis);
103
+ addToCartographicBounds(result, scratchPoint);
104
+ zAxis.negate();
105
+ }
106
+ yAxis.negate();
107
+ }
108
+ xAxis.negate();
109
+ }
110
+ return result;
111
+ }
112
+ function boundingSphereToCartographicBounds(boundingVolume) {
113
+ const result = emptyCartographicBounds();
114
+ const {
115
+ center,
116
+ radius
117
+ } = boundingVolume;
118
+ const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
119
+ let zAxis;
120
+ if (point) {
121
+ zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point);
122
+ } else {
123
+ zAxis = new Vector3(0, 0, 1);
124
+ }
125
+ let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);
126
+ if (xAxis.len() > 0) {
127
+ xAxis.normalize();
128
+ } else {
129
+ xAxis = new Vector3(0, 1, 0);
130
+ }
131
+ const yAxis = xAxis.clone().cross(zAxis);
132
+ for (const axis of [xAxis, yAxis, zAxis]) {
133
+ scratchScale.copy(axis).scale(radius);
134
+ for (let dir = 0; dir < 2; dir++) {
135
+ scratchPoint.copy(center);
136
+ scratchPoint.add(scratchScale);
137
+ addToCartographicBounds(result, scratchPoint);
138
+ scratchScale.negate();
139
+ }
140
+ }
141
+ return result;
142
+ }
143
+ function emptyCartographicBounds() {
144
+ return [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
145
+ }
146
+ function addToCartographicBounds(target, cartesian) {
147
+ Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
148
+ target[0][0] = Math.min(target[0][0], scratchPoint[0]);
149
+ target[0][1] = Math.min(target[0][1], scratchPoint[1]);
150
+ target[0][2] = Math.min(target[0][2], scratchPoint[2]);
151
+ target[1][0] = Math.max(target[1][0], scratchPoint[0]);
152
+ target[1][1] = Math.max(target[1][1], scratchPoint[1]);
153
+ target[1][2] = Math.max(target[1][2], scratchPoint[2]);
154
+ }
82
155
  //# sourceMappingURL=bounding-volume.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"bounding-volume.js","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"],"sources":["../../../../src/tileset/helpers/bounding-volume.ts"],"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"],"mappings":";;AAIA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC5E,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,kBAAkB;AACpE,SAAQC,SAAS,QAAO,qBAAqB;AAC7C,SAAQC,MAAM,QAAO,0BAA0B;;AAI/C,SAASC,OAAO,CAACC,CAAC,EAAE;EAClB,OAAOA,CAAC,KAAKC,SAAS,IAAID,CAAC,KAAK,IAAI;AACtC;;AAGA,MAAME,YAAY,GAAG,IAAIX,OAAO,EAAE;AAClC,MAAMY,gBAAgB,GAAG,IAAIZ,OAAO,EAAE;AACtC,MAAMa,gBAAgB,GAAG,IAAIb,OAAO,EAAE;;AAYtC,OAAO,SAASc,oBAAoB,CAACC,oBAAoB,EAAEC,SAAS,EAAEC,MAAM,EAAE;EAC5EV,MAAM,CAACQ,oBAAoB,EAAE,yCAAyC,CAAC;;EAIvE,IAAIA,oBAAoB,CAACG,GAAG,EAAE;IAC5B,OAAOC,SAAS,CAACJ,oBAAoB,CAACG,GAAG,EAAEF,SAAS,EAAEC,MAAM,CAAC;EAC/D;EACA,IAAIF,oBAAoB,CAACK,MAAM,EAAE;IAI/B,MAAM,CAACC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,CAAC,GAAGX,oBAAoB,CAACK,MAAM;IAEpF,MAAMO,SAAS,GAAGrB,SAAS,CAACsB,KAAK,CAACC,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,GAAGC,IAAI,CAACC,GAAG,CAACD,IAAI,CAACC,GAAG,CAACV,KAAK,CAAC,CAAC,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,CAAC,EAAEA,KAAK,CAAC,CAAC,CAAC,CAAC;EACrE,MAAMhB,MAAM,GAAGI,MAAM,CAAC,CAAC,CAAC,GAAGoB,YAAY;EAEvC,IAAIlD,OAAO,CAACS,MAAM,CAAC,EAAE;IACnBA,MAAM,CAACuB,MAAM,GAAGA,MAAM;IACtBvB,MAAM,CAACiB,MAAM,GAAGA,MAAM;IACtB,OAAOjB,MAAM;EACf;EAEA,OAAO,IAAIb,cAAc,CAACoC,MAAM,EAAEN,MAAM,CAAC;AAC3C"}
1
+ {"version":3,"file":"bounding-volume.js","names":["Quaternion","Vector3","Matrix3","Matrix4","degrees","BoundingSphere","OrientedBoundingBox","Ellipsoid","assert","defined","x","undefined","scratchPoint","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","getCartographicBounds","boundingVolume","orientedBoundingBoxToCartographicBounds","boundingSphereToCartographicBounds","center","origin","length","halfSize","slice","quaternion","fromArray","y","z","transformByQuaternion","scale","toArray","xAxis","transformAsVector","yAxis","zAxis","halfAxes","getScale","uniformScale","Math","max","emptyCartographicBounds","getColumn","copy","add","addToCartographicBounds","negate","point","scaleToGeodeticSurface","geodeticSurfaceNormal","normalize","clone","cross","axis","dir","Infinity","target","cartesian","cartesianToCartographic","min"],"sources":["../../../../src/tileset/helpers/bounding-volume.ts"],"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 scratchPoint = new Vector3();\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\n/** [min, max] each in [longitude, latitude, altitude] */\nexport type CartographicBounds = [min: number[], max: number[]];\n\n/**\n * Calculate the cartographic bounding box the tile's bounding volume.\n * @param {Object} boundingVolumeHeader The tile's bounding volume header.\n * @param {BoundingVolume} boundingVolume The bounding volume.\n * @returns {CartographicBounds}\n */\nexport function getCartographicBounds(\n boundingVolumeHeader,\n boundingVolume: OrientedBoundingBox | BoundingSphere\n): CartographicBounds {\n // boundingVolume schema:\n // https://github.com/AnalyticalGraphicsInc/3d-tiles/blob/master/specification/schema/boundingVolume.schema.json\n if (boundingVolumeHeader.box) {\n return orientedBoundingBoxToCartographicBounds(boundingVolume as OrientedBoundingBox);\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 return [\n [degrees(west), degrees(south), minHeight],\n [degrees(east), degrees(north), maxHeight]\n ];\n }\n\n if (boundingVolumeHeader.sphere) {\n return boundingSphereToCartographicBounds(boundingVolume as BoundingSphere);\n }\n\n throw new Error('Unkown boundingVolume type');\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\n/**\n * Convert a bounding volume defined by OrientedBoundingBox to cartographic bounds\n * @returns {CartographicBounds}\n */\nfunction orientedBoundingBoxToCartographicBounds(\n boundingVolume: OrientedBoundingBox\n): CartographicBounds {\n const result = emptyCartographicBounds();\n\n const {halfAxes} = boundingVolume as OrientedBoundingBox;\n const xAxis = new Vector3(halfAxes.getColumn(0));\n const yAxis = new Vector3(halfAxes.getColumn(1));\n const zAxis = new Vector3(halfAxes.getColumn(2));\n\n // Test all 8 corners of the box\n for (let x = 0; x < 2; x++) {\n for (let y = 0; y < 2; y++) {\n for (let z = 0; z < 2; z++) {\n scratchPoint.copy(boundingVolume.center);\n scratchPoint.add(xAxis);\n scratchPoint.add(yAxis);\n scratchPoint.add(zAxis);\n\n addToCartographicBounds(result, scratchPoint);\n zAxis.negate();\n }\n yAxis.negate();\n }\n xAxis.negate();\n }\n return result;\n}\n\n/**\n * Convert a bounding volume defined by BoundingSphere to cartographic bounds\n * @returns {CartographicBounds}\n */\nfunction boundingSphereToCartographicBounds(boundingVolume: BoundingSphere): CartographicBounds {\n const result = emptyCartographicBounds();\n\n const {center, radius} = boundingVolume as BoundingSphere;\n const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);\n\n let zAxis: Vector3;\n if (point) {\n zAxis = Ellipsoid.WGS84.geodeticSurfaceNormal(point) as Vector3;\n } else {\n zAxis = new Vector3(0, 0, 1);\n }\n let xAxis = new Vector3(zAxis[2], -zAxis[1], 0);\n if (xAxis.len() > 0) {\n xAxis.normalize();\n } else {\n xAxis = new Vector3(0, 1, 0);\n }\n const yAxis = xAxis.clone().cross(zAxis);\n\n // Test 6 end points of the 3 axes\n for (const axis of [xAxis, yAxis, zAxis]) {\n scratchScale.copy(axis).scale(radius);\n for (let dir = 0; dir < 2; dir++) {\n scratchPoint.copy(center);\n scratchPoint.add(scratchScale);\n addToCartographicBounds(result, scratchPoint);\n // Flip the axis\n scratchScale.negate();\n }\n }\n return result;\n}\n\n/**\n * Create a new cartographic bounds that contains no points\n * @returns {CartographicBounds}\n */\nfunction emptyCartographicBounds(): CartographicBounds {\n return [\n [Infinity, Infinity, Infinity],\n [-Infinity, -Infinity, -Infinity]\n ];\n}\n\n/**\n * Add a point to the target cartographic bounds\n * @param {CartographicBounds} target\n * @param {Vector3} cartesian coordinates of the point to add\n */\nfunction addToCartographicBounds(target: CartographicBounds, cartesian: Readonly<Vector3>) {\n Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);\n target[0][0] = Math.min(target[0][0], scratchPoint[0]);\n target[0][1] = Math.min(target[0][1], scratchPoint[1]);\n target[0][2] = Math.min(target[0][2], scratchPoint[2]);\n\n target[1][0] = Math.max(target[1][0], scratchPoint[0]);\n target[1][1] = Math.max(target[1][1], scratchPoint[1]);\n target[1][2] = Math.max(target[1][2], scratchPoint[2]);\n}\n"],"mappings":"AAIA,SAAQA,UAAU,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC5E,SAAQC,cAAc,EAAEC,mBAAmB,QAAO,kBAAkB;AACpE,SAAQC,SAAS,QAAO,qBAAqB;AAC7C,SAAQC,MAAM,QAAO,0BAA0B;AAI/C,SAASC,OAAOA,CAACC,CAAC,EAAE;EAClB,OAAOA,CAAC,KAAKC,SAAS,IAAID,CAAC,KAAK,IAAI;AACtC;AAGA,MAAME,YAAY,GAAG,IAAIX,OAAO,CAAC,CAAC;AAClC,MAAMY,YAAY,GAAG,IAAIZ,OAAO,CAAC,CAAC;AAClC,MAAMa,gBAAgB,GAAG,IAAIb,OAAO,CAAC,CAAC;AACtC,MAAMc,gBAAgB,GAAG,IAAId,OAAO,CAAC,CAAC;AAYtC,OAAO,SAASe,oBAAoBA,CAACC,oBAAoB,EAAEC,SAAS,EAAEC,MAAM,EAAE;EAC5EX,MAAM,CAACS,oBAAoB,EAAE,yCAAyC,CAAC;EAIvE,IAAIA,oBAAoB,CAACG,GAAG,EAAE;IAC5B,OAAOC,SAAS,CAACJ,oBAAoB,CAACG,GAAG,EAAEF,SAAS,EAAEC,MAAM,CAAC;EAC/D;EACA,IAAIF,oBAAoB,CAACK,MAAM,EAAE;IAI/B,MAAM,CAACC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAEC,KAAK,EAAEC,SAAS,EAAEC,SAAS,CAAC,GAAGX,oBAAoB,CAACK,MAAM;IAEpF,MAAMO,SAAS,GAAGtB,SAAS,CAACuB,KAAK,CAACC,uBAAuB,CACvD,CAAC3B,OAAO,CAACmB,IAAI,CAAC,EAAEnB,OAAO,CAACsB,KAAK,CAAC,EAAEC,SAAS,CAAC,EAC1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,SAASV,uBAAuBA,CAACW,MAA0B,EAAEC,SAA4B,EAAE;EACzF5E,SAAS,CAACuB,KAAK,CAACsD,uBAAuB,CAACD,SAAS,EAAEvE,YAAY,CAAC;EAChEsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACoB,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EACtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACoB,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EACtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACoB,GAAG,CAACH,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EAEtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACC,GAAG,CAACgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EACtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACC,GAAG,CAACgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;EACtDsE,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAGjB,IAAI,CAACC,GAAG,CAACgB,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAEtE,YAAY,CAAC,CAAC,CAAC,CAAC;AACxD"}
@@ -4,7 +4,6 @@ import { Ellipsoid } from '@math.gl/geospatial';
4
4
  const scratchVector = new Vector3();
5
5
  const scratchPosition = new Vector3();
6
6
  const cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
7
-
8
7
  export function getFrameState(viewport, frameNumber) {
9
8
  const {
10
9
  cameraDirection,
@@ -14,16 +13,12 @@ export function getFrameState(viewport, frameNumber) {
14
13
  const {
15
14
  metersPerUnit
16
15
  } = viewport.distanceScales;
17
-
18
16
  const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
19
17
  const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
20
18
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
21
19
  const cameraPositionCartesian = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
22
-
23
- const cameraDirectionCartesian = new Vector3(
24
- enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
25
- const cameraUpCartesian = new Vector3(
26
- enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
20
+ const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
21
+ const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
27
22
  commonSpacePlanesToWGS84(viewport);
28
23
  const ViewportClass = viewport.constructor;
29
24
  const {
@@ -42,7 +37,6 @@ export function getFrameState(viewport, frameNumber) {
42
37
  zoom,
43
38
  pitch: 0
44
39
  });
45
-
46
40
  return {
47
41
  camera: {
48
42
  position: cameraPositionCartesian,
@@ -57,7 +51,6 @@ export function getFrameState(viewport, frameNumber) {
57
51
  sseDenominator: 1.15
58
52
  };
59
53
  }
60
-
61
54
  export function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
62
55
  if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {
63
56
  return [tiles, []];
@@ -87,7 +80,6 @@ export function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
87
80
  }
88
81
  function commonSpacePlanesToWGS84(viewport) {
89
82
  const frustumPlanes = viewport.getFrustumPlanes();
90
-
91
83
  const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);
92
84
  const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
93
85
  const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);
@@ -97,12 +89,10 @@ function commonSpacePlanesToWGS84(viewport) {
97
89
  if (dir === 'near') {
98
90
  continue;
99
91
  }
100
-
101
92
  const plane = frustumPlanes[dir];
102
93
  const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);
103
94
  const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);
104
- cullingVolume.planes[i++].fromPointNormal(cartesianPos,
105
- scratchVector.copy(nearCenterCartesian).subtract(cartesianPos));
95
+ cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector.copy(nearCenterCartesian).subtract(cartesianPos));
106
96
  }
107
97
  }
108
98
  function closestPointOnPlane(plane, refPoint) {
@@ -1 +1 @@
1
- {"version":3,"file":"frame-state.js","names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartesian","worldToCartesian","center","enuToFixedTransform","WGS84","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cartographicToCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","ViewportClass","constructor","longitude","latitude","width","bearing","zoom","topDownViewport","pitch","camera","position","direction","up","sseDenominator","limitSelectedTiles","tiles","frameState","maximumTilesSelected","length","tuples","viewportLongitude","viewportLatitude","index","tile","entries","header","mbs","deltaLon","Math","abs","deltaLat","distance","sqrt","push","tuplesSorted","sort","a","b","selectedTiles","i","unselectedTiles","frustumPlanes","getFrustumPlanes","nearCenterCommon","closestPointOnPlane","near","nearCenterCartesian","cameraCartesian","planes","fromPointNormal","copy","subtract","dir","plane","posCommon","cartesianPos","refPoint","out","distanceToRef","normal","dot","add","point","cartographicPos"],"sources":["../../../../src/tileset/helpers/frame-state.ts"],"sourcesContent":["import {Tile3D} from '@loaders.gl/tiles';\nimport {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {GeospatialViewport, Viewport} from '../../types';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: GeospatialViewport;\n topDownViewport: GeospatialViewport; // Use it to calculate projected radius for a tile\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: GeospatialViewport, frameNumber: number): FrameState {\n // Traverse and and request. Update _selectedTiles so that we know what to render.\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 // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);\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);\n\n const ViewportClass = viewport.constructor;\n const {longitude, latitude, width, bearing, zoom} = viewport;\n // @ts-ignore\n const topDownViewport = new ViewportClass({\n longitude,\n latitude,\n height,\n width,\n bearing,\n zoom,\n pitch: 0\n });\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 topDownViewport,\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\n/**\n * Limit `tiles` array length with `maximumTilesSelected` number.\n * The criteria for this filtering is distance of a tile center\n * to the `frameState.viewport`'s longitude and latitude\n * @param tiles - tiles array to filter\n * @param frameState - frameState to calculate distances\n * @param maximumTilesSelected - maximal amount of tiles in the output array\n * @returns new tiles array\n */\nexport function limitSelectedTiles(\n tiles: Tile3D[],\n frameState: FrameState,\n maximumTilesSelected: number\n): [Tile3D[], Tile3D[]] {\n if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {\n return [tiles, []];\n }\n // Accumulate distances in couples array: [tileIndex: number, distanceToViewport: number]\n const tuples: [number, number][] = [];\n const {longitude: viewportLongitude, latitude: viewportLatitude} = frameState.viewport;\n for (const [index, tile] of tiles.entries()) {\n const [longitude, latitude] = tile.header.mbs;\n const deltaLon = Math.abs(viewportLongitude - longitude);\n const deltaLat = Math.abs(viewportLatitude - latitude);\n const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);\n tuples.push([index, distance]);\n }\n const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);\n const selectedTiles: Tile3D[] = [];\n for (let i = 0; i < maximumTilesSelected; i++) {\n selectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n const unselectedTiles: Tile3D[] = [];\n for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {\n unselectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n\n return [selectedTiles, unselectedTiles];\n}\n\nfunction commonSpacePlanesToWGS84(viewport) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n\n // Get the near/far plane centers\n const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);\n const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);\n const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);\n\n let i = 0;\n cullingVolume.planes[i++].fromPointNormal(\n nearCenterCartesian,\n scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian)\n );\n\n for (const dir in frustumPlanes) {\n if (dir === 'near') {\n continue; // eslint-disable-line no-continue\n }\n const plane = frustumPlanes[dir];\n const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);\n const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);\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(nearCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n\nfunction closestPointOnPlane(\n plane: {distance: number; normal: Vector3},\n refPoint: [number, number, number] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const distanceToRef = plane.normal.dot(refPoint);\n out\n .copy(plane.normal)\n .scale(plane.distance - distanceToRef)\n .add(refPoint);\n return out;\n}\n\nfunction worldToCartesian(\n viewport: Viewport,\n point: number[] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const cartographicPos = viewport.unprojectPosition(point);\n return Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);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L,GAAY,uEAAG,IAAIzF,OAAO,EAAE;EAE5B,MAAM+F,eAAe,GAAGvF,QAAQ,CAACc,iBAAiB,CAACwE,KAAK,CAAC;EACzD,OAAO3F,SAAS,CAACgB,KAAK,CAACM,uBAAuB,CAACsE,eAAe,EAAEN,GAAG,CAAC;AACtE"}
1
+ {"version":3,"file":"frame-state.js","names":["Vector3","CullingVolume","Plane","Ellipsoid","scratchVector","scratchPosition","cullingVolume","getFrameState","viewport","frameNumber","cameraDirection","cameraUp","height","metersPerUnit","distanceScales","viewportCenterCartesian","worldToCartesian","center","enuToFixedTransform","WGS84","eastNorthUpToFixedFrame","cameraPositionCartographic","unprojectPosition","cameraPosition","cameraPositionCartesian","cartographicToCartesian","cameraDirectionCartesian","transformAsVector","scale","normalize","cameraUpCartesian","commonSpacePlanesToWGS84","ViewportClass","constructor","longitude","latitude","width","bearing","zoom","topDownViewport","pitch","camera","position","direction","up","sseDenominator","limitSelectedTiles","tiles","frameState","maximumTilesSelected","length","tuples","viewportLongitude","viewportLatitude","index","tile","entries","header","mbs","deltaLon","Math","abs","deltaLat","distance","sqrt","push","tuplesSorted","sort","a","b","selectedTiles","i","unselectedTiles","frustumPlanes","getFrustumPlanes","nearCenterCommon","closestPointOnPlane","near","nearCenterCartesian","cameraCartesian","planes","fromPointNormal","copy","subtract","dir","plane","posCommon","cartesianPos","refPoint","out","arguments","undefined","distanceToRef","normal","dot","add","point","cartographicPos"],"sources":["../../../../src/tileset/helpers/frame-state.ts"],"sourcesContent":["import {Tile3D} from '@loaders.gl/tiles';\nimport {Vector3} from '@math.gl/core';\nimport {CullingVolume, Plane} from '@math.gl/culling';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {GeospatialViewport, Viewport} from '../../types';\n\nexport type FrameState = {\n camera: {\n position: number[];\n direction: number[];\n up: number[];\n };\n viewport: GeospatialViewport;\n topDownViewport: GeospatialViewport; // Use it to calculate projected radius for a tile\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: GeospatialViewport, frameNumber: number): FrameState {\n // Traverse and and request. Update _selectedTiles so that we know what to render.\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 // TODO - Ellipsoid.eastNorthUpToFixedFrame() breaks on raw array, create a Vector.\n // TODO - Ellipsoid.eastNorthUpToFixedFrame() takes a cartesian, is that intuitive?\n const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);\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);\n\n const ViewportClass = viewport.constructor;\n const {longitude, latitude, width, bearing, zoom} = viewport;\n // @ts-ignore\n const topDownViewport = new ViewportClass({\n longitude,\n latitude,\n height,\n width,\n bearing,\n zoom,\n pitch: 0\n });\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 topDownViewport,\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\n/**\n * Limit `tiles` array length with `maximumTilesSelected` number.\n * The criteria for this filtering is distance of a tile center\n * to the `frameState.viewport`'s longitude and latitude\n * @param tiles - tiles array to filter\n * @param frameState - frameState to calculate distances\n * @param maximumTilesSelected - maximal amount of tiles in the output array\n * @returns new tiles array\n */\nexport function limitSelectedTiles(\n tiles: Tile3D[],\n frameState: FrameState,\n maximumTilesSelected: number\n): [Tile3D[], Tile3D[]] {\n if (maximumTilesSelected === 0 || tiles.length <= maximumTilesSelected) {\n return [tiles, []];\n }\n // Accumulate distances in couples array: [tileIndex: number, distanceToViewport: number]\n const tuples: [number, number][] = [];\n const {longitude: viewportLongitude, latitude: viewportLatitude} = frameState.viewport;\n for (const [index, tile] of tiles.entries()) {\n const [longitude, latitude] = tile.header.mbs;\n const deltaLon = Math.abs(viewportLongitude - longitude);\n const deltaLat = Math.abs(viewportLatitude - latitude);\n const distance = Math.sqrt(deltaLat * deltaLat + deltaLon * deltaLon);\n tuples.push([index, distance]);\n }\n const tuplesSorted = tuples.sort((a, b) => a[1] - b[1]);\n const selectedTiles: Tile3D[] = [];\n for (let i = 0; i < maximumTilesSelected; i++) {\n selectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n const unselectedTiles: Tile3D[] = [];\n for (let i = maximumTilesSelected; i < tuplesSorted.length; i++) {\n unselectedTiles.push(tiles[tuplesSorted[i][0]]);\n }\n\n return [selectedTiles, unselectedTiles];\n}\n\nfunction commonSpacePlanesToWGS84(viewport) {\n // Extract frustum planes based on current view.\n const frustumPlanes = viewport.getFrustumPlanes();\n\n // Get the near/far plane centers\n const nearCenterCommon = closestPointOnPlane(frustumPlanes.near, viewport.cameraPosition);\n const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);\n const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition);\n\n let i = 0;\n cullingVolume.planes[i++].fromPointNormal(\n nearCenterCartesian,\n scratchVector.copy(nearCenterCartesian).subtract(cameraCartesian)\n );\n\n for (const dir in frustumPlanes) {\n if (dir === 'near') {\n continue; // eslint-disable-line no-continue\n }\n const plane = frustumPlanes[dir];\n const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition);\n const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition);\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(nearCenterCartesian).subtract(cartesianPos)\n );\n }\n}\n\nfunction closestPointOnPlane(\n plane: {distance: number; normal: Vector3},\n refPoint: [number, number, number] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const distanceToRef = plane.normal.dot(refPoint);\n out\n .copy(plane.normal)\n .scale(plane.distance - distanceToRef)\n .add(refPoint);\n return out;\n}\n\nfunction worldToCartesian(\n viewport: Viewport,\n point: number[] | Vector3,\n out: Vector3 = new Vector3()\n): Vector3 {\n const cartographicPos = viewport.unprojectPosition(point);\n return Ellipsoid.WGS84.cartographicToCartesian(cartographicPos, out);\n}\n"],"mappings":"AACA,SAAQA,OAAO,QAAO,eAAe;AACrC,SAAQC,aAAa,EAAEC,KAAK,QAAO,kBAAkB;AACrD,SAAQC,SAAS,QAAO,qBAAqB;AAiB7C,MAAMC,aAAa,GAAG,IAAIJ,OAAO,CAAC,CAAC;AACnC,MAAMK,eAAe,GAAG,IAAIL,OAAO,CAAC,CAAC;AACrC,MAAMM,aAAa,GAAG,IAAIL,aAAa,CAAC,CACtC,IAAIC,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,EACX,IAAIA,KAAK,CAAC,CAAC,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Matrix4, Vector3 } from '@math.gl/core';
4
2
  import { Ellipsoid } from '@math.gl/geospatial';
5
3
  const cameraPositionCartesian = new Vector3();
@@ -9,7 +7,6 @@ const extraVertexEnu = new Vector3();
9
7
  const projectedOriginVector = new Vector3();
10
8
  const enuToCartesianMatrix = new Matrix4();
11
9
  const cartesianToEnuMatrix = new Matrix4();
12
-
13
10
  export function getLodStatus(tile, frameState) {
14
11
  if (tile.lodMetricValue === 0 || isNaN(tile.lodMetricValue)) {
15
12
  return 'DIG';
@@ -25,7 +22,6 @@ export function getLodStatus(tile, frameState) {
25
22
  }
26
23
  return 'OUT';
27
24
  }
28
-
29
25
  export function getProjectedRadius(tile, frameState) {
30
26
  const {
31
27
  topDownViewport: viewport
@@ -37,7 +33,6 @@ export function getProjectedRadius(tile, frameState) {
37
33
  const mbsCenterCartesian = [...tile.boundingVolume.center];
38
34
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
39
35
  Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);
40
-
41
36
  toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();
42
37
  Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
43
38
  cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
@@ -50,7 +45,6 @@ export function getProjectedRadius(tile, frameState) {
50
45
  const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
51
46
  const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
52
47
  const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
53
-
54
48
  const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
55
49
  const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
56
50
  const projectedRadius = projectedOriginVector.copy(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
@@ -1 +1 @@
1
- {"version":3,"file":"i3s-lod.js","names":["Matrix4","Vector3","Ellipsoid","cameraPositionCartesian","toEye","cameraPositionEnu","extraVertexEnu","projectedOriginVector","enuToCartesianMatrix","cartesianToEnuMatrix","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","topDownViewport","viewport","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","WGS84","cartographicToCartesian","copy","subtract","normalize","eastNorthUpToFixedFrame","invert","transform","projection","Math","sqrt","extraZ","extraVertexCartesian","extraVectorCartesian","radiusVector","cross","scale","sphereMbsBorderVertexCartesian","add","sphereMbsBorderVertexCartographic","cartesianToCartographic","projectedOrigin","project","projectedMbsBorderVertex","projectedRadius","magnitude"],"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {Tile3D} from '../tile-3d';\nimport {FrameState} from './frame-state';\n\nconst cameraPositionCartesian = new Vector3();\nconst toEye = new Vector3();\nconst cameraPositionEnu = new Vector3();\nconst extraVertexEnu = new Vector3();\nconst projectedOriginVector = new Vector3();\nconst enuToCartesianMatrix = new Matrix4();\nconst cartesianToEnuMatrix = new Matrix4();\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 {topDownViewport: viewport} = frameState;\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 Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);\n\n // ---------------------------\n // Calculate mbs border vertex\n // ---------------------------\n toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();\n // Add extra vector to form plane\n Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);\n cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();\n cameraPositionEnu.copy(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 extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);\n const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);\n const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();\n // We need radius vector orthogonal to toEye vector\n const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);\n const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);\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(\n sphereMbsBorderVertexCartographic as [number, number, number]\n );\n const projectedRadius = projectedOriginVector\n .copy(projectedOrigin)\n .subtract(projectedMbsBorderVertex)\n .magnitude();\n return projectedRadius;\n}\n"],"mappings":";;AAEA,SAAQA,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC9C,SAAQC,SAAS,QAAO,qBAAqB;AAI7C,MAAMC,uBAAuB,GAAG,IAAIF,OAAO,EAAE;AAC7C,MAAMG,KAAK,GAAG,IAAIH,OAAO,EAAE;AAC3B,MAAMI,iBAAiB,GAAG,IAAIJ,OAAO,EAAE;AACvC,MAAMK,cAAc,GAAG,IAAIL,OAAO,EAAE;AACpC,MAAMM,qBAAqB,GAAG,IAAIN,OAAO,EAAE;AAC3C,MAAMO,oBAAoB,GAAG,IAAIR,OAAO,EAAE;AAC1C,MAAMS,oBAAoB,GAAG,IAAIT,OAAO,EAAE;;AAW1C,OAAO,SAASU,YAAY,CAACC,IAAY,EAAEC,UAAsB,EAA0B;EACzF,IAAID,IAAI,CAACE,cAAc,KAAK,CAAC,IAAIC,KAAK,CAACH,IAAI,CAACE,cAAc,CAAC,EAAE;IAC3D,OAAO,KAAK;EACd;EACA,MAAME,UAAU,GAAG,CAAC,GAAGC,kBAAkB,CAACL,IAAI,EAAEC,UAAU,CAAC;EAC3D,IAAIG,UAAU,GAAG,CAAC,EAAE;IAClB,OAAO,KAAK;EACd;EACA,IAAI,CAACJ,IAAI,CAACM,MAAM,CAACC,QAAQ,IAAIH,UAAU,IAAIJ,IAAI,CAACE,cAAc,EAAE;IAC9D,OAAO,MAAM;EACf,CAAC,MAAM,IAAIF,IAAI,CAACM,MAAM,CAACC,QAAQ,EAAE;IAC/B,OAAO,KAAK;EACd;EACA,OAAO,KAAK;AACd;;AASA,OAAO,SAASF,kBAAkB,CAACL,IAAY,EAAEC,UAAs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EAC/DC,cAAc,CAAC4B,IAAI,CAAC,CAAC7B,iBAAiB,CAAC,CAAC,CAAC,EAAEA,iBAAiB,CAAC,CAAC,CAAC,EAAEsC,MAAM,CAAC,CAAC;EACzE,MAAMC,oBAAoB,GAAGtC,cAAc,CAACiC,SAAS,CAAC/B,oBAAoB,CAAC;EAC3E,MAAMqC,oBAAoB,GAAGD,oBAAoB,CAACT,QAAQ,CAACT,kBAAkB,CAAC,CAACU,SAAS,EAAE;EAE1F,MAAMU,YAAY,GAAG1C,KAAK,CAAC2C,KAAK,CAACF,oBAAoB,CAAC,CAACT,SAAS,EAAE,CAACY,KAAK,CAACvB,IAAI,CAAC;EAC9E,MAAMwB,8BAA8B,GAAGH,YAAY,CAACI,GAAG,CAACxB,kBAAkB,CAAC;EAC3E,MAAMyB,iCAAiC,GAAGjD,SAAS,CAAC8B,KAAK,CAACoB,uBAAuB,CAC/EH,8BAA8B,CAC/B;;EAID,MAAMI,eAAe,GAAGjC,QAAQ,CAACkC,OAAO,CAAC,CAAC/B,MAAM,EAAEF,MAAM,EAAEG,IAAI,CAAC,CAAC;EAChE,MAAM+B,wBAAwB,GAAGnC,QAAQ,CAACkC,OAAO,CAC/CH,iCAAiC,CAClC;EACD,MAAMK,eAAe,GAAGjD,qBAAqB,CAC1C2B,IAAI,CAACmB,eAAe,CAAC,CACrBlB,QAAQ,CAACoB,wBAAwB,CAAC,CAClCE,SAAS,EAAE;EACd,OAAOD,eAAe;AACxB"}
1
+ {"version":3,"file":"i3s-lod.js","names":["Matrix4","Vector3","Ellipsoid","cameraPositionCartesian","toEye","cameraPositionEnu","extraVertexEnu","projectedOriginVector","enuToCartesianMatrix","cartesianToEnuMatrix","getLodStatus","tile","frameState","lodMetricValue","isNaN","screenSize","getProjectedRadius","header","children","topDownViewport","viewport","mbsLat","mbs","mbsLon","mbsZ","mbsR","mbsCenterCartesian","boundingVolume","center","cameraPositionCartographic","unprojectPosition","cameraPosition","WGS84","cartographicToCartesian","copy","subtract","normalize","eastNorthUpToFixedFrame","invert","transform","projection","Math","sqrt","extraZ","extraVertexCartesian","extraVectorCartesian","radiusVector","cross","scale","sphereMbsBorderVertexCartesian","add","sphereMbsBorderVertexCartographic","cartesianToCartographic","projectedOrigin","project","projectedMbsBorderVertex","projectedRadius","magnitude"],"sources":["../../../../src/tileset/helpers/i3s-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\nimport {Matrix4, Vector3} from '@math.gl/core';\nimport {Ellipsoid} from '@math.gl/geospatial';\nimport {Tile3D} from '../tile-3d';\nimport {FrameState} from './frame-state';\n\nconst cameraPositionCartesian = new Vector3();\nconst toEye = new Vector3();\nconst cameraPositionEnu = new Vector3();\nconst extraVertexEnu = new Vector3();\nconst projectedOriginVector = new Vector3();\nconst enuToCartesianMatrix = new Matrix4();\nconst cartesianToEnuMatrix = new Matrix4();\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 {topDownViewport: viewport} = frameState;\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 Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, cameraPositionCartesian);\n\n // ---------------------------\n // Calculate mbs border vertex\n // ---------------------------\n toEye.copy(cameraPositionCartesian).subtract(mbsCenterCartesian).normalize();\n // Add extra vector to form plane\n Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);\n cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();\n cameraPositionEnu.copy(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 extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);\n const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);\n const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();\n // We need radius vector orthogonal to toEye vector\n const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);\n const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);\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(\n sphereMbsBorderVertexCartographic as [number, number, number]\n );\n const projectedRadius = projectedOriginVector\n .copy(projectedOrigin)\n .subtract(projectedMbsBorderVertex)\n .magnitude();\n return projectedRadius;\n}\n"],"mappings":"AAEA,SAAQA,OAAO,EAAEC,OAAO,QAAO,eAAe;AAC9C,SAAQC,SAAS,QAAO,qBAAqB;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AAkB,CAAC,CAACU,SAAS,CAAC,CAAC;EAE1F,MAAMU,YAAY,GAAG1C,KAAK,CAAC2C,KAAK,CAACF,oBAAoB,CAAC,CAACT,SAAS,CAAC,CAAC,CAACY,KAAK,CAACvB,IAAI,CAAC;EAC9E,MAAMwB,8BAA8B,GAAGH,YAAY,CAACI,GAAG,CAACxB,kBAAkB,CAAC;EAC3E,MAAMyB,iCAAiC,GAAGjD,SAAS,CAAC8B,KAAK,CAACoB,uBAAuB,CAC/EH,8BACF,CAAC;EAID,MAAMI,eAAe,GAAGjC,QAAQ,CAACkC,OAAO,CAAC,CAAC/B,MAAM,EAAEF,MAAM,EAAEG,IAAI,CAAC,CAAC;EAChE,MAAM+B,wBAAwB,GAAGnC,QAAQ,CAACkC,OAAO,CAC/CH,iCACF,CAAC;EACD,MAAMK,eAAe,GAAGjD,qBAAqB,CAC1C2B,IAAI,CAACmB,eAAe,CAAC,CACrBlB,QAAQ,CAACoB,wBAAwB,CAAC,CAClCE,SAAS,CAAC,CAAC;EACd,OAAOD,eAAe;AACxB"}
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  import { Matrix4, Vector3, clamp } from '@math.gl/core';
4
2
  const scratchPositionNormal = new Vector3();
5
3
  const scratchCartographic = new Vector3();
@@ -7,7 +5,6 @@ const scratchMatrix = new Matrix4();
7
5
  const scratchCenter = new Vector3();
8
6
  const scratchPosition = new Vector3();
9
7
  const scratchDirection = new Vector3();
10
-
11
8
  export function calculateDynamicScreenSpaceError(root, _ref) {
12
9
  let {
13
10
  camera,
@@ -59,15 +56,12 @@ export function calculateDynamicScreenSpaceError(root, _ref) {
59
56
  }
60
57
  }
61
58
  }
62
-
63
59
  const heightFalloff = dynamicScreenSpaceErrorHeightFalloff;
64
60
  const heightClose = minimumHeight + (maximumHeight - minimumHeight) * heightFalloff;
65
61
  const heightFar = maximumHeight;
66
62
  const t = clamp((height - heightClose) / (heightFar - heightClose), 0.0, 1.0);
67
-
68
63
  const dot = Math.abs(Cartesian3.dot(direction, up));
69
64
  let horizonFactor = 1.0 - dot;
70
-
71
65
  horizonFactor = horizonFactor * (1.0 - t);
72
66
  return dynamicScreenSpaceErrorDensity * horizonFactor;
73
67
  }
@@ -88,11 +82,9 @@ export function getTiles3DScreenSpaceError(tile, frameState, useParentLodMetric)
88
82
  const tileset = tile.tileset;
89
83
  const parentLodMetricValue = tile.parent && tile.parent.lodMetricValue || tile.lodMetricValue;
90
84
  const lodMetricValue = useParentLodMetric ? parentLodMetricValue : tile.lodMetricValue;
91
-
92
85
  if (lodMetricValue === 0.0) {
93
86
  return 0.0;
94
87
  }
95
-
96
88
  const distance = Math.max(tile._distanceToCamera, 1e-7);
97
89
  const {
98
90
  height,
@@ -1 +1 @@
1
- {"version":3,"file":"tiles-3d-lod.js","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"],"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// 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"],"mappings":";;AAUA,SAAQA,OAAO,EAAEC,OAAO,EAAEC,KAAK,QAAO,eAAe;AAErD,MAAMC,qBAAqB,GAAG,IAAIF,OAAO,EAAE;AAC3C,MAAMG,mBAAmB,GAAG,IAAIH,OAAO,EAAE;AACzC,MAAMI,aAAa,GAAG,IAAIL,OAAO,EAAE;AACnC,MAAMM,aAAa,GAAG,IAAIL,OAAO,EAAE;AACnC,MAAMM,eAAe,GAAG,IAAIN,OAAO,EAAE;AACrC,MAAMO,gBAAgB,GAAG,IAAIP,OAAO,EAAE;;AAGtC,OAAO,SAASQ,gCAAgC,CAACC,IAAI,QAAyC;EAAA,IAAvC;IAACC,MAAM;IAAEC;EAAa,CAAC;EAAA,IAAEC,OAAO,uEAAG,CAAC,CAAC;EAC1F,MAAM;IAACC,oCAAoC,GAAG,IAAI;IAAEC,8BAA8B,GAAG;EAAO,CAAC,GAC3FF,OAAO;EAET,IAAIG,EAAE;EACN,IAAIC,SAAS;EACb,IAAIC,MAAM;EACV,IAAIC,aAAa;EACjB,IAAIC,aAAa;EAEjB,MAAMC,kBAAkB,GAAGX,IAAI,CAACY,qBAAqB;EAErD,IAAID,kBAAkB,YAAYE,kBA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hGE,KAAK,IAAInB,0BAA0B,CAACC,OAAO,EAAEa,QAAQ,CAAC;EAEtD,OAAOK,KAAK;AACd"}
1
+ {"version":3,"file":"tiles-3d-lod.js","names":["Matrix4","Vector3","clamp","scratchPositionNormal","scratchCartographic","scratchMatrix","scratchCenter","scratchPosition","scratchDirection","calculateDynamicScreenSpaceError","root","_ref","camera","mapProjection","options","arguments","length","undefined","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"],"sources":["../../../../src/tileset/helpers/tiles-3d-lod.ts"],"sourcesContent":["// loaders.gl, MIT license\n\n// 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"],"mappings":"AAUA,SAAQA,OAAO,EAAEC,OAAO,EAAEC,KAAK,QAAO,eAAe;AAErD,MAAMC,qBAAqB,GAAG,IAAIF,OAAO,CAAC,CAAC;AAC3C,MAAMG,mBAAmB,GAAG,IAAIH,OAAO,CAAC,CAAC;AACzC,MAAMI,aAAa,GAAG,IAAIL,OAAO,CAAC,CAAC;AACnC,MAAMM,aAAa,GAAG,IAAIL,OAAO,CAAC,CAAC;AACnC,MAAMM,eAAe,GAAG,IAAIN,OAAO,CAAC,CAAC;AACrC,MAAMO,gBAAgB,GAAG,IAAIP,OAAO,CAAC,CAAC;AAGtC,OAAO,SAASQ,gCAAgCA,CAACC,IAAI,EAAAC,IAAA,EAAyC;EAAA,IAAvC;IAACC,MAAM;IAAEC;EAAa,CAAC,GAAAF,IAAA;EAAA,IAAEG,OAAO,GAAAC,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAG,CAAC,CAAC;EAC1F,MAAM;IAACG,oCAAoC,GAAG,IAAI;IAAEC,8BAA8B,GAAG;EAAO,CAAC,GAC3FL,OAAO;EAET,IAAIM,EAAE;EACN,IAAIC,SAAS;EACb,IAAIC,MAAM;EACV,IAAIC,aAAa;EACjB,IAAIC,aAAa;EAEjB,MAAMC,kBAAkB,GAAGf,IAAI,CAACgB,qBAAqB;EAErD,IAAID,kBAAkB,YAAYE,kBAAkB,EAAE;IACpDP,EAAE,GAAGQ,UAAU,CAACC,SAAS,CAACjB,MAAM,CAACkB,UAAU,EAAE3B,qBAAqB,CAAC;IACnEkB,SAAS,GAAGT,MAAM,CAACmB,WAAW;IAC9BT,MAAM,GAAGV,MAAM,CAACoB,oBAAoB,CAACV,MAAM;IAC3CC,aAAa,GAAGE,k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AgB,EAAE;EACpE,IAAIK,OAAO,CAACC,uBAAuB,IAAID,OAAO,CAACE,sCAAsC,EAAE;IACrF,MAAMN,OAAO,GAAGI,OAAO,CAACE,sCAAsC;IAC9D,MAAMC,MAAM,GAAGH,OAAO,CAACI,6BAA6B;IAEpD,MAAMC,YAAY,GAAGX,GAAG,CAACC,gBAAgB,EAAEC,OAAO,CAAC,GAAGO,MAAM;IAC5D,OAAOE,YAAY;EACrB;EAEA,OAAO,CAAC;AACV;AAEA,OAAO,SAASC,0BAA0BA,CAACC,IAAI,EAAEC,UAAU,EAAEC,kBAAkB,EAAE;EAC/E,MAAMT,OAAO,GAAGO,IAAI,CAACP,OAAO;EAC5B,MAAMU,oBAAoB,GAAIH,IAAI,CAACI,MAAM,IAAIJ,IAAI,CAACI,MAAM,CAACC,cAAc,IAAKL,IAAI,CAACK,cAAc;EAC/F,MAAMA,cAAc,GAAGH,kBAAkB,GAAGC,oBAAoB,GAAGH,IAAI,CAACK,cAAc;EAGtF,IAAIA,cAAc,KAAK,GAAG,EAAE;IAC1B,OAAO,GAAG;EACZ;EAMA,MAAMC,QAAQ,GAAGtB,IAAI,CAACuB,GAAG,CAACP,IAAI,CAACQ,iBAAiB,EAAE,IAAI,CAAC;EACvD,MAAM;IAAC/D,MAAM;IAAEgE;EAAc,CAAC,GAAGR,UAAU;EAC3C,MAAM;IAACS;EAAiB,CAAC,GAAGjB,OAAO,CAACxD,OAAO;EAC3C,IAAI0E,KAAK,GAAIN,cAAc,GAAG5D,MAAM,IAAIiE,iBAAiB,IAAI,GAAG,CAAC,IAAKJ,QAAQ,GAAGG,cAAc,CAAC;EAEhGE,KAAK,IAAInB,0BAA0B,CAACC,OAAO,EAAEa,QAAQ,CAAC;EAEtD,OAAOK,KAAK;AACd"}
@@ -1,5 +1,3 @@
1
-
2
-
3
1
  import { Ellipsoid } from '@math.gl/geospatial';
4
2
  import { Matrix4, Vector3 } from '@math.gl/core';
5
3
  import { assert } from '@loaders.gl/loader-utils';
@@ -17,11 +15,9 @@ export function calculateTransformProps(tileHeader, tile) {
17
15
  }
18
16
  } = tileHeader;
19
17
  let modelMatrix = new Matrix4(computedTransform);
20
-
21
18
  if (rtcCenter) {
22
19
  modelMatrix.translate(rtcCenter);
23
20
  }
24
-
25
21
  switch (gltfUpAxis) {
26
22
  case 'Z':
27
23
  break;
@@ -36,21 +32,17 @@ export function calculateTransformProps(tileHeader, tile) {
36
32
  default:
37
33
  break;
38
34
  }
39
-
40
35
  if (tile.isQuantized) {
41
36
  modelMatrix.translate(tile.quantizedVolumeOffset).scale(tile.quantizedVolumeScale);
42
37
  }
43
-
44
38
  const cartesianOrigin = new Vector3(center);
45
39
  tile.cartesianModelMatrix = modelMatrix;
46
40
  tile.cartesianOrigin = cartesianOrigin;
47
-
48
41
  const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
49
42
  const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
50
43
  const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
51
44
  tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
52
45
  tile.cartographicOrigin = cartographicOrigin;
53
-
54
46
  if (!tile.coordinateSystem) {
55
47
  tile.modelMatrix = tile.cartographicModelMatrix;
56
48
  }