Today’s article presents a collection of procedurally-generated 3D shapes for Stage3D. In addition to spheres and cylinders, I’ve added circles, pyramids, cubes, and quads to the mix and refactored them all to inherit from a new Shape3D class. Read on for the full source code for all of these as well as a demo app.

Of the new shapes, only the Circle3D takes any parameter to control its smoothness. For that, you can specify a number of sides and the circle is then generated just like the caps of the Cylinder3D. The remaining shapes—Cube3D, Pyramid3D, and Quad3D—are procedurally-generated from static data since they have no parameters to force creation to occur at runtime. Accordingly, these are much faster to generate as no math is necessary. Further, they don’t have many triangles so the amount of data to upload to the GPU is quite low.

With all that in mind, check out the demo app which creates random shapes and provides camera controls to view them. It looks like this:

Demo App's random shapes

Since there is much more code involved in this than most articles, I won’t post it all inline here in the article but instead make it available as a ZIP file so you’ll have everything you need to check it out and build it for yourself: source code, sample texture, HTML viewer.

Spot a bug? Have a question or suggestion? Post a comment!