Defining 3D Meshes

So far we've only used a couple of triangles as placeholders for objects in our worlds. What about more complex objects?

We already talked about how the GPU is just a big, mean triangle-rendering machine. All our 3D objects therefore have to be composed of triangles as well. In the previous chapters we used two triangles to represent a flat rectangle. The principles we used there, like vertex positioning, colors, texturing, and vertex indexing, are exactly the same in 3D. Our triangles are just not limited to lie in the x-y plane anymore; we can freely specify each vertex's position in 3D space.

How do we go about creating such soups of triangles that make up a 3D object? We can do that programmatically, as we've done for the rectangles of our sprites. We could also use software that lets us sculpture 3D objects in a WYSIWYG fashion. There are various paradigms used in those applications, ranging from manipulating separate triangles to just specifying a couple of parameters that output a so-called triangle mesh (a fancy name for a list of triangles that we'll adopt).

Prominent software packages like Blender, 3ds Max, ZBrush, and Wings 3D provide users with tons of functionality for creating 3D objects. Some of them are free (e.g., Blender and Wings 3D), and some of them are commercial (e.g., 3ds Max and ZBrush). It's not within the scope of this book to teach you how to use one of these programs, so we'll do something else instead. All these programs can save the 3D models to different file formats. The Web is also full of free-to-use 3D models. We'll write a loader for one of the simplest and most common file formats in use in the next chapter.

In this chapter we'll do everything programmatically. Let's create one of the simplest 3D objects we can come up with: a cube.

0 0

Post a comment