forked from: forked from: forked from: forked from: Ginny Effect 3D
forked from forked from: forked from: forked from: Ginny Effect 3D (diff: 12)
Ginny Effect 3D Photo by http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
ActionScript3 source code
/**
* Copyright jules ( http://wonderfl.net/user/jules )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/u0n4
*/
// forked from jules's forked from: forked from: forked from: Ginny Effect 3D
// forked from jules's forked from: forked from: Ginny Effect 3D
// forked from jules's forked from: Ginny Effect 3D
// forked from clockmaker's Ginny Effect 3D
/**
* Ginny Effect 3D
*
* Photo by
* http://www.flickr.com/photos/88403964@N00/2662752839/ (by clockmaker)
*/
package {
import flash.display.*;
import flash.events.*;
import flash.geom.*;
import flash.net.*;
import flash.system.*;
import flash.utils.*;
import org.libspark.betweenas3.BetweenAS3;
import org.libspark.betweenas3.easing.*;
import org.libspark.betweenas3.tweens.ITween;
import org.papervision3d.core.geom.renderables.Vertex3D;
import org.papervision3d.core.utils.Mouse3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.BitmapMaterial;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.objects.primitives.Sphere;
import org.papervision3d.render.QuadrantRenderEngine;
import org.papervision3d.view.BasicView;
import com.bit101.components.*;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.FlatShadeMaterial;
[SWF(frameRate = 30)]
public class Main extends BasicView {
private const IMAGE_URL:String = "http://farm8.staticflickr.com/7023/6727533433_ae28179c3f.jpg";
private const IMAGE_URL1:String = "http://farm8.staticflickr.com/7021/6727512117_68eab4772a.jpg";
private const IMAGE_URL2:String = "http://farm8.staticflickr.com/7021/6727512117_68eab4772a.jpg";
private const IMAGE_URL3:String = "http://farm8.staticflickr.com/7021/6727512117_68eab4772a.jpg";
private const IMAGE_URL4:String = "http://farm8.staticflickr.com/7021/6727512117_68eab4772a.jpg";
private const IMAGE_URL5:String = "http://farm8.staticflickr.com/7021/6727512117_68eab4772a.jpg";
private const IMG_W:Number = 500 * 2;
private const IMG_H:Number = 375 * 2;
private const SEGMENT:int = 12;
private const sphereSEGMENT:int = 2;
private const PLANE_Y:int = 200;
private const FLOOR_LENGTH:int = 3000;
private var loader:Loader;
private var isHide:Boolean = false;
private var isShift:Boolean = false;
private var plane:Plane;
//private var plane2:Plane;
private var floorPlane:Plane;
private var tween:ITween;
private var vertexs:Array = [];
// xListInt after offset is: [21, 64, 53, 90, 110, 58, 80, 58, 38, 29, 20, 110]
//[62, 90, 106, 130, 102, 68, 35, 20, 51, 45, 59, 119]
private var xList:Array = [114, 121, 98, 105, 34, 20];
private var yList:Array = [20, 69, 73, 120, 130, 36];
private var imageRotationsX:Array = [45, 60, 50, 30, 30, 20];
private var imageRotationsY:Array = [30, 60, 50, 30, 90, 90];
private var imageRotationsZ:Array = [45, 80, 50, 45, 45, 45];
private var xListCeiling:Array = [114, 121, 98, 105, 34, 20];
private var yListCeiling:Array = [20, 69, 73, 120, 130, 36];
private var light :PointLight3D;
private var scaleFactor:int = 10;
private var offset:int = 1000;
public function Main():void {
// init
super(0, 0, true, true);
stage.quality = StageQuality.LOW;
// 3dの初期化
Mouse3D.enabled = true;
renderer = new QuadrantRenderEngine(QuadrantRenderEngine.ALL_FILTERS);
viewport.opaqueBackground = 0x0;
// load
var context:LoaderContext = new LoaderContext(true);
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, compHandler);
loader.load(new URLRequest(IMAGE_URL), context);
// とりあえず説明
new Label(this, 360, 440, "PLEASE CLICK STAGE");
}
private function compHandler(e:Event):void {
// 写真のマテリアル
var material:BitmapMaterial = new BitmapMaterial(Bitmap(loader.content).bitmapData);
plane = new Plane(material, IMG_W, IMG_H, SEGMENT - 1, SEGMENT - 1);
plane.x = 000;
plane.y = 20;
plane.rotationX = 90;
// scene.addChild(plane);
var plane2:Plane;
plane2 = new Plane(material, 100, 100, SEGMENT - 1, SEGMENT - 1);
plane.x = 100;
//scene.addChild(plane2);
var h:int;
//Material mat = new FlatShadeMaterial(light, 0x336699);
var mat:FlatShadeMaterial = new FlatShadeMaterial(light, 0x992200, 0x992200, 100);
for (h= 0; h < xList.length; h++) {
var plane3:Sphere;
//plane3 = new Plane(material, 50, 50, SEGMENT - 1, SEGMENT - 1);
plane3 = new Sphere(mat, 50, sphereSEGMENT - 1, sphereSEGMENT - 1);
plane3.x = xList[h]*scaleFactor-offset;
plane3.z = yList[h]*scaleFactor-offset;
plane3.y = -10;
scene.addChild(plane3);
var image:Plane;
image = new Plane(material, 500, 300, SEGMENT - 1, SEGMENT - 1);
image.x = xList[h]*scaleFactor-offset;
image.z = yList[h]*scaleFactor-offset;
image.y = -10;
image.rotationX = imageRotationsX[h];
image.rotationY =imageRotationsY[h];
//image.rotationZ = imageRotationsZ[h];
scene.addChild(image);
var plane4:Sphere;
plane4 = new Sphere(mat, 50, sphereSEGMENT - 1, sphereSEGMENT - 1);
plane4.x = xList[h]*scaleFactor-offset;
plane4.z = yList[h]*scaleFactor-offset;
plane4.y = 300;
scene.addChild(plane4);
}
/*
h=0;
for (h= 0; h < xList.length; h++) {
var plane4:Sphere;
plane4 = new Sphere(mat, 50, SEGMENT - 1, SEGMENT - 1);
plane4.x = xList[h]*scaleFactor-offset;
plane4.z = yList[h]*scaleFactor-offset;
plane4.y = 300;
scene.addChild(plane4);
}
*/
// 各頂点の座標を配列に格納しておく
/*
var j:int = 10;
var i:int = 0, xx:int, yy:int;
for (xx = 0; xx < SEGMENT; xx++) {
vertexs[xx] = [];
for (yy = 0; yy < SEGMENT; yy++) {
var v:Vertex3D = plane.geometry.vertices[i++];
vertexs[xx][yy] = { x : v.x, y : v.y, z : v.z };
new Label(this, 3, j+10, "vx " + v.x + " v.y " + v.y + "v.z " + v.z);
j = j +10;
}
}*/
// 地面を作る: タイルの作り方はrectさんのを参考
var bmd:BitmapData = new BitmapData(2, 2, false);
bmd.setPixel(0, 0, 0xDDDDDD);
bmd.setPixel(0, 1, 0xFFFFFF);
bmd.setPixel(1, 0, 0xFFFFFF);
bmd.setPixel(1, 1, 0xDDDDDD);
var floorMat:BitmapMaterial = new BitmapMaterial(bmd, true);
floorMat.tiled = true;
floorMat.maxU = 20, floorMat.maxV = 20;
floorMat.interactive = true;
floorPlane = new Plane(floorMat, FLOOR_LENGTH, FLOOR_LENGTH, 5, 5);
scene.addChild(floorPlane);
floorPlane.rotationX = 90;
floorPlane.y = - PLANE_Y;
floorPlane.addEventListener(InteractiveScene3DEvent.OBJECT_CLICK, clickHandler);
// いろいろイベントを登録
addEventListener(Event.ENTER_FRAME, loop);
stage.addEventListener(KeyboardEvent.KEY_UP, keyUpHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, keyDownHandler);
startRendering();
}
private function clickHandler(e:InteractiveScene3DEvent):void {
// トゥイーン実行中なら終了
if (tween) if (tween.isPlaying) return;
// クリックした点のワールド座標を取得
var vx:Number = viewport.interactiveSceneManager.mouse3D.x;
var vy:Number = viewport.interactiveSceneManager.mouse3D.y;
var vz:Number = viewport.interactiveSceneManager.mouse3D.z;
// いろいろ変数
var tweens:Array = [];
var i:int = 0, xx:int, yy:int, delay:Number, distance:Number;
// 各頂点ごとにトゥイーンを設定
for (xx = 0; xx < SEGMENT; xx++) {
for (yy = 0; yy < SEGMENT; yy++) {
// 各頂点のオリジナルの位置
var bx:Number = vertexs[xx][yy].x;
var by:Number = vertexs[xx][yy].y;
var bz:Number = vertexs[xx][yy].z;
// クリックした点までの距離を測定
distance = Math.sqrt((bx - vx) * (bx - vx) + (by - vy) * (by - vy) + (bz - vz) * (bz - vz));
// 遅延を設定
delay = distance / 1500;
// 頂点制御 PV3Dだと楽チン
var v:Vertex3D = plane.geometry.vertices[i++];
// BetweenAS3
tweens.push(
BetweenAS3.delay(
BetweenAS3.tween(v,
{ x : vx, y : vy, z : vz },
{ x : bx, y : by, z : bz },
delay, Cubic.easeIn),
delay / 2)
);
}
}
// ごにょごにょ
tween = BetweenAS3.parallelTweens(tweens);
if (isHide) tween = BetweenAS3.reverse(tween);
if (isShift) tween = BetweenAS3.scale(tween, 5);
tween.play();
isHide = !isHide;
}
private function loop(e:Event = null):void {
// 角度に応じてカメラの位置を設定
camera.x = 1000 * Math.sin(getTimer() / 3000);
camera.y = 500 * Math.sin(getTimer() / 2500) + 800;
camera.y = 500 * Math.sin(getTimer() / 2500) + 1000;
camera.z = -750;
}
/**
* Shiftキーを押してるとスローモーションになる
* macの挙動と同じように
*/
private function keyUpHandler(e:KeyboardEvent):void {
if(e.keyCode == 16) isShift = false;
}
private function keyDownHandler(e:KeyboardEvent):void {
if(e.keyCode == 16) isShift = true;
}
}
}
