package{
import flash.events.Event;
import flash.filters.BlurFilter;
import org.papervision3d.core.effects.BitmapLayerEffect;
import org.papervision3d.core.effects.utils.BitmapClearMode;
import org.papervision3d.core.effects.utils.BitmapDrawCommand;
import org.papervision3d.core.geom.Pixels;
import org.papervision3d.core.geom.renderables.Pixel3D;
import org.papervision3d.objects.DisplayObject3D;
import org.papervision3d.view.BasicView;
import org.papervision3d.view.layer.BitmapEffectLayer;
import org.papervision3d.view.layer.util.ViewportLayerSortMode;
[SWF(width="800", height="600", frameRate="60",backgroundColor="0x000000")]
public class Pixel3DTest2 extends BasicView{
private var pixels:Pixels;
public function Pixel3DTest2(){
super(800, 600, true, true);
init3D();
startRendering();
}
private function init3D():void{
var bfx:BitmapEffectLayer=new BitmapEffectLayer(viewport, 800, 600, true, 0, BitmapClearMode.CLEAR_POST, true, true);
viewport.containerSprite.addLayer(bfx);
//bfx.addEffect(new BitmapLayerEffect(new BlurFilter(8, 8, 4), false));
var drawCommand:BitmapDrawCommand=new BitmapDrawCommand();
drawCommand.drawContainer=true;
bfx.drawCommand=drawCommand;
bfx.sortMode=ViewportLayerSortMode.Z_SORT;
pixels=new Pixels(bfx);
createPixels();
}
private function createPixels():void{
var count:int=0;
while (count < 12000){
var pixel:Pixel3D=new Pixel3D(0xFFFFFFFF, Math.random() * 400 - 200, Math.random() * 400 - 200, Math.random() * 400 - 200);
var xpos:Number=pixel.x;
var ypos:Number=pixel.y;
var zpos:Number=pixel.z;
var distance:Number=Math.sqrt(xpos * xpos + ypos * ypos + zpos * zpos);
var alpha:Number=(1 - distance / 200) * 255;
var red:Number=(1 - distance / 250) * 255;
var green:Number=Math.abs(xpos) / distance * 255;
var blue:Number=Math.abs(ypos) / distance * 255;
pixel.color=alpha << 24 | red << 16 | green << 8 | blue;
pixels.addPixel3D(pixel);
count++;
}
scene.addChild(pixels);
}
protected override function onRenderTick(event:Event=null):void{
var fac:int=5;
camera.x-=(camera.x - Math.sin((stage.mouseX - (stage.stageWidth / 2)) * 0.0002) * 8000) / fac;
camera.z-=(camera.z - Math.cos((stage.mouseX - (stage.stageWidth / 2)) * 0.0005) * -500) / fac;
camera.y-=(camera.y - Math.sin((stage.mouseY - (stage.stageHeight / 2)) * 0.0002) * -8000) / fac;
super.onRenderTick(event);
}
}
}
转载请注明:陈童的博客 » 粒子矩形