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

Earcut.js #3998

Merged
merged 18 commits into from
Jun 6, 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
10 changes: 5 additions & 5 deletions Apps/Sandcastle/gallery/GeoJSON and TopoJSON.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@

//Reset the scene when switching demos.
Sandcastle.reset = function() {
viewer.dataSources.removeAll();
viewer.dataSources.removeAll();

//Set the camera to a US centered tilted view and switch back to moving in world coordinates.
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(-98.0, 40.0), new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
//Set the camera to a US centered tilted view and switch back to moving in world coordinates.
viewer.camera.lookAt(Cesium.Cartesian3.fromDegrees(-98.0, 40.0), new Cesium.Cartesian3(0.0, -4790000.0, 3930000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
};
//Sandcastle_End
Sandcastle.finishedLoading();
Expand All @@ -104,4 +104,4 @@
}
</script>
</body>
</html>
</html>
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ Change Log

* Add a `rotatable2D` option to to `Scene`, `CesiumWidget` and `Viewer` to enable a rotatable map in 2D. [#3897](https://github.com/AnalyticalGraphicsInc/cesium/issues/3897)
* `Camera.setView` and `Camera.flyTo` will now use the `orientation.heading` parameter in 2D if the map is rotatable.
* Added `packArray` and `unpackArray` functions to `Cartesian2`, `Cartesian3`, and `Cartesian4`.
* Fix some large polygon triangulations. [#2788](https://github.com/AnalyticalGraphicsInc/cesium/issues/2788)
* Improved performance and accuracy of polygon triangulation by using the [earcut](https://github.com/mapbox/earcut) library. Loading a GeoJSON with polygons for each country was ~50% faster.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean 2x faster, i.e., 50% less time?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup. I'll fix it in master.

* Added CZML support for Box, Corridor and Cylinder

### 1.22 - 2016-06-01
Expand Down
18 changes: 18 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,24 @@ https://github.com/richtr/NoSleep.js
> Rich Tibbett
> MIT license

### earcut

https://github.com/mapbox/earcut

>Copyright (c) 2016, Mapbox
>
>Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
>
>THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.

Tests
=====

Expand Down
55 changes: 55 additions & 0 deletions Source/Core/Cartesian2.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,61 @@ define([
return result;
};

/**
* Flattens an array of Cartesian2s into and array of components.
*
* @param {Cartesian2[]} array The array of cartesians to pack.
* @param {Number[]} result The array onto which to store the result.
* @returns {Number[]} The packed array.
*/
Cartesian2.packArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length * 2);
} else {
result.length = length * 2;
}

for (var i = 0; i < length; ++i) {
Cartesian2.pack(array[i], result, i * 2);
}
return result;
};

/**
* Unpacks an array of cartesian components into and array of Cartesian2s.
*
* @param {Number[]} array The array of components to unpack.
* @param {Cartesian2[]} result The array onto which to store the result.
* @returns {Cartesian2[]} The unpacked array.
*/
Cartesian2.unpackArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length / 2);
} else {
result.length = length / 2;
}

for (var i = 0; i < length; i += 2) {
var index = i / 2;
result[index] = Cartesian2.unpack(array, i, result[index]);
}
return result;
};

/**
* Creates a Cartesian2 from two consecutive elements in an array.
* @function
Expand Down
55 changes: 55 additions & 0 deletions Source/Core/Cartesian3.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,61 @@ define([
return result;
};

/**
* Flattens an array of Cartesian3s into and array of components.
*
* @param {Cartesian3[]} array The array of cartesians to pack.
* @param {Number[]} result The array onto which to store the result.
* @returns {Number[]} The packed array.
*/
Cartesian3.packArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length * 3);
} else {
result.length = length * 3;
}

for (var i = 0; i < length; ++i) {
Cartesian3.pack(array[i], result, i * 3);
}
return result;
};

/**
* Unpacks an array of cartesian components into and array of Cartesian3s.
*
* @param {Number[]} array The array of components to unpack.
* @param {Cartesian3[]} result The array onto which to store the result.
* @returns {Cartesian3[]} The unpacked array.
*/
Cartesian3.unpackArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length / 3);
} else {
result.length = length / 3;
}

for (var i = 0; i < length; i += 3) {
var index = i / 3;
result[index] = Cartesian3.unpack(array, i, result[index]);
}
return result;
};

/**
* Creates a Cartesian3 from three consecutive elements in an array.
* @function
Expand Down
55 changes: 55 additions & 0 deletions Source/Core/Cartesian4.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,61 @@ define([
return result;
};

/**
* Flattens an array of Cartesian4s into and array of components.
*
* @param {Cartesian4[]} array The array of cartesians to pack.
* @param {Number[]} result The array onto which to store the result.
* @returns {Number[]} The packed array.
*/
Cartesian4.packArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length * 4);
} else {
result.length = length * 4;
}

for (var i = 0; i < length; ++i) {
Cartesian4.pack(array[i], result, i * 4);
}
return result;
};

/**
* Unpacks an array of cartesian components into and array of Cartesian4s.
*
* @param {Number[]} array The array of components to unpack.
* @param {Cartesian4[]} result The array onto which to store the result.
* @returns {Cartesian4[]} The unpacked array.
*/
Cartesian4.unpackArray = function(array, result) {
//>>includeStart('debug', pragmas.debug);
if (!defined(array)) {
throw new DeveloperError('array is required');
}
//>>includeEnd('debug');

var length = array.length;
if (!defined(result)) {
result = new Array(length / 4);
} else {
result.length = length / 4;
}

for (var i = 0; i < length; i += 4) {
var index = i / 4;
result[index] = Cartesian4.unpack(array, i, result[index]);
}
return result;
};

/**
* Creates a Cartesian4 from four consecutive elements in an array.
* @function
Expand Down
36 changes: 17 additions & 19 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,14 +347,14 @@ define([

var createGeometryFromPositionsExtrudedPositions = [];

function createGeometryFromPositionsExtruded(ellipsoid, positions, granularity, hierarchy, perPositionHeight, closeTop, closeBottom, vertexFormat) {
function createGeometryFromPositionsExtruded(ellipsoid, polygon, granularity, hierarchy, perPositionHeight, closeTop, closeBottom, vertexFormat) {
var geos = {
walls : []
};
var i;

if (closeTop || closeBottom) {
var topGeo = PolygonGeometryLibrary.createGeometryFromPositions(ellipsoid, positions, granularity, perPositionHeight, vertexFormat);
var topGeo = PolygonGeometryLibrary.createGeometryFromPositions(ellipsoid, polygon, granularity, perPositionHeight, vertexFormat);

var edgePoints = topGeo.attributes.position.values;
var indices = topGeo.indices;
Expand Down Expand Up @@ -764,29 +764,22 @@ define([
var closeTop = polygonGeometry._closeTop;
var closeBottom = polygonGeometry._closeBottom;

var walls;
var topAndBottom;
var outerPositions;
var outerPositions = polygonHierarchy.positions;
if (outerPositions.length < 3) {
return;
}

var tangentPlane = EllipsoidTangentPlane.fromPoints(outerPositions, ellipsoid);

var results = PolygonGeometryLibrary.polygonsFromHierarchy(polygonHierarchy, perPositionHeight, ellipsoid);
var results = PolygonGeometryLibrary.polygonsFromHierarchy(polygonHierarchy, perPositionHeight, tangentPlane, ellipsoid);
var hierarchy = results.hierarchy;
var polygons = results.polygons;
var i;

if (polygons.length === 0) {
if (hierarchy.length === 0) {
return;
}

if (perPositionHeight) {
outerPositions = polygons[0].slice();
for (i = 0; i < outerPositions.length; i++) {
outerPositions[i] = ellipsoid.scaleToGeodeticSurface(outerPositions[i]);
}
} else {
outerPositions = polygons[0];
}

var tangentPlane = EllipsoidTangentPlane.fromPoints(outerPositions, ellipsoid);
outerPositions = hierarchy[0].outerRing;
var boundingRectangle = computeBoundingRectangle(tangentPlane, outerPositions, stRotation, scratchBoundingRectangle);

var geometry;
Expand All @@ -804,11 +797,16 @@ define([
top: true,
wall: false
};

var i;

if (extrude) {
options.top = closeTop;
options.bottom = closeBottom;
for (i = 0; i < polygons.length; i++) {
geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, hierarchy[i], perPositionHeight, closeTop, closeBottom, vertexFormat);

var topAndBottom;
if (closeTop && closeBottom) {
topAndBottom = geometry.topAndBottom;
options.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(topAndBottom.geometry, height, extrudedHeight, ellipsoid, perPositionHeight);
Expand All @@ -827,7 +825,7 @@ define([
geometries.push(topAndBottom);
}

walls = geometry.walls;
var walls = geometry.walls;
options.wall = true;
for ( var k = 0; k < walls.length; k++) {
var wall = walls[k];
Expand Down
Loading