Skip to content

Commit

Permalink
Merge pull request #1528 from AnalyticalGraphicsInc/extrudedPolygon
Browse files Browse the repository at this point in the history
Extruded polygon
  • Loading branch information
pjcozzi committed Mar 4, 2014
2 parents 41cadca + 5b58b24 commit ceb09a0
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Beta Releases
* Breaking changes:
*
* `loadArrayBuffer`, `loadBlob`, `loadJson`, `loadText`, and `loadXML` now support loading data from data URIs.
* Fixed extruded polygons rendered in the southern hemisphere. [#1490](https://github.com/AnalyticalGraphicsInc/cesium/issues/1490)
* Fixed Primitive picking that have a closed appearance drawn on the surface. [#1333](https://github.com/AnalyticalGraphicsInc/cesium/issues/1333)

### b26 - 2014-03-03
Expand Down
21 changes: 16 additions & 5 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ define([
});
}

var createGeometryFromPositionsExtrudedPositions = [];

function createGeometryFromPositionsExtruded(ellipsoid, positions, granularity, hierarchy, perPositionHeight) {
var topGeo = createGeometryFromPositions(ellipsoid, positions, granularity, perPositionHeight).geometry;
var edgePoints = topGeo.attributes.position.values;
Expand Down Expand Up @@ -433,10 +435,14 @@ define([

geos.walls = [];
var outerRing = hierarchy.outerRing;
var windingOrder = PolygonPipeline.computeWindingOrder2D(outerRing);
var tangentPlane = EllipsoidTangentPlane.fromPoints(outerRing, ellipsoid);
var positions2D = tangentPlane.projectPointsOntoPlane(outerRing, createGeometryFromPositionsExtrudedPositions);

var windingOrder = PolygonPipeline.computeWindingOrder2D(positions2D);
if (windingOrder === WindingOrder.CLOCKWISE) {
outerRing = outerRing.reverse();
outerRing.reverse();
}

var wallGeo = computeWallIndices(outerRing, granularity, perPositionHeight);
geos.walls.push(new GeometryInstance({
geometry : wallGeo
Expand All @@ -445,10 +451,15 @@ define([
var holes = hierarchy.holes;
for (i = 0; i < holes.length; i++) {
var hole = holes[i];
windingOrder = PolygonPipeline.computeWindingOrder2D(hole);
if (windingOrder !== WindingOrder.CLOCKWISE) {
hole = hole.reverse();

tangentPlane = EllipsoidTangentPlane.fromPoints(hole, ellipsoid);
positions2D = tangentPlane.projectPointsOntoPlane(hole, createGeometryFromPositionsExtrudedPositions);

windingOrder = PolygonPipeline.computeWindingOrder2D(positions2D);
if (windingOrder === WindingOrder.CLOCKWISE) {
hole.reverse();
}

wallGeo = computeWallIndices(hole, granularity);
geos.walls.push(new GeometryInstance({
geometry : wallGeo
Expand Down
46 changes: 46 additions & 0 deletions Specs/Scene/GeometryRenderingSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,52 @@ defineSuite([
};
render3D(instance, afterView);
});

it('renders with correct winding order in southern hemisphere', function() {
var primitive = new Primitive({
geometryInstances : new GeometryInstance({
geometry : PolygonGeometry.fromPositions({
vertexFormat : PerInstanceColorAppearance.VERTEX_FORMAT,
ellipsoid : ellipsoid,
positions : ellipsoid.cartographicArrayToCartesianArray([
Cartographic.fromDegrees(-108.0, -25.0, 500000),
Cartographic.fromDegrees(-100.0, -25.0, 500000),
Cartographic.fromDegrees(-100.0, -30.0, 500000),
Cartographic.fromDegrees(-108.0, -30.0, 500000)
]),
perPositionHeight : true,
extrudedHeight: 0
}),
id : 'extrudedPolygon',
attributes : {
color : new ColorGeometryInstanceAttribute(1.0, 1.0, 0.0, 1.0)
}
}),
appearance : new PerInstanceColorAppearance({
closed : true,
translucent : false
}),
asynchronous : false
});

var frameState = createFrameState();
primitive.update(context, frameState, []);
viewSphere3D(frameState.camera, primitive._boundingSphere, primitive.modelMatrix);

var transform = Transforms.eastNorthUpToFixedFrame(primitive._boundingSphere.center);
frameState.camera.controller.rotateDown(-CesiumMath.PI_OVER_TWO, transform);
frameState.camera.controller.moveForward(primitive._boundingSphere.radius * 0.75);

context.getUniformState().update(context, frameState);

ClearCommand.ALL.execute(context);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

render(context, frameState, primitive);
expect(context.readPixels()).toEqual([0, 0, 0, 0]);

primitive = primitive && primitive.destroy();
});
}, 'WebGL');


Expand Down

0 comments on commit ceb09a0

Please sign in to comment.