Keeping the ratio of a Texture and fit it into a plane

Software: Away3D 4.x

RIPI, Jr. Member
Posted: 11 July 2012 09:36 AM   Total Posts: 33

hey guys!
I used mat jansons great tutorial to set up a plane which fits perfectly into the viewport.. but i have a problem with that.
The ratio of my view is never the same as the bitmap that i wanted to draw on the plane. I’m searching for a intelligent way to fill the whole plane with my Bitmap without changing the ratio of it.
Is there a method to achieve this result or has anyone a hint for this?

i’ve attached an image to illustrate the idea better!

Thank you very very much!

 

   

Richard Olsson, Administrator
Posted: 11 July 2012 11:23 AM   Total Posts: 1192   [ # 1 ]

This doesn’t seem like a 3D specific issue. The general case to solve this is to just calculate the scaleX and scaleY, and use the larger of the two for both:

var scaleX Number viewWidth imageWidth;
var 
scaleY Number viewHeight imageHeight;
var 
scale Math.max(scaleXscaleY);

myMesh.scaleX scale;
myMesh.scaleY scale

Depending on your set up, something like that should work.

   

RIPI, Jr. Member
Posted: 11 July 2012 11:46 AM   Total Posts: 33   [ # 2 ]

Thank you – that would imply to use the textures ratio also for the plane, right? the math behind this issue isn’t the main problem – because fitting an image the described way is a well known practice.. I was looking for a way to manipulate the texture of a plane which has a given size, just like in the attached file, like, handling the problem via uv’s or sth like that… or could this be done by simply scaling it the way you supposed?

   

Richard Olsson, Administrator
Posted: 11 July 2012 01:11 PM   Total Posts: 1192   [ # 3 ]

You can scale the plane, or you scale the UVs (using SubMesh.scaleU and scaleV) but if you scale the UVs you’ll have to offset them as well. If I were you, and the plane covers the entire view, I would just scale the plane.

   

RIPI, Jr. Member
Posted: 11 July 2012 01:19 PM   Total Posts: 33   [ # 4 ]

i think that’s the way to go, thank you! wink

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X