1,使用LineSegment创建线段
(2)将创建好的一系列线条添加到SegmentSet,最后将SegmentSet添加到View3D里。
代码如下所示
package{
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.geom.Vector3D;
import away3d.containers.View3D;
import away3d.controllers.HoverController;
import away3d.entities.Mesh;
import away3d.entities.SegmentSet;
import away3d.materials.TextureMaterial;
import away3d.primitives.CubeGeometry;
import away3d.primitives.LineSegment;
import away3d.utils.Cast;
[SWF(frameRate="60", backgroundColor="#FFFFFF")]
public class S3 extends Sprite {
private var _view3D:View3D;
private var cameraController:HoverController;//360全景展示相机控制器
//地板图片(用作地板的纹理 )
[Embed(source="assets/road.jpg")]
private var floorClass:Class;
//地板材质
private var floorMaterial:TextureMaterial;
private var lastPanAngle:Number;
private var lastTiltAngle:Number;
private var lastMouseX:Number;
private var lastMouseY:Number;
private var move:Boolean;
public function S3() {
initEngine();
initMaterials();
initObjects();
initListeners();
}
/**
* 初始化引擎
*/
private function initEngine():void
{
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;
// 创建一个视口
_view3D = new View3D();
_view3D.antiAlias = 4; //设置抗锯齿级别
//初始化摄像头
cameraController = new HoverController(_view3D.camera);
/*cameraController.distance = 1000;
cameraController.minTiltAngle = 0;
cameraController.maxTiltAngle = 90;
cameraController.panAngle = 45;*/
cameraController.tiltAngle = 15;
addChild(_view3D);
}
/**
* 初始化材质
*/
private function initMaterials():void
{
//地板的纹理
floorMaterial = new TextureMaterial(Cast.bitmapTexture(floorClass));
}
/**
* 初始化物体
*/
private function initObjects():void
{
// 在三维舞台中创建一个方块(地板 )
var cube1:Mesh = new Mesh(new CubeGeometry(700, 20, 500), floorMaterial);
_view3D.scene.addChild(cube1);
//创建线条
var linesContainer:SegmentSet = new SegmentSet();
//线的两端点,粗细,起始端颜色,结束端颜色
var line:LineSegment = new LineSegment(new Vector3D(0,0,0),new Vector3D(200,200,200),
0xFF0000,0x00FF00,1);
linesContainer.addSegment(line);
_view3D.scene.addChild(linesContainer);
}
/**
* 初始化监听
*/
private function initListeners():void
{
addEventListener(Event.ENTER_FRAME, _onEnterFrame);
//鼠标事件监听
stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
stage.addEventListener(MouseEvent.MOUSE_UP, onMouseUp);
stage.addEventListener(MouseEvent.MOUSE_WHEEL,onWheel);
stage.addEventListener(Event.RESIZE, onResize);
onResize();
}
/**
* 渲染视图
*/
private function _onEnterFrame(e:Event):void
{
//移动视角
if (move) {
cameraController.panAngle = 0.3 * (stage.mouseX - lastMouseX) + lastPanAngle;
cameraController.tiltAngle = 0.3 * (stage.mouseY - lastMouseY) + lastTiltAngle;
}
//渲染视图
_view3D.render();
}
/**
* 使用舞台大小一直全屏
*/
private function onResize(event:Event = null):void
{
_view3D.width = stage.stageWidth;
_view3D.height = stage.stageHeight;
}
/**
* 鼠标滚轮事件
*/
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
{
lastPanAngle = cameraController.panAngle;
lastTiltAngle = cameraController.tiltAngle;
lastMouseX = stage.mouseX;
lastMouseY = stage.mouseY;
move = true;
}
/**
* 鼠标弹起事件
*/
private function onMouseUp(event:MouseEvent):void
{
move = false;
}
}
}
火柴人忍者3v3M0D版内置功能菜单 v5.5
下载重生细胞腾讯版 安卓版v3.5.2-bilibili-UO
下载拳皇命运体验服 最新免费版v2.31.000
下载地牢杀手无限生命版 内置修改器最新版v0.707.12
下载天天爱烹饪 安卓版1.1.1
天天爱烹饪是由润谦科技游戏厂商出品的美食烹饪餐厅模拟经营休闲
我的世界RLCraft任务汉化版 安卓版v2.9.1
我的世界RLCraft任务汉化版是一个非常有趣的整合包,游戏
光与夜之恋内测版 最新版v1.8.0803
光与夜之恋是一款女性向恋爱养成游戏,精美的画面,丰富的剧情故
光与夜之恋台服 安卓版v1.8.0803
光与夜之恋是一款高品质恋爱互动式养成游戏,超一线画师及豪华编
俄罗斯乡村模拟器3D 手机版v1.8.2
俄罗斯乡村模拟器(Russian Village Simul