-
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
Clipping planes for models, tilesets, point clouds #5913
Changes from 1 commit
05a4387
5d0d22e
cb685e4
5512b11
ff35a7d
c3945d1
9252ad5
2b342c0
7a56927
1513f0c
d25a825
8642cf7
f843aa3
d9a2c56
bb4c63f
5be9ef6
973ae3a
7d6cba2
1c101a8
b01ffa9
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 |
---|---|---|
|
@@ -340,7 +340,6 @@ define([ | |
* @param {Color} [options.silhouetteColor=Color.RED] The silhouette color. If more than 256 models have silhouettes enabled, there is a small chance that overlapping models will have minor artifacts. | ||
* @param {Number} [options.silhouetteSize=0.0] The size of the silhouette in pixels. | ||
* @param {Plane[]} [options.clippingPlanes=[]] An array of {@link Plane} used to clip the model. | ||
* @param {} | ||
* | ||
* @exception {DeveloperError} bgltf is not a valid Binary glTF file. | ||
* @exception {DeveloperError} Only glTF Binary version 1 is supported. | ||
|
@@ -699,6 +698,8 @@ define([ | |
this._rtcCenterEye = undefined; // in eye coordinates | ||
this._rtcCenter3D = undefined; // in world coordinates | ||
this._rtcCenter2D = undefined; // in projected world coordinates | ||
|
||
this._packedClippingPlanes = []; | ||
} | ||
|
||
defineProperties(Model.prototype, { | ||
|
@@ -3312,7 +3313,6 @@ define([ | |
} | ||
|
||
var scratchCartesian = new Cartesian3(); | ||
var scratchPlane = new Cartesian4(); | ||
var scratchMatrix = new Matrix4(); | ||
|
||
function createClippingPlanesFunction(model, context) { | ||
|
@@ -3323,15 +3323,15 @@ define([ | |
|
||
var planes = model.clippingPlanes; | ||
var length = planes.length; | ||
var packedPlanes = new Array(length); | ||
var packedPlanes = model._packedClippingPlanes; | ||
for (var i = 0; i < length; ++i) { | ||
var plane = planes[i]; | ||
Matrix4.multiplyByPointAsVector(scratchMatrix, plane.normal, scratchPlane); | ||
Cartesian3.normalize(scratchPlane, scratchPlane); | ||
var packedPlane = packedPlanes[i]; | ||
Matrix4.multiplyByPointAsVector(scratchMatrix, plane.normal, packedPlane); | ||
Cartesian3.normalize(packedPlane, packedPlane); | ||
Cartesian3.multiplyByScalar(plane.normal, plane.distance, scratchCartesian); | ||
Matrix4.multiplyByPoint(scratchMatrix, scratchCartesian, scratchCartesian); | ||
scratchPlane.w = Cartesian3.dot(scratchPlane, scratchCartesian); | ||
packedPlanes[i] = scratchPlane.clone(); | ||
packedPlane.w = Cartesian3.dot(packedPlane, scratchCartesian); | ||
} | ||
return packedPlanes; | ||
}; | ||
|
@@ -4263,6 +4263,18 @@ define([ | |
} | ||
} | ||
|
||
function updateClippingPlanes(model) { | ||
var length = model.clippingPlanes.length; | ||
|
||
if (model._packedClippingPlanes.length !== length) { | ||
model._packedClippingPlanes= new Array(length); | ||
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. Slight spacing tweak: |
||
|
||
for (var i = 0; i < length; ++i) { | ||
model._packedClippingPlanes[i] = new Cartesian4(); | ||
} | ||
} | ||
} | ||
|
||
var scratchBoundingSphere = new BoundingSphere(); | ||
|
||
function scaleInPixels(positionWC, radius, frameState) { | ||
|
@@ -4727,6 +4739,7 @@ define([ | |
updateShadows(this); | ||
updateColor(this, frameState); | ||
updateSilhouette(this, frameState); | ||
updateClippingPlanes(this); | ||
} | ||
|
||
if (justLoaded) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -136,6 +136,8 @@ define([ | |
|
||
this._features = undefined; | ||
|
||
this._packedClippingPlanes = []; | ||
|
||
/** | ||
* @inheritdoc Cesium3DTileContent#featurePropertiesDirty | ||
*/ | ||
|
@@ -513,7 +515,6 @@ define([ | |
} | ||
|
||
var scratchCartesian = new Cartesian3(); | ||
var scratchPlane = new Cartesian4(); | ||
|
||
var uniformMap = { | ||
u_pointSizeAndTilesetTime : function() { | ||
|
@@ -533,14 +534,15 @@ define([ | |
u_clippingPlanes : function() { | ||
var planes = content._tileset.clippingPlanes; | ||
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. Same comment. |
||
var length = planes.length; | ||
var packedPlanes = new Array(length); | ||
var packedPlanes = content._packedClippingPlanes; | ||
for (var i = 0; i < length; ++i) { | ||
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. Limit to 6 here as well. |
||
var plane = planes[i]; | ||
Matrix3.multiplyByVector(context.uniformState.normal, plane.normal, scratchPlane); | ||
var packedPlane = packedPlanes[i]; | ||
|
||
Matrix3.multiplyByVector(context.uniformState.normal, plane.normal, packedPlane); | ||
Cartesian3.multiplyByScalar(plane.normal, plane.distance, scratchCartesian); | ||
Matrix4.multiplyByPoint(context.uniformState.modelView3D, scratchCartesian, scratchCartesian); | ||
scratchPlane.w = Cartesian3.dot(scratchPlane, scratchCartesian); | ||
packedPlanes[i] = scratchPlane.clone(); | ||
packedPlane.w = Cartesian3.dot(packedPlane, scratchCartesian); | ||
} | ||
return packedPlanes; | ||
} | ||
|
@@ -1262,6 +1264,16 @@ define([ | |
if (passes.pick) { | ||
commandList.push(this._pickCommand); | ||
} | ||
|
||
// update clipping planes | ||
var length = this._tileset.clippingPlanes.length; | ||
if (this._packedClippingPlanes.length !== length) { | ||
this._packedClippingPlanes = new Array(length); | ||
|
||
for (var i = 0; i < length; ++i) { | ||
this._packedClippingPlanes[i] = new Cartesian4(); | ||
} | ||
} | ||
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. Place this above the command list code. In general commands go last. |
||
}; | ||
|
||
/** | ||
|
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.
This should probably be limited to 6. Check what happens if you have more than 6 clipping planes, there may be an error in setting the uniform.