@loaders.gl/tiles 4.4.0-alpha.9 → 4.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -224,10 +224,34 @@ function calculateTransformProps(tileHeader, tile) {
224
224
  const toFixedFrameMatrix = fromFixedFrameMatrix.invert();
225
225
  tile.cartographicModelMatrix = toFixedFrameMatrix.multiplyRight(modelMatrix);
226
226
  tile.cartographicOrigin = cartographicOrigin;
227
+ const rootNode = _getRootNode(tile);
228
+ if (rootNode) {
229
+ tile.cartesianModelMatrix = new import_core.Matrix4(modelMatrix).multiplyRight(rootNode.matrix);
230
+ tile.cartographicModelMatrix.multiplyRight(rootNode.matrix);
231
+ rootNode.matrix = import_core.Matrix4.IDENTITY;
232
+ }
227
233
  if (!tile.coordinateSystem) {
228
234
  tile.modelMatrix = tile.cartographicModelMatrix;
229
235
  }
230
236
  }
237
+ var TRANSLATION_LIMIT_SQUARED = 1e6 ** 2;
238
+ function _getRootNode(tile) {
239
+ var _a, _b;
240
+ const gltf = tile.gltf;
241
+ if (!gltf) {
242
+ return null;
243
+ }
244
+ const sceneIndex = typeof gltf.scene === "number" ? gltf.scene : 0;
245
+ const scene = (_a = gltf.scenes) == null ? void 0 : _a[sceneIndex];
246
+ const rootNode = (_b = scene == null ? void 0 : scene.nodes) == null ? void 0 : _b[0];
247
+ if (!(rootNode == null ? void 0 : rootNode.matrix))
248
+ return null;
249
+ const m = rootNode.matrix;
250
+ const translationMagnitude = m[12] * m[12] + m[13] * m[13] + m[14] * m[14];
251
+ if (translationMagnitude <= TRANSLATION_LIMIT_SQUARED)
252
+ return null;
253
+ return rootNode;
254
+ }
231
255
 
232
256
  // dist/tileset/helpers/frame-state.js
233
257
  var import_core2 = require("@math.gl/core");
@@ -1095,7 +1119,7 @@ var TilesetTraverser = class {
1095
1119
  }
1096
1120
  }
1097
1121
  }
1098
- return allDescendantsLoaded;
1122
+ return root.hasEmptyContent || allDescendantsLoaded;
1099
1123
  }
1100
1124
  };
1101
1125
 
@@ -1169,6 +1193,13 @@ var Tile3D = class {
1169
1193
  _inRequestVolume = false;
1170
1194
  _lodJudge = null;
1171
1195
  // TODO i3s specific, needs to remove
1196
+ /**
1197
+ * Indicates whether the tile has been drawn by the renderer.
1198
+ * Defaults to true for backwards compatibility — renderers that support
1199
+ * transition hold (e.g. deck.gl 9.3+) should set this to false on tile load,
1200
+ * then back to true after first draw to avoid flashes (see deck.gl #7914).
1201
+ */
1202
+ tileDrawn = true;
1172
1203
  /**
1173
1204
  * @constructs
1174
1205
  * Create a Tile3D instance
@@ -1388,6 +1419,7 @@ var Tile3D = class {
1388
1419
  }
1389
1420
  this.header.content = null;
1390
1421
  this.contentState = TILE_CONTENT_STATE.UNLOADED;
1422
+ this.tileDrawn = true;
1391
1423
  return true;
1392
1424
  }
1393
1425
  /**
@@ -1848,6 +1880,8 @@ var DEFAULT_PROPS2 = {
1848
1880
  onTileError: () => {
1849
1881
  },
1850
1882
  onTraversalComplete: (selectedTiles) => selectedTiles,
1883
+ onUpdate: () => {
1884
+ },
1851
1885
  contentLoader: void 0,
1852
1886
  viewDistanceScale: 1,
1853
1887
  maximumScreenSpaceError: 8,
@@ -1941,6 +1975,8 @@ var Tileset3D = class {
1941
1975
  _traverser;
1942
1976
  _cache = new TilesetCache();
1943
1977
  _requestScheduler;
1978
+ /** Tile IDs held visible during transitions until replacements have drawn */
1979
+ _heldTiles = /* @__PURE__ */ new Set();
1944
1980
  // Promise tracking
1945
1981
  updatePromise = null;
1946
1982
  tilesetInitializationPromise;
@@ -2146,6 +2182,7 @@ var Tileset3D = class {
2146
2182
  * Update tiles relying on data from all traversers
2147
2183
  */
2148
2184
  _updateTiles() {
2185
+ const previousSelectedTiles = this.selectedTiles;
2149
2186
  this.selectedTiles = [];
2150
2187
  this._requestedTiles = [];
2151
2188
  this._emptyTiles = [];
@@ -2156,12 +2193,42 @@ var Tileset3D = class {
2156
2193
  this._emptyTiles = this._emptyTiles.concat(frameStateDataValue._emptyTiles);
2157
2194
  }
2158
2195
  this.selectedTiles = this.options.onTraversalComplete(this.selectedTiles);
2196
+ const selectedIds = new Set(this.selectedTiles.map((t) => t.id));
2197
+ const hasUndrawnTiles = this.selectedTiles.some((t) => !t.tileDrawn);
2198
+ let heldBackCount = 0;
2199
+ if (hasUndrawnTiles) {
2200
+ for (const tileId of selectedIds) {
2201
+ this._heldTiles.add(tileId);
2202
+ }
2203
+ for (const tileId of this._heldTiles) {
2204
+ if (selectedIds.has(tileId))
2205
+ continue;
2206
+ const tile = this._tiles[tileId];
2207
+ if (tile && tile.contentAvailable) {
2208
+ tile._selectedFrame = this._frameNumber;
2209
+ this.selectedTiles.push(tile);
2210
+ heldBackCount++;
2211
+ } else {
2212
+ this._heldTiles.delete(tileId);
2213
+ }
2214
+ }
2215
+ } else {
2216
+ this._heldTiles = selectedIds;
2217
+ }
2218
+ if (heldBackCount > 0) {
2219
+ setTimeout(() => {
2220
+ this.selectTiles();
2221
+ }, 0);
2222
+ }
2159
2223
  for (const tile of this.selectedTiles) {
2160
2224
  this._tiles[tile.id] = tile;
2161
2225
  }
2162
2226
  this._loadTiles();
2163
2227
  this._unloadTiles();
2164
2228
  this._updateStats();
2229
+ if (this._tilesChanged(previousSelectedTiles, this.selectedTiles)) {
2230
+ this.options.onUpdate();
2231
+ }
2165
2232
  }
2166
2233
  _tilesChanged(oldSelectedTiles, selectedTiles) {
2167
2234
  if (oldSelectedTiles.length !== selectedTiles.length) {
@@ -2174,6 +2241,7 @@ var Tileset3D = class {
2174
2241
  return changed;
2175
2242
  }
2176
2243
  _loadTiles() {
2244
+ this._requestedTiles.sort((a, b) => a._priority - b._priority);
2177
2245
  for (const tile of this._requestedTiles) {
2178
2246
  if (tile.contentUnloaded) {
2179
2247
  this._loadTile(tile);