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

Polygons on terrain #2865

Merged
merged 82 commits into from
Aug 21, 2015
Merged
Show file tree
Hide file tree
Changes from 77 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
c6c2d03
Ground primitive WIP.
bagnell Feb 21, 2015
11770c1
Clamp positions to near plane. Shadow volume sides that are entirely …
bagnell Feb 24, 2015
c1c9c65
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 3, 2015
1b42df4
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 11, 2015
ba6026a
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 18, 2015
fe5fab1
Declare commands and properly release shaders.
bagnell Mar 18, 2015
5d408bf
Update CHANGES.md.
bagnell Mar 18, 2015
5496e4b
Merge branch 'globe-depth' into ground-primitive
bagnell Mar 24, 2015
4d72baf
Clip polygon to the near plane of the first frustum WIP. Added debug …
bagnell Mar 24, 2015
36b6772
More ground polygon WIP. Only extrude vertices in vertex shader. Vert…
bagnell Mar 24, 2015
0790da0
Fix blinking polygon by slightly offsetting intersection point from t…
bagnell Mar 24, 2015
f0c8e24
Fix multi-frustum artifact on ground polygons volume.
bagnell Mar 25, 2015
94e1336
Clean up intersection function to make it more clear and add comments.
bagnell Mar 25, 2015
3a96b61
Some shader clean up and fixing a volume artifact WIP.
bagnell Mar 27, 2015
60ab053
Remove ground polygon texture coordinates.
bagnell Apr 1, 2015
0230cb0
Merge branch 'globe-depth' into ground-primitive
bagnell Apr 1, 2015
f1d5831
Add ground polygon development Sandcastle example.
bagnell Apr 1, 2015
01d4d6a
Use the same normal for both extruded and non-extruded positions. Add…
bagnell Apr 8, 2015
d051c08
Fix artifact where more than one frustum was drawing at the far plane…
bagnell Apr 9, 2015
94552de
Merge branch 'master' into ground-primitive
bagnell Jul 1, 2015
063a0ac
Merge remote-tracking branch 'origin' into ground-primitive
bagnell Jul 8, 2015
9b54673
Fix looking up at terrain when inside the shadow volume.
bagnell Jul 9, 2015
239cd1c
Remove code for culled lines from the function to clip the line again…
bagnell Jul 9, 2015
a7eb9b6
Avoid computing eye coordinates multiple times.
bagnell Jul 9, 2015
f8877cd
Fix shadow volumes by using a different technique.
bagnell Jul 15, 2015
c344aa2
Move to more general ground primitive WIP.
bagnell Jul 15, 2015
e9affe0
Remove ground polygon for more general ground primitive.
bagnell Jul 15, 2015
fdd5e5b
Merge branch 'master' into ground-primitive
bagnell Jul 15, 2015
23f6700
Add Columbus view support and per instance attribute support.
bagnell Jul 15, 2015
ff0a67a
Add commands for z-pass algorithm.
bagnell Jul 16, 2015
50bf334
Add support for more geometry that can be clamped to the ground. Add …
bagnell Jul 17, 2015
face14c
Compute shadow volume height based on granularity. Overlap frustums w…
bagnell Jul 22, 2015
ea1fd7b
Merge branch 'master' into ground-primitive
bagnell Jul 22, 2015
68c49f8
Remove z-pass optimization to fix multi-frustum artifact.
bagnell Jul 23, 2015
d55ff80
Fix rectangle geometry surface volume.
bagnell Jul 23, 2015
2d1894c
Clean up primitive shadow volume creation.
bagnell Jul 23, 2015
3e10cf5
Add picking support to ground primitive and remove model matrix option.
bagnell Jul 23, 2015
6f546c6
Merge branch 'master' into ground-primitive
bagnell Jul 24, 2015
c99bd57
Reapply change from merge to reorganized code.
bagnell Jul 24, 2015
84ff66e
Merge branch 'globe-pick' into ground-primitive
bagnell Jul 24, 2015
3269056
Use a depth/stencil renderbuffer with the picking fbo.
bagnell Jul 24, 2015
6ab9532
Merge branch 'master' into ground-primitive
bagnell Jul 27, 2015
277930f
Merge branch 'depth-plane' into ground-primitive
bagnell Jul 27, 2015
164dbc8
Add doc and properties forwarded to the primitive.
bagnell Jul 28, 2015
9ef18a0
Clean up ground primitive example.
bagnell Jul 28, 2015
5c9e945
Rename _createShadowVolume by removing the underscore and making it p…
bagnell Jul 28, 2015
49d3769
Merge branch 'master' into ground-primitive
bagnell Jul 28, 2015
198f857
Remove #ifdefs from shader checking for GL_EXT_frag_depth. The shader…
bagnell Jul 28, 2015
282463f
Porting Primitive tests for GroundPrimitive WIP.
bagnell Jul 29, 2015
256c47b
Add remaining tests.
bagnell Jul 29, 2015
cd15a4e
Update doc.
bagnell Jul 29, 2015
ff9a863
Update CHANGES.md.
bagnell Jul 29, 2015
deaf939
Merge branch 'master' into ground-primitive
bagnell Jul 31, 2015
f503bd0
Refactor Primitive and GroundPrimitive updates.
bagnell Aug 17, 2015
1b7d5c2
Merge branch 'master' into ground-primitive
bagnell Aug 17, 2015
7a3417e
Add hooks to Primitive to override render state, shader, and command …
bagnell Aug 17, 2015
ea855bb
The GroundPrimitive creates more commands that Primitive. Properly sy…
bagnell Aug 17, 2015
71f0bc9
Add prototype versions of distanceSquaredTo and computePlaneDistances…
bagnell Aug 18, 2015
001fdf6
Add OrientedBoundingBox.distanceSquaredTo.
bagnell Aug 18, 2015
3043c44
Add OrientedBoundingBox.computePlaneDistances.
bagnell Aug 18, 2015
e4587c1
Add an isOccluded function to the prototypes of BoundingSphere and Or…
bagnell Aug 18, 2015
71193a8
Add support for both bounding spheres and boxes to Scene.
bagnell Aug 18, 2015
21d0118
Add hook to primitive for creating custom bounding volumes for geometry.
bagnell Aug 18, 2015
7c23324
Remove unnecessary vector multiplies and magnitudes when getting dist…
bagnell Aug 18, 2015
a4e8fa9
Use OBBs as bounding volumes for ground primitives.
bagnell Aug 18, 2015
6517e2d
Modify debugShowBoundingVolume to work with OBBs.
bagnell Aug 18, 2015
f10fecc
Merge branch 'master' into ground-primitive
bagnell Aug 19, 2015
3d9ced1
Fix ground primitive bounding volumes when not in 3D.
bagnell Aug 19, 2015
e301a3c
Change geometryInstances to geometryInstance since batching is not su…
bagnell Aug 19, 2015
e9caa53
Fix tests.
bagnell Aug 19, 2015
8155c35
Test optimization from review.
bagnell Aug 19, 2015
a18e6ab
Add tests for new BoundingSphere and OrientedBoundingBox functions.
bagnell Aug 19, 2015
b50d97a
Use scene instead of context for ground primitive rendering tests.
bagnell Aug 20, 2015
cc60873
Fix test.
bagnell Aug 20, 2015
3a6ee56
Enable picking ground primitives when depthTestAgainstTerrain is false.
bagnell Aug 20, 2015
2521859
Merge branch 'master' into ground-primitive
bagnell Aug 20, 2015
c320e39
Merge branch 'master' into ground-primitive
bagnell Aug 20, 2015
79aed81
Update CHANGES.ms.
bagnell Aug 21, 2015
870e68a
Merge branch 'master' into ground-primitive
bagnell Aug 21, 2015
d76b729
Fix after merge.
bagnell Aug 21, 2015
9f6664d
Fix IE tests.
bagnell Aug 21, 2015
b9856c0
Add GroundPrimitive.isSupported.
bagnell Aug 21, 2015
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
179 changes: 179 additions & 0 deletions Apps/Sandcastle/gallery/development/Ground Primitive.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1"> <!-- Use Chrome Frame in IE -->
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<meta name="description" content="Draw a polygon or extruded polygon on the globe surface.">
<meta name="cesium-sandcastle-labels" content="Development">
<title>Cesium Demo</title>
<script type="text/javascript" src="../Sandcastle-header.js"></script>
<script type="text/javascript" src="../../../ThirdParty/requirejs-2.1.9/require.js"></script>
<script type="text/javascript">
require.config({
baseUrl : '../../../Source',
waitSeconds : 60
});
</script>
</head>
<body class="sandcastle-loading" data-sandcastle-bucket="bucket-requirejs.html">
<style>
@import url(../templates/bucket.css);
</style>
<div id="cesiumContainer" class="fullSize"></div>
<div id="loadingOverlay"><h1>Loading...</h1></div>
<div id="toolbar"></div>
<script id="cesium_sandcastle_script">
function startup(Cesium) {
"use strict";
//Sandcastle_Begin

//Create the viewer.
var viewer = new Cesium.Viewer('cesiumContainer');
var scene = viewer.scene;
scene.terrainProvider = new Cesium.CesiumTerrainProvider({
url: '//cesiumjs.org/stk-terrain/tilesets/world/tiles',
requestVertexNormals : true
});

// Circle geometry
scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance: new Cesium.GeometryInstance({
geometry : new Cesium.CircleGeometry({
center : Cesium.Cartesian3.fromDegrees(-95.0, 45.0),
radius : 250000.0
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(1.0, 0.0, 0.0, 0.5))
},
id : 'circle'
})
}));

// Ellipse Geometry
scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance: new Cesium.GeometryInstance({
geometry : new Cesium.EllipseGeometry({
center : Cesium.Cartesian3.fromDegrees(-105.0, 40.0),
semiMinorAxis : 300000.0,
semiMajorAxis : 400000.0
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 1.0, 1.0, 0.5))
},
id : 'ellipse'
})
}));

// Corridor Geometry
scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance : new Cesium.GeometryInstance({
geometry: new Cesium.CorridorGeometry({
positions : Cesium.Cartesian3.fromDegreesArray([
-112.0, 40.0,
-117.0, 40.0,
-117.0, 35.0
]),
width : 200000.0
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 0.0, 1.0, 0.5))
},
id : 'corridor'
})
}));

// Rectangle geometry
scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance : new Cesium.GeometryInstance({
geometry : new Cesium.RectangleGeometry({
rectangle : Cesium.Rectangle.fromDegrees(-100.0, 30.0, -90.0, 40.0),
rotation : Cesium.Math.toRadians(45)
}),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(new Cesium.Color(0.0, 1.0, 0.0, 0.5))
},
id : 'rectangle'
})
}));

// Polygon on Mount Saint Helens
var positions = [new Cesium.Cartesian3(-2358138.847340281, -3744072.459541374, 4581158.5714175375),
new Cesium.Cartesian3(-2357231.4925370603, -3745103.7886602185, 4580702.9757762635),
new Cesium.Cartesian3(-2355912.902205431, -3744249.029778454, 4582402.154378103),
new Cesium.Cartesian3(-2357208.0209552636, -3743553.4420488174, 4581961.863286629)];
var polygonHierarchy = { positions : positions };

var primitive = scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance : new Cesium.GeometryInstance({
geometry : new Cesium.PolygonGeometry({
polygonHierarchy : polygonHierarchy
}),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.RED.withAlpha(0.5))
},
id : 'polygon 1'
})
}));

// Same polygon slightly offset and overlapping.
positions = scene.globe.ellipsoid.cartesianArrayToCartographicArray(positions);
var delta = Cesium.Math.toRadians(0.01);
for (var i = 0; i < positions.length; ++i) {
var position = positions[i];
position.latitude += delta;
position.longitude += delta;
}
positions = scene.globe.ellipsoid.cartographicArrayToCartesianArray(positions);
polygonHierarchy = { positions : positions };

scene.primitives.add(new Cesium.GroundPrimitive({
geometryInstance : new Cesium.GeometryInstance({
geometry : new Cesium.PolygonGeometry({
polygonHierarchy : polygonHierarchy
}),
attributes: {
color: Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.BLUE.withAlpha(0.5))
},
id : 'polygon 2'
})
}));

Sandcastle.addToolbarButton('View Mount Saint Helens', function() {
viewer.camera.lookAt(new Cesium.Cartesian3(-2354331.3069306486, -3742016.2427205616, 4581875.591571755), new Cesium.HeadingPitchRange(Cesium.Math.toRadians(20.0), Cesium.Math.toRadians(-35.0), 10000.0));
viewer.camera.lookAtTransform(Cesium.Matrix4.IDENTITY);
});

var currentObject = undefined;
var lastColor = undefined;

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function(movement) {
var pickedObject = scene.pick(movement.endPosition);
if (Cesium.defined(pickedObject) && pickedObject !== currentObject) {
if (Cesium.defined(currentObject)) {
currentObject.primitive.getGeometryInstanceAttributes(currentObject.id).color = lastColor;
}

currentObject = pickedObject;

var attributes = currentObject.primitive.getGeometryInstanceAttributes(currentObject.id);
lastColor = attributes.color;
attributes.color = [255, 255, 0, 128];
} else if (!Cesium.defined(pickedObject) && Cesium.defined(currentObject)) {
currentObject.primitive.getGeometryInstanceAttributes(currentObject.id).color = lastColor;
currentObject = undefined;
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ Change Log
* Fix an issue where non-feature nodes prevented KML documents from loading. [#2945](https://github.com/AnalyticalGraphicsInc/cesium/pull/2945).
* Removed [es5-shim](https://github.com/kriskowal/es5-shim), which is no longer required by the unit tests. [#2933](https://github.com/AnalyticalGraphicsInc/cesium/pull/2945)
* Fix issue where `JulianDate` would not parse certain dates properly. [#405](https://github.com/AnalyticalGraphicsInc/cesium/issues/405)
* Added support for `GroundPrimitive` which works much like `Primitive` but it drapes the geometry over terrain. Valid geometries that can be draped on terrain are `CircleGeometry`, `CorridorGeometry`, `EllipseGeometry`, `PolygonGeometry`, and `RectangleGeometry`.

### 1.12 - 2015-08-03

Expand Down
66 changes: 63 additions & 3 deletions Source/Core/BoundingSphere.js
Original file line number Diff line number Diff line change
Expand Up @@ -902,7 +902,7 @@ define([
* @param {BoundingSphere} sphere The bounding sphere to calculate the distance to.
* @param {Cartesian3} position The position to calculate the distance from.
* @param {Cartesian3} direction The direction from position.
* @param {Cartesian2} [result] A Cartesian2 to store the nearest and farthest distances.
* @param {Interval} [result] A Interval to store the nearest and farthest distances.
* @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
*/
BoundingSphere.computePlaneDistances = function(sphere, position, direction, result) {
Expand All @@ -925,8 +925,7 @@ define([
}

var toCenter = Cartesian3.subtract(sphere.center, position, scratchCartesian3);
var proj = Cartesian3.multiplyByScalar(direction, Cartesian3.dot(direction, toCenter), scratchCartesian3);
var mag = Cartesian3.magnitude(proj);
var mag = Cartesian3.dot(direction, toCenter);

result.start = mag - sphere.radius;
result.stop = mag + sphere.radius;
Expand Down Expand Up @@ -1044,6 +1043,25 @@ define([
return result;
};

/**
* Determines whether or not a sphere is hidden from view by the occluder.
*
* @param {BoundingSphere} sphere The bounding sphere surrounding the occludee object.
* @param {Occluder} occluder The occluder.
* @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
*/
BoundingSphere.isOccluded = function(sphere, occluder) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Add these new functions to CHANGES.md.

//>>includeStart('debug', pragmas.debug);
if (!defined(sphere)) {
throw new DeveloperError('sphere is required.');
}
if (!defined(occluder)) {
throw new DeveloperError('occluder is required.');
}
//>>includeEnd('debug');
return !occluder.isBoundingSphereVisible(sphere);
};

/**
* Compares the provided BoundingSphere componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
Expand Down Expand Up @@ -1073,6 +1091,48 @@ define([
return BoundingSphere.intersectPlane(this, plane);
};

/**
* Computes the estimated distance squared from the closest point on a bounding sphere to a point.
*
* @param {Cartesian3} cartesian The point
* @returns {Number} The estimated distance squared from the bounding sphere to the point.
*
* @example
* // Sort bounding spheres from back to front
* spheres.sort(function(a, b) {
* return b.distanceSquaredTo(camera.positionWC) - a.distanceSquaredTo(camera.positionWC);
* });
*/
BoundingSphere.prototype.distanceSquaredTo = function(cartesian) {
return BoundingSphere.distanceSquaredTo(this, cartesian);
};

/**
* The distances calculated by the vector from the center of the bounding sphere to position projected onto direction
* plus/minus the radius of the bounding sphere.
* <br>
* If you imagine the infinite number of planes with normal direction, this computes the smallest distance to the
* closest and farthest planes from position that intersect the bounding sphere.
*
* @param {Cartesian3} position The position to calculate the distance from.
* @param {Cartesian3} direction The direction from position.
* @param {Interval} [result] A Interval to store the nearest and farthest distances.
* @returns {Interval} The nearest and farthest distances on the bounding sphere from position in direction.
*/
BoundingSphere.prototype.computePlaneDistances = function(position, direction, result) {
return BoundingSphere.computePlaneDistances(this, position, direction, result);
};

/**
* Determines whether or not a sphere is hidden from view by the occluder.
*
* @param {Occluder} occluder The occluder.
* @returns {Boolean} <code>true</code> if the sphere is not visible; otherwise <code>false</code>.
*/
BoundingSphere.prototype.isOccluded = function(occluder) {
return BoundingSphere.isOccluded(this, occluder);
};

/**
* Compares this BoundingSphere against the provided BoundingSphere componentwise and returns
* <code>true</code> if they are equal, <code>false</code> otherwise.
Expand Down
26 changes: 25 additions & 1 deletion Source/Core/CircleGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ define([
'./DeveloperError',
'./EllipseGeometry',
'./Ellipsoid',
'./Math',
'./VertexFormat'
], function(
Cartesian3,
Expand All @@ -14,11 +15,12 @@ define([
DeveloperError,
EllipseGeometry,
Ellipsoid,
CesiumMath,
VertexFormat) {
"use strict";

/**
* A description of a circle on the ellipsoid.
* A description of a circle on the ellipsoid. Circle geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
*
* @alias CircleGeometry
* @constructor
Expand Down Expand Up @@ -157,5 +159,27 @@ define([
return EllipseGeometry.createGeometry(circleGeometry._ellipseGeometry);
};

/**
* @private
*/
CircleGeometry.createShadowVolume = function(circleGeometry, minHeightFunc, maxHeightFunc) {
var granularity = circleGeometry._ellipseGeometry._granularity;
var ellipsoid = circleGeometry._ellipseGeometry._ellipsoid;

var minHeight = minHeightFunc(granularity, ellipsoid);
var maxHeight = maxHeightFunc(granularity, ellipsoid);

return new CircleGeometry({
center : circleGeometry._ellipseGeometry._center,
radius : circleGeometry._ellipseGeometry._semiMajorAxis,
ellipsoid : ellipsoid,
stRotation : circleGeometry._ellipseGeometry._stRotation,
granularity : granularity,
extrudedHeight : minHeight,
height : maxHeight,
vertexFormat : VertexFormat.POSITION_ONLY
});
};

return CircleGeometry;
});
24 changes: 23 additions & 1 deletion Source/Core/CorridorGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -621,7 +621,7 @@ define([
}

/**
* A description of a corridor.
* A description of a corridor. Corridor geometry can be rendered with both {@link Primitive} and {@link GroundPrimitive}.
*
* @alias CorridorGeometry
* @constructor
Expand Down Expand Up @@ -846,5 +846,27 @@ define([
});
};

/**
* @private
*/
CorridorGeometry.createShadowVolume = function(corridorGeometry, minHeightFunc, maxHeightFunc) {
var granularity = corridorGeometry._granularity;
var ellipsoid = corridorGeometry._ellipsoid;

var minHeight = minHeightFunc(granularity, ellipsoid);
var maxHeight = maxHeightFunc(granularity, ellipsoid);

return new CorridorGeometry({
positions : corridorGeometry._positions,
width : corridorGeometry._width,
cornerType : corridorGeometry._cornerType,
ellipsoid : ellipsoid,
granularity : granularity,
extrudedHeight : minHeight,
height : maxHeight,
vertexFormat : VertexFormat.POSITION_ONLY
});
};

return CorridorGeometry;
});
Loading