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

Extruded polygon #1528

Merged
merged 5 commits into from
Mar 4, 2014
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 @@ -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