Skip to content

Commit

Permalink
Merge pull request #11210 from CesiumGS/frustum-fix
Browse files Browse the repository at this point in the history
Ensure offCenterFrustum's values are updated
  • Loading branch information
jjhembd authored Apr 12, 2023
2 parents c31cef7 + efe190b commit 8c82397
Show file tree
Hide file tree
Showing 12 changed files with 61 additions and 26 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@

##### Fixes :wrench:

- Fixed issue with calling `switchToOrthographicFunction` and `camera.flyTo` in immediate succession. [#11210](https://github.com/CesiumGS/cesium/pull/11210)
- Fixed an issue when zooming in an orthographic frustum. [#11206](https://github.com/CesiumGS/cesium/pull/11206)
- Fixed atmosphere rendering performance issue. [10510](https://github.com/CesiumGS/cesium/issues/10510)
- Fixed model rendering when emissiveTexture is defined and emissiveFactor is not. [#11215](https://github.com/CesiumGS/cesium/pull/11215)

#### @cesium/widgets

##### Fixes :wrench:

- Fixed missing `ContextOptions` in generated TypeScript definitions. [10963](https://github.com/CesiumGS/cesium/issues/10963)
- Fixed model rendering when emissiveTexture is defined and emissiveFactor is not. [#11215](https://github.com/CesiumGS/cesium/pull/11215)

### 1.104 - 2023-04-03

Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Core/FrustumGeometry.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,9 @@ FrustumGeometry._computeNearFarPlanes = function (
);

if (!defined(inverseViewProjection)) {
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}

const near = frustumSplits[i];
Expand Down
13 changes: 13 additions & 0 deletions packages/engine/Source/Core/OrthographicFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,19 @@ Object.defineProperties(OrthographicFrustum.prototype, {
return this._offCenterFrustum.projectionMatrix;
},
},
/**
* Gets the orthographic projection matrix computed from the view frustum.
* @memberof OrthographicFrustum.prototype
* @type {OrthographicOffCenterFrustum}
* @readonly
* @private
*/
offCenterFrustum: {
get: function () {
update(this);
return this._offCenterFrustum;
},
},
});

/**
Expand Down
14 changes: 14 additions & 0 deletions packages/engine/Source/Core/PerspectiveFrustum.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,20 @@ Object.defineProperties(PerspectiveFrustum.prototype, {
return this._sseDenominator;
},
},

/**
* Gets the orthographic projection matrix computed from the view frustum.
* @memberof PerspectiveFrustum.prototype
* @type {PerspectiveOffCenterFrustum}
* @readonly
* @private
*/
offCenterFrustum: {
get: function () {
update(this);
return this._offCenterFrustum;
},
},
});

/**
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Renderer/UniformState.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,8 +1173,9 @@ UniformState.prototype.updateFrustum = function (frustum) {
this._oneOverLog2FarDepthFromNearPlusOne =
1.0 / this._log2FarDepthFromNearPlusOne;

if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}

this._frustumPlanes.x = frustum.top;
Expand Down
15 changes: 8 additions & 7 deletions packages/engine/Source/Scene/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -2602,9 +2602,8 @@ function rectangleCameraPosition3D(camera, rectangle, result, updateCamera) {

let rightScalar;
let topScalar;
const ratio =
camera.frustum._offCenterFrustum.right /
camera.frustum._offCenterFrustum.top;
const offCenterFrustum = camera.frustum._offCenterFrustum;
const ratio = offCenterFrustum.right / offCenterFrustum.top;
const heightRatio = height * ratio;
if (width > heightRatio) {
rightScalar = width;
Expand Down Expand Up @@ -2950,8 +2949,9 @@ function getPickRayOrthographic(camera, windowPosition, result) {
const height = canvas.clientHeight;

let frustum = camera.frustum;
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}
let x = (2.0 / width) * windowPosition.x - 1.0;
x *= (frustum.right - frustum.left) * 0.5;
Expand Down Expand Up @@ -3440,8 +3440,9 @@ function distanceToBoundingSphere3D(camera, radius) {

function distanceToBoundingSphere2D(camera, radius) {
let frustum = camera.frustum;
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}

let right, top;
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Scene/Cesium3DTile.js
Original file line number Diff line number Diff line change
Expand Up @@ -917,8 +917,9 @@ Cesium3DTile.prototype.getScreenSpaceError = function (
frameState.mode === SceneMode.SCENE2D ||
frustum instanceof OrthographicFrustum
) {
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}
const pixelSize =
Math.max(frustum.top - frustum.bottom, frustum.right - frustum.left) /
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Scene/Picking.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,9 @@ function getPickOrthographicCullingVolume(
) {
const camera = scene.camera;
let frustum = camera.frustum;
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}

let x = (2.0 * (drawingBufferPosition.x - viewport.x)) / viewport.width - 1.0;
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Scene/QuadtreePrimitive.js
Original file line number Diff line number Diff line change
Expand Up @@ -1275,8 +1275,9 @@ function screenSpaceError(primitive, frameState, tile) {
function screenSpaceError2D(primitive, frameState, tile) {
const camera = frameState.camera;
let frustum = camera.frustum;
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}

const context = frameState.context;
Expand Down
5 changes: 3 additions & 2 deletions packages/engine/Source/Scene/SceneTransforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,9 @@ SceneTransforms.drawingBufferToWgs84Coordinates = function (
let worldCoords;
let frustum = scene.camera.frustum;
if (!defined(frustum.fovy)) {
if (defined(frustum._offCenterFrustum)) {
frustum = frustum._offCenterFrustum;
const offCenterFrustum = frustum.offCenterFrustum;
if (defined(offCenterFrustum)) {
frustum = offCenterFrustum;
}
worldCoords = scratchWorldCoords;
worldCoords.x =
Expand Down
8 changes: 4 additions & 4 deletions packages/engine/Specs/Core/OrthographicFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,7 @@ describe("Core/OrthographicFrustum", function () {
});

it("get orthographic projection matrix", function () {
const projectionMatrix = frustum.projectionMatrix;
frustum = frustum._offCenterFrustum;
frustum = frustum.offCenterFrustum;
const expected = Matrix4.computeOrthographicOffCenter(
frustum.left,
frustum.right,
Expand All @@ -149,6 +148,7 @@ describe("Core/OrthographicFrustum", function () {
frustum.far,
new Matrix4()
);
const projectionMatrix = frustum.projectionMatrix;
expect(projectionMatrix).toEqualEpsilon(expected, CesiumMath.EPSILON6);
});

Expand Down Expand Up @@ -217,7 +217,7 @@ describe("Core/OrthographicFrustum", function () {
pixelRatio,
new Cartesian2()
);
const expected = frustum._offCenterFrustum.getPixelDimensions(
const expected = frustum.offCenterFrustum.getPixelDimensions(
dimensions.x,
dimensions.y,
distance,
Expand All @@ -239,7 +239,7 @@ describe("Core/OrthographicFrustum", function () {
pixelRatio,
new Cartesian2()
);
const expected = frustum._offCenterFrustum.getPixelDimensions(
const expected = frustum.offCenterFrustum.getPixelDimensions(
dimensions.x,
dimensions.y,
distance,
Expand Down
4 changes: 2 additions & 2 deletions packages/engine/Specs/Core/PerspectiveFrustumSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe("Core/PerspectiveFrustum", function () {
pixelRatio,
new Cartesian2()
);
const expected = frustum._offCenterFrustum.getPixelDimensions(
const expected = frustum.offCenterFrustum.getPixelDimensions(
dimensions.x,
dimensions.y,
distance,
Expand All @@ -272,7 +272,7 @@ describe("Core/PerspectiveFrustum", function () {
pixelRatio,
new Cartesian2()
);
const expected = frustum._offCenterFrustum.getPixelDimensions(
const expected = frustum.offCenterFrustum.getPixelDimensions(
dimensions.x,
dimensions.y,
distance,
Expand Down

0 comments on commit 8c82397

Please sign in to comment.