How could I resize mesh width and height, say simple box (or loaded gltf mesh), according to the texture resolution?
So this is the point: The user uploads his own texture, the texture is applied to the box and the box width and height are changed to the aspect ratio of the texture.
I know already how to get the texture height and width but I am not sure how would I convert that resolution so that I can change the box mesh width and height. Any ideas?
Any help would be appreciated
Thank you in advance!
You can calculate the ratio and then apply it as a box scale, something like:
const boxSize = 1.0; // This can be any number
const ratio = texture.height / texture.width;
object.scale.set(boxSize, boxSize * ratio, 1.0) // x - width; y - height; z - you can just as well ignore it
Since size in 3D is relative to the camera transformation and perspective, using texture resolution values won’t help much, besides calculating this ratio (if you’d want the textured box to take up the entire screen, this may help though.)
Thank you for taking the time to explain this. I think I got it to work