itowns 2.45.2-next.3 → 2.45.2-next.5

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.
@@ -189,6 +189,7 @@ declare class OGC3DTilesLayer extends GeometryLayer {
189
189
  * @private
190
190
  */
191
191
  private _setupCacheAndQueues;
192
+ _viewId: any;
192
193
  /**
193
194
  * Binds 3d-tiles-renderer events to this layer.
194
195
  * @private
@@ -271,7 +272,7 @@ declare class OGC3DTilesLayer extends GeometryLayer {
271
272
  * 1. tile (Object) - the JSON tile
272
273
  * 2. scene (THREE.Object3D | null) - The tile content. Contains a `batchTable` property. Can be null if the tile
273
274
  * has not yet been loaded.
274
- */
275
+ */
275
276
  forEachTile(callback: Function): void;
276
277
  }
277
278
  import GeometryLayer from '../Layer/GeometryLayer';
@@ -291,16 +291,12 @@ class OGC3DTilesLayer extends GeometryLayer {
291
291
  if (config.sseThreshold) {
292
292
  this.sseThreshold = config.sseThreshold;
293
293
  }
294
+
294
295
  // Used for custom schedule callbacks (VR)
295
296
  this.tasks = [];
296
297
  this.tilesSchedulingCB = func => {
297
298
  this.tasks.push(func);
298
299
  };
299
- // We set our scheduling callback for tiles downloading and parsing -> MANDATORY for VR
300
- // (WebXR session has its own requestAnimationFrame method separate from that of the window
301
- // https://github.com/NASA-AMMOS/3DTilesRendererJS/issues/213#issuecomment-947943386)
302
- this.tilesRenderer.downloadQueue.schedulingCallback = this.tilesSchedulingCB;
303
- this.tilesRenderer.parseQueue.schedulingCallback = this.tilesSchedulingCB;
304
300
  }
305
301
 
306
302
  /**
@@ -311,20 +307,46 @@ class OGC3DTilesLayer extends GeometryLayer {
311
307
  */
312
308
  _setupCacheAndQueues(view) {
313
309
  const id = view.id;
310
+ // Share the caches and queues to cut down on memory and correctly prioritize downloads.
311
+ // https://github.com/NASA-AMMOS/3DTilesRendererJS?tab=readme-ov-file#multiple-tilesrenderers-with-shared-caches-and-queues
314
312
  if (viewers[id]) {
315
313
  this.tilesRenderer.lruCache = viewers[id].lruCache;
316
314
  this.tilesRenderer.downloadQueue = viewers[id].downloadQueue;
317
315
  this.tilesRenderer.parseQueue = viewers[id].parseQueue;
316
+
317
+ // Add this layer's callback to the map
318
+ viewers[id].layerCallbacks[this.id] = this.tilesSchedulingCB;
318
319
  } else {
320
+ // Create a combined callback that calls all layer callbacks
321
+ const combinedCallback = func => {
322
+ Object.values(viewers[id].layerCallbacks).forEach(callback => {
323
+ callback(func);
324
+ });
325
+ };
326
+
327
+ // Set the combined callback
328
+ // We set our scheduling callback for tiles downloading and parsing -> MANDATORY for VR
329
+ // (WebXR session has its own requestAnimationFrame method separate from that of the window
330
+ // https://github.com/NASA-AMMOS/3DTilesRendererJS/issues/213#issuecomment-947943386)
331
+ // Necessary to update rendering of the tiles in VR
332
+ // Example: https://github.com/NASA-AMMOS/3DTilesRendererJS/blob/de25d27dc0e75278962b5f401faee30f8dce2fe0/example/vr.js
333
+ this.tilesRenderer.downloadQueue.schedulingCallback = combinedCallback;
334
+ this.tilesRenderer.parseQueue.schedulingCallback = combinedCallback;
319
335
  viewers[id] = {
320
336
  lruCache: this.tilesRenderer.lruCache,
321
337
  downloadQueue: this.tilesRenderer.downloadQueue,
322
- parseQueue: this.tilesRenderer.parseQueue
338
+ parseQueue: this.tilesRenderer.parseQueue,
339
+ layerCallbacks: {
340
+ [this.id]: this.tilesSchedulingCB
341
+ }
323
342
  };
324
343
  view.addEventListener(VIEW_EVENTS.DISPOSED, evt => {
325
344
  delete viewers[evt.target.id];
326
345
  });
327
346
  }
347
+
348
+ // Store the view reference for cleanup
349
+ this._viewId = id;
328
350
  }
329
351
 
330
352
  /**
@@ -439,7 +461,20 @@ class OGC3DTilesLayer extends GeometryLayer {
439
461
  * Deletes the layer and frees associated memory
440
462
  */
441
463
  delete() {
464
+ // Clean up the callback reference from the shared callbacks
465
+ if (this._viewId != null && viewers[this._viewId]?.layerCallbacks) {
466
+ delete viewers[this._viewId].layerCallbacks[this.id];
467
+
468
+ // If no more layers are using this view's queues, clean up completely
469
+ if (Object.keys(viewers[this._viewId].layerCallbacks).length === 0) {
470
+ delete viewers[this._viewId];
471
+ }
472
+ }
442
473
  this.tilesRenderer.dispose();
474
+
475
+ // Clean up references
476
+ this.tilesSchedulingCB = null;
477
+ this._viewId = null;
443
478
  }
444
479
 
445
480
  /**
@@ -488,7 +523,7 @@ class OGC3DTilesLayer extends GeometryLayer {
488
523
 
489
524
  /** @type{number|null} */
490
525
  let batchId;
491
- if (object.isPoints && index) {
526
+ if (object.isPoints && index != null) {
492
527
  batchId = object.geometry.getAttribute('_BATCHID')?.getX(index) ?? index;
493
528
  } else if (object.isMesh && face) {
494
529
  batchId = object.geometry.getAttribute('_BATCHID')?.getX(face.a) ?? instanceId;
@@ -554,7 +589,7 @@ class OGC3DTilesLayer extends GeometryLayer {
554
589
  * 1. tile (Object) - the JSON tile
555
590
  * 2. scene (THREE.Object3D | null) - The tile content. Contains a `batchTable` property. Can be null if the tile
556
591
  * has not yet been loaded.
557
- */
592
+ */
558
593
  forEachTile(callback) {
559
594
  this.tilesRenderer.traverse(tile => {
560
595
  callback(tile, tile.cached.scene);
package/lib/Main.js CHANGED
@@ -1,5 +1,5 @@
1
1
  const conf = {
2
- version: '2.45.2-next.3'
2
+ version: '2.45.2-next.5'
3
3
  };
4
4
  export const REVISION = conf.version;
5
5
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "itowns",
3
- "version": "2.45.2-next.3",
3
+ "version": "2.45.2-next.5",
4
4
  "description": "A JS/WebGL framework for 3D geospatial data visualization",
5
5
  "type": "module",
6
6
  "main": "lib/Main.js",
@@ -51,7 +51,7 @@
51
51
  "url": "https://github.com/iTowns/itowns/issues"
52
52
  },
53
53
  "dependencies": {
54
- "@itowns/geographic": "^2.45.2-next.3",
54
+ "@itowns/geographic": "^2.45.2-next.5",
55
55
  "@mapbox/vector-tile": "^2.0.3",
56
56
  "@maplibre/maplibre-gl-style-spec": "^23.1.0",
57
57
  "@tmcw/togeojson": "^7.0.0",