package { import flash.display.*; import flash.events.*; import org.papervision3d.core.proto.*; import org.papervision3d.scenes.*; import org.papervision3d.objects.*; import org.papervision3d.cameras.*; import org.papervision3d.materials.*; import caurina.transitions.*; [SWF( backgroundColor="0xffffff", frameRate="45" ) ] public class Plane3D extends Sprite { private var container : Sprite; private var scene : Scene3D; private var camera : Camera3D; // camera private var rootNode : DisplayObject3D; private var obj : DisplayObject3D ; //object private var size : int = 100;//object's size private var segment : int = 3; //object's segment private var material : MaterialObject3D; //object's material private var isTween : Boolean; // flag of tween private var original : Array; //Original Position //--------------------------------------------Constructor public function Plane3D():void { //super classのstage this.stage.quality = "MEDIUM"; this.stage.scaleMode = "noScale"; this.stage.align = StageAlign.TOP_LEFT; this.stage.addEventListener(Event.ENTER_FRAME, loop); this.stage.addEventListener(Event.RESIZE, resize); //containerの生成 container = new Sprite(); container.x = this.stage.stageWidth / 2; container.y = this.stage.stageHeight / 2; addChild(container); //sceneの生成 scene = new Scene3D(container); //rootNodeの生成 rootNode = new DisplayObject3D("rootNode"); scene.addChild(rootNode); //materialの設定 material = new BitmapFileMaterial( "http://www.adamrocker.com/blog/wp-content/uploads/2008/04/adamrocker.jpg" ); material.doubleSided = true; //objectの生成 obj = new Plane(material, size*6/5, size*8/5, segment, segment); //obj.rotationY = 10; //obj.rotationX = 0; rootNode.addChild(obj); //cameraの設定 camera = new Camera3D(); camera.z = -size; camera.focus = 300; camera.zoom = 2; //Tweenのstatus flag isTween = false; //originalのポジションを保存 original = new Array(obj.geometry.vertices); //event listenerの登録 container.addEventListener(MouseEvent.CLICK, clickObj); } //--------------------------------------------loop private function loop(event:Event):void { scene.renderCamera(camera); } //--------------------------------------------stage private function resize(e:Event):void{ container.x = this.stage.stageWidth / 2; container.y = this.stage.stageHeight / 2; } //--------------------------------------------mouse click private function clickObj (e:MouseEvent):void { var i:*= obj.geometry.vertices; if(isTween) { movePoint(i[1], -10, 30, -10); movePoint(i[5], -5, 30, -10); movePoint(i[9], 5, 30, -10); movePoint(i[13], 10, 30, -10); movePoint(i[2], -5, 50, -20); movePoint(i[6], 0, 50, -20); movePoint(i[10], 0, 50, -20); movePoint(i[14], 5, 50, -20); movePoint(i[3], 0, 70, 0); movePoint(i[7], 0, 70, 0); movePoint(i[11], 0, 70, 0); movePoint(i[15], 0, 70, 0); isTween = false; } else { movePoint(i[1], 10, -30, 10); movePoint(i[5], 5, -30, 10); movePoint(i[9], -5, -30, 10); movePoint(i[13], -10, -30, 10); movePoint(i[2], 5, -50, 20); movePoint(i[6], 0, -50, 20); movePoint(i[10], 0, -50, 20); movePoint(i[14], -5, -50, 20); movePoint(i[3], 0, -70, 0); movePoint(i[7], 0, -70, 0); movePoint(i[11], 0, -70, 0); movePoint(i[15], 0, -70, 0); isTween = true; } scene.renderCamera(camera); } private function movePoint(p:*, diffX:Number, diffY:Number, diffZ:Number):void { Tweener.addTween(p, {x:(p.x + diffX), y:(p.y + diffY), z:(p.z + diffZ), time:1, delay:0, transition:"easeOutElastic"}); } } }