@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.
Files changed (102) hide show
  1. package/.rush/temp/operation/build_ci/state.json +3 -0
  2. package/.rush/temp/package-deps_build_ci.json +21 -0
  3. package/.rush/temp/shrinkwrap-deps.json +287 -0
  4. package/LICENSE.md +9 -0
  5. package/README.md +12 -0
  6. package/config/rush-project.json +7 -0
  7. package/frontend-tiles.build.error.log +1 -0
  8. package/frontend-tiles.build.log +2 -0
  9. package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts +4 -0
  10. package/lib/cjs/BatchedSpatialTileTreeRefs.d.ts.map +1 -0
  11. package/lib/cjs/BatchedSpatialTileTreeRefs.js +28 -0
  12. package/lib/cjs/BatchedSpatialTileTreeRefs.js.map +1 -0
  13. package/lib/cjs/BatchedTile.d.ts +24 -0
  14. package/lib/cjs/BatchedTile.d.ts.map +1 -0
  15. package/lib/cjs/BatchedTile.js +156 -0
  16. package/lib/cjs/BatchedTile.js.map +1 -0
  17. package/lib/cjs/BatchedTileContentReader.d.ts +23 -0
  18. package/lib/cjs/BatchedTileContentReader.d.ts.map +1 -0
  19. package/lib/cjs/BatchedTileContentReader.js +75 -0
  20. package/lib/cjs/BatchedTileContentReader.js.map +1 -0
  21. package/lib/cjs/BatchedTileTree.d.ts +23 -0
  22. package/lib/cjs/BatchedTileTree.d.ts.map +1 -0
  23. package/lib/cjs/BatchedTileTree.js +53 -0
  24. package/lib/cjs/BatchedTileTree.js.map +1 -0
  25. package/lib/cjs/BatchedTileTreeReference.d.ts +4 -0
  26. package/lib/cjs/BatchedTileTreeReference.d.ts.map +1 -0
  27. package/lib/cjs/BatchedTileTreeReference.js +25 -0
  28. package/lib/cjs/BatchedTileTreeReference.js.map +1 -0
  29. package/lib/cjs/BatchedTileTreeSupplier.d.ts +6 -0
  30. package/lib/cjs/BatchedTileTreeSupplier.d.ts.map +1 -0
  31. package/lib/cjs/BatchedTileTreeSupplier.js +39 -0
  32. package/lib/cjs/BatchedTileTreeSupplier.js.map +1 -0
  33. package/lib/cjs/BatchedTilesetReader.d.ts +14 -0
  34. package/lib/cjs/BatchedTilesetReader.d.ts.map +1 -0
  35. package/lib/cjs/BatchedTilesetReader.js +90 -0
  36. package/lib/cjs/BatchedTilesetReader.js.map +1 -0
  37. package/lib/cjs/FrontendTiles.d.ts +15 -0
  38. package/lib/cjs/FrontendTiles.d.ts.map +1 -0
  39. package/lib/cjs/FrontendTiles.js +17 -0
  40. package/lib/cjs/FrontendTiles.js.map +1 -0
  41. package/lib/cjs/LoggerCategory.d.ts +3 -0
  42. package/lib/cjs/LoggerCategory.d.ts.map +1 -0
  43. package/lib/cjs/LoggerCategory.js +10 -0
  44. package/lib/cjs/LoggerCategory.js.map +1 -0
  45. package/lib/cjs/frontend-tiles.d.ts +2 -0
  46. package/lib/cjs/frontend-tiles.d.ts.map +1 -0
  47. package/lib/cjs/frontend-tiles.js +18 -0
  48. package/lib/cjs/frontend-tiles.js.map +1 -0
  49. package/lib/cjs/tsconfig.tsbuildinfo +1 -0
  50. package/lib/esm/BatchedSpatialTileTreeRefs.d.ts +4 -0
  51. package/lib/esm/BatchedSpatialTileTreeRefs.d.ts.map +1 -0
  52. package/lib/esm/BatchedSpatialTileTreeRefs.js +24 -0
  53. package/lib/esm/BatchedSpatialTileTreeRefs.js.map +1 -0
  54. package/lib/esm/BatchedTile.d.ts +24 -0
  55. package/lib/esm/BatchedTile.d.ts.map +1 -0
  56. package/lib/esm/BatchedTile.js +152 -0
  57. package/lib/esm/BatchedTile.js.map +1 -0
  58. package/lib/esm/BatchedTileContentReader.d.ts +23 -0
  59. package/lib/esm/BatchedTileContentReader.d.ts.map +1 -0
  60. package/lib/esm/BatchedTileContentReader.js +71 -0
  61. package/lib/esm/BatchedTileContentReader.js.map +1 -0
  62. package/lib/esm/BatchedTileTree.d.ts +23 -0
  63. package/lib/esm/BatchedTileTree.d.ts.map +1 -0
  64. package/lib/esm/BatchedTileTree.js +49 -0
  65. package/lib/esm/BatchedTileTree.js.map +1 -0
  66. package/lib/esm/BatchedTileTreeReference.d.ts +4 -0
  67. package/lib/esm/BatchedTileTreeReference.d.ts.map +1 -0
  68. package/lib/esm/BatchedTileTreeReference.js +21 -0
  69. package/lib/esm/BatchedTileTreeReference.js.map +1 -0
  70. package/lib/esm/BatchedTileTreeSupplier.d.ts +6 -0
  71. package/lib/esm/BatchedTileTreeSupplier.d.ts.map +1 -0
  72. package/lib/esm/BatchedTileTreeSupplier.js +35 -0
  73. package/lib/esm/BatchedTileTreeSupplier.js.map +1 -0
  74. package/lib/esm/BatchedTilesetReader.d.ts +14 -0
  75. package/lib/esm/BatchedTilesetReader.d.ts.map +1 -0
  76. package/lib/esm/BatchedTilesetReader.js +86 -0
  77. package/lib/esm/BatchedTilesetReader.js.map +1 -0
  78. package/lib/esm/FrontendTiles.d.ts +15 -0
  79. package/lib/esm/FrontendTiles.d.ts.map +1 -0
  80. package/lib/esm/FrontendTiles.js +13 -0
  81. package/lib/esm/FrontendTiles.js.map +1 -0
  82. package/lib/esm/LoggerCategory.d.ts +3 -0
  83. package/lib/esm/LoggerCategory.d.ts.map +1 -0
  84. package/lib/esm/LoggerCategory.js +7 -0
  85. package/lib/esm/LoggerCategory.js.map +1 -0
  86. package/lib/esm/frontend-tiles.d.ts +2 -0
  87. package/lib/esm/frontend-tiles.d.ts.map +1 -0
  88. package/lib/esm/frontend-tiles.js +6 -0
  89. package/lib/esm/frontend-tiles.js.map +1 -0
  90. package/lib/esm/tsconfig.tsbuildinfo +1 -0
  91. package/package.json +61 -0
  92. package/src/BatchedSpatialTileTreeRefs.ts +34 -0
  93. package/src/BatchedTile.ts +186 -0
  94. package/src/BatchedTileContentReader.ts +96 -0
  95. package/src/BatchedTileTree.ts +71 -0
  96. package/src/BatchedTileTreeReference.ts +28 -0
  97. package/src/BatchedTileTreeSupplier.ts +45 -0
  98. package/src/BatchedTilesetReader.ts +115 -0
  99. package/src/FrontendTiles.ts +24 -0
  100. package/src/LoggerCategory.ts +8 -0
  101. package/src/frontend-tiles.ts +6 -0
  102. package/tsconfig.json +6 -0
@@ -0,0 +1,156 @@
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
+ /** @internal */
14
+ class BatchedTile extends core_frontend_1.Tile {
15
+ constructor(params, tree) {
16
+ super(params, tree);
17
+ if (params.childrenProps?.length)
18
+ this._childrenProps = params.childrenProps;
19
+ if (!this.contentId)
20
+ this.setIsReady();
21
+ }
22
+ get batchedTree() {
23
+ return this.tree;
24
+ }
25
+ get _batchedChildren() {
26
+ return this.children;
27
+ }
28
+ computeLoadPriority(viewports, _users) {
29
+ // Prioritize tiles closer to camera and center of attention (zoom point or screen center).
30
+ return core_frontend_1.RealityTileLoader.computeTileLocationPriority(this, viewports, this.tree.iModelTransform);
31
+ }
32
+ selectTiles(selected, args) {
33
+ const vis = this.computeVisibility(args);
34
+ if (core_frontend_1.TileVisibility.OutsideFrustum === vis)
35
+ return;
36
+ // ###TODO proper tile refinement. Currently we simply load each level of the tree in succession until we find a tile that
37
+ // meets screen space error. Moreover, while we wait for children to load we stop displaying the parent.
38
+ // Prefer to skip some levels where appropriate.
39
+ // More importantly, fix tile tree structure so that children can be substituted for (portions of) parents more quickly, especially near the camera
40
+ // (need non-overlapping child volumes).
41
+ if (!this.isReady) {
42
+ args.insertMissing(this);
43
+ return;
44
+ }
45
+ if (core_frontend_1.TileVisibility.Visible === vis && this.hasGraphics) {
46
+ args.markReady(this);
47
+ selected.push(this);
48
+ return;
49
+ }
50
+ args.markUsed(this);
51
+ if (this.isReady) {
52
+ const childrenStatus = this.loadChildren();
53
+ if (core_frontend_1.TileTreeLoadStatus.Loading === childrenStatus)
54
+ args.markChildrenLoading();
55
+ const children = this._batchedChildren;
56
+ if (children)
57
+ for (const child of children)
58
+ child.selectTiles(selected, args);
59
+ }
60
+ }
61
+ _loadChildren(resolve, reject) {
62
+ let children;
63
+ if (this._childrenProps) {
64
+ try {
65
+ for (const childProps of this._childrenProps) {
66
+ const params = this.batchedTree.reader.readTileParams(childProps, this);
67
+ const child = new BatchedTile(params, this.batchedTree);
68
+ children = children ?? [];
69
+ children.push(child);
70
+ }
71
+ }
72
+ catch (err) {
73
+ core_bentley_1.Logger.logException(LoggerCategory_1.loggerCategory, err);
74
+ children = undefined;
75
+ if (err instanceof Error)
76
+ reject(err);
77
+ }
78
+ }
79
+ resolve(children);
80
+ }
81
+ get channel() {
82
+ return core_frontend_1.IModelApp.tileAdmin.channels.getForHttp("itwinjs-batched-models");
83
+ }
84
+ async requestContent(_isCanceled) {
85
+ const url = new URL(this.contentId, this.batchedTree.reader.baseUrl);
86
+ url.search = this.batchedTree.reader.baseUrl.search;
87
+ const response = await fetch(url.toString());
88
+ return response.arrayBuffer();
89
+ }
90
+ async readContent(data, system, shouldAbort) {
91
+ (0, core_bentley_1.assert)(data instanceof Uint8Array);
92
+ if (!(data instanceof Uint8Array))
93
+ return {};
94
+ let reader = core_frontend_1.ImdlReader.create({
95
+ stream: core_bentley_1.ByteStream.fromUint8Array(data),
96
+ iModel: this.tree.iModel,
97
+ modelId: this.tree.modelId,
98
+ is3d: true,
99
+ system,
100
+ isCanceled: shouldAbort,
101
+ options: {
102
+ tileId: this.contentId,
103
+ },
104
+ });
105
+ if (!reader) {
106
+ const gltfProps = core_frontend_1.GltfReaderProps.create(data, false, this.batchedTree.reader.baseUrl);
107
+ if (gltfProps) {
108
+ reader = new BatchedTileContentReader_1.BatchedTileContentReader({
109
+ props: gltfProps,
110
+ iModel: this.tree.iModel,
111
+ system,
112
+ shouldAbort,
113
+ vertexTableRequired: true,
114
+ modelId: this.tree.modelId,
115
+ isLeaf: this.isLeaf,
116
+ range: this.range,
117
+ });
118
+ }
119
+ }
120
+ if (!reader)
121
+ return {};
122
+ return reader.read();
123
+ }
124
+ addRangeGraphic(builder, type) {
125
+ if (core_frontend_1.TileBoundingBoxes.ChildVolumes !== type) {
126
+ super.addRangeGraphic(builder, type);
127
+ return;
128
+ }
129
+ builder.setSymbology(core_common_1.ColorDef.green, core_common_1.ColorDef.green, 2);
130
+ builder.addRangeBox(this.range);
131
+ this.loadChildren();
132
+ const children = this.children;
133
+ if (!children)
134
+ return;
135
+ builder.setSymbology(core_common_1.ColorDef.blue, core_common_1.ColorDef.blue.withTransparency(0xdf), 1);
136
+ for (const child of children) {
137
+ const range = child.range;
138
+ builder.addRangeBox(range);
139
+ builder.addRangeBox(range, true);
140
+ }
141
+ }
142
+ prune(olderThan) {
143
+ const children = this._batchedChildren;
144
+ if (!children)
145
+ return;
146
+ if (this.usageMarker.isExpired(olderThan)) {
147
+ this.disposeChildren();
148
+ }
149
+ else {
150
+ for (const child of children)
151
+ child.prune(olderThan);
152
+ }
153
+ }
154
+ }
155
+ exports.BatchedTile = BatchedTile;
156
+ //# sourceMappingURL=BatchedTile.js.map
@@ -0,0 +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,gBAAgB;AAChB,MAAa,WAAY,SAAQ,oBAAI;IAOnC,YAAmB,MAAyB,EAAE,IAAqB;QACjE,KAAK,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;QACpB,IAAI,MAAM,CAAC,aAAa,EAAE,MAA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------------------------------------------------------------\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, Tile, TileBoundingBoxes, TileContent, TileDrawArgs, TileParams, TileRequest,\r\n 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\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 }\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): void {\r\n const vis = this.computeVisibility(args);\r\n if (TileVisibility.OutsideFrustum === vis)\r\n return;\r\n\r\n // ###TODO proper tile refinement. Currently we simply load each level of the tree in succession until we find a tile that\r\n // meets screen space error. Moreover, while we wait for children to load we stop displaying the parent.\r\n // Prefer to skip some levels where appropriate.\r\n // More importantly, fix tile tree structure so that children can be substituted for (portions of) parents more quickly, especially near the camera\r\n // (need non-overlapping child volumes).\r\n if (!this.isReady) {\r\n args.insertMissing(this);\r\n return;\r\n }\r\n\r\n if (TileVisibility.Visible === vis && this.hasGraphics) {\r\n args.markReady(this);\r\n selected.push(this);\r\n return;\r\n }\r\n\r\n args.markUsed(this);\r\n if (this.isReady) {\r\n const childrenStatus = this.loadChildren();\r\n if (TileTreeLoadStatus.Loading === childrenStatus)\r\n args.markChildrenLoading();\r\n\r\n const children = this._batchedChildren;\r\n if (children)\r\n for (const child of children)\r\n child.selectTiles(selected, args);\r\n }\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 return IModelApp.tileAdmin.channels.getForHttp(\"itwinjs-batched-models\");\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"]}
@@ -0,0 +1,23 @@
1
+ import { Id64String } from "@itwin/core-bentley";
2
+ import { Range3d } from "@itwin/core-geometry";
3
+ import { Feature } from "@itwin/core-common";
4
+ import { GltfMeshPrimitive, GltfReader, GltfReaderArgs, GltfReaderResult } from "@itwin/core-frontend";
5
+ interface BatchedTileReaderArgs extends GltfReaderArgs {
6
+ modelId: Id64String;
7
+ isLeaf: boolean;
8
+ range: Range3d;
9
+ }
10
+ /** Read batched tiles in 3d Tiles 1.1 format. Currently, we prefer to produce tiles in iMdl format, so this goes unused for now.
11
+ * @internal
12
+ */
13
+ export declare class BatchedTileContentReader extends GltfReader {
14
+ private readonly _modelId;
15
+ private readonly _isLeaf;
16
+ private readonly _range;
17
+ constructor(args: BatchedTileReaderArgs);
18
+ read(): Promise<GltfReaderResult>;
19
+ private readFeatureTable;
20
+ protected readPrimitiveFeatures(primitive: GltfMeshPrimitive): Feature | number[] | undefined;
21
+ }
22
+ export {};
23
+ //# sourceMappingURL=BatchedTileContentReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileContentReader.d.ts","sourceRoot":"","sources":["../../src/BatchedTileContentReader.ts"],"names":[],"mappings":"AAKA,OAAO,EAAgB,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAC/C,OAAO,EAAE,OAAO,EAAgC,MAAM,oBAAoB,CAAC;AAC3E,OAAO,EACS,iBAAiB,EAAE,UAAU,EAAE,cAAc,EAAE,gBAAgB,EAC9E,MAAM,sBAAsB,CAAC;AAE9B,UAAU,qBAAsB,SAAQ,cAAc;IACpD,OAAO,EAAE,UAAU,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,KAAK,EAAE,OAAO,CAAC;CAChB;AAED;;GAEG;AACH,qBAAa,wBAAyB,SAAQ,UAAU;IACtD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAa;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAU;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAU;gBAEd,IAAI,EAAE,qBAAqB;IAOxB,IAAI,IAAI,OAAO,CAAC,gBAAgB,CAAC;IASvD,OAAO,CAAC,gBAAgB;cAgCL,qBAAqB,CAAC,SAAS,EAAE,iBAAiB,GAAG,OAAO,GAAG,MAAM,EAAE,GAAG,SAAS;CAqBvG"}
@@ -0,0 +1,75 @@
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.BatchedTileContentReader = 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
+ /** Read batched tiles in 3d Tiles 1.1 format. Currently, we prefer to produce tiles in iMdl format, so this goes unused for now.
12
+ * @internal
13
+ */
14
+ class BatchedTileContentReader extends core_frontend_1.GltfReader {
15
+ constructor(args) {
16
+ super(args);
17
+ this._modelId = args.modelId;
18
+ this._isLeaf = args.isLeaf;
19
+ this._range = args.range;
20
+ }
21
+ async read() {
22
+ const featureTable = this.readFeatureTable();
23
+ await this.resolveResources();
24
+ if (this._isCanceled)
25
+ return { readStatus: core_common_1.TileReadStatus.Canceled, isLeaf: this._isLeaf };
26
+ return this.readGltfAndCreateGraphics(this._isLeaf, featureTable, this._range);
27
+ }
28
+ readFeatureTable() {
29
+ // ###TODO we're just assuming there's one property table with one u64 property containing element Ids.
30
+ const tables = this._glTF.extensions?.EXT_structural_metadata?.propertyTables;
31
+ const table = tables ? tables[0] : undefined;
32
+ const elementIdProperty = table?.properties ? table.properties.ElementId : undefined;
33
+ if (!elementIdProperty)
34
+ return undefined;
35
+ const bufferView = this._bufferViews[elementIdProperty.values];
36
+ if (!bufferView || undefined === bufferView.buffer)
37
+ return undefined;
38
+ const bufferData = this._buffers[bufferView.buffer]?.resolvedBuffer;
39
+ if (!bufferData)
40
+ return undefined;
41
+ (0, core_bentley_1.assert)(undefined !== bufferView.byteLength); // required by spec; TypeScript interface is wrong.
42
+ const byteOffset = bufferView.byteOffset ?? 0;
43
+ const bytes = bufferData.subarray(byteOffset, byteOffset + bufferView.byteLength);
44
+ // 2 u32s per element Id.
45
+ const elementIds = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);
46
+ const numFeatures = elementIds.length / 2;
47
+ const featureTable = new core_common_1.FeatureTable(numFeatures, this._modelId);
48
+ for (let i = 0; i < numFeatures; i++) {
49
+ const elementId = core_bentley_1.Id64.fromUint32Pair(elementIds[i * 2], elementIds[i * 2 + 1]);
50
+ featureTable.insertWithIndex(new core_common_1.Feature(elementId), i);
51
+ }
52
+ return featureTable;
53
+ }
54
+ readPrimitiveFeatures(primitive) {
55
+ const ext = primitive.extensions?.EXT_mesh_features;
56
+ if (ext) {
57
+ // ###TODO making assumptions here.
58
+ const view = this.getBufferView(primitive.attributes, `_FEATURE_ID_${ext.featureIds[0].attribute}`);
59
+ // NB: 32-bit integers are not supported, but 8- and 16-bit integers will be converted to them.
60
+ // With more than 64k features in the tile we represent the Ids as floats instead.
61
+ const featureIds = view?.toBufferData(core_frontend_1.GltfDataType.Float) ?? view?.toBufferData(core_frontend_1.GltfDataType.UInt32);
62
+ if (view && featureIds) {
63
+ const indices = [];
64
+ for (let i = 0; i < featureIds.count; i++) {
65
+ const featureId = featureIds.buffer[i * view.stride];
66
+ indices.push(featureId);
67
+ }
68
+ return indices;
69
+ }
70
+ }
71
+ return new core_common_1.Feature(this._modelId);
72
+ }
73
+ }
74
+ exports.BatchedTileContentReader = BatchedTileContentReader;
75
+ //# sourceMappingURL=BatchedTileContentReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileContentReader.js","sourceRoot":"","sources":["../../src/BatchedTileContentReader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA+D;AAE/D,oDAA2E;AAC3E,wDAE8B;AAQ9B;;GAEG;AACH,MAAa,wBAAyB,SAAQ,0BAAU;IAKtD,YAAmB,IAA2B;QAC5C,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pG,+FAA+F;YAC/F,kFAAkF;YAClF,MAAM,UAAU,GAAG,IAAI,EAAE,YAAY,CAAC,4BAAY,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,YAAY,CAAC,4BAAY,CAAC,MAAM,CAAC,CAAC;YACrG,IAAI,IAAI,IAAI,UAAU,EAAE;gBACtB,MAAM,OAAO,GAAG,EAAE,CAAC;gBACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE;oBACzC,MAAM,SAAS,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC;oBACrD,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;iBACzB;gBAED,OAAO,OAAO,CAAC;aAChB;SACF;QAED,OAAO,IAAI,qBAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IACpC,CAAC;CACF;AA1ED,4DA0EC","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, Id64, Id64String } from \"@itwin/core-bentley\";\r\nimport { Range3d } from \"@itwin/core-geometry\";\r\nimport { Feature, FeatureTable, TileReadStatus } from \"@itwin/core-common\";\r\nimport {\r\n GltfDataType, GltfMeshPrimitive, GltfReader, GltfReaderArgs, GltfReaderResult,\r\n} from \"@itwin/core-frontend\";\r\n\r\ninterface BatchedTileReaderArgs extends GltfReaderArgs {\r\n modelId: Id64String;\r\n isLeaf: boolean;\r\n range: Range3d;\r\n}\r\n\r\n/** Read batched tiles in 3d Tiles 1.1 format. Currently, we prefer to produce tiles in iMdl format, so this goes unused for now.\r\n * @internal\r\n */\r\nexport class BatchedTileContentReader extends GltfReader {\r\n private readonly _modelId: Id64String;\r\n private readonly _isLeaf: boolean;\r\n private readonly _range: Range3d;\r\n\r\n public constructor(args: BatchedTileReaderArgs) {\r\n super(args);\r\n this._modelId = args.modelId;\r\n this._isLeaf = args.isLeaf;\r\n this._range = args.range;\r\n }\r\n\r\n public override async read(): Promise<GltfReaderResult> {\r\n const featureTable = this.readFeatureTable();\r\n await this.resolveResources();\r\n if (this._isCanceled)\r\n return { readStatus: TileReadStatus.Canceled, isLeaf: this._isLeaf };\r\n\r\n return this.readGltfAndCreateGraphics(this._isLeaf, featureTable, this._range);\r\n }\r\n\r\n private readFeatureTable(): FeatureTable | undefined {\r\n // ###TODO we're just assuming there's one property table with one u64 property containing element Ids.\r\n const tables = this._glTF.extensions?.EXT_structural_metadata?.propertyTables;\r\n const table = tables ? tables[0] : undefined;\r\n const elementIdProperty = table?.properties ? table.properties.ElementId : undefined;\r\n if (!elementIdProperty)\r\n return undefined;\r\n\r\n const bufferView = this._bufferViews[elementIdProperty.values];\r\n if (!bufferView || undefined === bufferView.buffer)\r\n return undefined;\r\n\r\n const bufferData = this._buffers[bufferView.buffer]?.resolvedBuffer;\r\n if (!bufferData)\r\n return undefined;\r\n\r\n assert(undefined !== bufferView.byteLength); // required by spec; TypeScript interface is wrong.\r\n const byteOffset = bufferView.byteOffset ?? 0;\r\n const bytes = bufferData.subarray(byteOffset, byteOffset + bufferView.byteLength);\r\n\r\n // 2 u32s per element Id.\r\n const elementIds = new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4);\r\n const numFeatures = elementIds.length / 2;\r\n const featureTable = new FeatureTable(numFeatures, this._modelId);\r\n for (let i = 0; i < numFeatures; i++) {\r\n const elementId = Id64.fromUint32Pair(elementIds[i * 2], elementIds[i * 2 + 1]);\r\n featureTable.insertWithIndex(new Feature(elementId), i);\r\n }\r\n\r\n return featureTable;\r\n }\r\n\r\n protected override readPrimitiveFeatures(primitive: GltfMeshPrimitive): Feature | number[] | undefined {\r\n const ext = primitive.extensions?.EXT_mesh_features;\r\n if (ext) {\r\n // ###TODO making assumptions here.\r\n const view = this.getBufferView(primitive.attributes, `_FEATURE_ID_${ext.featureIds[0].attribute}`);\r\n // NB: 32-bit integers are not supported, but 8- and 16-bit integers will be converted to them.\r\n // With more than 64k features in the tile we represent the Ids as floats instead.\r\n const featureIds = view?.toBufferData(GltfDataType.Float) ?? view?.toBufferData(GltfDataType.UInt32);\r\n if (view && featureIds) {\r\n const indices = [];\r\n for (let i = 0; i < featureIds.count; i++) {\r\n const featureId = featureIds.buffer[i * view.stride];\r\n indices.push(featureId);\r\n }\r\n\r\n return indices;\r\n }\r\n }\r\n\r\n return new Feature(this._modelId);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,23 @@
1
+ import { ViewFlagOverrides } from "@itwin/core-common";
2
+ import { Tile, TileDrawArgs, TileTree, TileTreeParams } from "@itwin/core-frontend";
3
+ import { BatchedTile, BatchedTileParams } from "./BatchedTile";
4
+ import { BatchedTilesetReader } from "./BatchedTilesetReader";
5
+ /** @internal */
6
+ export interface BatchedTileTreeParams extends TileTreeParams {
7
+ rootTile: BatchedTileParams;
8
+ reader: BatchedTilesetReader;
9
+ }
10
+ /** @internal */
11
+ export declare class BatchedTileTree extends TileTree {
12
+ private readonly _rootTile;
13
+ readonly reader: BatchedTilesetReader;
14
+ constructor(params: BatchedTileTreeParams);
15
+ get rootTile(): BatchedTile;
16
+ get is3d(): boolean;
17
+ get maxDepth(): number | undefined;
18
+ get viewFlagOverrides(): ViewFlagOverrides;
19
+ _selectTiles(args: TileDrawArgs): Tile[];
20
+ draw(args: TileDrawArgs): void;
21
+ prune(): void;
22
+ }
23
+ //# sourceMappingURL=BatchedTileTree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTree.d.ts","sourceRoot":"","sources":["../../src/BatchedTileTree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAc,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACnE,OAAO,EACL,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAC7C,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,gBAAgB;AAChB,MAAM,WAAW,qBAAsB,SAAQ,cAAc;IAC3D,QAAQ,EAAE,iBAAiB,CAAC;IAC5B,MAAM,EAAE,oBAAoB,CAAC;CAC9B;AAOD,gBAAgB;AAChB,qBAAa,eAAgB,SAAQ,QAAQ;IAC3C,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,SAAgB,MAAM,EAAE,oBAAoB,CAAC;gBAE1B,MAAM,EAAE,qBAAqB;IAMhD,IAAoB,QAAQ,IAAI,WAAW,CAE1C;IAED,IAAoB,IAAI,IAAI,OAAO,CAElC;IAED,IAAoB,QAAQ,IAAI,MAAM,GAAG,SAAS,CAEjD;IAED,IAAoB,iBAAiB,IAAI,iBAAiB,CAEzD;IAGe,YAAY,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI,EAAE;IAMxC,IAAI,CAAC,IAAI,EAAE,YAAY,GAAG,IAAI;IAQ9B,KAAK,IAAI,IAAI;CAI9B"}
@@ -0,0 +1,53 @@
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.BatchedTileTree = 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 BatchedTile_1 = require("./BatchedTile");
12
+ const viewFlagOverrides = {
13
+ renderMode: core_common_1.RenderMode.SmoothShade,
14
+ visibleEdges: false,
15
+ };
16
+ /** @internal */
17
+ class BatchedTileTree extends core_frontend_1.TileTree {
18
+ constructor(params) {
19
+ super(params);
20
+ this._rootTile = new BatchedTile_1.BatchedTile(params.rootTile, this);
21
+ this.reader = params.reader;
22
+ }
23
+ get rootTile() {
24
+ return this._rootTile;
25
+ }
26
+ get is3d() {
27
+ return true;
28
+ }
29
+ get maxDepth() {
30
+ return undefined;
31
+ }
32
+ get viewFlagOverrides() {
33
+ return viewFlagOverrides;
34
+ }
35
+ // eslint-disable-next-line @typescript-eslint/naming-convention
36
+ _selectTiles(args) {
37
+ const selected = [];
38
+ this.rootTile.selectTiles(selected, args);
39
+ return selected;
40
+ }
41
+ draw(args) {
42
+ const tiles = this.selectTiles(args);
43
+ for (const tile of tiles)
44
+ tile.drawGraphics(args);
45
+ args.drawGraphics();
46
+ }
47
+ prune() {
48
+ const olderThan = core_bentley_1.BeTimePoint.now().minus(this.expirationTime);
49
+ this.rootTile.prune(olderThan);
50
+ }
51
+ }
52
+ exports.BatchedTileTree = BatchedTileTree;
53
+ //# sourceMappingURL=BatchedTileTree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTree.js","sourceRoot":"","sources":["../../src/BatchedTileTree.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAAkD;AAClD,oDAAmE;AACnE,wDAE8B;AAC9B,+CAA+D;AAS/D,MAAM,iBAAiB,GAAsB;IAC3C,UAAU,EAAE,wBAAU,CAAC,WAAW;IAClC,YAAY,EAAE,KAAK;CACpB,CAAC;AAEF,gBAAgB;AAChB,MAAa,eAAgB,SAAQ,wBAAQ;IAI3C,YAAmB,MAA6B;QAC9C,KAAK,CAAC,MAAM,CAAC,CAAC;QACd,IAAI,CAAC,SAAS,GAAG,IAAI,yBAAW,CAAC,MAAM,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QACxD,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAC9B,CAAC;IAED,IAAoB,QAAQ;QAC1B,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAED,IAAoB,IAAI;QACtB,OAAO,IAAI,CAAC;IACd,CAAC;IAED,IAAoB,QAAQ;QAC1B,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAoB,iBAAiB;QACnC,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED,gEAAgE;IAChD,YAAY,CAAC,IAAkB;QAC7C,MAAM,QAAQ,GAAkB,EAAE,CAAC;QACnC,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC1C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAEe,IAAI,CAAC,IAAkB;QACrC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACrC,KAAK,MAAM,IAAI,IAAI,KAAK;YACtB,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC;QAE1B,IAAI,CAAC,YAAY,EAAE,CAAC;IACtB,CAAC;IAEe,KAAK;QACnB,MAAM,SAAS,GAAG,0BAAW,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC;QAC/D,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IACjC,CAAC;CACF;AA7CD,0CA6CC","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 { BeTimePoint } from \"@itwin/core-bentley\";\r\nimport { RenderMode, ViewFlagOverrides } from \"@itwin/core-common\";\r\nimport {\r\n Tile, TileDrawArgs, TileTree, TileTreeParams,\r\n} from \"@itwin/core-frontend\";\r\nimport { BatchedTile, BatchedTileParams } from \"./BatchedTile\";\r\nimport { BatchedTilesetReader } from \"./BatchedTilesetReader\";\r\n\r\n/** @internal */\r\nexport interface BatchedTileTreeParams extends TileTreeParams {\r\n rootTile: BatchedTileParams;\r\n reader: BatchedTilesetReader;\r\n}\r\n\r\nconst viewFlagOverrides: ViewFlagOverrides = {\r\n renderMode: RenderMode.SmoothShade,\r\n visibleEdges: false,\r\n};\r\n\r\n/** @internal */\r\nexport class BatchedTileTree extends TileTree {\r\n private readonly _rootTile: BatchedTile;\r\n public readonly reader: BatchedTilesetReader;\r\n\r\n public constructor(params: BatchedTileTreeParams) {\r\n super(params);\r\n this._rootTile = new BatchedTile(params.rootTile, this);\r\n this.reader = params.reader;\r\n }\r\n\r\n public override get rootTile(): BatchedTile {\r\n return this._rootTile;\r\n }\r\n\r\n public override get is3d(): boolean {\r\n return true;\r\n }\r\n\r\n public override get maxDepth(): number | undefined {\r\n return undefined;\r\n }\r\n\r\n public override get viewFlagOverrides(): ViewFlagOverrides {\r\n return viewFlagOverrides;\r\n }\r\n\r\n // eslint-disable-next-line @typescript-eslint/naming-convention\r\n public override _selectTiles(args: TileDrawArgs): Tile[] {\r\n const selected: BatchedTile[] = [];\r\n this.rootTile.selectTiles(selected, args);\r\n return selected;\r\n }\r\n\r\n public override draw(args: TileDrawArgs): void {\r\n const tiles = this.selectTiles(args);\r\n for (const tile of tiles)\r\n tile.drawGraphics(args);\r\n\r\n args.drawGraphics();\r\n }\r\n\r\n public override prune(): void {\r\n const olderThan = BeTimePoint.now().minus(this.expirationTime);\r\n this.rootTile.prune(olderThan);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,4 @@
1
+ import { IModelConnection, TileTreeReference } from "@itwin/core-frontend";
2
+ /** @internal */
3
+ export declare function createBatchedTileTreeReference(iModel: IModelConnection, baseUrl: URL): TileTreeReference;
4
+ //# sourceMappingURL=BatchedTileTreeReference.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTreeReference.d.ts","sourceRoot":"","sources":["../../src/BatchedTileTreeReference.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,gBAAgB,EAAiB,iBAAiB,EACnD,MAAM,sBAAsB,CAAC;AAgB9B,gBAAgB;AAChB,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,GAAG,iBAAiB,CAGxG"}
@@ -0,0 +1,25 @@
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.createBatchedTileTreeReference = void 0;
8
+ const core_frontend_1 = require("@itwin/core-frontend");
9
+ const BatchedTileTreeSupplier_1 = require("./BatchedTileTreeSupplier");
10
+ class BatchedTileTreeReference extends core_frontend_1.TileTreeReference {
11
+ constructor(treeOwner) {
12
+ super();
13
+ this._treeOwner = treeOwner;
14
+ }
15
+ get treeOwner() {
16
+ return this._treeOwner;
17
+ }
18
+ }
19
+ /** @internal */
20
+ function createBatchedTileTreeReference(iModel, baseUrl) {
21
+ const owner = (0, BatchedTileTreeSupplier_1.getBatchedTileTreeOwner)(iModel, baseUrl);
22
+ return new BatchedTileTreeReference(owner);
23
+ }
24
+ exports.createBatchedTileTreeReference = createBatchedTileTreeReference;
25
+ //# sourceMappingURL=BatchedTileTreeReference.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTreeReference.js","sourceRoot":"","sources":["../../src/BatchedTileTreeReference.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,wDAE8B;AAC9B,uEAAoE;AAEpE,MAAM,wBAAyB,SAAQ,iCAAiB;IAGtD,YAAmB,SAAwB;QACzC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,IAAoB,SAAS;QAC3B,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF;AAED,gBAAgB;AAChB,SAAgB,8BAA8B,CAAC,MAAwB,EAAE,OAAY;IACnF,MAAM,KAAK,GAAG,IAAA,iDAAuB,EAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACvD,OAAO,IAAI,wBAAwB,CAAC,KAAK,CAAC,CAAC;AAC7C,CAAC;AAHD,wEAGC","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 {\r\n IModelConnection, TileTreeOwner, TileTreeReference,\r\n} from \"@itwin/core-frontend\";\r\nimport { getBatchedTileTreeOwner } from \"./BatchedTileTreeSupplier\";\r\n\r\nclass BatchedTileTreeReference extends TileTreeReference {\r\n private readonly _treeOwner: TileTreeOwner;\r\n\r\n public constructor(treeOwner: TileTreeOwner) {\r\n super();\r\n this._treeOwner = treeOwner;\r\n }\r\n\r\n public override get treeOwner(): TileTreeOwner {\r\n return this._treeOwner;\r\n }\r\n}\r\n\r\n/** @internal */\r\nexport function createBatchedTileTreeReference(iModel: IModelConnection, baseUrl: URL): TileTreeReference {\r\n const owner = getBatchedTileTreeOwner(iModel, baseUrl);\r\n return new BatchedTileTreeReference(owner);\r\n}\r\n"]}
@@ -0,0 +1,6 @@
1
+ import { IModelConnection, TileTreeOwner } from "@itwin/core-frontend";
2
+ /** @internal */
3
+ export declare type TreeId = URL;
4
+ /** @internal */
5
+ export declare function getBatchedTileTreeOwner(iModel: IModelConnection, baseUrl: URL): TileTreeOwner;
6
+ //# sourceMappingURL=BatchedTileTreeSupplier.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTreeSupplier.d.ts","sourceRoot":"","sources":["../../src/BatchedTileTreeSupplier.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,gBAAgB,EAAY,aAAa,EAC1C,MAAM,sBAAsB,CAAC;AAK9B,gBAAgB;AAChB,oBAAY,MAAM,GAAG,GAAG,CAAC;AA2BzB,gBAAgB;AAChB,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG,GAAG,aAAa,CAE7F"}
@@ -0,0 +1,39 @@
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.getBatchedTileTreeOwner = void 0;
8
+ const core_bentley_1 = require("@itwin/core-bentley");
9
+ const LoggerCategory_1 = require("./LoggerCategory");
10
+ const BatchedTilesetReader_1 = require("./BatchedTilesetReader");
11
+ const BatchedTileTree_1 = require("./BatchedTileTree");
12
+ class BatchedTileTreeSupplier {
13
+ compareTileTreeIds(lhs, rhs) {
14
+ // Currently each iModel has exactly 1 unique tile tree for all spatial models.
15
+ return (0, core_bentley_1.compareStrings)(lhs.toString(), rhs.toString());
16
+ }
17
+ async createTileTree(baseUrl, iModel) {
18
+ const url = new URL("tileset.json", baseUrl);
19
+ url.search = baseUrl.search;
20
+ try {
21
+ const response = await fetch(url.toString());
22
+ const json = await response.json();
23
+ const reader = new BatchedTilesetReader_1.BatchedTilesetReader(json, iModel, baseUrl);
24
+ const params = await reader.readTileTreeParams();
25
+ return new BatchedTileTree_1.BatchedTileTree(params);
26
+ }
27
+ catch (err) {
28
+ core_bentley_1.Logger.logException(LoggerCategory_1.loggerCategory, err);
29
+ return undefined;
30
+ }
31
+ }
32
+ }
33
+ const batchedTileTreeSupplier = new BatchedTileTreeSupplier();
34
+ /** @internal */
35
+ function getBatchedTileTreeOwner(iModel, baseUrl) {
36
+ return iModel.tiles.getTileTreeOwner(baseUrl, batchedTileTreeSupplier);
37
+ }
38
+ exports.getBatchedTileTreeOwner = getBatchedTileTreeOwner;
39
+ //# sourceMappingURL=BatchedTileTreeSupplier.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTileTreeSupplier.js","sourceRoot":"","sources":["../../src/BatchedTileTreeSupplier.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,sDAA6D;AAI7D,qDAAkD;AAClD,iEAA8D;AAC9D,uDAAoD;AAKpD,MAAM,uBAAuB;IACpB,kBAAkB,CAAC,GAAW,EAAE,GAAW;QAChD,+EAA+E;QAC/E,OAAO,IAAA,6BAAc,EAAC,GAAG,CAAC,QAAQ,EAAE,EAAE,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;IACxD,CAAC;IAEM,KAAK,CAAC,cAAc,CAAC,OAAe,EAAE,MAAwB;QACnE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAC7C,GAAG,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC5B,IAAI;YACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC,CAAC;YAC7C,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;YAEnC,MAAM,MAAM,GAAG,IAAI,2CAAoB,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;YAC/D,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,kBAAkB,EAAE,CAAC;YACjD,OAAO,IAAI,iCAAe,CAAC,MAAM,CAAC,CAAC;SACpC;QAAC,OAAO,GAAG,EAAE;YACZ,qBAAM,CAAC,YAAY,CAAC,+BAAc,EAAE,GAAG,CAAC,CAAC;YACzC,OAAO,SAAS,CAAC;SAClB;IACH,CAAC;CACF;AAED,MAAM,uBAAuB,GAAqB,IAAI,uBAAuB,EAAE,CAAC;AAEhF,gBAAgB;AAChB,SAAgB,uBAAuB,CAAC,MAAwB,EAAE,OAAY;IAC5E,OAAO,MAAM,CAAC,KAAK,CAAC,gBAAgB,CAAC,OAAO,EAAE,uBAAuB,CAAC,CAAC;AACzE,CAAC;AAFD,0DAEC","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 { compareStrings, Logger } from \"@itwin/core-bentley\";\r\nimport {\r\n IModelConnection, TileTree, TileTreeOwner, TileTreeSupplier,\r\n} from \"@itwin/core-frontend\";\r\nimport { loggerCategory } from \"./LoggerCategory\";\r\nimport { BatchedTilesetReader } from \"./BatchedTilesetReader\";\r\nimport { BatchedTileTree } from \"./BatchedTileTree\";\r\n\r\n/** @internal */\r\nexport type TreeId = URL;\r\n\r\nclass BatchedTileTreeSupplier implements TileTreeSupplier {\r\n public compareTileTreeIds(lhs: TreeId, rhs: TreeId): number {\r\n // Currently each iModel has exactly 1 unique tile tree for all spatial models.\r\n return compareStrings(lhs.toString(), rhs.toString());\r\n }\r\n\r\n public async createTileTree(baseUrl: TreeId, iModel: IModelConnection): Promise<TileTree | undefined> {\r\n const url = new URL(\"tileset.json\", baseUrl);\r\n url.search = baseUrl.search;\r\n try {\r\n const response = await fetch(url.toString());\r\n const json = await response.json();\r\n\r\n const reader = new BatchedTilesetReader(json, iModel, baseUrl);\r\n const params = await reader.readTileTreeParams();\r\n return new BatchedTileTree(params);\r\n } catch (err) {\r\n Logger.logException(loggerCategory, err);\r\n return undefined;\r\n }\r\n }\r\n}\r\n\r\nconst batchedTileTreeSupplier: TileTreeSupplier = new BatchedTileTreeSupplier();\r\n\r\n/** @internal */\r\nexport function getBatchedTileTreeOwner(iModel: IModelConnection, baseUrl: URL): TileTreeOwner {\r\n return iModel.tiles.getTileTreeOwner(baseUrl, batchedTileTreeSupplier);\r\n}\r\n"]}
@@ -0,0 +1,14 @@
1
+ import { Tileset3dSchema as schema } from "@itwin/core-common";
2
+ import { IModelConnection } from "@itwin/core-frontend";
3
+ import { BatchedTileTreeParams } from "./BatchedTileTree";
4
+ import { BatchedTile, BatchedTileParams } from "./BatchedTile";
5
+ /** @internal */
6
+ export declare class BatchedTilesetReader {
7
+ private readonly _iModel;
8
+ private readonly _tileset;
9
+ readonly baseUrl: URL;
10
+ constructor(json: unknown, iModel: IModelConnection, baseUrl: URL);
11
+ readTileParams(json: schema.Tile, parent?: BatchedTile): BatchedTileParams;
12
+ readTileTreeParams(): Promise<BatchedTileTreeParams>;
13
+ }
14
+ //# sourceMappingURL=BatchedTilesetReader.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTilesetReader.d.ts","sourceRoot":"","sources":["../../src/BatchedTilesetReader.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,IAAI,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,gBAAgB,EAA2C,MAAM,sBAAsB,CAAC;AACjG,OAAO,EAAE,qBAAqB,EAAE,MAAM,mBAAmB,CAAC;AAC1D,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAqD/D,gBAAgB;AAChB,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAmB;IAC3C,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAiB;IAC1C,SAAgB,OAAO,EAAE,GAAG,CAAC;gBAEV,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,OAAO,EAAE,GAAG;IASjE,cAAc,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,iBAAiB;IAmBpE,kBAAkB,IAAI,OAAO,CAAC,qBAAqB,CAAC;CAgBlE"}
@@ -0,0 +1,90 @@
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.BatchedTilesetReader = void 0;
8
+ const core_geometry_1 = require("@itwin/core-geometry");
9
+ const core_frontend_1 = require("@itwin/core-frontend");
10
+ function isTileset3d(json) {
11
+ if (typeof json !== "object")
12
+ return false;
13
+ const props = json;
14
+ if (!props.root || !props.asset)
15
+ return false;
16
+ // ###TODO spec requires geometricError to be present on tileset and all tiles; exporter is omitting from tileset.
17
+ if (undefined === props.geometricError)
18
+ props.geometricError = props.root.geometricError;
19
+ return true;
20
+ }
21
+ function rangeFromBoundingVolume(vol) {
22
+ if (vol.box) {
23
+ const center = new core_geometry_1.Point3d(vol.box[0], vol.box[1], vol.box[2]);
24
+ const ux = new core_geometry_1.Vector3d(vol.box[3], vol.box[4], vol.box[5]);
25
+ const uy = new core_geometry_1.Vector3d(vol.box[6], vol.box[7], vol.box[8]);
26
+ const uz = new core_geometry_1.Vector3d(vol.box[9], vol.box[10], vol.box[11]);
27
+ const range = core_geometry_1.Range3d.createNull();
28
+ for (let i = -1; i <= 1; i += 2)
29
+ for (let j = -1; j <= 1; j += 2)
30
+ for (let k = -1; k <= 1; k += 2)
31
+ range.extendPoint(center.plus3Scaled(ux, i, uy, j, uz, k));
32
+ return range;
33
+ }
34
+ else if (vol.sphere) {
35
+ const center = new core_geometry_1.Point3d(vol.sphere[0], vol.sphere[1], vol.sphere[2]);
36
+ const radius = vol.sphere[3];
37
+ return core_geometry_1.Range3d.createXYZXYZ(center.x - radius, center.y - radius, center.z - radius, center.x + radius, center.y + radius, center.z + radius);
38
+ }
39
+ // We won't get region bounding volumes in our tiles.
40
+ throw new Error("region bounding volume unimplemented");
41
+ }
42
+ function transformFromJSON(json) {
43
+ const translation = new core_geometry_1.Point3d(json[12], json[13], json[14]);
44
+ const matrix = core_geometry_1.Matrix3d.createRowValues(json[0], json[4], json[8], json[1], json[5], json[9], json[2], json[6], json[10]);
45
+ return core_geometry_1.Transform.createOriginAndMatrix(translation, matrix);
46
+ }
47
+ /** @internal */
48
+ class BatchedTilesetReader {
49
+ constructor(json, iModel, baseUrl) {
50
+ if (!isTileset3d(json))
51
+ throw new Error("Invalid tileset JSON");
52
+ this._iModel = iModel;
53
+ this._tileset = json;
54
+ this.baseUrl = baseUrl;
55
+ }
56
+ readTileParams(json, parent) {
57
+ const content = json.content;
58
+ const geometricError = json.geometricError;
59
+ const range = rangeFromBoundingVolume(json.boundingVolume);
60
+ const isLeaf = undefined === json.children || json.children.length === 0;
61
+ // ###TODO evaluate this. The geometric errors in the tiles seem far too small.
62
+ const maximumSizeScale = 8;
63
+ return {
64
+ parent,
65
+ contentId: content?.uri ?? "",
66
+ range,
67
+ contentRange: content?.boundingVolume ? rangeFromBoundingVolume(content.boundingVolume) : undefined,
68
+ isLeaf,
69
+ maximumSize: maximumSizeScale * core_frontend_1.RealityModelTileUtils.maximumSizeFromGeometricTolerance(range, geometricError),
70
+ childrenProps: isLeaf ? undefined : json.children,
71
+ };
72
+ }
73
+ async readTileTreeParams() {
74
+ const root = this._tileset.root;
75
+ const location = root.transform ? transformFromJSON(root.transform) : core_geometry_1.Transform.createIdentity();
76
+ // y axis is up in glTF. we want z up.
77
+ location.multiplyTransformMatrix3d(core_geometry_1.Matrix3d.createRotationAroundVector(core_geometry_1.Vector3d.create(1, 0, 0), core_geometry_1.Angle.createRadians(core_geometry_1.Angle.piOver2Radians)), location);
78
+ return {
79
+ id: "spatial-models",
80
+ modelId: this._iModel.transientIds.getNext(),
81
+ iModel: this._iModel,
82
+ location,
83
+ priority: core_frontend_1.TileLoadPriority.Primary,
84
+ rootTile: this.readTileParams(root),
85
+ reader: this,
86
+ };
87
+ }
88
+ }
89
+ exports.BatchedTilesetReader = BatchedTilesetReader;
90
+ //# sourceMappingURL=BatchedTilesetReader.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BatchedTilesetReader.js","sourceRoot":"","sources":["../../src/BatchedTilesetReader.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;;;AAE/F,wDAE8B;AAE9B,wDAAiG;AAIjG,SAAS,WAAW,CAAC,IAAa;IAChC,IAAI,OAAO,IAAI,KAAK,QAAQ;QAC1B,OAAO,KAAK,CAAC;IAEf,MAAM,KAA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B,CAAC,iCAAiC,CAAC,KAAK,EAAE,cAAc,CAAC;YAC9G,aAAa,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ;SAClD,CAAC;IACJ,CAAC;IAEM,KAAK,CAAC,kBAAkB;QAC7B,MAAM,IAAI,GAAG,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,yBAAS,CAAC,cAAc,EAAE,CAAC;QACjG,sCAAsC;QACtC,QAAQ,CAAC,yBAAyB,CAAC,wBAAQ,CAAC,0BAA0B,CAAC,wBAAQ,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAAE,qBAAK,CAAC,aAAa,CAAC,qBAAK,CAAC,cAAc,CAAC,CAAE,EAAE,QAAQ,CAAC,CAAC;QAExJ,OAAO;YACL,EAAE,EAAE,gBAAgB;YACpB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,OAAO,EAAE;YAC5C,MAAM,EAAE,IAAI,CAAC,OAAO;YACpB,QAAQ;YACR,QAAQ,EAAE,gCAAgB,CAAC,OAAO;YAClC,QAAQ,EAAE,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC;YACnC,MAAM,EAAE,IAAI;SACb,CAAC;IACJ,CAAC;CACF;AAjDD,oDAiDC","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 {\r\n Angle, Matrix3d, Point3d, Range3d, Transform, Vector3d,\r\n} from \"@itwin/core-geometry\";\r\nimport { Tileset3dSchema as schema } from \"@itwin/core-common\";\r\nimport { IModelConnection, RealityModelTileUtils, TileLoadPriority } from \"@itwin/core-frontend\";\r\nimport { BatchedTileTreeParams } from \"./BatchedTileTree\";\r\nimport { BatchedTile, BatchedTileParams } from \"./BatchedTile\";\r\n\r\nfunction isTileset3d(json: unknown): json is schema.Tileset {\r\n if (typeof json !== \"object\")\r\n return false;\r\n\r\n const props = json as schema.Tileset;\r\n\r\n if (!props.root || !props.asset)\r\n return false;\r\n\r\n // ###TODO spec requires geometricError to be present on tileset and all tiles; exporter is omitting from tileset.\r\n if (undefined === props.geometricError)\r\n props.geometricError = props.root.geometricError;\r\n\r\n return true;\r\n}\r\n\r\nfunction rangeFromBoundingVolume(vol: schema.BoundingVolume): Range3d {\r\n if (vol.box) {\r\n const center = new Point3d(vol.box[0], vol.box[1], vol.box[2]);\r\n const ux = new Vector3d(vol.box[3], vol.box[4], vol.box[5]);\r\n const uy = new Vector3d(vol.box[6], vol.box[7], vol.box[8]);\r\n const uz = new Vector3d(vol.box[9], vol.box[10], vol.box[11]);\r\n\r\n const range = Range3d.createNull();\r\n for (let i = -1; i <= 1; i += 2)\r\n for (let j = -1; j <= 1; j += 2)\r\n for (let k = -1; k <= 1; k += 2)\r\n range.extendPoint(center.plus3Scaled(ux, i, uy, j, uz, k));\r\n\r\n return range;\r\n } else if (vol.sphere) {\r\n const center = new Point3d(vol.sphere[0], vol.sphere[1], vol.sphere[2]);\r\n const radius = vol.sphere[3];\r\n return Range3d.createXYZXYZ(center.x - radius, center.y - radius, center.z - radius, center.x + radius, center.y + radius, center.z + radius);\r\n }\r\n\r\n // We won't get region bounding volumes in our tiles.\r\n throw new Error(\"region bounding volume unimplemented\");\r\n}\r\n\r\nfunction transformFromJSON(json: schema.Transform): Transform {\r\n const translation = new Point3d(json[12], json[13], json[14]);\r\n const matrix = Matrix3d.createRowValues(\r\n json[0], json[4], json[8],\r\n json[1], json[5], json[9],\r\n json[2], json[6], json[10]\r\n );\r\n\r\n return Transform.createOriginAndMatrix(translation, matrix);\r\n}\r\n\r\n/** @internal */\r\nexport class BatchedTilesetReader {\r\n private readonly _iModel: IModelConnection;\r\n private readonly _tileset: schema.Tileset;\r\n public readonly baseUrl: URL;\r\n\r\n public constructor(json: unknown, iModel: IModelConnection, baseUrl: URL) {\r\n if (!isTileset3d(json))\r\n throw new Error(\"Invalid tileset JSON\");\r\n\r\n this._iModel = iModel;\r\n this._tileset = json;\r\n this.baseUrl = baseUrl;\r\n }\r\n\r\n public readTileParams(json: schema.Tile, parent?: BatchedTile): BatchedTileParams {\r\n const content = json.content;\r\n const geometricError = json.geometricError;\r\n const range = rangeFromBoundingVolume(json.boundingVolume);\r\n const isLeaf = undefined === json.children || json.children.length === 0;\r\n\r\n // ###TODO evaluate this. The geometric errors in the tiles seem far too small.\r\n const maximumSizeScale = 8;\r\n return {\r\n parent,\r\n contentId: content?.uri ?? \"\",\r\n range,\r\n contentRange: content?.boundingVolume ? rangeFromBoundingVolume(content.boundingVolume) : undefined,\r\n isLeaf,\r\n maximumSize: maximumSizeScale * RealityModelTileUtils.maximumSizeFromGeometricTolerance(range, geometricError),\r\n childrenProps: isLeaf ? undefined : json.children,\r\n };\r\n }\r\n\r\n public async readTileTreeParams(): Promise<BatchedTileTreeParams> {\r\n const root = this._tileset.root;\r\n const location = root.transform ? transformFromJSON(root.transform) : Transform.createIdentity();\r\n // y axis is up in glTF. we want z up.\r\n location.multiplyTransformMatrix3d(Matrix3d.createRotationAroundVector(Vector3d.create(1, 0, 0), Angle.createRadians(Angle.piOver2Radians))!, location);\r\n\r\n return {\r\n id: \"spatial-models\",\r\n modelId: this._iModel.transientIds.getNext(),\r\n iModel: this._iModel,\r\n location,\r\n priority: TileLoadPriority.Primary,\r\n rootTile: this.readTileParams(root),\r\n reader: this,\r\n };\r\n }\r\n}\r\n"]}