Need help with image camera stretching

Hi.
I want to use user’s device camera as background and I want to keep the proportions of camera independent of scene dimension. As example if the scene is in portrait mode, I have to scale down a little bit the background, so the image to fit the scene bondaries, same if the scene is landscape.
I tried something here, I think I’m close
https://playground.babylonjs.com/#2DZ2J4#1
Thank you

So you need to also account for the screen aspect in the computation:

https://playground.babylonjs.com/#2DZ2J4#4

I leave you the offset computation to also ensure it would always be centered.

1 Like

Hi @sebavan this is exactly what I was looking for.
One small thing, it is possiblle if I want to center the image?

Yup you can play with uOffset and vOffset.

The goal is to find how much to move which should be half one minus the video width on canvas width or the same for the height i would guess :slight_smile:

2 Likes

Thank you @sebavan.
Here is https://playground.babylonjs.com/#2DZ2J4#7, if somebody will search for something similar

1 Like

could come in handy eventually.