GLART week 6: Models

Models store the vertices and triangles that make up the "geometry", the shapes that OpenGL renders to the screen. In previous examples we have already created geometry using the glVertex(), glBegin() and glEnd() commands, though these shapes have been very simple. To create complex shapes, we need a way to store complex geometry. The ideas are the same: we're still connecting vertices together to make triangles, but the vertices, normals and texture coordinates have been edited in modelling software such as Maya or 3D Studio Max and stored in a file. Assigment: mid-term Reading: Redbook pages 255-277 "Chapter 7: Display Lists" Examples: Load and Render a Model Create a Display List Sort Triangles for Alpha Rendering Examples with GLmodel code, images and models GLART_2010_march05.zip Resources: TurboSquid 3D modelling resources 3D models and textures Mapping Texture to an Object in 3DS Max Wings3D Modelling Tool MilkShape 3D Modelling tool UVMapper uvw mapping tool (Windows) The End of Perspective: Picasso’s Demoiselles "This is a painting about looking. It announces the collapse - overnight - of traditional modes of perspective and representation that had held firm in western art since the Renaissance." NOTES: ================================================================= Model a structure to hold complex geometry vertex positions faces (usually triangles but may be quads, polygons) may also store: normals texture coordinates more complex features such as skeletal information, animation keyframing, etc. formats vary considerably 3DS is a binary format assigns normals to each vertex OBJ is text has a normal for each vertex in each face normals are important for accurate lighting To create sharp edges there may be multiple normals for one vertex ie. if a vertex is at the corner of a cube, it is shared by three triangles but each triangle has it's own normal (so edge is sharp) If we have one normal at the corner all three faces will be smoothed together. File formats must have list of vertices each vertex is a position: x,y,z must have list of faces (usually triangles) 3 or more vertex IDs: vertID1, vertID2, vertID3 ... a vertex ID is an index into the list of vertices may have normals may have texture coordinates may have groups faces can be organized into groups each group can have a separate material parts of a model can be smoothed separately from other parts 3DS Discreet's 3D Studio Max older format binary (hard to read) contains vertices and triangles (may also contain animation data) one normal for each vertex 3DS Max splits single verts into multiple when it saves 3DS file so it can store normal for each vert in each triangle Can store animation Specification: http://www.dcs.ed.ac.uk/home/mxr/gfx/3d/3DS.spec OBJ Maya newer format vertices and faces (may be triangles, quads or polygons) text (easy to read) normals are specified for each vertex in each face optional material file .mtl for materials Stores only geometry, no animation Specification: http://www.dcs.ed.ac.uk/home/mxr/gfx/3d/OBJ.spec Load Model package JOModel contains classes to load models. use JOOBJImporter.java to import OBJ files use JO3DSImporter.java to import 3DS files both importers will load the model into a JOMesh.java object the GL_Mesh holds vertices and triangles in arrays for fast access. the Importer converts OBJ faces into triangles OBJ files may contain triangle, quad or polygon face for simplicity, convert them triangles. see GL_Mesh.regenerateNormals() to calculate normals useful for models that don't have normals smooths normals for triangles that are on same surface calcs separate normals for triangles that are on different surfaces angle of triangles determines if it's on same surface or not. Render Model loop through all triangles set normal, texture coordinate, vertex for each point of triangle Display lists Optimize rendering by "pre-compiling" geometry glGenLists(): allocate a new display list glNewList(): begin OpenGL rendering commands glEndList(): end rendering commands glDeleteLists(): free up resources when exiting program "Freeze" a shape can't be changed once in a display list can include rendering commands glColor() glMaterial() geometry can be stored on graphics card for fast access Render geometry with a single function call glCallList() very efficient renders compiled geometry