Menu
Samaritan's Purse

CYLINDER

Cylinder is a primitive object.

EXAMPLE

Cylinder

INSTRUCTIONS

  1. Import import org.papervision3d.objects.primitives.Cylinder;
  2. Declare private var object :Cylinder;
  3. Initialize object = new Cylinder(material, radius, height, segmentsW, segmentsH, topRadius, topFace, bottomFace);
    PARAMETER DEFAULT DESCRIPTION
    material null material properties
    radius 100 radius
    height 100 height
    segmentsW 8 horizontal segments
    segmentsH 6 vertical segments
    topRadius -1 top radius, -1 sets topRadius = radius
    topFace true draw top face
    bottomFace true draw bottom face
  4. Add scene.addChild(object);

CODE

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

    import org.papervision3d.cameras.Camera3D;
    import org.papervision3d.events.InteractiveScene3DEvent;
    import org.papervision3d.materials.ColorMaterial;
    import org.papervision3d.materials.WireframeMaterial;
    import org.papervision3d.materials.special.CompositeMaterial;
    import org.papervision3d.objects.primitives.Cylinder;
    import org.papervision3d.render.BasicRenderEngine;
    import org.papervision3d.scenes.Scene3D;
    import org.papervision3d.view.Viewport3D;

    public class Papervision3DCylinder extends Sprite
    {
        private var scene    :Scene3D;
        private var camera :Camera3D;
        private var viewport :Viewport3D;
        private var renderer :BasicRenderEngine;
        private var material :CompositeMaterial;
        private var object :Cylinder;

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

            camera = new Camera3D();

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

            renderer = new BasicRenderEngine();

            material             = new CompositeMaterial();
            material.doubleSided = true;
            material.interactive = true;
            material.addMaterial(new ColorMaterial(0x000000, 0.5));
            material.addMaterial(new WireframeMaterial(0x000000));

            object = new Cylinder(material, 400, 400);
            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);

            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 color :uint = Math.random() * 0xFFFFFF;

            material.removeAllMaterials();
            material.addMaterial(new ColorMaterial(color, 0.5));
            material.addMaterial(new WireframeMaterial(color));
        }
    }
}

Download

Papervision3D Official Documentation