Skip to content

Commit

Permalink
Merge pull request #7959 from tinco/optimize-approx-terrain-heights
Browse files Browse the repository at this point in the history
Optimize approximateTerrainHeights file for quicker page loads (Solves #6557)
  • Loading branch information
Hannah authored Sep 18, 2019
2 parents 339fd2f + ba98865 commit 501a83b
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Change Log
* Fixed 3D tiles style coloring when multiple tilesets are in the scene [#8051](https://github.com/AnalyticalGraphicsInc/cesium/pull/8051)
* Improved display of tile coordinates for `TileCoordinatesImageryProvider` [#8131](https://github.com/AnalyticalGraphicsInc/cesium/pull/8131)
* Fixed relative-to-center check, `depthFailAppearance` resource freeing for `Primitive` [#8044](https://github.com/AnalyticalGraphicsInc/cesium/pull/8044)
* Reduces size of approximateTerrainHeights.json by rounding the numbers [#7959](https://github.com/AnalyticalGraphicsInc/cesium/pull/7959)
* Fixed undefined `quadDetails` error from zooming into the map really close. [#8011](https://github.com/AnalyticalGraphicsInc/cesium/pull/8011)

### 1.61 - 2019-09-03
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -234,3 +234,4 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [TJKoury](https://github.com/tjkoury)
* [Qiming Zhang](https://github.com/bbbbx)
* [Chris Wingler](https://github.com/chriswingler)
* [Tinco Andringa](https://github.com/tinco)
2 changes: 1 addition & 1 deletion Source/Assets/approximateTerrainHeights.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions Source/Assets/approximateTerrainHeightsPrecise.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Specs/Core/ApproximateTerrainHeightsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('Core/ApproximateTerrainHeights', function() {

it('getMinimumMaximumHeights computes minimum and maximum terrain heights', function() {
var result = ApproximateTerrainHeights.getMinimumMaximumHeights(Rectangle.fromDegrees(-121.0, 10.0, -120.0, 11.0));
expect(result.minimumTerrainHeight).toEqualEpsilon(-476.125711887558, CesiumMath.EPSILON10);
expect(result.maximumTerrainHeight).toEqualEpsilon(-28.53441619873047, CesiumMath.EPSILON10);
expect(result.minimumTerrainHeight).toEqualEpsilon(-476.12571188755, CesiumMath.EPSILON10);
expect(result.maximumTerrainHeight).toEqualEpsilon(-28.53, CesiumMath.EPSILON10);
});

it('getMinimumMaximumHeights throws with no rectangle', function() {
Expand All @@ -51,8 +51,8 @@ describe('Core/ApproximateTerrainHeights', function() {

it('getBoundingSphere computes a bounding sphere', function() {
var result = ApproximateTerrainHeights.getBoundingSphere(Rectangle.fromDegrees(-121.0, 10.0, -120.0, 11.0));
expect(result.center).toEqualEpsilon(new Cartesian3(-3183013.8480289434, -5403772.557261968, 1154581.5817616477), CesiumMath.EPSILON10);
expect(result.radius).toEqualEpsilon(77884.16539096291, CesiumMath.EPSILON10);
expect(result.center).toEqualEpsilon(new Cartesian3(-3183013.849117281, -5403772.559109628, 1154581.5821590829), CesiumMath.EPSILON10);
expect(result.radius).toEqualEpsilon(77884.16321007285, CesiumMath.EPSILON10);
});

it('getBoundingSphere throws with no rectangle', function() {
Expand Down
22 changes: 22 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var gulpInsert = require('gulp-insert');
var gulpZip = require('gulp-zip');
var gulpRename = require('gulp-rename');
var gulpReplace = require('gulp-replace');
var gulpJsonTransform = require('gulp-json-transform');
var Promise = require('bluebird');
var requirejs = require('requirejs');
var Karma = require('karma');
Expand Down Expand Up @@ -132,6 +133,27 @@ gulp.task('requirejs', function(done) {
}, done);
});

// optimizeApproximateTerrainHeights can be used to regenerate the approximateTerrainHeights
// file from an overly precise terrain heights file to reduce bandwidth
// the approximate terrain heights are only used when the terrain provider does not have this
// information and not a high level of precision is required
gulp.task('optimizeApproximateTerrainHeights', function() {
var argv = yargs.usage('Usage: optimizeApproximateTerrainHeights -p [degree of precision]').argv;
var precision = typeof argv.p !== undefined ? argv.p : 1;
precision = Math.pow(10, precision);
return gulp.src('Source/Assets/approximateTerrainHeightsPrecise.json')
.pipe(gulpJsonTransform(function(data, file) {
Object.entries(data).forEach(function(entry) {
var values = entry[1];
data[entry[0]] = [Math.floor(values[0] * precision) / precision,
Math.ceil(values[1] * precision) / precision ];
});
return data;
}))
.pipe(gulpRename('approximateTerrainHeights.json'))
.pipe(gulp.dest('Source/Assets/'));
});

function cloc() {
var cmdLine;
var clocPath = path.join('node_modules', 'cloc', 'lib', 'cloc');
Expand Down
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"glsl-strip-comments": "^1.0.0",
"gulp": "^4.0.0",
"gulp-insert": "^0.5.0",
"gulp-json-transform": "^0.4.6",
"gulp-rename": "^1.2.2",
"gulp-replace": "^1.0.0",
"gulp-tap": "^1.0.1",
Expand Down Expand Up @@ -90,6 +91,7 @@
"makeZipFile": "gulp makeZipFile",
"minify": "gulp minify",
"minifyRelease": "gulp minifyRelease",
"optimizeApproximateTerrainHeights": "gulp optimizeApproximateTerrainHeights -p 2",
"release": "gulp release",
"test": "gulp test",
"test-all": "gulp test --all",
Expand Down

0 comments on commit 501a83b

Please sign in to comment.