Skip to content

Commit

Permalink
Update Sandcastles
Browse files Browse the repository at this point in the history
  • Loading branch information
ggetz committed Mar 20, 2023
1 parent 0a498ca commit 4f8c8cd
Show file tree
Hide file tree
Showing 49 changed files with 979 additions and 877 deletions.
3 changes: 1 addition & 2 deletions Apps/Sandcastle/gallery/3D Tiles BIM.html
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,7 @@
});
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}
//Sandcastle_End
} //Sandcastle_End
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
Expand Down
152 changes: 78 additions & 74 deletions Apps/Sandcastle/gallery/3D Tiles Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
}

let tileset;
function loadTileset(url) {
async function loadTileset(resource) {
const currentExampleType = viewModel.currentExampleType;
clippingPlanes = new Cesium.ClippingPlaneCollection({
planes: [
new Cesium.ClippingPlane(
Expand All @@ -153,77 +154,76 @@
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)
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,11 +308,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).then(() => {
// Position the instanced tileset above terrain
tileset.modelMatrix = new Cesium.Matrix4.fromTranslation(
new Cesium.Cartesian3(15.0, -58.6, 50.825)
);
});
} else {
loadModel(modelUrl);
}
Expand All @@ -336,7 +337,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
10 changes: 6 additions & 4 deletions Apps/Sandcastle/gallery/3D Tiles Feature Picking.html
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,12 @@
});

// Load the NYC buildings tileset
const tileset = new Cesium.Cesium3DTileset({
url: Cesium.IonResource.fromAssetId(75343),
});
viewer.scene.primitives.add(tileset);
try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(75343);
viewer.scene.primitives.add(tileset);
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}

// HTML overlay for showing feature name on mouseover
const nameOverlay = document.createElement("div");
Expand Down
2 changes: 1 addition & 1 deletion Apps/Sandcastle/gallery/3D Tiles Feature Styling.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h1>Loading...</h1>
const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);

// Add Cesium OSM buildings to the scene as our example 3D Tileset.
const osmBuildingsTileset = Cesium.createOsmBuildings();
const osmBuildingsTileset = await Cesium.createOsmBuildingsAsync();
viewer.scene.primitives.add(osmBuildingsTileset);

// Set the initial camera to look at Seattle
Expand Down
83 changes: 43 additions & 40 deletions Apps/Sandcastle/gallery/3D Tiles Formats.html
Original file line number Diff line number Diff line change
Expand Up @@ -140,59 +140,62 @@
viewer.shadows = enabled;
});

let resourceToLoad;
Cesium.knockout
.getObservable(viewModel, "selectedTileset")
.subscribe(function (options) {
.subscribe(async function (options) {
if (Cesium.defined(tileset)) {
scene.primitives.remove(tileset);
}
if (!Cesium.defined(options)) {
inspectorViewModel.tileset = undefined;
resourceToLoad = undefined;
return;
}

tileset = viewer.scene.primitives.add(
new Cesium.Cesium3DTileset({
url: options.resource,
resourceToLoad = options.resource;
try {
tileset = await Cesium.Cesium3DTileset.fromUrl(resourceToLoad, {
enableDebugWireframe: true,
})
);
});
if (options.resource !== resourceToLoad) {
// Another tileset was loaded. Discard the result.
return;
}
viewer.scene.primitives.add(tileset);

tileset.readyPromise
.then(function () {
inspectorViewModel.tileset = tileset;
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0,
-2.0,
Math.max(100.0 - tileset.boundingSphere.radius, 0.0)
)
);
inspectorViewModel.tileset = tileset;
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0,
-2.0,
Math.max(100.0 - tileset.boundingSphere.radius, 0.0)
)
);

const properties = tileset.properties;
if (
Cesium.defined(properties) &&
Cesium.defined(properties.Height)
) {
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
["${Height} >= 83", "color('purple', 0.5)"],
["${Height} >= 80", "color('red')"],
["${Height} >= 70", "color('orange')"],
["${Height} >= 12", "color('yellow')"],
["${Height} >= 7", "color('lime')"],
["${Height} >= 1", "color('cyan')"],
["true", "color('blue')"],
],
},
});
}
})
.catch(function (error) {
throw error;
});
const properties = tileset.properties;
if (
Cesium.defined(properties) &&
Cesium.defined(properties.Height)
) {
tileset.style = new Cesium.Cesium3DTileStyle({
color: {
conditions: [
["${Height} >= 83", "color('purple', 0.5)"],
["${Height} >= 80", "color('red')"],
["${Height} >= 70", "color('orange')"],
["${Height} >= 12", "color('yellow')"],
["${Height} >= 7", "color('lime')"],
["${Height} >= 1", "color('cyan')"],
["true", "color('blue')"],
],
},
});
}
} catch (error) {
console.log(`Error loading tileset: ${error}`);
}
});

viewModel.selectedTileset = viewModel.tilesets[0];
Expand Down
31 changes: 16 additions & 15 deletions Apps/Sandcastle/gallery/3D Tiles Inspector.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,23 @@
viewer.extend(Cesium.viewerCesium3DTilesInspectorMixin);
const inspectorViewModel = viewer.cesium3DTilesInspector.viewModel;

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

await tileset.readyPromise;
try {
const tileset = await Cesium.Cesium3DTileset.fromIonAssetId(75343, {
enableDebugWireframe: true,
});
viewer.scene.primitives.add(tileset);

viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.0,
-0.5,
tileset.boundingSphere.radius / 4.0
)
); //Sandcastle_End
viewer.zoomTo(
tileset,
new Cesium.HeadingPitchRange(
0.0,
-0.5,
tileset.boundingSphere.radius / 4.0
)
);
} catch (error) {
console.log(`Error loading tileset: ${error}`);
} //Sandcastle_End
};
if (typeof Cesium !== "undefined") {
window.startupCalled = true;
Expand Down
Loading

0 comments on commit 4f8c8cd

Please sign in to comment.