Cube

Cube is a primitive object.

Example

Cube

Instructions

  1. Import import org.papervision3d.objects.primitives.Cube;
  2. Declare private var object :Cube;
  3. Initialize object = new Cube(materials, width, depth, height, segmentsS, segmentsT, segmentsH, insideFaces, excludeFaces);
    Parameter Default Description
    materials NONE material list properties
    width 500 width
    depth 500 depth
    height 500 height
    segmentsS 1 sagital segments
    segmentsT 1 transversal segments
    segmentsH 1 horizontal segments
    insideFaces 0 visible inside faces
    excludeFaces 0 uncreated faces
  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.materials.utils.MaterialsList;
  import org.papervision3d.objects.primitives.Cube;
  import org.papervision3d.render.QuadrantRenderEngine;
  import org.papervision3d.scenes.Scene3D;
  import org.papervision3d.view.Viewport3D;

  public class Papervision3DCube extends Sprite
  {
    private var scene     :Scene3D;
    private var camera    :Camera3D;
    private var viewport  :Viewport3D;
    private var renderer  :QuadrantRenderEngine;
    private var material  :CompositeMaterial;
    private var material2 :CompositeMaterial;
    private var material3 :CompositeMaterial;
    private var material4 :CompositeMaterial;
    private var material5 :CompositeMaterial;
    private var material6 :CompositeMaterial;
    private var materials :MaterialsList;
    private var object    :Cube;

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

      camera = new Camera3D();

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

      renderer = new QuadrantRenderEngine();

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

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

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

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

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

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

      materials = new MaterialsList({
        //all:    material,
        front:  material,
        back:   material2,
        right:  material3,
        left:   material4,
        top:    material5,
        bottom: material6});

      object = new Cube(materials);
      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));

      object.material = material;
    }
  }
}

Download

External

Papervision3D Official Documentation