- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
1.Interactivity 交互
在3D 场景中尼可以使用下面两种类型的鼠标交互
通过材质
通过一个3D 对象
要与材质或者3D 对象进行鼠标交互必须先设置viewport 的interactive 属性为***e。Viewport 的interactive
属性默认为false。viewport.interactive = ***e;如果类是继承自BasicView,那么也可以通过下面的方法来实现:
super(640,480,false,***e);
请一定要在startRendering()方法执行前,先条用super()方法。
还有一种方法,就是在创建一个Viewport3D 对象时,用参数来指定:
var viewport:Viewport3D = new Viewport3D(640,480,false,***e);为了能通过材质进行交互,必须将材质的interactive 属性设为***e:material.interactive = ***e;所有的材质
类型都有这个属性
2.材质交互(Material interactivity) 如: private function init():void{
viewport.interactive = ***e;
var material:MovieAssetMaterial = new MovieAssetMaterial("material",false,***e,false,***e);
material.doubleSided = ***e;
material.rect = new Rectangle(0,0,200,200);
material.smooth = ***e;
material.precisionMode = PrecisionMode.STABLE;
material.interactive = ***e;
MovieClip(MovieClip(material.movie).getChildByName("btn")).mouseChildren = false;
MovieClip(material.movie).getChildByName("btn").addEventListener(MouseEvent.CLICK,click);
MovieClip(material.movie).getChildByName("btn").addEventListener(MouseEvent.MOUSE_OVER,mouseOver);
MovieClip(material.movie).getChildByName("btn").addEventListener(MouseEvent.MOUSE_OUT,mouseOut); plane = new Plane(material,500,500);
scene.addChild(plane);
} private function click(e:MouseEvent):void
{
var buttonText:TextField = MovieClip(e.target).getChildByName("label") as TextField;
switch(buttonText.text)
{
case "start":
buttonText.text = "stop";
MovieClip( MovieClip(e.target).parent ).play();
break;
default:
buttonText.text = "start";
MovieClip( MovieClip(e.target).parent ).stop();
}
}
private function mouseOver(e:MouseEvent):void
{
viewport.buttonMode = ***e;
}
private function mouseOut(e:MouseEvent):void
{
viewport.buttonMode = false;
} 3.除了材质交互,我们还有物体对象交互,这个在我们想要对整个物体进行交互时就会很有用。可以向3D
物体添加事件侦听然后就等待响应了private function init():void{
viewport.interactive = ***e;
var material:ColorMaterial = new ColorMaterial();
material.doubleSided = ***e;
material.interactive = ***e; var planelane = new Plane(material);
//添加交互事件
plane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK,click);
scene.addChild(plane);
}private function click(e:InteractiveScene3DEvent):void{
e.displayObject3D.localRotationY +=12;
}
do3D会发出如下事件:
InteractiveScene3DEvent.OBJECT_ADDED
InteractiveScene3DEvent.OBJECT_CLICK
InteractiveScene3DEvent.OBJECT_DOUBLE_CLICK
InteractiveScene3DEvent.OBJECT_MOVE
InteractiveScene3DEvent.OBJECT_OUT
InteractiveScene3DEvent.OBJECT_OVER
InteractiveScene3DEvent.OBJECT_PRESS
InteractiveScene3DEvent.OBJECT_RELEASE
InteractiveScene3DEvent.OBJECT_RELEASE_OUTSIDE
【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/ |
|