Skip to content

Commit

Permalink
rename namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
jjspace committed Nov 15, 2024
1 parent dc79961 commit 46bd2f0
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 41 deletions.
8 changes: 4 additions & 4 deletions Apps/Sandcastle/gallery/iTwin Demo.html
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -123,20 +123,20 @@

statusOutput.innerText = "Creating Tileset";

let tileset = await Cesium.createIModel3DTileset.fromModelId(
let tileset = await Cesium.ITwinData.createTilesetFromModelId(
imodelId,
changesetId,
);
if (!Cesium.defined(tileset)) {
// 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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
*/
Expand All @@ -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",
Expand All @@ -73,7 +73,7 @@ ITwin.ExportStatus = Object.freeze({
/**
* @enum {string}
*/
ITwin.ExportType = Object.freeze({
ITwinPlatform.ExportType = Object.freeze({
IMODEL: "IMODEL",
CESIUM: "CESIUM",
"3DTILES": "3DTILES",
Expand All @@ -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.
Expand All @@ -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",
});

Expand All @@ -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
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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')
Expand All @@ -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,
);

Expand Down Expand Up @@ -310,4 +310,4 @@ ITwin.createExportForModelId = async function (iModelId, changesetId) {
return result.export.id;
};

export default ITwin;
export default ITwinPlatform;
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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}`);

Expand All @@ -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.
Expand All @@ -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;
};
Expand All @@ -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
Expand All @@ -99,20 +99,20 @@ 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;
}
return loadExport(cesiumExport, options);
};

export default createIModel3DTileset;
export default ITwinData;

0 comments on commit 46bd2f0

Please sign in to comment.