@itwin/core-frontend 4.1.0-dev.0 → 4.1.0-dev.11

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 (129) hide show
  1. package/lib/cjs/AccuSnap.d.ts.map +1 -1
  2. package/lib/cjs/AccuSnap.js +8 -0
  3. package/lib/cjs/AccuSnap.js.map +1 -1
  4. package/lib/cjs/BriefcaseTxns.d.ts +2 -2
  5. package/lib/cjs/BriefcaseTxns.d.ts.map +1 -1
  6. package/lib/cjs/BriefcaseTxns.js +3 -3
  7. package/lib/cjs/BriefcaseTxns.js.map +1 -1
  8. package/lib/cjs/GraphicalEditingScope.d.ts +2 -2
  9. package/lib/cjs/GraphicalEditingScope.d.ts.map +1 -1
  10. package/lib/cjs/GraphicalEditingScope.js +1 -1
  11. package/lib/cjs/GraphicalEditingScope.js.map +1 -1
  12. package/lib/cjs/IpcApp.d.ts.map +1 -1
  13. package/lib/cjs/IpcApp.js +3 -3
  14. package/lib/cjs/IpcApp.js.map +1 -1
  15. package/lib/cjs/LocalhostIpcApp.js +1 -1
  16. package/lib/cjs/LocalhostIpcApp.js.map +1 -1
  17. package/lib/cjs/NativeApp.d.ts.map +1 -1
  18. package/lib/cjs/NativeApp.js +3 -3
  19. package/lib/cjs/NativeApp.js.map +1 -1
  20. package/lib/cjs/core-frontend.d.ts +3 -0
  21. package/lib/cjs/core-frontend.d.ts.map +1 -1
  22. package/lib/cjs/core-frontend.js +3 -0
  23. package/lib/cjs/core-frontend.js.map +1 -1
  24. package/lib/cjs/imdl/ImdlGraphicsCreator.d.ts +19 -0
  25. package/lib/cjs/imdl/ImdlGraphicsCreator.d.ts.map +1 -0
  26. package/lib/cjs/imdl/ImdlGraphicsCreator.js +328 -0
  27. package/lib/cjs/imdl/ImdlGraphicsCreator.js.map +1 -0
  28. package/lib/cjs/imdl/ImdlModel.d.ts +181 -0
  29. package/lib/cjs/imdl/ImdlModel.d.ts.map +1 -0
  30. package/lib/cjs/imdl/ImdlModel.js +10 -0
  31. package/lib/cjs/imdl/ImdlModel.js.map +1 -0
  32. package/lib/cjs/imdl/ImdlParser.d.ts +40 -0
  33. package/lib/cjs/imdl/ImdlParser.d.ts.map +1 -0
  34. package/lib/cjs/imdl/ImdlParser.js +996 -0
  35. package/lib/cjs/imdl/ImdlParser.js.map +1 -0
  36. package/lib/cjs/imdl/ImdlSchema.d.ts +380 -0
  37. package/lib/cjs/imdl/ImdlSchema.d.ts.map +1 -0
  38. package/lib/cjs/imdl/ImdlSchema.js +10 -0
  39. package/lib/cjs/imdl/ImdlSchema.js.map +1 -0
  40. package/lib/cjs/render/primitives/AuxChannelTable.d.ts +4 -0
  41. package/lib/cjs/render/primitives/AuxChannelTable.d.ts.map +1 -1
  42. package/lib/cjs/render/primitives/AuxChannelTable.js +33 -0
  43. package/lib/cjs/render/primitives/AuxChannelTable.js.map +1 -1
  44. package/lib/cjs/render/primitives/VertexTable.d.ts +3 -3
  45. package/lib/cjs/render/primitives/VertexTable.d.ts.map +1 -1
  46. package/lib/cjs/render/primitives/VertexTable.js.map +1 -1
  47. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts +5 -1
  48. package/lib/cjs/render/primitives/VertexTableSplitter.d.ts.map +1 -1
  49. package/lib/cjs/render/primitives/VertexTableSplitter.js +13 -12
  50. package/lib/cjs/render/primitives/VertexTableSplitter.js.map +1 -1
  51. package/lib/cjs/tile/IModelTile.d.ts.map +1 -1
  52. package/lib/cjs/tile/IModelTile.js +14 -15
  53. package/lib/cjs/tile/IModelTile.js.map +1 -1
  54. package/lib/cjs/tile/ImdlReader.d.ts +11 -420
  55. package/lib/cjs/tile/ImdlReader.d.ts.map +1 -1
  56. package/lib/cjs/tile/ImdlReader.js +64 -902
  57. package/lib/cjs/tile/ImdlReader.js.map +1 -1
  58. package/lib/cjs/tile/map/MapTile.d.ts +6 -1
  59. package/lib/cjs/tile/map/MapTile.d.ts.map +1 -1
  60. package/lib/cjs/tile/map/MapTile.js +8 -7
  61. package/lib/cjs/tile/map/MapTile.js.map +1 -1
  62. package/lib/cjs/tile/map/MapTileTree.d.ts.map +1 -1
  63. package/lib/cjs/tile/map/MapTileTree.js +8 -2
  64. package/lib/cjs/tile/map/MapTileTree.js.map +1 -1
  65. package/lib/esm/AccuSnap.d.ts.map +1 -1
  66. package/lib/esm/AccuSnap.js +8 -0
  67. package/lib/esm/AccuSnap.js.map +1 -1
  68. package/lib/esm/BriefcaseTxns.d.ts +2 -2
  69. package/lib/esm/BriefcaseTxns.d.ts.map +1 -1
  70. package/lib/esm/BriefcaseTxns.js +3 -3
  71. package/lib/esm/BriefcaseTxns.js.map +1 -1
  72. package/lib/esm/GraphicalEditingScope.d.ts +2 -2
  73. package/lib/esm/GraphicalEditingScope.d.ts.map +1 -1
  74. package/lib/esm/GraphicalEditingScope.js +2 -2
  75. package/lib/esm/GraphicalEditingScope.js.map +1 -1
  76. package/lib/esm/IpcApp.d.ts.map +1 -1
  77. package/lib/esm/IpcApp.js +4 -4
  78. package/lib/esm/IpcApp.js.map +1 -1
  79. package/lib/esm/LocalhostIpcApp.js +2 -2
  80. package/lib/esm/LocalhostIpcApp.js.map +1 -1
  81. package/lib/esm/NativeApp.d.ts.map +1 -1
  82. package/lib/esm/NativeApp.js +4 -4
  83. package/lib/esm/NativeApp.js.map +1 -1
  84. package/lib/esm/core-frontend.d.ts +3 -0
  85. package/lib/esm/core-frontend.d.ts.map +1 -1
  86. package/lib/esm/core-frontend.js +3 -0
  87. package/lib/esm/core-frontend.js.map +1 -1
  88. package/lib/esm/imdl/ImdlGraphicsCreator.d.ts +19 -0
  89. package/lib/esm/imdl/ImdlGraphicsCreator.d.ts.map +1 -0
  90. package/lib/esm/imdl/ImdlGraphicsCreator.js +324 -0
  91. package/lib/esm/imdl/ImdlGraphicsCreator.js.map +1 -0
  92. package/lib/esm/imdl/ImdlModel.d.ts +181 -0
  93. package/lib/esm/imdl/ImdlModel.d.ts.map +1 -0
  94. package/lib/esm/imdl/ImdlModel.js +9 -0
  95. package/lib/esm/imdl/ImdlModel.js.map +1 -0
  96. package/lib/esm/imdl/ImdlParser.d.ts +40 -0
  97. package/lib/esm/imdl/ImdlParser.d.ts.map +1 -0
  98. package/lib/esm/imdl/ImdlParser.js +988 -0
  99. package/lib/esm/imdl/ImdlParser.js.map +1 -0
  100. package/lib/esm/imdl/ImdlSchema.d.ts +380 -0
  101. package/lib/esm/imdl/ImdlSchema.d.ts.map +1 -0
  102. package/lib/esm/imdl/ImdlSchema.js +9 -0
  103. package/lib/esm/imdl/ImdlSchema.js.map +1 -0
  104. package/lib/esm/render/primitives/AuxChannelTable.d.ts +4 -0
  105. package/lib/esm/render/primitives/AuxChannelTable.d.ts.map +1 -1
  106. package/lib/esm/render/primitives/AuxChannelTable.js +33 -0
  107. package/lib/esm/render/primitives/AuxChannelTable.js.map +1 -1
  108. package/lib/esm/render/primitives/VertexTable.d.ts +3 -3
  109. package/lib/esm/render/primitives/VertexTable.d.ts.map +1 -1
  110. package/lib/esm/render/primitives/VertexTable.js.map +1 -1
  111. package/lib/esm/render/primitives/VertexTableSplitter.d.ts +5 -1
  112. package/lib/esm/render/primitives/VertexTableSplitter.d.ts.map +1 -1
  113. package/lib/esm/render/primitives/VertexTableSplitter.js +13 -12
  114. package/lib/esm/render/primitives/VertexTableSplitter.js.map +1 -1
  115. package/lib/esm/tile/IModelTile.d.ts.map +1 -1
  116. package/lib/esm/tile/IModelTile.js +14 -15
  117. package/lib/esm/tile/IModelTile.js.map +1 -1
  118. package/lib/esm/tile/ImdlReader.d.ts +11 -420
  119. package/lib/esm/tile/ImdlReader.d.ts.map +1 -1
  120. package/lib/esm/tile/ImdlReader.js +67 -903
  121. package/lib/esm/tile/ImdlReader.js.map +1 -1
  122. package/lib/esm/tile/map/MapTile.d.ts +6 -1
  123. package/lib/esm/tile/map/MapTile.d.ts.map +1 -1
  124. package/lib/esm/tile/map/MapTile.js +8 -7
  125. package/lib/esm/tile/map/MapTile.js.map +1 -1
  126. package/lib/esm/tile/map/MapTileTree.d.ts.map +1 -1
  127. package/lib/esm/tile/map/MapTileTree.js +8 -2
  128. package/lib/esm/tile/map/MapTileTree.js.map +1 -1
  129. package/package.json +18 -18
@@ -0,0 +1,19 @@
1
+ /** @packageDocumentation
2
+ * @module Tiles
3
+ */
4
+ import type { ImdlModel as Imdl } from "../imdl/ImdlModel";
5
+ import type { RenderGraphic } from "../render/RenderGraphic";
6
+ import type { RenderSystem } from "../render/RenderSystem";
7
+ import type { IModelConnection } from "../IModelConnection";
8
+ /** Options provided to [[decodeImdlContent]].
9
+ * @internal
10
+ */
11
+ export interface ImdlDecodeOptions {
12
+ document: Imdl.Document;
13
+ system: RenderSystem;
14
+ iModel: IModelConnection;
15
+ isCanceled?: () => boolean;
16
+ }
17
+ /** @internal */
18
+ export declare function decodeImdlGraphics(options: ImdlDecodeOptions): Promise<RenderGraphic | undefined>;
19
+ //# sourceMappingURL=ImdlGraphicsCreator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImdlGraphicsCreator.d.ts","sourceRoot":"","sources":["../../../src/imdl/ImdlGraphicsCreator.ts"],"names":[],"mappings":"AAIA;;GAEG;AAQH,OAAO,KAAK,EAAE,SAAS,IAAI,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAE3D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AAE7D,OAAO,KAAK,EAAkB,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAE3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAK5D;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC;IACxB,MAAM,EAAE,YAAY,CAAC;IACrB,MAAM,EAAE,gBAAgB,CAAC;IACzB,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC;CAC5B;AAoUD,gBAAgB;AAChB,wBAAsB,kBAAkB,CAAC,OAAO,EAAE,iBAAiB,GAAG,OAAO,CAAC,aAAa,GAAG,SAAS,CAAC,CAqCvG"}
@@ -0,0 +1,328 @@
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
+ /** @packageDocumentation
7
+ * @module Tiles
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.decodeImdlGraphics = void 0;
11
+ const core_bentley_1 = require("@itwin/core-bentley");
12
+ const core_geometry_1 = require("@itwin/core-geometry");
13
+ const core_common_1 = require("@itwin/core-common");
14
+ const ImdlParser_1 = require("../imdl/ImdlParser");
15
+ const GraphicBranch_1 = require("../render/GraphicBranch");
16
+ const SurfaceParams_1 = require("../render/primitives/SurfaceParams");
17
+ const VertexTable_1 = require("../render/primitives/VertexTable");
18
+ const AuxChannelTable_1 = require("../render/primitives/AuxChannelTable");
19
+ async function loadNamedTexture(name, namedTex, options) {
20
+ // Reasons a texture could be embedded in the tile content instead of requested separately from the backend:
21
+ // - external textures are disabled
22
+ // - the texture name is not a valid Id64 string
23
+ // - the texture is below a certain backend-hardcoded size threshold
24
+ // The bufferViewJson being defined signifies any of the above conditions. In that case, the image content
25
+ // has been embedded in the tile contents. Otherwise, we will attempt to request the image content separately
26
+ // from the backend.
27
+ try {
28
+ let textureType = core_common_1.RenderTexture.Type.Normal;
29
+ const isGlyph = core_bentley_1.JsonUtils.asBool(namedTex.isGlyph);
30
+ const isTileSection = !isGlyph && core_bentley_1.JsonUtils.asBool(namedTex.isTileSection);
31
+ if (isGlyph)
32
+ textureType = core_common_1.RenderTexture.Type.Glyph;
33
+ else if (isTileSection)
34
+ textureType = core_common_1.RenderTexture.Type.TileSection;
35
+ // We produce unique tile sections for very large (> 8 megapixel) textures, and unique glyph atlases for raster text.
36
+ // Neither should be cached.
37
+ const cacheable = !isGlyph && !isTileSection;
38
+ const ownership = cacheable ? { iModel: options.iModel, key: name } : undefined;
39
+ const bufferViewId = core_bentley_1.JsonUtils.asString(namedTex.bufferView);
40
+ const bufferViewJson = 0 !== bufferViewId.length ? options.document.json.bufferViews[bufferViewId] : undefined;
41
+ if (undefined !== bufferViewJson) { // presence of bufferViewJson signifies we should read the texture from the tile content
42
+ const byteOffset = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteOffset);
43
+ const byteLength = core_bentley_1.JsonUtils.asInt(bufferViewJson.byteLength);
44
+ if (0 === byteLength)
45
+ return undefined;
46
+ const texBytes = options.document.binaryData.subarray(byteOffset, byteOffset + byteLength);
47
+ const format = namedTex.format;
48
+ const source = new core_common_1.ImageSource(texBytes, format);
49
+ return await options.system.createTextureFromSource({ source, ownership, type: textureType, transparency: namedTex.transparency });
50
+ }
51
+ // bufferViewJson was undefined, so attempt to request the texture directly from the backend
52
+ // eslint-disable-next-line deprecation/deprecation
53
+ const params = new core_common_1.RenderTexture.Params(cacheable ? name : undefined, textureType);
54
+ return options.system.createTextureFromElement(name, options.iModel, params, namedTex.format);
55
+ }
56
+ catch (_) {
57
+ return undefined;
58
+ }
59
+ }
60
+ async function loadNamedTextures(options) {
61
+ const result = new Map();
62
+ const namedTextures = options.document.json.namedTextures;
63
+ if (!namedTextures)
64
+ return result;
65
+ const promises = new Array();
66
+ for (const [name, namedTexture] of Object.entries(namedTextures)) {
67
+ const texture = options.system.findTexture(name, options.iModel);
68
+ if (texture) {
69
+ result.set(name, texture);
70
+ continue;
71
+ }
72
+ else if (namedTexture) {
73
+ promises.push(loadNamedTexture(name, namedTexture, options).then((tx) => {
74
+ if (tx)
75
+ result.set(name, tx);
76
+ }));
77
+ }
78
+ }
79
+ if (promises.length > 0)
80
+ await Promise.all(promises);
81
+ return result;
82
+ }
83
+ function constantLodParamPropsFromJson(propsJson) {
84
+ if (undefined === propsJson)
85
+ return undefined;
86
+ const constantLodPops = {
87
+ repetitions: core_bentley_1.JsonUtils.asDouble(propsJson.repetitions, 1.0),
88
+ 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 },
89
+ minDistClamp: core_bentley_1.JsonUtils.asDouble(propsJson.minDistClamp, 1.0),
90
+ maxDistClamp: core_bentley_1.JsonUtils.asDouble(propsJson.maxDistClamp, 4096.0 * 1024.0 * 1024.0),
91
+ };
92
+ return constantLodPops;
93
+ }
94
+ function textureMappingFromJson(json, options) {
95
+ if (!json)
96
+ return undefined;
97
+ const texture = options.textures.get(core_bentley_1.JsonUtils.asString(json.name));
98
+ if (!texture)
99
+ return undefined;
100
+ const paramsJson = json.params;
101
+ const tf = paramsJson.transform;
102
+ const paramProps = {
103
+ 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]),
104
+ textureWeight: core_bentley_1.JsonUtils.asDouble(paramsJson.weight, 1.0),
105
+ mapMode: core_bentley_1.JsonUtils.asInt(paramsJson.mode),
106
+ worldMapping: core_bentley_1.JsonUtils.asBool(paramsJson.worldMapping),
107
+ useConstantLod: core_bentley_1.JsonUtils.asBool(paramsJson.useConstantLod),
108
+ constantLodProps: constantLodParamPropsFromJson(paramsJson.constantLodParams),
109
+ };
110
+ const textureMapping = new core_common_1.TextureMapping(texture, new core_common_1.TextureMapping.Params(paramProps));
111
+ const normalMapJson = json.normalMapParams;
112
+ if (normalMapJson) {
113
+ let normalMap;
114
+ const normalTexName = core_bentley_1.JsonUtils.asString(normalMapJson.textureName);
115
+ if (normalTexName.length === 0 || undefined !== (normalMap = options.textures.get(normalTexName))) {
116
+ textureMapping.normalMapParams = {
117
+ normalMap,
118
+ greenUp: core_bentley_1.JsonUtils.asBool(normalMapJson.greenUp),
119
+ scale: core_bentley_1.JsonUtils.asDouble(normalMapJson.scale, 1),
120
+ useConstantLod: core_bentley_1.JsonUtils.asBool(normalMapJson.useConstantLod),
121
+ };
122
+ }
123
+ }
124
+ return textureMapping;
125
+ }
126
+ function getMaterial(mat, options) {
127
+ if (typeof mat !== "string") {
128
+ const args = (0, ImdlParser_1.toMaterialArgs)(mat);
129
+ return options.system.createRenderMaterial(args);
130
+ }
131
+ const material = options.system.findMaterial(mat, options.iModel);
132
+ if (material || !options.document.json.renderMaterials)
133
+ return material;
134
+ const json = options.document.json.renderMaterials[mat];
135
+ if (!json)
136
+ return undefined;
137
+ function colorDefFromJson(col) {
138
+ return col ? core_common_1.ColorDef.from(col[0] * 255 + 0.5, col[1] * 255 + 0.5, col[2] * 255 + 0.5) : undefined;
139
+ }
140
+ // eslint-disable-next-line deprecation/deprecation
141
+ const params = new core_common_1.RenderMaterial.Params(mat);
142
+ params.diffuseColor = colorDefFromJson(json.diffuseColor);
143
+ if (json.diffuse !== undefined)
144
+ params.diffuse = core_bentley_1.JsonUtils.asDouble(json.diffuse);
145
+ params.specularColor = colorDefFromJson(json.specularColor);
146
+ if (json.specular !== undefined)
147
+ params.specular = core_bentley_1.JsonUtils.asDouble(json.specular);
148
+ params.reflectColor = colorDefFromJson(json.reflectColor);
149
+ if (json.reflect !== undefined)
150
+ params.reflect = core_bentley_1.JsonUtils.asDouble(json.reflect);
151
+ if (json.specularExponent !== undefined)
152
+ params.specularExponent = json.specularExponent;
153
+ if (undefined !== json.transparency)
154
+ params.alpha = 1.0 - json.transparency;
155
+ params.refract = core_bentley_1.JsonUtils.asDouble(json.refract);
156
+ params.shadows = core_bentley_1.JsonUtils.asBool(json.shadows);
157
+ params.ambient = core_bentley_1.JsonUtils.asDouble(json.ambient);
158
+ if (undefined !== json.textureMapping)
159
+ params.textureMapping = textureMappingFromJson(json.textureMapping.texture, options);
160
+ // eslint-disable-next-line deprecation/deprecation
161
+ return options.system.createMaterial(params, options.iModel);
162
+ }
163
+ function getModifiers(primitive) {
164
+ const mod = primitive.modifier;
165
+ switch (mod?.type) {
166
+ case "instances":
167
+ return {
168
+ instances: {
169
+ ...mod,
170
+ transformCenter: core_geometry_1.Point3d.fromJSON(mod.transformCenter),
171
+ range: mod.range ? core_geometry_1.Range3d.fromJSON(mod.range) : undefined,
172
+ },
173
+ };
174
+ case "viewIndependentOrigin":
175
+ return {
176
+ viOrigin: core_geometry_1.Point3d.fromJSON(mod.origin),
177
+ };
178
+ default:
179
+ return {};
180
+ }
181
+ }
182
+ function createPrimitiveGeometry(primitive, options, viOrigin) {
183
+ switch (primitive.type) {
184
+ case "point":
185
+ return options.system.createPointStringGeometry({
186
+ ...primitive.params,
187
+ vertices: (0, ImdlParser_1.toVertexTable)(primitive.params.vertices),
188
+ indices: new VertexTable_1.VertexIndices(primitive.params.indices),
189
+ }, viOrigin);
190
+ case "polyline":
191
+ return options.system.createPolylineGeometry({
192
+ ...primitive.params,
193
+ vertices: (0, ImdlParser_1.toVertexTable)(primitive.params.vertices),
194
+ polyline: {
195
+ ...primitive.params.polyline,
196
+ indices: new VertexTable_1.VertexIndices(primitive.params.polyline.indices),
197
+ prevIndices: new VertexTable_1.VertexIndices(primitive.params.polyline.prevIndices),
198
+ },
199
+ }, viOrigin);
200
+ case "mesh": {
201
+ const surf = primitive.params.surface;
202
+ let material;
203
+ if (surf.material) {
204
+ if (!surf.material.isAtlas)
205
+ material = (0, SurfaceParams_1.createSurfaceMaterial)(getMaterial(surf.material.material, options));
206
+ else
207
+ material = surf.material;
208
+ }
209
+ let textureMapping;
210
+ if (surf.textureMapping) {
211
+ let texture;
212
+ if (typeof surf.textureMapping.texture === "string") {
213
+ texture = options.textures.get(surf.textureMapping.texture);
214
+ }
215
+ else {
216
+ const gradient = core_common_1.Gradient.Symb.fromJSON(surf.textureMapping.texture);
217
+ texture = options.system.getGradientTexture(gradient, options.iModel);
218
+ }
219
+ if (texture)
220
+ textureMapping = { texture, alwaysDisplayed: surf.textureMapping.alwaysDisplayed };
221
+ }
222
+ return options.system.createMeshGeometry({
223
+ ...primitive.params,
224
+ edges: primitive.params.edges ? (0, ImdlParser_1.edgeParamsFromImdl)(primitive.params.edges) : undefined,
225
+ vertices: (0, ImdlParser_1.toVertexTable)(primitive.params.vertices),
226
+ auxChannels: primitive.params.auxChannels ? AuxChannelTable_1.AuxChannelTable.fromJSON(primitive.params.auxChannels) : undefined,
227
+ surface: {
228
+ ...primitive.params.surface,
229
+ material,
230
+ textureMapping,
231
+ indices: new VertexTable_1.VertexIndices(primitive.params.surface.indices),
232
+ },
233
+ }, viOrigin);
234
+ }
235
+ }
236
+ }
237
+ function createPrimitiveGraphic(primitive, options) {
238
+ const mods = getModifiers(primitive);
239
+ const geometry = createPrimitiveGeometry(primitive, options, mods.viOrigin);
240
+ return geometry ? options.system.createRenderGraphic(geometry, mods.instances) : undefined;
241
+ }
242
+ function createPatternGeometries(primitives, options) {
243
+ const geometries = [];
244
+ for (const primitive of primitives) {
245
+ const geometry = createPrimitiveGeometry(primitive, options, undefined);
246
+ if (geometry)
247
+ geometries.push(geometry);
248
+ }
249
+ return geometries;
250
+ }
251
+ function createPatternGraphic(params, options) {
252
+ const geometries = options.patterns.get(params.symbolName);
253
+ if (!geometries || geometries.length === 0)
254
+ return undefined;
255
+ const clip = core_geometry_1.ClipVector.fromJSON(params.clip);
256
+ const clipVolume = clip?.isValid ? options.system.createClipVolume(clip) : undefined;
257
+ if (!clipVolume)
258
+ return undefined;
259
+ const viewIndependentOrigin = params.viewIndependentOrigin ? core_geometry_1.Point3d.fromJSON(params.viewIndependentOrigin) : undefined;
260
+ const pattern = options.system.createAreaPattern({
261
+ xyOffsets: params.xyOffsets,
262
+ featureId: params.featureId,
263
+ orgTransform: core_geometry_1.Transform.fromJSON(params.orgTransform),
264
+ origin: core_geometry_1.Point2d.fromJSON(params.origin),
265
+ scale: params.scale,
266
+ spacing: core_geometry_1.Point2d.fromJSON(params.spacing),
267
+ patternToModel: core_geometry_1.Transform.fromJSON(params.modelTransform),
268
+ range: core_geometry_1.Range3d.fromJSON(params.range),
269
+ symbolTranslation: core_geometry_1.Point3d.fromJSON(params.symbolTranslation),
270
+ viewIndependentOrigin,
271
+ });
272
+ if (!pattern)
273
+ return undefined;
274
+ const branch = new GraphicBranch_1.GraphicBranch(true);
275
+ for (const geometry of geometries) {
276
+ const graphic = options.system.createRenderGraphic(geometry, pattern);
277
+ if (graphic)
278
+ branch.add(graphic);
279
+ }
280
+ return branch.isEmpty ? undefined : options.system.createGraphicBranch(branch, core_geometry_1.Transform.createIdentity(), { clipVolume });
281
+ }
282
+ function createNodeGraphics(node, options) {
283
+ const graphics = [];
284
+ for (const primitive of node.primitives) {
285
+ const graphic = primitive.type === "pattern" ? createPatternGraphic(primitive.params, options) : createPrimitiveGraphic(primitive, options);
286
+ if (graphic)
287
+ graphics.push(graphic);
288
+ }
289
+ return graphics;
290
+ }
291
+ /** @internal */
292
+ async function decodeImdlGraphics(options) {
293
+ const textures = await loadNamedTextures(options);
294
+ if (options.isCanceled && options.isCanceled())
295
+ return undefined;
296
+ const patterns = new Map();
297
+ const graphicsOptions = { ...options, textures, patterns };
298
+ for (const [name, primitives] of options.document.patterns)
299
+ patterns.set(name, createPatternGeometries(primitives, graphicsOptions));
300
+ const system = options.system;
301
+ const graphics = [];
302
+ for (const node of options.document.nodes) {
303
+ const nodeGraphics = createNodeGraphics(node, graphicsOptions);
304
+ if (nodeGraphics.length === 0)
305
+ continue;
306
+ if (undefined !== node.layerId) {
307
+ const layerGraphic = 1 === nodeGraphics.length ? nodeGraphics[0] : system.createGraphicList(nodeGraphics);
308
+ graphics.push(system.createGraphicLayer(layerGraphic, node.layerId));
309
+ }
310
+ else if (undefined !== node.animationNodeId) {
311
+ const branch = new GraphicBranch_1.GraphicBranch(true);
312
+ branch.animationId = node.animationId;
313
+ branch.animationNodeId = node.animationNodeId;
314
+ branch.entries.push(...nodeGraphics);
315
+ graphics.push(system.createBranch(branch, core_geometry_1.Transform.createIdentity()));
316
+ }
317
+ else {
318
+ graphics.push(...nodeGraphics);
319
+ }
320
+ }
321
+ switch (graphics.length) {
322
+ case 0: return undefined;
323
+ case 1: return graphics[0];
324
+ default: return system.createGraphicList(graphics);
325
+ }
326
+ }
327
+ exports.decodeImdlGraphics = decodeImdlGraphics;
328
+ //# sourceMappingURL=ImdlGraphicsCreator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImdlGraphicsCreator.js","sourceRoot":"","sources":["../../../src/imdl/ImdlGraphicsCreator.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;AAEH,sDAAgD;AAChD,wDAAwF;AACxF,oDAE4B;AAG5B,mDAAuF;AAEvF,2DAAwD;AAIxD,sEAA2E;AAC3E,kEAAiE;AACjE,0EAAuE;AAYvE,KAAK,UAAU,gBAAgB,CAAC,IAAY,EAAE,QAA0B,EAAE,OAA0B;IAClG,4GAA4G;IAC5G,mCAAmC;IACnC,gDAAgD;IAChD,oEAAoE;IACpE,0GAA0G;IAC1G,6GAA6G;IAC7G,oBAAoB;IAEpB,IAAI;QACF,IAAI,WAAW,GAAG,2BAAa,CAAC,IAAI,CAAC,MAAM,CAAC;QAC5C,MAAM,OAAO,GAAG,wBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QACnD,MAAM,aAAa,GAAG,CAAC,OAAO,IAAI,wBAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,aAAa,CAAC,CAAC;QAC3E,IAAI,OAAO;YACT,WAAW,GAAG,2BAAa,CAAC,IAAI,CAAC,KAAK,CAAC;aACpC,IAAI,aAAa;YACpB,WAAW,GAAG,2BAAa,CAAC,IAAI,CAAC,WAAW,CAAC;QAE/C,qHAAqH;QACrH,4BAA4B;QAC5B,MAAM,SAAS,GAAG,CAAC,OAAO,IAAI,CAAC,aAAa,CAAC;QAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,MAAM,EAAE,GAAG,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;QAEhF,MAAM,YAAY,GAAG,wBAAS,CAAC,QAAQ,CAA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CAAC;QAC3B,OAAO,CAAC,CAAC,OAAO,MAAM,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC;KACpD;AACH,CAAC;AArCD,gDAqCC","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/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { JsonUtils } from \"@itwin/core-bentley\";\r\nimport { ClipVector, Point2d, Point3d, Range3d, Transform } from \"@itwin/core-geometry\";\r\nimport {\r\n ColorDef, Gradient, ImageSource, RenderMaterial, RenderTexture, TextureMapping,\r\n} from \"@itwin/core-common\";\r\nimport type { ImdlColorDef, ImdlNamedTexture, ImdlTextureMapping } from \"../imdl/ImdlSchema\";\r\nimport type { ImdlModel as Imdl } from \"../imdl/ImdlModel\";\r\nimport { edgeParamsFromImdl, toMaterialArgs, toVertexTable } from \"../imdl/ImdlParser\";\r\nimport type { RenderGraphic } from \"../render/RenderGraphic\";\r\nimport { GraphicBranch } from \"../render/GraphicBranch\";\r\nimport type { RenderGeometry, RenderSystem } from \"../render/RenderSystem\";\r\nimport type { InstancedGraphicParams } from \"../render/InstancedGraphicParams\";\r\nimport type { IModelConnection } from \"../IModelConnection\";\r\nimport { createSurfaceMaterial } from \"../render/primitives/SurfaceParams\";\r\nimport { VertexIndices } from \"../render/primitives/VertexTable\";\r\nimport { AuxChannelTable } from \"../render/primitives/AuxChannelTable\";\r\n\r\n/** Options provided to [[decodeImdlContent]].\r\n * @internal\r\n */\r\nexport interface ImdlDecodeOptions {\r\n document: Imdl.Document;\r\n system: RenderSystem;\r\n iModel: IModelConnection;\r\n isCanceled?: () => boolean;\r\n}\r\n\r\nasync function loadNamedTexture(name: string, namedTex: ImdlNamedTexture, options: ImdlDecodeOptions): Promise<RenderTexture | undefined> {\r\n // Reasons a texture could be embedded in the tile content instead of requested separately from the backend:\r\n // - external textures are disabled\r\n // - the texture name is not a valid Id64 string\r\n // - the texture is below a certain backend-hardcoded size threshold\r\n // The bufferViewJson being defined signifies any of the above conditions. In that case, the image content\r\n // has been embedded in the tile contents. Otherwise, we will attempt to request the image content separately\r\n // from the backend.\r\n\r\n try {\r\n let textureType = RenderTexture.Type.Normal;\r\n const isGlyph = JsonUtils.asBool(namedTex.isGlyph);\r\n const isTileSection = !isGlyph && JsonUtils.asBool(namedTex.isTileSection);\r\n if (isGlyph)\r\n textureType = RenderTexture.Type.Glyph;\r\n else if (isTileSection)\r\n textureType = RenderTexture.Type.TileSection;\r\n\r\n // We produce unique tile sections for very large (> 8 megapixel) textures, and unique glyph atlases for raster text.\r\n // Neither should be cached.\r\n const cacheable = !isGlyph && !isTileSection;\r\n const ownership = cacheable ? { iModel: options.iModel, key: name } : undefined;\r\n\r\n const bufferViewId = JsonUtils.asString(namedTex.bufferView);\r\n const bufferViewJson = 0 !== bufferViewId.length ? options.document.json.bufferViews[bufferViewId] : undefined;\r\n\r\n if (undefined !== bufferViewJson) { // presence of bufferViewJson signifies we should read the texture from the tile content\r\n const byteOffset = JsonUtils.asInt(bufferViewJson.byteOffset);\r\n const byteLength = JsonUtils.asInt(bufferViewJson.byteLength);\r\n if (0 === byteLength)\r\n return undefined;\r\n\r\n const texBytes = options.document.binaryData.subarray(byteOffset, byteOffset + byteLength);\r\n const format = namedTex.format;\r\n const source = new ImageSource(texBytes, format);\r\n return await options.system.createTextureFromSource({ source, ownership, type: textureType, transparency: namedTex.transparency });\r\n }\r\n\r\n // bufferViewJson was undefined, so attempt to request the texture directly from the backend\r\n // eslint-disable-next-line deprecation/deprecation\r\n const params = new RenderTexture.Params(cacheable ? name : undefined, textureType);\r\n return options.system.createTextureFromElement(name, options.iModel, params, namedTex.format);\r\n } catch (_) {\r\n return undefined;\r\n }\r\n}\r\n\r\nasync function loadNamedTextures(options: ImdlDecodeOptions): Promise<Map<string, RenderTexture>> {\r\n const result = new Map<string, RenderTexture>();\r\n const namedTextures = options.document.json.namedTextures;\r\n if (!namedTextures)\r\n return result;\r\n\r\n const promises = new Array<Promise<void>>();\r\n for (const [name, namedTexture] of Object.entries(namedTextures)) {\r\n const texture = options.system.findTexture(name, options.iModel);\r\n if (texture) {\r\n result.set(name, texture);\r\n continue;\r\n } else if (namedTexture) {\r\n promises.push(loadNamedTexture(name, namedTexture, options).then((tx) => {\r\n if (tx)\r\n result.set(name, tx);\r\n }));\r\n }\r\n }\r\n\r\n if (promises.length > 0)\r\n await Promise.all(promises);\r\n\r\n return result;\r\n}\r\n\r\ninterface GraphicsOptions extends ImdlDecodeOptions {\r\n textures: Map<string, RenderTexture>;\r\n patterns: Map<string, RenderGeometry[]>;\r\n}\r\n\r\nfunction constantLodParamPropsFromJson(propsJson: { repetitions?: number, offset?: number[], minDistClamp?: number, maxDistClamp?: number } | undefined): TextureMapping.ConstantLodParamProps | undefined {\r\n if (undefined === propsJson)\r\n return undefined;\r\n\r\n const constantLodPops: TextureMapping.ConstantLodParamProps = {\r\n repetitions: JsonUtils.asDouble(propsJson.repetitions, 1.0),\r\n offset: { x: propsJson.offset ? JsonUtils.asDouble(propsJson.offset[0]) : 0.0, y: propsJson.offset ? JsonUtils.asDouble(propsJson.offset[1]) : 0.0 },\r\n minDistClamp: JsonUtils.asDouble(propsJson.minDistClamp, 1.0),\r\n maxDistClamp: JsonUtils.asDouble(propsJson.maxDistClamp, 4096.0 * 1024.0 * 1024.0),\r\n };\r\n return constantLodPops;\r\n}\r\n\r\nfunction textureMappingFromJson(json: ImdlTextureMapping | undefined, options: GraphicsOptions): TextureMapping | undefined {\r\n if (!json)\r\n return undefined;\r\n\r\n const texture = options.textures.get(JsonUtils.asString(json.name));\r\n if (!texture)\r\n return undefined;\r\n\r\n const paramsJson = json.params;\r\n const tf = paramsJson.transform;\r\n\r\n const paramProps: TextureMapping.ParamProps = {\r\n textureMat2x3: new TextureMapping.Trans2x3(tf[0][0], tf[0][1], tf[0][2], tf[1][0], tf[1][1], tf[1][2]),\r\n textureWeight: JsonUtils.asDouble(paramsJson.weight, 1.0),\r\n mapMode: JsonUtils.asInt(paramsJson.mode),\r\n worldMapping: JsonUtils.asBool(paramsJson.worldMapping),\r\n useConstantLod: JsonUtils.asBool(paramsJson.useConstantLod),\r\n constantLodProps: constantLodParamPropsFromJson(paramsJson.constantLodParams),\r\n };\r\n\r\n const textureMapping = new TextureMapping(texture, new TextureMapping.Params(paramProps));\r\n\r\n const normalMapJson = json.normalMapParams;\r\n if (normalMapJson) {\r\n let normalMap;\r\n const normalTexName = JsonUtils.asString(normalMapJson.textureName);\r\n if (normalTexName.length === 0 || undefined !== (normalMap = options.textures.get(normalTexName))) {\r\n textureMapping.normalMapParams = {\r\n normalMap,\r\n greenUp: JsonUtils.asBool(normalMapJson.greenUp),\r\n scale: JsonUtils.asDouble(normalMapJson.scale, 1),\r\n useConstantLod: JsonUtils.asBool(normalMapJson.useConstantLod),\r\n };\r\n }\r\n }\r\n\r\n return textureMapping;\r\n}\r\n\r\nfunction getMaterial(mat: string | Imdl.SurfaceMaterialParams, options: GraphicsOptions): RenderMaterial | undefined {\r\n if (typeof mat !== \"string\") {\r\n const args = toMaterialArgs(mat);\r\n return options.system.createRenderMaterial(args);\r\n }\r\n\r\n const material = options.system.findMaterial(mat, options.iModel);\r\n if (material || !options.document.json.renderMaterials)\r\n return material;\r\n\r\n const json = options.document.json.renderMaterials[mat];\r\n if (!json)\r\n return undefined;\r\n\r\n function colorDefFromJson(col: ImdlColorDef | undefined): ColorDef | undefined {\r\n return col ? ColorDef.from(col[0] * 255 + 0.5, col[1] * 255 + 0.5, col[2] * 255 + 0.5) : undefined;\r\n }\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n const params = new RenderMaterial.Params(mat);\r\n params.diffuseColor = colorDefFromJson(json.diffuseColor);\r\n if (json.diffuse !== undefined)\r\n params.diffuse = JsonUtils.asDouble(json.diffuse);\r\n\r\n params.specularColor = colorDefFromJson(json.specularColor);\r\n if (json.specular !== undefined)\r\n params.specular = JsonUtils.asDouble(json.specular);\r\n\r\n params.reflectColor = colorDefFromJson(json.reflectColor);\r\n if (json.reflect !== undefined)\r\n params.reflect = JsonUtils.asDouble(json.reflect);\r\n\r\n if (json.specularExponent !== undefined)\r\n params.specularExponent = json.specularExponent;\r\n\r\n if (undefined !== json.transparency)\r\n params.alpha = 1.0 - json.transparency;\r\n\r\n params.refract = JsonUtils.asDouble(json.refract);\r\n params.shadows = JsonUtils.asBool(json.shadows);\r\n params.ambient = JsonUtils.asDouble(json.ambient);\r\n\r\n if (undefined !== json.textureMapping)\r\n params.textureMapping = textureMappingFromJson(json.textureMapping.texture, options);\r\n\r\n // eslint-disable-next-line deprecation/deprecation\r\n return options.system.createMaterial(params, options.iModel);\r\n}\r\n\r\nfunction getModifiers(primitive: Imdl.Primitive): { viOrigin?: Point3d, instances?: InstancedGraphicParams } {\r\n const mod = primitive.modifier;\r\n switch (mod?.type) {\r\n case \"instances\":\r\n return {\r\n instances: {\r\n ...mod,\r\n transformCenter: Point3d.fromJSON(mod.transformCenter),\r\n range: mod.range ? Range3d.fromJSON(mod.range) : undefined,\r\n },\r\n };\r\n case \"viewIndependentOrigin\":\r\n return {\r\n viOrigin: Point3d.fromJSON(mod.origin),\r\n };\r\n default:\r\n return { };\r\n }\r\n}\r\n\r\nfunction createPrimitiveGeometry(primitive: Imdl.Primitive, options: GraphicsOptions, viOrigin: Point3d | undefined): RenderGeometry | undefined {\r\n switch (primitive.type) {\r\n case \"point\":\r\n return options.system.createPointStringGeometry({\r\n ...primitive.params,\r\n vertices: toVertexTable(primitive.params.vertices),\r\n indices: new VertexIndices(primitive.params.indices),\r\n }, viOrigin);\r\n case \"polyline\":\r\n return options.system.createPolylineGeometry({\r\n ...primitive.params,\r\n vertices: toVertexTable(primitive.params.vertices),\r\n polyline: {\r\n ...primitive.params.polyline,\r\n indices: new VertexIndices(primitive.params.polyline.indices),\r\n prevIndices: new VertexIndices(primitive.params.polyline.prevIndices),\r\n },\r\n }, viOrigin);\r\n case \"mesh\": {\r\n const surf = primitive.params.surface;\r\n let material;\r\n if (surf.material) {\r\n if (!surf.material.isAtlas)\r\n material = createSurfaceMaterial(getMaterial(surf.material.material, options));\r\n else\r\n material = surf.material;\r\n }\r\n\r\n let textureMapping;\r\n if (surf.textureMapping) {\r\n let texture;\r\n if (typeof surf.textureMapping.texture === \"string\") {\r\n texture = options.textures.get(surf.textureMapping.texture);\r\n } else {\r\n const gradient = Gradient.Symb.fromJSON(surf.textureMapping.texture);\r\n texture = options.system.getGradientTexture(gradient, options.iModel);\r\n }\r\n\r\n if (texture)\r\n textureMapping = { texture, alwaysDisplayed: surf.textureMapping.alwaysDisplayed };\r\n }\r\n\r\n return options.system.createMeshGeometry({\r\n ...primitive.params,\r\n edges: primitive.params.edges ? edgeParamsFromImdl(primitive.params.edges) : undefined,\r\n vertices: toVertexTable(primitive.params.vertices),\r\n auxChannels: primitive.params.auxChannels ? AuxChannelTable.fromJSON(primitive.params.auxChannels) : undefined,\r\n surface: {\r\n ...primitive.params.surface,\r\n material,\r\n textureMapping,\r\n indices: new VertexIndices(primitive.params.surface.indices),\r\n },\r\n }, viOrigin);\r\n }\r\n }\r\n}\r\n\r\nfunction createPrimitiveGraphic(primitive: Imdl.Primitive, options: GraphicsOptions): RenderGraphic | undefined {\r\n const mods = getModifiers(primitive);\r\n const geometry = createPrimitiveGeometry(primitive, options, mods.viOrigin);\r\n return geometry ? options.system.createRenderGraphic(geometry, mods.instances) : undefined;\r\n}\r\n\r\nfunction createPatternGeometries(primitives: Imdl.Primitive[], options: GraphicsOptions): RenderGeometry[] {\r\n const geometries = [];\r\n for (const primitive of primitives) {\r\n const geometry = createPrimitiveGeometry(primitive, options, undefined);\r\n if (geometry)\r\n geometries.push(geometry);\r\n }\r\n\r\n return geometries;\r\n}\r\n\r\nfunction createPatternGraphic(params: Imdl.AreaPatternParams, options: GraphicsOptions): RenderGraphic | undefined {\r\n const geometries = options.patterns.get(params.symbolName);\r\n if (!geometries || geometries.length === 0)\r\n return undefined;\r\n\r\n const clip = ClipVector.fromJSON(params.clip);\r\n const clipVolume = clip?.isValid ? options.system.createClipVolume(clip) : undefined;\r\n if (!clipVolume)\r\n return undefined;\r\n\r\n const viewIndependentOrigin = params.viewIndependentOrigin ? Point3d.fromJSON(params.viewIndependentOrigin) : undefined;\r\n const pattern = options.system.createAreaPattern({\r\n xyOffsets: params.xyOffsets,\r\n featureId: params.featureId,\r\n orgTransform: Transform.fromJSON(params.orgTransform),\r\n origin: Point2d.fromJSON(params.origin),\r\n scale: params.scale,\r\n spacing: Point2d.fromJSON(params.spacing),\r\n patternToModel: Transform.fromJSON(params.modelTransform),\r\n range: Range3d.fromJSON(params.range),\r\n symbolTranslation: Point3d.fromJSON(params.symbolTranslation),\r\n viewIndependentOrigin,\r\n });\r\n\r\n if (!pattern)\r\n return undefined;\r\n\r\n const branch = new GraphicBranch(true);\r\n for (const geometry of geometries) {\r\n const graphic = options.system.createRenderGraphic(geometry, pattern);\r\n if (graphic)\r\n branch.add(graphic);\r\n }\r\n\r\n return branch.isEmpty ? undefined : options.system.createGraphicBranch(branch, Transform.createIdentity(), { clipVolume });\r\n}\r\n\r\nfunction createNodeGraphics(node: Imdl.Node, options: GraphicsOptions): RenderGraphic[] {\r\n const graphics = [];\r\n for (const primitive of node.primitives) {\r\n const graphic = primitive.type === \"pattern\" ? createPatternGraphic(primitive.params, options) : createPrimitiveGraphic(primitive, options);\r\n if (graphic)\r\n graphics.push(graphic);\r\n }\r\n\r\n return graphics;\r\n}\r\n\r\n/** @internal */\r\nexport async function decodeImdlGraphics(options: ImdlDecodeOptions): Promise<RenderGraphic | undefined> {\r\n const textures = await loadNamedTextures(options);\r\n if (options.isCanceled && options.isCanceled())\r\n return undefined;\r\n\r\n const patterns = new Map<string, RenderGeometry[]>();\r\n const graphicsOptions = { ...options, textures, patterns };\r\n\r\n for (const [name, primitives] of options.document.patterns)\r\n patterns.set(name, createPatternGeometries(primitives, graphicsOptions));\r\n\r\n const system = options.system;\r\n const graphics: RenderGraphic[] = [];\r\n for (const node of options.document.nodes) {\r\n const nodeGraphics = createNodeGraphics(node, graphicsOptions);\r\n if (nodeGraphics.length === 0)\r\n continue;\r\n\r\n if (undefined !== node.layerId) {\r\n const layerGraphic = 1 === nodeGraphics.length ? nodeGraphics[0] : system.createGraphicList(nodeGraphics);\r\n graphics.push(system.createGraphicLayer(layerGraphic, node.layerId));\r\n } else if (undefined !== node.animationNodeId) {\r\n const branch = new GraphicBranch(true);\r\n branch.animationId = node.animationId;\r\n branch.animationNodeId = node.animationNodeId;\r\n branch.entries.push(...nodeGraphics);\r\n graphics.push(system.createBranch(branch, Transform.createIdentity()));\r\n } else {\r\n graphics.push(...nodeGraphics);\r\n }\r\n }\r\n\r\n switch (graphics.length) {\r\n case 0: return undefined;\r\n case 1: return graphics[0];\r\n default: return system.createGraphicList(graphics);\r\n }\r\n}\r\n"]}
@@ -0,0 +1,181 @@
1
+ /** @packageDocumentation
2
+ * @module Tiles
3
+ */
4
+ import { UintArray } from "@itwin/core-bentley";
5
+ import { LowAndHighXYZ, XYAndZ } from "@itwin/core-geometry";
6
+ import { ColorDefProps, FeatureIndexType, FillFlags, Gradient, LinePixels, PolylineTypeFlags, QParams2dProps, QParams3dProps } from "@itwin/core-common";
7
+ import { EdgeTable } from "../render/primitives/EdgeParams";
8
+ import { SurfaceMaterialAtlas, SurfaceType } from "../render/primitives/SurfaceParams";
9
+ import { AuxChannelTableProps } from "../render/primitives/AuxChannelTable";
10
+ import { ImdlAreaPattern, ImdlDocument } from "./ImdlSchema";
11
+ /** Types comprising the parsed representation of an ImdlDocument, produced by [[parseImdlDocument]] and consumed by [[decodeImdlGraphics]].
12
+ * All of the types are required to support [structured cloning](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) so that they
13
+ * can be passed between workers and the main JavaScript thread.
14
+ * @internal
15
+ */
16
+ export declare namespace ImdlModel {
17
+ interface VertexTable {
18
+ data: Uint8Array;
19
+ usesUnquantizedPositions?: boolean;
20
+ qparams: QParams3dProps;
21
+ width: number;
22
+ height: number;
23
+ hasTranslucency: boolean;
24
+ uniformColor?: ColorDefProps;
25
+ featureIndexType: FeatureIndexType;
26
+ uniformFeatureID?: number;
27
+ numVertices: number;
28
+ numRgbaPerVertex: number;
29
+ uvParams?: QParams2dProps;
30
+ }
31
+ interface PointStringParams {
32
+ vertices: VertexTable;
33
+ indices: Uint8Array;
34
+ weight: number;
35
+ }
36
+ interface TesselatedPolyline {
37
+ indices: Uint8Array;
38
+ prevIndices: Uint8Array;
39
+ nextIndicesAndParams: Uint8Array;
40
+ }
41
+ interface PolylineParams {
42
+ vertices: VertexTable;
43
+ polyline: TesselatedPolyline;
44
+ isPlanar: boolean;
45
+ type: PolylineTypeFlags;
46
+ weight: number;
47
+ linePixels: LinePixels;
48
+ }
49
+ interface SegmentEdgeParams {
50
+ indices: Uint8Array;
51
+ endPointAndQuadIndices: Uint8Array;
52
+ }
53
+ interface SilhouetteParams extends SegmentEdgeParams {
54
+ normalPairs: Uint8Array;
55
+ }
56
+ interface IndexedEdgeParams {
57
+ indices: Uint8Array;
58
+ edges: EdgeTable;
59
+ }
60
+ interface EdgeParams {
61
+ weight: number;
62
+ linePixels: LinePixels;
63
+ segments?: SegmentEdgeParams;
64
+ silhouettes?: SilhouetteParams;
65
+ polylines?: TesselatedPolyline;
66
+ indexed?: IndexedEdgeParams;
67
+ }
68
+ interface SurfaceMaterialParams {
69
+ alpha?: number;
70
+ diffuse?: {
71
+ color?: ColorDefProps;
72
+ weight?: number;
73
+ };
74
+ specular?: {
75
+ color?: ColorDefProps;
76
+ weight?: number;
77
+ exponent?: number;
78
+ };
79
+ }
80
+ interface SurfaceRenderMaterial {
81
+ isAtlas: false;
82
+ material: string | SurfaceMaterialParams;
83
+ }
84
+ type SurfaceMaterial = SurfaceRenderMaterial | SurfaceMaterialAtlas;
85
+ interface SurfaceParams {
86
+ type: SurfaceType;
87
+ indices: Uint8Array;
88
+ fillFlags: FillFlags;
89
+ hasBakedLighting: boolean;
90
+ material?: SurfaceMaterial;
91
+ textureMapping?: {
92
+ texture: string | Gradient.SymbProps;
93
+ alwaysDisplayed: boolean;
94
+ };
95
+ }
96
+ interface MeshParams {
97
+ vertices: VertexTable;
98
+ surface: SurfaceParams;
99
+ edges?: EdgeParams;
100
+ isPlanar: boolean;
101
+ auxChannels?: AuxChannelTableProps;
102
+ }
103
+ interface Instances {
104
+ type: "instances";
105
+ count: number;
106
+ transforms: Float32Array;
107
+ transformCenter: XYAndZ;
108
+ featureIds?: Uint8Array;
109
+ symbologyOverrides?: Uint8Array;
110
+ range?: LowAndHighXYZ;
111
+ }
112
+ interface ViewIndependentOrigin {
113
+ type: "viewIndependentOrigin";
114
+ origin: XYAndZ;
115
+ }
116
+ type PrimitiveModifier = Instances | ViewIndependentOrigin;
117
+ type Primitive = {
118
+ params: MeshParams;
119
+ modifier?: PrimitiveModifier;
120
+ type: "mesh";
121
+ } | {
122
+ params: PointStringParams;
123
+ modifier?: PrimitiveModifier;
124
+ type: "point";
125
+ } | {
126
+ params: PolylineParams;
127
+ modifier?: PrimitiveModifier;
128
+ type: "polyline";
129
+ };
130
+ type AreaPatternParams = Omit<ImdlAreaPattern, "xyOffsets"> & {
131
+ xyOffsets: Float32Array;
132
+ };
133
+ type NodePrimitive = Primitive | {
134
+ params: AreaPatternParams;
135
+ modifier?: never;
136
+ type: "pattern";
137
+ };
138
+ interface BasicNode {
139
+ primitives: NodePrimitive[];
140
+ animationNodeId?: never;
141
+ animationId?: never;
142
+ layerId?: never;
143
+ }
144
+ interface AnimationNode {
145
+ primitives: NodePrimitive[];
146
+ animationNodeId: number;
147
+ animationId?: string;
148
+ layerId?: never;
149
+ }
150
+ interface Layer {
151
+ primitives: NodePrimitive[];
152
+ layerId: string;
153
+ animationNodeId?: never;
154
+ animationId?: never;
155
+ }
156
+ type Node = BasicNode | AnimationNode | Layer;
157
+ interface SingleModelFeatureTable {
158
+ multiModel: false;
159
+ data: Uint32Array;
160
+ numFeatures: number;
161
+ animationNodeIds?: UintArray;
162
+ numSubCategories?: never;
163
+ }
164
+ interface MultiModelFeatureTable {
165
+ multiModel: true;
166
+ data: Uint32Array;
167
+ numFeatures: number;
168
+ numSubCategories: number;
169
+ animationNodeIds?: UintArray;
170
+ }
171
+ type FeatureTable = SingleModelFeatureTable | MultiModelFeatureTable;
172
+ interface Document {
173
+ featureTable: FeatureTable;
174
+ nodes: Node[];
175
+ patterns: Map<string, Primitive[]>;
176
+ rtcCenter?: XYAndZ;
177
+ binaryData: Uint8Array;
178
+ json: ImdlDocument;
179
+ }
180
+ }
181
+ //# sourceMappingURL=ImdlModel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImdlModel.d.ts","sourceRoot":"","sources":["../../../src/imdl/ImdlModel.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7D,OAAO,EACL,aAAa,EAAE,gBAAgB,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,iBAAiB,EAAE,cAAc,EAAE,cAAc,EACpH,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC;AAC5D,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAC;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE7D;;;;GAIG;AACH,yBAAiB,SAAS,CAAC;IACzB,UAAiB,WAAW;QAC1B,IAAI,EAAE,UAAU,CAAC;QACjB,wBAAwB,CAAC,EAAE,OAAO,CAAC;QACnC,OAAO,EAAE,cAAc,CAAC;QACxB,KAAK,EAAE,MAAM,CAAC;QACd,MAAM,EAAE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Y,IAAI,GAAG,SAAS,GAAG,aAAa,GAAG,KAAK,CAAC;IAErD,UAAiB,uBAAuB;QACtC,UAAU,EAAE,KAAK,CAAC;QAClB,IAAI,EAAE,WAAW,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,CAAC,EAAE,SAAS,CAAC;QAC7B,gBAAgB,CAAC,EAAE,KAAK,CAAC;KAC1B;IAED,UAAiB,sBAAsB;QACrC,UAAU,EAAE,IAAI,CAAC;QACjB,IAAI,EAAE,WAAW,CAAC;QAClB,WAAW,EAAE,MAAM,CAAC;QACpB,gBAAgB,EAAE,MAAM,CAAC;QACzB,gBAAgB,CAAC,EAAE,SAAS,CAAC;KAC9B;IAED,KAAY,YAAY,GAAG,uBAAuB,GAAG,sBAAsB,CAAC;IAE5E,UAAiB,QAAQ;QACvB,YAAY,EAAE,YAAY,CAAC;QAC3B,KAAK,EAAE,IAAI,EAAE,CAAC;QACd,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,SAAS,EAAE,CAAC,CAAC;QACnC,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,UAAU,CAAC;QACvB,IAAI,EAAE,YAAY,CAAC;KACpB;CACF"}
@@ -0,0 +1,10 @@
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
+ /** @packageDocumentation
7
+ * @module Tiles
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ //# sourceMappingURL=ImdlModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ImdlModel.js","sourceRoot":"","sources":["../../../src/imdl/ImdlModel.ts"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG","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/** @packageDocumentation\r\n * @module Tiles\r\n */\r\n\r\nimport { UintArray } from \"@itwin/core-bentley\";\r\nimport { LowAndHighXYZ, XYAndZ } from \"@itwin/core-geometry\";\r\nimport {\r\n ColorDefProps, FeatureIndexType, FillFlags, Gradient, LinePixels, PolylineTypeFlags, QParams2dProps, QParams3dProps,\r\n} from \"@itwin/core-common\";\r\nimport { EdgeTable } from \"../render/primitives/EdgeParams\";\r\nimport { SurfaceMaterialAtlas, SurfaceType } from \"../render/primitives/SurfaceParams\";\r\nimport { AuxChannelTableProps } from \"../render/primitives/AuxChannelTable\";\r\nimport { ImdlAreaPattern, ImdlDocument } from \"./ImdlSchema\";\r\n\r\n/** Types comprising the parsed representation of an ImdlDocument, produced by [[parseImdlDocument]] and consumed by [[decodeImdlGraphics]].\r\n * All of the types are required to support [structured cloning](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm) so that they\r\n * can be passed between workers and the main JavaScript thread.\r\n * @internal\r\n */\r\nexport namespace ImdlModel {\r\n export interface VertexTable {\r\n data: Uint8Array;\r\n usesUnquantizedPositions?: boolean;\r\n qparams: QParams3dProps;\r\n width: number;\r\n height: number;\r\n hasTranslucency: boolean;\r\n uniformColor?: ColorDefProps;\r\n featureIndexType: FeatureIndexType;\r\n uniformFeatureID?: number;\r\n numVertices: number;\r\n numRgbaPerVertex: number;\r\n uvParams?: QParams2dProps;\r\n }\r\n\r\n export interface PointStringParams {\r\n vertices: VertexTable;\r\n indices: Uint8Array;\r\n weight: number;\r\n }\r\n\r\n export interface TesselatedPolyline {\r\n indices: Uint8Array;\r\n prevIndices: Uint8Array;\r\n nextIndicesAndParams: Uint8Array;\r\n }\r\n\r\n export interface PolylineParams {\r\n vertices: VertexTable;\r\n polyline: TesselatedPolyline;\r\n isPlanar: boolean;\r\n type: PolylineTypeFlags;\r\n weight: number;\r\n linePixels: LinePixels;\r\n }\r\n\r\n export interface SegmentEdgeParams {\r\n indices: Uint8Array;\r\n endPointAndQuadIndices: Uint8Array;\r\n }\r\n\r\n export interface SilhouetteParams extends SegmentEdgeParams {\r\n normalPairs: Uint8Array;\r\n }\r\n\r\n export interface IndexedEdgeParams {\r\n indices: Uint8Array;\r\n edges: EdgeTable;\r\n }\r\n\r\n export interface EdgeParams {\r\n weight: number;\r\n linePixels: LinePixels;\r\n segments?: SegmentEdgeParams;\r\n silhouettes?: SilhouetteParams;\r\n polylines?: TesselatedPolyline;\r\n indexed?: IndexedEdgeParams;\r\n }\r\n\r\n export interface SurfaceMaterialParams {\r\n alpha?: number;\r\n diffuse?: {\r\n color?: ColorDefProps;\r\n weight?: number;\r\n };\r\n specular?: {\r\n color?: ColorDefProps;\r\n weight?: number;\r\n exponent?: number;\r\n };\r\n }\r\n\r\n export interface SurfaceRenderMaterial {\r\n isAtlas: false;\r\n material: string | SurfaceMaterialParams;\r\n }\r\n\r\n export type SurfaceMaterial = SurfaceRenderMaterial | SurfaceMaterialAtlas;\r\n\r\n export interface SurfaceParams {\r\n type: SurfaceType;\r\n indices: Uint8Array;\r\n fillFlags: FillFlags;\r\n hasBakedLighting: boolean;\r\n material?: SurfaceMaterial;\r\n textureMapping?: {\r\n texture: string | Gradient.SymbProps;\r\n alwaysDisplayed: boolean;\r\n };\r\n }\r\n\r\n export interface MeshParams {\r\n vertices: VertexTable;\r\n surface: SurfaceParams;\r\n edges?: EdgeParams;\r\n isPlanar: boolean;\r\n auxChannels?: AuxChannelTableProps;\r\n }\r\n\r\n export interface Instances {\r\n type: \"instances\";\r\n count: number;\r\n transforms: Float32Array;\r\n transformCenter: XYAndZ;\r\n featureIds?: Uint8Array;\r\n symbologyOverrides?: Uint8Array;\r\n range?: LowAndHighXYZ;\r\n }\r\n\r\n export interface ViewIndependentOrigin {\r\n type: \"viewIndependentOrigin\";\r\n origin: XYAndZ;\r\n }\r\n\r\n export type PrimitiveModifier = Instances | ViewIndependentOrigin;\r\n\r\n export type Primitive = {\r\n params: MeshParams;\r\n modifier?: PrimitiveModifier;\r\n type: \"mesh\";\r\n } | {\r\n params: PointStringParams;\r\n modifier?: PrimitiveModifier;\r\n type: \"point\";\r\n } | {\r\n params: PolylineParams;\r\n modifier?: PrimitiveModifier;\r\n type: \"polyline\";\r\n };\r\n\r\n export type AreaPatternParams = Omit<ImdlAreaPattern, \"xyOffsets\"> & {\r\n xyOffsets: Float32Array;\r\n };\r\n\r\n export type NodePrimitive = Primitive | {\r\n params: AreaPatternParams;\r\n modifier?: never;\r\n type: \"pattern\";\r\n };\r\n\r\n export interface BasicNode {\r\n primitives: NodePrimitive[];\r\n animationNodeId?: never;\r\n animationId?: never;\r\n layerId?: never;\r\n }\r\n\r\n export interface AnimationNode {\r\n primitives: NodePrimitive[];\r\n animationNodeId: number;\r\n animationId?: string;\r\n layerId?: never;\r\n }\r\n\r\n export interface Layer {\r\n primitives: NodePrimitive[];\r\n layerId: string;\r\n animationNodeId?: never;\r\n animationId?: never;\r\n }\r\n\r\n export type Node = BasicNode | AnimationNode | Layer;\r\n\r\n export interface SingleModelFeatureTable {\r\n multiModel: false;\r\n data: Uint32Array;\r\n numFeatures: number;\r\n animationNodeIds?: UintArray;\r\n numSubCategories?: never;\r\n }\r\n\r\n export interface MultiModelFeatureTable {\r\n multiModel: true;\r\n data: Uint32Array;\r\n numFeatures: number;\r\n numSubCategories: number;\r\n animationNodeIds?: UintArray;\r\n }\r\n\r\n export type FeatureTable = SingleModelFeatureTable | MultiModelFeatureTable;\r\n\r\n export interface Document {\r\n featureTable: FeatureTable;\r\n nodes: Node[];\r\n patterns: Map<string, Primitive[]>;\r\n rtcCenter?: XYAndZ;\r\n binaryData: Uint8Array;\r\n json: ImdlDocument;\r\n }\r\n}\r\n"]}