Menu Home

BasicView

osbo.com | Flash | Papervision3D | BasicView

BasicView is a scene, camera, viewport, and renderer together in one class.

Example

BasicView

Instructions - Extending BasicView

  1. Import
    import org.papervision3d.view.BasicView;
  2. Call
    super(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
    Parameter Default Description
    viewportWidth 640 viewport width
    viewportHeight 480 viewport height
    scaleToStage true set viewport size to stage size
    interactive false listen for mouse events
    cameraType "Target" "Target" | "Free" | "Debug" | "Spring"
    "Target" - camera with target x:0 y:0 z:0
    "Free" - camera without target
    "Debug" - camera with mouse/keyboard control and display information
    "Spring" - camera with spring effect
  3. Listen
    startRendering();
  4. Handle
    override protected function onRenderTick(e:Event=null):void {}
  5. Render
    super.onRenderTick(e);

Code - Extending BasicView

package
{
    import flash.events.Event;

    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.view.BasicView;

    public class Papervision3DBasicViewExtension extends BasicView
    {
        private var material :ColorMaterial;
        private var object   :Plane;

        public function Papervision3DBasicViewExtension()
        {
            super(640, 480, true, true, "Target");

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

            object = new Plane(material);
            scene.addChild(object);

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

            startRendering();
            //or
            //addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

        override protected function onRenderTick(e:Event=null):void
        //or
        //private function handleEnterFrame(e:Event):void
        {
            object.yaw(1);

            super.onRenderTick(e);
            //or
            //singleRender();
            //or
            //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
        {
            material.fillColor = Math.random() * 0xFFFFFF;
        }
    }
}

Download

Instructions - Extending Sprite

  1. Import
    import org.papervision3d.view.BasicView;
  2. Declare
    private var view :BasicView;
  3. Initialize
    view = new BasicView(viewportWidth, viewportHeight, scaleToStage, interactive, cameraType);
    Parameter Default Description
    viewportWidth 640 viewport width
    viewportHeight 480 viewport height
    scaleToStage true set viewport size to stage size
    interactive false listen for mouse events
    cameraType "Target" "Target" | "Free" | "Debug" | "Spring"
    "Target" - camera with target x:0 y:0 z:0
    "Free" - camera without target
    "Debug" - camera with mouse/keyboard control and display information
    "Spring" - camera with spring effect
  4. Add
    addChild(view);
  5. Render
    view.singleRender();

Code - Extending Sprite

package
{
    import flash.display.Sprite;
    import flash.events.Event;

    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.view.BasicView;

    public class Papervision3DBasicView extends Sprite
    {
        private var view     :BasicView;
        private var material :ColorMaterial;
        private var object   :Plane;

        public function Papervision3DBasicView()
        {
            view = new BasicView(640, 480, true, true, "Target");
            addChild(view);

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

            object = new Plane(material);
            view.scene.addChild(object);

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

            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

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

            view.singleRender();
            //or
            //view.renderer.renderScene(view.scene, view.camera, view.viewport);
        }

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

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

        private function handleObjectPress(e:InteractiveScene3DEvent):void
        {
            material.fillColor = Math.random() * 0xFFFFFF;
        }
    }
}

Download

Papervision3D Official Documentation