Skip to content

Commit

Permalink
refactor(core): update view Matrix view only when it's needed
Browse files Browse the repository at this point in the history
  • Loading branch information
gchoqueux committed Jan 22, 2019
1 parent f3d9df7 commit 29fa985
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Renderer/Camera.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ function Camera(crs, width, height, options = {}) {
this._viewMatrix = new THREE.Matrix4();
this.width = width;
this.height = height;
this._viewMatrixNeedsUpdate = true;
this.resize(width, height);

this._preSSE = Infinity;
Expand Down Expand Up @@ -93,15 +94,14 @@ Camera.prototype.resize = function resize(width, height) {

if (this.camera3D.updateProjectionMatrix) {
this.camera3D.updateProjectionMatrix();
this._viewMatrixNeedsUpdate = true;
}
};

Camera.prototype.update = function update() {
// update matrix
this.camera3D.updateMatrixWorld();

// keep our visibility testing matrix ready
this._viewMatrix.multiplyMatrices(this.camera3D.projectionMatrix, this.camera3D.matrixWorldInverse);
this._viewMatrixNeedsUpdate = true;
};

/**
Expand Down Expand Up @@ -180,6 +180,11 @@ Camera.prototype.isBox3Visible = function isBox3Visible(box3, matrixWorld) {
};

Camera.prototype.isSphereVisible = function isSphereVisible(sphere, matrixWorld) {
if (this._viewMatrixNeedsUpdate) {
// update visibility testing matrix
this._viewMatrix.multiplyMatrices(this.camera3D.projectionMatrix, this.camera3D.matrixWorldInverse);
this._viewMatrixNeedsUpdate = false;
}
if (matrixWorld) {
tmp.matrix.multiplyMatrices(this._viewMatrix, matrixWorld);
tmp.frustum.setFromMatrix(tmp.matrix);
Expand Down

0 comments on commit 29fa985

Please sign in to comment.