TextureMaterial and URLRequest

Software: Away3D 4.x

Mael, Newbie
Posted: 18 June 2012 08:37 PM   Total Posts: 5

Hi !
I’m looking for a way to delete a material from a mesh and replace it with a new one which uses an external texture (.png) called by an URLRequest. How could I do that? BitmapFileMaterial is not supported any more…
thxs

   

Avatar
Austen, Newbie
Posted: 19 June 2012 03:17 AM   Total Posts: 21   [ # 1 ]

you need to use TextureMaterial now smile

   

Mael, Newbie
Posted: 19 June 2012 12:55 PM   Total Posts: 5   [ # 2 ]

I forgot : sorry for my english.
I know ( I wrote it in title) But I never use TextureMaterial or bitmapdata. There are some exemples on the forum but all use embeded textures…
I just asked for an exemple.

I tried that, is it the right way to do? :

function onModelLoaded(LoaderEvent):void
{
 tete
.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonModelLoaded);

 var 
i:int;
 var 
mesh:Mesh;
 var 
numChil:uint tete.numChildren;
 var 
texMat:TextureMaterial;

 for (
0numChil; ++i)
 
{
  mesh 
Mesh(tete.getChildAt(i));
  
mesh.material.dispose();

  var 
bmd:BitmapData = new BitmapData(128,128);
  var 
ldr:Loader = new Loader();

  
ldr.contentLoaderInfo.addEventListener(Event.COMPLETEonComplete);
  
ldr.load(new URLRequest("texture.png"));

  function 
onComplete(event:Event):void
  {
   bmd
.draw(ldr);
   var 
texMat = new TextureMaterial(new BitmapTexture(bmd));
   
mesh.material texMat;
   
_container.addChild(tete);
  
}

 }

   

Avatar
Austen, Newbie
Posted: 19 June 2012 06:13 PM   Total Posts: 21   [ # 3 ]

i’m not a texture expert, but what error does it throw exactly?

i give you the piece of code i use to load my textures from an embedded tileset:

[Embed(source="/../assets/mat/tileset.jpg")private var TileSet:Class;

var 
bmd:BitmapData = new TileSet().bitmapData;
 var 
tba:ByteArray bmd.getPixels(new Rectangle(0,0,64,64) );
 
tba.position 0;
 var 
tbmd:BitmapData = new BitmapData(64,64,false,0);
 
tbmd.setPixels(new Rectangle(0,0,64,64),tba);
 
mat = new TextureMaterial(new BitmapTexture(tbmd));
mesh.material mat
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X