Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate Model and Cesium3DTileset readyPromise #11173

Merged
merged 22 commits into from
Mar 28, 2023
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 19 additions & 22 deletions Apps/Sandcastle/gallery/3D Tiles Adjust Height.html
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
shadows: true,
});

viewer.scene.globe.depthTestAgainstTerrain = true;

const viewModel = {
height: 0,
};
Expand All @@ -71,31 +69,30 @@
const toolbar = document.getElementById("toolbar");
Cesium.knockout.applyBindings(viewModel, toolbar);

const tileset = new Cesium.Cesium3DTileset({
url: "../../SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json",
});

tileset.readyPromise
.then(function (tileset) {
viewer.scene.primitives.add(tileset);
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.0,
-0.5,
tileset.boundingSphere.radius * 2.0
)
);
})
.catch(function (error) {
console.log(error);
});
let tileset;
try {
tileset = await Cesium.Cesium3DTileset.fromUrl(
"../../SampleData/Cesium3DTiles/Tilesets/Tileset/tileset.json"
);
viewer.scene.primitives.add(tileset);
viewer.scene.globe.depthTestAgainstTerrain = true;
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.0,
-0.5,
tileset.boundingSphere.radius * 2.0
)
);
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}

Cesium.knockout
.getObservable(viewModel, "height")
.subscribe(function (height) {
height = Number(height);
if (isNaN(height)) {
if (isNaN(height) || !Cesium.defined(tileset)) {
return;
}

Expand Down
53 changes: 23 additions & 30 deletions Apps/Sandcastle/gallery/3D Tiles BIM.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,29 +43,6 @@
"2022-08-01T00:00:00Z"
);

const tileset = scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(1240402),
})
);

tileset.readyPromise
.then(function (tileset) {
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.5,
-0.2,
tileset.boundingSphere.radius * 4.0
)
);
})
.catch(function (error) {
console.log(error);
});

tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.REPLACE;

let selectedFeature;
let picking = false;

Expand Down Expand Up @@ -209,14 +186,30 @@
}
}

tileset.tileLoad.addEventListener(function (tile) {
processTileFeatures(tile, loadFeature);
});
try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(1240402);
scene.primitives.add(tileset);

viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.5,
-0.2,
tileset.boundingSphere.radius * 4.0
)
);

tileset.colorBlendMode = Cesium.Cesium3DTileColorBlendMode.REPLACE;
tileset.tileLoad.addEventListener(function (tile) {
processTileFeatures(tile, loadFeature);
});

tileset.tileUnload.addEventListener(function (tile) {
processTileFeatures(tile, unloadFeature);
});
//Sandcastle_End
tileset.tileUnload.addEventListener(function (tile) {
processTileFeatures(tile, unloadFeature);
});
} catch (error) {
console.log(`Error loading tileset: ${error}`);
} //Sandcastle_End
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
Expand Down
32 changes: 20 additions & 12 deletions Apps/Sandcastle/gallery/3D Tiles Batch Table Hierarchy.html
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,27 @@
const viewer = new Cesium.Viewer("cesiumContainer");
viewer.clock.currentTime = new Cesium.JulianDate(2457522.154792);

const tileset = new Cesium.Cesium3DTileset({
url:
"../../SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json",
});
let tileset;
try {
tileset = await Cesium.Cesium3DTileset.fromUrl(
"../../SampleData/Cesium3DTiles/Hierarchy/BatchTableHierarchy/tileset.json"
);

viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.3, 0.0));
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}

viewer.scene.primitives.add(tileset);
viewer.zoomTo(tileset, new Cesium.HeadingPitchRange(0.0, -0.3, 0.0));
function setStyle(style) {
return function () {
if (!Cesium.defined(tileset)) {
return;
}

tileset.style = new Cesium.Cesium3DTileStyle(style);
};
}

const styles = [];
function addStyle(name, style) {
Expand Down Expand Up @@ -167,12 +181,6 @@
},
});

function setStyle(style) {
return function () {
tileset.style = new Cesium.Cesium3DTileStyle(style);
};
}

const styleOptions = [];
for (let i = 0; i < styles.length; ++i) {
const style = styles[i];
Expand Down
153 changes: 82 additions & 71 deletions Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,9 @@
}

let tileset;
function loadTileset(url) {
async function loadTileset(resource, modelMatrix) {
const currentExampleType = viewModel.currentExampleType;

clippingPlanes = new Cesium.ClippingPlaneCollection({
planes: [
new Cesium.ClippingPlane(
Expand All @@ -153,77 +155,81 @@
edgeWidth: viewModel.edgeStylingEnabled ? 1.0 : 0.0,
});

tileset = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: url,
try {
const url = await Promise.resolve(resource);
tileset = await Cesium.Cesium3DTileset.fromUrl(url, {
clippingPlanes: clippingPlanes,
})
);
});

tileset.debugShowBoundingVolume =
viewModel.debugBoundingVolumesEnabled;
return tileset.readyPromise
.then(function () {
const boundingSphere = tileset.boundingSphere;
const radius = boundingSphere.radius;
if (currentExampleType !== viewModel.currentExampleType) {
// Another tileset was loaded, discard the current result
return;
}

viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0)
if (Cesium.defined(modelMatrix)) {
tileset.modelMatrix = modelMatrix;
}

viewer.scene.primitives.add(tileset);

tileset.debugShowBoundingVolume =
viewModel.debugBoundingVolumesEnabled;
const boundingSphere = tileset.boundingSphere;
const radius = boundingSphere.radius;

viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(0.5, -0.2, radius * 4.0)
);

if (
!Cesium.Matrix4.equals(
tileset.root.transform,
Cesium.Matrix4.IDENTITY
)
) {
// The clipping plane is initially positioned at the tileset's root transform.
// Apply an additional matrix to center the clipping plane on the bounding sphere center.
const transformCenter = Cesium.Matrix4.getTranslation(
tileset.root.transform,
new Cesium.Cartesian3()
);
const transformCartographic = Cesium.Cartographic.fromCartesian(
transformCenter
);
const boundingSphereCartographic = Cesium.Cartographic.fromCartesian(
tileset.boundingSphere.center
);
const height =
boundingSphereCartographic.height -
transformCartographic.height;
clippingPlanes.modelMatrix = Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(0.0, 0.0, height)
);
}

if (
!Cesium.Matrix4.equals(
tileset.root.transform,
Cesium.Matrix4.IDENTITY
)
) {
// The clipping plane is initially positioned at the tileset's root transform.
// Apply an additional matrix to center the clipping plane on the bounding sphere center.
const transformCenter = Cesium.Matrix4.getTranslation(
tileset.root.transform,
new Cesium.Cartesian3()
);
const transformCartographic = Cesium.Cartographic.fromCartesian(
transformCenter
);
const boundingSphereCartographic = Cesium.Cartographic.fromCartesian(
tileset.boundingSphere.center
);
const height =
boundingSphereCartographic.height -
transformCartographic.height;
clippingPlanes.modelMatrix = Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(0.0, 0.0, height)
);
}

for (let i = 0; i < clippingPlanes.length; ++i) {
const plane = clippingPlanes.get(i);
const planeEntity = viewer.entities.add({
position: boundingSphere.center,
plane: {
dimensions: new Cesium.Cartesian2(
radius * 2.5,
radius * 2.5
),
material: Cesium.Color.WHITE.withAlpha(0.1),
plane: new Cesium.CallbackProperty(
createPlaneUpdateFunction(plane),
false
),
outline: true,
outlineColor: Cesium.Color.WHITE,
},
});

planeEntities.push(planeEntity);
}
return tileset;
})
.catch(function (error) {
console.log(error);
});
for (let i = 0; i < clippingPlanes.length; ++i) {
const plane = clippingPlanes.get(i);
const planeEntity = viewer.entities.add({
position: boundingSphere.center,
plane: {
dimensions: new Cesium.Cartesian2(radius * 2.5, radius * 2.5),
material: Cesium.Color.WHITE.withAlpha(0.1),
plane: new Cesium.CallbackProperty(
createPlaneUpdateFunction(plane),
false
),
outline: true,
outlineColor: Cesium.Color.WHITE,
},
});

planeEntities.push(planeEntity);
}
return tileset;
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}
}

function loadModel(url) {
Expand Down Expand Up @@ -308,10 +314,12 @@
} else if (newValue === clipObjects[1]) {
loadTileset(pointCloudUrl);
} else if (newValue === clipObjects[2]) {
loadTileset(instancedUrl);
// Position the instanced tileset above terrain
tileset.modelMatrix = new Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(15.0, -58.6, 50.825)
loadTileset(
instancedUrl,
Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(15.0, -58.6, 50.825)
)
);
} else {
loadModel(modelUrl);
Expand All @@ -336,7 +344,10 @@

function reset() {
viewer.entities.removeAll();
viewer.scene.primitives.remove(tileset);
if (Cesium.defined(tileset)) {
viewer.scene.primitives.remove(tileset);
}

planeEntities = [];
targetY = 0.0;
tileset = undefined;
Expand Down
21 changes: 11 additions & 10 deletions Apps/Sandcastle/gallery/3D Tiles Compare.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@
//Sandcastle_Begin
const viewer = new Cesium.Viewer("cesiumContainer");

const left = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(69380),
})
);
try {
const left = await Cesium.Cesium3DTileset.fromIonAssetId(69380);
viewer.scene.primitives.add(left);
left.splitDirection = Cesium.SplitDirection.LEFT;

left.splitDirection = Cesium.SplitDirection.LEFT;
viewer.zoomTo(left);

const right = viewer.scene.primitives.add(Cesium.createOsmBuildings());
right.splitDirection = Cesium.SplitDirection.RIGHT;

viewer.zoomTo(left);
const right = await Cesium.createOsmBuildingsAsync();
viewer.scene.primitives.add(right);
right.splitDirection = Cesium.SplitDirection.RIGHT;
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}

// Sync the position of the slider with the split position
const slider = document.getElementById("slider");
Expand Down
Loading