GLART week 6: Models
February 22, 2006
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:
scene
Reading:
Redbook pages 255-277 "Chapter 7: Display Lists"
Examples:
Load and Render a Model
Sort Triangles for Alpha Rendering
Create a Display List
Examples with GLmodel code, images and models
glart_week6_examples.zip
More models
zip of various obj models
Resources:
3D models and textures
Mapping Texture to an Object in 3DS Max
Wings3D Modelling Tool
Wings3D Tutorials
MilkShape 3D Modelling tool
MilkShape tutorials
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."
"The Opening of the Fifth Seal of the Apocalypse"
by El Greco, (1608-1614), Metropolitan Museum of Art in New York
NOTES:
=================================================================
Model
a structure to hold complex geometry
stores
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
each triangle creates a plane
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 blend together and soften.
File formats
must have list of verts
3 numbers: x,y,z
must have list of faces (triangles)
3 or more vertex IDs: vertID1, vertID2, vertID3 ...
a vertID is an index into the list of vertices
may have normals
may have texture coordinates
may have groups
to describe how parts of a model should be smoothed
and/or material colored
3DS
Discreet's 3D Studio Max
older format
binary (hard to read)
vertices and triangles
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 glmodel contains classes to load models.
use GL_OBJ_Importer.java to import OBJ files
use GL_3DS_Importer.java to import 3DS files
both importers will load the model into a GL_Mesh.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