[ActionScript 3.0] Away3D 非skybox的全景例子

  1 package
  2 {
  3     import away3d.containers.View3D;
  4     import away3d.controllers.HoverController;
  5     import away3d.entities.Mesh;
  6     import away3d.materials.TextureMaterial;
  7     import away3d.primitives.SphereGeometry;
  8     import away3d.utils.Cast;
  9     
 10     import flash.display.Sprite;
 11     import flash.display.StageAlign;
 12     import flash.display.StageScaleMode;
 13     import flash.events.Event;
 14     import flash.events.MouseEvent;
 15     
 16     /**
 17      * @author Frost.Yen
 18      * @E-mail 871979853@qq.com
 19      * @create 2015-9-23 下午3:18:40
 20      *
 21      */
 22     [SWF(width='800',height='600',frameRate="60", backgroundColor="0x000000")]
 23 
 24     
 25     public class Away3dOverall extends Sprite
 26     {
 27         [Embed(source = "assets/1.jpg")]
 28         private static var BallMaterial:Class;
 29         private var _startX:Number;
 30         private var _startY:Number;
 31         private var _mouseX:Number;
 32         private var _mouseY:Number;
 33         private var _view:View3D;
 34         private var _cameraHoverController:HoverController;
 35         private var _sphere:SphereGeometry;
 36         private var _sphereMaterial:TextureMaterial;
 37         private var _mesh:Mesh;
 38         public function Away3dOverall()
 39         {
 40             if (stage) {
 41                 init();
 42             }else {
 43                 this.addEventListener(Event.ADDED_TO_STAGE, init);
 44             }
 45 
 46         }
 47         private function init(e:Event = null):void {
 48             stage.scaleMode = StageScaleMode.NO_SCALE;
 49             stage.align = StageAlign.TOP_LEFT;
 50             this.removeEventListener(Event.ADDED_TO_STAGE, init);
 51             
 52             _view = new View3D();
 53             addChild(_view);
 54             _view.antiAlias = 6;
 55             //摄像机渲染范围2000
 56             _view.camera.lens.far = 2000;
 57             
 58             _cameraHoverController = new HoverController(_view.camera, null, 90, 0, 300);
 59             _cameraHoverController.yFactor = 1;
 60             _sphere = new SphereGeometry(1000, 64);
 61             //_sphere.yUp = false;
 62             _sphereMaterial = new TextureMaterial(Cast.bitmapTexture(BallMaterial));
 63             _sphereMaterial.bothSides = true;
 64             _sphereMaterial.smooth = true;
 65             _mesh = new Mesh(_sphere, _sphereMaterial);
 66             //MeshHelper.invertFaces(_mesh);
 67             
 68             _view.camera.position = _mesh.position;
 69             
 70             _view.scene.addChild(_mesh);this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
 71             stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownFunction);
 72             stage.addEventListener(MouseEvent.MOUSE_WHEEL, onWheel);
 73         }
 74         private function onWheel(e:MouseEvent):void 
 75         {
 76             if (e.delta > 0) {
 77                 if (_cameraHoverController.distance > 6) {
 78                     _cameraHoverController.distance -= 5;
 79                 }
 80             }else if (e.delta < 0) {
 81                 if (_cameraHoverController.distance < 600) {
 82                     _cameraHoverController.distance += 5;
 83                 }
 84             }
 85         }
 86         
 87         private function mouseDownFunction(e:MouseEvent):void 
 88         {
 89             _startX = _cameraHoverController.panAngle;
 90             _startY = _cameraHoverController.tiltAngle;
 91             _mouseX = mouseX;
 92             _mouseY = mouseY;
 93             stage.addEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunction);
 94             stage.addEventListener(MouseEvent.MOUSE_UP,mouseUpFunction);
 95         }
 96         
 97         private function mouseUpFunction(e:MouseEvent):void 
 98         {
 99             stage.removeEventListener(MouseEvent.MOUSE_MOVE,mouseMoveFunction);
100             stage.removeEventListener(MouseEvent.MOUSE_UP,mouseUpFunction);
101             //stage.addEventListener(MouseEvent.MOUSE_DOWN,mouseDownFunction);
102         }
103         
104         private function mouseMoveFunction(e:MouseEvent):void 
105         {
106             _cameraHoverController.panAngle = (mouseX - _mouseX) * .3 + _startX;
107             _cameraHoverController.tiltAngle = (mouseY - _mouseY) * .3 + _startY;
108         }
109         
110         private function onEnterFrame(e:Event):void 
111         {
112             _view.render();
113         }
114 
115     }
116 }

需要一张无缝全景图,像这样的:

------------------------------------------------------------------ Always put yourself in the other's shoes.If you feel that it hurts you,it probably hurts others,too.------------------------------------------------------------------
posted on 2015-11-27 11:04  晏过留痕  阅读(359)  评论(0编辑  收藏  举报