[AS 3] Papervision and a Blur Filter
1 comment so farSo I was going through a nice video tutorial over at gotoandlearn.com about Papervision and decided to try it out. I suggest visiting their site for the full details. I changed the demo below by allowing the object to load in an external image as well as I added a blur filter to the images.. although processor intensive, I just decided to play around with it for now.
The demo is here, I had to pull out the Blur Filter as my G5 processor was on fire!
Sorry for this, but I put the Actionscript within the first frame of the .fla movie. If I have more time later I will place in an external file.
// 1] bring in all the packages
import org.papervision3d.scenes.*;
import org.papervision3d.cameras.*;
import org.papervision3d.objects.*;
import org.papervision3d.materials.*;
// 2] need to create a container for the scene - either mc or sprite
var container:Sprite = new Sprite();
// position in middle of splash page
container.x = stage.stageWidth * .5;
container.y = stage.stageHeight * .5;
addChild(container);
// 3] create our papervision 3d scene, the most basic is scene3d
var scene:Scene3D = new Scene3D(container)
// 4] now get the camera
var camera:Camera3D = new Camera3D();
// 5] set the zoom (with origin as target - 0,0,0)
camera.zoom = 100;
// 6] make the plains and apply bitmap to the plane
// need to create a material (if loading a file need to use class: BitmapFileMaterial)
// var bam:BitmapAssetMaterial = new BitmapAssetMaterial("FlashIcon");
var bam:BitmapFileMaterial = new BitmapFileMaterial("http://manewc.com/projects/flash/GlowFilterDemo/gahlordSmall.jpg");
bam.oneSide = false; // we will now be able to see both sides of material
bam.smooth = true; // make it not
for (var i:uint=0; i < 30; i++)
{
// create a new 3d plane
var p:Plane = new Plane(bam,200,203,2,2); // parameters: material / width / height / complexity of plain (higher number is more complex - more processor heavy as well/ complexity of plain)
// add to the scene
scene.addChild(p);
// place within scene
p.x = Math.random() * 1000 - 100;
p.y = Math.random() * 500 - 100;
p.z = Math.random() * 500 - 100;
p.rotationY = Math.random() * 360;
}
// 6b] new listener
this.addEventListener (Event.ENTER_FRAME, render);
function render(e:Event):void
{
camera.x += stage.mouseX - (stage.stageWidth * 0.5);
camera.y += stage.mouseY - (stage.stageHeight * 0.5);
// now we need to render a camera
scene.renderCamera(camera); // pass in camera that we created
}
var filter:BitmapFilter = getBitmapFilter();
var myFilters:Array = new Array();
myFilters.push(filter);
filters = myFilters;
function getBitmapFilter():BitmapFilter {
var color:Number = 0x003366;
var alpha:Number = 0.8;
var blurX:Number = 35;
var blurY:Number = 35;
var strength:Number = 2;
var inner:Boolean = false;
var knockout:Boolean = false;
var quality:Number = BitmapFilterQuality.HIGH;
return new GlowFilter(color,
alpha,
blurX,
blurY,
strength,
quality,
inner,
knockout);
}
Wednesday, March 19th, 2008 at 10:20 am and is filed under Actionscript 3, Papervision. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
I don’t see any blur?