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

Allow users to define clipping regions with polygons #11750

Merged
merged 31 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
77bb0d1
ClippingPolygonCollection
ggetz Jan 9, 2024
eab1d19
Fix TS
ggetz Jan 9, 2024
0140ce0
Update CHANGES.md
ggetz Jan 9, 2024
15cad35
Draft
ggetz Mar 12, 2024
5079310
Merge branch 'main' into clip-region
ggetz Mar 12, 2024
7a789fd
Draft 2
ggetz Mar 13, 2024
70f1170
Merge branch 'main' into clip-region
ggetz Mar 15, 2024
b5ba48d
Draft
ggetz Mar 18, 2024
c185b7b
Merge branch 'main' into clip-region
ggetz Mar 18, 2024
fe5704e
Start cleanup
ggetz Mar 19, 2024
f42b7db
Update Specs
ggetz Mar 22, 2024
be45ded
Update clipping plane performance, wire through terrain clipping
ggetz Mar 25, 2024
c624775
Merge branch 'main' into clip-region
ggetz Mar 25, 2024
aca4f14
cleanup doc
ggetz Mar 25, 2024
3158943
Cleanup private classes
ggetz Mar 25, 2024
e87589d
Fix jagged edges
ggetz Apr 3, 2024
7305ce1
Specs cleanup
ggetz Apr 5, 2024
1b24f93
More specs
ggetz Apr 5, 2024
3cf00dc
More specs
ggetz Apr 5, 2024
58b5a42
Cleanup AEC example for tutorial
ggetz Apr 10, 2024
73cf3e2
Fix typos and whitespace
Apr 10, 2024
a43d78f
Fix typos and whitespace
Apr 11, 2024
dc84c67
Feedback from PR
ggetz Apr 12, 2024
3ac081f
Fix issue with terrain when zoomed out
ggetz Apr 15, 2024
38a2b9d
Update tests
ggetz Apr 16, 2024
e69d21f
Fix P3DT not clipping when zoomed out
ggetz Apr 16, 2024
b32fa28
Cleanup:
ggetz Apr 17, 2024
0f5c0a3
Cleanup
ggetz Apr 17, 2024
859abb9
Fix minor docs typos
Apr 22, 2024
71f7197
Fix sandcastle angle, too agressive simplification
ggetz Apr 23, 2024
620a0ec
Adjust clip polygon region combining
ggetz Apr 26, 2024
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Start cleanup
  • Loading branch information
ggetz committed Mar 19, 2024
commit fe5704e56b335af83fd4a0abdcef54e419be6c88
138 changes: 120 additions & 18 deletions packages/engine/Source/Scene/ClippingPolygon.js
Original file line number Diff line number Diff line change
@@ -1,37 +1,71 @@
import ArcType from "../Core/ArcType.js";
import Check from "../Core/Check.js";
import Cartesian3 from "../Core/Cartesian3.js";
import Cartographic from "../Core/Cartographic.js";
import defaultValue from "../Core/defaultValue.js";
import Ellipsoid from "../Core/Ellipsoid.js";
import CesiumMath from "../Core/Math.js";
import PolygonGeometry from "../Core/PolygonGeometry.js";
import Rectangle from "../Core/Rectangle.js";

/**
* No holes or complex polygons. TODO
* A geodesic polygon to be used with {@link ClippingPlaneCollection} for selectively hiding regions in a model, a 3D tileset, or the globe.
* @alias ClippingPolygon
* @constructor
*
* @param {object} [options] Object with the following properties:
* @param {object} options Object with the following properties:
* @param {PolygonHierarchy} options.hierarchy TODO
* @param {Ellipsoid} [options.ellipsoid=Ellipsoid.WGS84]
*
* TODO: Example
*/
function ClippingPolygon(options) {
options = defaultValue(options, defaultValue.EMPTY_OBJECT);

//>>includeStart('debug', pragmas.debug);
// TODO: Check
// TODO: At least three positions
Check.typeOf.object("options", options);
Check.typeOf.object("options.hierarchy", options.hierarchy);
Check.typeOf.number.greaterThanOrEquals(
"options.hierarchy.positions",
options.hierarchy.positions,
3
);
//>>includeEnd('debug');

this.ellipsoid = defaultValue(options.ellipsoid, Ellipsoid.WGS84);
this.arcType = defaultValue(options.arcType, ArcType.GEODESIC);
this.positions = options.positions;

this._rectangle = PolygonGeometry.computeRectangleFromPositions(
this.positions,
this.ellipsoid,
this.arcType
); // TODO:
this.hierarchy = options.hierarchy;
}

Object.defineProperties(ClippingPolygon.prototype, {});
Object.defineProperties(ClippingPolygon.prototype, {
/**
* Returns the total number of positions in the polygon, include any holes.
*
* @memberof ClippingPolygon.prototype
* @type {number}
* @readonly
*/
length: {
get: function () {
const hierarchy = this.hierarchy;
let length = hierarchy.positions.length;
let holes = hierarchy.holes;
while (holes.positions.length > 0) {
length += holes.positions.length;
holes = holes.holes;
}
return length;
},
},
/**
* Returns the outer ring of positions.
*
* @memberof ClippingPolygon.prototype
* @type {Cartesian3[]}
* @readonly
*/
outerPositions: {
get: function () {
return this.hierarchy.positions;
},
},
});

/**
* Clones the ClippingPolygon without setting its ownership.
Expand All @@ -44,14 +78,82 @@ ClippingPolygon.clone = function (clippingPlane, result) {
};

/**
* Computes a rectangle which encloses the polygon defined by the list of positions, including cases over the international date line and the poles.
* Computes a cartographic rectangle which encloses the polygon defined by the list of positions, including cases over the international date line and the poles.
*
* @param {Rectangle} [result] An object in which to store the result.
*
* @returns {Rectangle} The result rectangle
*/
ClippingPolygon.prototype.computeRectangle = function (result) {
return this._rectangle; // TODO
return PolygonGeometry.computeRectangleFromPositions(
this.hierarchy.positions,
this.ellipsoid,
undefined,
result
);
};

const scratchRectangle = new Rectangle();
const spherePointScratch = new Cartesian3();
/**
* Computes a rectangle with the spherical extents that encloses the polygon defined by the list of positions, including cases over the international date line and the poles.
*
* @private
*
* @param {Rectangle} [result] An object in which to store the result.
* @returns {Rectangle} The result rectangle with spherical extents.
*/
ClippingPolygon.prototype.computeSphericalExtents = function (result) {
const rectangle = PolygonGeometry.computeRectangleFromPositions(
this.hierarchy.positions,
this.ellipsoid,
undefined,
scratchRectangle
);

let spherePoint = Cartographic.toCartesian(
Rectangle.southwest(rectangle),
this.ellipsoid,
spherePointScratch
);

// Project into plane with vertical for latitude
let magXY = Math.sqrt(
spherePoint.x * spherePoint.x + spherePoint.y * spherePoint.y
);

// Use fastApproximateAtan2 for alignment with shader
let sphereLatitude = CesiumMath.fastApproximateAtan2(magXY, spherePoint.z);
let sphereLongitude = CesiumMath.fastApproximateAtan2(
spherePoint.x,
spherePoint.y
);

result.south = sphereLatitude;
result.west = sphereLongitude;

spherePoint = Cartographic.toCartesian(
Rectangle.northeast(rectangle),
this.ellipsoid,
spherePointScratch
);

// Project into plane with vertical for latitude
magXY = Math.sqrt(
spherePoint.x * spherePoint.x + spherePoint.y * spherePoint.y
);

// Use fastApproximateAtan2 for alignment with shader
sphereLatitude = CesiumMath.fastApproximateAtan2(magXY, spherePoint.z);
sphereLongitude = CesiumMath.fastApproximateAtan2(
spherePoint.x,
spherePoint.y
);

result.north = sphereLatitude;
result.east = sphereLongitude;

return result;
};

export default ClippingPolygon;
Loading