Navigation


RSS : Articles / Comments


Papervision 3D ViewportLayer + Effects

8:26 AM, Posted by Jim Foley, No Comment

In this example you'll learn how to apply effects to individual objects in your 3D scene using ViewportLayers and by applying filters directly to your object. Its really only a few extra lines of code to apply your effects. The results (when put into a smooth production) can be quite amazing.

Example Code:
package {
import flash.display.Sprite;
import flash.events.Event;
//For this example you will need to import your desired filters
import flash.filters.BlurFilter;
import flash.filters.DropShadowFilter;


import org.papervision3d.cameras.CameraType;
import org.papervision3d.lights.PointLight3D;
import org.papervision3d.materials.shadematerials.GouraudMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.view.BasicView;
//Import the ViewportLayer class
import org.papervision3d.view.layer.ViewportLayer;


[SWF(width="600", height="400", framerate="31", backgroundColor="0xFFFFFF")]
public class Effects extends Sprite
{
private var view:BasicView;
private var cube:Cube;

public function Effects()
{
view = new BasicView(600, 400, false, false, CameraType.FREE);
var light:PointLight3D = new PointLight3D();
var mat:GouraudMaterial = new GouraudMaterial(light, 0x0066CC, 0x000033);
var matList:MaterialsList = new MaterialsList();
matList.addMaterial(mat, "all");
cube = new Cube(matList, 300, 100, 50, 1, 1, 1);
cube.useOwnContainer = true;
//Use the filters method to apply an array of filters
cube.filters = [new BlurFilter(20, 0, 1), new DropShadowFilter(20, 45, 0x000000, .5, 3, 3, 1, 1)];
//create a new ViewportLayer instance
//a ViewportLayer basically allows objects to be drawn and separated into its own layer
//The getChildLayer parameters are as follows
//getChildLayer(the display object to reference, create new layer)
var layer1:ViewportLayer = view.viewport.getChildLayer(cube, true);


addEventListener(Event.ENTER_FRAME, onRenderViewport);
view.scene.addChild(cube);
addChild(view);
}

private function onRenderViewport(e:Event):void
{
cube.yaw(2);
cube.roll(4);
view.singleRender();
}

}
}

Example: click here
Flash Source: click here
Flex Source: click here

No Comment