Sunday, September 27, 2009

Flash Papervision 3D - 3D Animation Using Cube Class | Part 1



Its a nice 3D rotation type of effect, you can say it a sort of 3D animation. The cube will rotate around the camera according to your mouse movements, to give an illusion of 3D rotation. Wann view the 3D animation.

Using Papervision 3D API, Action Script 3.0 and by the help of Plane Class of Papervision 3D this small application is developed. You need Flex SDK for compiling this stuff. Its free available for developing application.

Source Code:

import org.papervision3d.scenes.*;
import org.papervision3d.objects.*;
import org.papervision3d.cameras.*;
import org.papervision3d.materials.*;

// Create the container Sprite
var container:Sprite = new Sprite();
container.x = stage.stageWidth * 0.5;
container.y = stage.stageHeight * 0.5;
addChild(container);

// Setup the 3D scene
var scene:Scene3D = new Scene3D(container);
var camera:Camera3D = new Camera3D();
camera.zoom = 5;

// Create the material
var bam:BitmapAssetMaterial = new BitmapAssetMaterial("layer");// layer is the class name for the bitmap image imported to the library
bam.oneSide = false;
bam.smooth = true;

// Create the 3D cubes
var c:Cube = new Cube(bam, 300, 300, 335, 5, 5, 5);
scene.addChild(c);

this.addEventListener(Event.ENTER_FRAME, render);

function render(e:Event):void
{
    camera.x = (mouseX * 5)-(stage.width*0.5);
    camera.y = (mouseY * 5)-(stage.height*0.5);
    c.rotationX += 5;
    c.rotationY += 5;
    scene.renderCamera(camera);
}


3D rotating cube animation by ~Biti-24X7 on deviantART


Bookmark and Share

0 comments:

Post a Comment

Type here your comments