flash on 2010-8-24
/**
* Copyright kitouch0124 ( http://wonderfl.net/user/kitouch0124 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/oDgB
*/
package {
import flash.display.*;
import flash.events.*;
import flash.utils.*;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.*;
import org.papervision3d.materials.shadematerials.*;
import org.papervision3d.materials.shaders.*;
import org.papervision3d.objects.*;
import org.papervision3d.objects.primitives.*;
import org.papervision3d.lights.*;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.view.Viewport3D;
import flash.filters.BlurFilter;
import org.papervision3d.core.effects.view.ReflectionView;
[SWF(backgroundColor = "#000000")]
public class PV3D_01 extends ReflectionView {
private var bmpData:BitmapData;
private var material:BitmapMaterial;
private var cube :Cube;
private var sphere:Sphere;
private var light:PointLight3D;
public function PV3D_01() {
//viewport.opaqueBackground = 0x000000;//背景色
super(640, 480, true, false, "Debug");
//リフレクションを置く場所
surfaceHeight = 0;
//ぼかし反映
var blur:Number = 4;
viewportReflection.filters = [new BlurFilter(blur, blur, 1)];
//鏡面反射用平面(分かりやすいようにワイヤーフレーム表示)
var size:Number = 1000;
var rPlane:Plane = new Plane(new WireframeMaterial(0xffffff), size, size, 10, 10);
rPlane.rotationX = 90;
scene.addChild(rPlane);
var TEXTURE_W:int = 300;
var TEXTURE_H:int = 300;
//BitmapDataの作成。Bitmapに角丸矩形を描く
bmpData = new BitmapData(TEXTURE_W,TEXTURE_H,true,0x00000000);
var rrect:Shape = new Shape();
rrect.graphics.beginFill(0x888888);
rrect.graphics.drawRect(0,0,TEXTURE_W,TEXTURE_H);
rrect.graphics.endFill();
rrect.graphics.beginFill(0x47FF8A);
rrect.graphics.drawRoundRect(10,10,TEXTURE_W - 20,TEXTURE_H - 20,50);
rrect.graphics.endFill();
bmpData.draw(rrect);
//マテリアル設定
material = new BitmapMaterial(bmpData);
material.oneSide = true;
material.smooth = true;
light = new PointLight3D(true);
//light.x = 500;
light.y = 200;
//light.z = -200;
scene.addChild(light);
camera.y = 300;
var sdr:GouraudShader = new GouraudShader(light);
var mat:ShadedMaterial = new ShadedMaterial(material, sdr);
//var materials :MaterialsList = new MaterialsList( { all : mat } );
var materials :MaterialsList = new MaterialsList( { all : new GouraudMaterial(light, 0x478AFF) } );
cube = new Cube( materials, TEXTURE_W, 10, TEXTURE_W);
cube.y = 300;
scene.addChild( cube );
//sphere = new Sphere(mat);
//scene.addChild(sphere);
addEventListener( Event.ENTER_FRAME, onEnterFrame );
}
public function onEnterFrame(e:Event): void {
cube.roll(1);
cube.yaw(0.5);
cube.pitch(0.7);
cube.y = Math.sin(getTimer() / 500) * 200 + 450;
//light.x = 2 * (mouseX - stage.stageWidth / 2);
//light.y = -2 * (mouseY - stage.stageHeight / 2);
//light.z = -400;
light.x = Math.sin(getTimer() / 300) * 400;
light.z = Math.cos(getTimer() / 300) * 400;
//camera.x += (mouseX / stage.stageWidth * 600 - 300) - camera.x * .07;
//camera.y += (mouseY / stage.stageHeight * 200) - camera.y * .07;
singleRender();
}
}
}