Skip to content

Commit

Permalink
Merge branch 'no-ready-promises' into model-ready
Browse files Browse the repository at this point in the history
  • Loading branch information
jjhembd authored Mar 28, 2023
2 parents d3af1ba + ba022f7 commit 72fddd6
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 35 deletions.
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/ArcticDEM.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
try {
// High-resolution arctic terrain from the Arctic DEM project (Release 4), tiled and hosted by Cesium ion.
// https://www.pgc.umn.edu/data/arcticdem/
viewer.scene.terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl(
Cesium.IonResource.fromAssetId(3956)
viewer.scene.terrainProvider = await Cesium.CesiumTerrainProvider.fromIonAssetId(
3956
);
} catch (error) {
window.alert(`Failed to load terrain. ${error}`);
Expand Down
4 changes: 2 additions & 2 deletions Apps/Sandcastle/gallery/PAMAP Terrain.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@
try {
// High resolution terrain of Pennsylvania curated by Pennsylvania Spatial Data Access (PASDA)
// http://www.pasda.psu.edu/
viewer.terrainProvider = await Cesium.CesiumTerrainProvider.fromUrl(
Cesium.IonResource.fromAssetId(3957)
viewer.terrainProvider = await Cesium.CesiumTerrainProvider.fromIonAssetId(
3957
);
} catch (error) {
window.alert(`Failed to load terrain. ${error}`);
Expand Down
4 changes: 2 additions & 2 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ try {

##### Additions :tada:

- Added `ArcGisMapServerImageryProvider.fromUrl`, `ArcGISTiledElevationTerrainProvider.fromUrl`, `BingMapsImageryProvider.fromUrl`, `CesiumTerrainProvider.fromUrl`, `GoogleEarthEnterpriseMetadata.fromUrl`, `GoogleEarthEnterpriseImageryProvider.fromMetadata`, `GoogleEarthEnterpriseMapsProvider.fromUrl`, `GoogleEarthEnterpriseTerrainProvider.fromMetadata`, `ImageryLayer.fromProviderAsync`, `IonImageryProvider.fromAssetId`, `SingleTileImageryProvider.fromUrl`, `Terrain`, `TileMapServiceImageryProvider.fromUrl`, `VRTheWorldTerrainProvider.fromUrl`, `createWorldTerrainAsync`, `Cesium3DTileset.fromUrl`, `Cesium3DTileset.fromIonAssetId`, `createOsmBuildingsAsync`, `Model.fromGltfAsync`, `Model.readyEvent`, `Model.errorEvent`,`Model.texturesReadyEvent`, `I3SDataProvider.fromUrl`, and `Cesium3DTilesVoxelProvider.fromUrl` for better async flow and error handling.
- Added `ArcGisMapServerImageryProvider.fromUrl`, `ArcGISTiledElevationTerrainProvider.fromUrl`, `BingMapsImageryProvider.fromUrl`, `CesiumTerrainProvider.fromUrl`, `CesiumTerrainProvider.fromIonAssetId`, `GoogleEarthEnterpriseMetadata.fromUrl`, `GoogleEarthEnterpriseImageryProvider.fromMetadata`, `GoogleEarthEnterpriseMapsProvider.fromUrl`, `GoogleEarthEnterpriseTerrainProvider.fromMetadata`, `ImageryLayer.fromProviderAsync`, `IonImageryProvider.fromAssetId`, `SingleTileImageryProvider.fromUrl`, `Terrain`, `TileMapServiceImageryProvider.fromUrl`, `VRTheWorldTerrainProvider.fromUrl`, `createWorldTerrainAsync`, `Cesium3DTileset.fromUrl`, `Cesium3DTileset.fromIonAssetId`, `createOsmBuildingsAsync`, `Model.fromGltfAsync`, `Model.readyEvent`, `Model.errorEvent`,`Model.texturesReadyEvent`, `I3SDataProvider.fromUrl`, and `Cesium3DTilesVoxelProvider.fromUrl` for better async flow and error handling.

##### Fixes :wrench:

Expand Down Expand Up @@ -52,7 +52,7 @@ try {
- `TerrainProvider.ready` and `TerrainProvider.readyPromise` were deprecated in CesiumJS 1.104. They will be removed in 1.107.
- `createWorldImagery` was deprecated in CesiumJS 1.104. It will be removed in 1.107. Use `createWorldImageryAsync` instead.
- `ArcGISTiledElevationTerrainProvider` constructor parameter `options.url`, `ArcGISTiledElevationTerrainProvider.ready`, and `ArcGISTiledElevationTerrainProvider.readyPromise` were deprecated in CesiumJS 1.104. They will be removed in 1.107. Use `ArcGISTiledElevationTerrainProvider.fromUrl` instead.
- `CesiumTerrainProvider` constructor parameter `options.url`, `CesiumTerrainProvider.ready`, and `CesiumTerrainProvider.readyPromise` were deprecated in CesiumJS 1.104. They will be removed in 1.107. Use `CesiumTerrainProvider.fromUrl` instead.
- `CesiumTerrainProvider` constructor parameter `options.url`, `CesiumTerrainProvider.ready`, and `CesiumTerrainProvider.readyPromise` were deprecated in CesiumJS 1.104. They will be removed in 1.107. Use `CesiumTerrainProvider.fromIonAssetId` or `CesiumTerrainProvider.fromUrl` instead.
- `CustomHeightmapTerrainProvider.ready`, and `CustomHeightmapTerrainProvider.readyPromise` were deprecated in CesiumJS 1.104.
- `EllipsoidTerrainProvider.ready`, and `EllipsoidTerrainProvider.readyPromise` were deprecated in CesiumJS 1.104.
- `GoogleEarthEnterpriseMetadata` constructor parameter `options.url` and `GoogleEarthEnterpriseMetadata.readyPromise` were deprecated in CesiumJS 1.104. They will be removed in 1.107. Use `GoogleEarthEnterpriseMetadata.fromUrl` instead.
Expand Down
54 changes: 47 additions & 7 deletions packages/engine/Source/Core/CesiumTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import WebMercatorTilingScheme from "./WebMercatorTilingScheme.js";
import getJsonFromTypedArray from "./getJsonFromTypedArray.js";
import HeightmapTerrainData from "./HeightmapTerrainData.js";
import IndexDatatype from "./IndexDatatype.js";
import IonResource from "./IonResource.js";
import OrientedBoundingBox from "./OrientedBoundingBox.js";
import QuantizedMeshTerrainData from "./QuantizedMeshTerrainData.js";
import Request from "./Request.js";
Expand Down Expand Up @@ -444,7 +445,7 @@ async function requestLayerJson(terrainProviderBuilder, provider) {

/**
* <div class="notice">
* To construct a CesiumTerrainProvider, call {@link CesiumTerrainProvider.fromUrl}. Do not call the constructor directly.
* To construct a CesiumTerrainProvider, call {@link CesiumTerrainProvider.fromIonAssetId} or {@link CesiumTerrainProvider.fromUrl}. Do not call the constructor directly.
* </div>
*
* A {@link TerrainProvider} that accesses terrain data in a Cesium terrain format.
Expand All @@ -463,9 +464,8 @@ async function requestLayerJson(terrainProviderBuilder, provider) {
* // Create Arctic DEM terrain with normals.
* try {
* const viewer = new Cesium.Viewer("cesiumContainer", {
* terrainProvider: await Cesium.CesiumTerrainProvider.fromUrl(
* Cesium.IonResource.fromAssetId(3956), {
* requestVertexNormals: true
* terrainProvider: await Cesium.CesiumTerrainProvider.fromIonAssetId(3956, {
* requestVertexNormals: true
* })
* });
* } catch (error) {
Expand All @@ -474,6 +474,7 @@ async function requestLayerJson(terrainProviderBuilder, provider) {
*
* @see createWorldTerrain
* @see CesiumTerrainProvider.fromUrl
* @see CesiumTerrainProvider.fromIonAssetId
* @see TerrainProvider
*/
function CesiumTerrainProvider(options) {
Expand Down Expand Up @@ -534,7 +535,7 @@ function CesiumTerrainProvider(options) {
if (defined(options.url)) {
deprecationWarning(
"CesiumTerrainProvider options.url",
"options.url was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromUrl instead."
"options.url was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromIonAssetId or CesiumTerrainProvider.fromUrl instead."
);
this._readyPromise = CesiumTerrainProvider._initializeReadyPromise(
options,
Expand Down Expand Up @@ -1061,7 +1062,7 @@ Object.defineProperties(CesiumTerrainProvider.prototype, {
get: function () {
deprecationWarning(
"CesiumTerrainProvider.ready",
"CesiumTerrainProvider.ready was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromUrl instead."
"CesiumTerrainProvider.ready was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromIonAssetId or CesiumTerrainProvider.fromUrl instead."
);
return this._ready;
},
Expand All @@ -1078,7 +1079,7 @@ Object.defineProperties(CesiumTerrainProvider.prototype, {
get: function () {
deprecationWarning(
"CesiumTerrainProvider.readyPromise",
"CesiumTerrainProvider.readyPromise was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromUrl instead."
"CesiumTerrainProvider.readyPromise was deprecated in CesiumJS 1.104. It will be in CesiumJS 1.107. Use CesiumTerrainProvider.fromIonAssetId or CesiumTerrainProvider.fromUrl instead."
);
return this._readyPromise;
},
Expand Down Expand Up @@ -1196,6 +1197,45 @@ CesiumTerrainProvider.prototype.getLevelMaximumGeometricError = function (
return this._levelZeroMaximumGeometricError / (1 << level);
};

/**
* Creates a {@link TerrainProvider} from a Cesium ion asset ID that accesses terrain data in a Cesium terrain format
* Terrain formats can be one of the following:
* <ul>
* <li> {@link https://github.com/AnalyticalGraphicsInc/quantized-mesh Quantized Mesh} </li>
* <li> {@link https://github.com/AnalyticalGraphicsInc/cesium/wiki/heightmap-1.0 Height Map} </li>
* </ul>
*
* @param {Resource|String|Promise<Resource>|Promise<String>} url The URL of the Cesium terrain server.
* @param {CesiumTerrainProvider.ConstructorOptions} [options] An object describing initialization options.
* @returns {Promise<CesiumTerrainProvider>}
*
* @example
* // Create Arctic DEM terrain with normals.
* try {
* const viewer = new Cesium.Viewer("cesiumContainer", {
* terrainProvider: await Cesium.CesiumTerrainProvider.fromIonAssetId(3956, {
* requestVertexNormals: true
* })
* });
* } catch (error) {
* console.log(error);
* }
*
* @exception {RuntimeError} layer.json does not specify a format
* @exception {RuntimeError} layer.json specifies an unknown format
* @exception {RuntimeError} layer.json specifies an unsupported quantized-mesh version
* @exception {RuntimeError} layer.json does not specify a tiles property, or specifies an empty array
* @exception {RuntimeError} layer.json does not specify any tile URL templates
*/
CesiumTerrainProvider.fromIonAssetId = async function (assetId, options) {
//>>includeStart('debug', pragmas.debug);
Check.defined("assetId", assetId);
//>>includeEnd('debug');

const resource = await IonResource.fromAssetId(assetId);
return CesiumTerrainProvider.fromUrl(resource, options);
};

/**
* Creates a {@link TerrainProvider} that accesses terrain data in a Cesium terrain format.
* Terrain formats can be one of the following:
Expand Down
2 changes: 1 addition & 1 deletion packages/engine/Source/Core/VRTheWorldTerrainProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async function requestMetadata(terrainProviderBuilder, resource, provider) {

/**
* <div class="notice">
* To construct a CesiumTerrainProvider, call {@link CesiumTerrainProvider.fromUrl}. Do not call the constructor directly.
* To construct a VRTheWorldTerrainProvider, call {@link VRTheWorldTerrainProvider.fromUrl}. Do not call the constructor directly.
* </div>
*
* A {@link TerrainProvider} that produces terrain geometry by tessellating height maps
Expand Down
3 changes: 1 addition & 2 deletions packages/engine/Source/Core/createWorldTerrainAsync.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import CesiumTerrainProvider from "./CesiumTerrainProvider.js";
import defaultValue from "./defaultValue.js";
import IonResource from "./IonResource.js";

/**
* Creates a {@link CesiumTerrainProvider} instance for the {@link https://cesium.com/content/#cesium-world-terrain|Cesium World Terrain}.
Expand Down Expand Up @@ -41,7 +40,7 @@ import IonResource from "./IonResource.js";
function createWorldTerrainAsync(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

return CesiumTerrainProvider.fromUrl(IonResource.fromAssetId(1), {
return CesiumTerrainProvider.fromIonAssetId(1, {
requestVertexNormals: defaultValue(options.requestVertexNormals, false),
requestWaterMask: defaultValue(options.requestWaterMask, false),
});
Expand Down
8 changes: 8 additions & 0 deletions packages/engine/Specs/Core/CesiumTerrainProviderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@ describe("Core/CesiumTerrainProvider", function () {
expect(CesiumTerrainProvider).toConformToInterface(TerrainProvider);
});

it("fromIonAssetId throws without assetId", async function () {
await expectAsync(
CesiumTerrainProvider.fromIonAssetId()
).toBeRejectedWithDeveloperError(
"assetId is required, actual value was undefined"
);
});

it("fromUrl throws without url", async function () {
await expectAsync(
CesiumTerrainProvider.fromUrl()
Expand Down
12 changes: 7 additions & 5 deletions packages/engine/Specs/Scene/BillboardCollectionSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ describe(
expect(b._clampedPosition).toBeUndefined();
});

it("changing the terrain provider", function () {
it("changing the terrain provider", async function () {
const b = billboardsWithHeight.add({
heightReference: HeightReference.CLAMP_TO_GROUND,
position: Cartesian3.fromDegrees(-72.0, 40.0),
Expand All @@ -2512,10 +2512,12 @@ describe(

spyOn(b, "_updateClamping").and.callThrough();

const terrainProvider = new CesiumTerrainProvider({
url: "made/up/url",
requestVertexNormals: true,
});
const terrainProvider = await CesiumTerrainProvider.fromUrl(
"made/up/url",
{
requestVertexNormals: true,
}
);

scene.terrainProvider = terrainProvider;

Expand Down
34 changes: 20 additions & 14 deletions packages/engine/Specs/Scene/GlobeSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,11 +227,13 @@ describe(
});
});

it("terrainProviderChanged event fires", function () {
const terrainProvider = new CesiumTerrainProvider({
url: "made/up/url",
requestVertexNormals: true,
});
it("terrainProviderChanged event fires", async function () {
const terrainProvider = await CesiumTerrainProvider.fromUrl(
"made/up/url",
{
requestVertexNormals: true,
}
);

const spyListener = jasmine.createSpy("listener");
globe.terrainProviderChanged.addEventListener(spyListener);
Expand All @@ -241,7 +243,7 @@ describe(
expect(spyListener).toHaveBeenCalledWith(terrainProvider);
});

it("tilesLoaded return true when tile load queue is empty", function () {
it("tilesLoaded return true when tile load queue is empty", async function () {
expect(globe.tilesLoaded).toBe(true);

globe._surface._tileLoadQueueHigh.length = 2;
Expand All @@ -262,10 +264,12 @@ describe(
globe._surface._tileLoadQueueLow.length = 0;
expect(globe.tilesLoaded).toBe(true);

const terrainProvider = new CesiumTerrainProvider({
url: "made/up/url",
requestVertexNormals: true,
});
const terrainProvider = await CesiumTerrainProvider.fromUrl(
"made/up/url",
{
requestVertexNormals: true,
}
);

globe.terrainProvider = terrainProvider;
scene.render();
Expand Down Expand Up @@ -306,10 +310,12 @@ describe(

returnVertexNormalTileJson();

const terrainProvider = new CesiumTerrainProvider({
url: "made/up/url",
requestVertexNormals: true,
});
const terrainProvider = await CesiumTerrainProvider.fromUrl(
"made/up/url",
{
requestVertexNormals: true,
}
);

globe.terrainProvider = terrainProvider;
scene.camera.setView({
Expand Down

0 comments on commit 72fddd6

Please sign in to comment.