ThreeJS Setting the Right Aspect Ratio for the Camera

Quick note for myself and anyone who will ever use this…

if you are working with an abnormal size canvas. Just do this to set the size of the renderer to be correct with the aspect ratio:

let rect = this.renderer.domElement.getBoundingClientRect();
		camera.aspect = rect.width / rect.height;
		camera.updateProjectionMatrix();
		renderer.setSize( rect.width, rect.height );

That’s it that’s all

Leave a Reply

Your email address will not be published. Required fields are marked *