diff --git a/Apps/Sandcastle/gallery/iTwin Demo.html b/Apps/Sandcastle/gallery/iTwin Demo.html index a26bc50f5db..dc87286bcd2 100644 --- a/Apps/Sandcastle/gallery/iTwin Demo.html +++ b/Apps/Sandcastle/gallery/iTwin Demo.html @@ -33,7 +33,7 @@ const serviceResponse = await fetch("http://localhost:3000/service"); const { token } = await serviceResponse.json(); - Cesium.ITwin.defaultAccessToken = token; + Cesium.ITwinPlatform.defaultAccessToken = token; // this is the iModel in the "Hello iTwinCesium" iTwin that we should all have access to // https://developer.bentley.com/my-itwins/b4a30036-0456-49ea-a439-3fcd9365e24e/home/ // const imodelId = "2852c3d7-00c3-4b5d-a0ce-82bbde4f061e"; @@ -123,7 +123,7 @@ statusOutput.innerText = "Creating Tileset"; - let tileset = await Cesium.createIModel3DTileset.fromModelId( + let tileset = await Cesium.ITwinData.createTilesetFromModelId( imodelId, changesetId, ); @@ -131,12 +131,12 @@ // TODO: this is temporary, we should not have to call the Start Export route ever after // auto generation is set up statusOutput.innerText = "Starting export"; - const exportId = await Cesium.ITwin.createExportForModelId( + const exportId = await Cesium.ITwinPlatform.createExportForModelId( imodelId, changesetId, ); statusOutput.innerText = "Creating Tileset from export"; - tileset = await Cesium.createIModel3DTileset.fromExportId(exportId); + tileset = await Cesium.ITwinData.createTilesetFromExportId(exportId); } scene.primitives.add(tileset); diff --git a/packages/engine/Source/Core/ITwin.js b/packages/engine/Source/Core/ITwinPlatform.js similarity index 86% rename from packages/engine/Source/Core/ITwin.js rename to packages/engine/Source/Core/ITwinPlatform.js index 249acd76ef8..0131e8efd5e 100644 --- a/packages/engine/Source/Core/ITwin.js +++ b/packages/engine/Source/Core/ITwinPlatform.js @@ -26,7 +26,7 @@ import RuntimeError from "./RuntimeError.js"; * @typedef {Object} StartExport * @property {string} iModelId * @property {string} changesetId - * @property {ITwin.ExportType} exportType Type of mesh to create. Currently, only GLTF and 3DFT are supported and undocumented CESIUM option + * @property {ITwinPlatform.ExportType} exportType Type of mesh to create. Currently, only GLTF and 3DFT are supported and undocumented CESIUM option * @property {GeometryOptions} geometryOptions * @property {ViewDefinitionFilter} viewDefinitionFilter */ @@ -40,7 +40,7 @@ import RuntimeError from "./RuntimeError.js"; * @typedef {Object} Export * @property {string} id * @property {string} displayName - * @property {ITwin.ExportStatus} status + * @property {ITwinPlatform.ExportStatus} status * @property {StartExport} request * @property {{mesh: Link}} _links */ @@ -55,15 +55,15 @@ import RuntimeError from "./RuntimeError.js"; * * @experimental This feature is not final and is subject to change without Cesium's standard deprecation policy. * - * @see createIModel3DTileset - * @namespace ITwin + * @see ITwinData for ways to import data + * @namespace ITwinPlatform */ -const ITwin = {}; +const ITwinPlatform = {}; /** * @enum {string} */ -ITwin.ExportStatus = Object.freeze({ +ITwinPlatform.ExportStatus = Object.freeze({ NotStarted: "NotStarted", InProgress: "InProgress", Complete: "Complete", @@ -73,7 +73,7 @@ ITwin.ExportStatus = Object.freeze({ /** * @enum {string} */ -ITwin.ExportType = Object.freeze({ +ITwinPlatform.ExportType = Object.freeze({ IMODEL: "IMODEL", CESIUM: "CESIUM", "3DTILES": "3DTILES", @@ -94,7 +94,7 @@ ITwin.ExportType = Object.freeze({ * * @type {string|undefined} */ -ITwin.defaultAccessToken = undefined; +ITwinPlatform.defaultAccessToken = undefined; /** * Gets or sets the default iTwin API endpoint. @@ -104,7 +104,7 @@ ITwin.defaultAccessToken = undefined; * @type {string|Resource} * @default https://api.bentley.com */ -ITwin.apiEndpoint = new Resource({ +ITwinPlatform.apiEndpoint = new Resource({ url: "https://api.bentley.com", }); @@ -120,21 +120,21 @@ ITwin.apiEndpoint = new Resource({ * @throws {RuntimeError} Too many requests * @throws {RuntimeError} Unknown request failure */ -ITwin.getExport = async function (exportId) { +ITwinPlatform.getExport = async function (exportId) { //>>includeStart('debug', pragmas.debug); Check.typeOf.string("exportId", exportId); - if (!defined(ITwin.defaultAccessToken)) { + if (!defined(ITwinPlatform.defaultAccessToken)) { throw new DeveloperError("Must set ITwin.defaultAccessToken first"); } //>>includeEnd('debug') const headers = { - Authorization: `Bearer ${ITwin.defaultAccessToken}`, + Authorization: `Bearer ${ITwinPlatform.defaultAccessToken}`, Accept: "application/vnd.bentley.itwin-platform.v1+json", }; // obtain export for specified export id - const url = `${ITwin.apiEndpoint}mesh-export/${exportId}`; + const url = `${ITwinPlatform.apiEndpoint}mesh-export/${exportId}`; // TODO: this request is _really_ slow, like 7 whole second alone for me // Arun said this was kinda normal but to keep track of the `x-correlation-id` of any that take EXTRA long @@ -172,31 +172,31 @@ ITwin.getExport = async function (exportId) { * @throws {RuntimeError} Too many requests * @throws {RuntimeError} Unknown request failure */ -ITwin.getExports = async function (iModelId, changesetId) { +ITwinPlatform.getExports = async function (iModelId, changesetId) { //>>includeStart('debug', pragmas.debug); Check.typeOf.string("iModelId", iModelId); if (defined(changesetId)) { Check.typeOf.string("changesetId", changesetId); } - if (!defined(ITwin.defaultAccessToken)) { + if (!defined(ITwinPlatform.defaultAccessToken)) { throw new DeveloperError("Must set ITwin.defaultAccessToken first"); } //>>includeEnd('debug') const headers = { - Authorization: `Bearer ${ITwin.defaultAccessToken}`, + Authorization: `Bearer ${ITwinPlatform.defaultAccessToken}`, Accept: "application/vnd.bentley.itwin-platform.v1+json", Prefer: "return=representation", // or return=minimal (the default) }; // obtain export for specified export id // TODO: if we do include the clientVersion what should it be set to? can we sync it with the package.json? - const url = new URL(`${ITwin.apiEndpoint}mesh-export`); + const url = new URL(`${ITwinPlatform.apiEndpoint}mesh-export`); url.searchParams.set("iModelId", iModelId); if (defined(changesetId) && changesetId !== "") { url.searchParams.set("changesetId", changesetId); } - url.searchParams.set("exportType", ITwin.ExportType["3DTILES"]); + url.searchParams.set("exportType", ITwinPlatform.ExportType["3DTILES"]); url.searchParams.set("$top", "1"); url.searchParams.set("client", "CesiumJS"); /* global CESIUM_VERSION */ @@ -247,13 +247,13 @@ ITwin.getExports = async function (iModelId, changesetId) { * @throws {RuntimeError} Too many requests * @throws {RuntimeError} Unknown request failure */ -ITwin.createExportForModelId = async function (iModelId, changesetId) { +ITwinPlatform.createExportForModelId = async function (iModelId, changesetId) { //>>includeStart('debug', pragmas.debug); Check.typeOf.string("iModelId", iModelId); if (defined(changesetId)) { Check.typeOf.string("changesetId", changesetId); } - if (!defined(ITwin.defaultAccessToken)) { + if (!defined(ITwinPlatform.defaultAccessToken)) { throw new DeveloperError("Must set ITwin.defaultAccessToken first"); } //>>includeEnd('debug') @@ -263,20 +263,20 @@ ITwin.createExportForModelId = async function (iModelId, changesetId) { const requestOptions = { method: "POST", headers: { - Authorization: `Bearer ${ITwin.defaultAccessToken}`, + Authorization: `Bearer ${ITwinPlatform.defaultAccessToken}`, Accept: "application/vnd.bentley.itwin-platform.v1+json", "Content-Type": "application/json", }, body: JSON.stringify({ iModelId, changesetId, - exportType: ITwin.ExportType["3DTILES"], + exportType: ITwinPlatform.ExportType["3DTILES"], }), }; // initiate mesh export const response = await fetch( - `${ITwin.apiEndpoint}mesh-export/`, + `${ITwinPlatform.apiEndpoint}mesh-export/`, requestOptions, ); @@ -310,4 +310,4 @@ ITwin.createExportForModelId = async function (iModelId, changesetId) { return result.export.id; }; -export default ITwin; +export default ITwinPlatform; diff --git a/packages/engine/Source/Scene/createIModel3DTileset.js b/packages/engine/Source/Scene/ITwinData.js similarity index 81% rename from packages/engine/Source/Scene/createIModel3DTileset.js rename to packages/engine/Source/Scene/ITwinData.js index f4ebb904318..e64307798e9 100644 --- a/packages/engine/Source/Scene/createIModel3DTileset.js +++ b/packages/engine/Source/Scene/ITwinData.js @@ -1,7 +1,7 @@ import Cesium3DTileset from "./Cesium3DTileset.js"; import defined from "../Core/defined.js"; import Resource from "../Core/Resource.js"; -import ITwin from "../Core/ITwin.js"; +import ITwinPlatform from "../Core/ITwinPlatform.js"; import RuntimeError from "../Core/RuntimeError.js"; import Check from "../Core/Check.js"; @@ -20,16 +20,16 @@ async function loadExport(exportObj, options) { let status = exportObj.status; - if (exportObj.request.exportType !== ITwin.ExportType["3DTILES"]) { + if (exportObj.request.exportType !== ITwinPlatform.ExportType["3DTILES"]) { throw new RuntimeError(`Wrong export type ${exportObj.request.exportType}`); } const timeoutAfter = 300000; const start = Date.now(); // wait until the export is complete - while (status !== ITwin.ExportStatus.Complete) { + while (status !== ITwinPlatform.ExportStatus.Complete) { await delay(5000); - exportObj = (await ITwin.getExport(exportObj.id)).export; + exportObj = (await ITwinPlatform.getExport(exportObj.id)).export; status = exportObj.status; console.log(`Export is ${status}`); @@ -51,7 +51,7 @@ async function loadExport(exportObj, options) { return Cesium3DTileset.fromUrl(resource, options); } -const createIModel3DTileset = {}; +const ITwinData = {}; /** * Creates a {@link Cesium3DTileset} instance for the Google Photorealistic 3D Tiles tileset. @@ -69,10 +69,10 @@ const createIModel3DTileset = {}; * @example * TODO: example after API finalized */ -createIModel3DTileset.fromExportId = async function (exportId, options) { +ITwinData.createTilesetFromExportId = async function (exportId, options) { options = options ?? {}; - const result = await ITwin.getExport(exportId); + const result = await ITwinPlatform.getExport(exportId); const tileset = await loadExport(result.export, options); return tileset; }; @@ -81,10 +81,10 @@ createIModel3DTileset.fromExportId = async function (exportId, options) { * Check the exports for the given iModel + changeset combination for any that * have the desired CESIUM type and returns the first one that matches as a new tileset. * - * If there is not a CESIUM export you can create it using {@link ITwin.createExportForModelId} + * If there is not a CESIUM export you can create it using {@link ITwinPlatform.createExportForModelId} * * This function assumes one export per type per "iModel id + changeset id". If you need to create - * multiple exports per "iModel id + changeset id" you should switch to using {@link createIModel3DTileset} + * multiple exports per "iModel id + changeset id" you should switch to using {@link ITwinData} * with the export id directly * * @example @@ -99,15 +99,15 @@ createIModel3DTileset.fromExportId = async function (exportId, options) { * @throws {RuntimeError} Wrong export type * @throws {RuntimeError} Export did not complete in time. */ -createIModel3DTileset.fromModelId = async function ( +ITwinData.createTilesetFromModelId = async function ( iModelId, changesetId, options, ) { - const { exports } = await ITwin.getExports(iModelId, changesetId); + const { exports } = await ITwinPlatform.getExports(iModelId, changesetId); const cesiumExport = exports.find( (exportObj) => - exportObj.request?.exportType === ITwin.ExportType["3DTILES"], + exportObj.request?.exportType === ITwinPlatform.ExportType["3DTILES"], ); if (!defined(cesiumExport)) { return; @@ -115,4 +115,4 @@ createIModel3DTileset.fromModelId = async function ( return loadExport(cesiumExport, options); }; -export default createIModel3DTileset; +export default ITwinData;