Loading OBJ model at runtime as opposed to embedding it

Software: Away3D 4.x

Avatar
ddddesigns, Jr. Member
Posted: 14 September 2011 11:02 PM   Total Posts: 37

Not sure if it is possible to load an OBJ at runtime or not.  Anyone know?  If so, could you please provide an example on how to load an OBJ at runtime?

   

EFFalcon, Jr. Member
Posted: 14 September 2011 11:31 PM   Total Posts: 44   [ # 1 ]

Certainly is, i’m fairly sure there is an example that does it?

one of the awayphysics examples does it.
BvhTriangleMeshCarTest.as

but the basics are:

import away3d.loaders.parsers.OBJParser
var _loader Loader3D = new Loader3D();
_loader.load(new URLRequest('../assets/scene.obj'), new OBJParser());
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonSceneResourceComplete); 
private function onSceneResourceComplete(event LoaderEvent) : void {
var container ObjectContainer3D ObjectContainer3D(event.target);
_view.scene.addChild(container);
   

Avatar
ddddesigns, Jr. Member
Posted: 14 September 2011 11:37 PM   Total Posts: 37   [ # 2 ]

Awesome!  Thanks. I am only able to get a small fraction of the examples to compile for me.  I was looking at the OBJLoader example which embeds.  Thanks so much.  This helps out a lot!

   

julespong, Member
Posted: 15 September 2011 01:26 AM   Total Posts: 53   [ # 3 ]

You’re gonna want to listen for the AssetEvent.ASSET_COMPLETE event as well. That fires when the individual meshes that comprise the loaded OBJ are processed.

   

Mr Margaret Scratcher, Sr. Member
Posted: 15 September 2011 04:03 AM   Total Posts: 344   [ # 4 ]
private function LoadEmporiumOBJ() : void
  
//Load the Virtual Emporium .OBJ
  
{
   Loader3D
.enableParser(OBJParser);
   
OBJloader = new Loader3D();
   
OBJloader.addEventListener(LoaderEvent.RESOURCE_COMPLETEScalePosOBJ);
   
   
OBJloader.load(new URLRequest("emporium/emporium.obj"));
   
view.scene.addChild(OBJloader); 
  
}

  
private function ScalePosOBJ(event LoaderEvent) : void
  
//rescale the emporium .OBJ
  
{
   
var mesh Mesh;
   for (var 
int 0OBJloader.numChildren; ++i{
    mesh 
Mesh(OBJloader.getChildAt(i));
    
mesh.geometry.scale(100);
    
//mesh.material = _material
   
}
  } 

From a project I’m working on…


(I pretty much nabbed it from the subsurface scattering example, I think)

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X