I guess something is wrong with my model, I export this obj model from blender, Thanks for any hints.
package
{
import away3d.cameras.Camera3D;
import away3d.containers.Scene3D;
import away3d.containers.View3D;
import away3d.controllers.HoverController;
import away3d.debug.AwayStats;
import away3d.entities.Mesh;
import away3d.events.AssetEvent;
import away3d.library.AssetLibrary;
import away3d.library.assets.AssetType;
import away3d.library.assets.IAsset;
import away3d.lights.PointLight;
import away3d.loaders.misc.AssetLoaderContext;
import away3d.loaders.parsers.Parsers;
import away3d.materials.BitmapMaterial;
import away3d.materials.ColorMaterial;
import away3d.materials.methods.BasicDiffuseMethod;
import away3d.materials.methods.BasicSpecularMethod;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.getTimer;
public class LightTest extends Sprite
{
[Embed(source="/../embeds/simpleland.obj", mimeType="application/octet-stream")]
private var Cube : Class;
private var camera:Camera3D;
private var scene:Scene3D;
private var view:View3D;
private var cameraController:HoverController;
private var light:PointLight;
private var cubeModel:Mesh;
private var move:Boolean;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseY:Number;
private var lastMouseX:Number;
private var cubeMaterial:BitmapMaterial;
private var diffuseMethod:BasicDiffuseMethod;
private var specularMethod:BasicSpecularMethod;
private var assetLoaderContext:AssetLoaderContext;
private var colorMaterial:ColorMaterial;
public function LightTest()
{
super();
init();
}
private function init():void
{
initEngine();
initLights();
initMaterials();
initObjects();
initListener();
}
private function initMaterials():void
{
colorMaterial = new ColorMaterial(0x52c167);
//just can not enable this line,
// colorMaterial.lights = [light];
}
private function initLights():void
{
light = new PointLight();
light.x = 200;
light.z = 200;
light.color = 0xff00ff;
scene.addChild(light);
}
private function initEngine():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
scene = new Scene3D();
camera = new Camera3D();
view = new View3D();
view.scene = scene;
view.camera = camera;
view.antiAlias = 6;
cameraController = new HoverController(camera,null,45,10,1500);
addChild(view);
addChild(new AwayStats(view));
}
private function initListener():void
{
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
addEventListener(Event.ENTER_FRAME,onEnterFrame);
}
private function initObjects():void
{
Parsers.enableAllBundled();
AssetLibrary.addEventListener(AssetEvent.ASSET_COMPLETE,onAssetComplete);
assetLoaderContext = new AssetLoaderContext(true,'../embeds/');
AssetLibrary.loadData(new Cube(),assetLoaderContext);
}
protected function onAssetComplete(event:AssetEvent):void
{
if (event.asset.assetType == AssetType.MESH){
cubeModel = event.asset as Mesh;
cubeModel.geometry.scale(100);
cubeModel.y = -50;
cubeModel.material = colorMaterial;
scene.addChild(cubeModel);
}
}
protected function onEnterFrame(event:Event):void
{
if (move) {
cameraController.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle;
cameraController.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle;
}
light.x = Math.sin(getTimer()/10000) * 200;
light.y = 1000;
light.z = Math.cos(getTimer()/10000) * 200;
view.render();
}
/**
* Mouse down listener for navigation
*/
private function onMouseDown(event:MouseEvent):void
{
lastPanAngle = cameraController.panAngle;
lastTiltAngle = cameraController.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = true;
stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
/**
* Mouse up listener for navigation
*/
private function onMouseUp(event:MouseEvent):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
/**
* Mouse stage leave listener for navigation
*/
private function onStageMouseLeave(event:Event):void
{
move = false;
stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}
}
}