Skip to content

Commit

Permalink
Merge pull request #8489 from AnalyticalGraphicsInc/show-skirts
Browse files Browse the repository at this point in the history
Globe show skirts option
  • Loading branch information
IanLilleyT authored Jan 6, 2020
2 parents 4a44e0e + 3dfd484 commit 215a588
Show file tree
Hide file tree
Showing 19 changed files with 472 additions and 271 deletions.
1 change: 1 addition & 0 deletions Apps/Sandcastle/gallery/Cartographic Limit Rectangle.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
var coffeeBeltRectangle = Cesium.Rectangle.fromDegrees(-180.0, -23.43687, 180.0, 23.43687);

viewer.scene.globe.cartographicLimitRectangle = coffeeBeltRectangle;
viewer.scene.globe.showSkirts = false;
viewer.scene.skyAtmosphere.show = false;

// Add rectangles to show bounds
Expand Down
6 changes: 6 additions & 0 deletions Apps/Sandcastle/gallery/Terrain Clipping Planes.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@
edgeColor: Cesium.Color.WHITE,
enabled : clippingPlanesEnabled
});
globe.backFaceCulling = true;
globe.showSkirts = true;

viewer.trackedEntity = entity;
}
Expand Down Expand Up @@ -156,6 +158,8 @@
edgeColor: Cesium.Color.WHITE,
enabled : clippingPlanesEnabled
});
globe.backFaceCulling = true;
globe.showSkirts = true;

// Load tileset
tileset = new Cesium.Cesium3DTileset({ url: Cesium.IonResource.fromAssetId(5713) });
Expand Down Expand Up @@ -201,6 +205,8 @@
],
unionClippingRegions : true
});
globe.backFaceCulling = false;
globe.showSkirts = false;

viewer.camera.viewBoundingSphere(boundingSphere, new Cesium.HeadingPitchRange(0.5, -0.5, boundingSphere.radius * 5.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
Expand Down
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ Change Log

### 1.66.0 - 2020-02-03

##### Additions :tada:

* Added `Globe.showSkirts` to support the ability to hide terrain skirts when viewing terrain from below the surface. [#8489](https://github.com/AnalyticalGraphicsInc/cesium/pull/8489)

##### Fixes :wrench:
* Fixed a bug where the camera could go underground during mouse navigation. [#8504](https://github.com/AnalyticalGraphicsInc/cesium/pull/8504)

Expand Down
12 changes: 5 additions & 7 deletions Source/Core/GoogleEarthEnterpriseTerrainData.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ import TerrainMesh from './TerrainMesh.js';
* });
*
* @see TerrainData
* @see HeightTerrainData
* @see HeightmapTerrainData
* @see QuantizedMeshTerrainData
*/
function GoogleEarthEnterpriseTerrainData(options) {
Expand Down Expand Up @@ -84,8 +84,6 @@ import TerrainMesh from './TerrainMesh.js';
this._mesh = undefined;
this._minimumHeight = undefined;
this._maximumHeight = undefined;
this._vertexCountWithoutSkirts = undefined;
this._skirtIndex = undefined;
}

defineProperties(GoogleEarthEnterpriseTerrainData.prototype, {
Expand Down Expand Up @@ -179,6 +177,8 @@ import TerrainMesh from './TerrainMesh.js';
center,
new Float32Array(result.vertices),
new Uint16Array(result.indices),
result.indexCountWithoutSkirts,
result.vertexCountWithoutSkirts,
result.minimumHeight,
result.maximumHeight,
BoundingSphere.clone(result.boundingSphere3D),
Expand All @@ -192,8 +192,6 @@ import TerrainMesh from './TerrainMesh.js';
result.eastIndicesNorthToSouth,
result.northIndicesWestToEast);

that._vertexCountWithoutSkirts = result.vertexCountWithoutSkirts;
that._skirtIndex = result.skirtIndex;
that._minimumHeight = result.minimumHeight;
that._maximumHeight = result.maximumHeight;

Expand Down Expand Up @@ -269,9 +267,9 @@ import TerrainMesh from './TerrainMesh.js';

var upsamplePromise = upsampleTaskProcessor.scheduleTask({
vertices : mesh.vertices,
vertexCountWithoutSkirts : this._vertexCountWithoutSkirts,
indices : mesh.indices,
skirtIndex : this._skirtIndex,
indexCountWithoutSkirts : mesh.indexCountWithoutSkirts,
vertexCountWithoutSkirts : mesh.vertexCountWithoutSkirts,
encoding : mesh.encoding,
minimumHeight : this._minimumHeight,
maximumHeight : this._maximumHeight,
Expand Down
67 changes: 35 additions & 32 deletions Source/Core/HeightmapTerrainData.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ import TerrainProvider from './TerrainProvider.js';
*
* @see TerrainData
* @see QuantizedMeshTerrainData
* @see GoogleEarthEnterpriseTerrainData
*/
function HeightmapTerrainData(options) {
//>>includeStart('debug', pragmas.debug);
Expand Down Expand Up @@ -233,12 +234,23 @@ import TerrainProvider from './TerrainProvider.js';

var that = this;
return when(verticesPromise, function(result) {
var indicesAndEdges;
if (that._skirtHeight > 0.0) {
indicesAndEdges = TerrainProvider.getRegularGridAndSkirtIndicesAndEdgeIndices(result.gridWidth, result.gridHeight);
} else {
indicesAndEdges = TerrainProvider.getRegularGridIndicesAndEdgeIndices(result.gridWidth, result.gridHeight);
}

var vertexCountWithoutSkirts = result.gridWidth * result.gridHeight;

// Clone complex result objects because the transfer from the web worker
// has stripped them down to JSON-style objects.
that._mesh = new TerrainMesh(
center,
new Float32Array(result.vertices),
TerrainProvider.getRegularGridIndices(result.gridWidth, result.gridHeight),
indicesAndEdges.indices,
indicesAndEdges.indexCountWithoutSkirts,
vertexCountWithoutSkirts,
result.minimumHeight,
result.maximumHeight,
BoundingSphere.clone(result.boundingSphere3D),
Expand All @@ -247,10 +259,10 @@ import TerrainProvider from './TerrainProvider.js';
OrientedBoundingBox.clone(result.orientedBoundingBox),
TerrainEncoding.clone(result.encoding),
exaggeration,
result.westIndicesSouthToNorth,
result.southIndicesEastToWest,
result.eastIndicesNorthToSouth,
result.northIndicesWestToEast);
indicesAndEdges.westIndicesSouthToNorth,
indicesAndEdges.southIndicesEastToWest,
indicesAndEdges.eastIndicesNorthToSouth,
indicesAndEdges.northIndicesWestToEast);

// Free memory received from server after mesh is created.
that._buffer = undefined;
Expand Down Expand Up @@ -309,20 +321,23 @@ import TerrainProvider from './TerrainProvider.js';
// Free memory received from server after mesh is created.
this._buffer = undefined;

var arrayWidth = this._width;
var arrayHeight = this._height;

var indicesAndEdges;
if (this._skirtHeight > 0.0) {
arrayWidth += 2;
arrayHeight += 2;
indicesAndEdges = TerrainProvider.getRegularGridAndSkirtIndicesAndEdgeIndices(this._width, this._height);
} else {
indicesAndEdges = TerrainProvider.getRegularGridIndicesAndEdgeIndices(this._width, this._height);
}

var vertexCountWithoutSkirts = result.gridWidth * result.gridHeight;

// No need to clone here (as we do in the async version) because the result
// is not coming from a web worker.
return new TerrainMesh(
center,
result.vertices,
TerrainProvider.getRegularGridIndices(arrayWidth, arrayHeight),
indicesAndEdges.indices,
indicesAndEdges.indexCountWithoutSkirts,
vertexCountWithoutSkirts,
result.minimumHeight,
result.maximumHeight,
result.boundingSphere3D,
Expand All @@ -331,10 +346,10 @@ import TerrainProvider from './TerrainProvider.js';
result.orientedBoundingBox,
result.encoding,
exaggeration,
result.westIndicesSouthToNorth,
result.southIndicesEastToWest,
result.eastIndicesNorthToSouth,
result.northIndicesWestToEast);
indicesAndEdges.westIndicesSouthToNorth,
indicesAndEdges.southIndicesEastToWest,
indicesAndEdges.eastIndicesNorthToSouth,
indicesAndEdges.northIndicesWestToEast);
};

/**
Expand Down Expand Up @@ -363,9 +378,8 @@ import TerrainProvider from './TerrainProvider.js';
if (defined(this._mesh)) {
var buffer = this._mesh.vertices;
var encoding = this._mesh.encoding;
var skirtHeight = this._skirtHeight;
var exaggeration = this._mesh.exaggeration;
heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, rectangle, width, height, longitude, latitude, exaggeration);
heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, rectangle, width, height, longitude, latitude, exaggeration);
} else {
heightSample = interpolateHeight(this._buffer, elementsPerHeight, elementMultiplier, stride, isBigEndian, rectangle, width, height, longitude, latitude);
heightSample = heightSample * heightScale + heightOffset;
Expand Down Expand Up @@ -426,7 +440,6 @@ import TerrainProvider from './TerrainProvider.js';
var width = this._width;
var height = this._height;
var structure = this._structure;
var skirtHeight = this._skirtHeight;
var stride = structure.stride;

var heights = new this._bufferType(width * height * stride);
Expand All @@ -452,7 +465,7 @@ import TerrainProvider from './TerrainProvider.js';
var latitude = CesiumMath.lerp(destinationRectangle.north, destinationRectangle.south, j / (height - 1));
for (var i = 0; i < width; ++i) {
var longitude = CesiumMath.lerp(destinationRectangle.west, destinationRectangle.east, i / (width - 1));
var heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, sourceRectangle, width, height, longitude, latitude, exaggeration);
var heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, sourceRectangle, width, height, longitude, latitude, exaggeration);

// Use conditionals here instead of Math.min and Math.max so that an undefined
// lowestEncodedHeight or highestEncodedHeight has no effect.
Expand Down Expand Up @@ -556,31 +569,21 @@ import TerrainProvider from './TerrainProvider.js';
return triangleInterpolateHeight(dx, dy, southwestHeight, southeastHeight, northwestHeight, northeastHeight);
}

function interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, sourceRectangle, width, height, longitude, latitude, exaggeration) {
function interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, sourceRectangle, width, height, longitude, latitude, exaggeration) {
// returns a height encoded according to the structure's heightScale and heightOffset.
var fromWest = (longitude - sourceRectangle.west) * (width - 1) / (sourceRectangle.east - sourceRectangle.west);
var fromSouth = (latitude - sourceRectangle.south) * (height - 1) / (sourceRectangle.north - sourceRectangle.south);

if (skirtHeight > 0) {
fromWest += 1.0;
fromSouth += 1.0;

width += 2;
height += 2;
}

var widthEdge = (skirtHeight > 0) ? width - 1 : width;
var westInteger = fromWest | 0;
var eastInteger = westInteger + 1;
if (eastInteger >= widthEdge) {
if (eastInteger >= width) {
eastInteger = width - 1;
westInteger = width - 2;
}

var heightEdge = (skirtHeight > 0) ? height - 1 : height;
var southInteger = fromSouth | 0;
var northInteger = southInteger + 1;
if (northInteger >= heightEdge) {
if (northInteger >= height) {
northInteger = height - 1;
southInteger = height - 2;
}
Expand Down
Loading

0 comments on commit 215a588

Please sign in to comment.