@loaders.gl/tiles 4.2.0-alpha.4 → 4.2.0-alpha.6

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 (75) hide show
  1. package/dist/constants.js +34 -32
  2. package/dist/dist.dev.js +679 -449
  3. package/dist/dist.min.js +9 -0
  4. package/dist/index.cjs +265 -326
  5. package/dist/index.cjs.map +7 -0
  6. package/dist/index.d.ts +10 -10
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +3 -1
  9. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts +1 -1
  10. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.d.ts.map +1 -1
  11. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js +45 -35
  12. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js +38 -22
  13. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts +1 -1
  14. package/dist/tileset/format-i3s/i3s-tile-manager.d.ts.map +1 -1
  15. package/dist/tileset/format-i3s/i3s-tile-manager.js +68 -69
  16. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts +2 -2
  17. package/dist/tileset/format-i3s/i3s-tileset-traverser.d.ts.map +1 -1
  18. package/dist/tileset/format-i3s/i3s-tileset-traverser.js +79 -57
  19. package/dist/tileset/helpers/3d-tiles-options.d.ts +1 -1
  20. package/dist/tileset/helpers/3d-tiles-options.d.ts.map +1 -1
  21. package/dist/tileset/helpers/3d-tiles-options.js +3 -4
  22. package/dist/tileset/helpers/bounding-volume.js +269 -128
  23. package/dist/tileset/helpers/frame-state.d.ts +1 -1
  24. package/dist/tileset/helpers/frame-state.d.ts.map +1 -1
  25. package/dist/tileset/helpers/frame-state.js +114 -95
  26. package/dist/tileset/helpers/i3s-lod.d.ts +2 -2
  27. package/dist/tileset/helpers/i3s-lod.d.ts.map +1 -1
  28. package/dist/tileset/helpers/i3s-lod.js +68 -39
  29. package/dist/tileset/helpers/tiles-3d-lod.js +97 -85
  30. package/dist/tileset/helpers/transform-utils.js +45 -44
  31. package/dist/tileset/helpers/zoom.d.ts +1 -1
  32. package/dist/tileset/helpers/zoom.d.ts.map +1 -1
  33. package/dist/tileset/helpers/zoom.js +70 -40
  34. package/dist/tileset/tile-3d.d.ts +7 -6
  35. package/dist/tileset/tile-3d.d.ts.map +1 -1
  36. package/dist/tileset/tile-3d.js +608 -399
  37. package/dist/tileset/tileset-3d.d.ts +7 -6
  38. package/dist/tileset/tileset-3d.d.ts.map +1 -1
  39. package/dist/tileset/tileset-3d.js +739 -597
  40. package/dist/tileset/tileset-cache.d.ts +2 -2
  41. package/dist/tileset/tileset-cache.d.ts.map +1 -1
  42. package/dist/tileset/tileset-cache.js +65 -48
  43. package/dist/tileset/tileset-traverser.d.ts +3 -3
  44. package/dist/tileset/tileset-traverser.d.ts.map +1 -1
  45. package/dist/tileset/tileset-traverser.js +282 -220
  46. package/dist/types.js +0 -1
  47. package/dist/utils/doubly-linked-list-node.js +17 -9
  48. package/dist/utils/doubly-linked-list.d.ts +1 -1
  49. package/dist/utils/doubly-linked-list.d.ts.map +1 -1
  50. package/dist/utils/doubly-linked-list.js +83 -56
  51. package/dist/utils/managed-array.js +140 -76
  52. package/package.json +10 -9
  53. package/src/tileset/tile-3d.ts +1 -1
  54. package/src/tileset/tileset-3d.ts +1 -1
  55. package/dist/constants.js.map +0 -1
  56. package/dist/index.js.map +0 -1
  57. package/dist/tileset/format-3d-tiles/tileset-3d-traverser.js.map +0 -1
  58. package/dist/tileset/format-i3s/i3s-pending-tiles-register.js.map +0 -1
  59. package/dist/tileset/format-i3s/i3s-tile-manager.js.map +0 -1
  60. package/dist/tileset/format-i3s/i3s-tileset-traverser.js.map +0 -1
  61. package/dist/tileset/helpers/3d-tiles-options.js.map +0 -1
  62. package/dist/tileset/helpers/bounding-volume.js.map +0 -1
  63. package/dist/tileset/helpers/frame-state.js.map +0 -1
  64. package/dist/tileset/helpers/i3s-lod.js.map +0 -1
  65. package/dist/tileset/helpers/tiles-3d-lod.js.map +0 -1
  66. package/dist/tileset/helpers/transform-utils.js.map +0 -1
  67. package/dist/tileset/helpers/zoom.js.map +0 -1
  68. package/dist/tileset/tile-3d.js.map +0 -1
  69. package/dist/tileset/tileset-3d.js.map +0 -1
  70. package/dist/tileset/tileset-cache.js.map +0 -1
  71. package/dist/tileset/tileset-traverser.js.map +0 -1
  72. package/dist/types.js.map +0 -1
  73. package/dist/utils/doubly-linked-list-node.js.map +0 -1
  74. package/dist/utils/doubly-linked-list.js.map +0 -1
  75. package/dist/utils/managed-array.js.map +0 -1
package/dist/dist.dev.js CHANGED
@@ -2,8 +2,8 @@
2
2
  if (typeof exports === 'object' && typeof module === 'object')
3
3
  module.exports = factory();
4
4
  else if (typeof define === 'function' && define.amd) define([], factory);
5
- else if (typeof exports === 'object') exports['loader'] = factory();
6
- else root['loader'] = factory();})(globalThis, function () {
5
+ else if (typeof exports === 'object') exports['loaders'] = factory();
6
+ else root['loaders'] = factory();})(globalThis, function () {
7
7
  "use strict";
8
8
  var __exports__ = (() => {
9
9
  var __create = Object.create;
@@ -27,6 +27,7 @@ var __exports__ = (() => {
27
27
  }
28
28
  return to;
29
29
  };
30
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
30
31
  var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
31
32
  // If the importer is in node compatibility mode or this is not an ESM
32
33
  // file that has been converted to a CommonJS file using a Babel-
@@ -44,9 +45,9 @@ var __exports__ = (() => {
44
45
  }
45
46
  });
46
47
 
47
- // src/index.ts
48
- var src_exports = {};
49
- __export(src_exports, {
48
+ // bundle.ts
49
+ var bundle_exports = {};
50
+ __export(bundle_exports, {
50
51
  LOD_METRIC_TYPE: () => LOD_METRIC_TYPE,
51
52
  TILESET_TYPE: () => TILESET_TYPE,
52
53
  TILE_CONTENT_STATE: () => TILE_CONTENT_STATE,
@@ -61,6 +62,7 @@ var __exports__ = (() => {
61
62
  getFrameState: () => getFrameState,
62
63
  getLodStatus: () => getLodStatus
63
64
  });
65
+ __reExport(bundle_exports, __toESM(require_core(), 1));
64
66
 
65
67
  // ../../node_modules/@math.gl/core/dist/lib/common.js
66
68
  var RADIANS_TO_DEGREES = 1 / Math.PI * 180;
@@ -4552,7 +4554,7 @@ var __exports__ = (() => {
4552
4554
  };
4553
4555
  _defineProperty(Ellipsoid, "WGS84", new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z));
4554
4556
 
4555
- // node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
4557
+ // ../../node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
4556
4558
  function getHiResTimestamp() {
4557
4559
  let timestamp;
4558
4560
  if (typeof window !== "undefined" && window.performance) {
@@ -4566,7 +4568,7 @@ var __exports__ = (() => {
4566
4568
  return timestamp;
4567
4569
  }
4568
4570
 
4569
- // node_modules/@probe.gl/stats/dist/lib/stat.js
4571
+ // ../../node_modules/@probe.gl/stats/dist/lib/stat.js
4570
4572
  var Stat = class {
4571
4573
  constructor(name, type) {
4572
4574
  _defineProperty(this, "name", void 0);
@@ -4678,7 +4680,7 @@ var __exports__ = (() => {
4678
4680
  }
4679
4681
  };
4680
4682
 
4681
- // node_modules/@probe.gl/stats/dist/lib/stats.js
4683
+ // ../../node_modules/@probe.gl/stats/dist/lib/stats.js
4682
4684
  var Stats = class {
4683
4685
  constructor(options) {
4684
4686
  _defineProperty(this, "id", void 0);
@@ -4750,197 +4752,6 @@ var __exports__ = (() => {
4750
4752
  }
4751
4753
  }
4752
4754
 
4753
- // ../loader-utils/node_modules/@probe.gl/stats/dist/utils/hi-res-timestamp.js
4754
- function getHiResTimestamp2() {
4755
- let timestamp;
4756
- if (typeof window !== "undefined" && window.performance) {
4757
- timestamp = window.performance.now();
4758
- } else if (typeof process !== "undefined" && process.hrtime) {
4759
- const timeParts = process.hrtime();
4760
- timestamp = timeParts[0] * 1e3 + timeParts[1] / 1e6;
4761
- } else {
4762
- timestamp = Date.now();
4763
- }
4764
- return timestamp;
4765
- }
4766
-
4767
- // ../loader-utils/node_modules/@probe.gl/stats/dist/lib/stat.js
4768
- var Stat2 = class {
4769
- constructor(name, type) {
4770
- _defineProperty(this, "name", void 0);
4771
- _defineProperty(this, "type", void 0);
4772
- _defineProperty(this, "sampleSize", 1);
4773
- _defineProperty(this, "time", 0);
4774
- _defineProperty(this, "count", 0);
4775
- _defineProperty(this, "samples", 0);
4776
- _defineProperty(this, "lastTiming", 0);
4777
- _defineProperty(this, "lastSampleTime", 0);
4778
- _defineProperty(this, "lastSampleCount", 0);
4779
- _defineProperty(this, "_count", 0);
4780
- _defineProperty(this, "_time", 0);
4781
- _defineProperty(this, "_samples", 0);
4782
- _defineProperty(this, "_startTime", 0);
4783
- _defineProperty(this, "_timerPending", false);
4784
- this.name = name;
4785
- this.type = type;
4786
- this.reset();
4787
- }
4788
- reset() {
4789
- this.time = 0;
4790
- this.count = 0;
4791
- this.samples = 0;
4792
- this.lastTiming = 0;
4793
- this.lastSampleTime = 0;
4794
- this.lastSampleCount = 0;
4795
- this._count = 0;
4796
- this._time = 0;
4797
- this._samples = 0;
4798
- this._startTime = 0;
4799
- this._timerPending = false;
4800
- return this;
4801
- }
4802
- setSampleSize(samples) {
4803
- this.sampleSize = samples;
4804
- return this;
4805
- }
4806
- incrementCount() {
4807
- this.addCount(1);
4808
- return this;
4809
- }
4810
- decrementCount() {
4811
- this.subtractCount(1);
4812
- return this;
4813
- }
4814
- addCount(value) {
4815
- this._count += value;
4816
- this._samples++;
4817
- this._checkSampling();
4818
- return this;
4819
- }
4820
- subtractCount(value) {
4821
- this._count -= value;
4822
- this._samples++;
4823
- this._checkSampling();
4824
- return this;
4825
- }
4826
- addTime(time) {
4827
- this._time += time;
4828
- this.lastTiming = time;
4829
- this._samples++;
4830
- this._checkSampling();
4831
- return this;
4832
- }
4833
- timeStart() {
4834
- this._startTime = getHiResTimestamp2();
4835
- this._timerPending = true;
4836
- return this;
4837
- }
4838
- timeEnd() {
4839
- if (!this._timerPending) {
4840
- return this;
4841
- }
4842
- this.addTime(getHiResTimestamp2() - this._startTime);
4843
- this._timerPending = false;
4844
- this._checkSampling();
4845
- return this;
4846
- }
4847
- getSampleAverageCount() {
4848
- return this.sampleSize > 0 ? this.lastSampleCount / this.sampleSize : 0;
4849
- }
4850
- getSampleAverageTime() {
4851
- return this.sampleSize > 0 ? this.lastSampleTime / this.sampleSize : 0;
4852
- }
4853
- getSampleHz() {
4854
- return this.lastSampleTime > 0 ? this.sampleSize / (this.lastSampleTime / 1e3) : 0;
4855
- }
4856
- getAverageCount() {
4857
- return this.samples > 0 ? this.count / this.samples : 0;
4858
- }
4859
- getAverageTime() {
4860
- return this.samples > 0 ? this.time / this.samples : 0;
4861
- }
4862
- getHz() {
4863
- return this.time > 0 ? this.samples / (this.time / 1e3) : 0;
4864
- }
4865
- _checkSampling() {
4866
- if (this._samples === this.sampleSize) {
4867
- this.lastSampleTime = this._time;
4868
- this.lastSampleCount = this._count;
4869
- this.count += this._count;
4870
- this.time += this._time;
4871
- this.samples += this._samples;
4872
- this._time = 0;
4873
- this._count = 0;
4874
- this._samples = 0;
4875
- }
4876
- }
4877
- };
4878
-
4879
- // ../loader-utils/node_modules/@probe.gl/stats/dist/lib/stats.js
4880
- var Stats2 = class {
4881
- constructor(options) {
4882
- _defineProperty(this, "id", void 0);
4883
- _defineProperty(this, "stats", {});
4884
- this.id = options.id;
4885
- this.stats = {};
4886
- this._initializeStats(options.stats);
4887
- Object.seal(this);
4888
- }
4889
- get(name) {
4890
- let type = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : "count";
4891
- return this._getOrCreate({
4892
- name,
4893
- type
4894
- });
4895
- }
4896
- get size() {
4897
- return Object.keys(this.stats).length;
4898
- }
4899
- reset() {
4900
- for (const stat of Object.values(this.stats)) {
4901
- stat.reset();
4902
- }
4903
- return this;
4904
- }
4905
- forEach(fn) {
4906
- for (const stat of Object.values(this.stats)) {
4907
- fn(stat);
4908
- }
4909
- }
4910
- getTable() {
4911
- const table = {};
4912
- this.forEach((stat) => {
4913
- table[stat.name] = {
4914
- time: stat.time || 0,
4915
- count: stat.count || 0,
4916
- average: stat.getAverageTime() || 0,
4917
- hz: stat.getHz() || 0
4918
- };
4919
- });
4920
- return table;
4921
- }
4922
- _initializeStats() {
4923
- let stats = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : [];
4924
- stats.forEach((stat) => this._getOrCreate(stat));
4925
- }
4926
- _getOrCreate(stat) {
4927
- const {
4928
- name,
4929
- type
4930
- } = stat;
4931
- let result = this.stats[name];
4932
- if (!result) {
4933
- if (stat instanceof Stat2) {
4934
- result = stat;
4935
- } else {
4936
- result = new Stat2(name, type);
4937
- }
4938
- this.stats[name] = result;
4939
- }
4940
- return result;
4941
- }
4942
- };
4943
-
4944
4755
  // ../loader-utils/src/lib/request-utils/request-scheduler.ts
4945
4756
  var STAT_QUEUED_REQUESTS = "Queued Requests";
4946
4757
  var STAT_ACTIVE_REQUESTS = "Active Requests";
@@ -4949,43 +4760,58 @@ var __exports__ = (() => {
4949
4760
  var STAT_ACTIVE_REQUESTS_EVER = "Active Requests Ever";
4950
4761
  var DEFAULT_PROPS = {
4951
4762
  id: "request-scheduler",
4763
+ /** Specifies if the request scheduler should throttle incoming requests, mainly for comparative testing. */
4952
4764
  throttleRequests: true,
4953
- maxRequests: 6
4765
+ /** The maximum number of simultaneous active requests. Un-throttled requests do not observe this limit. */
4766
+ maxRequests: 6,
4767
+ /**
4768
+ * Specifies a debounce time, in milliseconds. All requests are queued, until no new requests have
4769
+ * been added to the queue for this amount of time.
4770
+ */
4771
+ debounceTime: 0
4954
4772
  };
4955
4773
  var RequestScheduler = class {
4774
+ props;
4775
+ stats;
4956
4776
  activeRequestCount = 0;
4777
+ /** Tracks the number of active requests and prioritizes/cancels queued requests. */
4957
4778
  requestQueue = [];
4958
4779
  requestMap = /* @__PURE__ */ new Map();
4959
- deferredUpdate = null;
4780
+ updateTimer = null;
4960
4781
  constructor(props = {}) {
4961
- this.props = {
4962
- ...DEFAULT_PROPS,
4963
- ...props
4964
- };
4965
- this.stats = new Stats2({
4966
- id: this.props.id
4967
- });
4782
+ this.props = { ...DEFAULT_PROPS, ...props };
4783
+ this.stats = new Stats({ id: this.props.id });
4968
4784
  this.stats.get(STAT_QUEUED_REQUESTS);
4969
4785
  this.stats.get(STAT_ACTIVE_REQUESTS);
4970
4786
  this.stats.get(STAT_CANCELLED_REQUESTS);
4971
4787
  this.stats.get(STAT_QUEUED_REQUESTS_EVER);
4972
4788
  this.stats.get(STAT_ACTIVE_REQUESTS_EVER);
4973
4789
  }
4790
+ /**
4791
+ * Called by an application that wants to issue a request, without having it deeply queued by the browser
4792
+ *
4793
+ * When the returned promise resolved, it is OK for the application to issue a request.
4794
+ * The promise resolves to an object that contains a `done` method.
4795
+ * When the application's request has completed (or failed), the application must call the `done` function
4796
+ *
4797
+ * @param handle
4798
+ * @param getPriority will be called when request "slots" open up,
4799
+ * allowing the caller to update priority or cancel the request
4800
+ * Highest priority executes first, priority < 0 cancels the request
4801
+ * @returns a promise
4802
+ * - resolves to a object (with a `done` field) when the request can be issued without queueing,
4803
+ * - resolves to `null` if the request has been cancelled (by the callback return < 0).
4804
+ * In this case the application should not issue the request
4805
+ */
4974
4806
  scheduleRequest(handle, getPriority = () => 0) {
4975
4807
  if (!this.props.throttleRequests) {
4976
- return Promise.resolve({
4977
- done: () => {
4978
- }
4979
- });
4808
+ return Promise.resolve({ done: () => {
4809
+ } });
4980
4810
  }
4981
4811
  if (this.requestMap.has(handle)) {
4982
4812
  return this.requestMap.get(handle);
4983
4813
  }
4984
- const request = {
4985
- handle,
4986
- priority: 0,
4987
- getPriority
4988
- };
4814
+ const request = { handle, priority: 0, getPriority };
4989
4815
  const promise = new Promise((resolve2) => {
4990
4816
  request.resolve = resolve2;
4991
4817
  return request;
@@ -4995,11 +4821,9 @@ var __exports__ = (() => {
4995
4821
  this._issueNewRequests();
4996
4822
  return promise;
4997
4823
  }
4824
+ // PRIVATE
4998
4825
  _issueRequest(request) {
4999
- const {
5000
- handle,
5001
- resolve: resolve2
5002
- } = request;
4826
+ const { handle, resolve: resolve2 } = request;
5003
4827
  let isDone = false;
5004
4828
  const done = () => {
5005
4829
  if (!isDone) {
@@ -5010,19 +4834,21 @@ var __exports__ = (() => {
5010
4834
  }
5011
4835
  };
5012
4836
  this.activeRequestCount++;
5013
- return resolve2 ? resolve2({
5014
- done
5015
- }) : Promise.resolve({
5016
- done
5017
- });
4837
+ return resolve2 ? resolve2({ done }) : Promise.resolve({ done });
5018
4838
  }
4839
+ /** We check requests asynchronously, to prevent multiple updates */
5019
4840
  _issueNewRequests() {
5020
- if (!this.deferredUpdate) {
5021
- this.deferredUpdate = setTimeout(() => this._issueNewRequestsAsync(), 0);
4841
+ if (this.updateTimer !== null) {
4842
+ clearTimeout(this.updateTimer);
5022
4843
  }
4844
+ this.updateTimer = setTimeout(() => this._issueNewRequestsAsync(), this.props.debounceTime);
5023
4845
  }
4846
+ /** Refresh all requests */
5024
4847
  _issueNewRequestsAsync() {
5025
- this.deferredUpdate = null;
4848
+ if (this.updateTimer !== null) {
4849
+ clearTimeout(this.updateTimer);
4850
+ }
4851
+ this.updateTimer = null;
5026
4852
  const freeSlots = Math.max(this.props.maxRequests - this.activeRequestCount, 0);
5027
4853
  if (freeSlots === 0) {
5028
4854
  return;
@@ -5035,6 +4861,7 @@ var __exports__ = (() => {
5035
4861
  }
5036
4862
  }
5037
4863
  }
4864
+ /** Ensure all requests have updated priorities, and that no longer valid requests are cancelled */
5038
4865
  _updateAllRequests() {
5039
4866
  const requestQueue = this.requestQueue;
5040
4867
  for (let i = 0; i < requestQueue.length; ++i) {
@@ -5047,6 +4874,7 @@ var __exports__ = (() => {
5047
4874
  }
5048
4875
  requestQueue.sort((a, b) => a.priority - b.priority);
5049
4876
  }
4877
+ /** Update a single request by calling the callback */
5050
4878
  _updateRequest(request) {
5051
4879
  request.priority = request.getPriority(request.handle);
5052
4880
  if (request.priority < 0) {
@@ -5202,6 +5030,9 @@ var __exports__ = (() => {
5202
5030
 
5203
5031
  // src/utils/doubly-linked-list-node.ts
5204
5032
  var DoublyLinkedListNode = class {
5033
+ item;
5034
+ previous;
5035
+ next;
5205
5036
  constructor(item, previous, next) {
5206
5037
  this.item = item;
5207
5038
  this.previous = previous;
@@ -5217,6 +5048,11 @@ var __exports__ = (() => {
5217
5048
  get length() {
5218
5049
  return this._length;
5219
5050
  }
5051
+ /**
5052
+ * Adds the item to the end of the list
5053
+ * @param {*} [item]
5054
+ * @return {DoublyLinkedListNode}
5055
+ */
5220
5056
  add(item) {
5221
5057
  const node = new DoublyLinkedListNode(item, this.tail, null);
5222
5058
  if (this.tail) {
@@ -5229,6 +5065,10 @@ var __exports__ = (() => {
5229
5065
  ++this._length;
5230
5066
  return node;
5231
5067
  }
5068
+ /**
5069
+ * Removes the given node from the list
5070
+ * @param {DoublyLinkedListNode} node
5071
+ */
5232
5072
  remove(node) {
5233
5073
  if (!node) {
5234
5074
  return;
@@ -5250,6 +5090,11 @@ var __exports__ = (() => {
5250
5090
  node.previous = null;
5251
5091
  --this._length;
5252
5092
  }
5093
+ /**
5094
+ * Moves nextNode after node
5095
+ * @param {DoublyLinkedListNode} node
5096
+ * @param {DoublyLinkedListNode} nextNode
5097
+ */
5253
5098
  splice(node, nextNode) {
5254
5099
  if (node === nextNode) {
5255
5100
  return;
@@ -5273,6 +5118,9 @@ var __exports__ = (() => {
5273
5118
 
5274
5119
  // src/tileset/tileset-cache.ts
5275
5120
  var TilesetCache = class {
5121
+ _list;
5122
+ _sentinel;
5123
+ _trimTiles;
5276
5124
  constructor() {
5277
5125
  this._list = new DoublyLinkedList();
5278
5126
  this._sentinel = this._list.add("sentinel");
@@ -5328,15 +5176,10 @@ var __exports__ = (() => {
5328
5176
  function calculateTransformProps(tileHeader, tile) {
5329
5177
  assert2(tileHeader);
5330
5178
  assert2(tile);
5331
- const {
5332
- rtcCenter,
5333
- gltfUpAxis
5334
- } = tile;
5179
+ const { rtcCenter, gltfUpAxis } = tile;
5335
5180
  const {
5336
5181
  computedTransform,
5337
- boundingVolume: {
5338
- center
5339
- }
5182
+ boundingVolume: { center }
5340
5183
  } = tileHeader;
5341
5184
  let modelMatrix = new Matrix4(computedTransform);
5342
5185
  if (rtcCenter) {
@@ -5362,7 +5205,10 @@ var __exports__ = (() => {
5362
5205
  const cartesianOrigin = new Vector3(center);
5363
5206
  tile.cartesianModelMatrix = modelMatrix;
5364
5207
  tile.cartesianOrigin = cartesianOrigin;
5365
- const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(cartesianOrigin, new Vector3());
5208
+ const cartographicOrigin = Ellipsoid.WGS84.cartesianToCartographic(
5209
+ cartesianOrigin,
5210
+ new Vector3()
5211
+ );
5366
5212
  const fromFixedFrameMatrix = Ellipsoid.WGS84.eastNorthUpToFixedFrame(cartesianOrigin);
5367
5213
  const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
5368
5214
  tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
@@ -5825,31 +5671,35 @@ var __exports__ = (() => {
5825
5671
  // src/tileset/helpers/frame-state.ts
5826
5672
  var scratchVector8 = new Vector3();
5827
5673
  var scratchPosition3 = new Vector3();
5828
- var cullingVolume = new CullingVolume([new Plane(), new Plane(), new Plane(), new Plane(), new Plane(), new Plane()]);
5674
+ var cullingVolume = new CullingVolume([
5675
+ new Plane(),
5676
+ new Plane(),
5677
+ new Plane(),
5678
+ new Plane(),
5679
+ new Plane(),
5680
+ new Plane()
5681
+ ]);
5829
5682
  function getFrameState(viewport, frameNumber) {
5830
- const {
5831
- cameraDirection,
5832
- cameraUp,
5833
- height
5834
- } = viewport;
5835
- const {
5836
- metersPerUnit
5837
- } = viewport.distanceScales;
5683
+ const { cameraDirection, cameraUp, height } = viewport;
5684
+ const { metersPerUnit } = viewport.distanceScales;
5838
5685
  const viewportCenterCartesian = worldToCartesian(viewport, viewport.center);
5839
5686
  const enuToFixedTransform = Ellipsoid.WGS84.eastNorthUpToFixedFrame(viewportCenterCartesian);
5840
5687
  const cameraPositionCartographic = viewport.unprojectPosition(viewport.cameraPosition);
5841
- const cameraPositionCartesian2 = Ellipsoid.WGS84.cartographicToCartesian(cameraPositionCartographic, new Vector3());
5842
- const cameraDirectionCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))).normalize();
5843
- const cameraUpCartesian = new Vector3(enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))).normalize();
5688
+ const cameraPositionCartesian2 = Ellipsoid.WGS84.cartographicToCartesian(
5689
+ cameraPositionCartographic,
5690
+ new Vector3()
5691
+ );
5692
+ const cameraDirectionCartesian = new Vector3(
5693
+ // @ts-ignore
5694
+ enuToFixedTransform.transformAsVector(new Vector3(cameraDirection).scale(metersPerUnit))
5695
+ ).normalize();
5696
+ const cameraUpCartesian = new Vector3(
5697
+ // @ts-ignore
5698
+ enuToFixedTransform.transformAsVector(new Vector3(cameraUp).scale(metersPerUnit))
5699
+ ).normalize();
5844
5700
  commonSpacePlanesToWGS84(viewport);
5845
5701
  const ViewportClass = viewport.constructor;
5846
- const {
5847
- longitude,
5848
- latitude,
5849
- width,
5850
- bearing,
5851
- zoom
5852
- } = viewport;
5702
+ const { longitude, latitude, width, bearing, zoom } = viewport;
5853
5703
  const topDownViewport = new ViewportClass({
5854
5704
  longitude,
5855
5705
  latitude,
@@ -5870,7 +5720,9 @@ var __exports__ = (() => {
5870
5720
  height,
5871
5721
  cullingVolume,
5872
5722
  frameNumber,
5723
+ // TODO: This can be the same between updates, what number is unique for between updates?
5873
5724
  sseDenominator: 1.15
5725
+ // Assumes fovy = 60 degrees
5874
5726
  };
5875
5727
  }
5876
5728
  function limitSelectedTiles(tiles, frameState, maximumTilesSelected) {
@@ -5878,10 +5730,7 @@ var __exports__ = (() => {
5878
5730
  return [tiles, []];
5879
5731
  }
5880
5732
  const tuples = [];
5881
- const {
5882
- longitude: viewportLongitude,
5883
- latitude: viewportLatitude
5884
- } = frameState.viewport;
5733
+ const { longitude: viewportLongitude, latitude: viewportLatitude } = frameState.viewport;
5885
5734
  for (const [index, tile] of tiles.entries()) {
5886
5735
  const [longitude, latitude] = tile.header.mbs;
5887
5736
  const deltaLon = Math.abs(viewportLongitude - longitude);
@@ -5906,7 +5755,10 @@ var __exports__ = (() => {
5906
5755
  const nearCenterCartesian = worldToCartesian(viewport, nearCenterCommon);
5907
5756
  const cameraCartesian = worldToCartesian(viewport, viewport.cameraPosition, scratchPosition3);
5908
5757
  let i = 0;
5909
- cullingVolume.planes[i++].fromPointNormal(nearCenterCartesian, scratchVector8.copy(nearCenterCartesian).subtract(cameraCartesian));
5758
+ cullingVolume.planes[i++].fromPointNormal(
5759
+ nearCenterCartesian,
5760
+ scratchVector8.copy(nearCenterCartesian).subtract(cameraCartesian)
5761
+ );
5910
5762
  for (const dir in frustumPlanes) {
5911
5763
  if (dir === "near") {
5912
5764
  continue;
@@ -5914,7 +5766,11 @@ var __exports__ = (() => {
5914
5766
  const plane = frustumPlanes[dir];
5915
5767
  const posCommon = closestPointOnPlane(plane, nearCenterCommon, scratchPosition3);
5916
5768
  const cartesianPos = worldToCartesian(viewport, posCommon, scratchPosition3);
5917
- cullingVolume.planes[i++].fromPointNormal(cartesianPos, scratchVector8.copy(nearCenterCartesian).subtract(cartesianPos));
5769
+ cullingVolume.planes[i++].fromPointNormal(
5770
+ cartesianPos,
5771
+ // Want the normal to point into the frustum since that's what culling expects
5772
+ scratchVector8.copy(nearCenterCartesian).subtract(cartesianPos)
5773
+ );
5918
5774
  }
5919
5775
  }
5920
5776
  function closestPointOnPlane(plane, refPoint, out = new Vector3()) {
@@ -5934,21 +5790,14 @@ var __exports__ = (() => {
5934
5790
  var scratchVector9 = new Vector3();
5935
5791
  function getZoomFromBoundingVolume(boundingVolume, cartorgraphicCenter) {
5936
5792
  if (boundingVolume instanceof OrientedBoundingBox) {
5937
- const {
5938
- halfAxes
5939
- } = boundingVolume;
5793
+ const { halfAxes } = boundingVolume;
5940
5794
  const obbSize = getObbSize(halfAxes);
5941
5795
  return Math.log2(WGS84_RADIUS_Z2 / (obbSize + cartorgraphicCenter[2]));
5942
5796
  } else if (boundingVolume instanceof BoundingSphere) {
5943
- const {
5944
- radius
5945
- } = boundingVolume;
5797
+ const { radius } = boundingVolume;
5946
5798
  return Math.log2(WGS84_RADIUS_Z2 / (radius + cartorgraphicCenter[2]));
5947
5799
  } else if (boundingVolume.width && boundingVolume.height) {
5948
- const {
5949
- width,
5950
- height
5951
- } = boundingVolume;
5800
+ const { width, height } = boundingVolume;
5952
5801
  const zoomX = Math.log2(WGS84_RADIUS_X2 / width);
5953
5802
  const zoomY = Math.log2(WGS84_RADIUS_Y2 / height);
5954
5803
  return (zoomX + zoomY) / 2;
@@ -5956,20 +5805,22 @@ var __exports__ = (() => {
5956
5805
  return 1;
5957
5806
  }
5958
5807
  function getZoomFromFullExtent(fullExtent, cartorgraphicCenter, cartesianCenter) {
5959
- Ellipsoid.WGS84.cartographicToCartesian([fullExtent.xmax, fullExtent.ymax, fullExtent.zmax], scratchVector9);
5960
- const extentSize = Math.sqrt(Math.pow(scratchVector9[0] - cartesianCenter[0], 2) + Math.pow(scratchVector9[1] - cartesianCenter[1], 2) + Math.pow(scratchVector9[2] - cartesianCenter[2], 2));
5808
+ Ellipsoid.WGS84.cartographicToCartesian(
5809
+ [fullExtent.xmax, fullExtent.ymax, fullExtent.zmax],
5810
+ scratchVector9
5811
+ );
5812
+ const extentSize = Math.sqrt(
5813
+ Math.pow(scratchVector9[0] - cartesianCenter[0], 2) + Math.pow(scratchVector9[1] - cartesianCenter[1], 2) + Math.pow(scratchVector9[2] - cartesianCenter[2], 2)
5814
+ );
5961
5815
  return Math.log2(WGS84_RADIUS_Z2 / (extentSize + cartorgraphicCenter[2]));
5962
5816
  }
5963
5817
  function getZoomFromExtent(extent, cartorgraphicCenter, cartesianCenter) {
5964
5818
  const [xmin, ymin, xmax, ymax] = extent;
5965
- return getZoomFromFullExtent({
5966
- xmin,
5967
- xmax,
5968
- ymin,
5969
- ymax,
5970
- zmin: 0,
5971
- zmax: 0
5972
- }, cartorgraphicCenter, cartesianCenter);
5819
+ return getZoomFromFullExtent(
5820
+ { xmin, xmax, ymin, ymax, zmin: 0, zmax: 0 },
5821
+ cartorgraphicCenter,
5822
+ cartesianCenter
5823
+ );
5973
5824
  }
5974
5825
  function getObbSize(halfAxes) {
5975
5826
  halfAxes.getColumn(0, scratchVector9);
@@ -5986,34 +5837,40 @@ var __exports__ = (() => {
5986
5837
  // src/constants.ts
5987
5838
  var TILE_CONTENT_STATE = {
5988
5839
  UNLOADED: 0,
5840
+ // Has never been requested
5989
5841
  LOADING: 1,
5842
+ // Is waiting on a pending request
5990
5843
  PROCESSING: 2,
5844
+ // Request received. Contents are being processed for rendering. Depending on the content, it might make its own requests for external data.
5991
5845
  READY: 3,
5846
+ // Ready to render.
5992
5847
  EXPIRED: 4,
5848
+ // Is expired and will be unloaded once new content is loaded.
5993
5849
  FAILED: 5
5850
+ // Request failed.
5994
5851
  };
5995
- var TILE_REFINEMENT = function(TILE_REFINEMENT2) {
5852
+ var TILE_REFINEMENT = /* @__PURE__ */ ((TILE_REFINEMENT2) => {
5996
5853
  TILE_REFINEMENT2[TILE_REFINEMENT2["ADD"] = 1] = "ADD";
5997
5854
  TILE_REFINEMENT2[TILE_REFINEMENT2["REPLACE"] = 2] = "REPLACE";
5998
5855
  return TILE_REFINEMENT2;
5999
- }({});
6000
- var TILE_TYPE = function(TILE_TYPE2) {
5856
+ })(TILE_REFINEMENT || {});
5857
+ var TILE_TYPE = /* @__PURE__ */ ((TILE_TYPE2) => {
6001
5858
  TILE_TYPE2["EMPTY"] = "empty";
6002
5859
  TILE_TYPE2["SCENEGRAPH"] = "scenegraph";
6003
5860
  TILE_TYPE2["POINTCLOUD"] = "pointcloud";
6004
5861
  TILE_TYPE2["MESH"] = "mesh";
6005
5862
  return TILE_TYPE2;
6006
- }({});
6007
- var TILESET_TYPE = function(TILESET_TYPE2) {
5863
+ })(TILE_TYPE || {});
5864
+ var TILESET_TYPE = /* @__PURE__ */ ((TILESET_TYPE2) => {
6008
5865
  TILESET_TYPE2["I3S"] = "I3S";
6009
5866
  TILESET_TYPE2["TILES3D"] = "TILES3D";
6010
5867
  return TILESET_TYPE2;
6011
- }({});
6012
- var LOD_METRIC_TYPE = function(LOD_METRIC_TYPE2) {
5868
+ })(TILESET_TYPE || {});
5869
+ var LOD_METRIC_TYPE = /* @__PURE__ */ ((LOD_METRIC_TYPE2) => {
6013
5870
  LOD_METRIC_TYPE2["GEOMETRIC_ERROR"] = "geometricError";
6014
5871
  LOD_METRIC_TYPE2["MAX_SCREEN_THRESHOLD"] = "maxScreenThreshold";
6015
5872
  return LOD_METRIC_TYPE2;
6016
- }({});
5873
+ })(LOD_METRIC_TYPE || {});
6017
5874
  var TILE3D_OPTIMIZATION_HINT = {
6018
5875
  NOT_COMPUTED: -1,
6019
5876
  USE_OPTIMIZATION: 1,
@@ -6051,7 +5908,10 @@ var __exports__ = (() => {
6051
5908
  }
6052
5909
  if (boundingVolumeHeader.region) {
6053
5910
  const [west, south, east, north, minHeight, maxHeight] = boundingVolumeHeader.region;
6054
- return [[degrees(west), degrees(south), minHeight], [degrees(east), degrees(north), maxHeight]];
5911
+ return [
5912
+ [degrees(west), degrees(south), minHeight],
5913
+ [degrees(east), degrees(north), maxHeight]
5914
+ ];
6055
5915
  }
6056
5916
  if (boundingVolumeHeader.sphere) {
6057
5917
  return boundingSphereToCartographicBounds(boundingVolume);
@@ -6082,7 +5942,17 @@ var __exports__ = (() => {
6082
5942
  const xAxis = transform.transformAsVector(origin.slice(0, 3));
6083
5943
  const yAxis = transform.transformAsVector(origin.slice(3, 6));
6084
5944
  const zAxis = transform.transformAsVector(origin.slice(6, 9));
6085
- const halfAxes = new Matrix3([xAxis[0], xAxis[1], xAxis[2], yAxis[0], yAxis[1], yAxis[2], zAxis[0], zAxis[1], zAxis[2]]);
5945
+ const halfAxes = new Matrix3([
5946
+ xAxis[0],
5947
+ xAxis[1],
5948
+ xAxis[2],
5949
+ yAxis[0],
5950
+ yAxis[1],
5951
+ yAxis[2],
5952
+ zAxis[0],
5953
+ zAxis[1],
5954
+ zAxis[2]
5955
+ ]);
6086
5956
  if (defined(result)) {
6087
5957
  result.center = center;
6088
5958
  result.halfAxes = halfAxes;
@@ -6105,20 +5975,41 @@ var __exports__ = (() => {
6105
5975
  }
6106
5976
  function createObbFromRegion(region) {
6107
5977
  const [west, south, east, north, minHeight, maxHeight] = region;
6108
- const northWest = Ellipsoid.WGS84.cartographicToCartesian([degrees(west), degrees(north), minHeight], scratchNorthWest);
6109
- const southEast = Ellipsoid.WGS84.cartographicToCartesian([degrees(east), degrees(south), maxHeight], scratchSouthEast);
5978
+ const northWest = Ellipsoid.WGS84.cartographicToCartesian(
5979
+ [degrees(west), degrees(north), minHeight],
5980
+ scratchNorthWest
5981
+ );
5982
+ const southEast = Ellipsoid.WGS84.cartographicToCartesian(
5983
+ [degrees(east), degrees(south), maxHeight],
5984
+ scratchSouthEast
5985
+ );
6110
5986
  const centerInCartesian = new Vector3().addVectors(northWest, southEast).multiplyByScalar(0.5);
6111
5987
  Ellipsoid.WGS84.cartesianToCartographic(centerInCartesian, scratchCenter);
6112
- Ellipsoid.WGS84.cartographicToCartesian([degrees(east), scratchCenter[1], scratchCenter[2]], scratchXAxis);
6113
- Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], degrees(north), scratchCenter[2]], scratchYAxis);
6114
- Ellipsoid.WGS84.cartographicToCartesian([scratchCenter[0], scratchCenter[1], maxHeight], scratchZAxis);
6115
- return createBox([...centerInCartesian, ...scratchXAxis.subtract(centerInCartesian), ...scratchYAxis.subtract(centerInCartesian), ...scratchZAxis.subtract(centerInCartesian)], new Matrix4());
5988
+ Ellipsoid.WGS84.cartographicToCartesian(
5989
+ [degrees(east), scratchCenter[1], scratchCenter[2]],
5990
+ scratchXAxis
5991
+ );
5992
+ Ellipsoid.WGS84.cartographicToCartesian(
5993
+ [scratchCenter[0], degrees(north), scratchCenter[2]],
5994
+ scratchYAxis
5995
+ );
5996
+ Ellipsoid.WGS84.cartographicToCartesian(
5997
+ [scratchCenter[0], scratchCenter[1], maxHeight],
5998
+ scratchZAxis
5999
+ );
6000
+ return createBox(
6001
+ [
6002
+ ...centerInCartesian,
6003
+ ...scratchXAxis.subtract(centerInCartesian),
6004
+ ...scratchYAxis.subtract(centerInCartesian),
6005
+ ...scratchZAxis.subtract(centerInCartesian)
6006
+ ],
6007
+ new Matrix4()
6008
+ );
6116
6009
  }
6117
6010
  function orientedBoundingBoxToCartographicBounds(boundingVolume) {
6118
6011
  const result = emptyCartographicBounds();
6119
- const {
6120
- halfAxes
6121
- } = boundingVolume;
6012
+ const { halfAxes } = boundingVolume;
6122
6013
  const xAxis = new Vector3(halfAxes.getColumn(0));
6123
6014
  const yAxis = new Vector3(halfAxes.getColumn(1));
6124
6015
  const zAxis = new Vector3(halfAxes.getColumn(2));
@@ -6140,10 +6031,7 @@ var __exports__ = (() => {
6140
6031
  }
6141
6032
  function boundingSphereToCartographicBounds(boundingVolume) {
6142
6033
  const result = emptyCartographicBounds();
6143
- const {
6144
- center,
6145
- radius
6146
- } = boundingVolume;
6034
+ const { center, radius } = boundingVolume;
6147
6035
  const point = Ellipsoid.WGS84.scaleToGeodeticSurface(center, scratchPoint);
6148
6036
  let zAxis;
6149
6037
  if (point) {
@@ -6170,7 +6058,10 @@ var __exports__ = (() => {
6170
6058
  return result;
6171
6059
  }
6172
6060
  function emptyCartographicBounds() {
6173
- return [[Infinity, Infinity, Infinity], [-Infinity, -Infinity, -Infinity]];
6061
+ return [
6062
+ [Infinity, Infinity, Infinity],
6063
+ [-Infinity, -Infinity, -Infinity]
6064
+ ];
6174
6065
  }
6175
6066
  function addToCartographicBounds(target, cartesian) {
6176
6067
  Ellipsoid.WGS84.cartesianToCartographic(cartesian, scratchPoint);
@@ -6210,13 +6101,8 @@ var __exports__ = (() => {
6210
6101
  return 0;
6211
6102
  }
6212
6103
  const distance2 = Math.max(tile._distanceToCamera, 1e-7);
6213
- const {
6214
- height,
6215
- sseDenominator
6216
- } = frameState;
6217
- const {
6218
- viewDistanceScale
6219
- } = tileset.options;
6104
+ const { height, sseDenominator } = frameState;
6105
+ const { viewDistanceScale } = tileset.options;
6220
6106
  let error = lodMetricValue * height * (viewDistanceScale || 1) / (distance2 * sseDenominator);
6221
6107
  error -= getDynamicScreenSpaceError(tileset, distance2);
6222
6108
  return error;
@@ -6246,9 +6132,7 @@ var __exports__ = (() => {
6246
6132
  return "OUT";
6247
6133
  }
6248
6134
  function getProjectedRadius(tile, frameState) {
6249
- const {
6250
- topDownViewport: viewport
6251
- } = frameState;
6135
+ const { topDownViewport: viewport } = frameState;
6252
6136
  const mbsLat = tile.header.mbs[1];
6253
6137
  const mbsLon = tile.header.mbs[0];
6254
6138
  const mbsZ = tile.header.mbs[2];
@@ -6260,16 +6144,22 @@ var __exports__ = (() => {
6260
6144
  Ellipsoid.WGS84.eastNorthUpToFixedFrame(mbsCenterCartesian, enuToCartesianMatrix);
6261
6145
  cartesianToEnuMatrix.copy(enuToCartesianMatrix).invert();
6262
6146
  cameraPositionEnu.copy(cameraPositionCartesian).transform(cartesianToEnuMatrix);
6263
- const projection = Math.sqrt(cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]);
6147
+ const projection = Math.sqrt(
6148
+ cameraPositionEnu[0] * cameraPositionEnu[0] + cameraPositionEnu[1] * cameraPositionEnu[1]
6149
+ );
6264
6150
  const extraZ = projection * projection / cameraPositionEnu[2];
6265
6151
  extraVertexEnu.copy([cameraPositionEnu[0], cameraPositionEnu[1], extraZ]);
6266
6152
  const extraVertexCartesian = extraVertexEnu.transform(enuToCartesianMatrix);
6267
6153
  const extraVectorCartesian = extraVertexCartesian.subtract(mbsCenterCartesian).normalize();
6268
6154
  const radiusVector = toEye.cross(extraVectorCartesian).normalize().scale(mbsR);
6269
6155
  const sphereMbsBorderVertexCartesian = radiusVector.add(mbsCenterCartesian);
6270
- const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(sphereMbsBorderVertexCartesian);
6156
+ const sphereMbsBorderVertexCartographic = Ellipsoid.WGS84.cartesianToCartographic(
6157
+ sphereMbsBorderVertexCartesian
6158
+ );
6271
6159
  const projectedOrigin = viewport.project([mbsLon, mbsLat, mbsZ]);
6272
- const projectedMbsBorderVertex = viewport.project(sphereMbsBorderVertexCartographic);
6160
+ const projectedMbsBorderVertex = viewport.project(
6161
+ sphereMbsBorderVertexCartographic
6162
+ );
6273
6163
  const projectedRadius = projectedOriginVector.copy(projectedOrigin).subtract(projectedMbsBorderVertex).magnitude();
6274
6164
  return projectedRadius;
6275
6165
  }
@@ -6284,10 +6174,19 @@ var __exports__ = (() => {
6284
6174
  // src/utils/managed-array.ts
6285
6175
  var ManagedArray = class {
6286
6176
  _map = /* @__PURE__ */ new Map();
6177
+ _array;
6178
+ _length;
6287
6179
  constructor(length4 = 0) {
6288
6180
  this._array = new Array(length4);
6289
6181
  this._length = length4;
6290
6182
  }
6183
+ /**
6184
+ * Gets or sets the length of the array.
6185
+ * If the set length is greater than the length of the internal array, the internal array is resized.
6186
+ *
6187
+ * @memberof ManagedArray.prototype
6188
+ * @type Number
6189
+ */
6291
6190
  get length() {
6292
6191
  return this._length;
6293
6192
  }
@@ -6297,13 +6196,31 @@ var __exports__ = (() => {
6297
6196
  this._array.length = length4;
6298
6197
  }
6299
6198
  }
6199
+ /**
6200
+ * Gets the internal array.
6201
+ *
6202
+ * @memberof ManagedArray.prototype
6203
+ * @type Array
6204
+ * @readonly
6205
+ */
6300
6206
  get values() {
6301
6207
  return this._array;
6302
6208
  }
6209
+ /**
6210
+ * Gets the element at an index.
6211
+ *
6212
+ * @param {Number} index The index to get.
6213
+ */
6303
6214
  get(index) {
6304
6215
  assert2(index < this._array.length);
6305
6216
  return this._array[index];
6306
6217
  }
6218
+ /**
6219
+ * Sets the element at an index. Resizes the array if index is greater than the length of the array.
6220
+ *
6221
+ * @param {Number} index The index to set.
6222
+ * @param {*} element The element to set at index.
6223
+ */
6307
6224
  set(index, element) {
6308
6225
  assert2(index >= 0);
6309
6226
  if (index >= this.length) {
@@ -6323,9 +6240,19 @@ var __exports__ = (() => {
6323
6240
  this.length--;
6324
6241
  }
6325
6242
  }
6243
+ /**
6244
+ * Returns the last element in the array without modifying the array.
6245
+ *
6246
+ * @returns {*} The last element in the array.
6247
+ */
6326
6248
  peek() {
6327
6249
  return this._array[this._length - 1];
6328
6250
  }
6251
+ /**
6252
+ * Push an element into the array.
6253
+ *
6254
+ * @param {*} element The element to push.
6255
+ */
6329
6256
  push(element) {
6330
6257
  if (!this._map.has(element)) {
6331
6258
  const index = this.length++;
@@ -6333,21 +6260,41 @@ var __exports__ = (() => {
6333
6260
  this._map.set(element, index);
6334
6261
  }
6335
6262
  }
6263
+ /**
6264
+ * Pop an element from the array.
6265
+ *
6266
+ * @returns {*} The last element in the array.
6267
+ */
6336
6268
  pop() {
6337
6269
  const element = this._array[--this.length];
6338
6270
  this._map.delete(element);
6339
6271
  return element;
6340
6272
  }
6273
+ /**
6274
+ * Resize the internal array if length > _array.length.
6275
+ *
6276
+ * @param {Number} length The length.
6277
+ */
6341
6278
  reserve(length4) {
6342
6279
  assert2(length4 >= 0);
6343
6280
  if (length4 > this._array.length) {
6344
6281
  this._array.length = length4;
6345
6282
  }
6346
6283
  }
6284
+ /**
6285
+ * Resize the array.
6286
+ *
6287
+ * @param {Number} length The length.
6288
+ */
6347
6289
  resize(length4) {
6348
6290
  assert2(length4 >= 0);
6349
6291
  this.length = length4;
6350
6292
  }
6293
+ /**
6294
+ * Trim the internal array to the specified length. Defaults to the current length.
6295
+ *
6296
+ * @param {Number} [length] The length.
6297
+ */
6351
6298
  trim(length4) {
6352
6299
  if (length4 === null || length4 === void 0) {
6353
6300
  length4 = this.length;
@@ -6375,30 +6322,34 @@ var __exports__ = (() => {
6375
6322
  basePath: ""
6376
6323
  };
6377
6324
  var TilesetTraverser = class {
6325
+ options;
6326
+ // fulfill in traverse call
6378
6327
  root = null;
6328
+ // tiles should be rendered
6379
6329
  selectedTiles = {};
6330
+ // tiles should be loaded from server
6380
6331
  requestedTiles = {};
6332
+ // tiles does not have render content
6381
6333
  emptyTiles = {};
6382
6334
  lastUpdate = new Date().getTime();
6383
6335
  updateDebounceTime = 1e3;
6336
+ /** temporary storage to hold the traversed tiles during a traversal */
6384
6337
  _traversalStack = new ManagedArray();
6385
6338
  _emptyTraversalStack = new ManagedArray();
6339
+ /** set in every traverse cycle */
6386
6340
  _frameNumber = null;
6341
+ // RESULT
6387
6342
  traversalFinished(frameState) {
6388
6343
  return true;
6389
6344
  }
6345
+ // TODO nested props
6390
6346
  constructor(options) {
6391
- this.options = {
6392
- ...DEFAULT_PROPS2,
6393
- ...options
6394
- };
6347
+ this.options = { ...DEFAULT_PROPS2, ...options };
6395
6348
  }
6349
+ // tiles should be visible
6396
6350
  traverse(root, frameState, options) {
6397
6351
  this.root = root;
6398
- this.options = {
6399
- ...this.options,
6400
- ...options
6401
- };
6352
+ this.options = { ...this.options, ...options };
6402
6353
  this.reset();
6403
6354
  this.updateTile(root, frameState);
6404
6355
  this._frameNumber = frameState.frameNumber;
@@ -6411,6 +6362,16 @@ var __exports__ = (() => {
6411
6362
  this._traversalStack.reset();
6412
6363
  this._emptyTraversalStack.reset();
6413
6364
  }
6365
+ /**
6366
+ * Execute traverse
6367
+ * Depth-first traversal that traverses all visible tiles and marks tiles for selection.
6368
+ * If skipLevelOfDetail is off then a tile does not refine until all children are loaded.
6369
+ * This is the traditional replacement refinement approach and is called the base traversal.
6370
+ * Tiles that have a greater screen space error than the base screen space error are part of the base traversal,
6371
+ * all other tiles are part of the skip traversal. The skip traversal allows for skipping levels of the tree
6372
+ * and rendering children and parent tiles simultaneously.
6373
+ */
6374
+ /* eslint-disable-next-line complexity, max-statements */
6414
6375
  executeTraversal(root, frameState) {
6415
6376
  const stack = this._traversalStack;
6416
6377
  root._selectionDepth = 1;
@@ -6420,7 +6381,12 @@ var __exports__ = (() => {
6420
6381
  let shouldRefine = false;
6421
6382
  if (this.canTraverse(tile, frameState)) {
6422
6383
  this.updateChildTiles(tile, frameState);
6423
- shouldRefine = this.updateAndPushChildren(tile, frameState, stack, tile.hasRenderContent ? tile._selectionDepth + 1 : tile._selectionDepth);
6384
+ shouldRefine = this.updateAndPushChildren(
6385
+ tile,
6386
+ frameState,
6387
+ stack,
6388
+ tile.hasRenderContent ? tile._selectionDepth + 1 : tile._selectionDepth
6389
+ );
6424
6390
  }
6425
6391
  const parent = tile.parent;
6426
6392
  const parentRefines = Boolean(!parent || parent._shouldRefine);
@@ -6431,10 +6397,10 @@ var __exports__ = (() => {
6431
6397
  if (stoppedRefining) {
6432
6398
  this.selectTile(tile, frameState);
6433
6399
  }
6434
- } else if (tile.refine === TILE_REFINEMENT.ADD) {
6400
+ } else if (tile.refine === 1 /* ADD */) {
6435
6401
  this.loadTile(tile, frameState);
6436
6402
  this.selectTile(tile, frameState);
6437
- } else if (tile.refine === TILE_REFINEMENT.REPLACE) {
6403
+ } else if (tile.refine === 2 /* REPLACE */) {
6438
6404
  this.loadTile(tile, frameState);
6439
6405
  if (stoppedRefining) {
6440
6406
  this.selectTile(tile, frameState);
@@ -6455,14 +6421,12 @@ var __exports__ = (() => {
6455
6421
  this.updateTile(child, frameState);
6456
6422
  }
6457
6423
  }
6424
+ /* eslint-disable complexity, max-statements */
6458
6425
  updateAndPushChildren(tile, frameState, stack, depth) {
6459
- const {
6460
- loadSiblings,
6461
- skipLevelOfDetail
6462
- } = this.options;
6426
+ const { loadSiblings, skipLevelOfDetail } = this.options;
6463
6427
  const children = tile.children;
6464
6428
  children.sort(this.compareDistanceToCamera.bind(this));
6465
- const checkRefines = tile.refine === TILE_REFINEMENT.REPLACE && tile.hasRenderContent && !skipLevelOfDetail;
6429
+ const checkRefines = tile.refine === 2 /* REPLACE */ && tile.hasRenderContent && !skipLevelOfDetail;
6466
6430
  let hasVisibleChild = false;
6467
6431
  let refines = true;
6468
6432
  for (const child of children) {
@@ -6497,15 +6461,18 @@ var __exports__ = (() => {
6497
6461
  }
6498
6462
  return refines;
6499
6463
  }
6464
+ /* eslint-enable complexity, max-statements */
6500
6465
  updateTile(tile, frameState) {
6501
6466
  this.updateTileVisibility(tile, frameState);
6502
6467
  }
6468
+ // tile to render in the browser
6503
6469
  selectTile(tile, frameState) {
6504
6470
  if (this.shouldSelectTile(tile)) {
6505
6471
  tile._selectedFrame = frameState.frameNumber;
6506
6472
  this.selectedTiles[tile.id] = tile;
6507
6473
  }
6508
6474
  }
6475
+ // tile to load from server
6509
6476
  loadTile(tile, frameState) {
6510
6477
  if (this.shouldLoadTile(tile)) {
6511
6478
  tile._requestedFrame = frameState.frameNumber;
@@ -6513,10 +6480,14 @@ var __exports__ = (() => {
6513
6480
  this.requestedTiles[tile.id] = tile;
6514
6481
  }
6515
6482
  }
6483
+ // cache tile
6516
6484
  touchTile(tile, frameState) {
6517
6485
  tile.tileset._cache.touch(tile);
6518
6486
  tile._touchedFrame = frameState.frameNumber;
6519
6487
  }
6488
+ // tile should be visible
6489
+ // tile should have children
6490
+ // tile LoD (level of detail) is not sufficient under current viewport
6520
6491
  canTraverse(tile, frameState, useParentMetric = false, ignoreVisibility = false) {
6521
6492
  if (!tile.hasChildren) {
6522
6493
  return false;
@@ -6535,6 +6506,7 @@ var __exports__ = (() => {
6535
6506
  shouldSelectTile(tile) {
6536
6507
  return tile.contentAvailable && !this.options.skipLevelOfDetail;
6537
6508
  }
6509
+ /** Decide if tile LoD (level of detail) is not sufficient under current viewport */
6538
6510
  shouldRefine(tile, frameState, useParentMetric = false) {
6539
6511
  let screenSpaceError = tile._screenSpaceError;
6540
6512
  if (useParentMetric) {
@@ -6556,6 +6528,7 @@ var __exports__ = (() => {
6556
6528
  }
6557
6529
  tile.updateVisibility(frameState, viewportIds);
6558
6530
  }
6531
+ // UTILITIES
6559
6532
  compareDistanceToCamera(b, a) {
6560
6533
  return b._distanceToCamera - a._distanceToCamera;
6561
6534
  }
@@ -6567,6 +6540,8 @@ var __exports__ = (() => {
6567
6540
  }
6568
6541
  return anyVisible;
6569
6542
  }
6543
+ // Depth-first traversal that checks if all nearest descendants with content are loaded.
6544
+ // Ignores visibility.
6570
6545
  executeEmptyTraversal(root, frameState) {
6571
6546
  let allDescendantsLoaded = true;
6572
6547
  const stack = this._emptyTraversalStack;
@@ -6600,31 +6575,58 @@ var __exports__ = (() => {
6600
6575
  return x !== void 0 && x !== null;
6601
6576
  }
6602
6577
  var Tile3D = class {
6578
+ tileset;
6579
+ header;
6580
+ id;
6581
+ url;
6582
+ parent;
6583
+ /* Specifies the type of refine that is used when traversing this tile for rendering. */
6584
+ refine;
6585
+ type;
6586
+ contentUrl;
6587
+ /** Different refinement algorithms used by I3S and 3D tiles */
6603
6588
  lodMetricType = "geometricError";
6589
+ /** The error, in meters, introduced if this tile is rendered and its children are not. */
6604
6590
  lodMetricValue = 0;
6591
+ /** @todo math.gl is not exporting BoundingVolume base type? */
6605
6592
  boundingVolume = null;
6593
+ /**
6594
+ * The tile's content. This represents the actual tile's payload,
6595
+ * not the content's metadata in the tileset JSON file.
6596
+ */
6606
6597
  content = null;
6607
6598
  contentState = TILE_CONTENT_STATE.UNLOADED;
6608
6599
  gpuMemoryUsageInBytes = 0;
6600
+ /** The tile's children - an array of Tile3D objects. */
6609
6601
  children = [];
6610
6602
  depth = 0;
6611
6603
  viewportIds = [];
6612
6604
  transform = new Matrix4();
6613
6605
  extensions = null;
6606
+ /** TODO Cesium 3d tiles specific */
6614
6607
  implicitTiling = null;
6608
+ /** Container to store application specific data */
6615
6609
  userData = {};
6610
+ computedTransform;
6616
6611
  hasEmptyContent = false;
6617
6612
  hasTilesetContent = false;
6618
6613
  traverser = new TilesetTraverser({});
6614
+ /** Used by TilesetCache */
6619
6615
  _cacheNode = null;
6620
6616
  _frameNumber = null;
6617
+ // TODO Cesium 3d tiles specific
6621
6618
  _expireDate = null;
6622
6619
  _expiredContent = null;
6623
6620
  _boundingBox = void 0;
6621
+ /** updated every frame for tree traversal and rendering optimizations: */
6624
6622
  _distanceToCamera = 0;
6625
6623
  _screenSpaceError = 0;
6624
+ _visibilityPlaneMask;
6626
6625
  _visible = void 0;
6626
+ _contentBoundingVolume;
6627
+ _viewerRequestVolume;
6627
6628
  _initialTransform = new Matrix4();
6629
+ // Used by traverser, cannot be marked private
6628
6630
  _priority = 0;
6629
6631
  _selectedFrame = 0;
6630
6632
  _requestedFrame = 0;
@@ -6636,6 +6638,17 @@ var __exports__ = (() => {
6636
6638
  _visitedFrame = 0;
6637
6639
  _inRequestVolume = false;
6638
6640
  _lodJudge = null;
6641
+ // TODO i3s specific, needs to remove
6642
+ /**
6643
+ * @constructs
6644
+ * Create a Tile3D instance
6645
+ * @param tileset - Tileset3D instance
6646
+ * @param header - tile header - JSON loaded from a dataset
6647
+ * @param parentHeader - parent Tile3D instance
6648
+ * @param extendedId - optional ID to separate copies of a tile for different viewports.
6649
+ * const extendedId = `${tile.id}-${frameState.viewport.id}`;
6650
+ */
6651
+ // eslint-disable-next-line max-statements
6639
6652
  constructor(tileset, header, parentHeader, extendedId = "") {
6640
6653
  this.header = header;
6641
6654
  this.tileset = tileset;
@@ -6667,64 +6680,108 @@ var __exports__ = (() => {
6667
6680
  get isVisibleAndInRequestVolume() {
6668
6681
  return this._visible && this._inRequestVolume;
6669
6682
  }
6683
+ /** Returns true if tile is not an empty tile and not an external tileset */
6670
6684
  get hasRenderContent() {
6671
6685
  return !this.hasEmptyContent && !this.hasTilesetContent;
6672
6686
  }
6687
+ /** Returns true if tile has children */
6673
6688
  get hasChildren() {
6674
6689
  return this.children.length > 0 || this.header.children && this.header.children.length > 0;
6675
6690
  }
6691
+ /**
6692
+ * Determines if the tile's content is ready. This is automatically `true` for
6693
+ * tiles with empty content.
6694
+ */
6676
6695
  get contentReady() {
6677
6696
  return this.contentState === TILE_CONTENT_STATE.READY || this.hasEmptyContent;
6678
6697
  }
6698
+ /**
6699
+ * Determines if the tile has available content to render. `true` if the tile's
6700
+ * content is ready or if it has expired content this renders while new content loads; otherwise,
6701
+ */
6679
6702
  get contentAvailable() {
6680
- return Boolean(this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed);
6703
+ return Boolean(
6704
+ this.contentReady && this.hasRenderContent || this._expiredContent && !this.contentFailed
6705
+ );
6681
6706
  }
6707
+ /** Returns true if tile has renderable content but it's unloaded */
6682
6708
  get hasUnloadedContent() {
6683
6709
  return this.hasRenderContent && this.contentUnloaded;
6684
6710
  }
6711
+ /**
6712
+ * Determines if the tile's content has not be requested. `true` if tile's
6713
+ * content has not be requested; otherwise, `false`.
6714
+ */
6685
6715
  get contentUnloaded() {
6686
6716
  return this.contentState === TILE_CONTENT_STATE.UNLOADED;
6687
6717
  }
6718
+ /**
6719
+ * Determines if the tile's content is expired. `true` if tile's
6720
+ * content is expired; otherwise, `false`.
6721
+ */
6688
6722
  get contentExpired() {
6689
6723
  return this.contentState === TILE_CONTENT_STATE.EXPIRED;
6690
6724
  }
6725
+ // Determines if the tile's content failed to load. `true` if the tile's
6726
+ // content failed to load; otherwise, `false`.
6691
6727
  get contentFailed() {
6692
6728
  return this.contentState === TILE_CONTENT_STATE.FAILED;
6693
6729
  }
6730
+ /**
6731
+ * Distance from the tile's bounding volume center to the camera
6732
+ */
6694
6733
  get distanceToCamera() {
6695
6734
  return this._distanceToCamera;
6696
6735
  }
6736
+ /**
6737
+ * Screen space error for LOD selection
6738
+ */
6697
6739
  get screenSpaceError() {
6698
6740
  return this._screenSpaceError;
6699
6741
  }
6742
+ /**
6743
+ * Get bounding box in cartographic coordinates
6744
+ * @returns [min, max] each in [longitude, latitude, altitude]
6745
+ */
6700
6746
  get boundingBox() {
6701
6747
  if (!this._boundingBox) {
6702
6748
  this._boundingBox = getCartographicBounds(this.header.boundingVolume, this.boundingVolume);
6703
6749
  }
6704
6750
  return this._boundingBox;
6705
6751
  }
6752
+ /** Get the tile's screen space error. */
6706
6753
  getScreenSpaceError(frameState, useParentLodMetric) {
6707
6754
  switch (this.tileset.type) {
6708
- case TILESET_TYPE.I3S:
6755
+ case "I3S" /* I3S */:
6709
6756
  return getProjectedRadius(this, frameState);
6710
- case TILESET_TYPE.TILES3D:
6757
+ case "TILES3D" /* TILES3D */:
6711
6758
  return getTiles3DScreenSpaceError(this, frameState, useParentLodMetric);
6712
6759
  default:
6713
6760
  throw new Error("Unsupported tileset type");
6714
6761
  }
6715
6762
  }
6763
+ /**
6764
+ * Make tile unselected than means it won't be shown
6765
+ * but it can be still loaded in memory
6766
+ */
6716
6767
  unselect() {
6717
6768
  this._selectedFrame = 0;
6718
6769
  }
6770
+ /**
6771
+ * Memory usage of tile on GPU
6772
+ */
6719
6773
  _getGpuMemoryUsageInBytes() {
6720
6774
  return this.content.gpuMemoryUsageInBytes || this.content.byteLength || 0;
6721
6775
  }
6776
+ /*
6777
+ * If skipLevelOfDetail is off try to load child tiles as soon as possible so that their parent can refine sooner.
6778
+ * Tiles are prioritized by screen space error.
6779
+ */
6780
+ // eslint-disable-next-line complexity
6722
6781
  _getPriority() {
6723
6782
  const traverser = this.tileset._traverser;
6724
- const {
6725
- skipLevelOfDetail
6726
- } = traverser.options;
6727
- const maySkipTile = this.refine === TILE_REFINEMENT.ADD || skipLevelOfDetail;
6783
+ const { skipLevelOfDetail } = traverser.options;
6784
+ const maySkipTile = this.refine === 1 /* ADD */ || skipLevelOfDetail;
6728
6785
  if (maySkipTile && !this.isVisible && this._visible !== void 0) {
6729
6786
  return -1;
6730
6787
  }
@@ -6740,6 +6797,11 @@ var __exports__ = (() => {
6740
6797
  const rootScreenSpaceError = traverser.root ? traverser.root._screenSpaceError : 0;
6741
6798
  return Math.max(rootScreenSpaceError - screenSpaceError, 0);
6742
6799
  }
6800
+ /**
6801
+ * Requests the tile's content.
6802
+ * The request may not be made if the Request Scheduler can't prioritize it.
6803
+ */
6804
+ // eslint-disable-next-line max-statements, complexity
6743
6805
  async loadContent() {
6744
6806
  if (this.hasEmptyContent) {
6745
6807
  return false;
@@ -6752,7 +6814,10 @@ var __exports__ = (() => {
6752
6814
  this._expireDate = null;
6753
6815
  }
6754
6816
  this.contentState = TILE_CONTENT_STATE.LOADING;
6755
- const requestToken = await this.tileset._requestScheduler.scheduleRequest(this.id, this._getPriority.bind(this));
6817
+ const requestToken = await this.tileset._requestScheduler.scheduleRequest(
6818
+ this.id,
6819
+ this._getPriority.bind(this)
6820
+ );
6756
6821
  if (!requestToken) {
6757
6822
  this.contentState = TILE_CONTENT_STATE.UNLOADED;
6758
6823
  return false;
@@ -6763,6 +6828,7 @@ var __exports__ = (() => {
6763
6828
  const options = {
6764
6829
  ...this.tileset.loadOptions,
6765
6830
  [loader.id]: {
6831
+ // @ts-expect-error
6766
6832
  ...this.tileset.loadOptions[loader.id],
6767
6833
  isTileset: this.type === "json",
6768
6834
  ...this._getLoaderSpecificOptions(loader.id)
@@ -6785,6 +6851,7 @@ var __exports__ = (() => {
6785
6851
  requestToken.done();
6786
6852
  }
6787
6853
  }
6854
+ // Unloads the tile's content.
6788
6855
  unloadContent() {
6789
6856
  if (this.content && this.content.destroy) {
6790
6857
  this.content.destroy();
@@ -6797,6 +6864,12 @@ var __exports__ = (() => {
6797
6864
  this.contentState = TILE_CONTENT_STATE.UNLOADED;
6798
6865
  return true;
6799
6866
  }
6867
+ /**
6868
+ * Update the tile's visibility
6869
+ * @param {Object} frameState - frame state for tile culling
6870
+ * @param {string[]} viewportIds - a list of viewport ids that show this tile
6871
+ * @return {void}
6872
+ */
6800
6873
  updateVisibility(frameState, viewportIds) {
6801
6874
  if (this._frameNumber === frameState.frameNumber) {
6802
6875
  return;
@@ -6815,33 +6888,52 @@ var __exports__ = (() => {
6815
6888
  this._frameNumber = frameState.frameNumber;
6816
6889
  this.viewportIds = viewportIds;
6817
6890
  }
6891
+ // Determines whether the tile's bounding volume intersects the culling volume.
6892
+ // @param {FrameState} frameState The frame state.
6893
+ // @param {Number} parentVisibilityPlaneMask The parent's plane mask to speed up the visibility check.
6894
+ // @returns {Number} A plane mask as described above in {@link CullingVolume#computeVisibilityWithPlaneMask}.
6818
6895
  visibility(frameState, parentVisibilityPlaneMask) {
6819
- const {
6820
- cullingVolume: cullingVolume2
6821
- } = frameState;
6822
- const {
6823
- boundingVolume
6824
- } = this;
6896
+ const { cullingVolume: cullingVolume2 } = frameState;
6897
+ const { boundingVolume } = this;
6825
6898
  return cullingVolume2.computeVisibilityWithPlaneMask(boundingVolume, parentVisibilityPlaneMask);
6826
6899
  }
6900
+ // Assuming the tile's bounding volume intersects the culling volume, determines
6901
+ // whether the tile's content's bounding volume intersects the culling volume.
6902
+ // @param {FrameState} frameState The frame state.
6903
+ // @returns {Intersect} The result of the intersection: the tile's content is completely outside, completely inside, or intersecting the culling volume.
6827
6904
  contentVisibility() {
6828
6905
  return true;
6829
6906
  }
6907
+ /**
6908
+ * Computes the (potentially approximate) distance from the closest point of the tile's bounding volume to the camera.
6909
+ * @param frameState The frame state.
6910
+ * @returns {Number} The distance, in meters, or zero if the camera is inside the bounding volume.
6911
+ */
6830
6912
  distanceToTile(frameState) {
6831
6913
  const boundingVolume = this.boundingVolume;
6832
6914
  return Math.sqrt(Math.max(boundingVolume.distanceSquaredTo(frameState.camera.position), 0));
6833
6915
  }
6834
- cameraSpaceZDepth({
6835
- camera
6836
- }) {
6916
+ /**
6917
+ * Computes the tile's camera-space z-depth.
6918
+ * @param frameState The frame state.
6919
+ * @returns The distance, in meters.
6920
+ */
6921
+ cameraSpaceZDepth({ camera }) {
6837
6922
  const boundingVolume = this.boundingVolume;
6838
6923
  scratchVector10.subVectors(boundingVolume.center, camera.position);
6839
6924
  return camera.direction.dot(scratchVector10);
6840
6925
  }
6926
+ /**
6927
+ * Checks if the camera is inside the viewer request volume.
6928
+ * @param {FrameState} frameState The frame state.
6929
+ * @returns {Boolean} Whether the camera is inside the volume.
6930
+ */
6841
6931
  insideViewerRequestVolume(frameState) {
6842
6932
  const viewerRequestVolume = this._viewerRequestVolume;
6843
6933
  return !viewerRequestVolume || viewerRequestVolume.distanceSquaredTo(frameState.camera.position) <= 0;
6844
6934
  }
6935
+ // TODO Cesium specific
6936
+ // Update whether the tile has expired.
6845
6937
  updateExpiration() {
6846
6938
  if (defined2(this._expireDate) && this.contentReady && !this.hasEmptyContent) {
6847
6939
  const now = Date.now();
@@ -6854,6 +6946,7 @@ var __exports__ = (() => {
6854
6946
  get extras() {
6855
6947
  return this.header.extras;
6856
6948
  }
6949
+ // INTERNAL METHODS
6857
6950
  _initializeLodMetric(header) {
6858
6951
  if ("lodMetricType" in header) {
6859
6952
  this.lodMetricType = header.lodMetricType;
@@ -6865,7 +6958,9 @@ var __exports__ = (() => {
6865
6958
  this.lodMetricValue = header.lodMetricValue;
6866
6959
  } else {
6867
6960
  this.lodMetricValue = this.parent && this.parent.lodMetricValue || this.tileset.lodMetricValue;
6868
- console.warn("3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue");
6961
+ console.warn(
6962
+ "3D Tile: Required prop lodMetricValue is undefined. Using parent lodMetricValue"
6963
+ );
6869
6964
  }
6870
6965
  }
6871
6966
  _initializeTransforms(tileHeader) {
@@ -6883,10 +6978,7 @@ var __exports__ = (() => {
6883
6978
  this._updateBoundingVolume(tileHeader);
6884
6979
  }
6885
6980
  _initializeContent(tileHeader) {
6886
- this.content = {
6887
- _tileset: this.tileset,
6888
- _tile: this
6889
- };
6981
+ this.content = { _tileset: this.tileset, _tile: this };
6890
6982
  this.hasEmptyContent = true;
6891
6983
  this.contentState = TILE_CONTENT_STATE.UNLOADED;
6892
6984
  this.hasTilesetContent = false;
@@ -6895,6 +6987,7 @@ var __exports__ = (() => {
6895
6987
  this.hasEmptyContent = false;
6896
6988
  }
6897
6989
  }
6990
+ // TODO - remove anything not related to basic visibility detection
6898
6991
  _initializeRenderingState(header) {
6899
6992
  this.depth = header.level || (this.parent ? this.parent.depth + 1 : 0);
6900
6993
  this._shouldRefine = false;
@@ -6914,7 +7007,7 @@ var __exports__ = (() => {
6914
7007
  this._priority = 0;
6915
7008
  }
6916
7009
  _getRefine(refine) {
6917
- return refine || this.parent && this.parent.refine || TILE_REFINEMENT.REPLACE;
7010
+ return refine || this.parent && this.parent.refine || 2 /* REPLACE */;
6918
7011
  }
6919
7012
  _isTileset() {
6920
7013
  return this.contentUrl.indexOf(".json") !== -1;
@@ -6934,18 +7027,31 @@ var __exports__ = (() => {
6934
7027
  }
6935
7028
  }
6936
7029
  _updateBoundingVolume(header) {
6937
- this.boundingVolume = createBoundingVolume(header.boundingVolume, this.computedTransform, this.boundingVolume);
7030
+ this.boundingVolume = createBoundingVolume(
7031
+ header.boundingVolume,
7032
+ this.computedTransform,
7033
+ this.boundingVolume
7034
+ );
6938
7035
  const content = header.content;
6939
7036
  if (!content) {
6940
7037
  return;
6941
7038
  }
6942
7039
  if (content.boundingVolume) {
6943
- this._contentBoundingVolume = createBoundingVolume(content.boundingVolume, this.computedTransform, this._contentBoundingVolume);
7040
+ this._contentBoundingVolume = createBoundingVolume(
7041
+ content.boundingVolume,
7042
+ this.computedTransform,
7043
+ this._contentBoundingVolume
7044
+ );
6944
7045
  }
6945
7046
  if (header.viewerRequestVolume) {
6946
- this._viewerRequestVolume = createBoundingVolume(header.viewerRequestVolume, this.computedTransform, this._viewerRequestVolume);
7047
+ this._viewerRequestVolume = createBoundingVolume(
7048
+ header.viewerRequestVolume,
7049
+ this.computedTransform,
7050
+ this._viewerRequestVolume
7051
+ );
6947
7052
  }
6948
7053
  }
7054
+ // Update the tile's transform. The transform is applied to the tile's bounding volumes.
6949
7055
  _updateTransform(parentTransform = new Matrix4()) {
6950
7056
  const computedTransform = parentTransform.clone().multiplyRight(this.transform);
6951
7057
  const didTransformChange = !computedTransform.equals(this.computedTransform);
@@ -6955,6 +7061,7 @@ var __exports__ = (() => {
6955
7061
  this.computedTransform = computedTransform;
6956
7062
  this._updateBoundingVolume(this.header);
6957
7063
  }
7064
+ // Get options which are applicable only for the particular loader
6958
7065
  _getLoaderSpecificOptions(loaderId) {
6959
7066
  switch (loaderId) {
6960
7067
  case "i3s":
@@ -7005,7 +7112,7 @@ var __exports__ = (() => {
7005
7112
  tile._visible = false;
7006
7113
  return;
7007
7114
  }
7008
- const replace = tile.refine === TILE_REFINEMENT.REPLACE;
7115
+ const replace = tile.refine === 2 /* REPLACE */;
7009
7116
  const useOptimization = tile._optimChildrenWithinParent === TILE3D_OPTIMIZATION_HINT.USE_OPTIMIZATION;
7010
7117
  if (replace && useOptimization && hasChildren) {
7011
7118
  if (!this.anyChildrenVisible(tile, frameState)) {
@@ -7015,10 +7122,8 @@ var __exports__ = (() => {
7015
7122
  }
7016
7123
  }
7017
7124
  meetsScreenSpaceErrorEarly(tile, frameState) {
7018
- const {
7019
- parent
7020
- } = tile;
7021
- if (!parent || parent.hasTilesetContent || parent.refine !== TILE_REFINEMENT.ADD) {
7125
+ const { parent } = tile;
7126
+ if (!parent || parent.hasTilesetContent || parent.refine !== 1 /* ADD */) {
7022
7127
  return false;
7023
7128
  }
7024
7129
  return !this.shouldRefine(tile, frameState, true);
@@ -7031,12 +7136,22 @@ var __exports__ = (() => {
7031
7136
  // src/tileset/format-i3s/i3s-pending-tiles-register.ts
7032
7137
  var I3SPendingTilesRegister = class {
7033
7138
  frameNumberMap = /* @__PURE__ */ new Map();
7139
+ /**
7140
+ * Register a new pending tile header for the particular frameNumber
7141
+ * @param viewportId
7142
+ * @param frameNumber
7143
+ */
7034
7144
  register(viewportId, frameNumber) {
7035
7145
  const viewportMap = this.frameNumberMap.get(viewportId) || /* @__PURE__ */ new Map();
7036
7146
  const oldCount = viewportMap.get(frameNumber) || 0;
7037
7147
  viewportMap.set(frameNumber, oldCount + 1);
7038
7148
  this.frameNumberMap.set(viewportId, viewportMap);
7039
7149
  }
7150
+ /**
7151
+ * Deregister a pending tile header for the particular frameNumber
7152
+ * @param viewportId
7153
+ * @param frameNumber
7154
+ */
7040
7155
  deregister(viewportId, frameNumber) {
7041
7156
  const viewportMap = this.frameNumberMap.get(viewportId);
7042
7157
  if (!viewportMap) {
@@ -7045,6 +7160,12 @@ var __exports__ = (() => {
7045
7160
  const oldCount = viewportMap.get(frameNumber) || 1;
7046
7161
  viewportMap.set(frameNumber, oldCount - 1);
7047
7162
  }
7163
+ /**
7164
+ * Check is there are no pending tile headers registered for the particular frameNumber
7165
+ * @param viewportId
7166
+ * @param frameNumber
7167
+ * @returns
7168
+ */
7048
7169
  isZero(viewportId, frameNumber) {
7049
7170
  const count = this.frameNumberMap.get(viewportId)?.get(frameNumber) || 0;
7050
7171
  return count === 0;
@@ -7058,33 +7179,31 @@ var __exports__ = (() => {
7058
7179
  ERROR: "ERROR"
7059
7180
  };
7060
7181
  var I3STileManager = class {
7182
+ _statusMap;
7061
7183
  pendingTilesRegister = new I3SPendingTilesRegister();
7062
7184
  constructor() {
7063
7185
  this._statusMap = {};
7064
7186
  }
7187
+ /**
7188
+ * Add request to map
7189
+ * @param request - node metadata request
7190
+ * @param key - unique key
7191
+ * @param callback - callback after request completed
7192
+ * @param frameState - frameState data
7193
+ */
7065
7194
  add(request, key, callback, frameState) {
7066
7195
  if (!this._statusMap[key]) {
7067
7196
  const {
7068
7197
  frameNumber,
7069
- viewport: {
7070
- id
7071
- }
7198
+ viewport: { id }
7072
7199
  } = frameState;
7073
- this._statusMap[key] = {
7074
- request,
7075
- callback,
7076
- key,
7077
- frameState,
7078
- status: STATUS.REQUESTED
7079
- };
7200
+ this._statusMap[key] = { request, callback, key, frameState, status: STATUS.REQUESTED };
7080
7201
  this.pendingTilesRegister.register(id, frameNumber);
7081
7202
  request().then((data) => {
7082
7203
  this._statusMap[key].status = STATUS.COMPLETED;
7083
7204
  const {
7084
7205
  frameNumber: actualFrameNumber,
7085
- viewport: {
7086
- id: id2
7087
- }
7206
+ viewport: { id: id2 }
7088
7207
  } = this._statusMap[key].frameState;
7089
7208
  this.pendingTilesRegister.deregister(id2, actualFrameNumber);
7090
7209
  this._statusMap[key].callback(data, frameState);
@@ -7092,37 +7211,47 @@ var __exports__ = (() => {
7092
7211
  this._statusMap[key].status = STATUS.ERROR;
7093
7212
  const {
7094
7213
  frameNumber: actualFrameNumber,
7095
- viewport: {
7096
- id: id2
7097
- }
7214
+ viewport: { id: id2 }
7098
7215
  } = this._statusMap[key].frameState;
7099
7216
  this.pendingTilesRegister.deregister(id2, actualFrameNumber);
7100
7217
  callback(error);
7101
7218
  });
7102
7219
  }
7103
7220
  }
7221
+ /**
7222
+ * Update request if it is still actual for the new frameState
7223
+ * @param key - unique key
7224
+ * @param frameState - frameState data
7225
+ */
7104
7226
  update(key, frameState) {
7105
7227
  if (this._statusMap[key]) {
7106
7228
  const {
7107
7229
  frameNumber,
7108
- viewport: {
7109
- id
7110
- }
7230
+ viewport: { id }
7111
7231
  } = this._statusMap[key].frameState;
7112
7232
  this.pendingTilesRegister.deregister(id, frameNumber);
7113
7233
  const {
7114
7234
  frameNumber: newFrameNumber,
7115
- viewport: {
7116
- id: newViewportId
7117
- }
7235
+ viewport: { id: newViewportId }
7118
7236
  } = frameState;
7119
7237
  this.pendingTilesRegister.register(newViewportId, newFrameNumber);
7120
7238
  this._statusMap[key].frameState = frameState;
7121
7239
  }
7122
7240
  }
7241
+ /**
7242
+ * Find request in the map
7243
+ * @param key - unique key
7244
+ * @returns
7245
+ */
7123
7246
  find(key) {
7124
7247
  return this._statusMap[key];
7125
7248
  }
7249
+ /**
7250
+ * Check it there are pending tile headers for the particular frameNumber
7251
+ * @param viewportId
7252
+ * @param frameNumber
7253
+ * @returns
7254
+ */
7126
7255
  hasPendingTiles(viewportId, frameNumber) {
7127
7256
  return !this.pendingTilesRegister.isZero(viewportId, frameNumber);
7128
7257
  }
@@ -7130,10 +7259,16 @@ var __exports__ = (() => {
7130
7259
 
7131
7260
  // src/tileset/format-i3s/i3s-tileset-traverser.ts
7132
7261
  var I3STilesetTraverser = class extends TilesetTraverser {
7262
+ _tileManager;
7133
7263
  constructor(options) {
7134
7264
  super(options);
7135
7265
  this._tileManager = new I3STileManager();
7136
7266
  }
7267
+ /**
7268
+ * Check if there are no penging tile header requests,
7269
+ * that means the traversal is finished and we can call
7270
+ * following-up callbacks.
7271
+ */
7137
7272
  traversalFinished(frameState) {
7138
7273
  return !this._tileManager.hasPendingTiles(frameState.viewport.id, this._frameNumber || 0);
7139
7274
  }
@@ -7155,7 +7290,12 @@ var __exports__ = (() => {
7155
7290
  if (tileset.tileset.nodePages) {
7156
7291
  request = () => tileset.tileset.nodePagesTile.formTileFromNodePages(child.id);
7157
7292
  }
7158
- this._tileManager.add(request, extendedId, (header) => this._onTileLoad(header, tile, extendedId), frameState);
7293
+ this._tileManager.add(
7294
+ request,
7295
+ extendedId,
7296
+ (header) => this._onTileLoad(header, tile, extendedId),
7297
+ frameState
7298
+ );
7159
7299
  } else {
7160
7300
  this._tileManager.update(extendedId, frameState);
7161
7301
  }
@@ -7166,9 +7306,7 @@ var __exports__ = (() => {
7166
7306
  return false;
7167
7307
  }
7168
7308
  async _loadTile(nodeId, tileset) {
7169
- const {
7170
- loader
7171
- } = tileset;
7309
+ const { loader } = tileset;
7172
7310
  const nodeUrl = tileset.getTileUrl(`${tileset.url}/nodes/${nodeId}`);
7173
7311
  const options = {
7174
7312
  ...tileset.loadOptions,
@@ -7179,6 +7317,14 @@ var __exports__ = (() => {
7179
7317
  };
7180
7318
  return await (0, import_core22.load)(nodeUrl, loader, options);
7181
7319
  }
7320
+ /**
7321
+ * The callback to init Tile3D instance after loading the tile JSON
7322
+ * @param {Object} header - the tile JSON from a dataset
7323
+ * @param {Tile3D} tile - the parent Tile3D instance
7324
+ * @param {string} extendedId - optional ID to separate copies of a tile for different viewports.
7325
+ * const extendedId = `${tile.id}-${frameState.viewport.id}`;
7326
+ * @return {void}
7327
+ */
7182
7328
  _onTileLoad(header, tile, extendedId) {
7183
7329
  const childTile = new Tile3D(tile.tileset, header, tile, extendedId);
7184
7330
  tile.children.push(childTile);
@@ -7197,6 +7343,7 @@ var __exports__ = (() => {
7197
7343
  modelMatrix: new Matrix4(),
7198
7344
  throttleRequests: true,
7199
7345
  maxRequests: 64,
7346
+ /** Default memory values optimized for viewing mesh-based 3D Tiles on both mobile and desktop devices */
7200
7347
  maximumMemoryUsage: 32,
7201
7348
  memoryCacheOverflow: 1,
7202
7349
  maximumTilesSelected: 0,
@@ -7215,9 +7362,7 @@ var __exports__ = (() => {
7215
7362
  loadTiles: true,
7216
7363
  updateTransforms: true,
7217
7364
  viewportTraversersMap: null,
7218
- loadOptions: {
7219
- fetch: {}
7220
- },
7365
+ loadOptions: { fetch: {} },
7221
7366
  attributions: [],
7222
7367
  basePath: "",
7223
7368
  i3s: {}
@@ -7234,48 +7379,86 @@ var __exports__ = (() => {
7234
7379
  var TILES_GPU_MEMORY = "Tile Memory Use";
7235
7380
  var MAXIMUM_SSE = "Maximum Screen Space Error";
7236
7381
  var Tileset3D = class {
7382
+ // props: Tileset3DProps;
7383
+ options;
7384
+ loadOptions;
7385
+ type;
7386
+ tileset;
7387
+ loader;
7388
+ url;
7389
+ basePath;
7390
+ modelMatrix;
7391
+ ellipsoid;
7392
+ lodMetricType;
7393
+ lodMetricValue;
7394
+ refine;
7237
7395
  root = null;
7238
7396
  roots = {};
7397
+ /** @todo any->unknown */
7239
7398
  asset = {};
7399
+ // Metadata for the entire tileset
7240
7400
  description = "";
7401
+ properties;
7241
7402
  extras = null;
7242
7403
  attributions = {};
7243
7404
  credits = {};
7244
- contentFormats = {
7245
- draco: false,
7246
- meshopt: false,
7247
- dds: false,
7248
- ktx2: false
7249
- };
7405
+ stats;
7406
+ /** flags that contain information about data types in nested tiles */
7407
+ contentFormats = { draco: false, meshopt: false, dds: false, ktx2: false };
7408
+ // view props
7250
7409
  cartographicCenter = null;
7251
7410
  cartesianCenter = null;
7252
7411
  zoom = 1;
7253
7412
  boundingVolume = null;
7413
+ /** Updated based on the camera position and direction */
7254
7414
  dynamicScreenSpaceErrorComputedDensity = 0;
7415
+ // METRICS
7416
+ /**
7417
+ * The maximum amount of GPU memory (in MB) that may be used to cache tiles
7418
+ * Tiles not in view are unloaded to enforce private
7419
+ */
7255
7420
  maximumMemoryUsage = 32;
7421
+ /** The total amount of GPU memory in bytes used by the tileset. */
7256
7422
  gpuMemoryUsageInBytes = 0;
7423
+ /**
7424
+ * If loading the level of detail required by maximumScreenSpaceError
7425
+ * results in the memory usage exceeding maximumMemoryUsage (GPU), level of detail refinement
7426
+ * will instead use this (larger) adjusted screen space error to achieve the
7427
+ * best possible visual quality within the available memory.
7428
+ */
7257
7429
  memoryAdjustedScreenSpaceError = 0;
7258
7430
  _cacheBytes = 0;
7259
7431
  _cacheOverflowBytes = 0;
7432
+ /** Update tracker. increase in each update cycle. */
7260
7433
  _frameNumber = 0;
7261
7434
  _queryParams = {};
7262
7435
  _extensionsUsed = [];
7263
7436
  _tiles = {};
7437
+ /** counter for tracking tiles requests */
7264
7438
  _pendingCount = 0;
7439
+ /** Hold traversal results */
7265
7440
  selectedTiles = [];
7441
+ // TRAVERSAL
7266
7442
  traverseCounter = 0;
7267
7443
  geometricError = 0;
7268
7444
  lastUpdatedVieports = null;
7269
7445
  _requestedTiles = [];
7270
7446
  _emptyTiles = [];
7271
7447
  frameStateData = {};
7448
+ _traverser;
7272
7449
  _cache = new TilesetCache();
7450
+ _requestScheduler;
7451
+ // Promise tracking
7273
7452
  updatePromise = null;
7453
+ tilesetInitializationPromise;
7454
+ /**
7455
+ * Create a new Tileset3D
7456
+ * @param json
7457
+ * @param props
7458
+ */
7459
+ // eslint-disable-next-line max-statements
7274
7460
  constructor(tileset, options) {
7275
- this.options = {
7276
- ...DEFAULT_PROPS3,
7277
- ...options
7278
- };
7461
+ this.options = { ...DEFAULT_PROPS3, ...options };
7279
7462
  this.tileset = tileset;
7280
7463
  this.loader = tileset.loader;
7281
7464
  this.type = tileset.type;
@@ -7295,15 +7478,15 @@ var __exports__ = (() => {
7295
7478
  this.memoryAdjustedScreenSpaceError = this.options.maximumScreenSpaceError;
7296
7479
  this._cacheBytes = this.options.maximumMemoryUsage * 1024 * 1024;
7297
7480
  this._cacheOverflowBytes = this.options.memoryCacheOverflow * 1024 * 1024;
7298
- this.stats = new Stats({
7299
- id: this.url
7300
- });
7481
+ this.stats = new Stats({ id: this.url });
7301
7482
  this._initializeStats();
7302
7483
  this.tilesetInitializationPromise = this._initializeTileSet(tileset);
7303
7484
  }
7485
+ /** Release resources */
7304
7486
  destroy() {
7305
7487
  this._destroy();
7306
7488
  }
7489
+ /** Is the tileset loaded (update needs to have been called at least once) */
7307
7490
  isLoaded() {
7308
7491
  return this._pendingCount === 0 && this._frameNumber !== 0 && this._requestedTiles.length === 0;
7309
7492
  }
@@ -7317,11 +7500,16 @@ var __exports__ = (() => {
7317
7500
  return new URLSearchParams(this._queryParams).toString();
7318
7501
  }
7319
7502
  setProps(props) {
7320
- this.options = {
7321
- ...this.options,
7322
- ...props
7323
- };
7324
- }
7503
+ this.options = { ...this.options, ...props };
7504
+ }
7505
+ /** @deprecated */
7506
+ // setOptions(options: Tileset3DProps): void {
7507
+ // this.options = {...this.options, ...options};
7508
+ // }
7509
+ /**
7510
+ * Return a loadable tile url for a specific tile subpath
7511
+ * @param tilePath a tile subpath
7512
+ */
7325
7513
  getTileUrl(tilePath) {
7326
7514
  const isDataUrl = tilePath.startsWith("data:");
7327
7515
  if (isDataUrl) {
@@ -7333,9 +7521,15 @@ var __exports__ = (() => {
7333
7521
  }
7334
7522
  return tileUrl;
7335
7523
  }
7524
+ // TODO CESIUM specific
7336
7525
  hasExtension(extensionName) {
7337
7526
  return Boolean(this._extensionsUsed.indexOf(extensionName) > -1);
7338
7527
  }
7528
+ /**
7529
+ * Update visible tiles relying on a list of viewports
7530
+ * @param viewports - list of viewports
7531
+ * @deprecated
7532
+ */
7339
7533
  update(viewports = null) {
7340
7534
  this.tilesetInitializationPromise.then(() => {
7341
7535
  if (!viewports && this.lastUpdatedVieports) {
@@ -7348,6 +7542,12 @@ var __exports__ = (() => {
7348
7542
  }
7349
7543
  });
7350
7544
  }
7545
+ /**
7546
+ * Update visible tiles relying on a list of viewports.
7547
+ * Do it with debounce delay to prevent update spam
7548
+ * @param viewports viewports
7549
+ * @returns Promise of new frameNumber
7550
+ */
7351
7551
  async selectTiles(viewports = null) {
7352
7552
  await this.tilesetInitializationPromise;
7353
7553
  if (viewports) {
@@ -7368,11 +7568,19 @@ var __exports__ = (() => {
7368
7568
  }
7369
7569
  adjustScreenSpaceError() {
7370
7570
  if (this.gpuMemoryUsageInBytes < this._cacheBytes) {
7371
- this.memoryAdjustedScreenSpaceError = Math.max(this.memoryAdjustedScreenSpaceError / 1.02, this.options.maximumScreenSpaceError);
7571
+ this.memoryAdjustedScreenSpaceError = Math.max(
7572
+ this.memoryAdjustedScreenSpaceError / 1.02,
7573
+ this.options.maximumScreenSpaceError
7574
+ );
7372
7575
  } else if (this.gpuMemoryUsageInBytes > this._cacheBytes + this._cacheOverflowBytes) {
7373
7576
  this.memoryAdjustedScreenSpaceError *= 1.02;
7374
7577
  }
7375
7578
  }
7579
+ /**
7580
+ * Update visible tiles relying on a list of viewports
7581
+ * @param viewports viewports
7582
+ */
7583
+ // eslint-disable-next-line max-statements, complexity
7376
7584
  doUpdate(viewports) {
7377
7585
  if ("loadTiles" in this.options && !this.options.loadTiles) {
7378
7586
  return;
@@ -7405,6 +7613,11 @@ var __exports__ = (() => {
7405
7613
  this._traverser.traverse(this.roots[id], frameState, this.options);
7406
7614
  }
7407
7615
  }
7616
+ /**
7617
+ * Check if traversal is needed for particular viewport
7618
+ * @param {string} viewportId - id of a viewport
7619
+ * @return {boolean}
7620
+ */
7408
7621
  _needTraverse(viewportId) {
7409
7622
  let traverserId = viewportId;
7410
7623
  if (this.options.viewportTraversersMap) {
@@ -7415,18 +7628,22 @@ var __exports__ = (() => {
7415
7628
  }
7416
7629
  return true;
7417
7630
  }
7631
+ /**
7632
+ * The callback to post-process tiles after traversal procedure
7633
+ * @param frameState - frame state for tile culling
7634
+ */
7418
7635
  _onTraversalEnd(frameState) {
7419
7636
  const id = frameState.viewport.id;
7420
7637
  if (!this.frameStateData[id]) {
7421
- this.frameStateData[id] = {
7422
- selectedTiles: [],
7423
- _requestedTiles: [],
7424
- _emptyTiles: []
7425
- };
7638
+ this.frameStateData[id] = { selectedTiles: [], _requestedTiles: [], _emptyTiles: [] };
7426
7639
  }
7427
7640
  const currentFrameStateData = this.frameStateData[id];
7428
7641
  const selectedTiles = Object.values(this._traverser.selectedTiles);
7429
- const [filteredSelectedTiles, unselectedTiles] = limitSelectedTiles(selectedTiles, frameState, this.options.maximumTilesSelected);
7642
+ const [filteredSelectedTiles, unselectedTiles] = limitSelectedTiles(
7643
+ selectedTiles,
7644
+ frameState,
7645
+ this.options.maximumTilesSelected
7646
+ );
7430
7647
  currentFrameStateData.selectedTiles = filteredSelectedTiles;
7431
7648
  for (const tile of unselectedTiles) {
7432
7649
  tile.unselect();
@@ -7439,6 +7656,9 @@ var __exports__ = (() => {
7439
7656
  }
7440
7657
  this._updateTiles();
7441
7658
  }
7659
+ /**
7660
+ * Update tiles relying on data from all traversers
7661
+ */
7442
7662
  _updateTiles() {
7443
7663
  this.selectedTiles = [];
7444
7664
  this._requestedTiles = [];
@@ -7496,31 +7716,34 @@ var __exports__ = (() => {
7496
7716
  this.stats.get(MAXIMUM_SSE).count = this.memoryAdjustedScreenSpaceError;
7497
7717
  }
7498
7718
  async _initializeTileSet(tilesetJson) {
7499
- if (this.type === TILESET_TYPE.I3S) {
7719
+ if (this.type === "I3S" /* I3S */) {
7500
7720
  this.calculateViewPropsI3S();
7501
7721
  tilesetJson.root = await tilesetJson.root;
7502
7722
  }
7503
7723
  this.root = this._initializeTileHeaders(tilesetJson, null);
7504
- if (this.type === TILESET_TYPE.TILES3D) {
7724
+ if (this.type === "TILES3D" /* TILES3D */) {
7505
7725
  this._initializeTiles3DTileset(tilesetJson);
7506
7726
  this.calculateViewPropsTiles3D();
7507
7727
  }
7508
- if (this.type === TILESET_TYPE.I3S) {
7728
+ if (this.type === "I3S" /* I3S */) {
7509
7729
  this._initializeI3STileset();
7510
7730
  }
7511
7731
  }
7732
+ /**
7733
+ * Called during initialize Tileset to initialize the tileset's cartographic center (longitude, latitude) and zoom.
7734
+ * These metrics help apps center view on tileset
7735
+ * For I3S there is extent (<1.8 version) or fullExtent (>=1.8 version) to calculate view props
7736
+ * @returns
7737
+ */
7512
7738
  calculateViewPropsI3S() {
7513
7739
  const fullExtent = this.tileset.fullExtent;
7514
7740
  if (fullExtent) {
7515
- const {
7516
- xmin,
7517
- xmax,
7518
- ymin,
7519
- ymax,
7520
- zmin,
7521
- zmax
7522
- } = fullExtent;
7523
- this.cartographicCenter = new Vector3(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin + (zmax - zmin) / 2);
7741
+ const { xmin, xmax, ymin, ymax, zmin, zmax } = fullExtent;
7742
+ this.cartographicCenter = new Vector3(
7743
+ xmin + (xmax - xmin) / 2,
7744
+ ymin + (ymax - ymin) / 2,
7745
+ zmin + (zmax - zmin) / 2
7746
+ );
7524
7747
  this.cartesianCenter = new Vector3();
7525
7748
  Ellipsoid.WGS84.cartographicToCartesian(this.cartographicCenter, this.cartesianCenter);
7526
7749
  this.zoom = getZoomFromFullExtent(fullExtent, this.cartographicCenter, this.cartesianCenter);
@@ -7540,11 +7763,15 @@ var __exports__ = (() => {
7540
7763
  this.zoom = 1;
7541
7764
  return;
7542
7765
  }
7766
+ /**
7767
+ * Called during initialize Tileset to initialize the tileset's cartographic center (longitude, latitude) and zoom.
7768
+ * These metrics help apps center view on tileset.
7769
+ * For 3DTiles the root tile data is used to calculate view props.
7770
+ * @returns
7771
+ */
7543
7772
  calculateViewPropsTiles3D() {
7544
7773
  const root = this.root;
7545
- const {
7546
- center
7547
- } = root.boundingVolume;
7774
+ const { center } = root.boundingVolume;
7548
7775
  if (!center) {
7549
7776
  console.warn("center was not pre-calculated for the root tile");
7550
7777
  this.cartographicCenter = new Vector3();
@@ -7573,13 +7800,15 @@ var __exports__ = (() => {
7573
7800
  this.stats.get(TILES_GPU_MEMORY, "memory");
7574
7801
  this.stats.get(MAXIMUM_SSE);
7575
7802
  }
7803
+ // Installs the main tileset JSON file or a tileset JSON file referenced from a tile.
7804
+ // eslint-disable-next-line max-statements
7576
7805
  _initializeTileHeaders(tilesetJson, parentTileHeader) {
7577
7806
  const rootTile = new Tile3D(this, tilesetJson.root, parentTileHeader);
7578
7807
  if (parentTileHeader) {
7579
7808
  parentTileHeader.children.push(rootTile);
7580
7809
  rootTile.depth = parentTileHeader.depth + 1;
7581
7810
  }
7582
- if (this.type === TILESET_TYPE.TILES3D) {
7811
+ if (this.type === "TILES3D" /* TILES3D */) {
7583
7812
  const stack = [];
7584
7813
  stack.push(rootTile);
7585
7814
  while (stack.length > 0) {
@@ -7607,10 +7836,10 @@ var __exports__ = (() => {
7607
7836
  let TraverserClass;
7608
7837
  const type = this.type;
7609
7838
  switch (type) {
7610
- case TILESET_TYPE.TILES3D:
7839
+ case "TILES3D" /* TILES3D */:
7611
7840
  TraverserClass = Tileset3DTraverser;
7612
7841
  break;
7613
- case TILESET_TYPE.I3S:
7842
+ case "I3S" /* I3S */:
7614
7843
  TraverserClass = I3STilesetTraverser;
7615
7844
  break;
7616
7845
  default:
@@ -7647,7 +7876,7 @@ var __exports__ = (() => {
7647
7876
  if (!loaded) {
7648
7877
  return;
7649
7878
  }
7650
- if (this.type === TILESET_TYPE.I3S) {
7879
+ if (this.type === "I3S" /* I3S */) {
7651
7880
  const nodesInNodePages = this.tileset?.nodePagesTile?.nodesInNodePages || 0;
7652
7881
  this.stats.get(TILES_TOTAL).reset();
7653
7882
  this.stats.get(TILES_TOTAL).addCount(nodesInNodePages);
@@ -7659,8 +7888,12 @@ var __exports__ = (() => {
7659
7888
  this._addTileToCache(tile);
7660
7889
  this.options.onTileLoad(tile);
7661
7890
  }
7891
+ /**
7892
+ * Update information about data types in nested tiles
7893
+ * @param tile instance of a nested Tile3D
7894
+ */
7662
7895
  updateContentTypes(tile) {
7663
- if (this.type === TILESET_TYPE.I3S) {
7896
+ if (this.type === "I3S" /* I3S */) {
7664
7897
  if (tile.header.isDracoGeometry) {
7665
7898
  this.contentFormats.draco = true;
7666
7899
  }
@@ -7673,10 +7906,8 @@ var __exports__ = (() => {
7673
7906
  break;
7674
7907
  default:
7675
7908
  }
7676
- } else if (this.type === TILESET_TYPE.TILES3D) {
7677
- const {
7678
- extensionsRemoved = []
7679
- } = tile.content?.gltf || {};
7909
+ } else if (this.type === "TILES3D" /* TILES3D */) {
7910
+ const { extensionsRemoved = [] } = tile.content?.gltf || {};
7680
7911
  if (extensionsRemoved.includes("KHR_draco_mesh_compression")) {
7681
7912
  this.contentFormats.draco = true;
7682
7913
  }
@@ -7716,6 +7947,7 @@ var __exports__ = (() => {
7716
7947
  this.options.onTileUnload(tile);
7717
7948
  tile.unloadContent();
7718
7949
  }
7950
+ // Traverse the tree and destroy all tiles
7719
7951
  _destroy() {
7720
7952
  const stack = [];
7721
7953
  if (this.root) {
@@ -7730,6 +7962,7 @@ var __exports__ = (() => {
7730
7962
  }
7731
7963
  this.root = null;
7732
7964
  }
7965
+ // Traverse the tree and destroy all sub tiles
7733
7966
  _destroySubtree(tile) {
7734
7967
  const root = tile;
7735
7968
  const stack = [];
@@ -7754,10 +7987,7 @@ var __exports__ = (() => {
7754
7987
  if (tilesetJson.queryString) {
7755
7988
  const searchParams = new URLSearchParams(tilesetJson.queryString);
7756
7989
  const queryParams = Object.fromEntries(searchParams.entries());
7757
- this._queryParams = {
7758
- ...this._queryParams,
7759
- ...queryParams
7760
- };
7990
+ this._queryParams = { ...this._queryParams, ...queryParams };
7761
7991
  }
7762
7992
  this.asset = tilesetJson.asset;
7763
7993
  if (!this.asset) {
@@ -7784,7 +8014,7 @@ var __exports__ = (() => {
7784
8014
  }
7785
8015
  }
7786
8016
  };
7787
- return __toCommonJS(src_exports);
8017
+ return __toCommonJS(bundle_exports);
7788
8018
  })();
7789
8019
  return __exports__;
7790
8020
  });