ofMeshfile
ofMeshclass
Represents a set of vertices in 3D spaces with normals, colors, and texture coordinates at those points.
Each of these different properties is stored in a vector. Vertices are passed to your graphics card and your graphics card fill in the spaces in between them in a processing usually called the rendering pipeline. The rendering pipeline goes more or less like this:
- Say how you're going to connect all the points.
- Make some points.
- Say that you're done making points.
You may be thinking: I'll just make eight vertices and voila: a cube. Not so quick. There's a hitch and that hitch is that the OpenGL renderer has different ways of connecting the vertices that you pass to it and none are as efficient as to only need eight vertices to create a cube.
You've probably seen a version of the following image somewhere before.
Generally you have to create your points to fit the drawing mode that you've selected because of whats called winding. A vertex gets connected to another vertex in the order that the mode does its winding and this means that you might need multiple vertices in a given location to create the shape you want. The cube, for example, requires eighteen vertices, not the eight that you would expect. If you note the order of vertices in the GL chart above you'll see that all of them use their vertices slightly differently (in particular you should make note of the GL_TRIANGLE_STRIP example). Drawing a shape requires that you keep track of which drawing mode is being used and which order your vertices are declared in.
If you're thinking: it would be nice if there were an abstraction layer for this you're thinking right. Enter the mesh, which is really just an abstraction of the vertex and drawing mode that we started with but which has the added bonus of managing the draw order for you. That may seem insignificant at first, but it provides some real benefits when working with complex geometry.
A very typical usage is something like the following:
Now it's important to make sure that each vertex is correctly connected with the other vertices around it. This is done using indices, which you can set up like so:
Construction
Primitive constructor helper methods
Vertices
Normals
Faces
Colors
Texture Coordinates
Indices
Drawing
ofMeshFaceclass
An ofMeshFace is a face on one of the ofPrimitive instances. In the ofPrimitive a face consists of 3 points connected together.
You can get a vector of ofMeshFace instances from any ofPrimitive like so:
They're very handy for manipulating individual vertices or doing strange/fun things with intersection and boundary testing, among many many other things.
this is always a triangle