strange Result When trying to set Textures Size to power of 2

Software: Away3D 4.x

ArmanBM, Newbie
Posted: 22 December 2012 01:44 PM   Total Posts: 5

Hello every one…
im new to Away3D and i found it very powerful and lovly smile.

now i have a problem… i have a bunch of Textures with different size, when i import them into my project Away3D throw error.
so i changed the setBitmap function in Away3d engine . if a texture is not power of 2 then i create a new bitmap and draw old one into this new one:

if (!TextureUtils.isBitmapDataValid(value)){
var trueSize:Point = new Point()

newValue:BitmapData = new BitmapData(trueSize.,  trueSize.true ,0xFFFF00);
newValue.scroll((trueSize.value.width)/2, (trueSize.value.height)/2);
value newValue;

now the problem is textures dose not place in correct position of model.


please some one show me the correct way of doing this…

tanks a lot….



Fabrice Closier, Administrator
Posted: 22 December 2012 06:58 PM   Total Posts: 1265   [ # 1 ]

That’s because you do not draw with a matrix 2D having the correct scale factors set.


Fabrice Closier, Administrator
Posted: 22 December 2012 07:05 PM   Total Posts: 1265   [ # 2 ]

Here an example doing what you need.

public static function resizeMap(origBmd:BitmapData, dispose:Boolean = true):BitmapData
  var nw:uint = origBmd.width;
  var nh:uint = origBmd.height;
  if(!TextureUtils.isPowerOfTwo(nw)) nw = TextureUtils.getBestPowerOf2(nw);
  if(!TextureUtils.isPowerOfTwo(nh)) nh = TextureUtils.getBestPowerOf2(nh);
  if(nw == origBmd.width && nh == origBmd.height)
  return origBmd;
  var bmd:BitmapData = new BitmapData(nw, nh, origBmd.transparent, origBmd.transparent? 0x00FFFFFF : 0x000000);
  var w:Number = nw/origBmd.width;
  var h:Number = nh/origBmd.height;
  var t:Matrix = new Matrix();
  t.scale(w, h);
  bmd.draw(origBmd, t, null, “normal”, null, true);
  if(dispose) origBmd.dispose();
  return bmd;



ArmanBM, Newbie
Posted: 26 December 2012 09:21 AM   Total Posts: 5   [ # 3 ]

It Really Works!
Tanx Mr Fabrice.
Yo Are Really Smart In Helping Others smile



Away3D Forum

Member Login