Away3D Lite:Basic_InteractiveObject

初始化引擎:

scene = new Scene3D();

// 创建一个俯瞰镜头
// Extended camera used to hover round a specified target object
camera = new HoverCamera3D();
camera.focus = 50;
// 镜头距离中心点的距离
camera.distance = 1000;
// 镜头上下移动的最小角度
camera.minTiltAngle = 0;
// 镜头上下移动的最大角度
camera.maxTiltAngle = 90;
// 镜头的初始左右位置(角度)
camera.panAngle = 45;
// 镜头的初始上下位置(角度)
camera.tiltAngle = 20;
// 启动镜头俯瞰特性,必须每帧都有,不然就没有动画效果了
// Updates  the camera orientation
// Values are calculated using the defined tiltAngle, panAngle and steps variables.
// hover(true)表示使用steps属性,hover()表示不适用steps属性,默认是false
camera.hover(true);

renderer = new BasicRenderer();

view = new View3D();
view.scene = scene;
view.camera = camera;
view.renderer = renderer;

//view.addSourceURL("srcview/index.html");
addChild(view);

 

建立3D物体:

plane = new Plane();
plane.y = -20;
plane.width = 1000;
plane.height = 1000;
// sortType 表示这个物体在场景中Z-SORT的排序规则
// MeshSortType.BACK 表示以这个物体的最远点进行Z-SORT排序
// MeshSortType.CENTER 表示以这个物体的中心点进行Z-SORT排序
// MeshSortType.FRONT 表示以这个物体的最近点进行Z-SORT排序
plane.sortType = MeshSortType.BACK;
plane.segmentsW = 20;
plane.segmentsH = 20;
// Defines whether the coordinates of the plane points use a yUp orientation (true) or a zUp orientation (false).
// 确定该plane的法向量朝向,Y轴(true)还是Z轴(false)
plane.yUp = false;
scene.addChild(plane);
 

交互:判断点击的是哪个物体:

scene.addEventListener(MouseEvent3D.MOUSE_UP, onSceneMouseUp);

private function onSceneMouseUp(e:MouseEvent3D):void
{
    if (e.object is Mesh) {
        var mesh:Mesh = e.object as Mesh;
        mesh.material = new WireColorMaterial();
    }
}
 

实现拖拽镜头操作:

stage.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
addEventListener(Event.ENTER_FRAME, onEnterFrame);

private function onMouseDown(event:MouseEvent):void
{
    lastPanAngle = camera.panAngle;
    lastTiltAngle = camera.tiltAngle;
    lastMouseX = stage.mouseX;
    lastMouseY = stage.mouseY;
	move = true;
	stage.addEventListener(Event.MOUSE_LEAVE, onStageMouseLeave);
}

private function onEnterFrame(event:Event):void
{
	if (move) {
		camera.panAngle = 0.3*(stage.mouseX - lastMouseX) + lastPanAngle;
		camera.tiltAngle = 0.3*(stage.mouseY - lastMouseY) + lastTiltAngle;
	}	
    // 这句必须有
    camera.hover();  
	view.render();
}

 

Away3D Lite:Basic_InteractiveObject_第1张图片

你可能感兴趣的:(html,UP)