Away3D是当前流行的Flash3D引擎,这里写一下它的FlashBuilder配置方法,供各位查阅参考。
首先安装FlashBuilder4.6,这个过程这里不再赘述。
这里是Away3D的官网http://away3d.com/,下载一个“away3d-core-fp11_4_0_9_gold.zip”的文件,解压缩到D盘目录下(其他目录也可以)。
打开FlashBuilder,新建“ActionScript项目”,过程这里省略。
在“包资源管理器”,项目上点右键->“属性”,弹出的对话框左边找“资源”->“ActionScript构建路径”,右边的选项卡中选择“源路径”,点击右边的“添加文件夹”,添加“D:\away3d-core-fp11_4_0_9_gold\src”即可,“确定”关闭对话框。
这里提供一个例子代码,如果类名字不一样请相应修改:
package
{
import flash.display.Sprite;
import away3d.cameras.Camera3D;
import away3d.containers.View3D;
import away3d.controllers.FirstPersonController;
import away3d.controllers.HoverController;
import away3d.controllers.LookAtController;
import away3d.debug.Trident;
import away3d.entities.Mesh;
import away3d.lights.PointLight;
import away3d.materials.ColorMaterial;
import away3d.materials.lightpickers.StaticLightPicker;
import away3d.primitives.CubeGeometry;
import away3d.primitives.SphereGeometry;
import away3d.primitives.WireframePrimitiveBase;
import flash.display.*;
import flash.display.Sprite;
import flash.events.*;
import flash.events.Event;
import flash.geom.Vector3D;
[SWF(width="1024",height='768')]
public class Away3DNewProject extends Sprite
{
private var view:View3D;
private var spher:SphereGeometry;
private var cube:CubeGeometry;
private var mesh:Mesh;
private var color:ColorMaterial;
private var wiref:WireframePrimitiveBase;
private var light:PointLight;
private var staticlight:StaticLightPicker;
private var lix:Trident;
private var boolean:Boolean;
private var camera:Camera3D;
private var cameraZ:Number=800;
private var cameraxyz:Number;
private var mouseXAxis:Number;
//鼠标点击时X坐标
private var mouseYAxis:Number;
//鼠标点击时y坐标
private var mX:Number;
private var mY:Number;
private var firstController:HoverController;
//第一人控制器
public function Away3DNewProject()
{
//构造函数
this.addEventListener(Event.ENTER_FRAME,onAnimation);
this.addEventListener(MouseEvent.CLICK,onClick);
this.addEventListener(MouseEvent.MOUSE_DOWN,onDown);
//stage.addEventListener(MouseEvent.MOUSE_WHEEL,onMouse);
//用来渲染动画的,逐针事件。
initView();
initModel();
}
/* private function onMouse(e:MouseEvent):void{
if(e.delta>0){
camera.z-=100;
}
else
{camera.z+=100;
}
}*/
private function onDown(e:MouseEvent):void{
boolean= true;
mouseXAxis=stage.mouseX;
mouseYAxis=stage.mouseY;
//鼠标当前位置
mX=firstController.panAngle;
mY=firstController.tiltAngle;
boolean = true;
trace("点击");
}
private function onClick(e:MouseEvent):void{
boolean = false;
trace("点击放开");
}
private function initView():void{
lix = new Trident(500,true);
//坐标轴
view = new View3D();
view.backgroundColor = 0x00000f;
//设置背景颜色
view.antiAlias = 2;
//抗锯齿
addChild(view);
camera = new Camera3D();
//camera.z = 1000;
view.camera=camera;
// firstController =new FirstPersonController(camera, 180, 0, -60, 80);
light = new PointLight();
light.x=200;
light.z=200;
light.y=100;
light.color = 0xFF0000;
//灯光漫反射
light.diffuse = 1;
//灯光反射
light.specular = 100;
//灯光环绕范围
light.showBounds = true;
staticlight= new StaticLightPicker([light]);
}
private function initModel():void{
spher = new SphereGeometry(200);
//wiref = new WireframePrimitiveBase(0xffffff)
color = new ColorMaterial(0xFFD306);
cube = new CubeGeometry(200,500,25,1,1,1,true);
//x,y,z
mesh = new Mesh(cube,color);
mesh.material.lightPicker=staticlight;
view.scene.addChild(mesh);
view.scene.addChild(lix);
firstController =new HoverController(camera,mesh,0,0,1000,-90,90,NaN,NaN,8,1);
}
private function onAnimation(e:Event):void{
view.render();
if(boolean==true)
{
firstController.panAngle = 0.3*(stage.mouseX - mouseXAxis) + mX;
firstController.tiltAngle = 0.3*(stage.mouseY - mouseYAxis) + mY;
camera.lookAt(new Vector3D(0,0,0));
//trace(view.camera.z);
//mesh.rotationY++;
//View.camera.y++;
}
}
}
}
欢迎加入Flash3D技术交流群,号码274769317