[ActionScript 3.0] Away3D 天空盒(skybox)例子2

所谓skybox就是六个面即六张图能够无缝的拼成一个正方体的盒子。

  1 package
  2 {
  3     import away3d.cameras.Camera3D;
  4     import away3d.cameras.lenses.PerspectiveLens;
  5     import away3d.containers.Scene3D;
  6     import away3d.containers.View3D;
  7     import away3d.controllers.HoverController;
  8     import away3d.primitives.SkyBox;
  9     import away3d.textures.BitmapCubeTexture;
 10     import away3d.utils.Cast;
 11
 12     import flash.display.Sprite;
 13     import flash.display.StageAlign;
 14     import flash.display.StageScaleMode;
 15     import flash.events.Event;
 16     import flash.events.KeyboardEvent;
 17     import flash.events.MouseEvent;
 18     import flash.ui.Keyboard;
 19
 20     /**
 21      * @author Frost.Yen
 22      * @E-mail [email protected]
 23      * @create 2015-9-28 上午10:26:21
 24      *
 25      */
 26     public class Away3dSkybox extends Sprite
 27     {
 28         //skybox
 29         [Embed(source="assets/snow_positive_x.jpg")]
 30         private var EnvPosX:Class;
 31         [Embed(source="assets/snow_positive_y.jpg")]
 32         private var EnvPosY:Class;
 33         [Embed(source="assets/snow_positive_z.jpg")]
 34         private var EnvPosZ:Class;
 35         [Embed(source="assets/snow_negative_x.jpg")]
 36         private var EnvNegX:Class;
 37         [Embed(source="assets/snow_negative_y.jpg")]
 38         private var EnvNegY:Class;
 39         [Embed(source="assets/snow_negative_z.jpg")]
 40         private var EnvNegZ:Class;
 41
 42         private var view:View3D;
 43         private var scene:Scene3D;
 44         private var camera:Camera3D;
 45         private var cameraController:HoverController;
 46         private var cubeTexture:BitmapCubeTexture;
 47         private var move:Boolean = false;
 48         private var lastPanAngle:Number;
 49         private var lastTiltAngle:Number;
 50         private var lastMouseX:Number;
 51         private var lastMouseY:Number;
 52         private var tiltSpeed:Number = 2;
 53         private var panSpeed:Number = 2;
 54         private var distanceSpeed:Number = 1000;
 55         private var tiltIncrement:Number = 0;
 56         private var panIncrement:Number = 0;
 57         private var distanceIncrement:Number = 0;
 58         public function Away3dSkybox()
 59         {
 60             initEngine();
 61             initMaterials();
 62             initObjects();
 63             initListeners();
 64         }
 65         /**
 66          * Initialise the engine
 67          */
 68         private function initEngine():void
 69         {
 70             stage.scaleMode = StageScaleMode.NO_SCALE;
 71             stage.align = StageAlign.TOP_LEFT;
 72
 73             view = new View3D();
 74             scene = view.scene;
 75             camera = view.camera;
 76             //camera.lens.far = 1000000;
 77             view.camera.lens = new PerspectiveLens(90);
 78             //setup controller to be used on the camera
 79             cameraController = new HoverController(camera, null, 0, 10, 25000, 0, 70);
 80
 81             view.addSourceURL("srcview/index.html");
 82             addChild(view);
 83         }
 84         private function initMaterials():void
 85         {
 86             //create skybox texture
 87             cubeTexture = new BitmapCubeTexture(Cast.bitmapData(EnvPosX), Cast.bitmapData(EnvNegX), Cast.bitmapData(EnvPosY), Cast.bitmapData(EnvNegY), Cast.bitmapData(EnvPosZ), Cast.bitmapData(EnvNegZ));
 88         }
 89         /**
 90          * Initialise the scene objects
 91          */
 92         private function initObjects():void
 93         {
 94             //create skybox.
 95             scene.addChild(new SkyBox(cubeTexture));
 96         }
 97         /**
 98          * Initialise the listeners
 99          */
100         private function initListeners():void
101         {
102
103             addEventListener(Event.ENTER_FRAME, onEnterFrame);
104             view.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
105             view.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
106             stage.addEventListener(Event.RESIZE, onResize);
107             stage.addEventListener(KeyboardEvent.KEY_DOWN, onKeyDown);
108             stage.addEventListener(KeyboardEvent.KEY_UP, onKeyUp);
109             onResize();
110         }
111         /**
112          * Navigation and render loop
113          */
114         private function onEnterFrame(event:Event):void
115         {
116             if (move) {
117                 cameraController.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;
118                 cameraController.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;
119             }
120
121             cameraController.panAngle += panIncrement;
122             cameraController.tiltAngle += tiltIncrement;
123             cameraController.distance += distanceIncrement;
124
125             view.render();
126         }
127
128         /**
129          * Key down listener for camera control
130          */
131         private function onKeyDown(event:KeyboardEvent):void
132         {
133             switch (event.keyCode) {
134                 case Keyboard.UP:
135                 case Keyboard.W:
136                     tiltIncrement = tiltSpeed;
137                     break;
138                 case Keyboard.DOWN:
139                 case Keyboard.S:
140                     tiltIncrement = -tiltSpeed;
141                     break;
142                 case Keyboard.LEFT:
143                 case Keyboard.A:
144                     panIncrement = panSpeed;
145                     break;
146                 case Keyboard.RIGHT:
147                 case Keyboard.D:
148                     panIncrement = -panSpeed;
149                     break;
150                 case Keyboard.Z:
151                     distanceIncrement = distanceSpeed;
152                     break;
153                 case Keyboard.X:
154                     distanceIncrement = -distanceSpeed;
155                     break;
156             }
157         }
158
159         /**
160          * Key up listener for camera control
161          */
162         private function onKeyUp(event:KeyboardEvent):void
163         {
164             switch (event.keyCode) {
165                 case Keyboard.UP:
166                 case Keyboard.W:
167                 case Keyboard.DOWN:
168                 case Keyboard.S:
169                     tiltIncrement = 0;
170                     break;
171                 case Keyboard.LEFT:
172                 case Keyboard.A:
173                 case Keyboard.RIGHT:
174                 case Keyboard.D:
175                     panIncrement = 0;
176                     break;
177                 case Keyboard.Z:
178                 case Keyboard.X:
179                     distanceIncrement = 0;
180                     break;
181             }
182         }
183
184         /**
185          * Mouse down listener for navigation
186          */
187         private function onMouseDown(event:MouseEvent):void
188         {
189             move = true;
190             lastPanAngle = cameraController.panAngle;
191             lastTiltAngle = cameraController.tiltAngle;
192             lastMouseX = stage.mouseX;
193             lastMouseY = stage.mouseY;
194             stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
195         }
196
197         /**
198          * Mouse up listener for navigation
199          */
200         private function onMouseUp(event:MouseEvent):void
201         {
202             move = false;
203             stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
204         }
205
206         /**
207          * Mouse stage leave listener for navigation
208          */
209         private function onStageMouseLeave(event:Event):void
210         {
211             move = false;
212             stage.removeEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
213         }
214
215         /**
216          * stage listener for resize events
217          */
218         private function onResize(event:Event = null):void
219         {
220             view.width = stage.stageWidth;
221             view.height = stage.stageHeight;
222         }
223     }
224 }
时间: 2024-10-15 08:49:43

[ActionScript 3.0] Away3D 天空盒(skybox)例子2的相关文章

[ActionScript 3.0] Away3D 官网实例

1 /* 2 3 Dynamic tree generation and placement in a night-time scene 4 5 Demonstrates: 6 7 How to create a height map and splat map from scratch to use for realistic terrain 8 How to use fratacl algorithms to create a custom tree-generating geometry

[ActionScript 3.0] Away3D 旋转效果

1 package 2 { 3 import away3d.containers.View3D; 4 import away3d.entities.Mesh; 5 import away3d.events.MouseEvent3D; 6 import away3d.materials.TextureMaterial; 7 import away3d.primitives.PlaneGeometry; 8 import away3d.utils.Cast; 9 10 import flash.di

ActionScript 3.0 for the Lunder Algorithm

package com.feiruo.Calendar.LunderCalendar { /* *@ClassName: package:com.feiruo.Calendar.LunderCalendar::LunarDate *@INTRO: Calculating lunar and solar terms and other settings. *@Author: feiruo *@Language: ActionScript 3.0 *@SDKVersion: Flash Player

在 Flash ActionScript 2.0 中调用 Javascript 方法

本篇文章由:http://xinpure.com/call-the-javascript-method-in-flash-actionscript-2-0/ 在 Flash ActionScript 2.0 中调用 Javascript 方法 最近在工作中,有个这样的需求: 要从 Flash ActionScript 2.0 中调用网页上的 Javascript 方法 这是一个关于 Flash 和 Javascript 交互的问题. 在 ActionScript 2.0 中调用外部 javasc

ActionScript 3.0日期与时间管理(Date类)

/*Flash中,Date类管理着日期和时间信息.要获取   当前日期,可以新建一个Date对象   */var now:Date =new Date();trace (now);     /*输出当前时间和日期,格式如:                  Sun Jul 27 19:45:57 GMT+0800 2014  */ /*以上代码中,Date对象中包括了当前的秒.分.小时.  星期数.日.月.年.时区等信息...如果仅需要返  回星期值和日期值,而不返回时间或时区,可以使用Date

ActionScript 3.0数组操作

var arr:Array=new Array();arr=["a","b","c"];  //赋初值,注意这里的即使单个字符赋值使用的是""trace(arr[1]);       //获取成员信息trace(arr.length);    //获取数组中所包含的元素的个数 //接下来使用for循环逐个输出数组的每一个元素,这也称为数组的遍历var loopTime:int=arr.length;for (var i:int

[ActionScript 3.0] 正则表达式

正则表达式: 正则表达式最早是由数学家Stephen Kleene在对自然语言的递增研究成果的基础上,于1956提出来的.具有完整语法的正则表达式,主要使用在字符串的格式的匹配方面上,后来也逐渐应用到信息技术领域.不同的编程语言对于正则表达式有细微的不同,ActionScript 3.0是按照ECMAScript第3版语言规范(ECMA-262)中的定义实现正则表达式. 熟悉windows操作系统读者,应该知道windows中是怎样查找文件的.不错,使用通配符“*”用来匹配任意字符,“?”用来匹

ActionScript 3.0 加载外部SWF素材资源MovieClip,SimpleButton不支持鼠标事件

我们用flash buidler加载素材一般有三种途径: 1.SWC,这种方式会增大SWF的大小 2.flash cs项目关联 3.SWF专门放素材资源通过Loader方式加载 今天发现通过SWF加载方式有个问题要加载的素材如下图: A:是一个MC,里面放了一个B:mc,C:SimpleButton 问题:加载进A后对A添加鼠标事件如CLICK事件,单击B或C时没有反映? 开始我的加载方式是这样的: 目录结构如图: 代码如下: 1 package 2 { 3 import flash.displ

[ActionScript 3.0] as3处理xml的功能和遍历节点

as3比as2处理xml的功能增强了N倍,获取或遍历节点非常之方便,类似于json对像的处理方式. XML 的一个强大功能是它能够通过文本字符的线性字符串提供复杂的嵌套数据.将数据加载到 XML 对象时,ActionScript 会分析数据并将其分层结构加载到内存(如果 XML 数据格式有误,它会发送运行时错误). 利用 XML 和 XMLList 对象的运算符和方法可以轻松遍历 XML 数据的结构. 1.读取外部 XML 文档 可以使用 URLLoader 类从 URL 加载 XML 数据.若