-
-
Notifications
You must be signed in to change notification settings - Fork 36.2k
Closed as not planned
Closed as not planned
Copy link
Milestone
Description
Description
As the title says.
I'm happy to work on a PR. I would implement resize logic as described in https://threejs.org/manual/#en/responsive in order to have a consistent approach between the manual and examples section:
function resizeRendererToDisplaySize(renderer) {
const canvas = renderer.domElement;
const pixelRatio = window.devicePixelRatio;
const width = Math.floor( canvas.clientWidth * pixelRatio );
const height = Math.floor( canvas.clientHeight * pixelRatio );
const needResize = canvas.width !== width || canvas.height !== height;
if (needResize) {
renderer.setSize(width, height, false);
}
return needResize;
}What do you think?
Reproduction steps
- Open https://threejs.org/examples/?q=car#webgl_materials_car
- Zoom out the page
- Observe canvas width and height from the inspector
Code
I guess this is related to window.devicePixelRatio not being used in the resize logic.
function init() {
const container = document.getElementById( 'container' );
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setAnimationLoop( animate );
container.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize );
// ...
}
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}I picked the car example in this issue, but I think most of the examples are based on the same resize logic.
Live example
https://threejs.org/examples/?q=car#webgl_materials_car
Screenshots
2025-09-25.09-59-35.trimmed.mp4
Version
r180
Device
No response
Browser
No response
OS
No response
Metadata
Metadata
Assignees
Labels
No labels