@itwin/frontend-tiles 3.7.0-dev.7 → 3.7.0-dev.8

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 (78) hide show
  1. package/.rush/temp/66eda89ae927be7163ab4886bb1a316597deda28.log +10 -0
  2. package/.rush/temp/operation/build_ci/state.json +1 -1
  3. package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts +4 -4
  4. package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts.map +1 -1
  5. package/lib/cjs/BatchedSpatialTileTreeRefs.js +133 -129
  6. package/lib/cjs/BatchedSpatialTileTreeRefs.js.map +1 -1
  7. package/lib/cjs/BatchedTile.d.ts +23 -23
  8. package/lib/cjs/BatchedTile.d.ts.map +1 -1
  9. package/lib/cjs/BatchedTile.js +251 -250
  10. package/lib/cjs/BatchedTile.js.map +1 -1
  11. package/lib/cjs/BatchedTileContentReader.d.ts +22 -22
  12. package/lib/cjs/BatchedTileContentReader.js +76 -76
  13. package/lib/cjs/BatchedTileContentReader.js.map +1 -1
  14. package/lib/cjs/BatchedTileTree.d.ts +22 -22
  15. package/lib/cjs/BatchedTileTree.js +52 -52
  16. package/lib/cjs/BatchedTileTree.js.map +1 -1
  17. package/lib/cjs/BatchedTileTreeReference.d.ts +21 -17
  18. package/lib/cjs/BatchedTileTreeReference.d.ts.map +1 -1
  19. package/lib/cjs/BatchedTileTreeReference.js +73 -49
  20. package/lib/cjs/BatchedTileTreeReference.js.map +1 -1
  21. package/lib/cjs/BatchedTileTreeSupplier.d.ts +5 -5
  22. package/lib/cjs/BatchedTileTreeSupplier.js +38 -38
  23. package/lib/cjs/BatchedTileTreeSupplier.js.map +1 -1
  24. package/lib/cjs/BatchedTilesetReader.d.ts +13 -13
  25. package/lib/cjs/BatchedTilesetReader.js +88 -88
  26. package/lib/cjs/BatchedTilesetReader.js.map +1 -1
  27. package/lib/cjs/FrontendTiles.d.ts +32 -21
  28. package/lib/cjs/FrontendTiles.d.ts.map +1 -1
  29. package/lib/cjs/FrontendTiles.js +26 -18
  30. package/lib/cjs/FrontendTiles.js.map +1 -1
  31. package/lib/cjs/LoggerCategory.d.ts +2 -2
  32. package/lib/cjs/LoggerCategory.js +9 -9
  33. package/lib/cjs/LoggerCategory.js.map +1 -1
  34. package/lib/cjs/frontend-tiles.d.ts +1 -1
  35. package/lib/cjs/frontend-tiles.js +17 -17
  36. package/lib/cjs/frontend-tiles.js.map +1 -1
  37. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  38. package/lib/esm/BatchedSpatialTileTreeRefs.d.ts +4 -4
  39. package/lib/esm/BatchedSpatialTileTreeRefs.d.ts.map +1 -1
  40. package/lib/esm/BatchedSpatialTileTreeRefs.js +129 -125
  41. package/lib/esm/BatchedSpatialTileTreeRefs.js.map +1 -1
  42. package/lib/esm/BatchedTile.d.ts +23 -23
  43. package/lib/esm/BatchedTile.d.ts.map +1 -1
  44. package/lib/esm/BatchedTile.js +247 -246
  45. package/lib/esm/BatchedTile.js.map +1 -1
  46. package/lib/esm/BatchedTileContentReader.d.ts +22 -22
  47. package/lib/esm/BatchedTileContentReader.js +72 -72
  48. package/lib/esm/BatchedTileContentReader.js.map +1 -1
  49. package/lib/esm/BatchedTileTree.d.ts +22 -22
  50. package/lib/esm/BatchedTileTree.js +48 -48
  51. package/lib/esm/BatchedTileTree.js.map +1 -1
  52. package/lib/esm/BatchedTileTreeReference.d.ts +21 -17
  53. package/lib/esm/BatchedTileTreeReference.d.ts.map +1 -1
  54. package/lib/esm/BatchedTileTreeReference.js +69 -45
  55. package/lib/esm/BatchedTileTreeReference.js.map +1 -1
  56. package/lib/esm/BatchedTileTreeSupplier.d.ts +5 -5
  57. package/lib/esm/BatchedTileTreeSupplier.js +34 -34
  58. package/lib/esm/BatchedTileTreeSupplier.js.map +1 -1
  59. package/lib/esm/BatchedTilesetReader.d.ts +13 -13
  60. package/lib/esm/BatchedTilesetReader.js +84 -84
  61. package/lib/esm/BatchedTilesetReader.js.map +1 -1
  62. package/lib/esm/FrontendTiles.d.ts +32 -21
  63. package/lib/esm/FrontendTiles.d.ts.map +1 -1
  64. package/lib/esm/FrontendTiles.js +21 -14
  65. package/lib/esm/FrontendTiles.js.map +1 -1
  66. package/lib/esm/LoggerCategory.d.ts +2 -2
  67. package/lib/esm/LoggerCategory.js +6 -6
  68. package/lib/esm/LoggerCategory.js.map +1 -1
  69. package/lib/esm/frontend-tiles.d.ts +1 -1
  70. package/lib/esm/frontend-tiles.js +5 -5
  71. package/lib/esm/frontend-tiles.js.map +1 -1
  72. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  73. package/package.json +11 -11
  74. package/src/BatchedSpatialTileTreeRefs.ts +6 -4
  75. package/src/BatchedTile.ts +2 -1
  76. package/src/BatchedTileTreeReference.ts +36 -4
  77. package/src/FrontendTiles.ts +19 -0
  78. package/.rush/temp/package-deps_build_ci.json +0 -21
@@ -1,251 +1,252 @@
1
- "use strict";
2
- /*---------------------------------------------------------------------------------------------
3
- * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
- * See LICENSE.md in the project root for license terms and full copyright notice.
5
- *--------------------------------------------------------------------------------------------*/
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.BatchedTile = void 0;
8
- const core_bentley_1 = require("@itwin/core-bentley");
9
- const core_common_1 = require("@itwin/core-common");
10
- const core_frontend_1 = require("@itwin/core-frontend");
11
- const LoggerCategory_1 = require("./LoggerCategory");
12
- const BatchedTileContentReader_1 = require("./BatchedTileContentReader");
13
- let channel;
14
- /** @internal */
15
- class BatchedTile extends core_frontend_1.Tile {
16
- constructor(params, tree) {
17
- var _a;
18
- super(params, tree);
19
- if ((_a = params.childrenProps) === null || _a === void 0 ? void 0 : _a.length)
20
- this._childrenProps = params.childrenProps;
21
- if (!this.contentId) {
22
- this.setIsReady();
23
- // mark "undisplayable"
24
- this._maximumSize = 0;
25
- }
26
- }
27
- get batchedTree() {
28
- return this.tree;
29
- }
30
- get _batchedChildren() {
31
- return this.children;
32
- }
33
- computeLoadPriority(viewports, _users) {
34
- // Prioritize tiles closer to camera and center of attention (zoom point or screen center).
35
- return core_frontend_1.RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);
36
- }
37
- selectTiles(selected, args, numSkipped) {
38
- const vis = this.computeVisibility(args);
39
- if (core_frontend_1.TileVisibility.OutsideFrustum === vis)
40
- return core_frontend_1.SelectParent.No;
41
- if (core_frontend_1.TileVisibility.Visible === vis) {
42
- // This tile is of appropriate resolution to draw. If need loading or refinement, enqueue.
43
- if (!this.isReady)
44
- args.insertMissing(this);
45
- if (this.hasGraphics) {
46
- // It can be drawn - select it
47
- args.markReady(this);
48
- selected.push(this);
49
- }
50
- else if (!this.isReady) {
51
- // It can't be drawn. Try to draw children in its place; otherwise draw the parent.
52
- // Do not load/request the children for this purpose.
53
- const initialSize = selected.length;
54
- const kids = this._batchedChildren;
55
- if (undefined === kids)
56
- return core_frontend_1.SelectParent.Yes;
57
- // Find any descendant to draw, until we exceed max initial tiles to skip.
58
- // if (this.depth < this.iModelTree.maxInitialTilesToSkip) {
59
- // for (const kid of kids) {
60
- // if (SelectParent.Yes === kid.selectTiles(selected, args, numSkipped)) {
61
- // selected.length = initialSize;
62
- // return SelectParent.Yes;
63
- // }
64
- // return SelectParent.No;
65
- // }
66
- // }
67
- // If all visible direct children can be drawn, draw them.
68
- for (const kid of kids) {
69
- if (core_frontend_1.TileVisibility.OutsideFrustum !== kid.computeVisibility(args)) {
70
- if (!kid.hasGraphics) {
71
- selected.length = initialSize;
72
- return core_frontend_1.SelectParent.Yes;
73
- }
74
- else {
75
- selected.push(kid);
76
- }
77
- }
78
- }
79
- args.markUsed(this);
80
- }
81
- // We're drawing either this tile, or its direct children.
82
- return core_frontend_1.SelectParent.No;
83
- }
84
- // This tile is too coarse to draw. Try to draw something more appropriate.
85
- // If it is not ready to draw, we may want to skip loading in favor of loading its descendants.
86
- // If we previously loaded and later unloaded content for this tile to free memory, don't force it to reload its content - proceed to children.
87
- const maximumLevelsToSkip = core_frontend_1.IModelApp.tileAdmin.maximumLevelsToSkip;
88
- let canSkipThisTile = (this._hadGraphics && !this.hasGraphics) /* || this.depth < this.iModelTree.maxInitialTilesToSkip */;
89
- if (canSkipThisTile) {
90
- numSkipped = 1;
91
- }
92
- else {
93
- canSkipThisTile = this.isReady || this.isParentDisplayable /* || this.depth < this.iModelTree.maxInitialTilesToSkip */;
94
- if (canSkipThisTile && this.isDisplayable) { // skipping an undisplayable tile doesn't count toward the maximum
95
- // Some tiles do not sub-divide - they only facet the same geometry to a higher resolution. We can skip directly to the correct resolution.
96
- const isNotReady = !this.isReady && !this.hasGraphics /* && !this.hasSizeMultiplier */;
97
- if (isNotReady) {
98
- if (numSkipped >= maximumLevelsToSkip)
99
- canSkipThisTile = false;
100
- else
101
- numSkipped += 1;
102
- }
103
- }
104
- }
105
- const childrenLoadStatus = this.loadChildren(); // NB: asynchronous
106
- const children = canSkipThisTile ? this._batchedChildren : undefined;
107
- if (canSkipThisTile && core_frontend_1.TileTreeLoadStatus.Loading === childrenLoadStatus) {
108
- args.markChildrenLoading();
109
- args.markUsed(this);
110
- }
111
- if (undefined !== children) {
112
- // If we are the root tile and we are not displayable, then we want to draw *any* currently available children in our place, or else we would draw nothing.
113
- // Otherwise, if we want to draw children in our place, we should wait for *all* of them to load, or else we would show missing chunks where not-yet-loaded children belong.
114
- const isUndisplayableRootTile = this.isUndisplayableRootTile;
115
- args.markUsed(this);
116
- let drawChildren = true;
117
- const initialSize = selected.length;
118
- for (const child of children) {
119
- // NB: We must continue iterating children so that they can be requested if missing.
120
- if (core_frontend_1.SelectParent.Yes === child.selectTiles(selected, args, numSkipped)) {
121
- if (child.loadStatus === core_frontend_1.TileLoadStatus.NotFound) {
122
- // At least one child we want to draw failed to load. e.g., we reached max depth of map tile tree. Draw parent instead.
123
- drawChildren = canSkipThisTile = false;
124
- }
125
- else {
126
- // At least one child we want to draw is not yet loaded. Wait for it to load before drawing it and its siblings, unless we have nothing to draw in their place.
127
- drawChildren = isUndisplayableRootTile;
128
- }
129
- }
130
- }
131
- if (drawChildren)
132
- return core_frontend_1.SelectParent.No;
133
- // Some types of tiles (like maps) allow the ready children to be drawn on top of the parent while other children are not yet loaded.
134
- if (args.parentsAndChildrenExclusive)
135
- selected.length = initialSize;
136
- }
137
- if (this.isReady) {
138
- if (this.hasGraphics) {
139
- selected.push(this);
140
- if (!canSkipThisTile) {
141
- // This tile is too coarse, but we require loading it before we can start loading higher-res children.
142
- args.markReady(this);
143
- }
144
- }
145
- return core_frontend_1.SelectParent.No;
146
- }
147
- // This tile is not ready to be drawn. Request it *only* if we cannot skip it.
148
- if (!canSkipThisTile)
149
- args.insertMissing(this);
150
- return this.isParentDisplayable ? core_frontend_1.SelectParent.Yes : core_frontend_1.SelectParent.No;
151
- }
152
- _loadChildren(resolve, reject) {
153
- let children;
154
- if (this._childrenProps) {
155
- try {
156
- for (const childProps of this._childrenProps) {
157
- const params = this.batchedTree.reader.readTileParams(childProps, this);
158
- const child = new BatchedTile(params, this.batchedTree);
159
- children = children !== null && children !== void 0 ? children : [];
160
- children.push(child);
161
- }
162
- }
163
- catch (err) {
164
- core_bentley_1.Logger.logException(LoggerCategory_1.loggerCategory, err);
165
- children = undefined;
166
- if (err instanceof Error)
167
- reject(err);
168
- }
169
- }
170
- resolve(children);
171
- }
172
- get channel() {
173
- if (!channel) {
174
- channel = new core_frontend_1.TileRequestChannel("itwinjs-batched-models", 20);
175
- core_frontend_1.IModelApp.tileAdmin.channels.add(channel);
176
- }
177
- return channel;
178
- }
179
- async requestContent(_isCanceled) {
180
- const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);
181
- url.search = this.batchedTree.reader.baseUrl.search;
182
- const response = await fetch(url.toString());
183
- return response.arrayBuffer();
184
- }
185
- async readContent(data, system, shouldAbort) {
186
- (0, core_bentley_1.assert)(data instanceof Uint8Array);
187
- if (!(data instanceof Uint8Array))
188
- return {};
189
- let reader = core_frontend_1.ImdlReader.create({
190
- stream: core_bentley_1.ByteStream.fromUint8Array(data),
191
- iModel: this.tree.iModel,
192
- modelId: this.tree.modelId,
193
- is3d: true,
194
- system,
195
- isCanceled: shouldAbort,
196
- options: {
197
- tileId: this.contentId,
198
- },
199
- });
200
- if (!reader) {
201
- const gltfProps = core_frontend_1.GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);
202
- if (gltfProps) {
203
- reader = new BatchedTileContentReader_1.BatchedTileContentReader({
204
- props: gltfProps,
205
- iModel: this.tree.iModel,
206
- system,
207
- shouldAbort,
208
- vertexTableRequired: true,
209
- modelId: this.tree.modelId,
210
- isLeaf: this.isLeaf,
211
- range: this.range,
212
- });
213
- }
214
- }
215
- if (!reader)
216
- return {};
217
- return reader.read();
218
- }
219
- addRangeGraphic(builder, type) {
220
- if (core_frontend_1.TileBoundingBoxes.ChildVolumes !== type) {
221
- super.addRangeGraphic(builder, type);
222
- return;
223
- }
224
- builder.setSymbology(core_common_1.ColorDef.green, core_common_1.ColorDef.green, 2);
225
- builder.addRangeBox(this.range);
226
- this.loadChildren();
227
- const children = this.children;
228
- if (!children)
229
- return;
230
- builder.setSymbology(core_common_1.ColorDef.blue, core_common_1.ColorDef.blue.withTransparency(0xdf), 1);
231
- for (const child of children) {
232
- const range = child.range;
233
- builder.addRangeBox(range);
234
- builder.addRangeBox(range, true);
235
- }
236
- }
237
- prune(olderThan) {
238
- const children = this._batchedChildren;
239
- if (!children)
240
- return;
241
- if (this.usageMarker.isExpired(olderThan)) {
242
- this.disposeChildren();
243
- }
244
- else {
245
- for (const child of children)
246
- child.prune(olderThan);
247
- }
248
- }
249
- }
250
- exports.BatchedTile = BatchedTile;
1
+ "use strict";
2
+ /*---------------------------------------------------------------------------------------------
3
+ * Copyright (c) Bentley Systems, Incorporated. All rights reserved.
4
+ * See LICENSE.md in the project root for license terms and full copyright notice.
5
+ *--------------------------------------------------------------------------------------------*/
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.BatchedTile = void 0;
8
+ const core_bentley_1 = require("@itwin/core-bentley");
9
+ const core_common_1 = require("@itwin/core-common");
10
+ const core_frontend_1 = require("@itwin/core-frontend");
11
+ const LoggerCategory_1 = require("./LoggerCategory");
12
+ const BatchedTileContentReader_1 = require("./BatchedTileContentReader");
13
+ const FrontendTiles_1 = require("./FrontendTiles");
14
+ let channel;
15
+ /** @internal */
16
+ class BatchedTile extends core_frontend_1.Tile {
17
+ constructor(params, tree) {
18
+ var _a;
19
+ super(params, tree);
20
+ if ((_a = params.childrenProps) === null || _a === void 0 ? void 0 : _a.length)
21
+ this._childrenProps = params.childrenProps;
22
+ if (!this.contentId) {
23
+ this.setIsReady();
24
+ // mark "undisplayable"
25
+ this._maximumSize = 0;
26
+ }
27
+ }
28
+ get batchedTree() {
29
+ return this.tree;
30
+ }
31
+ get _batchedChildren() {
32
+ return this.children;
33
+ }
34
+ computeLoadPriority(viewports, _users) {
35
+ // Prioritize tiles closer to camera and center of attention (zoom point or screen center).
36
+ return core_frontend_1.RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);
37
+ }
38
+ selectTiles(selected, args, numSkipped) {
39
+ const vis = this.computeVisibility(args);
40
+ if (core_frontend_1.TileVisibility.OutsideFrustum === vis)
41
+ return core_frontend_1.SelectParent.No;
42
+ if (core_frontend_1.TileVisibility.Visible === vis) {
43
+ // This tile is of appropriate resolution to draw. If need loading or refinement, enqueue.
44
+ if (!this.isReady)
45
+ args.insertMissing(this);
46
+ if (this.hasGraphics) {
47
+ // It can be drawn - select it
48
+ args.markReady(this);
49
+ selected.push(this);
50
+ }
51
+ else if (!this.isReady) {
52
+ // It can't be drawn. Try to draw children in its place; otherwise draw the parent.
53
+ // Do not load/request the children for this purpose.
54
+ const initialSize = selected.length;
55
+ const kids = this._batchedChildren;
56
+ if (undefined === kids)
57
+ return core_frontend_1.SelectParent.Yes;
58
+ // Find any descendant to draw, until we exceed max initial tiles to skip.
59
+ // if (this.depth < this.iModelTree.maxInitialTilesToSkip) {
60
+ // for (const kid of kids) {
61
+ // if (SelectParent.Yes === kid.selectTiles(selected, args, numSkipped)) {
62
+ // selected.length = initialSize;
63
+ // return SelectParent.Yes;
64
+ // }
65
+ // return SelectParent.No;
66
+ // }
67
+ // }
68
+ // If all visible direct children can be drawn, draw them.
69
+ for (const kid of kids) {
70
+ if (core_frontend_1.TileVisibility.OutsideFrustum !== kid.computeVisibility(args)) {
71
+ if (!kid.hasGraphics) {
72
+ selected.length = initialSize;
73
+ return core_frontend_1.SelectParent.Yes;
74
+ }
75
+ else {
76
+ selected.push(kid);
77
+ }
78
+ }
79
+ }
80
+ args.markUsed(this);
81
+ }
82
+ // We're drawing either this tile, or its direct children.
83
+ return core_frontend_1.SelectParent.No;
84
+ }
85
+ // This tile is too coarse to draw. Try to draw something more appropriate.
86
+ // If it is not ready to draw, we may want to skip loading in favor of loading its descendants.
87
+ // If we previously loaded and later unloaded content for this tile to free memory, don't force it to reload its content - proceed to children.
88
+ const maximumLevelsToSkip = (0, FrontendTiles_1.getMaxLevelsToSkip)();
89
+ let canSkipThisTile = (this._hadGraphics && !this.hasGraphics) /* || this.depth < this.iModelTree.maxInitialTilesToSkip */;
90
+ if (canSkipThisTile) {
91
+ numSkipped = 1;
92
+ }
93
+ else {
94
+ canSkipThisTile = this.isReady || this.isParentDisplayable /* || this.depth < this.iModelTree.maxInitialTilesToSkip */;
95
+ if (canSkipThisTile && this.isDisplayable) { // skipping an undisplayable tile doesn't count toward the maximum
96
+ // Some tiles do not sub-divide - they only facet the same geometry to a higher resolution. We can skip directly to the correct resolution.
97
+ const isNotReady = !this.isReady && !this.hasGraphics /* && !this.hasSizeMultiplier */;
98
+ if (isNotReady) {
99
+ if (numSkipped >= maximumLevelsToSkip)
100
+ canSkipThisTile = false;
101
+ else
102
+ numSkipped += 1;
103
+ }
104
+ }
105
+ }
106
+ const childrenLoadStatus = this.loadChildren(); // NB: asynchronous
107
+ const children = canSkipThisTile ? this._batchedChildren : undefined;
108
+ if (canSkipThisTile && core_frontend_1.TileTreeLoadStatus.Loading === childrenLoadStatus) {
109
+ args.markChildrenLoading();
110
+ args.markUsed(this);
111
+ }
112
+ if (undefined !== children) {
113
+ // If we are the root tile and we are not displayable, then we want to draw *any* currently available children in our place, or else we would draw nothing.
114
+ // Otherwise, if we want to draw children in our place, we should wait for *all* of them to load, or else we would show missing chunks where not-yet-loaded children belong.
115
+ const isUndisplayableRootTile = this.isUndisplayableRootTile;
116
+ args.markUsed(this);
117
+ let drawChildren = true;
118
+ const initialSize = selected.length;
119
+ for (const child of children) {
120
+ // NB: We must continue iterating children so that they can be requested if missing.
121
+ if (core_frontend_1.SelectParent.Yes === child.selectTiles(selected, args, numSkipped)) {
122
+ if (child.loadStatus === core_frontend_1.TileLoadStatus.NotFound) {
123
+ // At least one child we want to draw failed to load. e.g., we reached max depth of map tile tree. Draw parent instead.
124
+ drawChildren = canSkipThisTile = false;
125
+ }
126
+ else {
127
+ // At least one child we want to draw is not yet loaded. Wait for it to load before drawing it and its siblings, unless we have nothing to draw in their place.
128
+ drawChildren = isUndisplayableRootTile;
129
+ }
130
+ }
131
+ }
132
+ if (drawChildren)
133
+ return core_frontend_1.SelectParent.No;
134
+ // Some types of tiles (like maps) allow the ready children to be drawn on top of the parent while other children are not yet loaded.
135
+ if (args.parentsAndChildrenExclusive)
136
+ selected.length = initialSize;
137
+ }
138
+ if (this.isReady) {
139
+ if (this.hasGraphics) {
140
+ selected.push(this);
141
+ if (!canSkipThisTile) {
142
+ // This tile is too coarse, but we require loading it before we can start loading higher-res children.
143
+ args.markReady(this);
144
+ }
145
+ }
146
+ return core_frontend_1.SelectParent.No;
147
+ }
148
+ // This tile is not ready to be drawn. Request it *only* if we cannot skip it.
149
+ if (!canSkipThisTile)
150
+ args.insertMissing(this);
151
+ return this.isParentDisplayable ? core_frontend_1.SelectParent.Yes : core_frontend_1.SelectParent.No;
152
+ }
153
+ _loadChildren(resolve, reject) {
154
+ let children;
155
+ if (this._childrenProps) {
156
+ try {
157
+ for (const childProps of this._childrenProps) {
158
+ const params = this.batchedTree.reader.readTileParams(childProps, this);
159
+ const child = new BatchedTile(params, this.batchedTree);
160
+ children = children !== null && children !== void 0 ? children : [];
161
+ children.push(child);
162
+ }
163
+ }
164
+ catch (err) {
165
+ core_bentley_1.Logger.logException(LoggerCategory_1.loggerCategory, err);
166
+ children = undefined;
167
+ if (err instanceof Error)
168
+ reject(err);
169
+ }
170
+ }
171
+ resolve(children);
172
+ }
173
+ get channel() {
174
+ if (!channel) {
175
+ channel = new core_frontend_1.TileRequestChannel("itwinjs-batched-models", 20);
176
+ core_frontend_1.IModelApp.tileAdmin.channels.add(channel);
177
+ }
178
+ return channel;
179
+ }
180
+ async requestContent(_isCanceled) {
181
+ const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);
182
+ url.search = this.batchedTree.reader.baseUrl.search;
183
+ const response = await fetch(url.toString());
184
+ return response.arrayBuffer();
185
+ }
186
+ async readContent(data, system, shouldAbort) {
187
+ (0, core_bentley_1.assert)(data instanceof Uint8Array);
188
+ if (!(data instanceof Uint8Array))
189
+ return {};
190
+ let reader = core_frontend_1.ImdlReader.create({
191
+ stream: core_bentley_1.ByteStream.fromUint8Array(data),
192
+ iModel: this.tree.iModel,
193
+ modelId: this.tree.modelId,
194
+ is3d: true,
195
+ system,
196
+ isCanceled: shouldAbort,
197
+ options: {
198
+ tileId: this.contentId,
199
+ },
200
+ });
201
+ if (!reader) {
202
+ const gltfProps = core_frontend_1.GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);
203
+ if (gltfProps) {
204
+ reader = new BatchedTileContentReader_1.BatchedTileContentReader({
205
+ props: gltfProps,
206
+ iModel: this.tree.iModel,
207
+ system,
208
+ shouldAbort,
209
+ vertexTableRequired: true,
210
+ modelId: this.tree.modelId,
211
+ isLeaf: this.isLeaf,
212
+ range: this.range,
213
+ });
214
+ }
215
+ }
216
+ if (!reader)
217
+ return {};
218
+ return reader.read();
219
+ }
220
+ addRangeGraphic(builder, type) {
221
+ if (core_frontend_1.TileBoundingBoxes.ChildVolumes !== type) {
222
+ super.addRangeGraphic(builder, type);
223
+ return;
224
+ }
225
+ builder.setSymbology(core_common_1.ColorDef.green, core_common_1.ColorDef.green, 2);
226
+ builder.addRangeBox(this.range);
227
+ this.loadChildren();
228
+ const children = this.children;
229
+ if (!children)
230
+ return;
231
+ builder.setSymbology(core_common_1.ColorDef.blue, core_common_1.ColorDef.blue.withTransparency(0xdf), 1);
232
+ for (const child of children) {
233
+ const range = child.range;
234
+ builder.addRangeBox(range);
235
+ builder.addRangeBox(range, true);
236
+ }
237
+ }
238
+ prune(olderThan) {
239
+ const children = this._batchedChildren;
240
+ if (!children)
241
+ return;
242
+ if (this.usageMarker.isExpired(olderThan)) {
243
+ this.disposeChildren();
244
+ }
245
+ else {
246
+ for (const child of children)
247
+ child.prune(olderThan);
248
+ }
249
+ }
250
+ }
251
+ exports.BatchedTile = BatchedTile;
251
252
  //# sourceMappingURL=BatchedTile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"BatchedTile.js","sourceRoot":"","sources":["../../src/BatchedTile.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA8E;AAC9E,oDAA+D;AAC/D,wDAG8B;AAC9B,qDAAkD;AAElD,yEAAsE;AAOtE,IAAI,OAAuC,CAAC;AAE5C,gBAAgB;AAChB,MAAa,WAAY,SAAQ,oBAAI;IAOnC,YAAmB,MAAyB,EAAE,IAAqB;;QACjE,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,MAAA,MAAM,CAAC,aAAa,0CAAE,MAAM;YAC9B,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC,aAAa,CAAC;QAE7C,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;YACnB,IAAI,CAAC,UAAU,EAAE,CAAC;YAClB,uBAAuB;YACvB,IAAI,CAAC,YAAY,GAAG,CAAC,CAAC;SACvB;IACH,CAAC;IAdD,IAAW,WAAW;QACpB,OAA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,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YACzC,IAAI,CAAC,eAAe,EAAE,CAAC;SACxB;aAAM;YACL,KAAK,MAAM,KAAK,IAAI,QAAQ;gBAC1B,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AA1QD,kCA0QC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n\r\nimport { assert, BeTimePoint, ByteStream, Logger } from \"@itwin/core-bentley\";\r\nimport { ColorDef, Tileset3dSchema } from \"@itwin/core-common\";\r\nimport {\r\n GltfReaderProps, GraphicBuilder, ImdlReader, IModelApp, RealityTileLoader, RenderSystem, SelectParent, Tile, TileBoundingBoxes, TileContent,\r\n TileDrawArgs, TileLoadStatus, TileParams, TileRequest, TileRequestChannel, TileTreeLoadStatus, TileUser, TileVisibility, Viewport,\r\n} from \"@itwin/core-frontend\";\r\nimport { loggerCategory } from \"./LoggerCategory\";\r\nimport { BatchedTileTree } from \"./BatchedTileTree\";\r\nimport { BatchedTileContentReader } from \"./BatchedTileContentReader\";\r\n\r\n/** @internal */\r\nexport interface BatchedTileParams extends TileParams {\r\n childrenProps: Tileset3dSchema.Tile[] | undefined;\r\n}\r\n\r\nlet channel: TileRequestChannel | undefined;\r\n\r\n/** @internal */\r\nexport class BatchedTile extends Tile {\r\n private readonly _childrenProps?: Tileset3dSchema.Tile[];\r\n\r\n public get batchedTree(): BatchedTileTree {\r\n return this.tree as BatchedTileTree;\r\n }\r\n\r\n public constructor(params: BatchedTileParams, tree: BatchedTileTree) {\r\n super(params, tree);\r\n if (params.childrenProps?.length)\r\n this._childrenProps = params.childrenProps;\r\n\r\n if (!this.contentId) {\r\n this.setIsReady();\r\n // mark \"undisplayable\"\r\n this._maximumSize = 0;\r\n }\r\n }\r\n\r\n private get _batchedChildren(): BatchedTile[] | undefined {\r\n return this.children as BatchedTile[] | undefined;\r\n }\r\n\r\n public override computeLoadPriority(viewports: Iterable<Viewport>, _users: Iterable<TileUser>): number {\r\n // Prioritize tiles closer to camera and center of attention (zoom point or screen center).\r\n return RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);\r\n }\r\n\r\n public selectTiles(selected: BatchedTile[], args: TileDrawArgs, numSkipped: number): SelectParent {\r\n const vis = this.computeVisibility(args);\r\n if (TileVisibility.OutsideFrustum === vis)\r\n return SelectParent.No;\r\n\r\n if (TileVisibility.Visible === vis) {\r\n // This tile is of appropriate resolution to draw. If need loading or refinement, enqueue.\r\n if (!this.isReady)\r\n args.insertMissing(this);\r\n\r\n if (this.hasGraphics) {\r\n // It can be drawn - select it\r\n args.markReady(this);\r\n selected.push(this);\r\n } else if (!this.isReady) {\r\n // It can't be drawn. Try to draw children in its place; otherwise draw the parent.\r\n // Do not load/request the children for this purpose.\r\n const initialSize = selected.length;\r\n const kids = this._batchedChildren;\r\n if (undefined === kids)\r\n return SelectParent.Yes;\r\n\r\n // Find any descendant to draw, until we exceed max initial tiles to skip.\r\n // if (this.depth < this.iModelTree.maxInitialTilesToSkip) {\r\n // for (const kid of kids) {\r\n // if (SelectParent.Yes === kid.selectTiles(selected, args, numSkipped)) {\r\n // selected.length = initialSize;\r\n // return SelectParent.Yes;\r\n // }\r\n\r\n // return SelectParent.No;\r\n // }\r\n // }\r\n\r\n // If all visible direct children can be drawn, draw them.\r\n for (const kid of kids) {\r\n if (TileVisibility.OutsideFrustum !== kid.computeVisibility(args)) {\r\n if (!kid.hasGraphics) {\r\n selected.length = initialSize;\r\n return SelectParent.Yes;\r\n } else {\r\n selected.push(kid);\r\n }\r\n }\r\n }\r\n\r\n args.markUsed(this);\r\n }\r\n\r\n // We're drawing either this tile, or its direct children.\r\n return SelectParent.No;\r\n }\r\n\r\n // This tile is too coarse to draw. Try to draw something more appropriate.\r\n // If it is not ready to draw, we may want to skip loading in favor of loading its descendants.\r\n // If we previously loaded and later unloaded content for this tile to free memory, don't force it to reload its content - proceed to children.\r\n const maximumLevelsToSkip = IModelApp.tileAdmin.maximumLevelsToSkip;\r\n let canSkipThisTile = (this._hadGraphics && !this.hasGraphics) /* || this.depth < this.iModelTree.maxInitialTilesToSkip */ ;\r\n if (canSkipThisTile) {\r\n numSkipped = 1;\r\n } else {\r\n canSkipThisTile = this.isReady || this.isParentDisplayable /* || this.depth < this.iModelTree.maxInitialTilesToSkip */ ;\r\n if (canSkipThisTile && this.isDisplayable) { // skipping an undisplayable tile doesn't count toward the maximum\r\n // Some tiles do not sub-divide - they only facet the same geometry to a higher resolution. We can skip directly to the correct resolution.\r\n const isNotReady = !this.isReady && !this.hasGraphics /* && !this.hasSizeMultiplier */ ;\r\n if (isNotReady) {\r\n if (numSkipped >= maximumLevelsToSkip)\r\n canSkipThisTile = false;\r\n else\r\n numSkipped += 1;\r\n }\r\n }\r\n }\r\n\r\n const childrenLoadStatus = this.loadChildren(); // NB: asynchronous\r\n const children = canSkipThisTile ? this._batchedChildren : undefined;\r\n if (canSkipThisTile && TileTreeLoadStatus.Loading === childrenLoadStatus) {\r\n args.markChildrenLoading();\r\n args.markUsed(this);\r\n }\r\n\r\n if (undefined !== children) {\r\n // If we are the root tile and we are not displayable, then we want to draw *any* currently available children in our place, or else we would draw nothing.\r\n // Otherwise, if we want to draw children in our place, we should wait for *all* of them to load, or else we would show missing chunks where not-yet-loaded children belong.\r\n const isUndisplayableRootTile = this.isUndisplayableRootTile;\r\n args.markUsed(this);\r\n let drawChildren = true;\r\n const initialSize = selected.length;\r\n for (const child of children) {\r\n // NB: We must continue iterating children so that they can be requested if missing.\r\n if (SelectParent.Yes === child.selectTiles(selected, args, numSkipped)) {\r\n if (child.loadStatus === TileLoadStatus.NotFound) {\r\n // At least one child we want to draw failed to load. e.g., we reached max depth of map tile tree. Draw parent instead.\r\n drawChildren = canSkipThisTile = false;\r\n } else {\r\n // At least one child we want to draw is not yet loaded. Wait for it to load before drawing it and its siblings, unless we have nothing to draw in their place.\r\n drawChildren = isUndisplayableRootTile;\r\n }\r\n }\r\n }\r\n\r\n if (drawChildren)\r\n return SelectParent.No;\r\n\r\n // Some types of tiles (like maps) allow the ready children to be drawn on top of the parent while other children are not yet loaded.\r\n if (args.parentsAndChildrenExclusive)\r\n selected.length = initialSize;\r\n }\r\n\r\n if (this.isReady) {\r\n if (this.hasGraphics) {\r\n selected.push(this);\r\n if (!canSkipThisTile) {\r\n // This tile is too coarse, but we require loading it before we can start loading higher-res children.\r\n args.markReady(this);\r\n }\r\n }\r\n\r\n return SelectParent.No;\r\n }\r\n\r\n // This tile is not ready to be drawn. Request it *only* if we cannot skip it.\r\n if (!canSkipThisTile)\r\n args.insertMissing(this);\r\n\r\n return this.isParentDisplayable ? SelectParent.Yes : SelectParent.No;\r\n }\r\n\r\n protected override _loadChildren(resolve: (children: Tile[] | undefined) => void, reject: (error: Error) => void): void {\r\n let children: BatchedTile[] | undefined;\r\n if (this._childrenProps) {\r\n try {\r\n for (const childProps of this._childrenProps) {\r\n const params = this.batchedTree.reader.readTileParams(childProps, this);\r\n const child = new BatchedTile(params, this.batchedTree);\r\n children = children ?? [];\r\n children.push(child);\r\n }\r\n } catch (err) {\r\n Logger.logException(loggerCategory, err);\r\n children = undefined;\r\n if (err instanceof Error)\r\n reject(err);\r\n }\r\n }\r\n\r\n resolve(children);\r\n }\r\n\r\n public override get channel(): TileRequestChannel {\r\n if (!channel) {\r\n channel = new TileRequestChannel(\"itwinjs-batched-models\", 20);\r\n IModelApp.tileAdmin.channels.add(channel);\r\n }\r\n\r\n return channel;\r\n }\r\n\r\n public override async requestContent(_isCanceled: () => boolean): Promise<TileRequest.Response> {\r\n const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);\r\n url.search = this.batchedTree.reader.baseUrl.search;\r\n const response = await fetch(url.toString());\r\n return response.arrayBuffer();\r\n }\r\n\r\n public override async readContent(data: TileRequest.ResponseData, system: RenderSystem, shouldAbort?: () => boolean): Promise<TileContent> {\r\n assert(data instanceof Uint8Array);\r\n if (!(data instanceof Uint8Array))\r\n return { };\r\n\r\n let reader: ImdlReader | BatchedTileContentReader | undefined = ImdlReader.create({\r\n stream: ByteStream.fromUint8Array(data),\r\n iModel: this.tree.iModel,\r\n modelId: this.tree.modelId,\r\n is3d: true,\r\n system,\r\n isCanceled: shouldAbort,\r\n options: {\r\n tileId: this.contentId,\r\n },\r\n });\r\n\r\n if (!reader) {\r\n const gltfProps = GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);\r\n if (gltfProps) {\r\n reader = new BatchedTileContentReader({\r\n props: gltfProps,\r\n iModel: this.tree.iModel,\r\n system,\r\n shouldAbort,\r\n vertexTableRequired: true,\r\n modelId: this.tree.modelId,\r\n isLeaf: this.isLeaf,\r\n range: this.range,\r\n });\r\n }\r\n }\r\n\r\n if (!reader)\r\n return { };\r\n\r\n return reader.read();\r\n }\r\n\r\n protected override addRangeGraphic(builder: GraphicBuilder, type: TileBoundingBoxes): void {\r\n if (TileBoundingBoxes.ChildVolumes !== type) {\r\n super.addRangeGraphic(builder, type);\r\n return;\r\n }\r\n\r\n builder.setSymbology(ColorDef.green, ColorDef.green, 2);\r\n builder.addRangeBox(this.range);\r\n\r\n this.loadChildren();\r\n const children = this.children;\r\n if (!children)\r\n return;\r\n\r\n builder.setSymbology(ColorDef.blue, ColorDef.blue.withTransparency(0xdf), 1);\r\n for (const child of children) {\r\n const range = child.range;\r\n builder.addRangeBox(range);\r\n builder.addRangeBox(range, true);\r\n }\r\n }\r\n\r\n public prune(olderThan: BeTimePoint): void {\r\n const children = this._batchedChildren;\r\n if (!children)\r\n return;\r\n\r\n if (this.usageMarker.isExpired(olderThan)) {\r\n this.disposeChildren();\r\n } else {\r\n for (const child of children)\r\n child.prune(olderThan);\r\n }\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"BatchedTile.js","sourceRoot":"","sources":["../../src/BatchedTile.ts"],"names":[],"mappings":";AAAA;;;+FAG+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B,IAAI,CAAC,QAAQ;YACX,OAAO;QAET,OAAO,CAAC,YAAY,CAAC,sBAAQ,CAAC,IAAI,EAAE,sBAAQ,CAAC,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC;QAC7E,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;YAC5B,MAAM,KAAK,GAAG,KAAK,CAAC,KAAK,CAAC;YAC1B,OAAO,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,CAAC,WAAW,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;SAClC;IACH,CAAC;IAEM,KAAK,CAAC,SAAsB;QACjC,MAAM,QAAQ,GAAG,IAAI,CAAC,gBAAgB,CAAC;QACvC,IAAI,CAAC,QAAQ;YACX,OAAO;QAET,IAAI,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,SAAS,CAAC,EAAE;YACzC,IAAI,CAAC,eAAe,EAAE,CAAC;SACxB;aAAM;YACL,KAAK,MAAM,KAAK,IAAI,QAAQ;gBAC1B,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SAC1B;IACH,CAAC;CACF;AA1QD,kCA0QC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { assert, BeTimePoint, ByteStream, Logger } from \"@itwin/core-bentley\";\nimport { ColorDef, Tileset3dSchema } from \"@itwin/core-common\";\nimport {\n GltfReaderProps, GraphicBuilder, ImdlReader, IModelApp, RealityTileLoader, RenderSystem, SelectParent, Tile, TileBoundingBoxes, TileContent,\n TileDrawArgs, TileLoadStatus, TileParams, TileRequest, TileRequestChannel, TileTreeLoadStatus, TileUser, TileVisibility, Viewport,\n} from \"@itwin/core-frontend\";\nimport { loggerCategory } from \"./LoggerCategory\";\nimport { BatchedTileTree } from \"./BatchedTileTree\";\nimport { BatchedTileContentReader } from \"./BatchedTileContentReader\";\nimport { getMaxLevelsToSkip } from \"./FrontendTiles\";\n\n/** @internal */\nexport interface BatchedTileParams extends TileParams {\n childrenProps: Tileset3dSchema.Tile[] | undefined;\n}\n\nlet channel: TileRequestChannel | undefined;\n\n/** @internal */\nexport class BatchedTile extends Tile {\n private readonly _childrenProps?: Tileset3dSchema.Tile[];\n\n public get batchedTree(): BatchedTileTree {\n return this.tree as BatchedTileTree;\n }\n\n public constructor(params: BatchedTileParams, tree: BatchedTileTree) {\n super(params, tree);\n if (params.childrenProps?.length)\n this._childrenProps = params.childrenProps;\n\n if (!this.contentId) {\n this.setIsReady();\n // mark \"undisplayable\"\n this._maximumSize = 0;\n }\n }\n\n private get _batchedChildren(): BatchedTile[] | undefined {\n return this.children as BatchedTile[] | undefined;\n }\n\n public override computeLoadPriority(viewports: Iterable<Viewport>, _users: Iterable<TileUser>): number {\n // Prioritize tiles closer to camera and center of attention (zoom point or screen center).\n return RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);\n }\n\n public selectTiles(selected: BatchedTile[], args: TileDrawArgs, numSkipped: number): SelectParent {\n const vis = this.computeVisibility(args);\n if (TileVisibility.OutsideFrustum === vis)\n return SelectParent.No;\n\n if (TileVisibility.Visible === vis) {\n // This tile is of appropriate resolution to draw. If need loading or refinement, enqueue.\n if (!this.isReady)\n args.insertMissing(this);\n\n if (this.hasGraphics) {\n // It can be drawn - select it\n args.markReady(this);\n selected.push(this);\n } else if (!this.isReady) {\n // It can't be drawn. Try to draw children in its place; otherwise draw the parent.\n // Do not load/request the children for this purpose.\n const initialSize = selected.length;\n const kids = this._batchedChildren;\n if (undefined === kids)\n return SelectParent.Yes;\n\n // Find any descendant to draw, until we exceed max initial tiles to skip.\n // if (this.depth < this.iModelTree.maxInitialTilesToSkip) {\n // for (const kid of kids) {\n // if (SelectParent.Yes === kid.selectTiles(selected, args, numSkipped)) {\n // selected.length = initialSize;\n // return SelectParent.Yes;\n // }\n\n // return SelectParent.No;\n // }\n // }\n\n // If all visible direct children can be drawn, draw them.\n for (const kid of kids) {\n if (TileVisibility.OutsideFrustum !== kid.computeVisibility(args)) {\n if (!kid.hasGraphics) {\n selected.length = initialSize;\n return SelectParent.Yes;\n } else {\n selected.push(kid);\n }\n }\n }\n\n args.markUsed(this);\n }\n\n // We're drawing either this tile, or its direct children.\n return SelectParent.No;\n }\n\n // This tile is too coarse to draw. Try to draw something more appropriate.\n // If it is not ready to draw, we may want to skip loading in favor of loading its descendants.\n // If we previously loaded and later unloaded content for this tile to free memory, don't force it to reload its content - proceed to children.\n const maximumLevelsToSkip = getMaxLevelsToSkip();\n let canSkipThisTile = (this._hadGraphics && !this.hasGraphics) /* || this.depth < this.iModelTree.maxInitialTilesToSkip */ ;\n if (canSkipThisTile) {\n numSkipped = 1;\n } else {\n canSkipThisTile = this.isReady || this.isParentDisplayable /* || this.depth < this.iModelTree.maxInitialTilesToSkip */ ;\n if (canSkipThisTile && this.isDisplayable) { // skipping an undisplayable tile doesn't count toward the maximum\n // Some tiles do not sub-divide - they only facet the same geometry to a higher resolution. We can skip directly to the correct resolution.\n const isNotReady = !this.isReady && !this.hasGraphics /* && !this.hasSizeMultiplier */ ;\n if (isNotReady) {\n if (numSkipped >= maximumLevelsToSkip)\n canSkipThisTile = false;\n else\n numSkipped += 1;\n }\n }\n }\n\n const childrenLoadStatus = this.loadChildren(); // NB: asynchronous\n const children = canSkipThisTile ? this._batchedChildren : undefined;\n if (canSkipThisTile && TileTreeLoadStatus.Loading === childrenLoadStatus) {\n args.markChildrenLoading();\n args.markUsed(this);\n }\n\n if (undefined !== children) {\n // If we are the root tile and we are not displayable, then we want to draw *any* currently available children in our place, or else we would draw nothing.\n // Otherwise, if we want to draw children in our place, we should wait for *all* of them to load, or else we would show missing chunks where not-yet-loaded children belong.\n const isUndisplayableRootTile = this.isUndisplayableRootTile;\n args.markUsed(this);\n let drawChildren = true;\n const initialSize = selected.length;\n for (const child of children) {\n // NB: We must continue iterating children so that they can be requested if missing.\n if (SelectParent.Yes === child.selectTiles(selected, args, numSkipped)) {\n if (child.loadStatus === TileLoadStatus.NotFound) {\n // At least one child we want to draw failed to load. e.g., we reached max depth of map tile tree. Draw parent instead.\n drawChildren = canSkipThisTile = false;\n } else {\n // At least one child we want to draw is not yet loaded. Wait for it to load before drawing it and its siblings, unless we have nothing to draw in their place.\n drawChildren = isUndisplayableRootTile;\n }\n }\n }\n\n if (drawChildren)\n return SelectParent.No;\n\n // Some types of tiles (like maps) allow the ready children to be drawn on top of the parent while other children are not yet loaded.\n if (args.parentsAndChildrenExclusive)\n selected.length = initialSize;\n }\n\n if (this.isReady) {\n if (this.hasGraphics) {\n selected.push(this);\n if (!canSkipThisTile) {\n // This tile is too coarse, but we require loading it before we can start loading higher-res children.\n args.markReady(this);\n }\n }\n\n return SelectParent.No;\n }\n\n // This tile is not ready to be drawn. Request it *only* if we cannot skip it.\n if (!canSkipThisTile)\n args.insertMissing(this);\n\n return this.isParentDisplayable ? SelectParent.Yes : SelectParent.No;\n }\n\n protected override _loadChildren(resolve: (children: Tile[] | undefined) => void, reject: (error: Error) => void): void {\n let children: BatchedTile[] | undefined;\n if (this._childrenProps) {\n try {\n for (const childProps of this._childrenProps) {\n const params = this.batchedTree.reader.readTileParams(childProps, this);\n const child = new BatchedTile(params, this.batchedTree);\n children = children ?? [];\n children.push(child);\n }\n } catch (err) {\n Logger.logException(loggerCategory, err);\n children = undefined;\n if (err instanceof Error)\n reject(err);\n }\n }\n\n resolve(children);\n }\n\n public override get channel(): TileRequestChannel {\n if (!channel) {\n channel = new TileRequestChannel(\"itwinjs-batched-models\", 20);\n IModelApp.tileAdmin.channels.add(channel);\n }\n\n return channel;\n }\n\n public override async requestContent(_isCanceled: () => boolean): Promise<TileRequest.Response> {\n const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);\n url.search = this.batchedTree.reader.baseUrl.search;\n const response = await fetch(url.toString());\n return response.arrayBuffer();\n }\n\n public override async readContent(data: TileRequest.ResponseData, system: RenderSystem, shouldAbort?: () => boolean): Promise<TileContent> {\n assert(data instanceof Uint8Array);\n if (!(data instanceof Uint8Array))\n return { };\n\n let reader: ImdlReader | BatchedTileContentReader | undefined = ImdlReader.create({\n stream: ByteStream.fromUint8Array(data),\n iModel: this.tree.iModel,\n modelId: this.tree.modelId,\n is3d: true,\n system,\n isCanceled: shouldAbort,\n options: {\n tileId: this.contentId,\n },\n });\n\n if (!reader) {\n const gltfProps = GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);\n if (gltfProps) {\n reader = new BatchedTileContentReader({\n props: gltfProps,\n iModel: this.tree.iModel,\n system,\n shouldAbort,\n vertexTableRequired: true,\n modelId: this.tree.modelId,\n isLeaf: this.isLeaf,\n range: this.range,\n });\n }\n }\n\n if (!reader)\n return { };\n\n return reader.read();\n }\n\n protected override addRangeGraphic(builder: GraphicBuilder, type: TileBoundingBoxes): void {\n if (TileBoundingBoxes.ChildVolumes !== type) {\n super.addRangeGraphic(builder, type);\n return;\n }\n\n builder.setSymbology(ColorDef.green, ColorDef.green, 2);\n builder.addRangeBox(this.range);\n\n this.loadChildren();\n const children = this.children;\n if (!children)\n return;\n\n builder.setSymbology(ColorDef.blue, ColorDef.blue.withTransparency(0xdf), 1);\n for (const child of children) {\n const range = child.range;\n builder.addRangeBox(range);\n builder.addRangeBox(range, true);\n }\n }\n\n public prune(olderThan: BeTimePoint): void {\n const children = this._batchedChildren;\n if (!children)\n return;\n\n if (this.usageMarker.isExpired(olderThan)) {\n this.disposeChildren();\n } else {\n for (const child of children)\n child.prune(olderThan);\n }\n }\n}\n"]}