How can I get the .obj resource after model loaded.

Software: Away3D 4.x

liuyi, Member
Posted: 14 September 2011 02:36 AM   Total Posts: 65

when the model assets loaded, trace it’s name.

trace:
assets loadedobj0
assets loadedobj1
assets loadedobj2
assets loadedobj3
assets loadedobj4
assets loadedobj5
GRWorld model loaded

But there are 5 mesh, I only want get an Mesh(the model object) and put it to scene.

How can I should do? And I have a list of .obj files need load.
I know AssetLibrary only care assets not resource, but how can I get the resource after loaded?

protected function init():void {
   Parsers
.enableAllBundled();
   
_models = new Vector.<Obj3d>();
   
_assetsLib AssetLibrary.getInstance();
   
_assetsLib.parseData(_model);
   
_assetsLib.addEventListener(LoaderEvent.RESOURCE_COMPLETEmodelLoaded);
   
_assetsLib.addEventListener(AssetEvent.ASSET_COMPLETEassetLoaded);
  
}
  
  
private function assetLoaded(e:AssetEvent):void 
  {
   trace
("assets loaded"+e.asset.name)
  
}
  
  
private function modelLoaded(e:LoaderEvent):void 
  {
   dispatchEvent
(new Event("modelLoaded"));
  
   

liuyi, Member
Posted: 14 September 2011 02:50 AM   Total Posts: 65   [ # 1 ]

shoud I new a Mesh or a ObjectContainer3D, and then put all loaded mesh to it?

   

liuyi, Member
Posted: 14 September 2011 11:05 AM   Total Posts: 65   [ # 2 ]

I have written a modelsManager class to resolve this problem.

can get model now.

like this:

var context:AssetLoaderContext = new AssetLoaderContext(true,"../assets/");
   
_modelManager ModelMangager.getInstance();
   
_modelManager.addEventListener(Event.COMPLETE,onModelsLoaded)
   
_modelManager.addFile(_model"motor");
   
_modelManager.addFile(_modelCar'car');
   
_modelManager.addFile(_terrain'terrain',null,context);
   
_modelManager.start(); 
   

liuyi, Member
Posted: 14 September 2011 11:07 AM   Total Posts: 65   [ # 3 ]

If you guys have better idea, tell me please~~
We need more talk.

   

Hector, Sr. Member
Posted: 16 November 2011 03:42 PM   Total Posts: 137   [ # 4 ]

I’m also a bit lost with AssetLibrary. If your resource has several meshes and materials, how do you get the whole resource to add it to the scene? Using namespace?

   

Avatar
Fabrice Closier, Administrator
Posted: 16 November 2011 04:58 PM   Total Posts: 1265   [ # 5 ]

Here an example of with an embeded awd2 file, same would work with all parsers/formats that we have already. If you would load external content—> loader.load(new URLRequest(url), would be the diff.

var loader:Loader3D = new Loader3D();
Loader3D.enableParser(AWD2Parser);
 
loader.addEventListener(AssetEvent.MESH_COMPLETE, onPartReady);
loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onLoadedComplete);
loader.addEventListener(LoaderEvent.LOAD_ERROR, onLoadedError);
loader.loadData(new embeddedAWDClass(), null, null, new AWD2Parser());

private function onPartReady(event:AssetEvent):void
  {
  var meshName:String = Mesh(event.asset);
  trace(“mesh part: “+meshName+” loaded”);
  }

private function onLoadedComplete(event:LoaderEvent):void
  {
  //addchilding the whole content of the awd
  _view.scene.addChild(ObjectContainer3D(event.currentTarget));
}
private function onLoadedError(e:LoaderEvent):void
  {
  trace(“ouch—>”+e.message);
  }

   

Hector, Sr. Member
Posted: 16 November 2011 05:17 PM   Total Posts: 137   [ # 6 ]

That’s what I was looking for! thanks very much smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X