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

Fix terrain exaggeration bug #3734

Merged
merged 1 commit into from
Mar 21, 2016
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Change Log
* Fix issue where the `GroundPrimitive` volume was being clipped by the far plane. [#3706](https://github.com/AnalyticalGraphicsInc/cesium/issues/3706)
* Fixed issue where `Camera.computeViewRectangle` was incorrect when crossing the international date line [#3717](https://github.com/AnalyticalGraphicsInc/cesium/issues/3717)
* Added `Rectangle` result parameter to `Camera.computeViewRectangle`
* Fix bug when upsampling exaggerated terrain where the terrain heights were exaggerated at twice the value. [#3607](https://github.com/AnalyticalGraphicsInc/cesium/issues/3607)

### 1.19 - 2016-03-01

Expand Down
19 changes: 11 additions & 8 deletions Source/Core/HeightmapTerrainData.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ define([
result.occludeePointInScaledSpace,
6,
result.orientedBoundingBox,
TerrainEncoding.clone(result.encoding));
TerrainEncoding.clone(result.encoding),
exaggeration);

// Free memory received from server after mesh is created.
that._buffer = undefined;
Expand Down Expand Up @@ -261,7 +262,8 @@ define([
var buffer = this._mesh.vertices;
var encoding = this._mesh.encoding;
var skirtHeight = this._skirtHeight;
heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, rectangle, width, height, longitude, latitude);
var exaggeration = this._mesh.exaggeration;
heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, 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 @@ -335,6 +337,7 @@ define([

var heightOffset = structure.heightOffset;
var heightScale = structure.heightScale;
var exaggeration = meshData.exaggeration;

var elementsPerHeight = structure.elementsPerHeight;
var elementMultiplier = structure.elementMultiplier;
Expand All @@ -346,7 +349,7 @@ define([
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);
var heightSample = interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, sourceRectangle, width, height, longitude, latitude, exaggeration);
setHeight(heights, elementsPerHeight, elementMultiplier, divisor, stride, isBigEndian, j * width + i, heightSample);
}
}
Expand Down Expand Up @@ -444,7 +447,7 @@ define([
return triangleInterpolateHeight(dx, dy, southwestHeight, southeastHeight, northwestHeight, northeastHeight);
}

function interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, sourceRectangle, width, height, longitude, latitude) {
function interpolateMeshHeight(buffer, encoding, heightOffset, heightScale, skirtHeight, sourceRectangle, width, height, longitude, latitude, exaggeration) {
var fromWest = (longitude - sourceRectangle.west) * (width - 1) / (sourceRectangle.east - sourceRectangle.west);
var fromSouth = (latitude - sourceRectangle.south) * (height - 1) / (sourceRectangle.north - sourceRectangle.south);

Expand Down Expand Up @@ -478,10 +481,10 @@ define([
southInteger = height - 1 - southInteger;
northInteger = height - 1 - northInteger;

var southwestHeight = (encoding.decodeHeight(buffer, southInteger * width + westInteger) - heightOffset) / heightScale;
var southeastHeight = (encoding.decodeHeight(buffer, southInteger * width + eastInteger) - heightOffset) / heightScale;
var northwestHeight = (encoding.decodeHeight(buffer, northInteger * width + westInteger) - heightOffset) / heightScale;
var northeastHeight = (encoding.decodeHeight(buffer, northInteger * width + eastInteger) - heightOffset) / heightScale;
var southwestHeight = (encoding.decodeHeight(buffer, southInteger * width + westInteger) / exaggeration - heightOffset) / heightScale;
var southeastHeight = (encoding.decodeHeight(buffer, southInteger * width + eastInteger) / exaggeration - heightOffset) / heightScale;
var northwestHeight = (encoding.decodeHeight(buffer, northInteger * width + westInteger) / exaggeration - heightOffset) / heightScale;
var northeastHeight = (encoding.decodeHeight(buffer, northInteger * width + eastInteger) / exaggeration - heightOffset) / heightScale;

return triangleInterpolateHeight(dx, dy, southwestHeight, southeastHeight, northwestHeight, northeastHeight);
}
Expand Down
6 changes: 4 additions & 2 deletions Source/Core/QuantizedMeshTerrainData.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,8 @@ define([
occlusionPoint,
stride,
obb,
terrainEncoding);
terrainEncoding,
exaggeration);

// Free memory received from server after mesh is created.
that._quantizedVertices = undefined;
Expand Down Expand Up @@ -408,7 +409,8 @@ define([
isEastChild : isEastChild,
isNorthChild : isNorthChild,
childRectangle : childRectangle,
ellipsoid : ellipsoid
ellipsoid : ellipsoid,
exaggeration : mesh.exaggeration
});

if (!defined(upsamplePromise)) {
Expand Down
8 changes: 7 additions & 1 deletion Source/Core/TerrainMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ define([
*
* @private
*/
function TerrainMesh(center, vertices, indices, minimumHeight, maximumHeight, boundingSphere3D, occludeePointInScaledSpace, vertexStride, orientedBoundingBox, encoding) {
function TerrainMesh(center, vertices, indices, minimumHeight, maximumHeight, boundingSphere3D, occludeePointInScaledSpace, vertexStride, orientedBoundingBox, encoding, exaggeration) {
/**
* The center of the tile. Vertex positions are specified relative to this center.
* @type {Cartesian3}
Expand Down Expand Up @@ -98,6 +98,12 @@ define([
* @type {TerrainEncoding}
*/
this.encoding = encoding;

/**
* The amount that this mesh was exaggerated.
* @type {Number}
*/
this.exaggeration = exaggeration;
}

return TerrainMesh;
Expand Down
3 changes: 2 additions & 1 deletion Source/Workers/upsampleQuantizedTerrainMesh.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ define([

var encoding = TerrainEncoding.clone(parameters.encoding);
var hasVertexNormals = encoding.hasVertexNormals;
var exaggeration = parameters.exaggeration;

var vertexCount = 0;
var quantizedVertexCount = parameters.vertexCountWithoutSkirts;
Expand All @@ -98,7 +99,7 @@ define([
var i, n;
for (i = 0, n = 0; i < quantizedVertexCount; ++i, n += 2) {
var texCoords = encoding.decodeTextureCoordinates(parentVertices, i, decodeTexCoordsScratch);
height = encoding.decodeHeight(parentVertices, i);
height = encoding.decodeHeight(parentVertices, i) / exaggeration;

parentUBuffer[i] = CesiumMath.clamp((texCoords.x * maxShort) | 0, 0, maxShort);
parentVBuffer[i] = CesiumMath.clamp((texCoords.y * maxShort) | 0, 0, maxShort);
Expand Down