Sample of Pixels, Pixel3D
...
@author ...
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import org.papervision3d.core.view.IView;
/**
* ...
* @author ...
*/
[SWF(width="465", height="465", frameRate="24", backgroundColor = "0x000000")]
public class Pv3d009 extends Sprite
{
private var _view:CustomView;
public function Pv3d009()
{
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
private function addedToStageHandler(e:Event):void
{
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate = 30;
_view = new CustomView();
addChild(_view);
}
}
}
import flash.events.Event;
import flash.filters.BlurFilter;
import org.papervision3d.core.geom.renderables.Pixel3D;
import org.papervision3d.core.effects.BitmapLayerEffect;
import org.papervision3d.view.BasicView;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.view.layer.BitmapEffectLayer;
import org.papervision3d.view.layer.ViewportLayer;
import org.papervision3d.core.effects.utils.BitmapClearMode;
import org.papervision3d.core.effects.utils.BitmapDrawCommand;
import org.papervision3d.core.geom.Pixels;
internal class CustomView extends BasicView {
public function CustomView() {
super(0, 0, true, true);
addEventListener(Event.ADDED_TO_STAGE, addedToStage);
}
private function addedToStage(e:Event):void
{
removeEventListener(e.type, arguments.callee);
buildScene();
startRendering();
addEventListener(Event.ENTER_FRAME, enterFrameHandler);
}
private function enterFrameHandler(e:Event):void
{
camera.orbit(viewport.containerSprite.mouseX, viewport.containerSprite.mouseY, true);
}
protected function buildScene():void {
var pixels:Pixels = createPixels();
scene.addChild(pixels);
trace(pixels);
camera.focus = 1300;
camera.zoom = 2;
camera.z = -3000;
}
private function createPixels():Pixels {
var bmpEfxlayer:BitmapEffectLayer =
new BitmapEffectLayer(viewport, stage.stageWidth, stage.stageHeight, true, 0, BitmapClearMode.CLEAR_PRE, true);
viewport.containerSprite.addLayer(bmpEfxlayer);
bmpEfxlayer.addEffect(new BitmapLayerEffect(new BlurFilter(8,8,4), false));
var pixels:Pixels = new Pixels(bmpEfxlayer);
var pixel3D:Pixel3D;
bmpEfxlayer.drawCommand = new BitmapDrawCommand();
var i:int = 0;
var px:Number;
var py:Number;
var pz:Number;
var len:Number;
var s1:Number, s2:Number, s3:Number, s4:Number;
while ( i < 12000) {
pixel3D = new Pixel3D(0xffffff, Math.random() * 400 - 200, Math.random() * 400 - 200, Math.random() * 400 - 200);
px = pixel3D.x;
py = pixel3D.y;
pz = pixel3D.z;
len = Math.sqrt(px * px + py * py + pz * pz);
s1 = (1 - len / 200) * 255;
s2 = (1 - len / 250) * 255;
s3 = Math.abs(px) / len * 255;
s4 = Math.abs(py) / len * 255;
pixel3D.color = s1 << 24 | s2 << 16 | s3 << 8 | s4; //trace(pixel3D.color.toString(16));
pixels.addPixel3D(pixel3D);
i++;
}
return pixels;
}
}