🔹set canvas size

three.jsrenderer ⟩ set canvas size

const canvas = renderer.domElement;

// calculate the real "resolution" size of the canvas
const pixelRatio = window.devicePixelRatio;
const width  = canvas.clientWidth  * pixelRatio | 0;
const height = canvas.clientHeight * pixelRatio | 0;

const needResize = 
    canvas.width  !== width || 
    canvas.height !== height;

if (needResize) {
    // set canvas "resolution" size
    // - false: without altering canvas's CSS settings.
    renderer.setSize(width, height, false);
}

Last updated