[AS 3] Papervision Random Cube Spin
No commentsI just wanted to play around a little more with the materials available for Papervision, not to mention I found this tutorial (http://labs.zeh.com.br/blog/?p=95) and used the tutorial’s code as my base. This was also a good time to get use to using Tweener. One note is that I used a MovieClip in my library to materialize a side of the cube I had an issue with not making the registration point of the MovieClip the top left area - I should have realized this as this is documented.
Here is the document class:
package {
import flash.display.*;
import flash.events.*;
import flash.ui.Keyboard;
import org.papervision3d.cameras.*;
import org.papervision3d.events.*;
import org.papervision3d.materials.*;
import org.papervision3d.objects.*;
import org.papervision3d.scenes.*;
import fl.controls.Button;
import org.papervision3d.core.proto.DisplayObjectContainer3D;
import caurina.transitions.Tweener;
public class PapervisionRandomSpin extends Sprite {
private var container:Sprite;
private var scene:Scene3D;
private var freeCamera:FreeCamera3D;
private var rootNode:DisplayObject3D;
private var ml:MaterialsList = new MaterialsList();
private var bmp:BitmapFileMaterial = new BitmapFileMaterial("http://manewc.com/projects/flash/PapervisionCubeSides/ski.jpg");
private var customcube:Cube;
private var randomBtn:Button;
public function PapervisionRandomSpin() {
// Main setup
stage.quality = "HIGH";
stage.scaleMode = "noScale";
// Creates container
container = new Sprite();
addChild(container);
container.x = 200;
container.y = 230;
// Create scene
scene = new Scene3D(container);
// Create camera
freeCamera = new FreeCamera3D();
freeCamera.zoom = 50;
freeCamera.y = 0;
freeCamera.x = -100;
freeCamera.z = -6000;
rootNode = new DisplayObject3D("rootNode");
scene.addChild(rootNode);
var ml:MaterialsList = new MaterialsList();
ml.addMaterial(bmp, 'face1');
ml.addMaterial(new ColorMaterial(Math.random() * 0xffffff), 'face2');
ml.addMaterial(bmp, 'face3');
ml.addMaterial(new ColorMaterial(Math.random() * 0xffffff), 'face4');
// mcCircle is the linkage name to my movie clip in the .fla library
ml.addMaterial(new MovieAssetMaterial("mcCircle"), 'face5');
ml.addMaterial(new ColorMaterial(Math.random() * 0x336699), 'face6');
customcube = new Cube( ml, 200, 200, 200, 1, 1, 1 );
rootNode.addChild( customcube, "myCube01" );
var randomBtn = new Button();
randomBtn.width = 100;
randomBtn.height = 30;
randomBtn.move ( stage.stageWidth - randomBtn.width - 10, stage.stageHeight - randomBtn.height - 10 );
randomBtn.label = "Random Spin";
addChild(randomBtn);
randomBtn.addEventListener(MouseEvent.CLICK, randomSpin);
setChildIndex(container, 0);
addEventListener( Event.ENTER_FRAME, loop3D );
}
private function loop3D( event :Event ):void {
scene.renderCamera(freeCamera);
}
private function randomSpin(event:Event):void {
Tweener.addTween(rootNode, {rotationY:Math.random() * 360, time:Math.random() * 10, transition:"easeinoutexpo"});
Tweener.addTween(rootNode, {rotationZ:Math.random() * 360, time:Math.random() * 10, transition:"easeinoutexpo"});
Tweener.addTween(rootNode, {rotationX:Math.random() * 360, time:Math.random() * 10, transition:"easeinoutexpo"});
}
}
}
Here is my document class
Tuesday, March 25th, 2008 at 9:59 am and is filed under Actionscript 3, Papervision. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.