Procedurally-Generated Shape Collection
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:
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!
#1 by Volgogradetzzz on July 30th, 2012 ·
You forgot about doughnut :)! BTW, thanks for useful source.
#2 by jackson on July 30th, 2012 ·
A torus is a good idea!
#3 by AlexG on July 30th, 2012 ·
Thanks! I want to ask what do you think about Away 3D 4 ?
Would be good if comments system would have email notifications… Like Facebook comments plugin…
#4 by jackson on July 30th, 2012 ·
I haven’t had time to really look at Away3D 4, so I’ll hold comment on it for now. I’ll look into the e-mail notifications feature. Thanks for the tip. In the meantime, there is an RSS feed for the comments.
#5 by orion elenzil on August 2nd, 2012 ·
for folks interested in procedurally generated surfaces and computational geometry in general, Paul Bourke’s site can’t be beat: http://paulbourke.net/geometry