Menu
Riverview Church

BITMAPEFFECTLAYER

BitmapEffectLayer is a layer that allows effects.

EXAMPLE

BitmapEffectLayer

INSTRUCTIONS

  1. Import import org.papervision3d.view.layer.BitmapEffectLayer;
  2. Declare private var layer :BitmapEffectLayer;
  3. Initialize layer = new BitmapEffectLayer(viewport, w, h, transparent, fillColor, clearMode, renderAbove, clearBeforeRender);
    PARAMETER DEFAULT DESCRIPTION
    viewport NONE viewport
    w 640 width
    h 480 height
    transparent true background transparency
    fillColor 0 background color
    clearMode "clear_pre"
    renderAbove false
    clearBeforeRender false
  4. Add effect layer.addEffect(effect);
  5. Add layer viewport.containerSprite.addLayer(layer);
  6. Add object layer.addDisplayObject3D(object);

CODE

´╗┐package
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.filters.BlurFilter;

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.core.effects.BitmapLayerEffect;
    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.DisplayObject3D;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;
    import org.papervision3d.view.layer.BitmapEffectLayer;

    public class Papervision3DBitmapEffectLayer extends Sprite
    {
        private var scene     :Scene3D;
        private var camera    :Camera3D;
        private var viewport :Viewport3D;
        private var layer     :BitmapEffectLayer;
        private var renderer :BasicRenderEngine;
        private var material :ColorMaterial;
        private var material2 :ColorMaterial;
        private var object    :Plane;
        private var object2 :Plane;

        public function Papervision3DBitmapEffectLayer()
        {
            scene = new Scene3D();

            camera = new Camera3D();

            viewport                 = new Viewport3D();
            viewport.autoScaleToStage = true;
            viewport.interactive     = true;
            addChild(viewport);

            layer = new BitmapEffectLayer(viewport);
            layer.addEffect(new BitmapLayerEffect(new BlurFilter(4, 4, 1)));
            viewport.containerSprite.addLayer(layer);

            renderer = new BasicRenderEngine();

            material             = new ColorMaterial(0x000000);
            material.doubleSided = true;
            material.interactive = true;

            material2             = new ColorMaterial(0xff0000);
            material2.doubleSided = true;
            material2.interactive = true;

            object = new Plane(material);
            object.x = -300;
            scene.addChild(object);

            object2 = new Plane(material2);
            object2.x = 300;
            scene.addChild(object2);

            layer.addDisplayObject3D(object);

            object.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver);
            object.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut);
            object.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress);

            object2.addEventListener(InteractiveScene3DEvent.OBJECT_OVER, handleObjectOver);
            object2.addEventListener(InteractiveScene3DEvent.OBJECT_OUT, handleObjectOut);
            object2.addEventListener(InteractiveScene3DEvent.OBJECT_PRESS, handleObjectPress);

            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        private function handleEnterFrame(e:Event):void
        {
            object.yaw(1);
            object2.yaw(1);

            renderer.renderScene(scene, camera, viewport);
        }

        private function handleObjectOver(e:InteractiveScene3DEvent):void
        {
            viewport.containerSprite.buttonMode = true;
        }

        private function handleObjectOut(e:InteractiveScene3DEvent):void
        {
            viewport.containerSprite.buttonMode = false;
        }

        private function handleObjectPress(e:InteractiveScene3DEvent):void
        {
            var do3d :DisplayObject3D = e.displayObject3D;

            if (layer.hasDisplayObject3D(do3d)) {
                layer.removeDisplayObject3D(do3d);
            } else {
                layer.addDisplayObject3D(do3d);
            }
        }
    }
}

Download

Papervision3D Official Documentation

Layer