Skip to content

Commit

Permalink
fix(view): fix view resize when width or height is 0
Browse files Browse the repository at this point in the history
  • Loading branch information
jailln committed Dec 8, 2022
1 parent cccacae commit dbd9ee3
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
11 changes: 9 additions & 2 deletions src/Core/View.js
Expand Up @@ -1088,6 +1088,11 @@ class View extends THREE.EventDispatcher {
* the viewer with. By default it is the `clientHeight` of the `viewerDiv`.
*/
resize(width, height) {
if (width < 0 || height < 0) {
console.warn(`Trying to resize the View with negative height (${height}) or width (${width}). Skipping resize.`);
return;
}

if (width == undefined) {
width = this.domElement.clientWidth;
}
Expand All @@ -1098,8 +1103,10 @@ class View extends THREE.EventDispatcher {

this.#fullSizeDepthBuffer = new Uint8Array(4 * width * height);
this.mainLoop.gfxEngine.onWindowResize(width, height);
this.camera.resize(width, height);
this.notifyChange(this.camera.camera3D);
if (width !== 0 && height !== 0) {
this.camera.resize(width, height);
this.notifyChange(this.camera.camera3D);
}
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/Renderer/Camera.js
Expand Up @@ -139,12 +139,16 @@ class Camera {
}

/**
* Resize the camera to a given width and height
* Resize the camera to a given width and height.
*
* @param {number} width The width to resize the camera to.
* @param {number} height The height to resize the camera to.
* @param {number} width The width to resize the camera to. Must be strictly positive, won't resize otherwise.
* @param {number} height The height to resize the camera to. Must be strictly positive, won't resize otherwise.
*/
resize(width, height) {
if (!width || width <= 0 || !height || height <= 0) {
console.warn(`Trying to resize the Camera with invalid height (${height}) or width (${width}). Skipping resize.`);
return;
}
const ratio = width / height;
if (this.camera3D.aspect !== ratio) {
if (this.camera3D.isOrthographicCamera) {
Expand Down

0 comments on commit dbd9ee3

Please sign in to comment.