loading multiple models, but only one mesh?

Software: Away3D 4.x

dangerop, Newbie
Posted: 01 September 2013 04:56 AM   Total Posts: 4

hi, sorry if this is really simple, but i’m new to away3d and can’t seem to find an answer to this.

i loaded two collada models, but when i trace(e.asset.assetType) in AssetEvent.ASSET_COMPLETE event listener, it says only one mesh. also i only see the first model and only the first model loads.

can someone tell me whats wrong or how to load two models in away3d?

here is the code:

package
{
 import flash
.display.Sprite;
 
import flash.display.StageAlign;
 
import flash.display.StageScaleMode;
 
import flash.events.Event;
 
import flash.events.MouseEvent;
 
import flash.geom.Point;
 
import flash.geom.Vector3D;
 
 
import away3d.animators.VertexAnimationSet;
 
import away3d.animators.VertexAnimator;
 
import away3d.cameras.lenses.PerspectiveLens;
 
import away3d.containers.ObjectContainer3D;
 
import away3d.containers.View3D;
 
import away3d.controllers.HoverController;
 
import away3d.core.base.Geometry;
 
import away3d.entities.Mesh;
 
import away3d.events.AssetEvent;
 
import away3d.events.LoaderEvent;
 
import away3d.events.MouseEvent3D;
 
import away3d.library.AssetLibrary;
 
import away3d.library.assets.AssetType;
 
import away3d.library.assets.IAsset;
 
import away3d.loaders.parsers.DAEParser;
 
import away3d.loaders.parsers.AWD2Parser;
 
import away3d.loaders.parsers.*;
 
import away3d.materials.TextureMaterial;
 
import away3d.primitives.PlaneGeometry;
 
import away3d.primitives.SkyBox;
 
import away3d.textures.BitmapCubeTexture;
 
import away3d.utils.Cast;
 
import away3d.loaders.Loader3D;
 
import flash.net.URLRequest;
 
 public class 
Box extends Sprite
 {
  [Embed
(source "assets/greenBox1.awd"mimeType="application/octet-stream")public static var BOX_DATA:Class;
  
[Embed(source "assets/blueBox.dae"mimeType="application/octet-stream")public static var BOX2_DATA:Class;
  
  private var 
_view:View3D;
  private var 
_modelMesh:Mesh;
  private var 
box:ObjectContainer3D;
  private var 
_mouseDown:Boolean;
  private var 
_previousMouse:Point;
  private var 
_camera:HoverController;
  private var 
_geometry:Geometry;
  
  public function 
Box()
  
{
   stage
.scaleMode StageScaleMode.NO_SCALE;
   
stage.align StageAlign.TOP_LEFT;
   
   
initView();
   
createBox();
   
   
_mouseDown false;
   
_previousMouse = new Point();
  
}
  
  
private function createBox():void
  {
   
var model:* = new BOX_DATA();
   var 
model2:* = new BOX2_DATA();
   
   
/*AssetLibrary.enableParser(AWD2Parser);
   AssetLibrary.enableParser(DAEParser);*/
   
Parsers.enableAllBundled();
   
/*AssetLibrary.loadData(model);
   AssetLibrary.loadData(model2);*/
   
   
var loader:Loader3D = new Loader3D();
   
loader.load(new URLRequest("assets/blueBox.dae"));
   
   
_view.scene.addChild(loader);
   
   var 
loader2:Loader3D = new Loader3D();
   
loader2.load(new URLRequest("assets/ball.dae"));
   
   
_view.scene.addChild(loader2);
   
   
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETEonAssetReady);
   
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceReady)
  
}
  
  
private function onAssetReady(e:AssetEvent):void
  {
   trace
(e.asset.assetType);
   if (
e.asset.assetType == AssetType.MESH)
   
{
    _modelMesh 
e.asset as Mesh;
    
AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETEonAssetReady);
   
}
   
else if (e.asset.assetType == AssetType.GEOMETRY)
   
{
    _geometry 
e.asset as Geometry;
   
}
  }
  
  
private function onResourceReady(e:LoaderEvent):void
  {
   AssetLibrary
.removeEventListener(LoaderEvent.RESOURCE_COMPLETEonResourceReady);
   
   
box = new ObjectContainer3D();
   
box.addChild(_modelMesh);
   
   
_modelMesh.mouseEnabled true;
   
_modelMesh.addEventListener(MouseEvent3D.CLICKonClick);
   
   
_view.scene.addChild(box);
   
   
createCamera();
   
   
stage.addEventListener(MouseEvent.MOUSE_DOWNonMouseDown);
   
stage.addEventListener(MouseEvent.MOUSE_UPonMouseUp);
   
   
addEventListener(Event.ENTER_FRAMEupdate);
  
}
  
  
protected function onClick(event:MouseEvent3D):void
  {
   trace
("object clicked!");
  
}
  
  
protected function onMouseDown(e:MouseEvent):void
  {
   _mouseDown 
true;
   
_previousMouse.e.stageX;
   
_previousMouse.e.stageY;
  
}
  
  
protected function onMouseUp(e:MouseEvent):void
  {
   _mouseDown 
false;
  
}
  
  
private function createCamera():void
  {
   _camera 
= new HoverController(_view.camerabox18025350);
   
_camera.steps 12;
   
_camera.minTiltAngle 5;
   
_camera.maxTiltAngle 33;
   
_camera.wrapPanAngle true;
  
}
  
  
private function update(e:Event):void
  {
   
if (_mouseDown)
   
{
    
var xDif:Number stage.mouseX _previousMouse.x;
    var 
yDif:Number stage.mouseY _previousMouse.y;
    
    if (
xDif 10)
     
xDif 10;
    
    if (
xDif < -10)
     
xDif = -10;
    
    
_camera.panAngle += xDif;
    
box.rotationY += xDif;
    
    
_camera.tiltAngle += yDif;
    
    
_previousMouse.stage.mouseX;
    
_previousMouse.stage.mouseY;
   
}
   
   _view
.render();
  
}
  
  
private function initView():void
  {
   _view 
= new View3D();
   
_view.backgroundColor 0x0;
   
_view.antiAlias 4;
   
addChild(_view);
   
   
_view.camera.= -250;
   
_view.camera.150;
   
_view.camera.lookAt(new Vector3D());
   
   
_view.camera.lens = new PerspectiveLens(90);
   
_view.camera.lens.far 5000;
  
}
 }
   

ActionFrob, Newbie
Posted: 01 September 2013 08:31 AM   Total Posts: 10   [ # 1 ]
private function onAssetReady(e:AssetEvent):void
  {
   trace
(e.asset.assetType);
   if (
e.asset.assetType == AssetType.MESH)
   
{
    _modelMesh 
e.asset as Mesh;
    
AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETEonAssetReady);
   
}
   
else if (e.asset.assetType == AssetType.GEOMETRY)
   
{
    _geometry 
e.asset as Geometry;
   
}
  } 

Hi,

I think the problem is that you remove the Eventlistener after you have loaded the first model so that the function is not executed twice.

Greetz

   

dangerop, Newbie
Posted: 01 September 2013 06:24 PM   Total Posts: 4   [ # 2 ]

thank you.

how do i get the second mesh now and add it to the scene?

   

dangerop, Newbie
Posted: 01 September 2013 06:54 PM   Total Posts: 4   [ # 3 ]

nevermind i figured it out. thanks for your help!

private function onAssetReady(e:AssetEvent):void
  {
   trace
(e.asset.assetType);
   
trace(e.asset.name);
   if (
e.asset.name == "Cube")
   
{
    _modelMesh 
e.asset as Mesh;
    
//AssetLibrary.removeEventListener(AssetEvent.ASSET_COMPLETE, onAssetReady);
   
}
   
else if (e.asset.name == "Sphere")
   
{
    _modelMesh2 
e.asset as Mesh;
    
_modelMesh2.200;
   
}
   
else if (e.asset.assetType == AssetType.GEOMETRY)
   
{
    _geometry 
e.asset as Geometry;
   
}
  } 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X