Tag Archive for 'Papervision Cube'

Controlling a Papervision Cube

Papervision 3D Cube Example

View Example

The goal for this example was to create a simple way to display a cube, then rotate it one side at a time. The image is just from Google Images which will be all 6 sides of the cube. This again like the exploding image example illustrates some control over your elements. You can easily modify this example to include mouse events that you can use trigger a view each side of the cube.
import caurina.transitions.Tweener;

import com.foomonger.utils.Later;

import flash.display.*;

import flash.events.Event;

import org.papervision3d.cameras.Camera3D;
import org.papervision3d.materials.ColorMaterial;
import org.papervision3d.materials.MovieMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cone;
import org.papervision3d.objects.primitives.Cube;
import org.papervision3d.objects.primitives.Plane;
import org.papervision3d.render.BasicRenderEngine;
import org.papervision3d.scenes.Scene3D;
import org.papervision3d.view.Viewport3D;

public class PapervisionControlledCube extends Sprite
private var __camera:Camera3D;
private var __scene:Scene3D;
private var __viewport:Viewport3D;
private var __renderer:BasicRenderEngine;

private var __cube:Cube;
private var __matList:MaterialsList;

private var __width:Number;
private var __height:Number;

private var __background:Shape;

//Only needed if you are linking the image from FlexBuilder
//public var Brick:Class;

protected var __brick:DisplayObject;

protected var __brickClip:MovieClip;

protected var __rotation:Number;

public function PapervisionControlledCube():void


protected function init():void
__rotation = 0;


//Only needed for flexbuilder

protected function setDefaultWidthHeight():void
__width = 500;
__height = 250;

protected function initPapervision():void
__scene = new Scene3D();
__camera = new Camera3D();

__camera.zoom = 11;
__camera.z = -5000;
__camera.y = 200;

__viewport = new Viewport3D(__width,__height,false,true,true);
__renderer = new BasicRenderEngine();

protected function initMaterials():void
__matList = new MaterialsList();

var movieMat:MovieMaterial = new MovieMaterial(__brickClip);

__matList.addMaterial( movieMat, “front” );
__matList.addMaterial( movieMat, “back” );
__matList.addMaterial( movieMat, “left” );
__matList.addMaterial( movieMat, “right” );
__matList.addMaterial( movieMat, “top” );
__matList.addMaterial( movieMat, “bottom” );


protected function initObjects():void
__cube = new Cube(__matList,250,130,130);


protected function zoomIn(e:Event = null):void

//Rotate Cube

protected function rotateCube(e:Event = null):void

__rotation += 90;

protected function initEvents():void

protected function render(e:Event):void

protected function createChildren():void
__brick = new Brick();
__brickClip = new MovieClip();

//Only used in flexbuilder
private function setupStage():void
stage.stageWidth = __width;
stage.stageHeight = __height;
stage.align = “cc”;
stage.scaleMode = “noScale”;
stage.stageFocusRect = true;

Download Source

Other classes used:

1) Papervision 2.0

2) Foomonger’s Code (Call Later)

3) Tweener

Follow papervision2 on Twitter

RSS Feed