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 20 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
65 changes: 65 additions & 0 deletions Apps/Sandcastle/gallery/development/Ground Polygon.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<!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
});
scene.globe.depthTestAgainstTerrain = true;

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 groundPolygon = scene.primitives.add(new Cesium.GroundPolygon({
//debugVolume : true,
polygonHierarchy : polygonHierarchy
}));

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);

//Sandcastle_End
Sandcastle.finishedLoading();
}
if (typeof Cesium !== "undefined") {
startup(Cesium);
} else if (typeof require === "function") {
require(["Cesium"], startup);
}
</script>
</body>
</html>
217 changes: 11 additions & 206 deletions Source/Core/PolygonGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ define([
'./Matrix3',
'./PolygonGeometryLibrary',
'./PolygonPipeline',
'./PrimitiveType',
'./Quaternion',
'./Queue',
'./VertexFormat',
'./WindingOrder'
], function(
Expand All @@ -46,9 +44,7 @@ define([
Matrix3,
PolygonGeometryLibrary,
PolygonPipeline,
PrimitiveType,
Quaternion,
Queue,
VertexFormat,
WindingOrder) {
"use strict";
Expand Down Expand Up @@ -89,55 +85,6 @@ define([
return result;
}

var createGeometryFromPositionsPositions = [];

function createGeometryFromPositions(ellipsoid, positions, granularity, perPositionHeight) {
var tangentPlane = EllipsoidTangentPlane.fromPoints(positions, ellipsoid);
var positions2D = tangentPlane.projectPointsOntoPlane(positions, createGeometryFromPositionsPositions);

var originalWindingOrder = PolygonPipeline.computeWindingOrder2D(positions2D);
if (originalWindingOrder === WindingOrder.CLOCKWISE) {
positions2D.reverse();
positions.reverse();
}

var indices = PolygonPipeline.triangulate(positions2D);
/* If polygon is completely unrenderable, just use the first three vertices */
if (indices.length < 3) {
indices = [0, 1, 2];
}

var geo;
if (!perPositionHeight) {
geo = PolygonPipeline.computeSubdivision(ellipsoid, positions, indices, granularity);
} else {
var length = positions.length;
var flattenedPositions = new Array(length * 3);
var index = 0;
for ( var i = 0; i < length; i++) {
var p = positions[i];
flattenedPositions[index++] = p.x;
flattenedPositions[index++] = p.y;
flattenedPositions[index++] = p.z;
}
geo = new Geometry({
attributes : {
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.DOUBLE,
componentsPerAttribute : 3,
values : flattenedPositions
})
},
indices : indices,
primitiveType : PrimitiveType.TRIANGLES
});
}

return new GeometryInstance({
geometry : geo
});
}

var scratchBoundingRectangle = new BoundingRectangle();
var scratchPosition = new Cartesian3();
var scratchNormal = new Cartesian3();
Expand Down Expand Up @@ -329,114 +276,10 @@ define([
return geometry;
}

var computeWallIndicesSubdivided = [];

function computeWallIndices(positions, ellipsoid, granularity, perPositionHeight){
var edgePositions;
var topEdgeLength;
var i;
var p1;
var p2;

var length = positions.length;
var index = 0;

if (!perPositionHeight) {
var minDistance = CesiumMath.chordLength(granularity, ellipsoid.maximumRadius);

var numVertices = 0;
for (i = 0; i < length; i++) {
numVertices += PolygonGeometryLibrary.subdivideLineCount(positions[i], positions[(i + 1) % length], minDistance);
}

topEdgeLength = (numVertices + length) * 3;
edgePositions = new Array(topEdgeLength * 2);
for (i = 0; i < length; i++) {
p1 = positions[i];
p2 = positions[(i + 1) % length];

var tempPositions = PolygonGeometryLibrary.subdivideLine(p1, p2, minDistance, computeWallIndicesSubdivided);
var tempPositionsLength = tempPositions.length;
for (var j = 0; j < tempPositionsLength; ++j, ++index) {
edgePositions[index] = tempPositions[j];
edgePositions[index + topEdgeLength] = tempPositions[j];
}

edgePositions[index] = p2.x;
edgePositions[index + topEdgeLength] = p2.x;
++index;

edgePositions[index] = p2.y;
edgePositions[index + topEdgeLength] = p2.y;
++index;

edgePositions[index] = p2.z;
edgePositions[index + topEdgeLength] = p2.z;
++index;
}
} else {
topEdgeLength = length * 3 * 2;
edgePositions = new Array(topEdgeLength * 2);
for (i = 0; i < length; i++) {
p1 = positions[i];
p2 = positions[(i + 1) % length];
edgePositions[index] = edgePositions[index + topEdgeLength] = p1.x;
++index;
edgePositions[index] = edgePositions[index + topEdgeLength] = p1.y;
++index;
edgePositions[index] = edgePositions[index + topEdgeLength] = p1.z;
++index;
edgePositions[index] = edgePositions[index + topEdgeLength] = p2.x;
++index;
edgePositions[index] = edgePositions[index + topEdgeLength] = p2.y;
++index;
edgePositions[index] = edgePositions[index + topEdgeLength] = p2.z;
++index;
}
}

length = edgePositions.length;
var indices = IndexDatatype.createTypedArray(length / 3, length - positions.length * 6);
var edgeIndex = 0;
length /= 6;

for (i = 0; i < length; i++) {
var UL = i;
var UR = UL + 1;
var LL = UL + length;
var LR = LL + 1;

p1 = Cartesian3.fromArray(edgePositions, UL * 3, p1Scratch);
p2 = Cartesian3.fromArray(edgePositions, UR * 3, p2Scratch);
if (Cartesian3.equalsEpsilon(p1, p2, CesiumMath.EPSILON14)) {
continue;
}

indices[edgeIndex++] = UL;
indices[edgeIndex++] = LL;
indices[edgeIndex++] = UR;
indices[edgeIndex++] = UR;
indices[edgeIndex++] = LL;
indices[edgeIndex++] = LR;
}

return new Geometry({
attributes : new GeometryAttributes({
position : new GeometryAttribute({
componentDatatype : ComponentDatatype.DOUBLE,
componentsPerAttribute : 3,
values : edgePositions
})
}),
indices : indices,
primitiveType : PrimitiveType.TRIANGLES
});
}

var createGeometryFromPositionsExtrudedPositions = [];

function createGeometryFromPositionsExtruded(ellipsoid, positions, granularity, hierarchy, perPositionHeight) {
var topGeo = createGeometryFromPositions(ellipsoid, positions, granularity, perPositionHeight).geometry;
var topGeo = PolygonGeometryLibrary.createGeometryFromPositions(ellipsoid, positions, granularity, perPositionHeight);

var edgePoints = topGeo.attributes.position.values;
var indices = topGeo.indices;
Expand Down Expand Up @@ -489,7 +332,7 @@ define([
outerRing.reverse();
}

var wallGeo = computeWallIndices(outerRing, ellipsoid, granularity, perPositionHeight);
var wallGeo = PolygonGeometryLibrary.computeWallGeometry(outerRing, ellipsoid, granularity, perPositionHeight);
geos.walls.push(new GeometryInstance({
geometry : wallGeo
}));
Expand All @@ -506,7 +349,7 @@ define([
hole.reverse();
}

wallGeo = computeWallIndices(hole, ellipsoid, granularity);
wallGeo = PolygonGeometryLibrary.computeWallGeometry(hole, ellipsoid, granularity);
geos.walls.push(new GeometryInstance({
geometry : wallGeo
}));
Expand Down Expand Up @@ -812,50 +655,9 @@ define([
var topAndBottom;
var outerPositions;

// create from a polygon hierarchy
// Algorithm adapted from http://www.geometrictools.com/Documentation/TriangulationByEarClipping.pdf
var polygons = [];
var queue = new Queue();
queue.enqueue(polygonHierarchy);
polygonHierarchy = [];
var i;
while (queue.length !== 0) {
var outerNode = queue.dequeue();
var outerRing = outerNode.positions;
var holes = outerNode.holes;
outerRing = PolygonPipeline.removeDuplicates(outerRing);
if (outerRing.length < 3) {
continue;
}

var numChildren = defined(holes) ? holes.length : 0;
var polygonHoles = [];
for (i = 0; i < numChildren; i++) {
var hole = holes[i];
hole.positions = PolygonPipeline.removeDuplicates(hole.positions);
if (hole.positions.length < 3) {
continue;
}
polygonHoles.push(hole.positions);

var numGrandchildren = 0;
if (defined(hole.holes)) {
numGrandchildren = hole.holes.length;
}

for ( var j = 0; j < numGrandchildren; j++) {
queue.enqueue(hole.holes[j]);
}
}

polygonHierarchy.push({
outerRing : outerRing,
holes : polygonHoles
});

var combinedPolygon = polygonHoles.length > 0 ? PolygonPipeline.eliminateHoles(outerRing, polygonHoles) : outerRing;
polygons.push(combinedPolygon);
}
var results = PolygonGeometryLibrary.polygonsFromHierarchy(polygonHierarchy);
var hierarchy = results.hierarchy;
var polygons = results.polygons;

if (polygons.length === 0) {
return undefined;
Expand All @@ -865,10 +667,11 @@ define([

var geometry;
var geometries = [];
var i;

if (extrude) {
for (i = 0; i < polygons.length; i++) {
geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, polygonHierarchy[i], perPositionHeight);
geometry = createGeometryFromPositionsExtruded(ellipsoid, polygons[i], granularity, hierarchy[i], perPositionHeight);
topAndBottom = geometry.topAndBottom;
topAndBottom.geometry = PolygonGeometryLibrary.scaleToGeodeticHeightExtruded(topAndBottom.geometry, height, extrudedHeight, ellipsoid, perPositionHeight);
topAndBottom.geometry = computeAttributes(vertexFormat, topAndBottom.geometry, outerPositions, ellipsoid, stRotation, true, false);
Expand All @@ -884,7 +687,9 @@ define([
}
} else {
for (i = 0; i < polygons.length; i++) {
geometry = createGeometryFromPositions(ellipsoid, polygons[i], granularity, perPositionHeight);
geometry = new GeometryInstance({
geometry : PolygonGeometryLibrary.createGeometryFromPositions(ellipsoid, polygons[i], granularity, perPositionHeight)
});
geometry.geometry = PolygonPipeline.scaleToGeodeticHeight(geometry.geometry, height, ellipsoid, !perPositionHeight);
geometry.geometry = computeAttributes(vertexFormat, geometry.geometry, outerPositions, ellipsoid, stRotation, false, false);
geometries.push(geometry);
Expand Down
Loading