※現在、「wonderfl build flash online」求人コンテンツ制作に関してのアンケートを実施中です!みなさまのお力添えを頂いて、続々とアンケート結果が集まっていますが、まだまだ募集しております。ご協力のほど、どうぞよろしくお願いいたします!

wonderfl運営事務局
→アンケートページ(※ログインしてからお答えいただけるようになっています。)

 notice: Flash editor updated! Join the development! Thanks to MiniBuilder


forked from : clockmaker's Ginny Effect Modoki [diff(177)]

FORKED
  1. // forked from clockmaker's Ginny Effect 3D
  2. /**
  3.  * Ginny Effect 3D
  4.  * 
  5.  * Photo by 
  6.  * http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
  7.  */
  8. package {
  9.     import flash.display.*;
  10.     import flash.events.*;
  11.     import flash.geom.*;
  12.     import flash.net.*;
  13.     import flash.system.*;
  14.     import flash.utils.*;
  15.     import org.libspark.betweenas3.BetweenAS3;
  16.     import org.libspark.betweenas3.easing.*;
  17.     import org.libspark.betweenas3.tweens.ITween;
  18.     import org.papervision3d.core.geom.renderables.Vertex3D;
  19.     import org.papervision3d.core.utils.Mouse3D;
  20.     import org.papervision3d.events.InteractiveScene3DEvent;
  21.     import org.papervision3d.materials.BitmapMaterial;
  22.     import org.papervision3d.objects.primitives.Plane;
  23.     import org.papervision3d.render.QuadrantRenderEngine;
  24.     import org.papervision3d.view.BasicView;
  25.     import com.bit101.components.*;
  26.     
  27.     [SWF(frameRate = 30)]
  28.     public class Main extends BasicView {
  29.             
  30.         private const IMAGE_URL:String = "http://farm4.static.flickr.com/3190/2662752839_249c6642b1.jpg";
  31.         private const IMG_W:Number = 500 * 2;
  32.         private const IMG_H:Number = 375 * 2;
  33.         private const SEGMENT:int = 12;
  34.         private const PLANE_Y:int = 500;
  35.         private const FLOOR_LENGTH:int = 3000;
  36.         private var loader:Loader;
  37.         private var isHide:Boolean = false;
  38.         private var isShift:Boolean = false;
  39.         private var plane:Plane;
  40.         private var floorPlane:Plane;
  41.         private var tween:ITween;
  42.         private var vertexs:Array = [];
  43.           
  44.         public function Main():void {
  45.             // init
  46.             super(00truetrue);
  47.             stage.quality = StageQuality.LOW;
  48.             
  49.             // 3dの初期化
  50.             Mouse3D.enabled = true;
  51.             renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
  52.             viewport.opaqueBackground = 0x0;
  53.                     
  54.             // load
  55.             var context:LoaderContext = new LoaderContext(true);
  56.             loader = new Loader();
  57.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
  58.             loader.load(new URLRequest(IMAGE_URL), context);
  59.             
  60.             // とりあえず説明
  61.             new Label(this360440"PLEASE CLICK STAGE");
  62.         }
  63.         
  64.         private function compHandler(e:Event):void {
  65.             // 写真のマテリアル
  66.             var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
  67.             plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
  68.             scene.addChild(plane);
  69.             
  70.             // 各頂点の座標を配列に格納しておく
  71.             var i:int = 0, xx:int, yy:int;
  72.             for (xx = 0; xx < SEGMENT; xx++) {
  73.                 vertexs[xx] = [];
  74.                 for (yy = 0; yy < SEGMENT; yy++) {
  75.                     var v:Vertex3D = plane.geometry.vertices[i++];
  76.                     vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
  77.                 }
  78.             }
  79.             
  80.             // 地面を作る: タイルの作り方はrectさんのを参考
  81.             var bmd:BitmapData = new BitmapData(22false);
  82.             bmd.setPixel(00, 0xDDDDDD);
  83.             bmd.setPixel(01, 0xFFFFFF);
  84.             bmd.setPixel(10, 0xFFFFFF);
  85.             bmd.setPixel(11, 0xDDDDDD);
  86.             
  87.             var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
  88.             floorMat.tiled = true;
  89.             floorMat.maxU = 20, floorMat.maxV = 20;
  90.             floorMat.interactive = true;
  91.             
  92.             floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 55);
  93.             scene.addChild(floorPlane);
  94.             floorPlane.rotationX = 90;
  95.             floorPlane.y = - PLANE_Y;
  96.             floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
  97.             
  98.             // いろいろイベントを登録
  99.             addEventListener(Event.ENTER_FRAME, loop);
  100.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  101.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  102.             startRendering();
  103.         }
  104.         
  105.         private function clickHandler(e:InteractiveScene3DEvent):void {
  106.             // トゥイーン実行中なら終了
  107.             if (tween) if (tween.isPlaying) return;
  108.                
  109.             // クリックした点のワールド座標を取得
  110.             var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
  111.             var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
  112.             var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
  113.             
  114.             // いろいろ変数
  115.             var tweens:Array = [];
  116.             var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
  117.             
  118.             // 各頂点ごとにトゥイーンを設定
  119.             for (xx = 0; xx < SEGMENT; xx++) {
  120.                 for (yy = 0; yy < SEGMENT; yy++) {
  121.                     // 各頂点のオリジナルの位置
  122.                     var bx:Number = vertexs[xx][yy].x;
  123.                     var by:Number = vertexs[xx][yy].y;
  124.                     var bz:Number = vertexs[xx][yy].z;
  125.                      
  126.                     // クリックした点までの距離を測定
  127.                     distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
  128.                          
  129.                     // 遅延を設定
  130.                     delay = distance / 1500;
  131.                     
  132.                     // 頂点制御 PV3Dだと楽チン
  133.                     var v:Vertex3D = plane.geometry.vertices[i++];
  134.                     
  135.                     // BetweenAS3
  136.                     tweens.push(
  137.                         BetweenAS3.delay(
  138.                             BetweenAS3.tween(v,
  139.                                 { x : vx, y : vy, z : vz },
  140.                                 { x : bx, y : by, z : bz },
  141.                                 delay, Cubic.easeIn),
  142.                             delay / 2)
  143.                         );
  144.                 }
  145.             }
  146.             
  147.             // ごにょごにょ
  148.             tween = BetweenAS3.parallelTweens(tweens);
  149.             if (isHide) tween = BetweenAS3.reverse(tween);
  150.             if (isShift) tween = BetweenAS3.scale(tween, 5);
  151.             tween.play();
  152.             
  153.             isHide = !isHide;
  154.         }
  155.         
  156.         private function loop(e:Event = null):void {
  157.             // 角度に応じてカメラの位置を設定
  158.             camera.x = 1000 * Math.sin(getTimer() / 3000);
  159.             camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
  160.             camera.z = -750;
  161.         }
  162.         
  163.         /**
  164.          * Shiftキーを押してるとスローモーションになる
  165.          * macの挙動と同じように
  166.          */
  167.         private function keyUpHandler(e:KeyboardEvent):void {
  168.             if(e.keyCode == 16) isShift = false;
  169.         }
  170.         
  171.         private function keyDownHandler(e:KeyboardEvent):void {
  172.             if(e.keyCode == 16) isShift = true;
  173.         }
  174.     }
  175. }
noswf
  1. // forked from clockmaker's Ginny Effect 3D
  2. /**
  3.  * Ginny Effect 3D
  4.  * 
  5.  * Photo by 
  6.  * http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
  7.  */
  8. package {
  9.     import flash.display.*;
  10.     import flash.events.*;
  11.     import flash.geom.*;
  12.     import flash.net.*;
  13.     import flash.system.*;
  14.     import flash.utils.*;
  15.     import org.libspark.betweenas3.BetweenAS3;
  16.     import org.libspark.betweenas3.easing.*;
  17.     import org.libspark.betweenas3.tweens.ITween;
  18.     import org.papervision3d.core.geom.renderables.Vertex3D;
  19.     import org.papervision3d.core.utils.Mouse3D;
  20.     import org.papervision3d.events.InteractiveScene3DEvent;
  21.     import org.papervision3d.materials.BitmapMaterial;
  22.     import org.papervision3d.objects.primitives.Plane;
  23.     import org.papervision3d.render.QuadrantRenderEngine;
  24.     import org.papervision3d.view.BasicView;
  25.     import com.bit101.components.*;
  26.     
  27.     [SWF(frameRate = 30)]
  28.     public class Main extends BasicView {
  29.             
  30.         private const IMAGE_URL:String = "http://farm4.static.flickr.com/3190/2662752839_249c6642b1.jpg";
  31.         private const IMG_W:Number = 500 * 2;
  32.         private const IMG_H:Number = 375 * 2;
  33.         private const SEGMENT:int = 12;
  34.         private const PLANE_Y:int = 500;
  35.         private const FLOOR_LENGTH:int = 3000;
  36.         private var loader:Loader;
  37.         private var isHide:Boolean = false;
  38.         private var isShift:Boolean = false;
  39.         private var plane:Plane;
  40.         private var floorPlane:Plane;
  41.         private var tween:ITween;
  42.         private var vertexs:Array = [];
  43.           
  44.         public function Main():void {
  45.             // init
  46.             super(00truetrue);
  47.             stage.quality = StageQuality.LOW;
  48.             
  49.             // 3dの初期化
  50.             Mouse3D.enabled = true;
  51.             renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
  52.             viewport.opaqueBackground = 0x0;
  53.                     
  54.             // load
  55.             var context:LoaderContext = new LoaderContext(true);
  56.             loader = new Loader();
  57.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
  58.             loader.load(new URLRequest(IMAGE_URL), context);
  59.             
  60.             // とりあえず説明
  61.             new Label(this360440"PLEASE CLICK STAGE");
  62.         }
  63.         
  64.         private function compHandler(e:Event):void {
  65.             // 写真のマテリアル
  66.             var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
  67.             plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
  68.             scene.addChild(plane);
  69.             
  70.             // 各頂点の座標を配列に格納しておく
  71.             var i:int = 0, xx:int, yy:int;
  72.             for (xx = 0; xx < SEGMENT; xx++) {
  73.                 vertexs[xx] = [];
  74.                 for (yy = 0; yy < SEGMENT; yy++) {
  75.                     var v:Vertex3D = plane.geometry.vertices[i++];
  76.                     vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
  77.                 }
  78.             }
  79.             
  80.             // 地面を作る: タイルの作り方はrectさんのを参考
  81.             var bmd:BitmapData = new BitmapData(22false);
  82.             bmd.setPixel(00, 0xDDDDDD);
  83.             bmd.setPixel(01, 0xFFFFFF);
  84.             bmd.setPixel(10, 0xFFFFFF);
  85.             bmd.setPixel(11, 0xDDDDDD);
  86.             
  87.             var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
  88.             floorMat.tiled = true;
  89.             floorMat.maxU = 20, floorMat.maxV = 20;
  90.             floorMat.interactive = true;
  91.             
  92.             floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 55);
  93.             scene.addChild(floorPlane);
  94.             floorPlane.rotationX = 90;
  95.             floorPlane.y = - PLANE_Y;
  96.             floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
  97.             
  98.             // いろいろイベントを登録
  99.             addEventListener(Event.ENTER_FRAME, loop);
  100.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  101.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  102.             startRendering();
  103.         }
  104.         
  105.         private function clickHandler(e:InteractiveScene3DEvent):void {
  106.             // トゥイーン実行中なら終了
  107.             if (tween) if (tween.isPlaying) return;
  108.                
  109.             // クリックした点のワールド座標を取得
  110.             var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
  111.             var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
  112.             var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
  113.             
  114.             // いろいろ変数
  115.             var tweens:Array = [];
  116.             var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
  117.             
  118.             // 各頂点ごとにトゥイーンを設定
  119.             for (xx = 0; xx < SEGMENT; xx++) {
  120.                 for (yy = 0; yy < SEGMENT; yy++) {
  121.                     // 各頂点のオリジナルの位置
  122.                     var bx:Number = vertexs[xx][yy].x;
  123.                     var by:Number = vertexs[xx][yy].y;
  124.                     var bz:Number = vertexs[xx][yy].z;
  125.                      
  126.                     // クリックした点までの距離を測定
  127.                     distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
  128.                          
  129.                     // 遅延を設定
  130.                     delay = distance / 1500;
  131.                     
  132.                     // 頂点制御 PV3Dだと楽チン
  133.                     var v:Vertex3D = plane.geometry.vertices[i++];
  134.                     
  135.                     // BetweenAS3
  136.                     tweens.push(
  137.                         BetweenAS3.delay(
  138.                             BetweenAS3.tween(v,
  139.                                 { x : vx, y : vy, z : vz },
  140.                                 { x : bx, y : by, z : bz },
  141.                                 delay, Cubic.easeIn),
  142.                             delay / 2)
  143.                         );
  144.                 }
  145.             }
  146.             
  147.             // ごにょごにょ
  148.             tween = BetweenAS3.parallelTweens(tweens);
  149.             if (isHide) tween = BetweenAS3.reverse(tween);
  150.             if (isShift) tween = BetweenAS3.scale(tween, 5);
  151.             tween.play();
  152.             
  153.             isHide = !isHide;
  154.         }
  155.         
  156.         private function loop(e:Event = null):void {
  157.             // 角度に応じてカメラの位置を設定
  158.             camera.x = 1000 * Math.sin(getTimer() / 3000);
  159.             camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
  160.             camera.z = -750;
  161.         }
  162.         
  163.         /**
  164.          * Shiftキーを押してるとスローモーションになる
  165.          * macの挙動と同じように
  166.          */
  167.         private function keyUpHandler(e:KeyboardEvent):void {
  168.             if(e.keyCode == 16) isShift = false;
  169.         }
  170.         
  171.         private function keyDownHandler(e:KeyboardEvent):void {
  172.             if(e.keyCode == 16) isShift = true;
  173.         }
  174.     }
  175. }
noswf
  1. // forked from clockmaker's Ginny Effect 3D
  2. /**
  3.  * Ginny Effect 3D
  4.  * 
  5.  * Photo by 
  6.  * http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
  7.  */
  8. package {
  9.     import flash.display.*;
  10.     import flash.events.*;
  11.     import flash.geom.*;
  12.     import flash.net.*;
  13.     import flash.system.*;
  14.     import flash.utils.*;
  15.     import org.libspark.betweenas3.BetweenAS3;
  16.     import org.libspark.betweenas3.easing.*;
  17.     import org.libspark.betweenas3.tweens.ITween;
  18.     import org.papervision3d.core.geom.renderables.Vertex3D;
  19.     import org.papervision3d.core.utils.Mouse3D;
  20.     import org.papervision3d.events.InteractiveScene3DEvent;
  21.     import org.papervision3d.materials.BitmapMaterial;
  22.     import org.papervision3d.objects.primitives.Plane;
  23.     import org.papervision3d.render.QuadrantRenderEngine;
  24.     import org.papervision3d.view.BasicView;
  25.     import com.bit101.components.*;
  26.     
  27.     [SWF(frameRate = 30)]
  28.     public class Main extends BasicView {
  29.             
  30.         private const IMAGE_URL:String = "http://farm4.static.flickr.com/3190/2662752839_249c6642b1.jpg";
  31.         private const IMG_W:Number = 500 * 2;
  32.         private const IMG_H:Number = 375 * 2;
  33.         private const SEGMENT:int = 12;
  34.         private const PLANE_Y:int = 500;
  35.         private const FLOOR_LENGTH:int = 3000;
  36.         private var loader:Loader;
  37.         private var isHide:Boolean = false;
  38.         private var isShift:Boolean = false;
  39.         private var plane:Plane;
  40.         private var floorPlane:Plane;
  41.         private var tween:ITween;
  42.         private var vertexs:Array = [];
  43.           
  44.         public function Main():void {
  45.             // init
  46.             super(00truetrue);
  47.             stage.quality = StageQuality.LOW;
  48.             
  49.             // 3dの初期化
  50.             Mouse3D.enabled = true;
  51.             renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
  52.             viewport.opaqueBackground = 0x0;
  53.                     
  54.             // load
  55.             var context:LoaderContext = new LoaderContext(true);
  56.             loader = new Loader();
  57.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
  58.             loader.load(new URLRequest(IMAGE_URL), context);
  59.             
  60.             // とりあえず説明
  61.             new Label(this360440"PLEASE CLICK STAGE");
  62.         }
  63.         
  64.         private function compHandler(e:Event):void {
  65.             // 写真のマテリアル
  66.             var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
  67.             plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
  68.             scene.addChild(plane);
  69.             
  70.             // 各頂点の座標を配列に格納しておく
  71.             var i:int = 0, xx:int, yy:int;
  72.             for (xx = 0; xx < SEGMENT; xx++) {
  73.                 vertexs[xx] = [];
  74.                 for (yy = 0; yy < SEGMENT; yy++) {
  75.                     var v:Vertex3D = plane.geometry.vertices[i++];
  76.                     vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
  77.                 }
  78.             }
  79.             
  80.             // 地面を作る: タイルの作り方はrectさんのを参考
  81.             var bmd:BitmapData = new BitmapData(22false);
  82.             bmd.setPixel(00, 0xDDDDDD);
  83.             bmd.setPixel(01, 0xFFFFFF);
  84.             bmd.setPixel(10, 0xFFFFFF);
  85.             bmd.setPixel(11, 0xDDDDDD);
  86.             
  87.             var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
  88.             floorMat.tiled = true;
  89.             floorMat.maxU = 20, floorMat.maxV = 20;
  90.             floorMat.interactive = true;
  91.             
  92.             floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 55);
  93.             scene.addChild(floorPlane);
  94.             floorPlane.rotationX = 90;
  95.             floorPlane.y = - PLANE_Y;
  96.             floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
  97.             
  98.             // いろいろイベントを登録
  99.             addEventListener(Event.ENTER_FRAME, loop);
  100.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  101.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  102.             startRendering();
  103.         }
  104.         
  105.         private function clickHandler(e:InteractiveScene3DEvent):void {
  106.             // トゥイーン実行中なら終了
  107.             if (tween) if (tween.isPlaying) return;
  108.                
  109.             // クリックした点のワールド座標を取得
  110.             var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
  111.             var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
  112.             var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
  113.             
  114.             // いろいろ変数
  115.             var tweens:Array = [];
  116.             var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
  117.             
  118.             // 各頂点ごとにトゥイーンを設定
  119.             for (xx = 0; xx < SEGMENT; xx++) {
  120.                 for (yy = 0; yy < SEGMENT; yy++) {
  121.                     // 各頂点のオリジナルの位置
  122.                     var bx:Number = vertexs[xx][yy].x;
  123.                     var by:Number = vertexs[xx][yy].y;
  124.                     var bz:Number = vertexs[xx][yy].z;
  125.                      
  126.                     // クリックした点までの距離を測定
  127.                     distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
  128.                          
  129.                     // 遅延を設定
  130.                     delay = distance / 1500;
  131.                     
  132.                     // 頂点制御 PV3Dだと楽チン
  133.                     var v:Vertex3D = plane.geometry.vertices[i++];
  134.                     
  135.                     // BetweenAS3
  136.                     tweens.push(
  137.                         BetweenAS3.delay(
  138.                             BetweenAS3.tween(v,
  139.                                 { x : vx, y : vy, z : vz },
  140.                                 { x : bx, y : by, z : bz },
  141.                                 delay, Cubic.easeIn),
  142.                             delay / 2)
  143.                         );
  144.                 }
  145.             }
  146.             
  147.             // ごにょごにょ
  148.             tween = BetweenAS3.parallelTweens(tweens);
  149.             if (isHide) tween = BetweenAS3.reverse(tween);
  150.             if (isShift) tween = BetweenAS3.scale(tween, 5);
  151.             tween.play();
  152.             
  153.             isHide = !isHide;
  154.         }
  155.         
  156.         private function loop(e:Event = null):void {
  157.             // 角度に応じてカメラの位置を設定
  158.             camera.x = 1000 * Math.sin(getTimer() / 3000);
  159.             camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
  160.             camera.z = -750;
  161.         }
  162.         
  163.         /**
  164.          * Shiftキーを押してるとスローモーションになる
  165.          * macの挙動と同じように
  166.          */
  167.         private function keyUpHandler(e:KeyboardEvent):void {
  168.             if(e.keyCode == 16) isShift = false;
  169.         }
  170.         
  171.         private function keyDownHandler(e:KeyboardEvent):void {
  172.             if(e.keyCode == 16) isShift = true;
  173.         }
  174.     }
  175. }
noswf
  1. // forked from clockmaker's Ginny Effect 3D
  2. /**
  3.  * Ginny Effect 3D
  4.  * 
  5.  * Photo by 
  6.  * http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
  7.  */
  8. package {
  9.     import flash.display.*;
  10.     import flash.events.*;
  11.     import flash.geom.*;
  12.     import flash.net.*;
  13.     import flash.system.*;
  14.     import flash.utils.*;
  15.     import org.libspark.betweenas3.BetweenAS3;
  16.     import org.libspark.betweenas3.easing.*;
  17.     import org.libspark.betweenas3.tweens.ITween;
  18.     import org.papervision3d.core.geom.renderables.Vertex3D;
  19.     import org.papervision3d.core.utils.Mouse3D;
  20.     import org.papervision3d.events.InteractiveScene3DEvent;
  21.     import org.papervision3d.materials.BitmapMaterial;
  22.     import org.papervision3d.objects.primitives.Plane;
  23.     import org.papervision3d.render.QuadrantRenderEngine;
  24.     import org.papervision3d.view.BasicView;
  25.     import com.bit101.components.*;
  26.     
  27.     [SWF(frameRate = 30)]
  28.     public class Main extends BasicView {
  29.             
  30.         private const IMAGE_URL:String = "http://farm4.static.flickr.com/3190/2662752839_249c6642b1.jpg";
  31.         private const IMG_W:Number = 500 * 2;
  32.         private const IMG_H:Number = 375 * 2;
  33.         private const SEGMENT:int = 12;
  34.         private const PLANE_Y:int = 500;
  35.         private const FLOOR_LENGTH:int = 3000;
  36.         private var loader:Loader;
  37.         private var isHide:Boolean = false;
  38.         private var isShift:Boolean = false;
  39.         private var plane:Plane;
  40.         private var floorPlane:Plane;
  41.         private var tween:ITween;
  42.         private var vertexs:Array = [];
  43.           
  44.         public function Main():void {
  45.             // init
  46.             super(00truetrue);
  47.             stage.quality = StageQuality.LOW;
  48.             
  49.             // 3dの初期化
  50.             Mouse3D.enabled = true;
  51.             renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
  52.             viewport.opaqueBackground = 0x0;
  53.                     
  54.             // load
  55.             var context:LoaderContext = new LoaderContext(true);
  56.             loader = new Loader();
  57.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
  58.             loader.load(new URLRequest(IMAGE_URL), context);
  59.             
  60.             // とりあえず説明
  61.             new Label(this360440"PLEASE CLICK STAGE");
  62.         }
  63.         
  64.         private function compHandler(e:Event):void {
  65.             // 写真のマテリアル
  66.             var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
  67.             plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
  68.             scene.addChild(plane);
  69.             
  70.             // 各頂点の座標を配列に格納しておく
  71.             var i:int = 0, xx:int, yy:int;
  72.             for (xx = 0; xx < SEGMENT; xx++) {
  73.                 vertexs[xx] = [];
  74.                 for (yy = 0; yy < SEGMENT; yy++) {
  75.                     var v:Vertex3D = plane.geometry.vertices[i++];
  76.                     vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
  77.                 }
  78.             }
  79.             
  80.             // 地面を作る: タイルの作り方はrectさんのを参考
  81.             var bmd:BitmapData = new BitmapData(22false);
  82.             bmd.setPixel(00, 0xDDDDDD);
  83.             bmd.setPixel(01, 0xFFFFFF);
  84.             bmd.setPixel(10, 0xFFFFFF);
  85.             bmd.setPixel(11, 0xDDDDDD);
  86.             
  87.             var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
  88.             floorMat.tiled = true;
  89.             floorMat.maxU = 20, floorMat.maxV = 20;
  90.             floorMat.interactive = true;
  91.             
  92.             floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 55);
  93.             scene.addChild(floorPlane);
  94.             floorPlane.rotationX = 90;
  95.             floorPlane.y = - PLANE_Y;
  96.             floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
  97.             
  98.             // いろいろイベントを登録
  99.             addEventListener(Event.ENTER_FRAME, loop);
  100.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  101.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  102.             startRendering();
  103.         }
  104.         
  105.         private function clickHandler(e:InteractiveScene3DEvent):void {
  106.             // トゥイーン実行中なら終了
  107.             if (tween) if (tween.isPlaying) return;
  108.                
  109.             // クリックした点のワールド座標を取得
  110.             var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
  111.             var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
  112.             var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
  113.             
  114.             // いろいろ変数
  115.             var tweens:Array = [];
  116.             var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
  117.             
  118.             // 各頂点ごとにトゥイーンを設定
  119.             for (xx = 0; xx < SEGMENT; xx++) {
  120.                 for (yy = 0; yy < SEGMENT; yy++) {
  121.                     // 各頂点のオリジナルの位置
  122.                     var bx:Number = vertexs[xx][yy].x;
  123.                     var by:Number = vertexs[xx][yy].y;
  124.                     var bz:Number = vertexs[xx][yy].z;
  125.                      
  126.                     // クリックした点までの距離を測定
  127.                     distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
  128.                          
  129.                     // 遅延を設定
  130.                     delay = distance / 1500;
  131.                     
  132.                     // 頂点制御 PV3Dだと楽チン
  133.                     var v:Vertex3D = plane.geometry.vertices[i++];
  134.                     
  135.                     // BetweenAS3
  136.                     tweens.push(
  137.                         BetweenAS3.delay(
  138.                             BetweenAS3.tween(v,
  139.                                 { x : vx, y : vy, z : vz },
  140.                                 { x : bx, y : by, z : bz },
  141.                                 delay, Cubic.easeIn),
  142.                             delay / 2)
  143.                         );
  144.                 }
  145.             }
  146.             
  147.             // ごにょごにょ
  148.             tween = BetweenAS3.parallelTweens(tweens);
  149.             if (isHide) tween = BetweenAS3.reverse(tween);
  150.             if (isShift) tween = BetweenAS3.scale(tween, 5);
  151.             tween.play();
  152.             
  153.             isHide = !isHide;
  154.         }
  155.         
  156.         private function loop(e:Event = null):void {
  157.             // 角度に応じてカメラの位置を設定
  158.             camera.x = 1000 * Math.sin(getTimer() / 3000);
  159.             camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
  160.             camera.z = -750;
  161.         }
  162.         
  163.         /**
  164.          * Shiftキーを押してるとスローモーションになる
  165.          * macの挙動と同じように
  166.          */
  167.         private function keyUpHandler(e:KeyboardEvent):void {
  168.             if(e.keyCode == 16) isShift = false;
  169.         }
  170.         
  171.         private function keyDownHandler(e:KeyboardEvent):void {
  172.             if(e.keyCode == 16) isShift = true;
  173.         }
  174.     }
  175. }
noswf
  1. // forked from clockmaker's Ginny Effect 3D
  2. /**
  3.  * Ginny Effect 3D
  4.  * 
  5.  * Photo by 
  6.  * http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
  7.  */
  8. package {
  9.     import flash.display.*;
  10.     import flash.events.*;
  11.     import flash.geom.*;
  12.     import flash.net.*;
  13.     import flash.system.*;
  14.     import flash.utils.*;
  15.     import org.libspark.betweenas3.BetweenAS3;
  16.     import org.libspark.betweenas3.easing.*;
  17.     import org.libspark.betweenas3.tweens.ITween;
  18.     import org.papervision3d.core.geom.renderables.Vertex3D;
  19.     import org.papervision3d.core.utils.Mouse3D;
  20.     import org.papervision3d.events.InteractiveScene3DEvent;
  21.     import org.papervision3d.materials.BitmapMaterial;
  22.     import org.papervision3d.objects.primitives.Plane;
  23.     import org.papervision3d.render.QuadrantRenderEngine;
  24.     import org.papervision3d.view.BasicView;
  25.     import com.bit101.components.*;
  26.     
  27.     [SWF(frameRate = 30)]
  28.     public class Main extends BasicView {
  29.             
  30.         private const IMAGE_URL:String = "http://farm4.static.flickr.com/3190/2662752839_249c6642b1.jpg";
  31.         private const IMG_W:Number = 500 * 2;
  32.         private const IMG_H:Number = 375 * 2;
  33.         private const SEGMENT:int = 12;
  34.         private const PLANE_Y:int = 500;
  35.         private const FLOOR_LENGTH:int = 3000;
  36.         private var loader:Loader;
  37.         private var isHide:Boolean = false;
  38.         private var isShift:Boolean = false;
  39.         private var plane:Plane;
  40.         private var floorPlane:Plane;
  41.         private var tween:ITween;
  42.         private var vertexs:Array = [];
  43.           
  44.         public function Main():void {
  45.             // init
  46.             super(00truetrue);
  47.             stage.quality = StageQuality.LOW;
  48.             
  49.             // 3dの初期化
  50.             Mouse3D.enabled = true;
  51.             renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
  52.             viewport.opaqueBackground = 0x0;
  53.                     
  54.             // load
  55.             var context:LoaderContext = new LoaderContext(true);
  56.             loader = new Loader();
  57.             loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
  58.             loader.load(new URLRequest(IMAGE_URL), context);
  59.             
  60.             // とりあえず説明
  61.             new Label(this360440"PLEASE CLICK STAGE");
  62.         }
  63.         
  64.         private function compHandler(e:Event):void {
  65.             // 写真のマテリアル
  66.             var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
  67.             plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
  68.             scene.addChild(plane);
  69.             
  70.             // 各頂点の座標を配列に格納しておく
  71.             var i:int = 0, xx:int, yy:int;
  72.             for (xx = 0; xx < SEGMENT; xx++) {
  73.                 vertexs[xx] = [];
  74.                 for (yy = 0; yy < SEGMENT; yy++) {
  75.                     var v:Vertex3D = plane.geometry.vertices[i++];
  76.                     vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
  77.                 }
  78.             }
  79.             
  80.             // 地面を作る: タイルの作り方はrectさんのを参考
  81.             var bmd:BitmapData = new BitmapData(22false);
  82.             bmd.setPixel(00, 0xDDDDDD);
  83.             bmd.setPixel(01, 0xFFFFFF);
  84.             bmd.setPixel(10, 0xFFFFFF);
  85.             bmd.setPixel(11, 0xDDDDDD);
  86.             
  87.             var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
  88.             floorMat.tiled = true;
  89.             floorMat.maxU = 20, floorMat.maxV = 20;
  90.             floorMat.interactive = true;
  91.             
  92.             floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 55);
  93.             scene.addChild(floorPlane);
  94.             floorPlane.rotationX = 90;
  95.             floorPlane.y = - PLANE_Y;
  96.             floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
  97.             
  98.             // いろいろイベントを登録
  99.             addEventListener(Event.ENTER_FRAME, loop);
  100.             stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
  101.             stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
  102.             startRendering();
  103.         }
  104.         
  105.         private function clickHandler(e:InteractiveScene3DEvent):void {
  106.             // トゥイーン実行中なら終了
  107.             if (tween) if (tween.isPlaying) return;
  108.                
  109.             // クリックした点のワールド座標を取得
  110.             var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
  111.             var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
  112.             var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
  113.             
  114.             // いろいろ変数
  115.             var tweens:Array = [];
  116.             var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
  117.             
  118.             // 各頂点ごとにトゥイーンを設定
  119.             for (xx = 0; xx < SEGMENT; xx++) {
  120.                 for (yy = 0; yy < SEGMENT; yy++) {
  121.                     // 各頂点のオリジナルの位置
  122.                     var bx:Number = vertexs[xx][yy].x;
  123.                     var by:Number = vertexs[xx][yy].y;
  124.                     var bz:Number = vertexs[xx][yy].z;
  125.                      
  126.                     // クリックした点までの距離を測定
  127.                     distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
  128.                          
  129.                     // 遅延を設定
  130.                     delay = distance / 1500;
  131.                     
  132.                     // 頂点制御 PV3Dだと楽チン
  133.                     var v:Vertex3D = plane.geometry.vertices[i++];
  134.                     
  135.                     // BetweenAS3
  136.                     tweens.push(
  137.                         BetweenAS3.delay(
  138.                             BetweenAS3.tween(v,
  139.                                 { x : vx, y : vy, z : vz },
  140.                                 { x : bx, y : by, z : bz },
  141.                                 delay, Cubic.easeIn),
  142.                             delay / 2)
  143.                         );
  144.                 }
  145.             }
  146.             
  147.             // ごにょごにょ
  148.             tween = BetweenAS3.parallelTweens(tweens);
  149.             if (isHide) tween = BetweenAS3.reverse(tween);
  150.             if (isShift) tween = BetweenAS3.scale(tween, 5);
  151.             tween.play();
  152.             
  153.             isHide = !isHide;
  154.         }
  155.         
  156.         private function loop(e:Event = null):void {
  157.             // 角度に応じてカメラの位置を設定
  158.             camera.x = 1000 * Math.sin(getTimer() / 3000);
  159.             camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
  160.             camera.z = -750;
  161.         }
  162.         
  163.         /**
  164.          * Shiftキーを押してるとスローモーションになる
  165.          * macの挙動と同じように
  166.          */
  167.         private function keyUpHandler(e:KeyboardEvent):void {
  168.             if(e.keyCode == 16) isShift = false;
  169.         }
  170.         
  171.         private function keyDownHandler(e:KeyboardEvent):void {
  172.             if(e.keyCode == 16) isShift = true;
  173.         }
  174.     }
  175. }
noswf
Get Adobe Flash Player