Loading multiple OBJ models with AssetLibrary

Software: Away3D 4.x

cyrix, Newbie
Posted: 28 April 2014 05:51 AM   Total Posts: 9

I am getting very frustrated with the lack of documentation on some of Away3D’s key features. There is no proper tutorial for how to load models. I can manage to load one embedded OBJ model with the AssetLibrary and display it, but if I load additional models the first one disappears.

Loading models like this (this is stripped code and might have typos, the full code loads the first model correctly):

[Embed(source="/../models/mymodel.obj",mimeType="application/octet-stream")]
private var mymodel:Class; 
AssetLibrary.loadData(new mymodel()); 
private function onAssetComplete(event:AssetEvent):void {
    mesh 
event.asset as Mesh;
    
mesh.geometry.scale(100);
    
mesh.material material;
    
    
scene.addChild(mesh);

 


What’s the solution here? Searching suggests it might be related to the AssetLoaderContext but there’s no documentation on how to use AssetLoaderContext.

   

John Brookes, Moderator
Posted: 28 April 2014 05:13 PM   Total Posts: 732   [ # 1 ]

You can use the nameSpace parameter of the load or loadData method of AssetLibrary.

eg
Lets say you have two awd files and in both of them you have a mesh called “MyMesh”.
Away3D needs to know which one you mean. Thats what “Namespace” is for.

Just for ease showing both as embedded awd files

AssetLibrary.loadData(MyEmbeddedAwd_A, null, “A_Unique_Name_For_This_AWD”);
AssetLibrary.loadData(MyEmbeddedAwd_B, null, “A_Different_Name”);

later you can get the two different “Mymesh” meshes by

var meshA:Mesh = Mesh(AssetLibrary.getAsset(“Mymesh”, “A_Unique_Name_For_This_AWD”));
var meshB:Mesh = Mesh(AssetLibrary.getAsset(“Mymesh”, “A_Different_Name”));

   

cyrix, Newbie
Posted: 29 April 2014 09:23 PM   Total Posts: 9   [ # 2 ]

How could any serious programmer name an argument “ns” and not write a comment for its purpose?

Anyway, thank you for the suggestion; I passed a unique name to the “ns” argument for each model, but loading the second model still causes the first to disappear.

I’m thinking now it’s a problem with my event flow; I’m probably starting to load the second model before the first model is loading and since it’s a static class, never successfully loading the first model. I’ll need to queue them.

   

bob56, Newbie
Posted: 13 July 2014 05:47 PM   Total Posts: 2   [ # 3 ]

Hi cyrix,

I have an almost identical situation to yours in that when i try to load multiple instances of a class (in my case four) for some reason only one item is ever displayed. I have been pulling my hair out for days and any guidance on this would be greatly apreciated.

I have a preloader that loads the relevant asset initially using AssetLibrary. In the Class from which i want to generate 4 instances (by calling that class with new operator),  i retrieve the model in the constructor using the unique name based on the ns (namespace), loop through with the iterator and assign the mesh, animator, geometry etc Then i add the mesh using addChild. Note i have no eventListeners in this class, should i be listening for some kind of completion?

Any guidance would help.

Thanks.

   

cyrix, Newbie
Posted: 13 July 2014 09:02 PM   Total Posts: 9   [ # 4 ]

You have to use the AssetEvent.ASSET_COMPLETE event to track loading of each asset and load them one at a time. I ended up writing my own AssetLoader to deal with this nonsense.

I hope you are not using Away3D for a professional project. From my experience building a mobile game from scratch and publishing it to the app store, Away3D is a garbage engine not suitable for anything more than basic tech demos. The documentation, usability, and performance of Away3D are so poor it simply isn’t viable for serious work. The lighting engine in particular is so slow we had to include an option to turn off lighting for devices that weren’t made in the last 12 months. Key features that existed in Away3D 3.x were inexplicably removed for Away3D 4. At best the engine is going nowhere, and more likely it’s moving backwards.

   

bob56, Newbie
Posted: 15 July 2014 04:00 PM   Total Posts: 2   [ # 5 ]

Regarding AssetEvent.ASSET_COMPLETE - I was under the assumption that once i loaded all my objects in the preloader using AssetLibrary.load/loadData i could then access them in relevant classes using the AssetLibrary.getAsset() method or AssetLibrary.createIterator, so that i could then assign textures, lighting etc This i can do. However the ASSET_COMPLETE only executes in the preloader when the load/loadData is called, getAsset does not seem to trigger any event at all, any meaning none! You mentioned that i need to wait until the first asset is loaded before the second and so forth but this does not seem to be possible in my case unless im missing something.
Describing the original issue, all i am trying to do is loop a certain amount of times and retrieve 4 instances of an ObjectContainer3D class and display on screen. However only one item seems to be visible. Debugging reveals the 4 entities exist.

Regarding Development -  i am attempting to publish a game eventually but its just one hurdle after the other. I feel your frustration as im going through the same pain. Lack of examples, lack/quality of documentation has been a common theme throughout my Adobe/Away 3d experience generally. When will someone take notice. Arrgghh.

   
   
‹‹ ---

X

Away3D Forum

Member Login

Username

Password

Remember_me



X