From 5ca64603623a1c6ab75a3edac5724b6938914459 Mon Sep 17 00:00:00 2001 From: Aimad Harilla Date: Wed, 22 Dec 2021 17:13:18 +0100 Subject: [PATCH] Update 3D view in case of canvas size changed --- src/Scene.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Scene.ts b/src/Scene.ts index 73a7958..f8c22cb 100644 --- a/src/Scene.ts +++ b/src/Scene.ts @@ -126,6 +126,10 @@ class Renderer { resize () { const { width, height } = this.el.getBoundingClientRect(); + const canvas = this.renderer.domElement; + // do not resize in case of canvas size didn't change + if (canvas.width === width && canvas.height === height) return; + this.renderer.setSize(width, height); this.camera.aspect = width / height; @@ -188,6 +192,8 @@ class Renderer { private animate () { this.animationID = window.requestAnimationFrame(this.animate.bind(this)); + this.resize(); + for (const block of this.scene.blocks) { if (block.beforeRenderHook !== null) { block.beforeRenderHook(