Away3D RoundedCube primitive

Flash, Tutorials

roundedcube

One of our users asked on our list last week how to build a RoundedCube… mmm…

The cube is one of the most popular primitives. But none or almost none are rounded cubes, and the very few ones you see around are generated in 3D apps and imported as collada… a waste of bandwidth and ease. The reason for this: no 3D APi for Flash offers one. True until 15 minutes ago.
There is now a RoundedCube primitive in Away3D.

How to use it
First you need to import the class.

import away3d.primitives.RoundedCube;

The roundedcube supports single and multiple materials
like the Cube primitive.

Single material

var mat:BitmapMaterial = new BitmapMaterial(someCoolBmd);

var rc: RoundedCube = new RoundedCube(
		{material:mat, 
		width:1000,
		depth: 1000,
		height: 1000,														  		 		 
		radius:500,												   
		subdivision:3 });
					
view.scene.addChild(rc);

Multiple materials

first you need to import the CubeMaterialsData class.

import away3d.primitives.data.CubeMaterialsData;

Then just declare a material per side, and pass it to the CubeMaterial instance.

var matleft:BitmapMaterial = new BitmapMaterial(someNiceBmd);
var mattop:BitmapMaterial = new BitmapMaterial(someCoolBmd);
var matbottom:BitmapMaterial = new BitmapMaterial(someWoWBmd);
var matfront:BitmapMaterial = new BitmapMaterial(someGreenBmd);
var matright:BitmapMaterial = new BitmapMaterial(someUglyBmd);
var matback:BitmapMaterial = new BitmapMaterial(someFunnyBmd);

var cubedata:CubeMaterialsData = new CubeMaterialsData(
			{top:mattop,
			bottom:matbottom,
			front:matfront,
			back:matback,
			left:matleft, 
			right:matright})

now you just need to pass the variable ‘faces’ as cubedata variable.

var rc: RoundedCube = new RoundedCube(
		{faces:cubedata,
		width: 1000,
		depth: 1000,
		height: 1000,														  		 		 
		radius: 500,												   
		subdivision:3 });
					
view.scene.addChild(rc);

Classic Cube looks soooo passé now… 🙂

Fabrice