Menu
Samaritan's Purse

VIEWPORT3D

Viewport3D is the area of the 3D environment to render.

EXAMPLE

Viewport3D

INSTRUCTIONS

  1. Import import org.papervision3d.view.Viewport3D;
  2. Declare private var viewport :Viewport3D;
  3. Initialize viewport = new Viewport3D(viewportWidth, viewportHeight, autoScaleToStage, interactive, autoClipping, autoCulling);
    PARAMETER DEFAULT DESCRIPTION
    viewportWidth 640 viewport width
    viewportHeight 480 viewport height
    autoScaleToStage false set viewport size to stage size
    interactive false listen for mouse events
    autoClipping true not render objects outside viewport
    autoCulling true not render triangles hidden behind other triangles
  4. Add addChild(viewport);

CODE

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

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.objects.primitives.Plane;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;

    public class Papervision3DViewport3D extends Sprite
    {
        private var scene    :Scene3D;
        private var camera :Camera3D;
        private var viewport :Viewport3D;
        private var renderer :BasicRenderEngine;
        private var material :ColorMaterial;
        private var object :Plane;

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

            camera = new Camera3D();

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

            renderer = new BasicRenderEngine();

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

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

            addEventListener(Event.ENTER_FRAME, handleEnterFrame);
        }

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

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

Download

Papervision3D Official Documentation