flash on 2009-11-19
/**
* Copyright gryyy451 ( http://wonderfl.net/user/gryyy451 )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/hGZI
*/
package
{
import caurina.transitions.Tweener;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageQuality;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.filters.BlurFilter;
import org.papervision3d.cameras.Camera3D;
import org.papervision3d.events.InteractiveScene3DEvent;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;
[SWF(backgroundColor=0xffffff)]
public class Papervision3D_sample56 extends Sprite
{
private var viewport:Viewport3D;
private var scene:Scene3D;
private var camera:Camera3D;
private var render:BasicRenderEngine;
private var rootNode:DisplayObject3D;
// コンストラクタ
public function Papervision3D_sample56()
{
// PV3Dの初期化
viewport=new Viewport3D(0, 0, true, true);
scene=new Scene3D();
camera=new Camera3D();
render=new BasicRenderEngine();
rootNode=scene.addChild(new DisplayObject3D("rootNode"));
// 基本設定
addChild(viewport);
camera.zoom=30;
camera.focus=30;
camera.x=camera.y=0;
camera.z=-300;
camera.target=DisplayObject3D.ZERO;
// ステージ設定
stage.frameRate=40;
stage.quality=StageQuality.HIGH;
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
// planeを配置
for(var i:int=0; i < 30; i++)
{
var do3d:DisplayObject3D=new DisplayObject3D;
do3d.rotationX=360 * Math.random();
do3d.rotationY=360 * Math.random();
do3d.rotationZ=360 * Math.random();
rootNode.addChild(do3d, "do3d" + i.toString());
var r:Number=100 - i * 7;
for(var rad:int=0; rad < 360; rad+=90)
{
var mat:ColorMaterial=new ColorMaterial(0xffffff * Math.random(), 1);
mat.doubleSided=mat.interactive=true;
var p:Plane=new Plane(mat, 20, 20, 1, 1);
p.extra={roll:0};
do3d.addChild(p, "plane" + rad.toString());
p.z=r * Math.cos(rad * Math.PI / 180);
p.x=r * Math.sin(rad * Math.PI / 180);
p.rotationY=rad;
}
}
addEventListener(Event.ENTER_FRAME, onFrame);
}
// フレームイベント用関数
public function onFrame(e:Event):void
{
for(var i:int=0; i < 30; i++)
{
var do3d:DisplayObject3D=rootNode.getChildByName("do3d" + i.toString());
if (i % 2 == 0)
{
do3d.rotationY+=0.2;
do3d.rotationZ+=0.2;
}
else
{
do3d.rotationY-=0.2;
do3d.rotationX-=0.2;
}
}
render.renderScene(scene, camera, viewport);
}
}
}