Away3D 4 Loading 3DS Model

Software: Away3D 4.x

lanceaeby, Newbie
Posted: 10 January 2012 04:53 PM   Total Posts: 8

I’ve been trying to load a .3DS model into an Away3D 4 project, but I am not able to load the texture from the model itself.  I’ve seen a few posts regarding AssetLibrary, but those approaches have not worked for me.  I’m able to load the .3DS model using the code below, but the model appears with a green color texture.

_loader = new Loader3D();
   
_loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
   
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceComplete);
   
_loader.load(new URLRequest('assets/skeleton.3DS')); 
private function onAssetComplete(event:AssetEvent): void {
   
var newMaterial:ColorMaterial = new ColorMaterial(0xFF000);
   var 
mesh:Mesh event.asset as Mesh;
   
mesh.material newMaterial
   
mesh.scale(.25);
   
mesh.rotationY 90;
  
private function onResourceComplete(ev:LoaderEvent): void {
   view
.scene.addChild(_loader);
  

 

I’ve also tried something like the code below within the onAssetComplete function, but I get a “Bad Input” error and a “A texture is bound on sampler 0 but not used by the fragment program.” error.

if (event.asset.assetType == AssetType.MESH{
    mesh 
Mesh(event.asset);
    
//mesh.material = newMaterial; 
    
mesh.scale(3);
    
mesh.rotationY 90;
    
view.scene.addChild(mesh);
   
}
   
else if(event.asset.assetType == AssetType.MATERIAL{
    mat 
ColorMaterial(event.asset);
    
//mesh.material = mat;
   

Any ideas?

   

Avatar
theMightyAtom, Sr. Member
Posted: 10 January 2012 05:38 PM   Total Posts: 669   [ # 1 ]

I always assign my materials manually after loading, generally because I want to manipulate them. The routine I use is something like this…

public function loadModel(product:String):void {
   Loader3D
.enableParser(Max3DSParser);
   
_loader = new Loader3D();
   
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonModelLoaded);
   
_loader.load(new URLRequest("models/" product)); 
   
   
   
  
}
private function onModelLoaded(LoaderEvent) : void
  {

   _view
.scene.addChild(_loader);
   
   var 
mat:ColorMaterial;
   
mat =  new ColorMaterial(0xCCCCCC1);
   
mat.lights [_light];
   
   var 
i:int;
   var 
mesh:Mesh;
   var 
numChil:uint _loader.numChildren;
   for (
0numChil; ++i{
    mesh 
Mesh(_loader.getChildAt(i));
    
//INSERT YOUR OWN CODE FOR MATERIAL, CHOOSE AFTER NAME, ETC.
    
mesh.material mat;
   
}
   
  } 

Try something like that.

Good Luck!

   

lanceaeby, Newbie
Posted: 10 January 2012 06:07 PM   Total Posts: 8   [ # 2 ]

Quick question, I’m getting an error at the first line within your loadModel function, it’s not liking OBJParserNamed.  I see an OBJParser class, but not an OBJParserNamed class.  Is this a custom class you created?  Thanks for your help smile

   

Avatar
theMightyAtom, Sr. Member
Posted: 11 January 2012 09:15 AM   Total Posts: 669   [ # 3 ]

Ah, you caught me smile
Yes, it’s a custom class so that meshes loaded in .obj format retain their mesh name. You can just remove it, as you’re using 3DS and so it’s not needed.
I’ll update the code in the post.

   

lanceaeby, Newbie
Posted: 11 January 2012 02:59 PM   Total Posts: 8   [ # 4 ]

Ahh gotcha.  I got the .3DS model loading using your example, I appreciate it! smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X