Reputation: 3020
I have a PNG image as a texture on a Three.js planeGeometry, and it is stretched to fit the geometry that is larger than the original image size. Is there a way to automatically size the geometry to the image texture - or at least allow the image not to be stretched on the oversized geometry?
One solution would be to save the sizes of the images when loaded and use these measurements to create the geometries, but I wondered if there was a more direct or efficient solution than this? Thanks!
Upvotes: 1
Views: 2163
Reputation: 19592
The trick is to create the geometry 1x1 dimensions and then scale:
var geometry = new THREE.PlaneGeometry( 1, 1 );
var mesh = new THREE.Mesh( geometry, material );
mesh.scale.x = image.width;
mesh.scale.y = image.height;
Upvotes: 4