How to loop through meshes in .obj file?

Software: Away3D 4.x

Rajneesh, Jr. Member
Posted: 15 January 2014 08:39 AM   Total Posts: 34

Hi,

I want to apply color material to some specific models in my .obj file.

I guess I should have number meshes and their names. So according to their names I can apply particular material to them.

How can get those meshes in .obj file?

Thanks

Rajneesh

   

Avatar
Fabrice Closier, Administrator
Posted: 15 January 2014 09:55 AM   Total Posts: 1265   [ # 1 ]

obj, 3ds etc… no matter the format, once parsed the data is serialised for Away3D. You can access all meshes by either parsing your scene if already addChilded to view.scene or during parsing listening to the assetEvent of type Mesh. You should prepare your data using Prefab3D or AwayBuilder to give your assets a name that you can easily check and export as awd or as3 for your project.

 

   

Rajneesh, Jr. Member
Posted: 15 January 2014 11:36 AM   Total Posts: 34   [ # 2 ]

Hi, I tried to load Tyre.obj file in Prefab. It does not load the tyre texture properly. I have attached all required files.

Please help me. I am new to Prefab3D.

Thanks

Rajneesh

 

File Attachments
PrefabTest.rar  (File Size: 475KB - Downloads: 0)
   

Avatar
theMightyAtom, Sr. Member
Posted: 15 January 2014 12:59 PM   Total Posts: 669   [ # 3 ]

I’ll let Fabrice answer your Prefab question, after all he wrote it! :O)

As far as looping through your objects in code and applying materials, it goes like this…

private function loadMyModel():void
  {
   _loader 
= new Loader3D();
   
Loader3D.enableParser(OBJParser);
 
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEassignMaterials);
   
//_loader.loadData(new fullmesh()); // for loading embeded content 
   
_loader.load(new URLRequest("mymodel.obj"));
   
_view.scene.addChild(_loader);
  
  
}

private function assignMaterials(evt:LoaderEvent):void
  {
   
var loader:Loader3D evt.currentTarget as Loader3D;
   
   for (var 
i:int 0loader.numChildren; ++i)
   
{
    
// make sure this is a mesh, could be another loader
    
if (loader.getChildAt(iis Mesh)
    
{
     
var mesh:Mesh Mesh(loader.getChildAt(i));
     
     switch (
mesh.name)
     
{
      
      
case "ring"
       
mesh.material = new ColorMaterial(0xFF00001);
       break;
       
      case 
"sprocket":
       
mesh.material = new ColorMaterial(0xFF00FF1);
       break;
      
      default: 
       break;
     
}
     
    }
   }
 } 

Good Luck!

 

   

Rajneesh, Jr. Member
Posted: 15 January 2014 02:30 PM   Total Posts: 34   [ # 4 ]

Thanks theMightyAtom.

Actually I used AssetLibrary.loadData() and I applied material using AssetEvent ‘s name property i.e. event.asset.name successfully.

Thanks

 

   

Avatar
Fabrice Closier, Administrator
Posted: 15 January 2014 03:05 PM   Total Posts: 1265   [ # 5 ]

If Prefab doesn’t load a map of an obj file:

Open the process log window, if something went wrong, an error and the faulty url will be listed there.

Common mistakes with obj resulting in errors:
- url found in the .mtl are not relative to obj file or machine specific. i.e. c:/somewindozDir/myModels/textures/im.jpg will never load on another machine but yours.
- .mtl file missing while obj file has a useMTL tag.
- maps not found at url stored in the mtl
- obj file do not have the useMTL tag pointing at the .mtl file url.

Note that Prefab allows you to drop your map from your system to one selected mesh and will set/overwrite by default the material diffuse map. Which would be an easy way to fix your problem before export. Same functionality is available under menu file.

 

   

Rajneesh, Jr. Member
Posted: 16 January 2014 03:55 AM   Total Posts: 34   [ # 6 ]

Prefab loads the map but it is not showing properly like in 3dsMax12.
UV mapping is disturbed.

Is there a problem while exporting .obj from 3dsMax12 or a problem with Prefab3D?

I have attached files with my first reply.

 

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X