actionscript 3 - Loading and unloading new models -


my apologies if question has been posted before, unable source out solution little problem.


i using pv3d load couple of models school project. models typically don't much, spin on dial when fired up.

at given time, there 2 models shown. initial thought utilize 2 global collada instances , have function call collada load function load new models instances. looking through collada parser, seem load function appends new model, leaving existing models there, opposed loading in new set of vertices.

fair enough. @ point decide should remove models scene, , create new ones every time function fires.

here problem lies. lack of understanding on workings of as3/pv3d, please bear me. when remove models scene , add them again, models not appear within scene. however, model instances still remain traceable when run trace.

here code reference. omitted portions duplicates.

instances created on global level onrendertick can't seem reference if create on other level

public var model:collada = new collada(); public var model2:collada = new collada(); 

the initial properties such x y position , pitch set when dials created

public function setupdials():void {    var materiallist:materialslist = new materialslist();    var bitmapfilematerial:bitmapfilematerial = new bitmapfilematerial("assets/images/uv/marble.jpg");    materiallist.addmaterial(bitmapfilematerial, "all");    dial = new collada("assets/dial.dae", materiallist);    dial2 = new collada("assets/dial.dae", materiallist);    dial.scale = 2;    dial.x = 400;    dial.y = -100;    dial.pitch(-10);    dial2.scale = 2;    dial2.x = -400;    dial2.y = -100;    dial2.pitch(-10);    scene.addchild(dial);       scene.addchild(dial2);     // run once    model.x = 450;    model.y = 100;    model.pitch(-10);    model2.x = -450;    model2.y = 100;    model2.pitch(-10);   } 

after dials setup, models loaded using loadanimals()

public function loadanimals(param1:string):void {     if (!first) {     scene.removechild(model);     scene.removechild(model2);     initnewmodels();    } // end if     first = false;    model.addeventlistener(fileloadevent.load_complete, daeloaded);    model2.addeventlistener(fileloadevent.load_complete, daeloaded);        if (param1 == "environment1") {     var leopardmats:materialslist = new materialslist();     var bitmapfilematerial:bitmapfilematerial = new bitmapfilematerial(textures[0]);     leopardmats.addmaterial(bitmapfilematerial, "all");     model.load("assets/leopard.dae", leopardmats);     model.scale = 2;      var wolverinemats:materialslist = new materialslist();     var bitmapfilematerial2:bitmapfilematerial = new bitmapfilematerial(textures[1]);     wolverinemats.addmaterial(bitmapfilematerial2, "all");     model2.load("assets/wolverine.dae", wolverinemats);     model2.scale = 0.7;    }     else if (param1 == "environment2") {     var markhormats:materialslist = new materialslist();     var markhorfilematerial:bitmapfilematerial = new bitmapfilematerial(textures[4]);     markhormats.addmaterial(markhorfilematerial, "all");     model.load("assets/markhor.dae", markhormats);     model.scale = 2;      var oryxmats:materialslist = new materialslist();     var oryxfilematerial:bitmapfilematerial = new bitmapfilematerial(textures[5]);     oryxmats.addmaterial(oryxfilematerial, "all");     model2.load("assets/oryx.dae", oryxmats);     model2.scale = 10;    }   } 

_adds loaded daes onto scene, self explanatory

  public function daeloaded(e:fileloadevent):void {    e.target.removeeventlistener(fileloadevent.load_complete, daeloaded);    scene.addchild(displayobject3d(e.target));   } 

initnewmodels() called upon removal of models scene, add new models

  public function initnewmodels():void {    var model:collada = new collada();    var model2:collada = new collada();    model.x = 450;    model.y = 100;    model.pitch(-10);    model2.x = -450;    model2.y = 100;    model2.pitch(-10);    } // end initmodels function 

at juncture, using code, happens models load fine on first click. when try load subsequent models, spinning dials remain, models seen. however, traceable when run trace, returning me x, y, z coordinates.

my questions are:

a) there way remove model scene? item should not traceable when call scene.removechild(model), yet is.

b) there better way approach this? should not creating new models initnewmodels function, seems me doing way cause other functions unable render new models (hence causing not visible).

i have preferred try , figure out on own seems rather simple issue, deadline approaching , should not dwell on long. appreciate rendered. looking through!

in initnewmodels() function re-declaring model , model2 variables not working global-scope collada instances new function-scope variables.

for doing should give object oriented programming in as3 because duplicating lot of code. should able more prolific , avoid these kind of errors simple oop , maybe xml file (or array configuration)!

hope helps...


Comments

Popular posts from this blog

Add email recipient to all new Trac tickets -

400 Bad Request on Apache/PHP AddHandler wrapper -

php - Change action and image src url's with jQuery -