I’m trying to fit the texture to the plane, someone knows how to do it, I want to do the same result as background-size: cover in CSS
I’m trying to fit the texture to the plane, someone knows how to do it, I want to do the same result as background-size: cover in CSS
Try it with this code:
texture.matrixAutoUpdate = false;
var aspect = window.innerWidth / window.innerHeight;
var imageAspect = texture.image.width / texture.image.height;
if ( aspect < imageAspect ) {
texture.matrix.setUvTransform( 0, 0, aspect / imageAspect, 1, 0, 0.5, 0.5 );
} else {
texture.matrix.setUvTransform( 0, 0, 1, imageAspect / aspect, 0, 0.5, 0.5 );
}
Live demo: Edit fiddle - JSFiddle - Code Playground
Thank you! you are a genius
4 years later and this just worked for me