-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
Polygonidl #720
Polygonidl #720
Changes from 40 commits
ce3bb4e
499da4f
a57c0bb
1779db8
2ef3f70
553e45b
ddebb2d
55bf30e
97cfe50
dc54e69
1437541
41df010
eaaee87
84b5a25
1a82ec5
62dc7ec
2046355
72019c5
604eb10
9a91e5f
8a72ddd
1b1f945
b387eee
e45eae3
9a5e145
1438d9b
5eb53e5
0b60e0b
9debf43
ccc6eaf
da9adc0
f063d96
8708500
5455333
fe52dcb
78420ba
956052a
8299faa
51958a7
2413324
fce825c
cd33da6
3a7d363
7843283
eaf79f2
d997fbb
ccc4723
06a7a4e
3486a02
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,10 @@ Beta Releases | |
* Fixed an error in Web Worker creation when loading Cesium.js from a different origin. | ||
* Fixed `EllipsoidPrimitive` picking and picking objects with materials that have transparent parts. | ||
|
||
### TODO | ||
|
||
* Added `IntersectionTests.trianglePlaneIntersection`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, we should move these to a new section for b17 since b16 is already done. |
||
|
||
### b15 - 2013-04-01 | ||
|
||
* Breaking changes: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,4 +208,4 @@ define([ | |
}; | ||
|
||
return EllipsoidTangentPlane; | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,13 @@ define([ | |
QuarticRealPolynomial) { | ||
"use strict"; | ||
|
||
// TODO | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are TODOs I had from a while back.
Nah.
Please test this, but if it doesn't work in 2D or Columbus view, write an issue. It doesn't need to holdup this pull request.
Please add them. Even though the polygon tests it indirectly, we want to have specific tests. |
||
// equals, etc. for Plane? | ||
// Should ray constructor normalize? | ||
// Make EllipsoidTangentPlane contain plane? | ||
// Does extent triangulator work over IDL? | ||
// Tests for new wrapLongitude. | ||
|
||
/** | ||
* DOC_TBA | ||
* | ||
|
@@ -418,5 +425,280 @@ define([ | |
return result; | ||
}; | ||
|
||
/** | ||
* Computes the intersection of a triangle and a plane | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mind adding an |
||
* @memberof IntersectionTests | ||
* | ||
* @param {Cartesian3} p0 First point of the triangle | ||
* @param {Cartesian3} p1 Second point of the triangle | ||
* @param {Cartesian3} p2 Third point of the triangle | ||
* @param {Plane} plane Intersection plane | ||
* | ||
* @returns Three triangles that do not cross the plane. (Undefined if no intersection exists) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type is missing. |
||
* | ||
* @exception {DeveloperError} p0, p1, p2, and plane are required. | ||
*/ | ||
IntersectionTests.trianglePlaneIntersection = function(p0, p1, p2, plane) { | ||
if ((typeof p0 === 'undefined') || | ||
(typeof p1 === 'undefined') || | ||
(typeof p2 === 'undefined') || | ||
(typeof plane === 'undefined')) { | ||
throw new DeveloperError('p0, p1, p2, and plane are required.'); | ||
} | ||
|
||
// TODO: returning triangle strips or fans? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can remove this. |
||
var planeNormal = plane.normal; | ||
var planeD = plane.distance; | ||
var p0Behind = (Cartesian3.dot(planeNormal, p0) + planeD) < 0.0; | ||
var p1Behind = (Cartesian3.dot(planeNormal, p1) + planeD) < 0.0; | ||
var p2Behind = (Cartesian3.dot(planeNormal, p2) + planeD) < 0.0; | ||
// Given these dots products, the calls to lineSegmentPlaneIntersection | ||
// always have defined results. | ||
|
||
var numBehind = 0; | ||
numBehind += p0Behind ? 1 : 0; | ||
numBehind += p1Behind ? 1 : 0; | ||
numBehind += p2Behind ? 1 : 0; | ||
|
||
var u1, u2; | ||
if (numBehind === 1 || numBehind === 2) { | ||
u1 = new Cartesian3(); | ||
u2 = new Cartesian3(); | ||
} | ||
|
||
if (numBehind === 1) { | ||
if (p0Behind) { | ||
IntersectionTests.lineSegmentPlane(p0, p1, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p0, p2, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
0, 3, 4, | ||
|
||
// In front | ||
1, 2, 4, | ||
1, 4, 3 | ||
] | ||
}; | ||
} else if (p1Behind) { | ||
IntersectionTests.lineSegmentPlane(p1, p2, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p1, p0, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
1, 3, 4, | ||
|
||
// In front | ||
2, 0, 4, | ||
2, 4, 3 | ||
] | ||
}; | ||
} else if (p2Behind) { | ||
IntersectionTests.lineSegmentPlane(p2, p0, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p2, p1, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
2, 3, 4, | ||
|
||
// In front | ||
0, 1, 4, | ||
0, 4, 3 | ||
] | ||
}; | ||
} | ||
} else if (numBehind === 2) { | ||
if (!p0Behind) { | ||
IntersectionTests.lineSegmentPlane(p1, p0, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p2, p0, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
1, 2, 4, | ||
1, 4, 3, | ||
|
||
// In front | ||
0, 3, 4 | ||
] | ||
}; | ||
} else if (!p1Behind) { | ||
IntersectionTests.lineSegmentPlane(p2, p1, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p0, p1, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
2, 0, 4, | ||
2, 4, 3, | ||
|
||
// In front | ||
1, 3, 4 | ||
] | ||
}; | ||
} else if (!p2Behind) { | ||
IntersectionTests.lineSegmentPlane(p0, p2, plane, u1); | ||
IntersectionTests.lineSegmentPlane(p1, p2, plane, u2); | ||
|
||
return { | ||
positions : [p0, p1, p2, u1, u2 ], | ||
indices : [ | ||
// Behind | ||
0, 1, 4, | ||
0, 4, 3, | ||
|
||
// In front | ||
2, 3, 4 | ||
] | ||
}; | ||
} | ||
} | ||
|
||
// if numBehind is 3, the triangle is completely behind the plane; | ||
// otherwise, it is completely in front (numBehind is 0). | ||
return undefined; | ||
}; | ||
|
||
|
||
/** | ||
* Computes the intersection of a triangle and the XZ plane. Offsets points from the XZ plane. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add an It will also be good to add some motivation for this function compared to |
||
* @memberof IntersectionTests | ||
* | ||
* @param {Cartesian3} p0 First point of triangle | ||
* @param {Cartesian3} p1 Second point of triange | ||
* @param {Cartesian3} p2 Third point of triange | ||
* | ||
* @return Three triangles that are offset from intersecting with the plane. (Undefined if no intersection found) | ||
* | ||
* @exception {DeveloperError} p0, p1 and p2 are required. | ||
*/ | ||
var xz_plane = new Plane(Cartesian3.UNIT_Y, 0.0); | ||
IntersectionTests.triangleXZPlaneIntersection = function(p0, p1, p2) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Given the use of the epsilon, this is pretty specific. This could use a new name like Since this is specific, it probably belongs as a file-level scope function in PolygonPipeline.js, in which case you don't have to worry about doc. Also, when I originally wrote
@bagnell thoughts? |
||
if ((typeof p0 === 'undefined') || | ||
(typeof p1 === 'undefined') || | ||
(typeof p2 === 'undefined')) { | ||
throw new DeveloperError('p0, p1 and p2 are required.'); | ||
} | ||
|
||
var p0Behind = p0.y < 0.0; | ||
var p1Behind = p1.y < 0.0; | ||
var p2Behind = p2.y < 0.0; | ||
|
||
offsetPointFromXZPlane(p0, p0Behind); | ||
offsetPointFromXZPlane(p1, p1Behind); | ||
offsetPointFromXZPlane(p2, p2Behind); | ||
|
||
var numBehind = 0; | ||
numBehind += p0Behind ? 1 : 0; | ||
numBehind += p1Behind ? 1 : 0; | ||
numBehind += p2Behind ? 1 : 0; | ||
|
||
var u1, u2, v1, v2, result; | ||
|
||
if (numBehind === 1 || numBehind === 2) { | ||
u1 = new Cartesian3(); | ||
u2 = new Cartesian3(); | ||
v1 = new Cartesian3(); | ||
v2 = new Cartesian3(); | ||
result = { positions : [p0, p1, p2, u1, u2, v1, v2 ] }; | ||
} | ||
|
||
if (numBehind === 1) { | ||
if (p0Behind) { | ||
getXZIntersectionOffsetPoints(p0, p1, p2, u1, u2, v1, v2); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can optimize this even more given that we are dealing with the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Whoops, sorry, it is the |
||
result.indices = [ | ||
// Behind | ||
0, 3, 4, | ||
|
||
// In front | ||
1, 2, 6, | ||
1, 6, 5 | ||
]; | ||
} else if (p1Behind) { | ||
getXZIntersectionOffsetPoints(p1, p0, p2, u1, u2, v1, v2); | ||
result.indices = [ | ||
// Behind | ||
1, 3, 4, | ||
|
||
// In front | ||
2, 0, 6, | ||
2, 6, 5 | ||
]; | ||
} else if (p2Behind) { | ||
getXZIntersectionOffsetPoints(p2, p0, p1, u1, u2, v1, v2); | ||
result.indices = [ | ||
// Behind | ||
2, 3, 4, | ||
|
||
// In front | ||
0, 1, 6, | ||
0, 6, 5 | ||
]; | ||
} | ||
} else if (numBehind === 2) { | ||
if (!p0Behind) { | ||
getXZIntersectionOffsetPoints(p0, p1, p2, u1, u2, v1, v2); | ||
result.indices = [ | ||
// Behind | ||
1, 2, 4, | ||
1, 4, 3, | ||
|
||
// In front | ||
0, 5, 6 | ||
]; | ||
} else if (!p1Behind) { | ||
getXZIntersectionOffsetPoints(p1, p2, p0, u1, u2, v1, v2); | ||
result.indices = [ | ||
// Behind | ||
2, 0, 4, | ||
2, 4, 3, | ||
|
||
// In front | ||
1, 5, 6 | ||
]; | ||
} else if (!p2Behind) { | ||
getXZIntersectionOffsetPoints(p2, p0, p1, u1, u2, v1, v2); | ||
result.indices = [ | ||
// Behind | ||
0, 1, 4, | ||
0, 4, 3, | ||
|
||
// In front | ||
2, 5, 6 | ||
]; | ||
} | ||
} | ||
return result; | ||
}; | ||
|
||
function getXZIntersectionOffsetPoints(p, p1, p2, u1, u2, v1, v2) { | ||
IntersectionTests.lineSegmentPlane(p, p1, xz_plane, u1); | ||
IntersectionTests.lineSegmentPlane(p, p2, xz_plane, u2); | ||
Cartesian3.clone(u1, v1); | ||
Cartesian3.clone(u2, v2); | ||
offsetPointFromXZPlane(u1, true); | ||
offsetPointFromXZPlane(u2, true); | ||
offsetPointFromXZPlane(v1, false); | ||
offsetPointFromXZPlane(v2, false); | ||
} | ||
|
||
function offsetPointFromXZPlane(p, isBehind) { | ||
if (Math.abs(p.y) < CesiumMath.EPSILON11){ | ||
if (isBehind) { | ||
p.y = -CesiumMath.EPSILON11; | ||
} else { | ||
p.y = CesiumMath.EPSILON11; | ||
} | ||
} | ||
} | ||
|
||
return IntersectionTests; | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -144,4 +144,4 @@ define([ | |
}; | ||
|
||
return Plane; | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes should be moved up to the b16 section.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this section and move it to
b16
(that's hoping we merge it quickly, of course).Also add a note that we fixed the polygon International Dateline in 2D and Columbus view.