Away3D Programming Tutorial - Primitives

Posted Mar 28, 2009 by mcasperson / comments 0 comments / Print / Font Size Decrease font size Increase font size

See how easy it is to use the build in primitive shapes supplied with Away3D. Demo and source code included.

VIEW THE DEMO
DOWNLOAD THE CODE

Most 3D applications you'll write will need to display custom 3D models. However there are many times when you'll need to display some pretty standard shapes like triangles, cubes and spheres. Rather than have to load these as external meshes, Away3D allows you to create them directly. The away3d.primitives namespace includes a number of common (and one or two not so common) 3D shapes  that you can create and display without the need for external mesh files.

This tutorial builds of code that is explained in the first tutorial of this set, so if you haven't read it then I suggest you do so now.

EngineManager.as

First of all we need to make some small changes to the EngineManager class. All we do here is create a ModelType getter/setter function, which sets the modelType string with the type of primitive that the user wants to display. For convenience we have also created a ModelTypes ArrayCollection, which lists the available modelType's, and can be used as a data source for a GUI control like a ComboBox, which we create in the MXML file.

Primitives.mxml

The beauty of wrapping the Away3D up in a UIComponent is that the MXML code is very basic. As before we add an instance of the EngineManager, and a ComboBox which will set the EngineManager MeshType from the list of options supplied from the ModelTypes ArrayCollection we defined above.

ApplicationManager.as

The ApplicationManager class contains one property: a MeshObject called mesh. This mesh gets initialised with one of ten of Away3D primitives during the call to startupApplicationManager depending on the value of the EngineManager ModelType. The enterFrame function rotates the mesh around by a small amount every frame.

It might not be immediately obvious, but you'll find a lot of opportunities to use these primitive shapes in your own work (except for maybe the sea turtle - I'm not sure that one gets used much). As you can see creating these built in shapes is quite easy, and is a whole lot easier than modelling them externally and loading them in from a 3DS file.

Find more Flash tutorials here.

Rate this Article:

Be the first to rate me.


* You must be logged in order to leave comments, please login or join us.

Comments

No comments yet.



Bookmark and Share
Sign up for our email newsletter
Name:
Email: