wonderfl test
package{
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.Event;
import caurina.transitions.Tweener;
import flash.events.MouseEvent;
import org.papervision3d.core.proto.DisplayObjectContainer3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.special.CompositeMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.materials.WireframeMaterial;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
[SWF(width="465", height="465", backgroundColor="0x111111")]
public class Main extends BasicView{
private var container:DisplayObject3D;
private const MAX_SIZE:Number = 1500;
private const BOX_NUM:int = 50;
public function Main():void{
super();
init();
}
private function init():void{
container = new DisplayObject3D();
var material:CompositeMaterial = new CompositeMaterial();
var c_mat:ColorMaterial = new ColorMaterial(0x000000, 0.8, false);
var w_mat:WireframeMaterial = new WireframeMaterial(0x999999, 1, 0);
material.addMaterial(c_mat);
material.addMaterial(w_mat);
for (var i:int = 0; i < BOX_NUM; i ++ ){
var cube:Cube = new Cube(new MaterialsList( { all:material } ), 50, 50, 50, 1, 1, 1);
cube.x = Math.random() * MAX_SIZE - MAX_SIZE / 2;
cube.y = Math.random() * MAX_SIZE - MAX_SIZE / 2;
cube.z = Math.random() * MAX_SIZE - MAX_SIZE / 2;
cube.name = 'cube' + i;
container.addChild(cube);
cubeRotate(cube);
}
scene.addChild(container);
this.addEventListener(Event.ENTER_FRAME, enterFrameFunc)
stage.addEventListener(MouseEvent.CLICK, stageClick);
}
private function cubeRotate(cube:Cube):void {
cube.rotationX = 0;
cube.rotationY = 0;
var rand:Number = (Math.random() * (12 - 10 + 1)) + 10;
Tweener.addTween(cube, {
rotationX:360 * 5,
rotationY:360 * 3,
time:rand,
transition:'linear',
onComplete:cubeRotate,
onCompleteParams:[cube]
});
}
private function stageClick(e:MouseEvent):void {
spread();
}
private function spread():void {
var num:int = container.numChildren;
for (var i:int = 0; i < num; i++ ) {
var cube:Cube = container.getChildByName('cube' + i) as Cube;
Tweener.addTween(cube, {
x:Math.random() * MAX_SIZE - MAX_SIZE / 2,
y:Math.random() * MAX_SIZE - MAX_SIZE / 2,
z:Math.random() * MAX_SIZE - MAX_SIZE / 2,
delay:Math.random() * 1.5,
time:3,
transition:'easeOutBack'
});
}
}
private function enterFrameFunc(e:Event):void{
container.yaw((mouseX - stage.stageWidth / 2) / 300);
container.pitch((mouseY - stage.stageHeight / 2 ) / 300);
startRendering();
}
}
}