

Papervision Popup Book : The source - Just the elements on the stage
Posted by admin in AS3, Adobe, Expert, Flash, Papervision, Source Code, Tutorials
Sorry for putting this up so late. This code is only used to arrange the items on the stage. Much work and re-working will need to be done to even start to achieve the effect of the ecodazoo website. Anyways, perhaps this will get someones brain moving in the right direction and help lead us in the path to re-creating this effect fully. As soon as I get some free time I will post a version that is a true popup book in papervision.
If anyone gets a chance sooner to do some cool things with the code please shoot me an email or a blog post and I would love to share it, with myself and with everyone else.
Don't forget the other code you will need to compile:
2) Tweener
-
package {
-
import caurina.transitions.Tweener;
-
import org.papervision3d.cameras.FreeCamera3D;
-
import org.papervision3d.core.data.qTree.QuadTree;
-
import org.papervision3d.objects.DisplayObject3D;
-
-
import com.foomonger.utils.Later;
-
-
import flash.display.*;
-
-
import flash.events.Event;
-
import flash.events.MouseEvent;
-
import org.papervision3d.cameras.Camera3D;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.materials.MovieMaterial;
-
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 Main extends Sprite
-
{
-
private var __camera :FreeCamera3D;
-
private var __scene :Scene3D;
-
private var __viewport :Viewport3D;
-
private var __renderer :BasicRenderEngine;
-
-
private var __width :Number;
-
private var __height :Number;
-
private var __background :Shape;
-
-
protected var __wallLeft :DisplayObject;
-
protected var __wallRight :DisplayObject;
-
protected var __wallBack :DisplayObject;
-
protected var __floor :DisplayObject;
-
protected var __tree :DisplayObject;
-
protected var __monster :DisplayObject;
-
-
protected var __moveMatWallLeft :MovieMaterial;
-
protected var __moveMatRightWall :MovieMaterial;
-
protected var __moveMatWallBack :MovieMaterial;
-
protected var __moveMatFloor :MovieMaterial;
-
protected var __moveMatTree :MovieMaterial;
-
protected var __moveMatMonster :MovieMaterial;
-
-
protected var __plane_wallLeft :Plane;
-
protected var __plane_rightWall :Plane;
-
protected var __plane_wallBack :Plane;
-
protected var __floorPlane :Plane;
-
protected var __treePlane :Plane;
-
protected var __monsterPlane :Plane;
-
-
protected var __rotation :Number;
-
-
public function Main():void
-
{
-
-
init();
-
-
}
-
protected function init():void
-
{
-
__rotation = 0;
-
-
setDefaultWidthHeight();
-
createChildren();
-
initPapervision();
-
initMaterials();
-
initObjects();
-
initEvents();
-
}
-
protected function setDefaultWidthHeight():void
-
{
-
__width = 1000;
-
__height = 600;
-
}
-
-
protected function initPapervision():void
-
{
-
__scene = new Scene3D();
-
__camera = new FreeCamera3D();
-
-
__camera.zoom = 11;
-
__camera.z = -2000;
-
__camera.y = 20;
-
-
__viewport = new Viewport3D(__width,__height,false,true,true);
-
__renderer = new BasicRenderEngine();
-
addChild(__viewport);
-
}
-
-
protected function initMaterials():void
-
{
-
-
__moveMatRightWall = new MovieMaterial(__wallRight, true)
-
__moveMatWallLeft = new MovieMaterial(__wallLeft, true);
-
__moveMatWallBack = new MovieMaterial(__wallBack)
-
__moveMatFloor = new MovieMaterial(__floor);
-
__moveMatTree = new MovieMaterial(__tree, true );
-
__moveMatMonster = new MovieMaterial(__monster, true);
-
-
__moveMatRightWall.doubleSided = true;
-
__moveMatWallLeft.doubleSided = true;
-
__moveMatWallBack.doubleSided = true;
-
__moveMatTree.doubleSided = true;
-
__moveMatFloor.doubleSided = true;
-
__moveMatTree.doubleSided = true;
-
__moveMatMonster.doubleSided = true;
-
-
}
-
-
protected function initObjects():void
-
{
-
-
__monsterPlane = new Plane(__moveMatMonster, 184, 237, 4, 4);
-
__plane_rightWall = new Plane(__moveMatRightWall, 386, 239, 4,4)
-
__plane_wallBack = new Plane(__moveMatWallBack, 734, 240, 4,4);
-
__plane_wallLeft = new Plane(__moveMatWallLeft,386,239,4,4)
-
__floorPlane = new Plane(__moveMatFloor, 800, 800, 14,14);
-
__treePlane = new Plane(__moveMatTree, 79, 112, 4, 4);
-
-
__scene.addChild(__floorPlane);
-
__scene.addChild(__plane_wallBack);
-
__scene.addChild(__treePlane);
-
__scene.addChild(__plane_wallLeft);
-
__scene.addChild(__plane_rightWall);
-
__scene.addChild(__monsterPlane);
-
-
__floorPlane.y = -120;
-
__treePlane.y = -69;
-
__floorPlane.pitch(90);
-
-
__monsterPlane.z = -300;
-
__monsterPlane.x = 150;
-
__monsterPlane.y = -10;
-
-
__plane_wallBack.z += 340
-
__treePlane.z = 300;
-
__treePlane.x = -220;
-
-
__plane_wallLeft.x = -155;
-
__plane_rightWall.x = 155;
-
-
__plane_wallLeft.rotationY = -35;
-
__plane_rightWall.rotationY = 35
-
}
-
-
protected function initEvents():void
-
{
-
this.addEventListener(Event.ENTER_FRAME,render);
-
}
-
-
protected function render(e:Event):void
-
{
-
__renderer.renderScene(__scene, __camera, __viewport, true);
-
var moveXAmount:Number = (mouseX - 1000 / 2) * 4
-
var moveYAmount:Number = (mouseY - 600 / 2) * 2
-
if (moveYAmount <0)
-
{
-
moveYAmount = 0;
-
}
-
-
__camera.x = moveXAmount;
-
__camera.y = moveYAmount;
-
__camera.lookAt(__floorPlane)
-
-
}
-
-
protected function createChildren():void
-
{
-
//Movieclips with Export for AS in Library
-
-
__wallBack = new Wall_back();
-
__wallLeft = new Wall_left();
-
__wallRight = new Wall_right();
-
__floor = new Floor();
-
__tree = new Tree();
-
__monster = new Monster();
-
-
}
-
-
}
-
}
read comments (2)Papervision Popup Book : Source Code To Follow Shortly
Posted by admin in AS3, Adobe, Expert, Flash, Papervision
While talking with Mike Britton this evening he sent me this link - http://www.ecodazoo.com/ If you surf around a bit you will eventually make your way to a Popup Book which was created with a custom engine (Sharikura 3D) written by Roxik. I decided to take a try at creating it in Papervision. So far I have some of the elements in place which in itself was kinda fun to put together. I would still need to get it to fold into a book but thought this was neat in itself to post.
Don't worry code will follow shortly. If anyone needs the rough version immediately feel free to send me a message cs54.com[at]gmail[dot]com
Here is a link to my quick version
Controlling a Papervision Cube
Posted by admin in AS3, Adobe, Flash, Intermediate, Papervision, Source Code, Tutorials
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.
-
package
-
{
-
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
-
//[Embed(source="assets/brick.png")]
-
//public var Brick:Class;
-
-
protected var __brick:DisplayObject;
-
-
protected var __brickClip:MovieClip;
-
-
protected var __rotation:Number;
-
-
public function PapervisionControlledCube():void
-
{
-
-
init();
-
-
}
-
protected function init():void
-
{
-
__rotation = 0;
-
-
setDefaultWidthHeight();
-
-
//Only needed for flexbuilder
-
//setupStage();
-
//--------------------------
-
-
createChildren();
-
initPapervision();
-
initMaterials();
-
initObjects();
-
initEvents();
-
}
-
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();
-
addChild(__viewport);
-
}
-
-
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);
-
__scene.addChild(__cube);
-
-
Later.call(this,zoomIn,1000,true);
-
-
}
-
protected function zoomIn(e:Event = null):void
-
{
-
Tweener.addTween(__camera,{z:-1000,transition:"easeInOutQuint",time:1,onComplete:rotateCube})
-
}
-
-
//-----------------------------------------------------------------------
-
//Rotate Cube
-
//-----------------------------------------------------------------------
-
-
protected function rotateCube(e:Event = null):void
-
{
-
-
__rotation += 90;
-
Tweener.addTween(__cube,{rotationY:__rotation,delay:.6,transition:"easeInOutQuint",time:1,onComplete:rotateCube})
-
}
-
-
protected function initEvents():void
-
{
-
this.addEventListener(Event.ENTER_FRAME,render);
-
}
-
-
protected function render(e:Event):void
-
{
-
__renderer.renderScene(__scene,__camera,__viewport,true);
-
}
-
-
protected function createChildren():void
-
{
-
__brick = new Brick();
-
__brickClip = new MovieClip();
-
__brickClip.addChild(__brick);
-
-
}
-
//Only used in flexbuilder
-
private function setupStage():void
-
{
-
stage.stageWidth = __width;
-
stage.stageHeight = __height;
-
stage.align = "cc";
-
stage.scaleMode = "noScale";
-
stage.stageFocusRect = true;
-
-
}
-
}
-
}
Other classes used:
2) Foomonger's Code (Call Later)
3) Tweener
Papervision 2.0 - Getting started from a simple starting example
Posted by admin in AS3, Adobe, Intermediate, Papervision, Tutorials
At first when trying to create my first few Papervision projects it seemed a bit overwhelming. As you work with it more and more you notice that there are really only a few elements for creating a simple Papervision project. Then you can forget about the code and just think about what cool things you can do.
For any Papervision 2.0 project you need:
-
//As always your imports
-
import flash.display.*;
-
import flash.events.Event;
-
import org.papervision3d.scenes.Scene3D;
-
import org.papervision3d.view.Viewport3D;
-
import org.papervision3d.cameras.Camera3D;
-
import org.papervision3d.materials.ColorMaterial;
-
import org.papervision3d.objects.primitives.Plane;
-
import org.papervision3d.render.BasicRenderEngine;
-
-
//1) A Scene
-
var scene:Scene3D = new Scene3D()
-
-
//2) A Camera
-
var camera = new Camera3D()
-
//Setting the camera zoom to 11 will make sure your objects are rendered at 100%
-
camera.zoom = 11;
-
-
//3) A view area "viewport" - think of this as your canvas or stage for your 3D objects
-
var viewport:Viewport3D = new Viewport3D(500,300,false,true,true)
-
-
//4) A render engine
-
var renderer:BasicRenderEngine = new BasicRenderEngine();
-
-
//5) add the viewport to the stage
-
addChild(viewport);
-
-
//6) Something in your scene such as a Plane, Cube, Sphere, etc - in this case a plane with a black color material
-
var plane:Plane = new Plane(new ColorMaterial(0x000000),100,100)
-
//add your object to your scene

