Hi,
How do i setup for camera to prevent from objects deformation on screen size changes?
I tried to set a orthographic camera (did not solve the issue)
all drei cameras as responsive by default, you donât need to do anything. nothing should deform just because you film orthographic. but if that wasnât the case could you make a quick repro?
Hi,
What i need to do is make object like image or sprite remain itâs aspect ratio regardless of screen size changes.
for example, i tried to set fixed aspect ratio but it didnât work.
Thank you, this is quite useful. But it did not solve my issue.
my plane geometry aspect ratio is still effected by screen size. i guess i misused word âresponsiveâ, what i need is to prevent the image from distorted. Ideally this item should be âresponsiveâ and yet undistorted, otherwise this image wonât look good on mobile device.
I assume there are a couple of ways, maybe use OrthographicCamera, or maybe update the aspect ratio on window resize. but none of them really worked
export function Items() {
const ref = useRef()
const texture = useLoader(TextureLoader, 'https://dummyimage.com/600x400/000/fff')
// Load the image using THREE.TextureLoader
const aspect = texture.image.width / texture.image.height
let scaleX = 1
let scaleY = 1
const desiredAspect = 600 / 400
if (aspect > desiredAspect) {
// Texture is wider than the desired aspect ratio
scaleY = (1 / aspect) * desiredAspect
} else {
// Texture is taller than or equal to the desired aspect ratio
scaleX = aspect / desiredAspect
}
return (
<group scale={[scaleX, scaleY, 1]}>
<mesh ref={ref}>
<planeGeometry />
<meshBasicMaterial map={texture} side={DoubleSide} />
</mesh>
</group>
)
}
i donât understand what you do with these cameras. it stretches because you set them up manually which would involve some math. but this is what these cameras would normally do automatically, thatâs why they exist, to remove that burden.
you can of course use plain three cameras, or drei cameras with the manual prop, or overwrite left/right/top/bottom, but then you need to know how to calculate aspect ratio.
the clone demo i linked above uses orthographic camera, and drei/bounds to adapt the model to screen size, it doesnât stretch.