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_COMPLETE, onAssetReady);
AssetLibrary.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceReady)
}
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_COMPLETE, onAssetReady);
}
else if (e.asset.assetType == AssetType.GEOMETRY)
{
_geometry = e.asset as Geometry;
}
}
private function onResourceReady(e:LoaderEvent):void
{
AssetLibrary.removeEventListener(LoaderEvent.RESOURCE_COMPLETE, onResourceReady);
box = new ObjectContainer3D();
box.addChild(_modelMesh);
_modelMesh.mouseEnabled = true;
_modelMesh.addEventListener(MouseEvent3D.CLICK, onClick);
_view.scene.addChild(box);
createCamera();
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME, update);
}
protected function onClick(event:MouseEvent3D):void
{
trace("object clicked!");
}
protected function onMouseDown(e:MouseEvent):void
{
_mouseDown = true;
_previousMouse.x = e.stageX;
_previousMouse.y = e.stageY;
}
protected function onMouseUp(e:MouseEvent):void
{
_mouseDown = false;
}
private function createCamera():void
{
_camera = new HoverController(_view.camera, box, 180, 25, 350);
_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.x = stage.mouseX;
_previousMouse.y = stage.mouseY;
}
_view.render();
}
private function initView():void
{
_view = new View3D();
_view.backgroundColor = 0x0;
_view.antiAlias = 4;
addChild(_view);
_view.camera.z = -250;
_view.camera.y = 150;
_view.camera.lookAt(new Vector3D());
_view.camera.lens = new PerspectiveLens(90);
_view.camera.lens.far = 5000;
}
}
}