Obj loader fails at more models in one file

Software: Away3D 3.x

pool338, Jr. Member
Posted: 27 September 2011 01:37 PM   Total Posts: 37

If i use Obj.load to load an obj-file, which includes 1 model, i can set the material via

mesh.children[i].faces[j].material 

But when the obj-file includes more than 1 model this doesnt work anymore. The models will be displayed but without the material.

   

Indica, Newbie
Posted: 29 September 2011 09:43 AM   Total Posts: 3   [ # 1 ]

Try to use this code:

...
[Embed(source="path/to/object.obj"mimeType="application/octet-stream")]
private var OBJ : Class;
...
Loader3D.enableParser(OBJParser);
...
_objects = new Loader3D();
_objects.addEventListener(LoaderEvent.RESOURCE_COMPLETEonObjectsComplete);
_objects.parseData(new OBJs(), null, new AssetLoaderContext(false));
...
private function 
onObjectsComplete(LoaderEvent) : void
{
   
var subObject:Mesh;
   var 
objectsMeshes:Vector.<Mesh> = new Vector.<Mesh>;
   var 
materials:Vector.<MaterialBase> = new Vector.<MaterialBase>;
   
   var 
objectsLen:uint _objects.numChildren;
   
   var 
material1:ColorMaterial = new ColorMaterial(0x00ff00);
   var 
material2:ColorMaterial = new ColorMaterial(0x0000ff);

   
materials[0] material1;
   
materials[1] material2;

   for (var 
i:uint 0objectsLeni++)
   
{
      subObject 
Mesh(_objects.getChildAt(i));
      
subObject.material materials[i];
      
objectsMeshes[i] subObject;
   
}
}
... 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X