@itwin/frontend-tiles 5.0.0-dev.8 → 5.0.0-dev.82

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 (62) hide show
  1. package/CHANGELOG.md +46 -1
  2. package/lib/cjs/BatchedModelGroups.js +15 -10
  3. package/lib/cjs/BatchedModelGroups.js.map +1 -1
  4. package/lib/cjs/BatchedModels.js +5 -2
  5. package/lib/cjs/BatchedModels.js.map +1 -1
  6. package/lib/cjs/BatchedSpatialTileTreeRefs.js +18 -2
  7. package/lib/cjs/BatchedSpatialTileTreeRefs.js.map +1 -1
  8. package/lib/cjs/BatchedTile.js +5 -0
  9. package/lib/cjs/BatchedTile.js.map +1 -1
  10. package/lib/cjs/BatchedTileContentReader.js +3 -0
  11. package/lib/cjs/BatchedTileContentReader.js.map +1 -1
  12. package/lib/cjs/BatchedTileTree.d.ts +1 -1
  13. package/lib/cjs/BatchedTileTree.d.ts.map +1 -1
  14. package/lib/cjs/BatchedTileTree.js +7 -2
  15. package/lib/cjs/BatchedTileTree.js.map +1 -1
  16. package/lib/cjs/BatchedTileTreeReference.js +4 -0
  17. package/lib/cjs/BatchedTileTreeReference.js.map +1 -1
  18. package/lib/cjs/BatchedTilesetReader.js +3 -0
  19. package/lib/cjs/BatchedTilesetReader.js.map +1 -1
  20. package/lib/cjs/FrontendTiles.js +1 -1
  21. package/lib/cjs/FrontendTiles.js.map +1 -1
  22. package/lib/cjs/GraphicsProvider/GraphicRepresentationProvider.d.ts +8 -15
  23. package/lib/cjs/GraphicsProvider/GraphicRepresentationProvider.d.ts.map +1 -1
  24. package/lib/cjs/GraphicsProvider/GraphicRepresentationProvider.js +1 -14
  25. package/lib/cjs/GraphicsProvider/GraphicRepresentationProvider.js.map +1 -1
  26. package/lib/cjs/GraphicsProvider/GraphicsProvider.js +1 -1
  27. package/lib/cjs/GraphicsProvider/GraphicsProvider.js.map +1 -1
  28. package/lib/cjs/IndexedDBCache.js +3 -0
  29. package/lib/cjs/IndexedDBCache.js.map +1 -1
  30. package/lib/cjs/ModelGroupDisplayTransforms.js +2 -1
  31. package/lib/cjs/ModelGroupDisplayTransforms.js.map +1 -1
  32. package/lib/esm/BatchedModelGroups.js +15 -10
  33. package/lib/esm/BatchedModelGroups.js.map +1 -1
  34. package/lib/esm/BatchedModels.js +5 -2
  35. package/lib/esm/BatchedModels.js.map +1 -1
  36. package/lib/esm/BatchedSpatialTileTreeRefs.js +18 -2
  37. package/lib/esm/BatchedSpatialTileTreeRefs.js.map +1 -1
  38. package/lib/esm/BatchedTile.js +5 -0
  39. package/lib/esm/BatchedTile.js.map +1 -1
  40. package/lib/esm/BatchedTileContentReader.js +3 -0
  41. package/lib/esm/BatchedTileContentReader.js.map +1 -1
  42. package/lib/esm/BatchedTileTree.d.ts +1 -1
  43. package/lib/esm/BatchedTileTree.d.ts.map +1 -1
  44. package/lib/esm/BatchedTileTree.js +7 -2
  45. package/lib/esm/BatchedTileTree.js.map +1 -1
  46. package/lib/esm/BatchedTileTreeReference.js +4 -0
  47. package/lib/esm/BatchedTileTreeReference.js.map +1 -1
  48. package/lib/esm/BatchedTilesetReader.js +3 -0
  49. package/lib/esm/BatchedTilesetReader.js.map +1 -1
  50. package/lib/esm/FrontendTiles.js +1 -1
  51. package/lib/esm/FrontendTiles.js.map +1 -1
  52. package/lib/esm/GraphicsProvider/GraphicRepresentationProvider.d.ts +8 -15
  53. package/lib/esm/GraphicsProvider/GraphicRepresentationProvider.d.ts.map +1 -1
  54. package/lib/esm/GraphicsProvider/GraphicRepresentationProvider.js +1 -13
  55. package/lib/esm/GraphicsProvider/GraphicRepresentationProvider.js.map +1 -1
  56. package/lib/esm/GraphicsProvider/GraphicsProvider.js +1 -1
  57. package/lib/esm/GraphicsProvider/GraphicsProvider.js.map +1 -1
  58. package/lib/esm/IndexedDBCache.js +3 -0
  59. package/lib/esm/IndexedDBCache.js.map +1 -1
  60. package/lib/esm/ModelGroupDisplayTransforms.js +2 -1
  61. package/lib/esm/ModelGroupDisplayTransforms.js.map +1 -1
  62. package/package.json +19 -19
@@ -2,17 +2,12 @@ import { AccessToken } from "@itwin/core-bentley";
2
2
  /** The expected format of the Graphic Representation
3
3
  * @beta
4
4
  */
5
- export type GraphicRepresentationFormat = "IMDL" | "3DTILES" | string;
5
+ export type GraphicRepresentationFormat = "3DFT" | "3DTiles" | "CESIUM" | "IMODEL" | string;
6
6
  /** Graphic representations are generated from Data Sources.
7
7
  * The status of a Graphic Representation indicates the progress of that generation process.
8
8
  * @beta
9
9
  */
10
- export declare enum GraphicRepresentationStatus {
11
- InProgress = "In progress",
12
- Complete = "Complete",
13
- NotStarted = "Not started",
14
- Failed = "Failed"
15
- }
10
+ export type GraphicRepresentationStatus = "Complete" | "InProgress" | "Invalid" | "NotStarted";
16
11
  /**
17
12
  * Represents a data source for a graphic representation.
18
13
  * A data source is usually higher-fidelity and contains more information, but may not be as well suited for visualization
@@ -38,7 +33,7 @@ export interface DataSource {
38
33
  * @see [[queryGraphicRepresentations]] for its construction as a representation of the data produced by a query of data sources.
39
34
  * @beta
40
35
  */
41
- export type GraphicRepresentation = {
36
+ export interface GraphicRepresentation {
42
37
  /** The display name of the Graphic Representation */
43
38
  displayName: string;
44
39
  /** The unique identifier for the Graphic Representation */
@@ -55,13 +50,11 @@ export type GraphicRepresentation = {
55
50
  * For example, a GraphicRepresentation in the 3D Tiles format might have a dataSource that is a specific iModel changeset.
56
51
  */
57
52
  dataSource: DataSource;
58
- } & ({
59
- status: Omit<GraphicRepresentationStatus, GraphicRepresentationStatus.Complete>;
60
- url?: string;
61
- } | {
62
- status: GraphicRepresentationStatus.Complete;
63
- url: string;
64
- });
53
+ /** The url of the graphic representation
54
+ * @note The url can only be guaranteed to be valid if the status is complete.
55
+ */
56
+ url: string | undefined;
57
+ }
65
58
  /** Creates a URL used to query for Graphic Representations
66
59
  * @internal
67
60
  */
@@ -1 +1 @@
1
- {"version":3,"file":"GraphicRepresentationProvider.d.ts","sourceRoot":"","s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,SAAS,CAAC,EAAE,OAAO,CAAC;IAAC,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAe5L;AAED;;GAEG;AACH,MAAM,WAAW,+BAA+B;IAC9C,yDAAyD;IACzD,WAAW,EAAE,WAAW,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,UAAU,EAAE,UAAU,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,2BAA2B,CAAC;IACpC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oIAAoI;IACpI,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAuB,2BAA2B,CAAC,IAAI,EAAE,+BAA+B,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CA4EtI;AAED;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,wDAAwD;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,UAAU,EAAE,UAAU,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,2BAA2B,CAAC;IACpC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAAC,IAAI,EAAE,kCAAkC,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAsCvH"}
1
+ {"version":3,"file":"GraphicRepresentationProvider.d.ts","sourceRoot":"","sources":["../../../src/GraphicsProvider/GraphicRepresentationProvider.ts"],"names":[],"mappings":"AAKA,OAAO,EA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,UAAU,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,2BAA2B,CAAC;IACpC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oIAAoI;IACpI,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,iCAAiC;IACjC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,wBAAuB,2BAA2B,CAAC,IAAI,EAAE,+BAA+B,GAAG,qBAAqB,CAAC,qBAAqB,CAAC,CA6CtI;AAED;;GAEG;AACH,MAAM,WAAW,kCAAkC;IACjD,wDAAwD;IACxD,WAAW,EAAE,WAAW,CAAC;IACzB;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB,qEAAqE;IACrE,UAAU,EAAE,UAAU,CAAC;IACvB;;OAEG;IACH,MAAM,EAAE,2BAA2B,CAAC;IACpC,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,gFAAgF;IAChF,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED;;;;;GAKG;AACH,wBAAsB,8BAA8B,CAAC,IAAI,EAAE,kCAAkC,GAAG,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC,CAsCvH"}
@@ -5,18 +5,6 @@
5
5
  import { Logger } from "@itwin/core-bentley";
6
6
  import { loggerCategory } from "../LoggerCategory";
7
7
  import { IModelApp, ITWINJS_CORE_VERSION } from "@itwin/core-frontend";
8
- /** Graphic representations are generated from Data Sources.
9
- * The status of a Graphic Representation indicates the progress of that generation process.
10
- * @beta
11
- */
12
- // ###TODO this needs to be expanded to include more statuses, and/or "failed" needs to be replaced with "invalid".
13
- export var GraphicRepresentationStatus;
14
- (function (GraphicRepresentationStatus) {
15
- GraphicRepresentationStatus["InProgress"] = "In progress";
16
- GraphicRepresentationStatus["Complete"] = "Complete";
17
- GraphicRepresentationStatus["NotStarted"] = "Not started";
18
- GraphicRepresentationStatus["Failed"] = "Failed";
19
- })(GraphicRepresentationStatus || (GraphicRepresentationStatus = {}));
20
8
  /** Creates a URL used to query for Graphic Representations
21
9
  * @internal
22
10
  */
@@ -58,7 +46,7 @@ export async function* queryGraphicRepresentations(args) {
58
46
  Logger.logError(loggerCategory, `Failed loading Graphics Data for Source ${args.dataSource.id}`);
59
47
  break;
60
48
  }
61
- const foundSources = result.exports.filter((x) => x.request.exportType === args.dataSource.type && (args.includeIncomplete || x.status === GraphicRepresentationStatus.Complete));
49
+ const foundSources = result.exports.filter((x) => x.request.exportType === args.dataSource.type && (args.includeIncomplete || x.status === "Complete"));
62
50
  for (const foundSource of foundSources) {
63
51
  const graphicRepresentation = {
64
52
  displayName: foundSource.displayName,
@@ -1 +1 @@
1
- {"version":3,"file":"GraphicRepresentationProvider.js","sourceRoot":"","sources":["../../../src/GraphicsProvider/GraphicRepresentationProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAe,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAQvE;;;GAGG;AACH,mHAAmH;AACnH,MAAM,CAAN,IAAY,2BAKX;AALD,WAAY,2BAA2B;IACrC,yDAA0B,CAAA;IAC1B,oDAAqB,CAAA;IACrB,yDAA0B,CAAA;IAC1B,gDAAiB,CAAA;AACnB,CAAC,EALW,2BAA2B,KAA3B,2BAA2B,QAKtC;AAyDD;;GAEG;AACH,MAAM,UAAU,oCAAoC,CAAC,IAA+H;IAClL,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;IACxC,IAAI,GAAG,GAAG,WAAW,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,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACtC,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,eAAe,CAAC;IAC9C,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\nimport { loggerCategory } from \"../LoggerCategory\";\nimport { IModelApp, ITWINJS_CORE_VERSION } from \"@itwin/core-frontend\";\n\n/** The expected format of the Graphic Representation\n * @beta\n */\n/* eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents */\nexport type GraphicRepresentationFormat = \"IMDL\" | \"3DTILES\" | string;\n\n/** Graphic representations are generated from Data Sources.\n * The status of a Graphic Representation indicates the progress of that generation process.\n * @beta\n */\n// ###TODO this needs to be expanded to include more statuses, and/or \"failed\" needs to be replaced with \"invalid\".\nexport enum GraphicRepresentationStatus {\n InProgress = \"In progress\",\n Complete = \"Complete\",\n NotStarted = \"Not started\",\n Failed = \"Failed\",\n}\n\n/**\n * Represents a data source for a graphic representation.\n * A data source is usually higher-fidelity and contains more information, but may not be as well suited for visualization\n * as a graphic representation.\n * @beta\n */\nexport interface DataSource {\n /** The iTwinId associated with the DataSource */\n iTwinId: string;\n /** The unique identifier of a DataSource.\n * For example, a DataSource of type \"IMODEL\" has an iModelId which would be attributed to this value.\n */\n id: string;\n /** The unique identifier for a specific version of a DataSource.\n * For example, if a specific version of an iModel is desired, the iModel's changesetId would be attributed to this value.\n */\n changeId?: string;\n /** The type of the data source. For example, a DataSource can be of type \"IMODEL\" or \"RealityData\" */\n type: string;\n}\n\n/** Represents a visual representation of a data source, for example a 3d tileset.\n * A data source can be an iModel, reality data, or other kind of graphical data.\n * @see [[queryGraphicRepresentations]] for its construction as a representation of the data produced by a query of data sources.\n * @beta\n */\nexport type GraphicRepresentation = {\n /** The display name of the Graphic Representation */\n displayName: string;\n /** The unique identifier for the Graphic Representation */\n representationId: string;\n /** The status of the generation of the Graphic Representation from its Data Source.\n * @see [[GraphicRepresentationStatus]] for possible values.\n */\n status: GraphicRepresentationStatus;\n /** The expected format of the Graphic Representation\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** The data source that the representation originates from.\n * For example, a GraphicRepresentation in the 3D Tiles format might have a dataSource that is a specific iModel changeset.\n */\n dataSource: DataSource;\n /** The url of the graphic representation\n * @note The url can only be guaranteed to be valid if the status is complete.\n * Therefore, the url is optional if the status is not complete, and required if the status is complete.\n */\n} & ({\n status: Omit<GraphicRepresentationStatus, GraphicRepresentationStatus.Complete>;\n url?: string;\n} | {\n status: GraphicRepresentationStatus.Complete;\n url: string;\n});\n\n/** Creates a URL used to query for Graphic Representations\n * @internal\n */\nexport function createGraphicRepresentationsQueryUrl(args: { sourceId: string, sourceType: string, urlPrefix?: string, changeId?: string, enableCDN?: boolean, numExports?: number }): string {\n const prefix = args.urlPrefix ?? \"\";\n const numExports = args.numExports ?? 5;\n let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.sourceId}&$orderBy=date:desc&$top=${numExports}`;\n\n if (args.changeId)\n url = `${url}&changesetId=${args.changeId}`;\n\n if (args.enableCDN)\n url = `${url}&cdn=1`;\n\n const tileVersion = IModelApp.tileAdmin.maximumMajorTileFormatVersion.toString();\n url = `${url}&tileVersion=${tileVersion}&iTwinJS=${ITWINJS_CORE_VERSION}&exportType=${args.sourceType}`;\n\n return url;\n}\n\n/** Arguments supplied to [[queryGraphicRepresentations]].\n * @beta\n */\nexport interface QueryGraphicRepresentationsArgs {\n /** The token used to access the data source provider. */\n accessToken: AccessToken;\n /** The unique identifier for the session in which this data source was queried.\n * A possible value is IModelApp.sessionId.\n */\n sessionId: string;\n /** The Data Source for which to query the graphic representations */\n dataSource: DataSource;\n /** The expected format of the graphic representations\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, exports whose status is not \"Complete\" (indicating the export successfully finished) will be included in the results */\n includeIncomplete?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n /** Number of exports to query */\n numExports?: number;\n}\n\n/** Query Graphic Representations matching the specified criteria, sorted from most-recently- to least-recently-produced.\n * @beta\n */\nexport async function* queryGraphicRepresentations(args: QueryGraphicRepresentationsArgs): AsyncIterableIterator<GraphicRepresentation> {\n interface ServiceJsonResponse {\n id: string;\n displayName: string;\n status: GraphicRepresentationStatus;\n request: {\n iModelId: string;\n changesetId: string;\n exportType: string;\n geometryOptions: any;\n viewDefinitionFilter: any;\n };\n\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n _links?: {\n mesh: {\n href: string;\n };\n };\n }\n\n interface ServiceJsonResponses {\n exports: ServiceJsonResponse[];\n\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n _links: {\n next?: {\n href: string;\n };\n };\n }\n\n const headers = {\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Authorization: args.accessToken,\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Accept: \"application/vnd.bentley.itwin-platform.v1+json\",\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Prefer: \"return=representation\",\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n SessionId: args.sessionId,\n };\n\n let url: string | undefined = createGraphicRepresentationsQueryUrl({ sourceId: args.dataSource.id, sourceType: args.dataSource.type, urlPrefix: args.urlPrefix, changeId: args.dataSource.changeId, enableCDN: args.enableCDN, numExports: args.numExports });\n while (url) {\n let result;\n try {\n const response = await fetch(url, { headers });\n result = await response.json() as ServiceJsonResponses;\n } catch (err) {\n Logger.logException(loggerCategory, err);\n Logger.logError(loggerCategory, `Failed loading Graphics Data for Source ${args.dataSource.id}`);\n break;\n }\n\n const foundSources = result.exports.filter((x) => x.request.exportType === args.dataSource.type && (args.includeIncomplete || x.status === GraphicRepresentationStatus.Complete));\n for (const foundSource of foundSources) {\n const graphicRepresentation: GraphicRepresentation = {\n displayName: foundSource.displayName,\n representationId: foundSource.id,\n status: foundSource.status,\n format: args.format,\n url: foundSource._links?.mesh.href,\n dataSource: {\n iTwinId: args.dataSource.iTwinId,\n id: foundSource.request.iModelId,\n changeId: foundSource.request.changesetId,\n type: foundSource.request.exportType,\n },\n };\n\n yield graphicRepresentation;\n }\n\n url = result._links.next?.href;\n }\n}\n\n/** Arguments supplied to [[obtainGraphicRepresentationUrl]].\n * @beta\n */\nexport interface ObtainGraphicRepresentationUrlArgs {\n /** The token used to access the mesh export service. */\n accessToken: AccessToken;\n /** The unique identifier for the session in which this data source was queried.\n * A possible value is IModelApp.sessionId.\n */\n sessionId: string;\n /** The data source for which to query the graphic representations */\n dataSource: DataSource;\n /** The expected format of the graphic representations\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, only data produced for a specific data source version will be considered;\n * otherwise, if no data sources are found with the specified version,the most recent data source version will be used.\n */\n requireExactVersion?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n}\n\n/** Obtains a URL pointing to a Graphic Representation.\n * [[queryGraphicRepresentations]] is used to obtain a list of available representations. By default, the list is sorted from most to least recently-created.\n * The first representation matching the source version is selected; or, if no such representation exists, the first representation in the list is selected.\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\n * @beta\n */\nexport async function obtainGraphicRepresentationUrl(args: ObtainGraphicRepresentationUrlArgs): Promise<URL | undefined> {\n if (!args.dataSource.id) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data from a source without an Id\");\n return undefined;\n }\n\n const queryArgs: QueryGraphicRepresentationsArgs = {\n accessToken: args.accessToken,\n sessionId: args.sessionId,\n dataSource: args.dataSource,\n format: args.format,\n urlPrefix: args.urlPrefix,\n enableCDN: args.enableCDN,\n };\n\n let selectedData;\n for await (const data of queryGraphicRepresentations(queryArgs)) {\n selectedData = data;\n break;\n }\n\n if (!selectedData && !args.requireExactVersion) {\n queryArgs.dataSource.changeId = undefined;\n for await (const data of queryGraphicRepresentations(queryArgs)) {\n selectedData = data;\n Logger.logInfo(loggerCategory, `No data for Data Source ${args.dataSource.id} for version ${args.dataSource.changeId}; falling back to most recent`);\n break;\n }\n }\n\n if ((!selectedData) || (!selectedData.url)) {\n Logger.logInfo(loggerCategory, `No data available for Data Source ${args.dataSource.id}`);\n return undefined;\n }\n\n const url = new URL(selectedData.url);\n url.pathname = `${url.pathname}/tileset.json`;\n return url;\n}\n"]}
1
+ {"version":3,"file":"GraphicRepresentationProvider.js","sourceRoot":"","sources":["../../../src/GraphicsProvider/GraphicRepresentationProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAe,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AA+DvE;;GAEG;AACH,MAAM,UAAU,oCAAoC,CAAC,IAA+H;IAClL,MAAM,MAAM,GAAG,IAAI,CAAC,SAAS,IAAI,EAAE,CAAC;IACpC,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,IAAI,CAAC,CAAC;IACxC,IAAI,GAAG,GAAG,WAAW,MAAM,yCAAyC,IAAI,CAAC,QAAQ,4BAA4B,UAAU,EAAE,CAAC;IAE1H,IAAI,IAAI,CAAC,QAAQ;QACf,GAAG,GAAG,GAAG,GAAG,gBAAgB,IAAI,CAAC,QAAQ,EAAE,CAAC;IAE9C,IAAI,IAAI,CAAC,SAAS;QAChB,GAAG,GAAG,GAAG,GAAG,QAAQ,CAAC;IAEvB,MAAM,WAAW,G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;QACzB,UAAU,EAAE,IAAI,CAAC,UAAU;QAC3B,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC;IAEF,IAAI,YAAY,CAAC;IACjB,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,2BAA2B,CAAC,SAAS,CAAC,EAAE,CAAC;QAChE,YAAY,GAAG,IAAI,CAAC;QACpB,MAAM;IACR,CAAC;IAED,IAAI,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC/C,SAAS,CAAC,UAAU,CAAC,QAAQ,GAAG,SAAS,CAAC;QAC1C,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,2BAA2B,CAAC,SAAS,CAAC,EAAE,CAAC;YAChE,YAAY,GAAG,IAAI,CAAC;YACpB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,2BAA2B,IAAI,CAAC,UAAU,CAAC,EAAE,gBAAgB,IAAI,CAAC,UAAU,CAAC,QAAQ,+BAA+B,CAAC,CAAC;YACrJ,MAAM;QACR,CAAC;IACH,CAAC;IAED,IAAI,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC;QAC3C,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,qCAAqC,IAAI,CAAC,UAAU,CAAC,EAAE,EAAE,CAAC,CAAC;QAC1F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC;IACtC,GAAG,CAAC,QAAQ,GAAG,GAAG,GAAG,CAAC,QAAQ,eAAe,CAAC;IAC9C,OAAO,GAAG,CAAC;AACb,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\nimport { loggerCategory } from \"../LoggerCategory\";\nimport { IModelApp, ITWINJS_CORE_VERSION } from \"@itwin/core-frontend\";\n\n/** The expected format of the Graphic Representation\n * @beta\n */\n// eslint-disable-next-line @typescript-eslint/no-redundant-type-constituents\nexport type GraphicRepresentationFormat = \"3DFT\" | \"3DTiles\" | \"CESIUM\" | \"IMODEL\" | string;\n\n/** Graphic representations are generated from Data Sources.\n * The status of a Graphic Representation indicates the progress of that generation process.\n * @beta\n */\nexport type GraphicRepresentationStatus = \"Complete\" | \"InProgress\" | \"Invalid\" | \"NotStarted\";\n\n/**\n * Represents a data source for a graphic representation.\n * A data source is usually higher-fidelity and contains more information, but may not be as well suited for visualization\n * as a graphic representation.\n * @beta\n */\nexport interface DataSource {\n /** The iTwinId associated with the DataSource */\n iTwinId: string;\n /** The unique identifier of a DataSource.\n * For example, a DataSource of type \"IMODEL\" has an iModelId which would be attributed to this value.\n */\n id: string;\n /** The unique identifier for a specific version of a DataSource.\n * For example, if a specific version of an iModel is desired, the iModel's changesetId would be attributed to this value.\n */\n changeId?: string;\n /** The type of the data source. For example, a DataSource can be of type \"IMODEL\" or \"RealityData\" */\n type: string;\n}\n\n/** Represents a visual representation of a data source, for example a 3d tileset.\n * A data source can be an iModel, reality data, or other kind of graphical data.\n * @see [[queryGraphicRepresentations]] for its construction as a representation of the data produced by a query of data sources.\n * @beta\n */\nexport interface GraphicRepresentation {\n /** The display name of the Graphic Representation */\n displayName: string;\n /** The unique identifier for the Graphic Representation */\n representationId: string;\n /** The status of the generation of the Graphic Representation from its Data Source.\n * @see [[GraphicRepresentationStatus]] for possible values.\n */\n status: GraphicRepresentationStatus;\n /** The expected format of the Graphic Representation\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** The data source that the representation originates from.\n * For example, a GraphicRepresentation in the 3D Tiles format might have a dataSource that is a specific iModel changeset.\n */\n dataSource: DataSource;\n /** The url of the graphic representation\n * @note The url can only be guaranteed to be valid if the status is complete.\n */\n url: string | undefined;\n}\n\n/** Creates a URL used to query for Graphic Representations\n * @internal\n */\nexport function createGraphicRepresentationsQueryUrl(args: { sourceId: string, sourceType: string, urlPrefix?: string, changeId?: string, enableCDN?: boolean, numExports?: number }): string {\n const prefix = args.urlPrefix ?? \"\";\n const numExports = args.numExports ?? 5;\n let url = `https://${prefix}api.bentley.com/mesh-export/?iModelId=${args.sourceId}&$orderBy=date:desc&$top=${numExports}`;\n\n if (args.changeId)\n url = `${url}&changesetId=${args.changeId}`;\n\n if (args.enableCDN)\n url = `${url}&cdn=1`;\n\n const tileVersion = IModelApp.tileAdmin.maximumMajorTileFormatVersion.toString();\n url = `${url}&tileVersion=${tileVersion}&iTwinJS=${ITWINJS_CORE_VERSION}&exportType=${args.sourceType}`;\n\n return url;\n}\n\n/** Represents an export object from a response from the Mesh Export Service.\n * @internal\n */\ninterface ServiceJsonResponse {\n id: string;\n displayName: string;\n status: GraphicRepresentationStatus;\n request: {\n iModelId: string;\n changesetId: string;\n exportType: string;\n };\n\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n _links?: {\n mesh: {\n href: string;\n };\n };\n}\n\n/** Represents a response from the Mesh Export Service.\n * @internal\n */\ninterface ServiceJsonResponses {\n exports: ServiceJsonResponse[];\n\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n _links: {\n next?: {\n href: string;\n };\n };\n}\n\n/** Arguments supplied to [[queryGraphicRepresentations]].\n * @beta\n */\nexport interface QueryGraphicRepresentationsArgs {\n /** The token used to access the data source provider. */\n accessToken: AccessToken;\n /** The unique identifier for the session in which this data source was queried.\n * A possible value is IModelApp.sessionId.\n */\n sessionId: string;\n /** The Data Source for which to query the graphic representations */\n dataSource: DataSource;\n /** The expected format of the graphic representations\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, exports whose status is not \"Complete\" (indicating the export successfully finished) will be included in the results */\n includeIncomplete?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n /** Number of exports to query */\n numExports?: number;\n}\n\n/** Query Graphic Representations matching the specified criteria, sorted from most-recently- to least-recently-produced.\n * @beta\n */\nexport async function* queryGraphicRepresentations(args: QueryGraphicRepresentationsArgs): AsyncIterableIterator<GraphicRepresentation> {\n const headers = {\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Authorization: args.accessToken,\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Accept: \"application/vnd.bentley.itwin-platform.v1+json\",\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n Prefer: \"return=representation\",\n /* eslint-disable-next-line @typescript-eslint/naming-convention */\n SessionId: args.sessionId,\n };\n\n let url: string | undefined = createGraphicRepresentationsQueryUrl({ sourceId: args.dataSource.id, sourceType: args.dataSource.type, urlPrefix: args.urlPrefix, changeId: args.dataSource.changeId, enableCDN: args.enableCDN, numExports: args.numExports });\n while (url) {\n let result;\n try {\n const response = await fetch(url, { headers });\n result = await response.json() as ServiceJsonResponses;\n } catch (err) {\n Logger.logException(loggerCategory, err);\n Logger.logError(loggerCategory, `Failed loading Graphics Data for Source ${args.dataSource.id}`);\n break;\n }\n\n const foundSources = result.exports.filter((x) => x.request.exportType === args.dataSource.type && (args.includeIncomplete || x.status === \"Complete\"));\n for (const foundSource of foundSources) {\n const graphicRepresentation: GraphicRepresentation = {\n displayName: foundSource.displayName,\n representationId: foundSource.id,\n status: foundSource.status,\n format: args.format,\n url: foundSource._links?.mesh.href,\n dataSource: {\n iTwinId: args.dataSource.iTwinId,\n id: foundSource.request.iModelId,\n changeId: foundSource.request.changesetId,\n type: foundSource.request.exportType,\n },\n };\n\n yield graphicRepresentation;\n }\n\n url = result._links.next?.href;\n }\n}\n\n/** Arguments supplied to [[obtainGraphicRepresentationUrl]].\n * @beta\n */\nexport interface ObtainGraphicRepresentationUrlArgs {\n /** The token used to access the mesh export service. */\n accessToken: AccessToken;\n /** The unique identifier for the session in which this data source was queried.\n * A possible value is IModelApp.sessionId.\n */\n sessionId: string;\n /** The data source for which to query the graphic representations */\n dataSource: DataSource;\n /** The expected format of the graphic representations\n * @see [[GraphicRepresentationFormat]] for possible values.\n */\n format: GraphicRepresentationFormat;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, only data produced for a specific data source version will be considered;\n * otherwise, if no data sources are found with the specified version,the most recent data source version will be used.\n */\n requireExactVersion?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n}\n\n/** Obtains a URL pointing to a Graphic Representation.\n * [[queryGraphicRepresentations]] is used to obtain a list of available representations. By default, the list is sorted from most to least recently-created.\n * The first representation matching the source version is selected; or, if no such representation exists, the first representation in the list is selected.\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\n * @beta\n */\nexport async function obtainGraphicRepresentationUrl(args: ObtainGraphicRepresentationUrlArgs): Promise<URL | undefined> {\n if (!args.dataSource.id) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data from a source without an Id\");\n return undefined;\n }\n\n const queryArgs: QueryGraphicRepresentationsArgs = {\n accessToken: args.accessToken,\n sessionId: args.sessionId,\n dataSource: args.dataSource,\n format: args.format,\n urlPrefix: args.urlPrefix,\n enableCDN: args.enableCDN,\n };\n\n let selectedData;\n for await (const data of queryGraphicRepresentations(queryArgs)) {\n selectedData = data;\n break;\n }\n\n if (!selectedData && !args.requireExactVersion) {\n queryArgs.dataSource.changeId = undefined;\n for await (const data of queryGraphicRepresentations(queryArgs)) {\n selectedData = data;\n Logger.logInfo(loggerCategory, `No data for Data Source ${args.dataSource.id} for version ${args.dataSource.changeId}; falling back to most recent`);\n break;\n }\n }\n\n if ((!selectedData) || (!selectedData.url)) {\n Logger.logInfo(loggerCategory, `No data available for Data Source ${args.dataSource.id}`);\n return undefined;\n }\n\n const url = new URL(selectedData.url);\n url.pathname = `${url.pathname}/tileset.json`;\n return url;\n}\n"]}
@@ -30,7 +30,7 @@ export async function obtainIModelTilesetUrl(args) {
30
30
  changeId: args.changesetId,
31
31
  type: "IMODEL",
32
32
  },
33
- format: "IMDL",
33
+ format: "IMODEL",
34
34
  urlPrefix: args.urlPrefix,
35
35
  requireExactVersion: args.requireExactChangeset,
36
36
  enableCDN: args.enableCDN,
@@ -1 +1 @@
1
- {"version":3,"file":"GraphicsProvider.js","sourceRoot":"","sources":["../../../src/GraphicsProvider/GraphicsProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAe,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAE,MAAM,iCAAiC,CAAC;AACjF,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAwBnD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAgC;IAE3E,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,4DAA4D,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,2DAA2D,CAAC,CAAC;QAC5F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,YAAY,GAAG;QACnB,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,UAAU,EAAE;YACV,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,EAAE,EAAE,IAAI,CAAC,QAAQ;YACjB,QAAQ,EAAE,IAAI,CAAC,WAAW;YAC1B,IAAI,EAAE,QAAQ;SACf;QACD,MAAM,EAAE,MAAM;QACd,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,mBAAmB,EAAE,IAAI,CAAC,qBAAqB;QAC/C,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC;IAEF,OAAO,8BAA8B,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { obtainGraphicRepresentationUrl } from \"./GraphicRepresentationProvider\";\nimport { loggerCategory } from \"../LoggerCategory\";\n\n/** Arguments supplied to [[obtainIModelTilesetUrl]].\n * @beta\n */\nexport interface ObtainIModelTilesetUrlArgs {\n /** The iTwin id for which to obtain a tileset URL. */\n iTwinId?: string;\n /** The iModel id for which to obtain a tileset URL. */\n iModelId?: string;\n /** The changeset id for which to obtain a tileset URL. */\n changesetId?: string;\n /** The token used to access the mesh export service. */\n accessToken: AccessToken;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,\n * the most recent export for any changeset will be used.\n */\n requireExactChangeset?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n}\n\n/** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.\n * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.\n * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\n * @beta\n */\nexport async function obtainIModelTilesetUrl(args: ObtainIModelTilesetUrlArgs):\n Promise<URL | undefined> {\n if (!args.iModelId) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data for an iModel with no iModelId\");\n return undefined;\n }\n\n if (!args.iTwinId) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data for an iModel with no iTwinId\");\n return undefined;\n }\n\n const graphicsArgs = {\n accessToken: args.accessToken,\n sessionId: IModelApp.sessionId,\n dataSource: {\n iTwinId: args.iTwinId,\n id: args.iModelId,\n changeId: args.changesetId,\n type: \"IMODEL\",\n },\n format: \"IMDL\",\n urlPrefix: args.urlPrefix,\n requireExactVersion: args.requireExactChangeset,\n enableCDN: args.enableCDN,\n };\n\n return obtainGraphicRepresentationUrl(graphicsArgs);\n}\n"]}
1
+ {"version":3,"file":"GraphicsProvider.js","sourceRoot":"","sources":["../../../src/GraphicsProvider/GraphicsProvider.ts"],"names":[],"mappings":"AAAA;;;gGAGgG;AAEhG,OAAO,EAAe,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC1D,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAC;AACjD,OAAO,EAAE,8BAA8B,EAAsC,MAAM,iCAAiC,CAAC;AACrH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAwBnD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAAC,IAAgC;IAE3E,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QACnB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,4DAA4D,CAAC,CAAC;QAC7F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;QAClB,MAAM,CAAC,OAAO,CAAC,cAAc,EAAE,2DAA2D,CAAC,CAAC;QAC5F,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,YAAY,GAAuC;QACvD,WAAW,EAAE,IAAI,CAAC,WAAW;QAC7B,SAAS,EAAE,SAAS,CAAC,SAAS;QAC9B,UAAU,EAAE;YACV,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,EAAE,EAAE,IAAI,CAAC,QAAQ;YACjB,QAAQ,EAAE,IAAI,CAAC,WAAW;YAC1B,IAAI,EAAE,QAAQ;SACf;QACD,MAAM,EAAE,QAAQ;QAChB,SAAS,EAAE,IAAI,CAAC,SAAS;QACzB,mBAAmB,EAAE,IAAI,CAAC,qBAAqB;QAC/C,SAAS,EAAE,IAAI,CAAC,SAAS;KAC1B,CAAC;IAEF,OAAO,8BAA8B,CAAC,YAAY,CAAC,CAAC;AACtD,CAAC","sourcesContent":["/*---------------------------------------------------------------------------------------------\n * Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n * See LICENSE.md in the project root for license terms and full copyright notice.\n *--------------------------------------------------------------------------------------------*/\n\nimport { AccessToken, Logger } from \"@itwin/core-bentley\";\nimport { IModelApp } from \"@itwin/core-frontend\";\nimport { obtainGraphicRepresentationUrl, ObtainGraphicRepresentationUrlArgs } from \"./GraphicRepresentationProvider\";\nimport { loggerCategory } from \"../LoggerCategory\";\n\n/** Arguments supplied to [[obtainIModelTilesetUrl]].\n * @beta\n */\nexport interface ObtainIModelTilesetUrlArgs {\n /** The iTwin id for which to obtain a tileset URL. */\n iTwinId?: string;\n /** The iModel id for which to obtain a tileset URL. */\n iModelId?: string;\n /** The changeset id for which to obtain a tileset URL. */\n changesetId?: string;\n /** The token used to access the mesh export service. */\n accessToken: AccessToken;\n /** Chiefly used in testing environments. */\n urlPrefix?: string;\n /** If true, only exports produced for `iModel`'s specific changeset will be considered; otherwise, if no exports are found for the changeset,\n * the most recent export for any changeset will be used.\n */\n requireExactChangeset?: boolean;\n /** If true, enables a CDN (content delivery network) to access tiles faster. */\n enableCDN?: boolean;\n}\n\n/** Obtains a URL pointing to a tileset appropriate for visualizing a specific iModel.\n * [[queryCompletedMeshExports]] is used to obtain a list of available exports. By default, the list is sorted from most to least recently-exported.\n * The first export matching the iModel's changeset is selected; or, if no such export exists, the first export in the list is selected.\n * @returns A URL from which the tileset can be loaded, or `undefined` if no appropriate URL could be obtained.\n * @beta\n */\nexport async function obtainIModelTilesetUrl(args: ObtainIModelTilesetUrlArgs):\n Promise<URL | undefined> {\n if (!args.iModelId) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data for an iModel with no iModelId\");\n return undefined;\n }\n\n if (!args.iTwinId) {\n Logger.logInfo(loggerCategory, \"Cannot obtain Graphics Data for an iModel with no iTwinId\");\n return undefined;\n }\n\n const graphicsArgs: ObtainGraphicRepresentationUrlArgs = {\n accessToken: args.accessToken,\n sessionId: IModelApp.sessionId,\n dataSource: {\n iTwinId: args.iTwinId,\n id: args.iModelId,\n changeId: args.changesetId,\n type: \"IMODEL\",\n },\n format: \"IMODEL\",\n urlPrefix: args.urlPrefix,\n requireExactVersion: args.requireExactChangeset,\n enableCDN: args.enableCDN,\n };\n\n return obtainGraphicRepresentationUrl(graphicsArgs);\n}\n"]}
@@ -15,6 +15,9 @@ export class PassThroughCache {
15
15
  }
16
16
  /** @internal */
17
17
  export class IndexedDBCache {
18
+ _db;
19
+ _dbName;
20
+ _expirationTime;
18
21
  constructor(dbName, expirationTime) {
19
22
  this._dbName = dbName;
20
23
  this._expirationTime = expirationTime ?? undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"IndexedDBCache.js","sourceRoot":"","sources":["../../src/IndexedDBCache.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAOxC,gBAAgB;AAChB,MAAM,OAAO,gBAAgB;IACpB,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,QAA4C,EAAE,WAAoB;QACrG,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACrD,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAClD,CAAC;CACF;AAED,gBAAgB;AAChB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G,MAAM,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;YAE5D,MAAM,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Logger } from \"@itwin/core-bentley\";\nconst loggerCategory = \"IndexedDBCache\";\n\n/** @internal */\nexport interface LocalCache {\n fetch(url: string, callback: (uniqueId: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer>;\n}\n\n/** @internal */\nexport class PassThroughCache implements LocalCache {\n public async fetch(uniqueId: string, callback: (url: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer> {\n if (callBackUrl) {\n return (await callback(callBackUrl)).arrayBuffer();\n }\n return (await callback(uniqueId)).arrayBuffer();\n }\n}\n\n/** @internal */\nexport class IndexedDBCache implements LocalCache{\n private _db: any;\n private _dbName: string;\n private _expirationTime?: number;\n\n public constructor(dbName: string, expirationTime?: number) {\n this._dbName = dbName;\n this._expirationTime = expirationTime ?? undefined;\n }\n\n protected async open(){\n\n // need to return a promise so that we can wait for the db to open before using it\n return new Promise(function (this: IndexedDBCache, resolve: any) {\n\n // open the db\n const openDB = window.indexedDB.open(this._dbName, 1);\n\n openDB.onerror = () => {\n Logger.logError(loggerCategory, \"Error opening IndexedDB\");\n };\n\n // this is the success callback for opening the db, it is called after onupgradeneeded\n openDB.onsuccess = async (event) => {\n\n const target: any = event.target;\n if (target) {\n this._db = target.result;\n return resolve(target.result);\n }\n };\n\n // This will get called when a new version is needed - including going from no database to first version\n // So this is how we set up the specifics of the db structure\n openDB.onupgradeneeded = async (event) => {\n const target: any = event.target;\n\n if (target)\n this._db = target.result;\n\n const initialObjectStore = this._db.createObjectStore(\"cache\", { keyPath: \"uniqueId\" });\n initialObjectStore.createIndex(\"content\", \"content\", {unique: false});\n initialObjectStore.createIndex(\"timeOfStorage\", \"timeOfStorage\", {unique: false});\n };\n }.bind(this));\n }\n\n protected async close() {\n await this._db.close();\n }\n\n protected async retrieveContent(uniqueId: string): Promise<ArrayBuffer | undefined> {\n return new Promise(async (resolve) => {\n await this.open();\n const getTransaction = await this._db.transaction(\"cache\", \"readonly\");\n const storedResponse = await getTransaction.objectStore(\"cache\").get(uniqueId);\n\n // this is successful if the db was successfully searched - not only if a match was found\n storedResponse.onsuccess = async () => {\n\n if (storedResponse.result !== undefined) {\n\n // if the content has an expiration time\n if (this._expirationTime) {\n // We want to know when the result was stored, and how long it's been since that point\n const timeSince = Date.now() - storedResponse.result.timeOfStorage;\n\n // If it's been greater than our time limit, delete it and return undefined.\n if (timeSince > this._expirationTime) {\n await this.deleteContent(uniqueId);\n return resolve(undefined);\n }\n }\n const content = storedResponse.result.content;\n await this.close();\n return resolve(content);\n }\n\n await this.close();\n return resolve(undefined);\n };\n\n storedResponse.onerror = async () => {\n Logger.logError(loggerCategory, \"Error retrieving content from IndexedDB\");\n };\n });\n }\n\n protected async deleteContent(uniqueId: string) {\n return new Promise(async (resolve) => {\n await this.open();\n const deleteTransaction = await this._db.transaction(\"cache\", \"readwrite\");\n const requestDelete = await deleteTransaction.objectStore(\"cache\").delete(uniqueId);\n\n requestDelete.onerror = () => {\n Logger.logError(loggerCategory, \"Error deleting content from IndexedDB\");\n };\n\n deleteTransaction.oncomplete = async () => {\n await this.close();\n return resolve(undefined);\n };\n\n deleteTransaction.onerror = async () => {\n Logger.logError(loggerCategory, \"Error deleting content from IndexedDB\");\n };\n });\n }\n\n protected async addContent(uniqueId: string, content: ArrayBuffer) {\n return new Promise(async (resolve) => {\n await this.open();\n const addTransaction = await this._db.transaction(\"cache\", \"readwrite\");\n const objectStore = await addTransaction.objectStore(\"cache\");\n\n const data = {\n uniqueId,\n content,\n timeOfStorage: Date.now(),\n };\n\n const requestAdd = await objectStore.add(data);\n\n requestAdd.onerror = () => {\n Logger.logError(loggerCategory, \"Error adding content to IndexedDB\");\n };\n\n addTransaction.oncomplete = async () => {\n await this.close();\n return resolve(undefined);\n };\n\n addTransaction.onerror = async () => {\n Logger.logError(loggerCategory, \"Error adding content to IndexedDB in add transaction\");\n await this.close();\n return resolve(undefined);\n };\n });\n }\n\n public async fetch(uniqueId: string, callback: (url: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer> {\n let response = await this.retrieveContent(uniqueId);\n\n // If nothing was found in the db, fetch normally, then add that content to the db\n if (response === undefined) {\n\n // If necessary, use the callback url\n if (callBackUrl)\n response = await (await callback(callBackUrl)).arrayBuffer();\n else\n response = await (await callback(uniqueId)).arrayBuffer();\n\n await this.addContent(uniqueId, response);\n }\n\n return response;\n }\n}\n\n"]}
1
+ {"version":3,"file":"IndexedDBCache.js","sourceRoot":"","sources":["../../src/IndexedDBCache.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAC/F,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,MAAM,cAAc,GAAG,gBAAgB,CAAC;AAOxC,gBAAgB;AAChB,MAAM,OAAO,gBAAgB;IACpB,KAAK,CAAC,KAAK,CAAC,QAAgB,EAAE,QAA4C,EAAE,WAAoB;QACrG,IAAI,WAAW,EAAE,CAAC;YAChB,OAAO,CAAC,MAAM,QAAQ,CAAC,WAAW,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;QACrD,CAAC;QACD,OAAO,CAAC,MAAM,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;IAClD,CAAC;CACF;AAED,gBAAgB;AAChB,MAAM,OAAO,cAAc;IACjB,GAAG,CAAM;IACT,OAAO,CAAS;IAChB,eAAe,CAAU;IAEjC,YAAmB,MAAc,EAAE,cAAuB;QACxD,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAA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AU,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;QAC5C,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\nimport { Logger } from \"@itwin/core-bentley\";\nconst loggerCategory = \"IndexedDBCache\";\n\n/** @internal */\nexport interface LocalCache {\n fetch(url: string, callback: (uniqueId: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer>;\n}\n\n/** @internal */\nexport class PassThroughCache implements LocalCache {\n public async fetch(uniqueId: string, callback: (url: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer> {\n if (callBackUrl) {\n return (await callback(callBackUrl)).arrayBuffer();\n }\n return (await callback(uniqueId)).arrayBuffer();\n }\n}\n\n/** @internal */\nexport class IndexedDBCache implements LocalCache{\n private _db: any;\n private _dbName: string;\n private _expirationTime?: number;\n\n public constructor(dbName: string, expirationTime?: number) {\n this._dbName = dbName;\n this._expirationTime = expirationTime ?? undefined;\n }\n\n protected async open(){\n\n // need to return a promise so that we can wait for the db to open before using it\n return new Promise(function (this: IndexedDBCache, resolve: any) {\n\n // open the db\n const openDB = window.indexedDB.open(this._dbName, 1);\n\n openDB.onerror = () => {\n Logger.logError(loggerCategory, \"Error opening IndexedDB\");\n };\n\n // this is the success callback for opening the db, it is called after onupgradeneeded\n openDB.onsuccess = async (event) => {\n\n const target: any = event.target;\n if (target) {\n this._db = target.result;\n return resolve(target.result);\n }\n };\n\n // This will get called when a new version is needed - including going from no database to first version\n // So this is how we set up the specifics of the db structure\n openDB.onupgradeneeded = async (event) => {\n const target: any = event.target;\n\n if (target)\n this._db = target.result;\n\n const initialObjectStore = this._db.createObjectStore(\"cache\", { keyPath: \"uniqueId\" });\n initialObjectStore.createIndex(\"content\", \"content\", {unique: false});\n initialObjectStore.createIndex(\"timeOfStorage\", \"timeOfStorage\", {unique: false});\n };\n }.bind(this));\n }\n\n protected async close() {\n await this._db.close();\n }\n\n protected async retrieveContent(uniqueId: string): Promise<ArrayBuffer | undefined> {\n return new Promise(async (resolve) => {\n await this.open();\n const getTransaction = await this._db.transaction(\"cache\", \"readonly\");\n const storedResponse = await getTransaction.objectStore(\"cache\").get(uniqueId);\n\n // this is successful if the db was successfully searched - not only if a match was found\n storedResponse.onsuccess = async () => {\n\n if (storedResponse.result !== undefined) {\n\n // if the content has an expiration time\n if (this._expirationTime) {\n // We want to know when the result was stored, and how long it's been since that point\n const timeSince = Date.now() - storedResponse.result.timeOfStorage;\n\n // If it's been greater than our time limit, delete it and return undefined.\n if (timeSince > this._expirationTime) {\n await this.deleteContent(uniqueId);\n return resolve(undefined);\n }\n }\n const content = storedResponse.result.content;\n await this.close();\n return resolve(content);\n }\n\n await this.close();\n return resolve(undefined);\n };\n\n storedResponse.onerror = async () => {\n Logger.logError(loggerCategory, \"Error retrieving content from IndexedDB\");\n };\n });\n }\n\n protected async deleteContent(uniqueId: string) {\n return new Promise(async (resolve) => {\n await this.open();\n const deleteTransaction = await this._db.transaction(\"cache\", \"readwrite\");\n const requestDelete = await deleteTransaction.objectStore(\"cache\").delete(uniqueId);\n\n requestDelete.onerror = () => {\n Logger.logError(loggerCategory, \"Error deleting content from IndexedDB\");\n };\n\n deleteTransaction.oncomplete = async () => {\n await this.close();\n return resolve(undefined);\n };\n\n deleteTransaction.onerror = async () => {\n Logger.logError(loggerCategory, \"Error deleting content from IndexedDB\");\n };\n });\n }\n\n protected async addContent(uniqueId: string, content: ArrayBuffer) {\n return new Promise(async (resolve) => {\n await this.open();\n const addTransaction = await this._db.transaction(\"cache\", \"readwrite\");\n const objectStore = await addTransaction.objectStore(\"cache\");\n\n const data = {\n uniqueId,\n content,\n timeOfStorage: Date.now(),\n };\n\n const requestAdd = await objectStore.add(data);\n\n requestAdd.onerror = () => {\n Logger.logError(loggerCategory, \"Error adding content to IndexedDB\");\n };\n\n addTransaction.oncomplete = async () => {\n await this.close();\n return resolve(undefined);\n };\n\n addTransaction.onerror = async () => {\n Logger.logError(loggerCategory, \"Error adding content to IndexedDB in add transaction\");\n await this.close();\n return resolve(undefined);\n };\n });\n }\n\n public async fetch(uniqueId: string, callback: (url: string) => Promise<Response>, callBackUrl?: string): Promise<ArrayBuffer> {\n let response = await this.retrieveContent(uniqueId);\n\n // If nothing was found in the db, fetch normally, then add that content to the db\n if (response === undefined) {\n\n // If necessary, use the callback url\n if (callBackUrl)\n response = await (await callback(callBackUrl)).arrayBuffer();\n else\n response = await (await callback(uniqueId)).arrayBuffer();\n\n await this.addContent(uniqueId, response);\n }\n\n return response;\n }\n}\n\n"]}
@@ -14,9 +14,10 @@ const emptyState = { transforms: [], guid: "" };
14
14
  * @internal
15
15
  */
16
16
  export class ModelGroupDisplayTransforms {
17
+ _state = emptyState;
18
+ _modelIds;
17
19
  /** Create a new set of groups for the specified `modelIds`. If `provider` is supplied, the grouping will be applied to those models immediately. */
18
20
  constructor(modelIds, provider) {
19
- this._state = emptyState;
20
21
  this._modelIds = modelIds;
21
22
  if (provider)
22
23
  this.update(provider);
@@ -1 +1 @@
1
- {"version":3,"file":"ModelGroupDisplayTransforms.js","sourceRoot":"","sources":["../../src/ModelGroupDisplayTransforms.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC;AAG7E,SAAS,sBAAsB,CAAC,CAAwB,EAAE,CAAwB;IAChF,OAAO,CAAC,CAAC,CAAC,CAAC,WAAW,KAAK,CAAC,CAAC,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,SAAS,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AACvF,CAAC;AAcD,yFAAyF;AACzF,MAAM,UAAU,GAAqC,EAAE,UAAU,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC;AAElF;;;;GAIG;AACH,MAAM,OA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AK;oBACR,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;gBAE9D,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YACzB,OAAO,UAAU,CAAC;QAEpB,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/F,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { CompressedId64Set, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport { ModelDisplayTransform, ModelDisplayTransformProvider } from \"@itwin/core-frontend\";\n\nfunction equalDisplayTransforms(a: ModelDisplayTransform, b: ModelDisplayTransform): boolean {\n return !!a.premultiply === !!b.premultiply && a.transform.isAlmostEqual(b.transform);\n}\n\n/** A display transform to be applied to a set of models. */\ninterface ModelGroupDisplayTransform {\n modelIds: Id64Set;\n transform: ModelDisplayTransform;\n}\n\n/** A collection of model Ids grouped according to the unique transforms to be applied to each group. */\ninterface ModelGroupDisplayTransformsState {\n readonly transforms: ReadonlyArray<ModelGroupDisplayTransform>;\n readonly guid: string;\n}\n\n/** Optimization for the common case in which no display transforms are to be applied. */\nconst emptyState: ModelGroupDisplayTransformsState = { transforms: [], guid: \"\" };\n\n/** Manages the display transforms to be applied to all of the models in a BatchedTileTree, enabling all models that share an equivalent transform\n * to be drawn together.\n * Call `update` whenever the transforms may have changed (e.g., after the viewport's scene is invalidated).\n * @internal\n */\nexport class ModelGroupDisplayTransforms {\n private _state: ModelGroupDisplayTransformsState = emptyState;\n private readonly _modelIds: Id64Set;\n\n /** Create a new set of groups for the specified `modelIds`. If `provider` is supplied, the grouping will be applied to those models immediately. */\n public constructor(modelIds: Id64Set, provider?: ModelDisplayTransformProvider) {\n this._modelIds = modelIds;\n if (provider)\n this.update(provider);\n }\n\n /** A string uniquely identifying the current grouping. */\n public get guid(): string { return this._state.guid; }\n\n /** Get the display transform for the specified model.\n * @note This method is guaranteed to return the same object for all models in the same group, at least between calls to `update`.\n */\n public getDisplayTransform(modelId: Id64String): ModelDisplayTransform | undefined {\n return this._state.transforms.find((x) => x.modelIds.has(modelId))?.transform;\n }\n\n // Update the display transforms and the model groupings based on the transforms supplied by `provider`.\n // Return `true` if the groupings changed as a result.\n public update(provider: ModelDisplayTransformProvider | undefined): boolean {\n const prevState = this._state;\n this._state = this.computeState(provider);\n return this._state.guid !== prevState.guid;\n }\n\n private computeState(provider: ModelDisplayTransformProvider | undefined): ModelGroupDisplayTransformsState {\n if (!provider)\n return emptyState;\n\n const transforms: ModelGroupDisplayTransform[] = [];\n for (const modelId of this._modelIds) {\n const transform = provider.getModelDisplayTransform(modelId);\n if (transform) {\n let entry = transforms.find((x) => equalDisplayTransforms(transform, x.transform));\n if (!entry)\n transforms.push(entry = { transform, modelIds: new Set() });\n\n entry.modelIds.add(modelId);\n }\n }\n\n if (transforms.length === 0)\n return emptyState;\n\n const guid = transforms.map((x) => CompressedId64Set.compressSet(x.modelIds)).sort().join(\"_\");\n return { transforms, guid };\n }\n}\n"]}
1
+ {"version":3,"file":"ModelGroupDisplayTransforms.js","sourceRoot":"","sources":["../../src/ModelGroupDisplayTransforms.ts"],"names":[],"mappings":"AAAA;;;+FAG+F;AAE/F,OAAO,EAAE,iBAAiB,EAAuB,MAAM,qBAAqB,CAAC;AAG7E,SAAS,sBAAsB,CAAC,CAAwB,EAAE,C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KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACrC,MAAM,SAAS,GAAG,QAAQ,CAAC,wBAAwB,CAAC,OAAO,CAAC,CAAC;YAC7D,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,KAAK,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,sBAAsB,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;gBACnF,IAAI,CAAC,KAAK;oBACR,UAAU,CAAC,IAAI,CAAC,KAAK,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC;gBAE9D,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YAC9B,CAAC;QACH,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,KAAK,CAAC;YACzB,OAAO,UAAU,CAAC;QAEpB,MAAM,IAAI,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC/F,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,CAAC;IAC9B,CAAC;CACF","sourcesContent":["/*---------------------------------------------------------------------------------------------\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\n* See LICENSE.md in the project root for license terms and full copyright notice.\n*--------------------------------------------------------------------------------------------*/\n\nimport { CompressedId64Set, Id64Set, Id64String } from \"@itwin/core-bentley\";\nimport { ModelDisplayTransform, ModelDisplayTransformProvider } from \"@itwin/core-frontend\";\n\nfunction equalDisplayTransforms(a: ModelDisplayTransform, b: ModelDisplayTransform): boolean {\n return !!a.premultiply === !!b.premultiply && a.transform.isAlmostEqual(b.transform);\n}\n\n/** A display transform to be applied to a set of models. */\ninterface ModelGroupDisplayTransform {\n modelIds: Id64Set;\n transform: ModelDisplayTransform;\n}\n\n/** A collection of model Ids grouped according to the unique transforms to be applied to each group. */\ninterface ModelGroupDisplayTransformsState {\n readonly transforms: ReadonlyArray<ModelGroupDisplayTransform>;\n readonly guid: string;\n}\n\n/** Optimization for the common case in which no display transforms are to be applied. */\nconst emptyState: ModelGroupDisplayTransformsState = { transforms: [], guid: \"\" };\n\n/** Manages the display transforms to be applied to all of the models in a BatchedTileTree, enabling all models that share an equivalent transform\n * to be drawn together.\n * Call `update` whenever the transforms may have changed (e.g., after the viewport's scene is invalidated).\n * @internal\n */\nexport class ModelGroupDisplayTransforms {\n private _state: ModelGroupDisplayTransformsState = emptyState;\n private readonly _modelIds: Id64Set;\n\n /** Create a new set of groups for the specified `modelIds`. If `provider` is supplied, the grouping will be applied to those models immediately. */\n public constructor(modelIds: Id64Set, provider?: ModelDisplayTransformProvider) {\n this._modelIds = modelIds;\n if (provider)\n this.update(provider);\n }\n\n /** A string uniquely identifying the current grouping. */\n public get guid(): string { return this._state.guid; }\n\n /** Get the display transform for the specified model.\n * @note This method is guaranteed to return the same object for all models in the same group, at least between calls to `update`.\n */\n public getDisplayTransform(modelId: Id64String): ModelDisplayTransform | undefined {\n return this._state.transforms.find((x) => x.modelIds.has(modelId))?.transform;\n }\n\n // Update the display transforms and the model groupings based on the transforms supplied by `provider`.\n // Return `true` if the groupings changed as a result.\n public update(provider: ModelDisplayTransformProvider | undefined): boolean {\n const prevState = this._state;\n this._state = this.computeState(provider);\n return this._state.guid !== prevState.guid;\n }\n\n private computeState(provider: ModelDisplayTransformProvider | undefined): ModelGroupDisplayTransformsState {\n if (!provider)\n return emptyState;\n\n const transforms: ModelGroupDisplayTransform[] = [];\n for (const modelId of this._modelIds) {\n const transform = provider.getModelDisplayTransform(modelId);\n if (transform) {\n let entry = transforms.find((x) => equalDisplayTransforms(transform, x.transform));\n if (!entry)\n transforms.push(entry = { transform, modelIds: new Set() });\n\n entry.modelIds.add(modelId);\n }\n }\n\n if (transforms.length === 0)\n return emptyState;\n\n const guid = transforms.map((x) => CompressedId64Set.compressSet(x.modelIds)).sort().join(\"_\");\n return { transforms, guid };\n }\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itwin/frontend-tiles",
3
- "version": "5.0.0-dev.8",
3
+ "version": "5.0.0-dev.82",
4
4
  "description": "Experimental alternative technique for visualizing the contents of iModels",
5
5
  "main": "lib/cjs/frontend-tiles.js",
6
6
  "module": "lib/esm/frontend-tiles.js",
@@ -21,42 +21,42 @@
21
21
  "url": "http://www.bentley.com"
22
22
  },
23
23
  "peerDependencies": {
24
- "@itwin/core-bentley": "5.0.0-dev.8",
25
- "@itwin/core-common": "5.0.0-dev.8",
26
- "@itwin/core-geometry": "5.0.0-dev.8",
27
- "@itwin/core-frontend": "5.0.0-dev.8"
24
+ "@itwin/core-bentley": "5.0.0-dev.82",
25
+ "@itwin/core-common": "5.0.0-dev.82",
26
+ "@itwin/core-frontend": "5.0.0-dev.82",
27
+ "@itwin/core-geometry": "5.0.0-dev.82"
28
28
  },
29
29
  "devDependencies": {
30
30
  "@itwin/eslint-plugin": "5.0.0-dev.1",
31
31
  "@types/chai": "4.3.1",
32
32
  "@types/chai-as-promised": "^7",
33
33
  "@types/mocha": "^10.0.6",
34
- "@types/node": "~20.9.5",
34
+ "@types/node": "~20.17.0",
35
35
  "@types/sinon": "^17.0.2",
36
36
  "babel-loader": "~8.2.5",
37
- "babel-plugin-istanbul": "~6.1.1",
37
+ "babel-plugin-istanbul": "^7.0.0",
38
38
  "chai": "^4.3.10",
39
39
  "chai-as-promised": "^7.1.1",
40
40
  "eslint": "^9.13.0",
41
41
  "glob": "^10.3.12",
42
- "mocha": "^10.2.0",
43
- "rimraf": "^3.0.2",
42
+ "mocha": "^11.1.0",
43
+ "rimraf": "^6.0.1",
44
44
  "sinon": "^17.0.2",
45
- "source-map-loader": "^4.0.0",
45
+ "source-map-loader": "^5.0.0",
46
46
  "typescript": "~5.6.2",
47
- "webpack": "^5.76.0",
48
- "@itwin/build-tools": "5.0.0-dev.8",
49
- "@itwin/core-frontend": "5.0.0-dev.8",
50
- "@itwin/core-bentley": "5.0.0-dev.8",
51
- "@itwin/core-common": "5.0.0-dev.8",
52
- "@itwin/certa": "5.0.0-dev.8",
53
- "@itwin/core-geometry": "5.0.0-dev.8"
47
+ "webpack": "^5.97.1",
48
+ "@itwin/build-tools": "5.0.0-dev.82",
49
+ "@itwin/certa": "5.0.0-dev.82",
50
+ "@itwin/core-bentley": "5.0.0-dev.82",
51
+ "@itwin/core-geometry": "5.0.0-dev.82",
52
+ "@itwin/core-common": "5.0.0-dev.82",
53
+ "@itwin/core-frontend": "5.0.0-dev.82"
54
54
  },
55
55
  "scripts": {
56
56
  "build": "npm run -s build:cjs && npm run -s build:esm",
57
57
  "build:cjs": "tsc 1>&2 --outDir lib/cjs",
58
- "build:esm": "tsc 1>&2 --module ES2020 --outDir lib/esm",
59
- "clean": "rimraf lib .rush/temp/package-deps*.json",
58
+ "build:esm": "tsc 1>&2 --module ES2022 --outDir lib/esm",
59
+ "clean": "rimraf -g lib .rush/temp/package-deps*.json",
60
60
  "cover": "npm -s test",
61
61
  "docs": "",
62
62
  "extract-api": "betools extract-api --entry=frontend-tiles",