Away3D RoundedCube primitive

Flash, Tutorials Add comments

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

14 Responses to “Away3D RoundedCube primitive”

  1. Peter Says:

    Looks like candy! Thanks for “reshaping” the way cubes are made in Flash 3D :)

  2. xinyi Says:

    I did it,but have a problem .
    1151: A conflict exists with definition rc in namespace internal.
    How to solve it ?

  3. xinyi Says:

    Could you give me the whole code of the Demo,I did it,but have many mistakes.Thanks.

  4. xinyi Says:

    My mail box is dongxinyingying@yahoo.cn

  5. eric Says:

    Hi Fabrice.

    Amazing job! Just wanted to let you know my roundedCube was applying the front material to the back faces, no matter what I set the back material to. I checked in the class and on line 415 it says:

    addFace(createFace(v1,v0,v2, (_cubeMaterials.front == null)? _material : _cubeMaterials.front, uv1, uv0, uv2 ));

    when it should be:

    addFace(createFace(v1,v0,v2, (_cubeMaterials.back == null)? _material : _cubeMaterials.back, uv1, uv0, uv2 ));

    Again, fantastic job! Keep up the amazing work!

  6. Fabrice Says:

    Hi Eric,
    Glad you like my work, allways nice to hear!
    Thx for the fix, i’ll update the trunk asap!

  7. Fabrice Says:

    Just looked at it. This bug was fixed already, what version are you using? Please check out the latest 2.3.

  8. NynjA Says:

    Hi Fabrice,

    Awesome work !!! This is exactly what I was looking for !
    Would you send me the whole project as I’m a beginner in AS3 and Away3D, but thrilled by all you can do with them !!!

    Thank you in advance

  9. NynjA Says:

    Hi again Fabrice,

    When I set the subdivisions to more than 2 (even number) my PhongBitmapMaterial render is quite bad. Any solution to this ?

    Thank you in advance

  10. Fabrice Says:

    it’s not linked to the geometry, extrudes and loaded objects are having similar issues … It’s the way lights are considered that goes wrong somehwere…, we are redoing a lot atm, so keep an eye on the trunk. Hopefully you should be able to render nice phong soon again if not better!

  11. NynjA Says:

    Thank you for your fast answer.
    Is the RoundedCube compatible with interactive textures ?

  12. NynjA Says:

    Yes it is !

  13. juliansmith Says:

    thank for sending this example.

  14. Den Says:

    How are you update RoundedCube?

Leave a Reply

Entries RSS Comments RSS Log in