@jdultra/threedtiles 11.1.7 → 11.1.9

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 (43) hide show
  1. package/dist/docs/InstancedOGC3DTile.html +3 -0
  2. package/dist/docs/InstancedTile.html +3 -0
  3. package/dist/docs/InstancedTileLoader.html +3 -0
  4. package/dist/docs/OGC3DTile.html +3 -0
  5. package/dist/docs/OGC3DTile.js.html +1451 -0
  6. package/dist/docs/OcclusionCullingService.html +3 -0
  7. package/dist/docs/OcclusionCullingService.js.html +84 -0
  8. package/dist/docs/TileLoader.html +3 -0
  9. package/dist/docs/TileLoader.js.html +550 -0
  10. package/dist/docs/data/search.json +1 -0
  11. package/dist/docs/fonts/Inconsolata-Regular.ttf +0 -0
  12. package/dist/docs/fonts/OpenSans-Regular.ttf +0 -0
  13. package/dist/docs/fonts/WorkSans-Bold.ttf +0 -0
  14. package/dist/docs/global.html +3 -0
  15. package/dist/docs/index.html +338 -0
  16. package/dist/docs/instanced_InstancedOGC3DTile.js.html +106 -0
  17. package/dist/docs/instanced_InstancedTile.js.html +701 -0
  18. package/dist/docs/instanced_InstancedTileLoader.js.html +497 -0
  19. package/dist/docs/scripts/core.js +726 -0
  20. package/dist/docs/scripts/core.min.js +23 -0
  21. package/dist/docs/scripts/resize.js +90 -0
  22. package/dist/docs/scripts/search.js +265 -0
  23. package/dist/docs/scripts/search.min.js +6 -0
  24. package/dist/docs/scripts/third-party/Apache-License-2.0.txt +202 -0
  25. package/dist/docs/scripts/third-party/fuse.js +9 -0
  26. package/dist/docs/scripts/third-party/hljs-line-num-original.js +369 -0
  27. package/dist/docs/scripts/third-party/hljs-line-num.js +1 -0
  28. package/dist/docs/scripts/third-party/hljs-original.js +5171 -0
  29. package/dist/docs/scripts/third-party/hljs.js +1 -0
  30. package/dist/docs/scripts/third-party/popper.js +5 -0
  31. package/dist/docs/scripts/third-party/tippy.js +1 -0
  32. package/dist/docs/scripts/third-party/tocbot.js +672 -0
  33. package/dist/docs/scripts/third-party/tocbot.min.js +1 -0
  34. package/dist/docs/styles/clean-jsdoc-theme-base.css +1159 -0
  35. package/dist/docs/styles/clean-jsdoc-theme-dark.css +412 -0
  36. package/dist/docs/styles/clean-jsdoc-theme-light.css +482 -0
  37. package/dist/docs/styles/clean-jsdoc-theme-scrollbar.css +30 -0
  38. package/dist/docs/styles/clean-jsdoc-theme-without-scrollbar.min.css +1 -0
  39. package/dist/docs/styles/clean-jsdoc-theme.min.css +1 -0
  40. package/dist/entry.d.ts +1 -1
  41. package/dist/threedtiles.min.js +1 -1
  42. package/dist/threedtiles.min.js.map +1 -1
  43. package/package.json +1 -1
@@ -0,0 +1,497 @@
1
+ <!DOCTYPE html><html lang="en" style="font-size:16px"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Source: instanced/InstancedTileLoader.js</title><!--[if lt IE 9]>
2
+ <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
3
+ <![endif]--><script src="scripts/third-party/hljs.js" defer="defer"></script><script src="scripts/third-party/hljs-line-num.js" defer="defer"></script><script src="scripts/third-party/popper.js" defer="defer"></script><script src="scripts/third-party/tippy.js" defer="defer"></script><script src="scripts/third-party/tocbot.min.js"></script><script>var baseURL="/",locationPathname="";baseURL=(locationPathname=document.location.pathname).substr(0,locationPathname.lastIndexOf("/")+1)</script><link rel="stylesheet" href="styles/clean-jsdoc-theme.min.css"><svg aria-hidden="true" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" style="display:none"><defs><symbol id="copy-icon" viewbox="0 0 488.3 488.3"><g><path d="M314.25,85.4h-227c-21.3,0-38.6,17.3-38.6,38.6v325.7c0,21.3,17.3,38.6,38.6,38.6h227c21.3,0,38.6-17.3,38.6-38.6V124 C352.75,102.7,335.45,85.4,314.25,85.4z M325.75,449.6c0,6.4-5.2,11.6-11.6,11.6h-227c-6.4,0-11.6-5.2-11.6-11.6V124 c0-6.4,5.2-11.6,11.6-11.6h227c6.4,0,11.6,5.2,11.6,11.6V449.6z"/><path d="M401.05,0h-227c-21.3,0-38.6,17.3-38.6,38.6c0,7.5,6,13.5,13.5,13.5s13.5-6,13.5-13.5c0-6.4,5.2-11.6,11.6-11.6h227 c6.4,0,11.6,5.2,11.6,11.6v325.7c0,6.4-5.2,11.6-11.6,11.6c-7.5,0-13.5,6-13.5,13.5s6,13.5,13.5,13.5c21.3,0,38.6-17.3,38.6-38.6 V38.6C439.65,17.3,422.35,0,401.05,0z"/></g></symbol><symbol id="search-icon" viewBox="0 0 512 512"><g><g><path d="M225.474,0C101.151,0,0,101.151,0,225.474c0,124.33,101.151,225.474,225.474,225.474 c124.33,0,225.474-101.144,225.474-225.474C450.948,101.151,349.804,0,225.474,0z M225.474,409.323 c-101.373,0-183.848-82.475-183.848-183.848S124.101,41.626,225.474,41.626s183.848,82.475,183.848,183.848 S326.847,409.323,225.474,409.323z"/></g></g><g><g><path d="M505.902,476.472L386.574,357.144c-8.131-8.131-21.299-8.131-29.43,0c-8.131,8.124-8.131,21.306,0,29.43l119.328,119.328 c4.065,4.065,9.387,6.098,14.715,6.098c5.321,0,10.649-2.033,14.715-6.098C514.033,497.778,514.033,484.596,505.902,476.472z"/></g></g></symbol><symbol id="font-size-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11.246 15H4.754l-2 5H.6L7 4h2l6.4 16h-2.154l-2-5zm-.8-2L8 6.885 5.554 13h4.892zM21 12.535V12h2v8h-2v-.535a4 4 0 1 1 0-6.93zM19 18a2 2 0 1 0 0-4 2 2 0 0 0 0 4z"/></symbol><symbol id="add-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M11 11V5h2v6h6v2h-6v6h-2v-6H5v-2z"/></symbol><symbol id="minus-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M5 11h14v2H5z"/></symbol><symbol id="dark-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M10 7a7 7 0 0 0 12 4.9v.1c0 5.523-4.477 10-10 10S2 17.523 2 12 6.477 2 12 2h.1A6.979 6.979 0 0 0 10 7zm-6 5a8 8 0 0 0 15.062 3.762A9 9 0 0 1 8.238 4.938 7.999 7.999 0 0 0 4 12z"/></symbol><symbol id="light-theme-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 18a6 6 0 1 1 0-12 6 6 0 0 1 0 12zm0-2a4 4 0 1 0 0-8 4 4 0 0 0 0 8zM11 1h2v3h-2V1zm0 19h2v3h-2v-3zM3.515 4.929l1.414-1.414L7.05 5.636 5.636 7.05 3.515 4.93zM16.95 18.364l1.414-1.414 2.121 2.121-1.414 1.414-2.121-2.121zm2.121-14.85l1.414 1.415-2.121 2.121-1.414-1.414 2.121-2.121zM5.636 16.95l1.414 1.414-2.121 2.121-1.414-1.414 2.121-2.121zM23 11v2h-3v-2h3zM4 11v2H1v-2h3z"/></symbol><symbol id="reset-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M18.537 19.567A9.961 9.961 0 0 1 12 22C6.477 22 2 17.523 2 12S6.477 2 12 2s10 4.477 10 10c0 2.136-.67 4.116-1.81 5.74L17 12h3a8 8 0 1 0-2.46 5.772l.997 1.795z"/></symbol><symbol id="down-icon" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M12.7803 6.21967C13.0732 6.51256 13.0732 6.98744 12.7803 7.28033L8.53033 11.5303C8.23744 11.8232 7.76256 11.8232 7.46967 11.5303L3.21967 7.28033C2.92678 6.98744 2.92678 6.51256 3.21967 6.21967C3.51256 5.92678 3.98744 5.92678 4.28033 6.21967L8 9.93934L11.7197 6.21967C12.0126 5.92678 12.4874 5.92678 12.7803 6.21967Z"></path></symbol><symbol id="codepen-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M16.5 13.202L13 15.535v3.596L19.197 15 16.5 13.202zM14.697 12L12 10.202 9.303 12 12 13.798 14.697 12zM20 10.869L18.303 12 20 13.131V10.87zM19.197 9L13 4.869v3.596l3.5 2.333L19.197 9zM7.5 10.798L11 8.465V4.869L4.803 9 7.5 10.798zM4.803 15L11 19.131v-3.596l-3.5-2.333L4.803 15zM4 13.131L5.697 12 4 10.869v2.262zM2 9a1 1 0 0 1 .445-.832l9-6a1 1 0 0 1 1.11 0l9 6A1 1 0 0 1 22 9v6a1 1 0 0 1-.445.832l-9 6a1 1 0 0 1-1.11 0l-9-6A1 1 0 0 1 2 15V9z"/></symbol><symbol id="close-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M12 10.586l4.95-4.95 1.414 1.414-4.95 4.95 4.95 4.95-1.414 1.414-4.95-4.95-4.95 4.95-1.414-1.414 4.95-4.95-4.95-4.95L7.05 5.636z"/></symbol><symbol id="menu-icon" viewBox="0 0 24 24"><path fill="none" d="M0 0h24v24H0z"/><path d="M3 4h18v2H3V4zm0 7h18v2H3v-2zm0 7h18v2H3v-2z"/></symbol></defs></svg></head><body data-theme="dark"><div class="sidebar-container"><div class="sidebar" id="sidebar"><div class="sidebar-items-container"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="InstancedOGC3DTile.html">InstancedOGC3DTile</a></div><div class="sidebar-section-children"><a href="InstancedTile.html">InstancedTile</a></div><div class="sidebar-section-children"><a href="InstancedTileLoader.html">InstancedTileLoader</a></div><div class="sidebar-section-children"><a href="OGC3DTile.html">OGC3DTile</a></div><div class="sidebar-section-children"><a href="OcclusionCullingService.html">OcclusionCullingService</a></div><div class="sidebar-section-children"><a href="TileLoader.html">TileLoader</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#getOGC3DTilesCopyrightInfo">getOGC3DTilesCopyrightInfo</a></div></div></div></div></div><div class="navbar-container" id="VuAckcnZhf"><nav class="navbar"><div class="navbar-left-items"></div><div class="navbar-right-items"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div><nav></nav></nav></div><div class="toc-container"><div class="toc-content"><span class="bold">On this page</span><div id="eed4d2a0bfd64539bb9df78095dec881"></div></div></div><div class="body-wrapper"><div class="main-content"><div class="main-wrapper"><section id="source-page" class="source-page"><header><h1 id="title" class="has-anchor">instanced_InstancedTileLoader.js</h1></header><article><pre class="prettyprint source lang-js"><code>import * as THREE from 'three';
4
+ import { LinkedHashMap } from 'js-utils-z';
5
+ import { B3DMDecoder } from "../../decoder/B3DMDecoder";
6
+ import { MeshTile } from './MeshTile';
7
+ import { JsonTile } from './JsonTile';
8
+ import { GLTFLoader } from 'three/addons/loaders/GLTFLoader.js';
9
+ import { DRACOLoader } from 'three/addons/loaders/DRACOLoader.js';
10
+ import { KTX2Loader } from "three/addons/loaders/KTX2Loader";
11
+ import { resolveImplicite } from '../implicit/ImplicitTileResolver.js';
12
+ import { InstancedOGC3DTile } from './InstancedOGC3DTile';
13
+ import { MeshoptDecoder } from 'meshoptimizer';
14
+
15
+ let concurrentDownloads = 0;
16
+
17
+
18
+ /**
19
+ * A Tile loader that manages caching and load order for instanced tiles.
20
+ * The cache is an LRU cache and is defined by the number of items it can hold.
21
+ * The actual number of cached items might grow beyond max if all items are in use.
22
+ *
23
+ * The load order is designed for optimal perceived loading speed (nearby tiles are refined first).
24
+ *
25
+ */
26
+ class InstancedTileLoader {
27
+ /**
28
+ * Creates a tile loader with a maximum number of cached items and callbacks.
29
+ * The only required property is a renderer that will be used to visualize the tiles.
30
+ * The maxCachedItems property is the size of the cache in number of objects, mesh tile and tileset.json files.
31
+ * The mesh and point callbacks will be called for every incoming mesh or points.
32
+ *
33
+ * @param {scene} [scene] - a threejs scene.
34
+ * @param {Object} [options] - Optional configuration object.
35
+ * @param {number} [options.maxCachedItems=100] - the cache size.
36
+ * @param {number} [options.maxInstances=1] - the cache size.
37
+ * @param {function} [options.meshCallback] - A callback to call on newly decoded meshes.
38
+ * @param {function} [options.pointsCallback] - A callback to call on newly decoded points.
39
+ * @param {sring} [options.proxy] - An optional proxy that tile requests will be directed too as POST requests with the actual tile url in the body of the request.
40
+ * @param {KTX2Loader} [options.ktx2Loader = undefined] - A KTX2Loader (three/addons)
41
+ * @param {DRACOLoader} [options.dracoLoader = undefined] - A DRACOLoader (three/addons)
42
+ * @param {renderer} [options.renderer = undefined] - optional the renderer, this is required only for on the fly ktx2 support. not needed if you pass a ktx2Loader manually
43
+
44
+ */
45
+ constructor(scene, options) {
46
+ this.zUpToYUpMatrix = new THREE.Matrix4();
47
+ this.zUpToYUpMatrix.set(1, 0, 0, 0,
48
+ 0, 0, -1, 0,
49
+ 0, 1, 0, 0,
50
+ 0, 0, 0, 1);
51
+ this.maxCachedItems = 100;
52
+ this.maxInstances = 1;
53
+ this.proxy = options.proxy;
54
+ if (!!options) {
55
+ this.meshCallback = options.meshCallback;
56
+ this.pointsCallback = options.pointsCallback;
57
+ if (options.maxCachedItems) this.maxCachedItems = options.maxCachedItems;
58
+ if (options.maxInstances) this.maxInstances = options.maxInstances;
59
+
60
+ }
61
+
62
+
63
+ this.gltfLoader = new GLTFLoader();
64
+ if (!!options &amp;&amp; !!options.dracoLoader) {
65
+ this.gltfLoader.setDRACOLoader(options.dracoLoader);
66
+ this.hasDracoLoader = true;
67
+ } else {
68
+ const dracoLoader = new DRACOLoader();
69
+ dracoLoader.setDecoderPath('https://www.gstatic.com/draco/versioned/decoders/1.4.3/');
70
+ this.gltfLoader.setDRACOLoader(dracoLoader);
71
+ this.gltfLoader.hasDracoLoader = true;
72
+ }
73
+
74
+ if (!!options &amp;&amp; !!options.ktx2Loader) {
75
+ this.gltfLoader.setKTX2Loader(options.ktx2Loader);
76
+ this.hasKTX2Loader = true;
77
+ } else if (!!options &amp;&amp; !!options.renderer) {
78
+ const ktx2Loader = new KTX2Loader();
79
+ ktx2Loader.setTranscoderPath('https://storage.googleapis.com/ogc-3d-tiles/basis/').detectSupport(options.renderer);
80
+ this.gltfLoader.setKTX2Loader(ktx2Loader);
81
+ this.gltfLoader.hasKTX2Loader = true;
82
+ }
83
+
84
+ this.gltfLoader.setMeshoptDecoder(MeshoptDecoder);
85
+ this.hasMeshOptDecoder = true;
86
+
87
+ this.b3dmDecoder = new B3DMDecoder(this.gltfLoader);
88
+
89
+
90
+ this.cache = new LinkedHashMap();
91
+ this.scene = scene;
92
+
93
+ this.ready = [];
94
+ this.downloads = [];
95
+ this.nextReady = [];
96
+ this.nextDownloads = [];
97
+
98
+ }
99
+
100
+ /**
101
+ * To be called in the render loop or at regular intervals.
102
+ * launches tile downloading and loading in an orderly fashion.
103
+ */
104
+ update() {
105
+ const self = this;
106
+ self._checkSize();
107
+ self.cache._data.forEach(v => {
108
+ v.update();
109
+ })
110
+
111
+ if (concurrentDownloads &lt; 8) {
112
+ self._download();
113
+ }
114
+ self._loadBatch();
115
+ }
116
+
117
+
118
+ _download() {
119
+ const self = this;
120
+ if (self.nextDownloads.length == 0) {
121
+ self._getNextDownloads();
122
+ if (self.nextDownloads.length == 0) return;
123
+ }
124
+ while (self.nextDownloads.length > 0) {
125
+ const nextDownload = self.nextDownloads.shift();
126
+ if (!!nextDownload) {//} &amp;&amp; nextDownload.shouldDoDownload()) {
127
+ //nextDownload.doDownload();
128
+ if (nextDownload.path.includes(".b3dm")) {
129
+ var fetchFunction;
130
+ if (!self.proxy) {
131
+ fetchFunction = () => {
132
+ return fetch(nextDownload.path);
133
+ }
134
+ } else {
135
+ fetchFunction = () => {
136
+ return fetch(self.proxy,
137
+ {
138
+ method: 'POST',
139
+ body: nextDownload.path
140
+ }
141
+ );
142
+ }
143
+ }
144
+ concurrentDownloads++;
145
+ fetchFunction().then(result => {
146
+ if (!result.ok) {
147
+ console.error("could not load tile with path : " + nextDownload.path)
148
+ throw new Error(`couldn't load "${nextDownload.path}". Request failed with status ${result.status} : ${result.statusText}`);
149
+ }
150
+ return result.arrayBuffer();
151
+
152
+ }).then(resultArrayBuffer => {
153
+ return this.b3dmDecoder.parseB3DMInstanced(resultArrayBuffer, (mesh) => { self.meshCallback(mesh, nextDownload.geometricError) }, self.maxInstances, nextDownload.sceneZupToYup, nextDownload.meshZupToYup);
154
+ }).then(mesh => {
155
+ mesh.frustumCulled = false;
156
+ nextDownload.tile.setObject(mesh);
157
+ self.ready.unshift(nextDownload);
158
+
159
+ }).catch(e => console.error(e))
160
+ .finally(() => {
161
+ concurrentDownloads--;
162
+ });
163
+ } if (nextDownload.path.includes(".glb") || (nextDownload.path.includes(".gltf"))) {
164
+ var fetchFunction;
165
+ if (!self.proxy) {
166
+ fetchFunction = () => {
167
+ return fetch(nextDownload.path);
168
+ }
169
+ } else {
170
+ fetchFunction = () => {
171
+ return fetch(self.proxy,
172
+ {
173
+ method: 'POST',
174
+ body: nextDownload.path
175
+ }
176
+ );
177
+ }
178
+ }
179
+ concurrentDownloads++;
180
+ fetchFunction().then(result => {
181
+ if (!result.ok) {
182
+ throw new Error("missing content");
183
+ }
184
+ return result.arrayBuffer();
185
+ }).then(async arrayBuffer => {
186
+ await _checkLoaderInitialized(this.gltfLoader);
187
+ this.gltfLoader.parse(arrayBuffer, null, gltf => {
188
+ gltf.scene.asset = gltf.asset;
189
+
190
+ if (nextDownload.sceneZupToYup) {
191
+ gltf.scene.applyMatrix4(this.zUpToYUpMatrix);
192
+ }
193
+ gltf.scene.traverse((o) => {
194
+ o.geometricError = nextDownload.geometricError;
195
+ if (o.isMesh) {
196
+ if (nextDownload.meshZupToYup) {
197
+ o.applyMatrix4(this.zUpToYUpMatrix);
198
+ }
199
+ if (!!self.meshCallback) {
200
+ self.meshCallback(o, o.geometricError);
201
+ }
202
+ }
203
+ if (o.isPoints) {
204
+ console.error("instanced point cloud is not supported");
205
+ }
206
+ });
207
+ let instancedMesh;
208
+ gltf.scene.updateWorldMatrix(false, true)
209
+ gltf.scene.traverse(child => {
210
+ //TODO several meshes in a single gltf
211
+ if (child.isMesh) {
212
+ instancedMesh = new THREE.InstancedMesh(child.geometry, child.material, self.maxInstances);
213
+ instancedMesh.baseMatrix = child.matrixWorld;
214
+ }
215
+
216
+ });
217
+ self.ready.unshift(nextDownload);
218
+ if (!instancedMesh) {
219
+ gltf.scene.traverse(c => {
220
+ if (c.dispose) c.dispose();
221
+ if (c.material) c.material.dispose();
222
+ });
223
+ } else {
224
+ instancedMesh.frustumCulled = false;
225
+ nextDownload.tile.setObject(instancedMesh);
226
+ }
227
+ });
228
+ }, e => {
229
+ console.error("could not load tile : " + nextDownload.path)
230
+ }).finally(() => {
231
+ concurrentDownloads--;
232
+ });
233
+
234
+
235
+
236
+ } else if (nextDownload.path.includes(".json")) {
237
+ var fetchFunction;
238
+ if (!self.proxy) {
239
+ fetchFunction = () => {
240
+ return fetch(nextDownload.path);
241
+ }
242
+ } else {
243
+ fetchFunction = () => {
244
+ return fetch(self.proxy,
245
+ {
246
+ method: 'POST',
247
+ body: nextDownload.path
248
+ }
249
+ );
250
+ }
251
+ }
252
+ concurrentDownloads++;
253
+ fetchFunction().then(result => {
254
+ if (!result.ok) {
255
+ console.error("could not load tile with path : " + nextDownload.path)
256
+ throw new Error(`couldn't load "${nextDownload.path}". Request failed with status ${result.status} : ${result.statusText}`);
257
+ }
258
+ return result.json();
259
+
260
+ }).then(json => {
261
+ return resolveImplicite(json, nextDownload.path)
262
+ }).then(json => {
263
+ nextDownload.tile.setObject(json, nextDownload.path);
264
+ self.ready.unshift(nextDownload);
265
+ })
266
+ .catch(e => console.error(e)).finally(() => {
267
+ concurrentDownloads--;
268
+ });
269
+ }
270
+ }
271
+ }
272
+ return;
273
+ }
274
+
275
+ _loadBatch() {
276
+ if (this.nextReady.length == 0) {
277
+ this._getNextReady();
278
+ if (this.nextReady.length == 0) return 0;
279
+ }
280
+ const download = this.nextReady.shift();
281
+ if (!download) return 0;
282
+
283
+ //if (!!download.tile.addToScene) download.tile.addToScene();
284
+ return 1;
285
+ }
286
+
287
+ _getNextReady() {
288
+ let smallestDistance = Number.MAX_VALUE;
289
+ let closest = -1;
290
+ for (let i = this.ready.length - 1; i >= 0; i--) {
291
+
292
+ if (!this.ready[i].distanceFunction) {// if no distance function, must be a json, give absolute priority!
293
+ this.nextReady.push(this.ready.splice(i, 1)[0]);
294
+ }
295
+ }
296
+ if (this.nextReady.length > 0) return;
297
+ for (let i = this.ready.length - 1; i >= 0; i--) {
298
+ const dist = this.ready[i].distanceFunction() * this.ready[i].level;
299
+ if (dist &lt; smallestDistance) {
300
+ smallestDistance = dist;
301
+ closest = i
302
+ }
303
+ }
304
+ if (closest >= 0) {
305
+ const closestItem = this.ready.splice(closest, 1).pop();
306
+ this.nextReady.push(closestItem);
307
+ const siblings = closestItem.getSiblings();
308
+ for (let i = this.ready.length - 1; i >= 0; i--) {
309
+ if (siblings.includes(this.ready[i].uuid)) {
310
+ this.nextready.push(this.ready.splice(i, 1).pop());
311
+ }
312
+ }
313
+ }
314
+ }
315
+
316
+ /**
317
+ * Schedules a tile content to be downloaded
318
+ *
319
+ * @param {AbortController} abortController
320
+ * @param {string} path path or url to tile content
321
+ * @param {string|Number} uuid tile id
322
+ * @param {InstancedOGC3DTile} instancedOGC3DTile
323
+ * @param {Function} distanceFunction
324
+ * @param {Function} getSiblings
325
+ * @param {Number} level
326
+ * @param {Boolean} sceneZupToYup
327
+ * @param {Boolean} meshZupToYup
328
+ * @param {Number} geometricError
329
+ */
330
+ get(abortController, path, uuid, instancedOGC3DTile, distanceFunction, getSiblings, level, sceneZupToYup, meshZupToYup, geometricError) {
331
+ const self = this;
332
+ const key = _simplifyPath(path);
333
+
334
+ if (!path.includes(".b3dm") &amp;&amp; !path.includes(".json") &amp;&amp; !path.includes(".glb") &amp;&amp; !path.includes(".gltf")) {
335
+ console.error("the 3DTiles cache can only be used to load B3DM, gltf and json data");
336
+ return;
337
+ }
338
+
339
+ const cachedTile = self.cache.get(key);
340
+ if (!!cachedTile) {
341
+ cachedTile.addInstance(instancedOGC3DTile);
342
+ return;
343
+ } else {
344
+
345
+ if (path.includes(".b3dm") || path.includes(".glb") || path.includes(".gltf")) {
346
+ const tile = new MeshTile(self.scene);
347
+ tile.addInstance(instancedOGC3DTile);
348
+
349
+ self.cache.put(key, tile);
350
+ //self._checkSize();
351
+ const realAbortController = new AbortController();
352
+ abortController.signal.addEventListener("abort", () => {
353
+ if (tile.getCount() == 0) {
354
+ realAbortController.abort();
355
+ }
356
+ })
357
+ this.downloads.push({
358
+ abortController: realAbortController,
359
+ tile: tile,
360
+ key: key,
361
+ path: path,
362
+ distanceFunction: distanceFunction,
363
+ getSiblings: getSiblings,
364
+ level: level,
365
+ uuid: uuid,
366
+ sceneZupToYup: sceneZupToYup,
367
+ meshZupToYup: meshZupToYup,
368
+ geometricError: geometricError,
369
+ shouldDoDownload: () => {
370
+ return true;
371
+ },
372
+ })
373
+ } else if (path.includes(".json")) {
374
+ const tile = new JsonTile();
375
+ tile.addInstance(instancedOGC3DTile);
376
+ self.cache.put(key, tile);
377
+ //self._checkSize();
378
+ const realAbortController = new AbortController();
379
+ abortController.signal.addEventListener("abort", () => {
380
+ if (tile.getCount() == 0) {
381
+ realAbortController.abort();
382
+ }
383
+ })
384
+ this.downloads.push({
385
+ abortController: realAbortController,
386
+ tile: tile,
387
+ key: key,
388
+ path: path,
389
+ distanceFunction: distanceFunction,
390
+ getSiblings: getSiblings,
391
+ level: level,
392
+ shouldDoDownload: () => {
393
+ return true;
394
+ },
395
+ })
396
+
397
+ }
398
+ }
399
+ }
400
+
401
+
402
+
403
+ _getNextDownloads() {
404
+ let smallestDistance = Number.MAX_VALUE;
405
+ let closest = -1;
406
+ for (let i = this.downloads.length - 1; i >= 0; i--) {
407
+ const download = this.downloads[i];
408
+ if (!download.shouldDoDownload()) {
409
+ this.downloads.splice(i, 1);
410
+ continue;
411
+ }
412
+ if (!download.distanceFunction) { // if no distance function, must be a json, give absolute priority!
413
+ this.nextDownloads.push(this.downloads.splice(i, 1)[0]);
414
+ }
415
+ }
416
+ if (this.nextDownloads.length > 0) return;
417
+ for (let i = this.downloads.length - 1; i >= 0; i--) {
418
+ const download = this.downloads[i];
419
+ const dist = download.distanceFunction() * download.level;
420
+ if (dist &lt; smallestDistance) {
421
+ smallestDistance = dist;
422
+ closest = i;
423
+ }
424
+ }
425
+ if (closest >= 0) {
426
+ const closestItem = this.downloads.splice(closest, 1).pop();
427
+ this.nextDownloads.push(closestItem);
428
+ const siblings = closestItem.getSiblings();
429
+ for (let i = this.downloads.length - 1; i >= 0; i--) {
430
+ if (siblings.includes(this.downloads[i].uuid)) {
431
+ this.nextDownloads.push(this.downloads.splice(i, 1).pop());
432
+ }
433
+ }
434
+ }
435
+ }
436
+
437
+ _checkSize() {
438
+ const self = this;
439
+
440
+ let i = 0;
441
+
442
+ while (self.cache.size() > self.maxCachedItems &amp;&amp; i &lt; self.cache.size()) {
443
+ i++;
444
+ const entry = self.cache.head();
445
+ self.cache.remove(entry.key);
446
+ if (!entry.value.dispose()) {
447
+ self.cache.put(entry.key, entry.value);
448
+ } else {
449
+ //console.log("disposed and removed")
450
+ }
451
+
452
+ }
453
+ }
454
+ }
455
+
456
+ async function _checkLoaderInitialized(loader) {
457
+
458
+ const self = this;
459
+ return new Promise((resolve) => {
460
+ const interval = setInterval(() => {
461
+ if ((!loader.hasDracoLoader || loader.dracoLoader) &amp;&amp; (!loader.hasKTX2Loader || loader.ktx2Loader)) {
462
+ clearInterval(interval);
463
+ resolve();
464
+ }
465
+ }, 10); // check every 100ms
466
+ });
467
+ };
468
+
469
+ function _simplifyPath(main_path) {
470
+
471
+ var parts = main_path.split('/'),
472
+ new_path = [],
473
+ length = 0;
474
+ for (var i = 0; i &lt; parts.length; i++) {
475
+ var part = parts[i];
476
+ if (part === '.' || part === '' || part === '..') {
477
+ if (part === '..' &amp;&amp; length > 0) {
478
+ length--;
479
+ }
480
+ continue;
481
+ }
482
+ new_path[length++] = part;
483
+ }
484
+
485
+ if (length === 0) {
486
+ return '/';
487
+ }
488
+
489
+ var result = '';
490
+ for (var i = 0; i &lt; length; i++) {
491
+ result += '/' + new_path[i];
492
+ }
493
+
494
+ return result;
495
+ }
496
+
497
+ export { InstancedTileLoader };</code></pre></article></section></div></div></div><div class="search-container" id="PkfLWpAbet" style="display:none"><div class="wrapper" id="iCxFxjkHbP"><button class="icon-button search-close-button" id="VjLlGakifb" aria-label="close search"><svg><use xlink:href="#close-icon"></use></svg></button><div class="search-box-c"><svg><use xlink:href="#search-icon"></use></svg> <input type="text" id="vpcKVYIppa" class="search-input" placeholder="Search..." autofocus></div><div class="search-result-c" id="fWwVHRuDuN"><span class="search-result-c-text">Type anything to view search result</span></div></div></div><div class="mobile-menu-icon-container"><button class="icon-button" id="mobile-menu" data-isopen="false" aria-label="menu"><svg><use xlink:href="#menu-icon"></use></svg></button></div><div id="mobile-sidebar" class="mobile-sidebar-container"><div class="mobile-sidebar-wrapper"><div class="mobile-nav-links"></div><div class="mobile-sidebar-items-c"><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-classes"><div>Classes</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="InstancedOGC3DTile.html">InstancedOGC3DTile</a></div><div class="sidebar-section-children"><a href="InstancedTile.html">InstancedTile</a></div><div class="sidebar-section-children"><a href="InstancedTileLoader.html">InstancedTileLoader</a></div><div class="sidebar-section-children"><a href="OGC3DTile.html">OGC3DTile</a></div><div class="sidebar-section-children"><a href="OcclusionCullingService.html">OcclusionCullingService</a></div><div class="sidebar-section-children"><a href="TileLoader.html">TileLoader</a></div></div><div class="sidebar-section-title with-arrow" data-isopen="false" id="sidebar-global"><div>Global</div><svg><use xlink:href="#down-icon"></use></svg></div><div class="sidebar-section-children-container"><div class="sidebar-section-children"><a href="global.html#getOGC3DTilesCopyrightInfo">getOGC3DTilesCopyrightInfo</a></div></div></div><div class="mobile-navbar-actions"><div class="navbar-right-item"><button class="icon-button search-button" aria-label="open-search"><svg><use xlink:href="#search-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button theme-toggle" aria-label="toggle-theme"><svg><use class="theme-svg-use" xlink:href="#light-theme-icon"></use></svg></button></div><div class="navbar-right-item"><button class="icon-button font-size" aria-label="change-font-size"><svg><use xlink:href="#font-size-icon"></use></svg></button></div></div></div></div><script type="text/javascript" src="scripts/core.min.js"></script><script src="scripts/search.min.js" defer="defer"></script><script src="scripts/third-party/fuse.js" defer="defer"></script><script type="text/javascript">var tocbotInstance=tocbot.init({tocSelector:"#eed4d2a0bfd64539bb9df78095dec881",contentSelector:".main-content",headingSelector:"h1, h2, h3",hasInnerContainers:!0,scrollContainer:".main-content",headingsOffset:130,onClick:bringLinkToView})</script></body></html>