diff --git a/packages/core/src/core/OrthoPerspectiveCamera/index.ts b/packages/core/src/core/OrthoPerspectiveCamera/index.ts index a70276357..7c5160802 100644 --- a/packages/core/src/core/OrthoPerspectiveCamera/index.ts +++ b/packages/core/src/core/OrthoPerspectiveCamera/index.ts @@ -223,6 +223,11 @@ export class OrthoPerspectiveCamera extends SimpleCamera { const size = this.currentWorld.renderer.getSize(); + if (this.previousSize.x === 0 || this.previousSize.y === 0) { + this.previousSize.copy(size); + return; + } + const previousHeight = this.threeOrtho.top; const previousWidth = this.threeOrtho.right; diff --git a/packages/core/src/core/Worlds/src/simple-camera.ts b/packages/core/src/core/Worlds/src/simple-camera.ts index c4bc99aef..0969e4f20 100644 --- a/packages/core/src/core/Worlds/src/simple-camera.ts +++ b/packages/core/src/core/Worlds/src/simple-camera.ts @@ -198,6 +198,16 @@ export class SimpleCamera extends BaseCamera implements Updateable, Disposable { */ updateAspect = () => { if (!this.currentWorld || !this.currentWorld.renderer) return; + if (this.currentWorld.renderer?.isResizeable()) { + const currentSize = this.currentWorld.renderer.getSize(); + // A collapsed or hidden container draws nothing. + // There is no aspect to derive from it, while applying one is + // destructive in both projections: a perspective camera takes + // `aspect = 0`, i.e. a non-finite projection matrix, and an orthographic + // one gets its extents scaled to zero. + // Keep the frustum we have. + if (currentSize.width === 0 || currentSize.height === 0) return; + } if (this.three instanceof THREE.OrthographicCamera) { this.onAspectUpdated.trigger(); return;