Load textures (run time)

Software: Away3D 4.x

maricate, Jr. Member
Posted: 09 May 2013 06:51 PM   Total Posts: 36

Im trying to follow this method…

http://www.allforthecode.co.uk/aftc/forum/user/modules/forum/article.php?index=5&subindex=5&aid=320


Using LoaderMax class…

var preloader = new LoaderMax( {
          name:“test”,
          maxConnections:5,
          auditSize:true,
          onComplete:loadComplete
        } );


preloader.append(new ImageLoader(“imagens/superficie_difuse_grama.jpg”,{name:“textura”,estimatedBytes:(221*1024)}));
preloader.load();


So i get this:
TypeError: Error #1034: coercion fail: can not convert com.greensock.events :: LoaderEvent @ 1ab7f159 in away3d.events.LoaderEvent.

I imagine that there is incompatibility between the latest versions of LoaderMax and Away3D ... perhaps using the same function name.
I build this:

var imagem:Texture2DBase = new BitmapTexture(imagemLoader.rawContent.bitmapData);

var superficieMaterial = new TextureMaterial(Cast.bitmapTexture(imagem),true,false,true);

So, I must put a image inside imagemLoader variable.
How else could I load an image into the variable imagemLoader?
I tried the method of standard loader but did not work.
As I am not accustomed to build using .as files. Them, is a challenge to adapt some parts of the code.

   

maricate, Jr. Member
Posted: 09 May 2013 07:47 PM   Total Posts: 36   [ # 1 ]

Here the solution to load images2texture runtime


var imageLoader:Loader = new Loader();

var _imageURL:URLRequest = new URLRequest(“image.jpg”);

_imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, _onLoaderComplete);
function _onLoaderComplete(e:Event){

var _imageContent=Bitmap(_imageLoader.content);

var _bmpData:BitmapData = new BitmapData(_imageContent.width, imageContent.height, true, 0x000000);

      _bmpData.draw(_imageContent);

    var _image:Texture2DBase = new BitmapTexture(_bmpData);
}

So just put the new loaded image on a TextureMaterial…

var _myMaterial = new TextureMaterial(Cast.bitmapTexture(_image));

The image Width and height must be power of 2 and cannot exceed 2048… 256… 512… 1024… 2048

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X