I’m just trying to load my .dae object externally. I’ve loaded before .obj format but I want to load Collada format but I didn’t see nothing on my display. Please guide me! Where is my mistake this code. I really appericate that! Thank you so much.
Here is my code :
import away3d.containers.*;
import flash.events.Event;
import away3d.loaders.Loader3D;
import away3d.loaders.parsers.*;
import away3d.events.LoaderEvent;
import flash.net.URLRequest;
import away3d.loaders.parsers.Parsers;
import away3d.events.AssetEvent;
import away3d.library.assets.AssetType;
import away3d.core.base.Geometry;
import away3d.cameras.Camera3D;
import away3d.containers.ObjectContainer3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.controllers.HoverController;
import flash.geom.Vector3D;
import away3d.entities.Mesh;
import away3d.materials.ColorMaterial;
import away3d.primitives.CubeGeometry;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.lights.DirectionalLight;
//for navigator
var isMouseMove:Boolean = false;
var lastMouseX:Number;
var lastMouseY:Number;
var lastPanAngle:Number;
var lastTiltAngle:Number;
var cameraController:HoverController;
var trans:*;
var _view:View3D = new View3D();
_view.backgroundColor = 0xFF0000;
addChild(_view);
var position:Vector3D;
cameraController = new HoverController(_view.camera,null,15,15);
cameraController.maxTiltAngle = 15;
cameraController.minTiltAngle = 15;
cameraController.maxPanAngle = 360;
loadModel();
initListeners();
function initListeners():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDownx);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUpx);
addEventListener(Event.ENTER_FRAME, render);
}
function onMouseDownx(event:MouseEvent):void
{
isMouseMove = true;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
lastPanAngle = cameraController.panAngle;
lastTiltAngle = cameraController.tiltAngle;
trace(lastTiltAngle);
}
function onMouseUpx(event:MouseEvent):void
{
isMouseMove = false;
}
var _loader:Loader3D;
var transformObj:ObjectContainer3D;
var cubeHolder:ObjectContainer3D = new ObjectContainer3D();
_view.scene.addChild(cubeHolder);
function loadModel():void
{
Loader3D.enableParser(DAEParser);
_loader = new Loader3D();
_loader.addEventListener(LoaderEvent.RESOURCE_COMPLETE, onModelLoaded);
_loader.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);
_loader.load(new URLRequest("rail_duz_ortaparca.dae"));
}
function onAssetComplete(event:AssetEvent):void
{
trace(" ev asse " + event.asset + "\nasse type "+event.asset.assetType);
if (event.asset.name == "ExitObject")
{
transformObj = event.asset as ObjectContainer3D;
trans = transformObj.sceneTransform;
}
if (event.asset.assetType == AssetType.MESH)
{
var mesh:Mesh = event.asset as Mesh;
cubeHolder.addChild(mesh);
}
if (event.asset.assetType == AssetType.CONTAINER)
{
var co:ObjectContainer3D = event.asset as ObjectContainer3D;
cubeHolder.addChild(co);
}
}
function onModelLoaded(e : LoaderEvent):void
{
cubeHolder.addChild(_loader);
}
function render(event:Event):void
{
if (isMouseMove)
{
cameraController.panAngle = 0.3 * (lastMouseX - stage.mouseX) + lastPanAngle;
cameraController.tiltAngle = 0.3 * (lastMouseY - stage.mouseY) + lastTiltAngle;
}
_view.render();
}