Can someone help understand .OBJ loading?

Software: Away3D 4.x

Avatar
Huck, Jr. Member
Posted: 10 February 2012 12:15 AM   Total Posts: 45

HI Guys,

im having a few issues loading with the OBJ file format and i jsut want to make sure if im not missing anything.

Basically i build in blender a multi object model and i export as .obj. So, suppose i have objects named “Sphere1” and “Cylinder1” in the same obj file.

Now, when i load the file in away3d, i would expect to have either 2 meshes with the names above, ot at least 1 mesh with 2 subgeometries with naems above. sadly, this is not what im getting.

when i export “Objects as OBJ objects” in blender, i get only one mesh with the name “obj0” (it ignores the names given by blender). If i export using “Objects as OBJ groups”, then i get my 2 meshes in the loader, but again with the names “obj0” and “obj1” instead of prop[er blender assigned names.

is it the parser that needs fixing or am i not understanding the original intent?

thanks!

   

Avatar
Matse, Sr. Member
Posted: 10 February 2012 10:16 AM   Total Posts: 149   [ # 1 ]

Hi Huck,

I haven’t been using OBJ lately but I did when I started away3D4 back in september and I remember it was like this already. I believe it comes from the parser, not sure how easy or hard it would be to fix.

So far I’m sticking with one file per mesh and I use the namespace to automatically rename my assets so I can access them easily.

For example I load like this :

AssetLibrary.loadData(COLUMN_1context"scenery::column_1"); 

and here’s what I do when the AssetLibrary dispatches the AssetEvent.ASSET_COMPLETE event :

protected function onAssetComplete($evt:AssetEvent):void
  {
   
var name:String $evt.asset.name;
   var nameSpace:
String $evt.asset.assetNamespace;
   var 
type:String $evt.asset.assetType;
   
   var 
msg:String "Asset loaded TYPE=" type " NAME=" name
        
" NAMESPACE=" + nameSpace;
   
log(msg);
   
   
AssetLibrary.removeAsset($evt.assetfalse);
   
   var array:Array = nameSpace.
split("::");
   if (array.
length 1{
    
switch(type{
     
case AssetType.SKELETON :
      
$evt.asset.name "skeleton";
      break;
      
     case 
AssetType.MESH :
      
$evt.asset.name array[1];
      break;
      
     case 
AssetType.ANIMATION :
      
$evt.asset.name array[1];
      break;
      
     default:
      return;
    
}
    $evt
.asset.resetAssetPath($evt.asset.namearray[0]);
   
else {
    $evt
.asset.resetAssetPath(namearray[0]);
   
}
   
   AssetLibrary
.addAsset($evt.asset);
  

then I can retrieve my column mesh simply :

var mesh:Mesh AssetLibrary.getAsset("column_1""scenery") as Mesh

 

 

   

Avatar
theMightyAtom, Sr. Member
Posted: 10 February 2012 12:45 PM   Total Posts: 669   [ # 2 ]

The parser needs a fix, and several people have already done it.

I have added an extra class, OBJParserNamed.as, which does exactly what your looking for, i.e. retain mesh names.
This is a direct replacement for the OBJParser.as, I just renamed it after accidentally over writing it when updating.

I never use the AssetLoader (had too many freaky bugs with it in the early days, it might be better now), I use Loader3D and manage my own assets.

File should be attached,

Enjoy!


Btw, 3DS files are smaller, if you have the opportunity to use them

 

File Attachments
OBJParserNamed.as  (File Size: 23KB - Downloads: 402)
   

Avatar
Huck, Jr. Member
Posted: 10 February 2012 02:14 PM   Total Posts: 45   [ # 3 ]

Thanks Guys,


yeah, that’s what i needed to hear that it was indeed a bug or a design flaw in the objparser.as.

I’ve created a fork of away3d on github where i will fix the parser bugs among others and propose pull requests by the devs. Thanks for the code mightyAtom, i will use it as my baseline fix and if you dont mind put it in my fork. hopefully it will end up in the final away3d4 someday.

thanks!

 

   

Avatar
Huck, Jr. Member
Posted: 11 February 2012 03:12 AM   Total Posts: 45   [ # 4 ]

Hi Guys,

i went ahead and fixed the OBJLoader and published the changes on my fork. you can get the file code here. changes are minimal and it fies the loading for multiple objects into file and it now uses proper names from the file for meshes.

OBJLoader.as

I will submit the patch to the dev team so hopefull it will make it into away3d 4.

smile

 

   

frukc, Newbie
Posted: 13 February 2012 10:41 PM   Total Posts: 8   [ # 5 ]

Hi,
i wasn’t happy about naming policy of meshes - (obj0, ob1, obj2, obj3…) and about the way materials where handled (one material for each mesh, and with same ID as mesh - obj<X>) too. so i made changes in OBJParser. now meshes and materials keeps their original names and just real number of materials are generated. keeping it possible to change one material to change look of all corresponding meshes.
to be able to find mesh by it’s name, i appended Container3D class with ‘getChildByName’ method.
i guess, Hulk did something similar.
if someone would like to use ‘fixed’ version of OBJParser, it can be found there http://www.frukc.com/away3d/

 

   

Stephen Hopkins, Sr. Member
Posted: 26 February 2012 11:16 PM   Total Posts: 110   [ # 6 ]
Matse - 10 February 2012 10:16 AM

Hi Huck,

I haven’t been using OBJ lately but I did when I started away3D4 back in september and I remember it was like this already. I believe it comes from the parser, not sure how easy or hard it would be to fix.

So far I’m sticking with one file per mesh and I use the namespace to automatically rename my assets so I can access them easily.

For example I load like this :

AssetLibrary.loadData(COLUMN_1context"scenery::column_1"); 

and here’s what I do when the AssetLibrary dispatches the AssetEvent.ASSET_COMPLETE event :

protected function onAssetComplete($evt:AssetEvent):void
  {
   
var name:String $evt.asset.name;
   var nameSpace:
String $evt.asset.assetNamespace;
   var 
type:String $evt.asset.assetType;
   
   var 
msg:String "Asset loaded TYPE=" type " NAME=" name
        
" NAMESPACE=" + nameSpace;
   
log(msg);
   
   
AssetLibrary.removeAsset($evt.assetfalse);
   
   var array:Array = nameSpace.
split("::");
   if (array.
length 1{
    
switch(type{
     
case AssetType.SKELETON :
      
$evt.asset.name "skeleton";
      break;
      
     case 
AssetType.MESH :
      
$evt.asset.name array[1];
      break;
      
     case 
AssetType.ANIMATION :
      
$evt.asset.name array[1];
      break;
      
     default:
      return;
    
}
    $evt
.asset.resetAssetPath($evt.asset.namearray[0]);
   
else {
    $evt
.asset.resetAssetPath(namearray[0]);
   
}
   
   AssetLibrary
.addAsset($evt.asset);
  

then I can retrieve my column mesh simply :

var mesh:Mesh AssetLibrary.getAsset("column_1""scenery") as Mesh

 

what is the contextsupposed to do in AssetLibrary.load(..., context… ?

Is it necessary?

 

 Signature 

http://www-scf.usc.edu/~shopkins

   

Avatar
Matse, Sr. Member
Posted: 27 February 2012 07:25 AM   Total Posts: 149   [ # 7 ]

AssetLoaderContext is not necessary for everyone I guess : I’m using it to avoid loading dependencies that the parser may find in the data, as I want to handle textures and materials myself (in order to share/re-use them).

You can also use it to define the base path for loading the dependencies, if you choose to keep them in.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X