Away3D - 添加资源状态监控窗口(使用AwayStats)
作者:hangge | 2015-11-14 09:10
通过添加AwayStats,可以在页面上显示一个小小的监控窗口。实时显示出away3d的帧数,面数,内存使用,cpu占用等信息。
下面在页面右上角添加一个状态监控窗口:
package{ import flash.display.Sprite; import flash.display.StageAlign; import flash.display.StageScaleMode; import flash.events.Event; import flash.events.MouseEvent; import away3d.cameras.Camera3D; import away3d.containers.View3D; import away3d.controllers.HoverController; import away3d.debug.AwayStats; import away3d.entities.Mesh; import away3d.materials.TextureMaterial; import away3d.primitives.CubeGeometry; import away3d.textures.BitmapTexture; [SWF(frameRate="60", backgroundColor="#FFFFFF")] public class S4 extends Sprite { private var _view3D:View3D; private var cameraController:HoverController;//360全景展示相机控制器 //状态监控 private var _awayStats:AwayStats; //地板图片(用作地板的纹理 ) [Embed(source="assets/road.jpg")] private var floorClass:Class; private var _lastX:Number = 0; private var _lastY:Number = 0; public function S4() { stage.scaleMode = StageScaleMode.NO_SCALE; stage.align = StageAlign.TOP_LEFT; // 创建一个视口 _view3D = new View3D(); _view3D.antiAlias = 4; //设置抗锯齿级别 addChild(_view3D); //添加 状态监控视图 addChild(_awayStats = new AwayStats(_view3D)); //地板的纹理 var bmpTexture1:BitmapTexture = new BitmapTexture(new floorClass().bitmapData); var material1:TextureMaterial = new TextureMaterial(bmpTexture1); // 在三维舞台中创建一个方块(地板 ) var cube1:Mesh = new Mesh(new CubeGeometry(700, 20, 500), material1); _view3D.scene.addChild(cube1); //初始化摄像头 initCamera(_view3D.camera); addEventListener(Event.ENTER_FRAME, _onEnterFrame); stage.addEventListener(Event.RESIZE, onResize); onResize(); //鼠标事件监听 stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown); stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp); stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheel); } /** * 摄像头初始化 */ private function initCamera(camera:Camera3D):void { cameraController = new HoverController(_view3D.camera); //cameraController.distance = 800;//摄像机和目标点距离 //cameraController.minTiltAngle = 0;//摄像机以Y轴旋转最小角度 //cameraController.maxTiltAngle = 90;//摄像机以Y轴旋转最大角度 //cameraController.panAngle = 45;//摄像机以Y轴旋转角度 cameraController.tiltAngle = 15;//摄像机以X轴旋转角度 } /** * 渲染视图 */ private function _onEnterFrame(e:Event):void { //渲染视图 _view3D.render(); } /** * 使用舞台大小一直全屏 */ private function onResize(event:Event = null):void { _view3D.width = stage.stageWidth; _view3D.height = stage.stageHeight; //监控 视图一直处于右上角 _awayStats.x = stage.stageWidth - _awayStats.width; } /** * 鼠标滚轮事件 */ private function onWheel(e:MouseEvent):void { if(e.delta > 0){ if(cameraController.distance < 1000) cameraController.distance += 100; }else{ if(cameraController.distance > 600) cameraController.distance -= 100; } } /** * 鼠标按下事件 */ private function onMouseDown(event:MouseEvent):void { _view3D.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); _lastX = _view3D.mouseX; _lastY = _view3D.mouseY; } /** * 鼠标弹起事件 */ private function onMouseUp(event:MouseEvent):void { _view3D.stage.removeEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler); } /** * 鼠标移动事件 */ private function mouseMoveHandler(event:MouseEvent):void { //移动摄像机 var dx:Number = _view3D.mouseX - _lastX; var dy:Number = _view3D.mouseY - _lastY; cameraController.panAngle += dx; cameraController.tiltAngle += dy; _lastX = _view3D.mouseX; _lastY = _view3D.mouseY; } } }
全部评论(0)