Loading a model with materials?

Software: Away3D 4.x

0L4F, Newbie
Posted: 14 October 2011 08:42 AM   Total Posts: 15

I still can’t seem to figure out how to load a model with materials into Away3D 4.0. I’ve got some .3ds and .obj models that I’d like to try, where .3ds is my preferred format.

I’ve looked at the updated 3DS parser, and the new examples, but it’s still not clear to me. The latest ‘soldier ant’ example has the texture embedded in the .swf…

Can it be done? If so, could you help me with some code hints?

Thanks in advance!

   

Richard Olsson, Administrator
Posted: 14 October 2011 06:00 PM   Total Posts: 1192   [ # 1 ]

Just load the 3DS file using Loader3D, AssetLoader or the AssetLibrary. The dependencies (e.g. textures) will be loaded automatically. If the path is incorrect, an error will be thrown (or an event be dispatched if you are listening for it.)

   

0L4F, Newbie
Posted: 19 October 2011 12:52 PM   Total Posts: 15   [ # 2 ]

Hi Richard,

thanks for your reply! But still no joy. This is the code I’m trying to get to work:

loader = new AssetLoader(); 
loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
loader.load(new URLRequest('embeds/wagen1.3ds'));

private function 
onAssetComplete(event:AssetEvent):void
{
    
if (event.asset.assetType == AssetType.MESH{
 
var mesh:Mesh event.asset as Mesh;
   
    
else if (event.asset.assetType == AssetType.MATERIAL{
 
var material:BitmapMaterial event.asset as BitmapMaterial;
 
material.lights [light];
 
material.gloss 30;
 
material.specular 1;
 
material.ambientColor 0x303040;
    
}

...but I can’t figure out how to add the loaded asset to the scene. Sorry for these noob questions smile

I’d love to see a simple code example that loads a 3ds model and adds it to the scene, maybe it will make the concept click for me.

Thanks in advance!

   

Richard Olsson, Administrator
Posted: 19 October 2011 12:58 PM   Total Posts: 1192   [ # 3 ]

Have a look at the away3d-examples-fp11 repository on GitHub, where you will find for example this: https://github.com/away3d/away3d-examples-fp11/blob/master/src/Basic_Load3DS.as

   

Avatar
80prozent, Sr. Member
Posted: 19 October 2011 01:12 PM   Total Posts: 430   [ # 4 ]

hi

to set your material to your mesh, you have to do something like this (code not tested):

loader = new AssetLoader(); 
loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
loader.load(new URLRequest('embeds/wagen1.3ds'));

private var 
mesh:Mesh;

private function 
onAssetComplete(event:AssetEvent):void
{
    
if (event.asset.assetType == AssetType.MESH{
        mesh 
event.asset as Mesh;
        
scene.addChild(mesh);
   
    
else if (event.asset.assetType == AssetType.MATERIAL{
 
var material:BitmapMaterial event.asset as BitmapMaterial;
 
material.lights [light];
 
material.gloss 30;
 
material.specular 1;
 
material.ambientColor 0x303040;
 
mesh.material=material;
    
}
 Signature 

sorry…i hope my actionscript is better than my english…

   

Marcos Neves, Newbie
Posted: 17 November 2011 07:06 PM   Total Posts: 6   [ # 5 ]

To handle the material by 3DS files as you can utilize the code below. Works well on Away3D 4x. A demo version can be seen in: http://marcosneves.com/extranet/away4Tests/

private function loadModels():void 
{
    Parsers
.enableAllBundled();
 
    
//Loader model.ac
    
acLoader = new Loader3D();
    
acLoader.addEventListener(AssetEvent.ASSET_COMPLETEonMeshLoadComplete);
    
acLoader.load( new URLRequest('TREE_AC/TREE_AC.ac') );
   
    
//Loader model.3ds
    
var maxParser:Max3DSParser = new Max3DSParser();
    
maxLoader = new Loader3D();
    
maxLoader.addEventListener(LoaderEvent.RESOURCE_COMPLETEonMaxLoaded);
    
maxLoader.load( new URLRequest('tree13.3ds'), nullnullmaxParser);
   
    
this.addEventListener(Event.ENTER_FRAMEonEnterFrame);
}

private function onMaxLoaded(e:LoaderEvent):void 
{
    maxLoader
.scale(70); 
 
    var 
obj:ObjectContainer3D maxLoader as ObjectContainer3D;
   
    var 
mesh:Mesh Mesh(obj.getChildAt(0));
 
    var 
map:BitmapMaterial mesh.material as BitmapMaterial;
    
map.ambient 1
    map
.specular 1;
    
map.alpha .7;
    
map.lights [ _light2_light3 ];//needed lights create
    
map.repeat true;
    
map.smooth true;
    
map.bothSides false;
   
    
_view.scene.addChild(maxLoader);
   
}
  
private function onMeshLoadComplete(e:AssetEvent) : void
{
   
    acLoader
.removeEventListener(AssetEvent.ASSET_COMPLETEonMeshLoadComplete);
 
    
acLoader.700;
    
acLoader.scale(30);

    if (
e.asset.assetType == AssetType.MESH)
    
{
        mesh 
e.asset as Mesh;
  
        var 
material BitmapMaterial mesh.material as BitmapMaterial;
        
material.lights [ _light2_light3 ];
        
material.specular 2;
        
material.alpha 1;
        
material.ambientColor 0x202030;
        
mesh.material material;
    
}
  
    _view
.scene.addChild(acLoader);
   

   

Avatar
maddog, Sr. Member
Posted: 17 November 2011 07:28 PM   Total Posts: 118   [ # 6 ]

you can use assetlibrary to access object mesh like this. Make sure you know your mesh’s name

loader.addEventListener(AssetEvent.ASSET_COMPLETEonAssetComplete);
loader.loadData(new mainModel());
container.addChild(loader);

private function 
onAssetComplete(event:AssetEvent):void
  {
HouseMesh 
Mesh(AssetLibrary.getAsset('3DOBJECTNAMEHERE'));
HouseMesh.material =  new BitmapMaterial((new modelTexture()).bitmapData);
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X