上一课主要学习基本3D交互场景事件的用法,这一课记录高级用法~!
我以旋转的立方体为例,3D场景中有一个立方体,立方体的6个面每一个面都有一幅图(贴图),当鼠标点击其中的任一面时,缓动放大,再点击时缓动缩小恢复原状继续旋转。效果图如下:
鼠标未点击时不断旋转的立方体效果
鼠标点击时缓动放大效果
效果代码如下:
package
{
import
flash.display.DisplayObject;
import
org.papervision3d.materials.BitmapFileMaterial;
import
org.papervision3d.materials.utils.MaterialsList;
import
org.papervision3d.events.InteractiveScene3DEvent;
import
org.papervision3d.objects.primitives.Cube;
public class
MainAdvancedInteractiveScene3dEvent extends PaperBase
{
//---------------------------------------------------------------6个面对应的material
private var frontMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/concretetex02.jpg");
private var backMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/concretetex03.jpg");
private var leftMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/bashi.jpg");
private var
rightMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/pic12.jpg");
private var topMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/pic37.jpg");
private var bottomMaterial:BitmapFileMaterial = new
BitmapFileMaterial("img/pic43.jpg");
//---------------------------------------------------------------目标旋转初始值
private var targetrotationX:Number = 0;
private var targetrotationY:Number = 0;
private var targetrotationZ:Number = 0;
//---------------------------------------------------------------判断是否缓动
private var tweening:Boolean = false;
private var cube:Cube;
public function MainAdvancedInteractiveScene3dEvent()
{
init(550, 400);
}
override protected function init3d():void
{
frontMaterial.interactive = true;
frontMaterial.name = "front";
backMaterial.interactive = true;
backMaterial.name = "back";
leftMaterial.interactive = true;
leftMaterial.name = "left";
rightMaterial.interactive = true;
rightMaterial.name = "right";
|