Assetlibrary - naming of .obj files.

Software: Away3D 4.x

Mavnus, Newbie
Posted: 28 June 2012 09:03 AM   Total Posts: 2

Hi ,
I´m new to Away3d and trying to load some .obj assets with AssetLibrary.as.

But i cant figure out, how to differentiate between multiple .obj assets in the Asset_Complete callback function. As far as i can see, it is not possible to name the meshes from the .obj´s.

Currently i´m doing this :

assetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE, assetComplete);
assetLibrary.loadData(new puckMesh(), assetLibraryContext,“someNS1”);
assetLibrary.loadData(new puckMesh(), assetLibraryContext,“someNS2”);

then in the callback

protected function assetComplete(event:AssetEvent):void {
switch(event.asset.assetNamespace)
{
  case “someNS1” : trace(“someNS1”);
  case “someNS2” : trace(“someNS2”);
}
}

What is the right way to handle this ?

Thanks in advance smile

   

Richard Olsson, Administrator
Posted: 29 June 2012 08:31 AM   Total Posts: 1192   [ # 1 ]

What do you mean it is not possible to name the meshes from the OBJ files? If the names are in the files, the name of the returned asset (event.asset.name) should be the one from the file.

If all you want to do is differentiate the files at load time, you can use the AssetLoaderToken returned by the loadData() function and set your event listeners on that instead of on the asset library. That way you can have different functions be called depending on what file (or rather, load operation) the events are being dispatched from.

If you have identical names in many files (or rather, many loading operations) like you have in your example where you load the same file twice, then namespaces is probably the right way to go. However, you should probably not be loading the same file twice in the first place.

You can do a lot of things with the loading framework. You can use tokens, separate namespaces, separate libraries, listen for type-specific events (e.g. MESH_COMPLETE), iterate over assets loaded into the library, and more. Your exact situations dictates which approach is best, so if you explain your situation a little more thoroughly I might be able to recommend the best way. No code is needed, just explain what it is exactly that you want to do, how many files you have, what they contain et c.

   

Mavnus, Newbie
Posted: 29 June 2012 08:45 AM   Total Posts: 2   [ # 2 ]

Hi Richard,
thanks for your reply!

All i need is to differentiate files at load time. I´m loading a puck, table, stick etc. and want to run different methods as the individual files (and their dependencies) are entirely parsed.

Listening on tokens sounds like exactly the solution I am looking for. Oh and I´m not actually loading the same files twice. That was just a horrible example smile

I think my obj files are missing o-tags and away-3d default to names like “obj0”, “obj1” etc. which got my confused in the first place.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X