Hi All
Pretty new to this 3d stuff so bare with me. I am working on a project lets call it model viewer. I need to be able to load models and then unload them. Due to the nature I need the model completely removed from memory. I seem to be removing a fair amount of memory but not all of it. I start with 27mb before loading model. I hit 89mb with loaded model. Then after running destroy() I end up with 59mb. Any help would be great.
_view = new View3D();
_view.antiAlias = 2;
_view.backgroundColor = 0x333333;
_camera = _view.camera;
_camera.lens = new PerspectiveLens();
_camera.lens.near = 10;
_camera.lens.far = 15000;
_camera.x = -122.74610137939453;
_camera.y = 184.41575622558594;
_camera.z = 2928.63330078125;
_group = new ObjectContainer3D();
_view.scene.addChild(_group);
direction = new Vector3D(-1, -1, 1);
_cameraController = new HoverController(_camera, null, 150, 10, 2000);
_cameraController.wrapPanAngle = true;
Loader3D.enableParser(AWD2Parser);
_loader = new Loader3D(false);
_loader.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete); _loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE,onResourceComplete);
_loader.load(new URLRequest(_path+_url), new AssetLoaderContext(true));
private function onAssetComplete(ev : AssetEvent) : void
{
trace("asset "+ev.asset)
if (ev.asset.assetType == AssetType.MESH) {
_mesh = Mesh(ev.asset);
_texMat = _mesh.material as TextureMaterial;
if (_mesh.material == null || (_texMat && _texMat.texture == null))
_mesh.material = new ColorMaterial(Math.random() * 0xffffff);
}
}
private function onResourceComplete(ev : LoaderEvent) : void
{
_camera.addEventListener(Object3DEvent.POSITION_CHANGED, changePosition)
_group.addChild(_loader);
_camera.lookAt(_loader.position);
}
public function destroy():void{
this.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
this.removeEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
this.removeEventListener(MouseEvent.MOUSE_UP, onMouseUp);
_loader.removeEventListener(AssetEvent.ASSET_COMPLETE, onAssetComplete);
_loader.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceComplete);
this.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
_camera.removeEventListener(Object3DEvent.POSITION_CHANGED, changePosition);
disposemodel(_loader)
try {
new LocalConnection().connect('foo');
new LocalConnection().connect('foo');
} catch (e:*) {}
}
public function disposemodel(model:Loader3D):void
{
_group.removeChild(_loader);
_view.scene.removeChild(_group);
_view.camera.disposeAsset();
_view.camera.dispose();
_camera.disposeAsset();
_camera.dispose();
while (_view.numChildren > 0){
_view.removeChildAt(0);
}
_view.dispose();
while (_loader.numChildren > 0){
_loader.removeChild(_loader.getChildAt(0));
}
_loader.disposeAsset();
_loader.dispose();
_mesh.geometry.dispose();
_mesh.dispose();
_mesh = null;
_texMat.texture.dispose();
_texMat.dispose();
_texMat = null;
this.removeChild(_view)
}