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

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/frontend-tiles",
3
- "version": "3.7.0-dev.6",
3
+ "version": "3.7.0-dev.7",
4
4
  "description": "Experimental alternative technique for visualizing the contents of iModels",
5
5
  "main": "lib/cjs/frontend-tiles.js",
6
6
  "module": "lib/esm/frontend-tiles.js",
@@ -22,18 +22,18 @@
22
22
  "url": "http://www.bentley.com"
23
23
  },
24
24
  "peerDependencies": {
25
- "@itwin/core-bentley": "3.7.0-dev.6",
26
- "@itwin/core-common": "3.7.0-dev.6",
27
- "@itwin/core-frontend": "3.7.0-dev.6",
28
- "@itwin/core-geometry": "3.7.0-dev.6"
25
+ "@itwin/core-bentley": "3.7.0-dev.7",
26
+ "@itwin/core-common": "3.7.0-dev.7",
27
+ "@itwin/core-frontend": "3.7.0-dev.7",
28
+ "@itwin/core-geometry": "3.7.0-dev.7"
29
29
  },
30
30
  "devDependencies": {
31
- "@itwin/build-tools": "3.7.0-dev.6",
32
- "@itwin/core-bentley": "3.7.0-dev.6",
33
- "@itwin/core-common": "3.7.0-dev.6",
34
- "@itwin/core-frontend": "3.7.0-dev.6",
35
- "@itwin/core-geometry": "3.7.0-dev.6",
36
- "@itwin/eslint-plugin": "3.7.0-dev.6",
31
+ "@itwin/build-tools": "3.7.0-dev.7",
32
+ "@itwin/core-bentley": "3.7.0-dev.7",
33
+ "@itwin/core-common": "3.7.0-dev.7",
34
+ "@itwin/core-frontend": "3.7.0-dev.7",
35
+ "@itwin/core-geometry": "3.7.0-dev.7",
36
+ "@itwin/eslint-plugin": "3.7.0-dev.7",
37
37
  "@types/node": "18.11.5",
38
38
  "eslint": "^7.11.0",
39
39
  "rimraf": "^3.0.2",
@@ -4,11 +4,13 @@
4
4
  *--------------------------------------------------------------------------------------------*/
5
5
 
6
6
  import {
7
- AttachToViewportArgs, IModelConnection, SpatialTileTreeReferences, SpatialViewState, TileTreeReference,
7
+ AttachToViewportArgs, IModelConnection, SpatialTileTreeReferences, SpatialViewState, TileTreeLoadStatus, TileTreeOwner, TileTreeReference,
8
8
  } from "@itwin/core-frontend";
9
9
  import { BatchedTileTreeReference } from "./BatchedTileTreeReference";
10
+ import { ComputeSpatialTilesetBaseUrl, createFallbackSpatialTileTreeReferences } from "./FrontendTiles";
10
11
 
11
- class TreeRefs implements SpatialTileTreeReferences {
12
+ // Obtains tiles pre-published by mesh export service.
13
+ class BatchedSpatialTileTreeReferences implements SpatialTileTreeReferences {
12
14
  private readonly _treeRef: BatchedTileTreeReference;
13
15
 
14
16
  public constructor(treeRef: BatchedTileTreeReference) {
@@ -36,8 +38,121 @@ class TreeRefs implements SpatialTileTreeReferences {
36
38
  }
37
39
  }
38
40
 
41
+ // A placeholder used by [[ProxySpatialTileTreeReferences]] until asynchronous loading completes.
42
+ // It provides a TileTreeOwner that never loads a tile tree.
43
+ // This ensures that [ViewState.areAllTileTreesLoaded]($frontend) will not return `true` while we are loading.
44
+ class ProxyTileTreeReference extends TileTreeReference {
45
+ private readonly _treeOwner: TileTreeOwner;
46
+
47
+ public constructor(iModel: IModelConnection) {
48
+ super();
49
+ this._treeOwner = {
50
+ iModel,
51
+ tileTree: undefined,
52
+ loadStatus: TileTreeLoadStatus.NotLoaded,
53
+ load: () => undefined,
54
+ dispose: () => { },
55
+ loadTree: async () => Promise.resolve(undefined),
56
+ };
57
+ }
58
+
59
+ public override get treeOwner() {
60
+ return this._treeOwner;
61
+ }
62
+
63
+ // eslint-disable-next-line @typescript-eslint/naming-convention
64
+ public override get _isLoadingComplete() {
65
+ return false;
66
+ }
67
+ }
68
+
69
+ // Serves as a placeholder while we asynchronously obtain the base URL for a pre-published tileset (or asynchronously determine
70
+ // that no such tileset exists).
71
+ class ProxySpatialTileTreeReferences implements SpatialTileTreeReferences {
72
+ // Once async loading completes, all methods will be forwarded to this implementation.
73
+ private _impl?: SpatialTileTreeReferences;
74
+ private readonly _proxyRef: ProxyTileTreeReference;
75
+ // Retained if attachToViewport is called while we are still loading; and reset if detachFromViewport is called while loading.
76
+ private _attachArgs?: AttachToViewportArgs;
77
+
78
+ public constructor(view: SpatialViewState, getBaseUrl: Promise<URL | undefined>) {
79
+ this._proxyRef = new ProxyTileTreeReference(view.iModel);
80
+ getBaseUrl.then((url: URL | undefined) => {
81
+ if (url) {
82
+ const ref = BatchedTileTreeReference.create(view, url);
83
+ this.setTreeRefs(new BatchedSpatialTileTreeReferences(ref));
84
+ } else {
85
+ this.setTreeRefs(createFallbackSpatialTileTreeReferences(view));
86
+ }
87
+ }).catch(() => {
88
+ this.setTreeRefs(createFallbackSpatialTileTreeReferences(view));
89
+ });
90
+ }
91
+
92
+ private setTreeRefs(refs: SpatialTileTreeReferences): void {
93
+ this._impl = refs;
94
+ if (this._attachArgs) {
95
+ this._impl.attachToViewport(this._attachArgs);
96
+ this._attachArgs.invalidateSymbologyOverrides();
97
+ this._attachArgs = undefined;
98
+ }
99
+ }
100
+
101
+ public update(): void {
102
+ this._impl?.update();
103
+ }
104
+
105
+ public attachToViewport(args: AttachToViewportArgs): void {
106
+ if (this._impl)
107
+ this._impl.attachToViewport(args);
108
+ else
109
+ this._attachArgs = args;
110
+ }
111
+
112
+ public detachFromViewport(): void {
113
+ if (this._impl)
114
+ this._impl.detachFromViewport();
115
+ else
116
+ this._attachArgs = undefined;
117
+ }
118
+
119
+ public setDeactivated(): void { }
120
+
121
+ public *[Symbol.iterator](): Iterator<TileTreeReference> {
122
+ if (this._impl)
123
+ return this._impl[Symbol.iterator]();
124
+
125
+ yield this._proxyRef;
126
+ }
127
+ }
128
+
129
+ const iModelToBaseUrl = new Map<IModelConnection, URL | null | Promise<URL | undefined>>();
130
+
39
131
  /** @internal */
40
- export function createBatchedSpatialTileTreeReferences(view: SpatialViewState, computeBaseUrl: (iModel: IModelConnection) => URL): SpatialTileTreeReferences {
41
- const treeRef = BatchedTileTreeReference.create(view, computeBaseUrl(view.iModel));
42
- return new TreeRefs(treeRef);
132
+ export function createBatchedSpatialTileTreeReferences(view: SpatialViewState, computeBaseUrl: ComputeSpatialTilesetBaseUrl): SpatialTileTreeReferences {
133
+ const iModel = view.iModel;
134
+ let entry = iModelToBaseUrl.get(iModel);
135
+ if (undefined === entry) {
136
+ const promise = computeBaseUrl(iModel);
137
+ iModelToBaseUrl.set(iModel, entry = promise);
138
+ iModel.onClose.addOnce(() => iModelToBaseUrl.delete(iModel));
139
+ promise.then((url: URL | undefined) => {
140
+ if (iModelToBaseUrl.has(iModel))
141
+ iModelToBaseUrl.set(iModel, url ?? null);
142
+ }).catch(() => {
143
+ if (iModelToBaseUrl.has(iModel))
144
+ iModelToBaseUrl.set(iModel, null);
145
+ });
146
+ }
147
+
148
+ if (null === entry) {
149
+ // No tileset exists for this iModel - use default tile generation instead.
150
+ return createFallbackSpatialTileTreeReferences(view);
151
+ }
152
+
153
+ if (entry instanceof Promise)
154
+ return new ProxySpatialTileTreeReferences(view, entry);
155
+
156
+ const ref = BatchedTileTreeReference.create(view, entry);
157
+ return new BatchedSpatialTileTreeReferences(ref);
43
158
  }
@@ -6,16 +6,25 @@
6
6
  import { IModelConnection, SpatialTileTreeReferences, SpatialViewState } from "@itwin/core-frontend";
7
7
  import { createBatchedSpatialTileTreeReferences } from "./BatchedSpatialTileTreeRefs";
8
8
 
9
+ /** A function that can provide the base URL where a tileset representing all of the spatial models in a given iModel are stored.
10
+ * The tileset is expected to reside at "baseUrl/tileset.json" and to have been produced by the [mesh export service](https://developer.bentley.com/apis/mesh-export/).
11
+ * If no such tileset exists for the given iModel, return `undefined`.
12
+ * @see [[FrontendTilesOptions.computeSpatialTilesetBaseUrl]].
13
+ * @alpha
14
+ */
15
+ export type ComputeSpatialTilesetBaseUrl = (iModel: IModelConnection) => Promise<URL | undefined>;
16
+
9
17
  /** Options supplied to [[initializeFrontendTiles]].
10
18
  * @alpha
11
19
  */
12
20
  export interface FrontendTilesOptions {
13
- /** Given an iModel, provide the base URL where the tiles are stored representing all of the spatial models in the iModel.
14
- * It is expected that baseUrl/tileset.json exists and contains a 3d tileset in which all relative URLs are relative to baseUrl.
15
- */
16
- computeSpatialTilesetBaseUrl: (iModel: IModelConnection) => URL;
21
+ /** Provide the base URL for the pre-published tileset for a given iModel. */
22
+ computeSpatialTilesetBaseUrl: ComputeSpatialTilesetBaseUrl;
17
23
  }
18
24
 
25
+ /** @internal */
26
+ export const createFallbackSpatialTileTreeReferences = SpatialTileTreeReferences.create;
27
+
19
28
  /** Initialize the frontend-tiles package to obtain tiles for spatial views.
20
29
  * @alpha
21
30
  */