@itwin/core-frontend 4.1.0-dev.6 → 4.1.0-dev.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/lib/cjs/BriefcaseTxns.d.ts +2 -2
  2. package/lib/cjs/BriefcaseTxns.d.ts.map +1 -1
  3. package/lib/cjs/BriefcaseTxns.js +3 -3
  4. package/lib/cjs/BriefcaseTxns.js.map +1 -1
  5. package/lib/cjs/GraphicalEditingScope.d.ts +2 -2
  6. package/lib/cjs/GraphicalEditingScope.d.ts.map +1 -1
  7. package/lib/cjs/GraphicalEditingScope.js +1 -1
  8. package/lib/cjs/GraphicalEditingScope.js.map +1 -1
  9. package/lib/cjs/IpcApp.d.ts.map +1 -1
  10. package/lib/cjs/IpcApp.js +3 -3
  11. package/lib/cjs/IpcApp.js.map +1 -1
  12. package/lib/cjs/LocalhostIpcApp.js +1 -1
  13. package/lib/cjs/LocalhostIpcApp.js.map +1 -1
  14. package/lib/cjs/NativeApp.d.ts.map +1 -1
  15. package/lib/cjs/NativeApp.js +3 -3
  16. package/lib/cjs/NativeApp.js.map +1 -1
  17. package/lib/cjs/core-frontend.d.ts +3 -0
  18. package/lib/cjs/core-frontend.d.ts.map +1 -1
  19. package/lib/cjs/core-frontend.js +3 -0
  20. package/lib/cjs/core-frontend.js.map +1 -1
  21. package/lib/cjs/imdl/ImdlGraphicsCreator.d.ts +19 -0
  22. package/lib/cjs/imdl/ImdlGraphicsCreator.d.ts.map +1 -0
  23. package/lib/cjs/imdl/ImdlGraphicsCreator.js +328 -0
  24. package/lib/cjs/imdl/ImdlGraphicsCreator.js.map +1 -0
  25. package/lib/cjs/imdl/ImdlModel.d.ts +181 -0
  26. package/lib/cjs/imdl/ImdlModel.d.ts.map +1 -0
  27. package/lib/cjs/imdl/ImdlModel.js +10 -0
  28. package/lib/cjs/imdl/ImdlModel.js.map +1 -0
  29. package/lib/cjs/imdl/ImdlParser.d.ts +40 -0
  30. package/lib/cjs/imdl/ImdlParser.d.ts.map +1 -0
  31. package/lib/cjs/imdl/ImdlParser.js +996 -0
  32. package/lib/cjs/imdl/ImdlParser.js.map +1 -0
  33. package/lib/cjs/imdl/ImdlSchema.d.ts +380 -0
  34. package/lib/cjs/imdl/ImdlSchema.d.ts.map +1 -0
  35. package/lib/cjs/imdl/ImdlSchema.js +10 -0
  36. package/lib/cjs/imdl/ImdlSchema.js.map +1 -0
  37. package/lib/cjs/render/primitives/AuxChannelTable.d.ts +4 -0
  38. package/lib/cjs/render/primitives/AuxChannelTable.d.ts.map +1 -1
  39. package/lib/cjs/render/primitives/AuxChannelTable.js +33 -0
  40. package/lib/cjs/render/primitives/AuxChannelTable.js.map +1 -1
  41. package/lib/cjs/render/primitives/VertexTable.d.ts +3 -3
  42. package/lib/cjs/render/primitives/VertexTable.d.ts.map +1 -1
  43. package/lib/cjs/render/primitives/VertexTable.js.map +1 -1
  44. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts +5 -1
  45. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts.map +1 -1
  46. package/lib/cjs/render/primitives/VertexTableSplitter.js +13 -12
  47. package/lib/cjs/render/primitives/VertexTableSplitter.js.map +1 -1
  48. package/lib/cjs/tile/IModelTile.d.ts.map +1 -1
  49. package/lib/cjs/tile/IModelTile.js +14 -15
  50. package/lib/cjs/tile/IModelTile.js.map +1 -1
  51. package/lib/cjs/tile/ImdlReader.d.ts +11 -420
  52. package/lib/cjs/tile/ImdlReader.d.ts.map +1 -1
  53. package/lib/cjs/tile/ImdlReader.js +64 -902
  54. package/lib/cjs/tile/ImdlReader.js.map +1 -1
  55. package/lib/cjs/tile/map/MapTile.d.ts +6 -1
  56. package/lib/cjs/tile/map/MapTile.d.ts.map +1 -1
  57. package/lib/cjs/tile/map/MapTile.js +8 -7
  58. package/lib/cjs/tile/map/MapTile.js.map +1 -1
  59. package/lib/cjs/tile/map/MapTileTree.d.ts.map +1 -1
  60. package/lib/cjs/tile/map/MapTileTree.js +8 -2
  61. package/lib/cjs/tile/map/MapTileTree.js.map +1 -1
  62. package/lib/esm/BriefcaseTxns.d.ts +2 -2
  63. package/lib/esm/BriefcaseTxns.d.ts.map +1 -1
  64. package/lib/esm/BriefcaseTxns.js +3 -3
  65. package/lib/esm/BriefcaseTxns.js.map +1 -1
  66. package/lib/esm/GraphicalEditingScope.d.ts +2 -2
  67. package/lib/esm/GraphicalEditingScope.d.ts.map +1 -1
  68. package/lib/esm/GraphicalEditingScope.js +2 -2
  69. package/lib/esm/GraphicalEditingScope.js.map +1 -1
  70. package/lib/esm/IpcApp.d.ts.map +1 -1
  71. package/lib/esm/IpcApp.js +4 -4
  72. package/lib/esm/IpcApp.js.map +1 -1
  73. package/lib/esm/LocalhostIpcApp.js +2 -2
  74. package/lib/esm/LocalhostIpcApp.js.map +1 -1
  75. package/lib/esm/NativeApp.d.ts.map +1 -1
  76. package/lib/esm/NativeApp.js +4 -4
  77. package/lib/esm/NativeApp.js.map +1 -1
  78. package/lib/esm/core-frontend.d.ts +3 -0
  79. package/lib/esm/core-frontend.d.ts.map +1 -1
  80. package/lib/esm/core-frontend.js +3 -0
  81. package/lib/esm/core-frontend.js.map +1 -1
  82. package/lib/esm/imdl/ImdlGraphicsCreator.d.ts +19 -0
  83. package/lib/esm/imdl/ImdlGraphicsCreator.d.ts.map +1 -0
  84. package/lib/esm/imdl/ImdlGraphicsCreator.js +324 -0
  85. package/lib/esm/imdl/ImdlGraphicsCreator.js.map +1 -0
  86. package/lib/esm/imdl/ImdlModel.d.ts +181 -0
  87. package/lib/esm/imdl/ImdlModel.d.ts.map +1 -0
  88. package/lib/esm/imdl/ImdlModel.js +9 -0
  89. package/lib/esm/imdl/ImdlModel.js.map +1 -0
  90. package/lib/esm/imdl/ImdlParser.d.ts +40 -0
  91. package/lib/esm/imdl/ImdlParser.d.ts.map +1 -0
  92. package/lib/esm/imdl/ImdlParser.js +988 -0
  93. package/lib/esm/imdl/ImdlParser.js.map +1 -0
  94. package/lib/esm/imdl/ImdlSchema.d.ts +380 -0
  95. package/lib/esm/imdl/ImdlSchema.d.ts.map +1 -0
  96. package/lib/esm/imdl/ImdlSchema.js +9 -0
  97. package/lib/esm/imdl/ImdlSchema.js.map +1 -0
  98. package/lib/esm/render/primitives/AuxChannelTable.d.ts +4 -0
  99. package/lib/esm/render/primitives/AuxChannelTable.d.ts.map +1 -1
  100. package/lib/esm/render/primitives/AuxChannelTable.js +33 -0
  101. package/lib/esm/render/primitives/AuxChannelTable.js.map +1 -1
  102. package/lib/esm/render/primitives/VertexTable.d.ts +3 -3
  103. package/lib/esm/render/primitives/VertexTable.d.ts.map +1 -1
  104. package/lib/esm/render/primitives/VertexTable.js.map +1 -1
  105. package/lib/esm/render/primitives/VertexTableSplitter.d.ts +5 -1
  106. package/lib/esm/render/primitives/VertexTableSplitter.d.ts.map +1 -1
  107. package/lib/esm/render/primitives/VertexTableSplitter.js +13 -12
  108. package/lib/esm/render/primitives/VertexTableSplitter.js.map +1 -1
  109. package/lib/esm/tile/IModelTile.d.ts.map +1 -1
  110. package/lib/esm/tile/IModelTile.js +14 -15
  111. package/lib/esm/tile/IModelTile.js.map +1 -1
  112. package/lib/esm/tile/ImdlReader.d.ts +11 -420
  113. package/lib/esm/tile/ImdlReader.d.ts.map +1 -1
  114. package/lib/esm/tile/ImdlReader.js +67 -903
  115. package/lib/esm/tile/ImdlReader.js.map +1 -1
  116. package/lib/esm/tile/map/MapTile.d.ts +6 -1
  117. package/lib/esm/tile/map/MapTile.d.ts.map +1 -1
  118. package/lib/esm/tile/map/MapTile.js +8 -7
  119. package/lib/esm/tile/map/MapTile.js.map +1 -1
  120. package/lib/esm/tile/map/MapTileTree.d.ts.map +1 -1
  121. package/lib/esm/tile/map/MapTileTree.js +8 -2
  122. package/lib/esm/tile/map/MapTileTree.js.map +1 -1
  123. package/package.json +18 -18
@@ -7,64 +7,14 @@
7
7
  * @module Tiles
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.ImdlReader = exports.readElementGraphics = exports.GltfHeader = void 0;
10
+ exports.ImdlReader = exports.readElementGraphics = void 0;
11
11
  const core_bentley_1 = require("@itwin/core-bentley");
12
12
  const core_geometry_1 = require("@itwin/core-geometry");
13
13
  const core_common_1 = require("@itwin/core-common");
14
14
  const IModelApp_1 = require("../IModelApp");
15
15
  const GraphicBranch_1 = require("../render/GraphicBranch");
16
- const AuxChannelTable_1 = require("../render/primitives/AuxChannelTable");
17
- const DisplayParams_1 = require("../render/primitives/DisplayParams");
18
- const MeshPrimitives_1 = require("../render/primitives/mesh/MeshPrimitives");
19
- const SurfaceParams_1 = require("../render/primitives/SurfaceParams");
20
- const VertexTable_1 = require("../render/primitives/VertexTable");
21
- const VertexTableSplitter_1 = require("../render/primitives/VertexTableSplitter");
22
- const PointStringParams_1 = require("../render/primitives/PointStringParams");
23
- const PolylineParams_1 = require("../render/primitives/PolylineParams");
24
- /** Header preceding "glTF" data in iMdl tile.
25
- * @internal
26
- */
27
- class GltfHeader extends core_common_1.TileHeader {
28
- get isValid() { return core_common_1.TileFormat.Gltf === this.format; }
29
- constructor(stream) {
30
- super(stream);
31
- this.scenePosition = 0;
32
- this.sceneStrLength = 0;
33
- this.binaryPosition = 0;
34
- this.gltfLength = stream.readUint32();
35
- this.sceneStrLength = stream.readUint32();
36
- const value5 = stream.readUint32();
37
- // Early versions of the reality data tile publisher incorrectly put version 2 into header - handle these old tiles
38
- // validating the chunk type.
39
- if (this.version === core_common_1.GltfVersions.Version2 && value5 === core_common_1.GltfVersions.Gltf1SceneFormat)
40
- this.version = core_common_1.GltfVersions.Version1;
41
- if (this.version === core_common_1.GltfVersions.Version1) {
42
- const gltfSceneFormat = value5;
43
- if (core_common_1.GltfVersions.Gltf1SceneFormat !== gltfSceneFormat) {
44
- this.invalidate();
45
- return;
46
- }
47
- this.scenePosition = stream.curPos;
48
- this.binaryPosition = stream.curPos + this.sceneStrLength;
49
- }
50
- else if (this.version === core_common_1.GltfVersions.Version2) {
51
- const sceneChunkType = value5;
52
- this.scenePosition = stream.curPos;
53
- stream.curPos = stream.curPos + this.sceneStrLength;
54
- const binaryLength = stream.readUint32();
55
- const binaryChunkType = stream.readUint32();
56
- if (core_common_1.GltfV2ChunkTypes.JSON !== sceneChunkType || core_common_1.GltfV2ChunkTypes.Binary !== binaryChunkType || 0 === binaryLength) {
57
- this.invalidate();
58
- return;
59
- }
60
- this.binaryPosition = stream.curPos;
61
- }
62
- else {
63
- this.invalidate();
64
- }
65
- }
66
- }
67
- exports.GltfHeader = GltfHeader;
16
+ const ImdlParser_1 = require("../imdl/ImdlParser");
17
+ const ImdlGraphicsCreator_1 = require("../imdl/ImdlGraphicsCreator");
68
18
  /** Convert the byte array returned by [[TileAdmin.requestElementGraphics]] into a [[RenderGraphic]].
69
19
  * @param bytes The binary graphics data obtained from `requestElementGraphics`.
70
20
  * @param iModel The iModel with which the graphics are associated.
@@ -80,862 +30,74 @@ async function readElementGraphics(bytes, iModel, modelId, is3d, options) {
80
30
  stream, iModel, modelId, is3d, options,
81
31
  system: IModelApp_1.IModelApp.renderSystem,
82
32
  });
83
- if (!reader)
84
- return undefined;
85
33
  const result = await reader.read();
86
34
  return result.graphic;
87
35
  }
88
36
  exports.readElementGraphics = readElementGraphics;
89
- const nodeIdRegex = /Node_(.*)/;
90
- function extractNodeId(nodeName) {
91
- const match = nodeName.match(nodeIdRegex);
92
- (0, core_bentley_1.assert)(!!match && match.length === 2);
93
- if (!match || match.length !== 2)
94
- return 0;
95
- const nodeId = Number.parseInt(match[1], 10);
96
- (0, core_bentley_1.assert)(!Number.isNaN(nodeId));
97
- return Number.isNaN(nodeId) ? 0 : nodeId;
98
- }
99
- /** Deserializes tile content in iMdl format. These tiles contain element geometry encoded into a format optimized for the imodeljs webgl renderer.
100
- * @internal
101
- */
102
- class ImdlReader {
103
- get _isCanceled() { return undefined !== this._canceled && this._canceled(this); }
104
- get _isVolumeClassifier() { return core_common_1.BatchType.VolumeClassifier === this._type; }
105
- /** Attempt to initialize an ImdlReader to deserialize iModel tile data beginning at the stream's current position. */
106
- static create(args) {
107
- const imdlHeader = new core_common_1.ImdlHeader(args.stream);
108
- if (!imdlHeader.isValid || !imdlHeader.isReadableVersion)
109
- return undefined;
110
- // The feature table follows the iMdl header
111
- if (!this.skipFeatureTable(args.stream))
112
- return undefined;
113
- // A glTF header follows the feature table
114
- const gltfHeader = new GltfHeader(args.stream);
115
- if (!gltfHeader.isValid)
116
- return undefined;
117
- args.stream.curPos = gltfHeader.scenePosition;
118
- const sceneStrData = args.stream.nextBytes(gltfHeader.sceneStrLength);
119
- const sceneStr = (0, core_bentley_1.utf8ToString)(sceneStrData);
120
- if (!sceneStr)
121
- return undefined;
122
- try {
123
- const sceneValue = JSON.parse(sceneStr);
124
- const imdl = {
125
- scene: core_bentley_1.JsonUtils.asString(sceneValue.scene),
126
- scenes: core_bentley_1.JsonUtils.asArray(sceneValue.scenes),
127
- animationNodes: core_bentley_1.JsonUtils.asObject(sceneValue.animationNodes),
128
- bufferViews: core_bentley_1.JsonUtils.asObject(sceneValue.bufferViews),
129
- meshes: core_bentley_1.JsonUtils.asObject(sceneValue.meshes),
130
- nodes: core_bentley_1.JsonUtils.asObject(sceneValue.nodes),
131
- materials: core_bentley_1.JsonUtils.asObject(sceneValue.materials),
132
- renderMaterials: core_bentley_1.JsonUtils.asObject(sceneValue.renderMaterials),
133
- namedTextures: core_bentley_1.JsonUtils.asObject(sceneValue.namedTextures),
134
- patternSymbols: core_bentley_1.JsonUtils.asObject(sceneValue.patternSymbols),
135
- rtcCenter: core_bentley_1.JsonUtils.asArray(sceneValue.rtcCenter),
136
- };
137
- return undefined !== imdl.meshes ? new ImdlReader(imdl, gltfHeader.binaryPosition, args, 0 !== (imdlHeader.flags & core_common_1.ImdlFlags.MultiModelFeatureTable)) : undefined;
138
- }
139
- catch (_) {
140
- return undefined;
141
- }
142
- }
143
- constructor(imdl, binaryPosition, args, hasMultiModelFeatureTable) {
144
- this._patternGeometry = new Map();
145
- this._buffer = args.stream;
146
- this._binaryData = new Uint8Array(this._buffer.arrayBuffer, binaryPosition);
147
- this._hasMultiModelFeatureTable = hasMultiModelFeatureTable;
148
- this._animationNodes = core_bentley_1.JsonUtils.asObject(imdl.animationNodes);
149
- this._bufferViews = imdl.bufferViews;
150
- this._meshes = imdl.meshes;
151
- this._nodes = imdl.nodes;
152
- this._materialValues = imdl.materials ?? {};
153
- this._renderMaterials = imdl.renderMaterials ?? {};
154
- this._namedTextures = imdl.namedTextures ?? {};
155
- this._patternSymbols = imdl.patternSymbols ?? {};
156
- this._rtcCenter = imdl.rtcCenter ? core_geometry_1.Point3d.fromJSON(imdl.rtcCenter) : undefined;
157
- this._iModel = args.iModel;
158
- this._modelId = args.modelId;
159
- this._is3d = args.is3d;
160
- this._isLeaf = args.isLeaf;
161
- this._system = args.system;
162
- this._type = args.type ?? core_common_1.BatchType.Primary;
163
- this._canceled = args.isCanceled;
164
- this._sizeMultiplier = args.sizeMultiplier;
165
- this._loadEdges = args.loadEdges ?? true;
166
- this._options = args.options ?? {};
167
- this._containsTransformNodes = args.containsTransformNodes ?? false;
168
- this._timeline = args.timeline;
169
- }
170
- /** Attempt to deserialize the tile data */
171
- async read() {
172
- let content;
173
- try {
174
- content = (0, core_common_1.decodeTileContentDescription)({
175
- stream: this._buffer,
176
- sizeMultiplier: this._sizeMultiplier,
177
- is2d: !this._is3d,
178
- options: IModelApp_1.IModelApp.tileAdmin,
179
- isVolumeClassifier: this._isVolumeClassifier,
180
- isLeaf: this._isLeaf,
181
- });
182
- }
183
- catch (e) {
184
- if (e instanceof core_common_1.TileReadError)
185
- return { isLeaf: true, readStatus: e.errorNumber };
186
- else
187
- throw e;
188
- }
189
- const featureTable = this.readFeatureTable(content.featureTableStartPos);
190
- if (undefined === featureTable)
191
- return { readStatus: core_common_1.TileReadStatus.InvalidFeatureTable, isLeaf: true };
192
- // Textures must be loaded asynchronously first...
193
- await this.loadNamedTextures();
194
- if (this._isCanceled)
195
- return { readStatus: core_common_1.TileReadStatus.Canceled, isLeaf: true };
196
- return this.finishRead(content.isLeaf, featureTable, content.contentRange, content.emptySubRangeMask, content.sizeMultiplier);
197
- }
198
- /** @internal */
199
- createDisplayParams(json) {
200
- const type = core_bentley_1.JsonUtils.asInt(json.type, DisplayParams_1.DisplayParams.Type.Mesh);
201
- const lineColor = core_common_1.ColorDef.create(core_bentley_1.JsonUtils.asInt(json.lineColor));
202
- const fillColor = core_common_1.ColorDef.create(core_bentley_1.JsonUtils.asInt(json.fillColor));
203
- const width = core_bentley_1.JsonUtils.asInt(json.lineWidth);
204
- const linePixels = core_bentley_1.JsonUtils.asInt(json.linePixels, core_common_1.LinePixels.Solid);
205
- const fillFlags = core_bentley_1.JsonUtils.asInt(json.fillFlags, core_common_1.FillFlags.None);
206
- const ignoreLighting = core_bentley_1.JsonUtils.asBool(json.ignoreLighting);
207
- // Material will always contain its own texture if it has one
208
- const materialKey = json.materialId;
209
- const material = undefined !== materialKey ? this.materialFromJson(materialKey) : undefined;
210
- // We will only attempt to include the texture if material is undefined
211
- let textureMapping;
212
- if (!material) {
213
- const textureJson = json.texture;
214
- textureMapping = undefined !== textureJson ? this.textureMappingFromJson(textureJson) : undefined;
215
- if (undefined === textureMapping) {
216
- // Look for a gradient. If defined, create a texture mapping. No reason to pass the Gradient.Symb to the DisplayParams once we have the texture.
217
- const gradientProps = json.gradient;
218
- const gradient = undefined !== gradientProps ? core_common_1.Gradient.Symb.fromJSON(gradientProps) : undefined;
219
- if (undefined !== gradient) {
220
- const texture = this._system.getGradientTexture(gradient, this._iModel);
221
- if (undefined !== texture) {
222
- // ###TODO: would be better if DisplayParams created the TextureMapping - but that requires an IModelConnection and a RenderSystem...
223
- textureMapping = new core_common_1.TextureMapping(texture, new core_common_1.TextureMapping.Params({ textureMat2x3: new core_common_1.TextureMapping.Trans2x3(0, 1, 0, 1, 0, 0) }));
224
- }
225
- }
226
- }
227
- }
228
- return new DisplayParams_1.DisplayParams(type, lineColor, fillColor, width, linePixels, fillFlags, material, undefined, ignoreLighting, textureMapping);
229
- }
230
- /** @internal */
231
- colorDefFromMaterialJson(json) {
232
- return undefined !== json ? core_common_1.ColorDef.from(json[0] * 255 + 0.5, json[1] * 255 + 0.5, json[2] * 255 + 0.5) : undefined;
233
- }
234
- /** @internal */
235
- materialFromJson(key) {
236
- const material = this._system.findMaterial(key, this._iModel);
237
- if (material)
238
- return material;
239
- if (!this._renderMaterials)
240
- return undefined;
241
- const materialJson = this._renderMaterials[key];
242
- if (!materialJson)
243
- return undefined;
244
- // eslint-disable-next-line deprecation/deprecation
245
- const materialParams = new core_common_1.RenderMaterial.Params(key);
246
- materialParams.diffuseColor = this.colorDefFromMaterialJson(materialJson.diffuseColor);
247
- if (materialJson.diffuse !== undefined)
248
- materialParams.diffuse = core_bentley_1.JsonUtils.asDouble(materialJson.diffuse);
249
- materialParams.specularColor = this.colorDefFromMaterialJson(materialJson.specularColor);
250
- if (materialJson.specular !== undefined)
251
- materialParams.specular = core_bentley_1.JsonUtils.asDouble(materialJson.specular);
252
- materialParams.reflectColor = this.colorDefFromMaterialJson(materialJson.reflectColor);
253
- if (materialJson.reflect !== undefined)
254
- materialParams.reflect = core_bentley_1.JsonUtils.asDouble(materialJson.reflect);
255
- if (materialJson.specularExponent !== undefined)
256
- materialParams.specularExponent = materialJson.specularExponent;
257
- if (undefined !== materialJson.transparency)
258
- materialParams.alpha = 1.0 - materialJson.transparency;
259
- materialParams.refract = core_bentley_1.JsonUtils.asDouble(materialJson.refract);
260
- materialParams.shadows = core_bentley_1.JsonUtils.asBool(materialJson.shadows);
261
- materialParams.ambient = core_bentley_1.JsonUtils.asDouble(materialJson.ambient);
262
- if (undefined !== materialJson.textureMapping)
263
- materialParams.textureMapping = this.textureMappingFromJson(materialJson.textureMapping.texture);
264
- // eslint-disable-next-line deprecation/deprecation
265
- return this._system.createMaterial(materialParams, this._iModel);
266
- }
267
- constantLodParamPropsFromJson(propsJson) {
268
- if (undefined === propsJson)
269
- return undefined;
270
- const constantLodPops = {
271
- repetitions: core_bentley_1.JsonUtils.asDouble(propsJson.repetitions, 1.0),
272
- offset: { x: propsJson.offset ? core_bentley_1.JsonUtils.asDouble(propsJson.offset[0]) : 0.0, y: propsJson.offset ? core_bentley_1.JsonUtils.asDouble(propsJson.offset[1]) : 0.0 },
273
- minDistClamp: core_bentley_1.JsonUtils.asDouble(propsJson.minDistClamp, 1.0),
274
- maxDistClamp: core_bentley_1.JsonUtils.asDouble(propsJson.maxDistClamp, 4096.0 * 1024.0 * 1024.0),
275
- };
276
- return constantLodPops;
277
- }
278
- textureMappingFromJson(json) {
279
- if (undefined === json)
280
- return undefined;
281
- const name = core_bentley_1.JsonUtils.asString(json.name);
282
- const namedTex = 0 !== name.length ? this._namedTextures[name] : undefined;
283
- const texture = undefined !== namedTex ? namedTex.renderTexture : undefined;
284
- if (undefined === texture) {
285
- (0, core_bentley_1.assert)(false, "bad texture mapping json");
286
- return undefined;
287
- }
288
- const paramsJson = json.params;
289
- const tf = paramsJson.transform;
290
- const paramProps = {
291
- textureMat2x3: new core_common_1.TextureMapping.Trans2x3(tf[0][0], tf[0][1], tf[0][2], tf[1][0], tf[1][1], tf[1][2]),
292
- textureWeight: core_bentley_1.JsonUtils.asDouble(paramsJson.weight, 1.0),
293
- mapMode: core_bentley_1.JsonUtils.asInt(paramsJson.mode),
294
- worldMapping: core_bentley_1.JsonUtils.asBool(paramsJson.worldMapping),
295
- useConstantLod: core_bentley_1.JsonUtils.asBool(paramsJson.useConstantLod),
296
- constantLodProps: this.constantLodParamPropsFromJson(paramsJson.constantLodParams),
297
- };
298
- const textureMapping = new core_common_1.TextureMapping(texture, new core_common_1.TextureMapping.Params(paramProps));
299
- const normalMapJson = json.normalMapParams;
300
- if (normalMapJson) {
301
- let normalMap;
302
- const normalTexName = core_bentley_1.JsonUtils.asString(normalMapJson.textureName);
303
- if (normalTexName.length === 0 || undefined !== (normalMap = this._namedTextures[normalTexName]?.renderTexture)) {
304
- textureMapping.normalMapParams = {
305
- normalMap,
306
- greenUp: core_bentley_1.JsonUtils.asBool(normalMapJson.greenUp),
307
- scale: core_bentley_1.JsonUtils.asDouble(normalMapJson.scale, 1),
308
- useConstantLod: core_bentley_1.JsonUtils.asBool(normalMapJson.useConstantLod),
309
- };
310
- }
311
- }
312
- return textureMapping;
313
- }
314
- async loadNamedTextures() {
315
- if (undefined === this._namedTextures)
316
- return;
317
- const promises = new Array();
318
- for (const name of Object.keys(this._namedTextures))
319
- promises.push(this.loadNamedTexture(name));
320
- if (promises.length > 0)
321
- await Promise.all(promises);
322
- }
323
- async loadNamedTexture(name) {
324
- if (this._isCanceled)
325
- return;
326
- const namedTex = this._namedTextures[name];
327
- (0, core_bentley_1.assert)(undefined !== namedTex); // we got here by iterating the keys of this.namedTextures...
328
- if (undefined === namedTex)
329
- return;
330
- const texture = this._system.findTexture(name, this._iModel);
331
- if (undefined !== texture) {
332
- namedTex.renderTexture = texture;
333
- return;
334
- }
335
- namedTex.renderTexture = await this.readNamedTexture(namedTex, name);
336
- }
337
- async readNamedTexture(namedTex, name) {
338
- // Reasons a texture could be embedded in the tile content instead of requested separately from the backend:
339
- // - external textures are disabled
340
- // - the texture name is not a valid Id64 string
341
- // - the texture is below a certain backend-hardcoded size threshold
342
- // The bufferViewJson being defined signifies any of the above conditions. In that case, the image content
343
- // has been embedded in the tile contents. Otherwise, we will attempt to request the image content separately
344
- // from the backend.
345
- let textureType = core_common_1.RenderTexture.Type.Normal;
346
- const isGlyph = core_bentley_1.JsonUtils.asBool(namedTex.isGlyph);
347
- const isTileSection = !isGlyph && core_bentley_1.JsonUtils.asBool(namedTex.isTileSection);
348
- if (isGlyph)
349
- textureType = core_common_1.RenderTexture.Type.Glyph;
350
- else if (isTileSection)
351
- textureType = core_common_1.RenderTexture.Type.TileSection;
352
- // We produce unique tile sections for very large (> 8 megapixel) textures, and unique glyph atlases for raster text.
353
- // Neither should be cached.
354
- const cacheable = !isGlyph && !isTileSection;
355
- const ownership = cacheable ? { iModel: this._iModel, key: name } : undefined;
356
- const bufferViewId = core_bentley_1.JsonUtils.asString(namedTex.bufferView);
357
- const bufferViewJson = 0 !== bufferViewId.length ? this._bufferViews[bufferViewId] : undefined;
358
- if (undefined !== bufferViewJson) { // presence of bufferViewJson signifies we should read the texture from the tile content
359
- const byteOffset = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteOffset);
360
- const byteLength = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteLength);
361
- if (0 === byteLength)
362
- return undefined;
363
- const texBytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
364
- const format = namedTex.format;
365
- const source = new core_common_1.ImageSource(texBytes, format);
366
- return this._system.createTextureFromSource({ source, ownership, type: textureType, transparency: namedTex.transparency });
367
- }
368
- // bufferViewJson was undefined, so attempt to request the texture directly from the backend
369
- // eslint-disable-next-line deprecation/deprecation
370
- const params = new core_common_1.RenderTexture.Params(cacheable ? name : undefined, textureType);
371
- return this._system.createTextureFromElement(name, this._iModel, params, namedTex.format);
372
- }
373
- /** @internal */
374
- readFeatureTable(startPos) {
375
- this._buffer.curPos = startPos;
376
- const header = core_common_1.FeatureTableHeader.readFrom(this._buffer);
377
- if (undefined === header || 0 !== header.length % 4)
378
- return undefined;
379
- // NB: We make a copy of the sub-array because we don't want to pin the entire data array in memory.
380
- const numUint32s = (header.length - core_common_1.FeatureTableHeader.sizeInBytes) / 4;
381
- const packedFeatureArray = new Uint32Array(this._buffer.nextUint32s(numUint32s));
382
- if (this._buffer.isPastTheEnd)
383
- return undefined;
384
- let featureTable;
385
- if (this._hasMultiModelFeatureTable) {
386
- featureTable = core_common_1.MultiModelPackedFeatureTable.create(packedFeatureArray, this._modelId, header.count, this._type, header.numSubCategories);
387
- }
388
- else {
389
- let animNodesArray;
390
- const animationNodes = this._animationNodes;
391
- if (undefined !== animationNodes) {
392
- const bytesPerId = core_bentley_1.JsonUtils.asInt(animationNodes.bytesPerId);
393
- const bufferViewId = core_bentley_1.JsonUtils.asString(animationNodes.bufferView);
394
- const bufferViewJson = this._bufferViews[bufferViewId];
395
- if (undefined !== bufferViewJson) {
396
- const byteOffset = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteOffset);
397
- const byteLength = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteLength);
398
- const bytes = this._binaryData.subarray(byteOffset, byteOffset + byteLength);
399
- switch (bytesPerId) {
400
- case 1:
401
- animNodesArray = new Uint8Array(bytes);
402
- break;
403
- case 2:
404
- // NB: A *copy* of the subarray.
405
- animNodesArray = Uint16Array.from(new Uint16Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 2));
406
- break;
407
- case 4:
408
- // NB: A *copy* of the subarray.
409
- animNodesArray = Uint32Array.from(new Uint32Array(bytes.buffer, bytes.byteOffset, bytes.byteLength / 4));
410
- break;
411
- }
412
- }
413
- }
414
- featureTable = new core_common_1.PackedFeatureTable(packedFeatureArray, this._modelId, header.count, this._type, animNodesArray);
415
- }
416
- this._buffer.curPos = startPos + header.length;
417
- return featureTable;
418
- }
419
- static skipFeatureTable(stream) {
420
- const startPos = stream.curPos;
421
- const header = core_common_1.FeatureTableHeader.readFrom(stream);
422
- if (undefined !== header)
423
- stream.curPos = startPos + header.length;
424
- return undefined !== header;
425
- }
426
- readAreaPattern(json) {
427
- const geometry = this.getPatternGeometry(json.symbolName);
428
- if (!geometry || geometry.length === 0)
429
- return undefined;
430
- const xyOffsets = this.findBuffer(json.xyOffsets);
431
- if (!xyOffsets)
432
- return undefined;
433
- const clip = core_geometry_1.ClipVector.fromJSON(json.clip);
434
- const clipVolume = clip && clip.isValid ? this._system.createClipVolume(clip) : undefined;
435
- if (!clipVolume)
436
- return undefined;
437
- const viewIndependentOrigin = json.viewIndependentOrigin ? core_geometry_1.Point3d.fromJSON(json.viewIndependentOrigin) : undefined;
438
- const pattern = this._system.createAreaPattern({
439
- xyOffsets: new Float32Array(xyOffsets.buffer, xyOffsets.byteOffset, xyOffsets.byteLength / 4),
440
- featureId: json.featureId,
441
- orgTransform: core_geometry_1.Transform.fromJSON(json.orgTransform),
442
- origin: core_geometry_1.Point2d.fromJSON(json.origin),
443
- scale: json.scale,
444
- spacing: core_geometry_1.Point2d.fromJSON(json.spacing),
445
- patternToModel: core_geometry_1.Transform.fromJSON(json.modelTransform),
446
- range: core_geometry_1.Range3d.fromJSON(json.range),
447
- symbolTranslation: core_geometry_1.Point3d.fromJSON(json.symbolTranslation),
448
- viewIndependentOrigin,
37
+ async function readImdlContent(args) {
38
+ let content;
39
+ try {
40
+ content = (0, core_common_1.decodeTileContentDescription)({
41
+ stream: args.stream,
42
+ sizeMultiplier: args.sizeMultiplier,
43
+ is2d: !args.is3d,
44
+ options: IModelApp_1.IModelApp.tileAdmin,
45
+ isVolumeClassifier: core_common_1.BatchType.VolumeClassifier === args.type,
46
+ isLeaf: args.isLeaf,
449
47
  });
450
- if (!pattern)
451
- return undefined;
452
- const branch = new GraphicBranch_1.GraphicBranch(true);
453
- for (const geom of geometry) {
454
- const graphic = this._system.createRenderGraphic(geom, pattern);
455
- if (graphic)
456
- branch.add(graphic);
457
- }
458
- if (branch.isEmpty)
459
- return undefined;
460
- return this._system.createGraphicBranch(branch, core_geometry_1.Transform.createIdentity(), { clipVolume });
461
- }
462
- readMeshGeometry(primitive) {
463
- const geometry = this.readPrimitiveGeometry(primitive);
464
- if (!geometry)
465
- return undefined;
466
- const instances = this.readInstances(primitive);
467
- return { geometry, instances };
468
- }
469
- readMeshGraphic(primitive) {
470
- if (primitive.type === "areaPattern")
471
- return this.readAreaPattern(primitive);
472
- const geom = this.readMeshGeometry(primitive);
473
- return geom ? this._system.createRenderGraphic(geom.geometry, geom.instances) : undefined;
474
- }
475
- findBuffer(bufferViewId) {
476
- if (typeof bufferViewId !== "string" || 0 === bufferViewId.length)
477
- return undefined;
478
- const bufferViewJson = this._bufferViews[bufferViewId];
479
- if (undefined === bufferViewJson)
480
- return undefined;
481
- const byteOffset = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteOffset);
482
- const byteLength = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteLength);
483
- if (0 === byteLength)
484
- return undefined;
485
- return this._binaryData.subarray(byteOffset, byteOffset + byteLength);
486
- }
487
- readVertexTable(primitive) {
488
- const json = primitive.vertices;
489
- if (undefined === json)
490
- return undefined;
491
- const bytes = this.findBuffer(core_bentley_1.JsonUtils.asString(json.bufferView));
492
- if (undefined === bytes)
493
- return undefined;
494
- const uniformFeatureID = undefined !== json.featureID ? core_bentley_1.JsonUtils.asInt(json.featureID) : undefined;
495
- const rangeMin = core_bentley_1.JsonUtils.asArray(json.params.decodedMin);
496
- const rangeMax = core_bentley_1.JsonUtils.asArray(json.params.decodedMax);
497
- if (undefined === rangeMin || undefined === rangeMax)
498
- return undefined;
499
- const qparams = core_common_1.QParams3d.fromRange(core_geometry_1.Range3d.create(core_geometry_1.Point3d.create(rangeMin[0], rangeMin[1], rangeMin[2]), core_geometry_1.Point3d.create(rangeMax[0], rangeMax[1], rangeMax[2])));
500
- const uniformColor = undefined !== json.uniformColor ? core_common_1.ColorDef.fromJSON(json.uniformColor) : undefined;
501
- let uvParams;
502
- if (MeshPrimitives_1.Mesh.PrimitiveType.Mesh === primitive.type && primitive.surface && primitive.surface.uvParams) {
503
- const uvMin = primitive.surface.uvParams.decodedMin;
504
- const uvMax = primitive.surface.uvParams.decodedMax;
505
- const uvRange = new core_geometry_1.Range2d(uvMin[0], uvMin[1], uvMax[0], uvMax[1]);
506
- uvParams = core_common_1.QParams2d.fromRange(uvRange);
507
- }
508
- return new VertexTable_1.VertexTable({
509
- data: bytes,
510
- qparams,
511
- width: json.width,
512
- height: json.height,
513
- hasTranslucency: json.hasTranslucency,
514
- uniformColor,
515
- featureIndexType: json.featureIndexType,
516
- uniformFeatureID,
517
- numVertices: json.count,
518
- numRgbaPerVertex: json.numRgbaPerVertex,
519
- uvParams,
520
- usesUnquantizedPositions: true === json.usesUnquantizedPositions,
521
- });
522
- }
523
- readAuxChannelTable(primitive) {
524
- const json = primitive.auxChannels;
525
- if (undefined === json)
526
- return undefined;
527
- const bytes = this.findBuffer(core_bentley_1.JsonUtils.asString(json.bufferView));
528
- if (undefined === bytes)
529
- return undefined;
530
- const props = {
531
- data: bytes,
532
- width: json.width,
533
- height: json.height,
534
- count: json.count,
535
- numBytesPerVertex: json.numBytesPerVertex,
536
- displacements: json.displacements,
537
- normals: json.normals,
538
- params: json.params,
539
- };
540
- return AuxChannelTable_1.AuxChannelTable.fromJSON(props);
541
- }
542
- readInstances(primitive) {
543
- const json = primitive.instances;
544
- if (undefined === json)
545
- return undefined;
546
- const count = core_bentley_1.JsonUtils.asInt(json.count, 0);
547
- if (count <= 0)
548
- return undefined;
549
- const centerComponents = core_bentley_1.JsonUtils.asArray(json.transformCenter);
550
- if (undefined === centerComponents || 3 !== centerComponents.length)
551
- return undefined;
552
- const transformCenter = core_geometry_1.Point3d.create(centerComponents[0], centerComponents[1], centerComponents[2]);
553
- const featureIds = this.findBuffer(core_bentley_1.JsonUtils.asString(json.featureIds));
554
- if (undefined === featureIds)
555
- return undefined;
556
- const transformBytes = this.findBuffer(core_bentley_1.JsonUtils.asString(json.transforms));
557
- if (undefined === transformBytes)
558
- return undefined;
559
- // 1 transform = 3 rows of 4 floats = 12 floats per instance
560
- const numFloats = transformBytes.byteLength / 4;
561
- (0, core_bentley_1.assert)(Math.floor(numFloats) === numFloats);
562
- (0, core_bentley_1.assert)(0 === numFloats % 12);
563
- const transforms = new Float32Array(transformBytes.buffer, transformBytes.byteOffset, numFloats);
564
- let symbologyOverrides;
565
- if (undefined !== json.symbologyOverrides)
566
- symbologyOverrides = this.findBuffer(core_bentley_1.JsonUtils.asString(json.symbologyOverrides));
567
- return { count, transforms, transformCenter, featureIds, symbologyOverrides };
568
- }
569
- readVertexIndices(bufferName) {
570
- const bytes = this.findBuffer(bufferName);
571
- return undefined !== bytes ? new VertexTable_1.VertexIndices(bytes) : undefined;
572
- }
573
- readTesselatedPolyline(json) {
574
- const indices = this.readVertexIndices(json.indices);
575
- const prevIndices = this.readVertexIndices(json.prevIndices);
576
- const nextIndicesAndParams = this.findBuffer(json.nextIndicesAndParams);
577
- if (!indices || !prevIndices || !nextIndicesAndParams)
578
- return undefined;
579
- return { indices, prevIndices, nextIndicesAndParams };
580
- }
581
- readSurface(mesh, displayParams) {
582
- const surf = mesh.surface;
583
- if (undefined === surf)
584
- return undefined;
585
- const indices = this.readVertexIndices(surf.indices);
586
- if (undefined === indices)
587
- return undefined;
588
- const type = surf.type;
589
- if (!(0, SurfaceParams_1.isValidSurfaceType)(type))
590
- return undefined;
591
- const texture = undefined !== displayParams.textureMapping ? displayParams.textureMapping.texture : undefined;
592
- let material;
593
- const atlas = mesh.vertices.materialAtlas;
594
- const numColors = mesh.vertices.numColors;
595
- if (undefined !== atlas && undefined !== numColors) {
596
- material = {
597
- isAtlas: true,
598
- hasTranslucency: core_bentley_1.JsonUtils.asBool(atlas.hasTranslucency),
599
- overridesAlpha: core_bentley_1.JsonUtils.asBool(atlas.overridesAlpha, false),
600
- vertexTableOffset: core_bentley_1.JsonUtils.asInt(numColors),
601
- numMaterials: core_bentley_1.JsonUtils.asInt(atlas.numMaterials),
602
- };
603
- }
604
- else {
605
- material = (0, SurfaceParams_1.createSurfaceMaterial)(displayParams.material);
606
- }
607
- const textureMapping = undefined !== texture ? { texture, alwaysDisplayed: core_bentley_1.JsonUtils.asBool(surf.alwaysDisplayTexture) } : undefined;
608
- return {
609
- type,
610
- indices,
611
- fillFlags: displayParams.fillFlags,
612
- hasBakedLighting: false,
613
- material,
614
- textureMapping,
615
- };
616
- }
617
- readSegmentEdges(json) {
618
- const indices = this.readVertexIndices(json.indices);
619
- const endPointAndQuadIndices = this.findBuffer(json.endPointAndQuadIndices);
620
- return undefined !== indices && undefined !== endPointAndQuadIndices ? { indices, endPointAndQuadIndices } : undefined;
621
- }
622
- readSilhouettes(json) {
623
- const segments = this.readSegmentEdges(json);
624
- const normalPairs = this.findBuffer(json.normalPairs);
625
- return undefined !== segments && undefined !== normalPairs ? { normalPairs, indices: segments.indices, endPointAndQuadIndices: segments.endPointAndQuadIndices } : undefined;
626
- }
627
- readIndexedEdges(json) {
628
- const indices = this.readVertexIndices(json.indices);
629
- const edgeTable = this.findBuffer(json.edges);
630
- if (!indices || !edgeTable)
631
- return undefined;
632
- return {
633
- indices,
634
- edges: {
635
- data: edgeTable,
636
- width: json.width,
637
- height: json.height,
638
- silhouettePadding: json.silhouettePadding,
639
- numSegments: json.numSegments,
640
- },
641
- };
642
- }
643
- readEdges(json, displayParams) {
644
- let segments;
645
- let silhouettes;
646
- let polylines;
647
- let indexed;
648
- let succeeded = false;
649
- if (undefined !== json.segments && undefined === (segments = this.readSegmentEdges(json.segments)))
650
- return { succeeded };
651
- if (undefined !== json.silhouettes && undefined === (silhouettes = this.readSilhouettes(json.silhouettes)))
652
- return { succeeded };
653
- if (undefined !== json.polylines && undefined === (polylines = this.readTesselatedPolyline(json.polylines)))
654
- return { succeeded };
655
- if (undefined !== json.indexed && undefined === (indexed = this.readIndexedEdges(json.indexed)))
656
- return { succeeded };
657
- succeeded = true;
658
- let params;
659
- if (segments || silhouettes || polylines || indexed) {
660
- params = {
661
- segments,
662
- silhouettes,
663
- polylines,
664
- indexed,
665
- weight: displayParams.width,
666
- linePixels: displayParams.linePixels,
667
- };
668
- }
669
- return { succeeded, params };
670
48
  }
671
- readPrimitiveParams(primitive) {
672
- const materialName = primitive.material ?? "";
673
- const materialValue = 0 < materialName.length ? core_bentley_1.JsonUtils.asObject(this._materialValues[materialName]) : undefined;
674
- const displayParams = undefined !== materialValue ? this.createDisplayParams(materialValue) : undefined;
675
- if (undefined === displayParams)
676
- return undefined;
677
- const vertices = this.readVertexTable(primitive);
678
- if (undefined === vertices) {
679
- (0, core_bentley_1.assert)(false, "bad vertex table in tile data.");
680
- return undefined;
681
- }
682
- const viOrigin = primitive.viewIndependentOrigin ? core_geometry_1.Point3d.fromJSON(primitive.viewIndependentOrigin) : undefined;
683
- const isPlanar = !this._is3d || core_bentley_1.JsonUtils.asBool(primitive.isPlanar);
684
- switch (primitive.type) {
685
- case MeshPrimitives_1.Mesh.PrimitiveType.Mesh: {
686
- const surface = this.readSurface(primitive, displayParams);
687
- if (!surface)
688
- return undefined;
689
- // ###TODO: Tile generator shouldn't bother producing edges for classification meshes in the first place...
690
- let edgeParams;
691
- if (this._loadEdges && undefined !== primitive.edges && SurfaceParams_1.SurfaceType.VolumeClassifier !== surface.type) {
692
- const edgeResult = this.readEdges(primitive.edges, displayParams);
693
- if (!edgeResult.succeeded)
694
- return undefined;
695
- else
696
- edgeParams = edgeResult.params;
697
- }
698
- return {
699
- params: new VertexTable_1.MeshParams(vertices, surface, edgeParams, isPlanar, this.readAuxChannelTable(primitive)),
700
- type: "mesh",
701
- viOrigin,
702
- };
703
- }
704
- case MeshPrimitives_1.Mesh.PrimitiveType.Polyline: {
705
- const polyline = this.readTesselatedPolyline(primitive);
706
- if (!polyline)
707
- return undefined;
708
- let flags = core_common_1.PolylineTypeFlags.Normal;
709
- if (DisplayParams_1.DisplayParams.RegionEdgeType.Outline === displayParams.regionEdgeType)
710
- flags = (undefined === displayParams.gradient || displayParams.gradient.isOutlined) ? core_common_1.PolylineTypeFlags.Edge : core_common_1.PolylineTypeFlags.Outline;
711
- return {
712
- params: new PolylineParams_1.PolylineParams(vertices, polyline, displayParams.width, displayParams.linePixels, isPlanar, flags),
713
- type: "polyline",
714
- viOrigin,
715
- };
716
- }
717
- case MeshPrimitives_1.Mesh.PrimitiveType.Point: {
718
- const indices = this.readVertexIndices(primitive.indices);
719
- if (undefined === indices)
720
- return undefined;
721
- return {
722
- params: new PointStringParams_1.PointStringParams(vertices, indices, displayParams.width),
723
- type: "point",
724
- viOrigin,
725
- };
726
- }
727
- default:
728
- (0, core_bentley_1.assert)(false, "unhandled primitive type");
729
- return undefined;
730
- }
731
- }
732
- readPrimitiveGeometry(primitive) {
733
- const prim = this.readPrimitiveParams(primitive);
734
- return prim ? this.createPrimitiveGeometry(prim) : undefined;
735
- }
736
- createPrimitiveGeometry(prim) {
737
- switch (prim.type) {
738
- case "mesh":
739
- return this._system.createMeshGeometry(prim.params, prim.viOrigin);
740
- case "polyline":
741
- return this._system.createPolylineGeometry(prim.params, prim.viOrigin);
742
- case "point":
743
- return this._system.createPointStringGeometry(prim.params, prim.viOrigin);
744
- }
745
- }
746
- getPatternGeometry(patternName) {
747
- let geometry = this._patternGeometry.get(patternName);
748
- if (geometry)
749
- return geometry;
750
- const symbol = this._patternSymbols[patternName];
751
- if (!symbol)
752
- return undefined;
753
- geometry = [];
754
- for (const primitive of symbol.primitives) {
755
- const geom = this.readPrimitiveGeometry(primitive);
756
- if (geom)
757
- geometry.push(geom);
758
- }
759
- this._patternGeometry.set(patternName, geometry);
760
- return geometry;
761
- }
762
- readAnimationBranches(output, mesh, featureTable, timeline) {
763
- const primitives = mesh.primitives;
764
- if (!primitives)
765
- return;
766
- const branchesByNodeId = new Map();
767
- const getBranch = (nodeId) => {
768
- let branch = branchesByNodeId.get(nodeId);
769
- if (!branch) {
770
- branchesByNodeId.set(nodeId, branch = new GraphicBranch_1.GraphicBranch(true));
771
- branch.animationNodeId = nodeId;
772
- branch.animationId = `${this._modelId}_Node_${nodeId}`;
773
- }
774
- return branch;
775
- };
776
- featureTable.populateAnimationNodeIds((feature) => timeline.getBatchIdForFeature(feature), timeline.maxBatchId);
777
- const discreteNodeIds = timeline.discreteBatchIds;
778
- const computeNodeId = (featureIndex) => {
779
- const nodeId = featureTable.getAnimationNodeId(featureIndex);
780
- return 0 !== nodeId && discreteNodeIds.has(nodeId) ? nodeId : 0;
781
- };
782
- const splitArgs = {
783
- maxDimension: this._system.maxTextureSize,
784
- computeNodeId,
785
- featureTable,
786
- };
787
- for (const primitive of primitives) {
788
- if (primitive.type === "areaPattern") {
789
- // ###TODO animated area patterns.
790
- const gf = this.readAreaPattern(primitive);
791
- if (gf)
792
- getBranch(GraphicBranch_1.AnimationNodeId.Untransformed).add(gf);
793
- }
794
- else {
795
- const prim = this.readPrimitiveParams(primitive);
796
- if (!prim)
797
- continue;
798
- const viOrigin = prim.viOrigin;
799
- switch (prim.type) {
800
- case "mesh": {
801
- const split = (0, VertexTableSplitter_1.splitMeshParams)({ ...splitArgs, params: prim.params });
802
- for (const [nodeId, params] of split) {
803
- const geometry = this.createPrimitiveGeometry({ params, viOrigin, type: "mesh" });
804
- const instances = undefined; // ###TODO support splitting instances (currently animation tile trees do not permit instancing).
805
- const graphic = geometry ? this._system.createRenderGraphic(geometry, instances) : undefined;
806
- if (graphic)
807
- getBranch(nodeId).add(graphic);
808
- }
809
- break;
810
- }
811
- case "point": {
812
- const split = (0, VertexTableSplitter_1.splitPointStringParams)({ ...splitArgs, params: prim.params });
813
- for (const [nodeId, params] of split) {
814
- const geometry = this.createPrimitiveGeometry({ params, viOrigin, type: "point" });
815
- const instances = undefined; // ###TODO support splitting instances (currently animation tile trees do not permit instancing).
816
- const graphic = geometry ? this._system.createRenderGraphic(geometry, instances) : undefined;
817
- if (graphic)
818
- getBranch(nodeId).add(graphic);
819
- }
820
- break;
821
- }
822
- case "polyline": {
823
- const split = (0, VertexTableSplitter_1.splitPolylineParams)({ ...splitArgs, params: prim.params });
824
- for (const [nodeId, params] of split) {
825
- const geometry = this.createPrimitiveGeometry({ params, viOrigin, type: "polyline" });
826
- const instances = undefined; // ###TODO support splitting instances (currently animation tile trees do not permit instancing).
827
- const graphic = geometry ? this._system.createRenderGraphic(geometry, instances) : undefined;
828
- if (graphic)
829
- getBranch(nodeId).add(graphic);
830
- }
831
- break;
832
- }
833
- }
834
- }
835
- }
836
- for (const branch of branchesByNodeId.values()) {
837
- (0, core_bentley_1.assert)(!branch.isEmpty);
838
- output.push(this._system.createBranch(branch, core_geometry_1.Transform.createIdentity()));
839
- }
840
- }
841
- readBranch(output, primitives, nodeId, animationId) {
842
- const branch = new GraphicBranch_1.GraphicBranch(true);
843
- branch.animationId = animationId;
844
- branch.animationNodeId = nodeId;
845
- for (const primitive of primitives) {
846
- const graphic = this.readMeshGraphic(primitive);
847
- if (graphic)
848
- branch.add(graphic);
849
- }
850
- if (!branch.isEmpty)
851
- output.push(this._system.createBranch(branch, core_geometry_1.Transform.createIdentity()));
852
- }
853
- finishRead(isLeaf, featureTable, contentRange, emptySubRangeMask, sizeMultiplier) {
854
- const graphics = [];
855
- if (undefined === this._nodes.Node_Root) {
856
- // Unstructured -- prior to animation support....
857
- for (const meshKey of Object.keys(this._meshes)) {
858
- const meshValue = this._meshes[meshKey];
859
- const primitives = meshValue?.primitives;
860
- if (!primitives || !meshValue)
861
- continue;
862
- for (const primitive of primitives) {
863
- const graphic = this.readMeshGraphic(primitive);
864
- if (undefined !== graphic)
865
- graphics.push(graphic);
866
- }
867
- }
868
- }
869
- else {
870
- for (const nodeKey of Object.keys(this._nodes)) {
871
- const nodeValue = this._nodes[nodeKey];
872
- const meshValue = undefined !== nodeValue ? this._meshes[nodeValue] : undefined;
873
- const primitives = meshValue?.primitives;
874
- if (!primitives || !meshValue)
875
- continue;
876
- const layerId = meshValue.layer;
877
- if ("Node_Root" === nodeKey) {
878
- if (this._timeline) {
879
- // Split up the root node into transform nodes.
880
- this.readAnimationBranches(graphics, meshValue, featureTable, this._timeline);
881
- }
882
- else if (this._containsTransformNodes) {
883
- // If transform nodes exist in the tile tree, then we need to create a branch for Node_Root so that elements not associated with
884
- // any node in the schedule script can be grouped together.
885
- this.readBranch(graphics, primitives, GraphicBranch_1.AnimationNodeId.Untransformed, undefined);
886
- }
887
- else {
888
- for (const primitive of primitives) {
889
- const graphic = this.readMeshGraphic(primitive);
890
- if (undefined !== graphic)
891
- graphics.push(graphic);
892
- }
893
- }
894
- }
895
- else if (undefined === layerId) {
896
- this.readBranch(graphics, primitives, extractNodeId(nodeKey), `${this._modelId}_${nodeKey}`);
897
- }
898
- else {
899
- const layerGraphics = [];
900
- for (const primitive of primitives) {
901
- const graphic = this.readMeshGraphic(primitive);
902
- if (undefined !== graphic)
903
- layerGraphics.push(graphic);
904
- }
905
- if (layerGraphics.length > 0) {
906
- const layerGraphic = 1 === layerGraphics.length ? layerGraphics[0] : this._system.createGraphicList(layerGraphics);
907
- graphics.push(this._system.createGraphicLayer(layerGraphic, layerId));
908
- }
909
- }
910
- }
911
- }
912
- let tileGraphic;
913
- switch (graphics.length) {
914
- case 0:
915
- break;
916
- case 1:
917
- tileGraphic = graphics[0];
918
- break;
919
- default:
920
- tileGraphic = this._system.createGraphicList(graphics);
921
- break;
922
- }
923
- if (tileGraphic && false !== this._options)
924
- tileGraphic = this._system.createBatch(tileGraphic, featureTable, contentRange, this._options);
925
- if (tileGraphic && this._rtcCenter) {
926
- const rtcBranch = new GraphicBranch_1.GraphicBranch(true);
927
- rtcBranch.add(tileGraphic);
928
- tileGraphic = this._system.createBranch(rtcBranch, core_geometry_1.Transform.createTranslation(this._rtcCenter));
929
- }
49
+ catch (e) {
50
+ if (e instanceof core_common_1.TileReadError)
51
+ return { isLeaf: true, readStatus: e.errorNumber };
52
+ else
53
+ throw e;
54
+ }
55
+ args.stream.reset();
56
+ const document = (0, ImdlParser_1.parseImdlDocument)({
57
+ stream: args.stream,
58
+ batchModelId: args.modelId,
59
+ is3d: args.is3d,
60
+ maxVertexTableSize: IModelApp_1.IModelApp.renderSystem.maxTextureSize,
61
+ omitEdges: false === args.loadEdges,
62
+ timeline: args.timeline,
63
+ createUntransformedRootNode: args.containsTransformNodes,
64
+ });
65
+ if (typeof document === "number")
66
+ return { isLeaf: true, readStatus: document };
67
+ let graphic = await (0, ImdlGraphicsCreator_1.decodeImdlGraphics)({
68
+ system: args.system,
69
+ iModel: args.iModel,
70
+ document,
71
+ isCanceled: args.isCanceled,
72
+ });
73
+ if (args.isCanceled && args.isCanceled())
74
+ return { isLeaf: true, readStatus: core_common_1.TileReadStatus.Canceled };
75
+ if (graphic && false !== args.options) {
76
+ const featureTable = (0, ImdlParser_1.convertFeatureTable)(document.featureTable, args.modelId);
77
+ graphic = args.system.createBatch(graphic, featureTable, content.contentRange, args.options);
78
+ }
79
+ if (graphic && document.rtcCenter) {
80
+ const rtcBranch = new GraphicBranch_1.GraphicBranch(true);
81
+ rtcBranch.add(graphic);
82
+ graphic = args.system.createBranch(rtcBranch, core_geometry_1.Transform.createTranslation(core_geometry_1.Point3d.fromJSON(document.rtcCenter)));
83
+ }
84
+ return {
85
+ readStatus: core_common_1.TileReadStatus.Success,
86
+ isLeaf: content.isLeaf,
87
+ sizeMultiplier: content.sizeMultiplier,
88
+ contentRange: content.contentRange.isNull ? undefined : content.contentRange,
89
+ graphic,
90
+ emptySubRangeMask: content.emptySubRangeMask,
91
+ };
92
+ }
93
+ /** @internal */
94
+ var ImdlReader;
95
+ (function (ImdlReader) {
96
+ function create(args) {
930
97
  return {
931
- readStatus: core_common_1.TileReadStatus.Success,
932
- isLeaf,
933
- sizeMultiplier,
934
- contentRange: contentRange.isNull ? undefined : contentRange,
935
- graphic: tileGraphic,
936
- emptySubRangeMask,
98
+ read: async () => readImdlContent(args),
937
99
  };
938
100
  }
939
- }
940
- exports.ImdlReader = ImdlReader;
101
+ ImdlReader.create = create;
102
+ })(ImdlReader = exports.ImdlReader || (exports.ImdlReader = {}));
941
103
  //# sourceMappingURL=ImdlReader.js.map