replacing a model with another

Software: Away3D 4.x

muroko, Newbie
Posted: 09 March 2013 12:22 AM   Total Posts: 9

Hi guys, i have a new problem. Finally i figured out how to export and load awd2 models into flash, i was so happy about it, my project is going good, till now.

The project is about customizable cars with several components which i can choose from comboboxes (bumpers, spoilers, etc)

Successfully managed to load the main body and the first combobox with the front bumpers. If i select bumper_1, it loads all right, if i select bumper_2 it loads over bumper_1, and so on.

Now i learned that there is no unload only dispose, but dispose gets rid of all models on the scene. i could just load the models again, but my problem is that if i do that, i can only load 1 new model at a time.

Here is what my combobox thingy looks like:

private function initComboBox1():void
  {
   
var cbBumperFront:ComboBox = new ComboBox();
      
   
this.addChild(cbBumperFront);
   
cbBumperFront.40;
   
cbBumperFront.40;
   
cbBumperFront.prompt "Front Bumpers";
   
cbBumperFront.addItem({label:"FrontBumper 1"data:"BumperFront1.awd"});
   
cbBumperFront.addItem({label:"FrontBumper 2"data:"BumperFront2.awd"});
   
   
cbBumperFront.addEventListener(Event.CHANGEonChange);
   
   function 
onChange(evt:Event):void {
    
    
    Parsers
.enableAllBundled();
    
trace("init loader");
    
loader = new Loader3D(falsenull);
    
loader.load(new URLRequest(evt.target.selectedItem.data));
    
view.scene.addChild(loader);
    
}
      
  } 

So how do i get rid of bumper 1 if i want to load bumper 2 without getting rid of all the other things? Or how do i keep the data from the combobox, so when i reload the scene, it should reload all the selected items in the comboboxes and not the default ones?

Thanks for the help in advance: Muroko

   

geekay, Jr. Member
Posted: 09 March 2013 12:39 AM   Total Posts: 40   [ # 1 ]

Perhaps loading the models into some sort of a cache/resourcemap (or using the AssetLibrary [ see: http://away3d.com/livedocs/away3d/4.0/away3d/library/AssetLibrary.html ]), might be your best bet.

First check if the asset has already been parsed and added to the cache, then if it is not, do your loading business, once done, add it to the scene… otherwise if it was already downloaded, parsed, and cached then you can just add it to the scene.

If memory usage becomes a problem (like if you have lots and lots of awd files that are really big—- you don’t really want to keep them needlessly hanging around…), you can do some cleanup when you check for resources. (setting the assets in the assetlibrary or your custom cache to null if they are not in use, and hoping that the gc will come about sometime in the future). My guess, in most cases, it will not be necessary to manage the assets in this way.

tl;dr Try downloading parsing and saving the data from the awd, and adding that to the scene.

If you need clarification of any sorts, please feel free to let me know anytime, I would love to be of help.

   

muroko, Newbie
Posted: 09 March 2013 04:12 AM   Total Posts: 9   [ # 2 ]

I checked that link you posted, i think i get it ( my guess is that i add all of my models into that assetlibrary and load them from there when i need them instead of loading external file directly ) , i just dont have any idea how to do that. Im really new to this thing >_< Is there somewhere a tutorial on howw to add files to assetlibrary and load/unload them from there?

   

geekay, Jr. Member
Posted: 09 March 2013 06:32 AM   Total Posts: 40   [ # 3 ]

As with all things, tutorials are in rather short supplies these days.

Generally speaking (I need to test the code, but this is a rough idea)...

AssetLibrary.enableParserAWD2Parser )
AssetLibrary.addEventListenerLoaderEvent.RESOURCE_COMPLETEonResourceComplete );
AssetLibrary.load( new URLRequest("your asset url here") );

//In your application after the resource complete is done (so when everything is all downloaded and parsed and ready to use.

//I want to get the mesh to use in the scene...
mesh Mesh(Mesh(AssetLibrary.getAsset("The name of the mesh")).clone());

//add the mesh to the scene
view.scene.addChild(mesh);

//wait a while

//remove the mesh to the scene
view.scene.removeChild(mesh);
mesh null
   

muroko, Newbie
Posted: 09 March 2013 05:57 PM   Total Posts: 9   [ # 4 ]

Ok, here is the thing. Please solve this for me and im all good to go :D

i have a scene with 2 combobox components. each combobox has 5 selectable options. So far what i was trying to do is that i added an event handler to the combobox , and when it changed , it loaded the selected data.
But like this, the other combobox selection got lost. My new idea is to add a Load button, add event handler to that (on press, load stuff). So how do i do this so it reads the selection from both combobox? Basically in order to read the selectedItem.data from a combobox, i always need an event handler? cant i just say : on button push load (combobox1 selection) and (combobox2 selection) ... where the selection would be that path to the file to load

   

geekay, Jr. Member
Posted: 09 March 2013 11:32 PM   Total Posts: 40   [ # 5 ]

As far as I can tell, the issue is not a specific failing of Away3D, but moreso you need help on how to solve for a specific issue.

If I find the time to work up a specific solution to your problem, I would be happy to post it here.

However, you might find a solution quicker than the time it would take for the above.

   

muroko, Newbie
Posted: 10 March 2013 08:20 AM   Total Posts: 9   [ # 6 ]

I would be the happiest ever if you or anyone could solve this, im thinking a lot, searching the interwebs, but i cannot find an answer. I guess with the assetlibrary is the same? Or with that i can load/unload models without touching the other loaded models?

   

geekay, Jr. Member
Posted: 10 March 2013 04:46 PM   Total Posts: 40   [ # 7 ]

In regards to not touching the other loaded models, if you go to use a mesh, be sure to ‘clone’ it out of the assetlibrary (that way you get a brand new fresh copy each time).

Hopefully I have some time to work something up for you quickly today… sorry for the wait (been a rough week :/)

   

muroko, Newbie
Posted: 12 March 2013 11:02 PM   Total Posts: 9   [ # 8 ]

I figured out my problem meanwhile, i just had to set variables for every combobox selection , than i could load all variables on a clear scene.

   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X