Trying to follow Example - strange error importing OBJ file

Software: Away3D 4.x

ollie, Newbie
Posted: 25 February 2012 01:00 AM   Total Posts: 3

Hi,

I’m new to Away3D (and seem to have started to trying to use it at the start of a new version when there’s barely any tutorials/help around) so I opened up one of the example files and tried to import a simple model using it (Basic_LoadOBJ.as on the git repository).

I’m trying to follow it through whilst removing some of the extra functionality (mouse movement and texturing mainly) as I just want to get something imported for now, but have come across a weird error.

I’m getting this:

[Fault] exception, information=Error: Error #2032: Stream Error. URL: file:///C|/Users/Ollie/Documents/Flash Projects/Test/bin/hex.mtl

But the file I tried to embed is hex.obj - nowhere have I told it that there’s a file called hex.mtl (because there isn’t) and I don’t know why it’s looking for it in the bin folder.

There’s a chance I’ve taken out something that was needed so here’s a stripped down version of my class in case that helps:

private function init(e:Event):void {
   removeEventListener
(Event.ADDED_TO_STAGEinit);
   
   
initEngine();
   
initObjects();
   
   
addEventListener(Event.ENTER_FRAMEupdate);
  
}
  
  
private function initEngine():void {
   stage
.align StageAlign.TOP_LEFT;
   
   
scene = new Scene3D;
   
camera = new Camera3D;
   
view = new View3D;
   
view.antiAlias 4;
   
view.scene scene;
   
view.camera camera;
   
   
//cameraControl = new HoverController(camera, null, 45, 10, 800);
   
  
}
  
  
private function initObjects():void {
   Parsers
.enableAllBundled();
   
   
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
AssetLibrary.loadData(new HexModel);
  
}
  
  
private function onAssetComplete(e:AssetEvent):void {
   
if (e.asset.assetType == AssetType.MESH{
    hex 
e.asset as Mesh;
    
hex.geometry.scale(100);
    
hex.= -50;
    
hex.material = new ColorMaterial(0x8080FF1);
    
    
scene.addChild(hex);
   
}
  }
  
  
  
private function update(e:Event):void {
   trace
("update");
   
//view.render();
  

Any help would be greatly appreciated, I don’t understand at all why it’s looking for a .mtl file

Ollie

   

ollie, Newbie
Posted: 25 February 2012 01:49 AM   Total Posts: 3   [ # 1 ]

Ok, this ended up being my fault. I didn’t notice that hex.mtl was generated with the hex.obj file. I had to manually add hex.mtl to the bin folder for it to work. Seems a bit weird but it’s not the end of the world I guess.

   

Avatar
Matse, Sr. Member
Posted: 25 February 2012 10:02 AM   Total Posts: 149   [ # 2 ]

Hi Ollie,

If you don’t want to load those materials and just apply your own in your program, you can use AssetLoaderContext :

private function initObjects():void {
   Parsers
.enableAllBundled();
   
   
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   var 
context:AssetLoaderContext = new AssetLoaderContext(false);
   
AssetLibrary.loadData(new HexModelcontext);
  
   

ollie, Newbie
Posted: 25 February 2012 03:55 PM   Total Posts: 3   [ # 3 ]

Oh cool, thanks for that, will give it a go. Will UV maps still work if I load the texture like that? (sorry, new to 3D)

   

Avatar
Matse, Sr. Member
Posted: 25 February 2012 04:16 PM   Total Posts: 149   [ # 4 ]

Yup, UV coordinates are linked to the Mesh, not to a Material. The AssetLoaderContext here just tells Away3D that you don’t want it to try loading dependencies that it might find in your OBJ file (meaning that you want to handle materials and textures yourself, in your code).

I always load like that as materials are expensive performance-wise so I want to keep their number to a minimum and share/re-use them whenever I can.

   
   
‹‹ VideoMaterial?

X

Away3D Forum

Member Login

Username

Password

Remember_me



X