@itwin/frontend-tiles 4.0.0-dev.46
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/.rush/temp/operation/build_ci/state.json +3 -0
- package/.rush/temp/package-deps_build_ci.json +21 -0
- package/.rush/temp/shrinkwrap-deps.json +287 -0
- package/LICENSE.md +9 -0
- package/README.md +12 -0
- package/config/rush-project.json +7 -0
- package/frontend-tiles.build.error.log +1 -0
- package/frontend-tiles.build.log +2 -0
- package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts +4 -0
- package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts.map +1 -0
- package/lib/cjs/BatchedSpatialTileTreeRefs.js +28 -0
- package/lib/cjs/BatchedSpatialTileTreeRefs.js.map +1 -0
- package/lib/cjs/BatchedTile.d.ts +24 -0
- package/lib/cjs/BatchedTile.d.ts.map +1 -0
- package/lib/cjs/BatchedTile.js +156 -0
- package/lib/cjs/BatchedTile.js.map +1 -0
- package/lib/cjs/BatchedTileContentReader.d.ts +23 -0
- package/lib/cjs/BatchedTileContentReader.d.ts.map +1 -0
- package/lib/cjs/BatchedTileContentReader.js +75 -0
- package/lib/cjs/BatchedTileContentReader.js.map +1 -0
- package/lib/cjs/BatchedTileTree.d.ts +23 -0
- package/lib/cjs/BatchedTileTree.d.ts.map +1 -0
- package/lib/cjs/BatchedTileTree.js +53 -0
- package/lib/cjs/BatchedTileTree.js.map +1 -0
- package/lib/cjs/BatchedTileTreeReference.d.ts +4 -0
- package/lib/cjs/BatchedTileTreeReference.d.ts.map +1 -0
- package/lib/cjs/BatchedTileTreeReference.js +25 -0
- package/lib/cjs/BatchedTileTreeReference.js.map +1 -0
- package/lib/cjs/BatchedTileTreeSupplier.d.ts +6 -0
- package/lib/cjs/BatchedTileTreeSupplier.d.ts.map +1 -0
- package/lib/cjs/BatchedTileTreeSupplier.js +39 -0
- package/lib/cjs/BatchedTileTreeSupplier.js.map +1 -0
- package/lib/cjs/BatchedTilesetReader.d.ts +14 -0
- package/lib/cjs/BatchedTilesetReader.d.ts.map +1 -0
- package/lib/cjs/BatchedTilesetReader.js +90 -0
- package/lib/cjs/BatchedTilesetReader.js.map +1 -0
- package/lib/cjs/FrontendTiles.d.ts +15 -0
- package/lib/cjs/FrontendTiles.d.ts.map +1 -0
- package/lib/cjs/FrontendTiles.js +17 -0
- package/lib/cjs/FrontendTiles.js.map +1 -0
- package/lib/cjs/LoggerCategory.d.ts +3 -0
- package/lib/cjs/LoggerCategory.d.ts.map +1 -0
- package/lib/cjs/LoggerCategory.js +10 -0
- package/lib/cjs/LoggerCategory.js.map +1 -0
- package/lib/cjs/frontend-tiles.d.ts +2 -0
- package/lib/cjs/frontend-tiles.d.ts.map +1 -0
- package/lib/cjs/frontend-tiles.js +18 -0
- package/lib/cjs/frontend-tiles.js.map +1 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/BatchedSpatialTileTreeRefs.d.ts +4 -0
- package/lib/esm/BatchedSpatialTileTreeRefs.d.ts.map +1 -0
- package/lib/esm/BatchedSpatialTileTreeRefs.js +24 -0
- package/lib/esm/BatchedSpatialTileTreeRefs.js.map +1 -0
- package/lib/esm/BatchedTile.d.ts +24 -0
- package/lib/esm/BatchedTile.d.ts.map +1 -0
- package/lib/esm/BatchedTile.js +152 -0
- package/lib/esm/BatchedTile.js.map +1 -0
- package/lib/esm/BatchedTileContentReader.d.ts +23 -0
- package/lib/esm/BatchedTileContentReader.d.ts.map +1 -0
- package/lib/esm/BatchedTileContentReader.js +71 -0
- package/lib/esm/BatchedTileContentReader.js.map +1 -0
- package/lib/esm/BatchedTileTree.d.ts +23 -0
- package/lib/esm/BatchedTileTree.d.ts.map +1 -0
- package/lib/esm/BatchedTileTree.js +49 -0
- package/lib/esm/BatchedTileTree.js.map +1 -0
- package/lib/esm/BatchedTileTreeReference.d.ts +4 -0
- package/lib/esm/BatchedTileTreeReference.d.ts.map +1 -0
- package/lib/esm/BatchedTileTreeReference.js +21 -0
- package/lib/esm/BatchedTileTreeReference.js.map +1 -0
- package/lib/esm/BatchedTileTreeSupplier.d.ts +6 -0
- package/lib/esm/BatchedTileTreeSupplier.d.ts.map +1 -0
- package/lib/esm/BatchedTileTreeSupplier.js +35 -0
- package/lib/esm/BatchedTileTreeSupplier.js.map +1 -0
- package/lib/esm/BatchedTilesetReader.d.ts +14 -0
- package/lib/esm/BatchedTilesetReader.d.ts.map +1 -0
- package/lib/esm/BatchedTilesetReader.js +86 -0
- package/lib/esm/BatchedTilesetReader.js.map +1 -0
- package/lib/esm/FrontendTiles.d.ts +15 -0
- package/lib/esm/FrontendTiles.d.ts.map +1 -0
- package/lib/esm/FrontendTiles.js +13 -0
- package/lib/esm/FrontendTiles.js.map +1 -0
- package/lib/esm/LoggerCategory.d.ts +3 -0
- package/lib/esm/LoggerCategory.d.ts.map +1 -0
- package/lib/esm/LoggerCategory.js +7 -0
- package/lib/esm/LoggerCategory.js.map +1 -0
- package/lib/esm/frontend-tiles.d.ts +2 -0
- package/lib/esm/frontend-tiles.d.ts.map +1 -0
- package/lib/esm/frontend-tiles.js +6 -0
- package/lib/esm/frontend-tiles.js.map +1 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/package.json +61 -0
- package/src/BatchedSpatialTileTreeRefs.ts +34 -0
- package/src/BatchedTile.ts +186 -0
- package/src/BatchedTileContentReader.ts +96 -0
- package/src/BatchedTileTree.ts +71 -0
- package/src/BatchedTileTreeReference.ts +28 -0
- package/src/BatchedTileTreeSupplier.ts +45 -0
- package/src/BatchedTilesetReader.ts +115 -0
- package/src/FrontendTiles.ts +24 -0
- package/src/LoggerCategory.ts +8 -0
- package/src/frontend-tiles.ts +6 -0
- package/tsconfig.json +6 -0
package/package.json
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@itwin/frontend-tiles",
|
|
3
|
+
"version": "4.0.0-dev.46",
|
|
4
|
+
"description": "Experimental alternative technique for visualizing the contents of iModels",
|
|
5
|
+
"main": "lib/cjs/frontend-tiles.js",
|
|
6
|
+
"module": "lib/esm/frontend-tiles.js",
|
|
7
|
+
"typings": "lib/cjs/frontend-tiles",
|
|
8
|
+
"license": "MIT",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/iTwin/itwinjs-core/tree/master/extensions/frontend-tiles"
|
|
12
|
+
},
|
|
13
|
+
"keywords": [
|
|
14
|
+
"Bentley",
|
|
15
|
+
"BIM",
|
|
16
|
+
"iModel",
|
|
17
|
+
"UI",
|
|
18
|
+
"Widget"
|
|
19
|
+
],
|
|
20
|
+
"author": {
|
|
21
|
+
"name": "Bentley Systems, Inc.",
|
|
22
|
+
"url": "http://www.bentley.com"
|
|
23
|
+
},
|
|
24
|
+
"peerDependencies": {
|
|
25
|
+
"@itwin/core-bentley": "4.0.0-dev.46",
|
|
26
|
+
"@itwin/core-common": "4.0.0-dev.46",
|
|
27
|
+
"@itwin/core-frontend": "4.0.0-dev.46",
|
|
28
|
+
"@itwin/core-geometry": "4.0.0-dev.46"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"@itwin/build-tools": "4.0.0-dev.46",
|
|
32
|
+
"@itwin/core-bentley": "4.0.0-dev.46",
|
|
33
|
+
"@itwin/core-common": "4.0.0-dev.46",
|
|
34
|
+
"@itwin/core-frontend": "4.0.0-dev.46",
|
|
35
|
+
"@itwin/core-geometry": "4.0.0-dev.46",
|
|
36
|
+
"@itwin/eslint-plugin": "nightly",
|
|
37
|
+
"@types/node": "^18.11.5",
|
|
38
|
+
"eslint": "^7.11.0",
|
|
39
|
+
"rimraf": "^3.0.2",
|
|
40
|
+
"typescript": "~4.4.0"
|
|
41
|
+
},
|
|
42
|
+
"eslintConfig": {
|
|
43
|
+
"plugins": [
|
|
44
|
+
"@itwin"
|
|
45
|
+
],
|
|
46
|
+
"extends": "plugin:@itwin/itwinjs-recommended"
|
|
47
|
+
},
|
|
48
|
+
"scripts": {
|
|
49
|
+
"build": "npm run -s build:cjs",
|
|
50
|
+
"build:ci": "npm run -s build && npm run -s build:esm",
|
|
51
|
+
"build:cjs": "tsc 1>&2 --outDir lib/cjs",
|
|
52
|
+
"build:esm": "tsc 1>&2 --module ES2020 --outDir lib/esm",
|
|
53
|
+
"clean": "rimraf lib .rush/temp/package-deps*.json",
|
|
54
|
+
"docs": "",
|
|
55
|
+
"extract-api": "betools extract-api --entry=frontend-tiles",
|
|
56
|
+
"lint": "eslint -f visualstudio \"./src/**/*.ts\" 1>&2",
|
|
57
|
+
"test": "",
|
|
58
|
+
"cover": ""
|
|
59
|
+
},
|
|
60
|
+
"readme": "# @itwin/core-frontend\r\n\r\nCopyright © Bentley Systems, Incorporated. All rights reserved. See LICENSE.md for license terms and full copyright notice.\r\n\r\n## Description\r\n\r\nThe __@itwin/frontend-tiles__ package provides an experimental alternative technique for visualizing the contents of an iModel. Use `initializeFrontendTiles` to activate it.\r\n\r\n## Documentation\r\n\r\nSee the [iTwin.js](https://www.itwinjs.org) documentation for more information.\r\n\r\n"
|
|
61
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
IModelConnection, SpatialTileTreeReferences, TileTreeReference,
|
|
8
|
+
} from "@itwin/core-frontend";
|
|
9
|
+
import { createBatchedTileTreeReference } from "./BatchedTileTreeReference";
|
|
10
|
+
|
|
11
|
+
class TreeRefs implements SpatialTileTreeReferences {
|
|
12
|
+
private readonly _treeRef: TileTreeReference;
|
|
13
|
+
|
|
14
|
+
public constructor(treeRef: TileTreeReference) {
|
|
15
|
+
this._treeRef = treeRef;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
public *[Symbol.iterator](): Iterator<TileTreeReference> {
|
|
19
|
+
yield this._treeRef;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public update(): void {
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public setDeactivated(): void {
|
|
26
|
+
// This exists chiefly for debugging. Unimplemented here.
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/** @internal */
|
|
31
|
+
export function createBatchedSpatialTileTreeReferences(iModel: IModelConnection, computeBaseUrl: (iModel: IModelConnection) => URL): SpatialTileTreeReferences {
|
|
32
|
+
const treeRef = createBatchedTileTreeReference(iModel, computeBaseUrl(iModel));
|
|
33
|
+
return new TreeRefs(treeRef);
|
|
34
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { assert, BeTimePoint, ByteStream, Logger } from "@itwin/core-bentley";
|
|
7
|
+
import { ColorDef, Tileset3dSchema } from "@itwin/core-common";
|
|
8
|
+
import {
|
|
9
|
+
GltfReaderProps, GraphicBuilder, ImdlReader, IModelApp, RealityTileLoader, RenderSystem, Tile, TileBoundingBoxes, TileContent, TileDrawArgs, TileParams, TileRequest,
|
|
10
|
+
TileRequestChannel, TileTreeLoadStatus, TileUser, TileVisibility, Viewport,
|
|
11
|
+
} from "@itwin/core-frontend";
|
|
12
|
+
import { loggerCategory } from "./LoggerCategory";
|
|
13
|
+
import { BatchedTileTree } from "./BatchedTileTree";
|
|
14
|
+
import { BatchedTileContentReader } from "./BatchedTileContentReader";
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export interface BatchedTileParams extends TileParams {
|
|
18
|
+
childrenProps: Tileset3dSchema.Tile[] | undefined;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** @internal */
|
|
22
|
+
export class BatchedTile extends Tile {
|
|
23
|
+
private readonly _childrenProps?: Tileset3dSchema.Tile[];
|
|
24
|
+
|
|
25
|
+
public get batchedTree(): BatchedTileTree {
|
|
26
|
+
return this.tree as BatchedTileTree;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
public constructor(params: BatchedTileParams, tree: BatchedTileTree) {
|
|
30
|
+
super(params, tree);
|
|
31
|
+
if (params.childrenProps?.length)
|
|
32
|
+
this._childrenProps = params.childrenProps;
|
|
33
|
+
|
|
34
|
+
if (!this.contentId)
|
|
35
|
+
this.setIsReady();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private get _batchedChildren(): BatchedTile[] | undefined {
|
|
39
|
+
return this.children as BatchedTile[] | undefined;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public override computeLoadPriority(viewports: Iterable<Viewport>, _users: Iterable<TileUser>): number {
|
|
43
|
+
// Prioritize tiles closer to camera and center of attention (zoom point or screen center).
|
|
44
|
+
return RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public selectTiles(selected: BatchedTile[], args: TileDrawArgs): void {
|
|
48
|
+
const vis = this.computeVisibility(args);
|
|
49
|
+
if (TileVisibility.OutsideFrustum === vis)
|
|
50
|
+
return;
|
|
51
|
+
|
|
52
|
+
// ###TODO proper tile refinement. Currently we simply load each level of the tree in succession until we find a tile that
|
|
53
|
+
// meets screen space error. Moreover, while we wait for children to load we stop displaying the parent.
|
|
54
|
+
// Prefer to skip some levels where appropriate.
|
|
55
|
+
// More importantly, fix tile tree structure so that children can be substituted for (portions of) parents more quickly, especially near the camera
|
|
56
|
+
// (need non-overlapping child volumes).
|
|
57
|
+
if (!this.isReady) {
|
|
58
|
+
args.insertMissing(this);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (TileVisibility.Visible === vis && this.hasGraphics) {
|
|
63
|
+
args.markReady(this);
|
|
64
|
+
selected.push(this);
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
args.markUsed(this);
|
|
69
|
+
if (this.isReady) {
|
|
70
|
+
const childrenStatus = this.loadChildren();
|
|
71
|
+
if (TileTreeLoadStatus.Loading === childrenStatus)
|
|
72
|
+
args.markChildrenLoading();
|
|
73
|
+
|
|
74
|
+
const children = this._batchedChildren;
|
|
75
|
+
if (children)
|
|
76
|
+
for (const child of children)
|
|
77
|
+
child.selectTiles(selected, args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
protected override _loadChildren(resolve: (children: Tile[] | undefined) => void, reject: (error: Error) => void): void {
|
|
82
|
+
let children: BatchedTile[] | undefined;
|
|
83
|
+
if (this._childrenProps) {
|
|
84
|
+
try {
|
|
85
|
+
for (const childProps of this._childrenProps) {
|
|
86
|
+
const params = this.batchedTree.reader.readTileParams(childProps, this);
|
|
87
|
+
const child = new BatchedTile(params, this.batchedTree);
|
|
88
|
+
children = children ?? [];
|
|
89
|
+
children.push(child);
|
|
90
|
+
}
|
|
91
|
+
} catch (err) {
|
|
92
|
+
Logger.logException(loggerCategory, err);
|
|
93
|
+
children = undefined;
|
|
94
|
+
if (err instanceof Error)
|
|
95
|
+
reject(err);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
resolve(children);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public override get channel(): TileRequestChannel {
|
|
103
|
+
return IModelApp.tileAdmin.channels.getForHttp("itwinjs-batched-models");
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
public override async requestContent(_isCanceled: () => boolean): Promise<TileRequest.Response> {
|
|
107
|
+
const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);
|
|
108
|
+
url.search = this.batchedTree.reader.baseUrl.search;
|
|
109
|
+
const response = await fetch(url.toString());
|
|
110
|
+
return response.arrayBuffer();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
public override async readContent(data: TileRequest.ResponseData, system: RenderSystem, shouldAbort?: () => boolean): Promise<TileContent> {
|
|
114
|
+
assert(data instanceof Uint8Array);
|
|
115
|
+
if (!(data instanceof Uint8Array))
|
|
116
|
+
return { };
|
|
117
|
+
|
|
118
|
+
let reader: ImdlReader | BatchedTileContentReader | undefined = ImdlReader.create({
|
|
119
|
+
stream: ByteStream.fromUint8Array(data),
|
|
120
|
+
iModel: this.tree.iModel,
|
|
121
|
+
modelId: this.tree.modelId,
|
|
122
|
+
is3d: true,
|
|
123
|
+
system,
|
|
124
|
+
isCanceled: shouldAbort,
|
|
125
|
+
options: {
|
|
126
|
+
tileId: this.contentId,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
if (!reader) {
|
|
131
|
+
const gltfProps = GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);
|
|
132
|
+
if (gltfProps) {
|
|
133
|
+
reader = new BatchedTileContentReader({
|
|
134
|
+
props: gltfProps,
|
|
135
|
+
iModel: this.tree.iModel,
|
|
136
|
+
system,
|
|
137
|
+
shouldAbort,
|
|
138
|
+
vertexTableRequired: true,
|
|
139
|
+
modelId: this.tree.modelId,
|
|
140
|
+
isLeaf: this.isLeaf,
|
|
141
|
+
range: this.range,
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
if (!reader)
|
|
147
|
+
return { };
|
|
148
|
+
|
|
149
|
+
return reader.read();
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
protected override addRangeGraphic(builder: GraphicBuilder, type: TileBoundingBoxes): void {
|
|
153
|
+
if (TileBoundingBoxes.ChildVolumes !== type) {
|
|
154
|
+
super.addRangeGraphic(builder, type);
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
builder.setSymbology(ColorDef.green, ColorDef.green, 2);
|
|
159
|
+
builder.addRangeBox(this.range);
|
|
160
|
+
|
|
161
|
+
this.loadChildren();
|
|
162
|
+
const children = this.children;
|
|
163
|
+
if (!children)
|
|
164
|
+
return;
|
|
165
|
+
|
|
166
|
+
builder.setSymbology(ColorDef.blue, ColorDef.blue.withTransparency(0xdf), 1);
|
|
167
|
+
for (const child of children) {
|
|
168
|
+
const range = child.range;
|
|
169
|
+
builder.addRangeBox(range);
|
|
170
|
+
builder.addRangeBox(range, true);
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
public prune(olderThan: BeTimePoint): void {
|
|
175
|
+
const children = this._batchedChildren;
|
|
176
|
+
if (!children)
|
|
177
|
+
return;
|
|
178
|
+
|
|
179
|
+
if (this.usageMarker.isExpired(olderThan)) {
|
|
180
|
+
this.disposeChildren();
|
|
181
|
+
} else {
|
|
182
|
+
for (const child of children)
|
|
183
|
+
child.prune(olderThan);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { assert, Id64, Id64String } from "@itwin/core-bentley";
|
|
7
|
+
import { Range3d } from "@itwin/core-geometry";
|
|
8
|
+
import { Feature, FeatureTable, TileReadStatus } from "@itwin/core-common";
|
|
9
|
+
import {
|
|
10
|
+
GltfDataType, GltfMeshPrimitive, GltfReader, GltfReaderArgs, GltfReaderResult,
|
|
11
|
+
} from "@itwin/core-frontend";
|
|
12
|
+
|
|
13
|
+
interface BatchedTileReaderArgs extends GltfReaderArgs {
|
|
14
|
+
modelId: Id64String;
|
|
15
|
+
isLeaf: boolean;
|
|
16
|
+
range: Range3d;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Read batched tiles in 3d Tiles 1.1 format. Currently, we prefer to produce tiles in iMdl format, so this goes unused for now.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export class BatchedTileContentReader extends GltfReader {
|
|
23
|
+
private readonly _modelId: Id64String;
|
|
24
|
+
private readonly _isLeaf: boolean;
|
|
25
|
+
private readonly _range: Range3d;
|
|
26
|
+
|
|
27
|
+
public constructor(args: BatchedTileReaderArgs) {
|
|
28
|
+
super(args);
|
|
29
|
+
this._modelId = args.modelId;
|
|
30
|
+
this._isLeaf = args.isLeaf;
|
|
31
|
+
this._range = args.range;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
public override async read(): Promise<GltfReaderResult> {
|
|
35
|
+
const featureTable = this.readFeatureTable();
|
|
36
|
+
await this.resolveResources();
|
|
37
|
+
if (this._isCanceled)
|
|
38
|
+
return { readStatus: TileReadStatus.Canceled, isLeaf: this._isLeaf };
|
|
39
|
+
|
|
40
|
+
return this.readGltfAndCreateGraphics(this._isLeaf, featureTable, this._range);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
private readFeatureTable(): FeatureTable | undefined {
|
|
44
|
+
// ###TODO we're just assuming there's one property table with one u64 property containing element Ids.
|
|
45
|
+
const tables = this._glTF.extensions?.EXT_structural_metadata?.propertyTables;
|
|
46
|
+
const table = tables ? tables[0] : undefined;
|
|
47
|
+
const elementIdProperty = table?.properties ? table.properties.ElementId : undefined;
|
|
48
|
+
if (!elementIdProperty)
|
|
49
|
+
return undefined;
|
|
50
|
+
|
|
51
|
+
const bufferView = this._bufferViews[elementIdProperty.values];
|
|
52
|
+
if (!bufferView || undefined === bufferView.buffer)
|
|
53
|
+
return undefined;
|
|
54
|
+
|
|
55
|
+
const bufferData = this._buffers[bufferView.buffer]?.resolvedBuffer;
|
|
56
|
+
if (!bufferData)
|
|
57
|
+
return undefined;
|
|
58
|
+
|
|
59
|
+
assert(undefined !== bufferView.byteLength); // required by spec; TypeScript interface is wrong.
|
|
60
|
+
const byteOffset = bufferView.byteOffset ?? 0;
|
|
61
|
+
const bytes = bufferData.subarray(byteOffset, byteOffset + bufferView.byteLength);
|
|
62
|
+
|
|
63
|
+
// 2 u32s per element Id.
|
|
64
|
+
const elementIds = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
|
|
65
|
+
const numFeatures = elementIds.length / 2;
|
|
66
|
+
const featureTable = new FeatureTable(numFeatures, this._modelId);
|
|
67
|
+
for (let i = 0; i < numFeatures; i++) {
|
|
68
|
+
const elementId = Id64.fromUint32Pair(elementIds[i * 2], elementIds[i * 2 + 1]);
|
|
69
|
+
featureTable.insertWithIndex(new Feature(elementId), i);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
return featureTable;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
protected override readPrimitiveFeatures(primitive: GltfMeshPrimitive): Feature | number[] | undefined {
|
|
76
|
+
const ext = primitive.extensions?.EXT_mesh_features;
|
|
77
|
+
if (ext) {
|
|
78
|
+
// ###TODO making assumptions here.
|
|
79
|
+
const view = this.getBufferView(primitive.attributes, `_FEATURE_ID_${ext.featureIds[0].attribute}`);
|
|
80
|
+
// NB: 32-bit integers are not supported, but 8- and 16-bit integers will be converted to them.
|
|
81
|
+
// With more than 64k features in the tile we represent the Ids as floats instead.
|
|
82
|
+
const featureIds = view?.toBufferData(GltfDataType.Float) ?? view?.toBufferData(GltfDataType.UInt32);
|
|
83
|
+
if (view && featureIds) {
|
|
84
|
+
const indices = [];
|
|
85
|
+
for (let i = 0; i < featureIds.count; i++) {
|
|
86
|
+
const featureId = featureIds.buffer[i * view.stride];
|
|
87
|
+
indices.push(featureId);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
return indices;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new Feature(this._modelId);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { BeTimePoint } from "@itwin/core-bentley";
|
|
7
|
+
import { RenderMode, ViewFlagOverrides } from "@itwin/core-common";
|
|
8
|
+
import {
|
|
9
|
+
Tile, TileDrawArgs, TileTree, TileTreeParams,
|
|
10
|
+
} from "@itwin/core-frontend";
|
|
11
|
+
import { BatchedTile, BatchedTileParams } from "./BatchedTile";
|
|
12
|
+
import { BatchedTilesetReader } from "./BatchedTilesetReader";
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export interface BatchedTileTreeParams extends TileTreeParams {
|
|
16
|
+
rootTile: BatchedTileParams;
|
|
17
|
+
reader: BatchedTilesetReader;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const viewFlagOverrides: ViewFlagOverrides = {
|
|
21
|
+
renderMode: RenderMode.SmoothShade,
|
|
22
|
+
visibleEdges: false,
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export class BatchedTileTree extends TileTree {
|
|
27
|
+
private readonly _rootTile: BatchedTile;
|
|
28
|
+
public readonly reader: BatchedTilesetReader;
|
|
29
|
+
|
|
30
|
+
public constructor(params: BatchedTileTreeParams) {
|
|
31
|
+
super(params);
|
|
32
|
+
this._rootTile = new BatchedTile(params.rootTile, this);
|
|
33
|
+
this.reader = params.reader;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
public override get rootTile(): BatchedTile {
|
|
37
|
+
return this._rootTile;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public override get is3d(): boolean {
|
|
41
|
+
return true;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public override get maxDepth(): number | undefined {
|
|
45
|
+
return undefined;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
public override get viewFlagOverrides(): ViewFlagOverrides {
|
|
49
|
+
return viewFlagOverrides;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
53
|
+
public override _selectTiles(args: TileDrawArgs): Tile[] {
|
|
54
|
+
const selected: BatchedTile[] = [];
|
|
55
|
+
this.rootTile.selectTiles(selected, args);
|
|
56
|
+
return selected;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
public override draw(args: TileDrawArgs): void {
|
|
60
|
+
const tiles = this.selectTiles(args);
|
|
61
|
+
for (const tile of tiles)
|
|
62
|
+
tile.drawGraphics(args);
|
|
63
|
+
|
|
64
|
+
args.drawGraphics();
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
public override prune(): void {
|
|
68
|
+
const olderThan = BeTimePoint.now().minus(this.expirationTime);
|
|
69
|
+
this.rootTile.prune(olderThan);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
IModelConnection, TileTreeOwner, TileTreeReference,
|
|
8
|
+
} from "@itwin/core-frontend";
|
|
9
|
+
import { getBatchedTileTreeOwner } from "./BatchedTileTreeSupplier";
|
|
10
|
+
|
|
11
|
+
class BatchedTileTreeReference extends TileTreeReference {
|
|
12
|
+
private readonly _treeOwner: TileTreeOwner;
|
|
13
|
+
|
|
14
|
+
public constructor(treeOwner: TileTreeOwner) {
|
|
15
|
+
super();
|
|
16
|
+
this._treeOwner = treeOwner;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
public override get treeOwner(): TileTreeOwner {
|
|
20
|
+
return this._treeOwner;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** @internal */
|
|
25
|
+
export function createBatchedTileTreeReference(iModel: IModelConnection, baseUrl: URL): TileTreeReference {
|
|
26
|
+
const owner = getBatchedTileTreeOwner(iModel, baseUrl);
|
|
27
|
+
return new BatchedTileTreeReference(owner);
|
|
28
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { compareStrings, Logger } from "@itwin/core-bentley";
|
|
7
|
+
import {
|
|
8
|
+
IModelConnection, TileTree, TileTreeOwner, TileTreeSupplier,
|
|
9
|
+
} from "@itwin/core-frontend";
|
|
10
|
+
import { loggerCategory } from "./LoggerCategory";
|
|
11
|
+
import { BatchedTilesetReader } from "./BatchedTilesetReader";
|
|
12
|
+
import { BatchedTileTree } from "./BatchedTileTree";
|
|
13
|
+
|
|
14
|
+
/** @internal */
|
|
15
|
+
export type TreeId = URL;
|
|
16
|
+
|
|
17
|
+
class BatchedTileTreeSupplier implements TileTreeSupplier {
|
|
18
|
+
public compareTileTreeIds(lhs: TreeId, rhs: TreeId): number {
|
|
19
|
+
// Currently each iModel has exactly 1 unique tile tree for all spatial models.
|
|
20
|
+
return compareStrings(lhs.toString(), rhs.toString());
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public async createTileTree(baseUrl: TreeId, iModel: IModelConnection): Promise<TileTree | undefined> {
|
|
24
|
+
const url = new URL("tileset.json", baseUrl);
|
|
25
|
+
url.search = baseUrl.search;
|
|
26
|
+
try {
|
|
27
|
+
const response = await fetch(url.toString());
|
|
28
|
+
const json = await response.json();
|
|
29
|
+
|
|
30
|
+
const reader = new BatchedTilesetReader(json, iModel, baseUrl);
|
|
31
|
+
const params = await reader.readTileTreeParams();
|
|
32
|
+
return new BatchedTileTree(params);
|
|
33
|
+
} catch (err) {
|
|
34
|
+
Logger.logException(loggerCategory, err);
|
|
35
|
+
return undefined;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const batchedTileTreeSupplier: TileTreeSupplier = new BatchedTileTreeSupplier();
|
|
41
|
+
|
|
42
|
+
/** @internal */
|
|
43
|
+
export function getBatchedTileTreeOwner(iModel: IModelConnection, baseUrl: URL): TileTreeOwner {
|
|
44
|
+
return iModel.tiles.getTileTreeOwner(baseUrl, batchedTileTreeSupplier);
|
|
45
|
+
}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
Angle, Matrix3d, Point3d, Range3d, Transform, Vector3d,
|
|
8
|
+
} from "@itwin/core-geometry";
|
|
9
|
+
import { Tileset3dSchema as schema } from "@itwin/core-common";
|
|
10
|
+
import { IModelConnection, RealityModelTileUtils, TileLoadPriority } from "@itwin/core-frontend";
|
|
11
|
+
import { BatchedTileTreeParams } from "./BatchedTileTree";
|
|
12
|
+
import { BatchedTile, BatchedTileParams } from "./BatchedTile";
|
|
13
|
+
|
|
14
|
+
function isTileset3d(json: unknown): json is schema.Tileset {
|
|
15
|
+
if (typeof json !== "object")
|
|
16
|
+
return false;
|
|
17
|
+
|
|
18
|
+
const props = json as schema.Tileset;
|
|
19
|
+
|
|
20
|
+
if (!props.root || !props.asset)
|
|
21
|
+
return false;
|
|
22
|
+
|
|
23
|
+
// ###TODO spec requires geometricError to be present on tileset and all tiles; exporter is omitting from tileset.
|
|
24
|
+
if (undefined === props.geometricError)
|
|
25
|
+
props.geometricError = props.root.geometricError;
|
|
26
|
+
|
|
27
|
+
return true;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function rangeFromBoundingVolume(vol: schema.BoundingVolume): Range3d {
|
|
31
|
+
if (vol.box) {
|
|
32
|
+
const center = new Point3d(vol.box[0], vol.box[1], vol.box[2]);
|
|
33
|
+
const ux = new Vector3d(vol.box[3], vol.box[4], vol.box[5]);
|
|
34
|
+
const uy = new Vector3d(vol.box[6], vol.box[7], vol.box[8]);
|
|
35
|
+
const uz = new Vector3d(vol.box[9], vol.box[10], vol.box[11]);
|
|
36
|
+
|
|
37
|
+
const range = Range3d.createNull();
|
|
38
|
+
for (let i = -1; i <= 1; i += 2)
|
|
39
|
+
for (let j = -1; j <= 1; j += 2)
|
|
40
|
+
for (let k = -1; k <= 1; k += 2)
|
|
41
|
+
range.extendPoint(center.plus3Scaled(ux, i, uy, j, uz, k));
|
|
42
|
+
|
|
43
|
+
return range;
|
|
44
|
+
} else if (vol.sphere) {
|
|
45
|
+
const center = new Point3d(vol.sphere[0], vol.sphere[1], vol.sphere[2]);
|
|
46
|
+
const radius = vol.sphere[3];
|
|
47
|
+
return Range3d.createXYZXYZ(center.x - radius, center.y - radius, center.z - radius, center.x + radius, center.y + radius, center.z + radius);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// We won't get region bounding volumes in our tiles.
|
|
51
|
+
throw new Error("region bounding volume unimplemented");
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function transformFromJSON(json: schema.Transform): Transform {
|
|
55
|
+
const translation = new Point3d(json[12], json[13], json[14]);
|
|
56
|
+
const matrix = Matrix3d.createRowValues(
|
|
57
|
+
json[0], json[4], json[8],
|
|
58
|
+
json[1], json[5], json[9],
|
|
59
|
+
json[2], json[6], json[10]
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return Transform.createOriginAndMatrix(translation, matrix);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** @internal */
|
|
66
|
+
export class BatchedTilesetReader {
|
|
67
|
+
private readonly _iModel: IModelConnection;
|
|
68
|
+
private readonly _tileset: schema.Tileset;
|
|
69
|
+
public readonly baseUrl: URL;
|
|
70
|
+
|
|
71
|
+
public constructor(json: unknown, iModel: IModelConnection, baseUrl: URL) {
|
|
72
|
+
if (!isTileset3d(json))
|
|
73
|
+
throw new Error("Invalid tileset JSON");
|
|
74
|
+
|
|
75
|
+
this._iModel = iModel;
|
|
76
|
+
this._tileset = json;
|
|
77
|
+
this.baseUrl = baseUrl;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
public readTileParams(json: schema.Tile, parent?: BatchedTile): BatchedTileParams {
|
|
81
|
+
const content = json.content;
|
|
82
|
+
const geometricError = json.geometricError;
|
|
83
|
+
const range = rangeFromBoundingVolume(json.boundingVolume);
|
|
84
|
+
const isLeaf = undefined === json.children || json.children.length === 0;
|
|
85
|
+
|
|
86
|
+
// ###TODO evaluate this. The geometric errors in the tiles seem far too small.
|
|
87
|
+
const maximumSizeScale = 8;
|
|
88
|
+
return {
|
|
89
|
+
parent,
|
|
90
|
+
contentId: content?.uri ?? "",
|
|
91
|
+
range,
|
|
92
|
+
contentRange: content?.boundingVolume ? rangeFromBoundingVolume(content.boundingVolume) : undefined,
|
|
93
|
+
isLeaf,
|
|
94
|
+
maximumSize: maximumSizeScale * RealityModelTileUtils.maximumSizeFromGeometricTolerance(range, geometricError),
|
|
95
|
+
childrenProps: isLeaf ? undefined : json.children,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
public async readTileTreeParams(): Promise<BatchedTileTreeParams> {
|
|
100
|
+
const root = this._tileset.root;
|
|
101
|
+
const location = root.transform ? transformFromJSON(root.transform) : Transform.createIdentity();
|
|
102
|
+
// y axis is up in glTF. we want z up.
|
|
103
|
+
location.multiplyTransformMatrix3d(Matrix3d.createRotationAroundVector(Vector3d.create(1, 0, 0), Angle.createRadians(Angle.piOver2Radians))!, location);
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
id: "spatial-models",
|
|
107
|
+
modelId: this._iModel.transientIds.getNext(),
|
|
108
|
+
iModel: this._iModel,
|
|
109
|
+
location,
|
|
110
|
+
priority: TileLoadPriority.Primary,
|
|
111
|
+
rootTile: this.readTileParams(root),
|
|
112
|
+
reader: this,
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
import { IModelConnection, SpatialTileTreeReferences, SpatialViewState } from "@itwin/core-frontend";
|
|
7
|
+
import { createBatchedSpatialTileTreeReferences } from "./BatchedSpatialTileTreeRefs";
|
|
8
|
+
|
|
9
|
+
/** Options supplied to [[initializeFrontendTiles]].
|
|
10
|
+
* @alpha
|
|
11
|
+
*/
|
|
12
|
+
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;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** Initialize the frontend-tiles package to obtain tiles for spatial views.
|
|
20
|
+
* @alpha
|
|
21
|
+
*/
|
|
22
|
+
export function initializeFrontendTiles(options: FrontendTilesOptions): void {
|
|
23
|
+
SpatialTileTreeReferences.create = (view: SpatialViewState) => createBatchedSpatialTileTreeReferences(view.iModel, options.computeSpatialTilesetBaseUrl);
|
|
24
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
/** @internal */
|
|
7
|
+
export const loggerCategory = "frontend-tiles";
|
|
8
|
+
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/*---------------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
|
|
3
|
+
* See LICENSE.md in the project root for license terms and full copyright notice.
|
|
4
|
+
*--------------------------------------------------------------------------------------------*/
|
|
5
|
+
|
|
6
|
+
export * from "./FrontendTiles";
|