Monday, September 9, 2013

Primitive 3d shapes using CC3ParametricMeshes

In the past few weeks, we looked at how to load/use materials but I always glossed over how to create our drawing data when running through some examples. Well, no more! Using cocos3d's CC3ParametricMeshes we can painlessly create a collection of different 3d primitive shapes. First, we create our object as so

CC3ParametricMeshes mesh = new CC3ParametricMeshes(0, "myShape");

and then we specify the appropriate populate method for the particular shaper we're after that will load the corresponding locations, normals and tex coordinates. So, we could create a sphere by

// radius and tessellation
mesh.PopulateAsSphere(3.0f, new CC3Tessellation(50,50));

or a cone by calling

// base radius, height and tessellation
mesh.PopulateAsHollowCone(3.0f, 5.0f, new CC3Tessellation(50, 50));

and so on. Currently, within Cocos3D-XNA the CC3ParametricMeshes class additionally provides support for creating rectangles and planes.

Once we've populated our mesh, that's pretty much it with respect to our drawing data! It's just a matter of associating our mesh with a corresponding material and putting it altogether as seen below

Click to enlarge

No comments:

Post a Comment