3d models from external loaded swf library

Software: Away3D 4.x

Nik_lot, Newbie
Posted: 13 March 2015 10:34 AM   Total Posts: 9

Hello everyone,

I am kinda new in actionscript 3 and away3d. I have reached a decent level in my coding ability but I face a problem that I can’t solve.. I am working on a game. What I did, is to create a swf library with three 3d models embed (.3ds format. a sphere, a cube, a pyramid), and then load that swf in my game.
What I am trying to manage is to be able to retrieve each of those 3d models from the loaded swf, and use them in my game.
I experimented a lot and I can’t find a proper way to achieve this. I can only retrieve one 3d model and add it in my game scene as mesh.
I am asking you if you can indicate a method that I can use or point me to a direction so I can do some research. Thanks for your time smile

   

rdoi, Member
Posted: 13 March 2015 05:07 PM   Total Posts: 86   [ # 1 ]

You can access your swf embedded 3D assets the same way you would for any other type of asset in Flash/AS3.
Just make sure you expose (define as public) some methods that can instantiate those assets after you have loaded the swf (through loaderInfo.content).

Post your loading code fragment so we can have an idea of how you trying to load it.

Also, you could try to convert your scene in AWD (Prefab/AwayBuilder) and follow its loading workflow. Check the away docs.

   

Nik_lot, Newbie
Posted: 13 March 2015 06:25 PM   Total Posts: 9   [ # 2 ]

hey mate, thnx for your answer. I already know how to access my models and add them to the scene. My problem is that I can only do it for one of them. What I need is a method to add them all. Anyway, here is my code.

private function start():void
  {
    libloader 
= new Loader();
       
libloader.contentLoaderInfo.addEventListener(Event.COMPLETElibloaded);
       
libloader.load(new URLRequest('ionlibrary.swf'));
   
       function 
libloaded(e:Event):void
    {
        libloader
.contentLoaderInfo.removeEventListener(Event.COMPLETElibloaded);
        var 
cubemodel:Class = libloader.contentLoaderInfo.applicationDomain.getDefinition("ionlibrary_cube") as Class;
      
        
AssetLibrary.enableParser(Max3DSParser);
        
AssetLibrary.loadData(cubemodel);
        
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEcubeready);
        
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETEcubedone);
     
        function 
cubeready(evt:AssetEvent):void
        {
           
if (evt.asset.assetType == AssetType.MESH)
              
{
                cubemesh1 
evt.asset as Mesh;
              
}
        }
     
        
function cubedone(ev:LoaderEvent):void
        {
         cubemesh1
.=0;
         
cubemesh1.0;
         
cubemesh1.0;
         
cubemesh1.scaleX 5;
         
cubemesh1.scaleY 5;
         
cubemesh1.scaleZ 5;
         
view.scene.addChild(cubemesh1); 
        
}
    } 

the thing is that there are two more models in the swf (sphere and pyramid) and I want to extract them too and add them to the scene. But when I load the next model into the AssetLibrary,  the previous is deleted and it’s child is null.

   

rdoi, Member
Posted: 14 March 2015 01:08 AM   Total Posts: 86   [ # 3 ]

Im not sure what is wrong exactly, but I think it the problem may be related to the function scope (closure) of “cubemesh1” variable.

The loading process is asynchronous, meaning the ASSET_COMPLETE execution may overlap if you call loadData() in direct sequence. For each model you should wait for its respective RESOUCE_COMPLETE.

Or maybe you could just addChild the mesh right in the ASSET_COMPLETE block (ignoring the RESOURCE_COMPLETE).


Just wondering:
1. Is there a reason you want to embed your 3d assets in a SWF file? Can’t you just load the 3ds file directly?

2. I am not sure about the 3ds parser, but by using the AWD format, you could embed all your assets in just one big file, load all of them at once, and manipulate each of them individually by their 3d object name / asset.name.

   

Nik_lot, Newbie
Posted: 14 March 2015 07:15 AM   Total Posts: 9   [ # 4 ]

Thank you rdoi, I already started working with the AWD format and away builder.
Since you ask, I wanted to embed my assets in SWF file so as to load it in my game and then retrieve the models one by one and construct my game level. But AWD makes it easier, I will start working with AWD smile .

   

Nik_lot, Newbie
Posted: 18 March 2015 03:40 PM   Total Posts: 9   [ # 5 ]

btw, the answer to my question was that I could push the meshes into a vector in the Asset Event. But I reccomend working with AWD smile

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X