load separated meshes from .awd

Software: Away3D 4.x

varDacha, Newbie
Posted: 13 June 2012 05:04 PM   Total Posts: 18

Hello,
Im a bit newbie to all this..

How can I load two meshes residing in a one .awd file, and separate them so I can later add different textures to each one of them?
For example, having a room, and a chair in that room?


Can I do something like

chair Mesh (_loader.getChildAt(1)) as Mesh

Or what would be the correct way?

Thnx

 

   

varDacha, Newbie
Posted: 13 June 2012 08:50 PM   Total Posts: 18   [ # 1 ]

Ok, I ve done it with

var chair:Mesh AssetLibrary.getAsset("chair") as Mesh

Cant do this on getAsset(“room”), but succesfuly added it to the scene referencing it as

room Mesh(ev.asset) as Mesh

Im not sure if Im doing this right, but it works.. :/
Still, any comments are wellcome..

   

Richard Olsson, Administrator
Posted: 16 June 2012 11:18 AM   Total Posts: 1192   [ # 2 ]

That’s definitely one way of doing it, although if you’re not going to use your Loader3D instance for anything except loading I suggest you do your loading through the AssetLibrary directly as well:

AssetLibrary.load(new URLRequest(‘myfile.awd’));

Loader3D is a container that you can add to the scene, similar to flash.display.Loader, but if you don’t plan on using it that way, it’s better to simply not use it at all. Internally it uses the AssetLibrary.load() by default anyway, so you might as well do that directly.

Another option that you could use to get hold of the separate assets is to listen for the AssetEvent.ASSET_COMPLETE event on your loader (Loader3D, AssetLoader or AssetLibrary, whichever you are using). If you care only about meshes specifically, you can listen for AssetEvent.MESH_COMPLETE.

The event object will contain a reference to the relevant asset (AssetEvent.asset) which will be of type IAsset, but which can be cast to one of the concrete classes (e.g. Mesh, Geometry et c) depending on the value of it’s assetType property (and in part also the event name, since if you’re listening for MESH_COMPLETE you can be sure that you only get meshes.)

   

varDacha, Newbie
Posted: 16 June 2012 04:13 PM   Total Posts: 18   [ # 3 ]

Thanx,
Im still doing something wrong..

I cant get second mesh from .awd -“room”

private function load(url String) : void {    
   AssetLibrary
.enableParser(AWD2Parser);
   
AssetLibrary.addEventListener(AssetEvent.MESH_COMPLETEonAssetComplete);
   
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
AssetLibrary.load(new URLRequest(url));
  
}
  
  
  
private function onAssetComplete(ev:AssetEvent) : void{
    
   
if (ev.asset.assetType == AssetType.MESH{   
    
    mainContainer 
= new ObjectContainer3D();
    
    
trace(ev.asset.name);// traces - room, chair, floor..
    
    
image = new ber();// from Flash lib
    
    
var texMat:TextureMaterial = new TextureMaterial(new BitmapTexture(image));
    
    var 
chair:Mesh AssetLibrary.getAsset("chair") as Mesh;
    
chair.material texMat;
    
chair.material.lightPicker lightPicker;
    
    
/*var room:Mesh = AssetLibrary.getAsset("room") as Mesh;
    room.material = new ColorMaterial(0xCCCCCC, 1);   
    room.material.lightPicker = lightPicker;
    
    
    mainContainer.addChild(room);*/

    
mainContainer.addChild(chair);
    
   
}
  
  }
  
  
  
private function onResourceComplete(ev LoaderEvent) : void{everything is ok here with setting engine and adding to view....

When I uncomment the “room” code I get nothing..
Otherwise everything is ok.
How to get the “room” mesh, and those other meshes from awd, also separated??

 

 

   

Richard Olsson, Administrator
Posted: 16 June 2012 04:20 PM   Total Posts: 1192   [ # 4 ]

You already have the room mesh in that code. The ev.asset object is your mesh, so when ev.asset.name == ‘room’, ev.asset is the mesh you’re after.

   

varDacha, Newbie
Posted: 16 June 2012 04:55 PM   Total Posts: 18   [ # 5 ]

Ok.. and then I do

switch(ev.asset.name){
case ‘room’:
settingRoom();
break;
...
...
...
}

..right?

Sorry for being a rookie pest, but I would love to learn this.. :/

   

Richard Olsson, Administrator
Posted: 16 June 2012 06:31 PM   Total Posts: 1192   [ # 6 ]

Yes, you can do that. Although you’ll probably want to pass in the actual room mesh to your “settingRoom()” function, like so:

settingRoom(ev.asset as Mesh);

   

varDacha, Newbie
Posted: 16 June 2012 06:54 PM   Total Posts: 18   [ # 7 ]

Many thanx Mr. Olsson!
Thank You for Your time and patience, and may the code be with You! smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X