Friday, August 20, 2010

How to draw a cube on flash using papervision with bitmap materials on faces

Here i'm going to show you how we can add a primitive data object cube on to flash canvas using flex and to load 6 different bitmap pictures on to different faces of the cube.

here what we need to know is there are standard names assigned by papervision libraries to a cube.There are:
front, back, right, left, top, bottom & all

'all' is the acronym that we can used to reference all the faces at once.

here is the total sample code:


import org.papervision3d.materials.BitmapFileMaterial;
import org.papervision3d.materials.utils.MaterialsList;
import org.papervision3d.objects.primitives.Cube;



var materialList:MaterialsList = new MaterialsList({
         front:new BitmapFileMaterial("pictures/tiles/1.jpg"),
back:new BitmapFileMaterial("pictures/tiles/2.jpg"),
right:new BitmapFileMaterial("pictures/tiles/3.jpg"),
left:new BitmapFileMaterial("pictures/tiles/4.jpg"),
top:new BitmapFileMaterial("pictures/tiles/5.jpg"),
bottom:new BitmapFileMaterial("pictures/tiles/6.jpg")});

var box:Cube = new Cube(materialList);
scene.addChild(box);

What we do here is first we make a list of faces assigned with a name which is to replace by bitmap material/picture.

then we create the cube with  material list. If there are the names we assigned are matched, then the materials are replaced.
Here is the sample output

No comments:

Post a Comment