Download Polygonal Meshes - Computer Graphics - Lecture Slides and more Slides Computer Graphics in PDF only on Docsity!
Computer Graphics
3D Modeling: Polygonal Meshes
@
Docsity.com
3D Modeling n Previously n Introduced 3D modeling n Previously introduced GLUT models (wireframe/solid) and Scene Description Language (SDL): 3D file format n Previously used GLUT calls n Cylinder: glutWireCylinder( ), glutSolidCylinder( ) n Cone: glutWireCone( ), glutSolidCone( ) n Sphere: glutWireSphere( ), glutSolidSphere( ) n Cube: glutWireCube( ), glutSolidCube( ) n Newell Teapot, torus, etc Docsity.com Non-solid Objects n Examples: box, face n Visualize as infinitely thin skin n Meshes to approximate complex objects n Shading used later to smoothen n Non-trivial: creating mesh for complex objects (CAD) Docsity.com What is a Polygonal Mesh n Polygonal mesh given by: n Polygon list n Direction of each polygon n Represent direction as normal vector n Normal vector used in shading n Normal vector/light vector determines shading Docsity.com Vertex Normal n Use vertex normal instead of face normal n See advantages later: n Facilitates clipping n Shading of smoothly curved shapes n Flat surfaces: all vertices associated with same n n Smoothly curved surfaces: V1, V2 with common edge share n Docsity.com Newell Method for Normal Vectors n Martin Newell at Utah (teapot guy) n Normal vector: n calculation difficult by hand n Given formulae, suitable for computer n Compute during mesh generation n Simple approach used previously: n Start with any three vertices V1, V2, V3 n Form two vectors, say V1-V2, V3-V2 n Normal: cross product (perp) of vectors Docsity.com Newell Method for Normal Vectors n Problems with simple approach: n If two vectors are almost parallel, cross product is small n Numerical inaccuracy may result n Newell method: robust n Formulae: Normal N = (mx, my, mz) ( )( ))( 1 0 )( inexti N i inextix zzyym +−= ∑ − = ( )( ))( 1 0 )( inexti N i inextiy xxzzm +−= ∑ − = ( )( ))( 1 0 )( inexti N i inextiz yyxxm +−= ∑ − = Docsity.com Newell Method Example n Example: Find normal of polygon with vertices P0 = (6,1,4), P1=(7,0,9) and P2 = (1,1,2) n Solution: Using simple cross product: ((7,0,9)-(6,1,4)) X ((1,1,2)-(6,1,4)) = (2,-23,-5) Using Newell method, plug in values result is the same: Normal is (2, -23, -5) Docsity.com
Meshes in Programs
= Tetrahedron example
a)
y num Verts
pl
numNorms
norm
numFaces
1 face
ae
~I
Sj
w
¥
[
at
ely
Docsity.com
Meshes in Programs n Data structure: // ############### Vertex ID ###################### class VertexID public: int vertIndex; // index of this vertex in the vertex list int normIndex; // index of this vertex’s normal } // ############### Face ###################### class Face public: int nVerts; // number of vertices in this face VertexID *vert; // the list of vertex and normal indices Face( ){nVerts = 0; vert = NULL;} // constructor -Face( ){delete[ ] vert; nVerts = 0; // destructor }; Docsity.com Meshes in Programs // ############### Mesh ###################### class Mesh{ private: int numVerts; // number of vertices in the mesh Point3 *pt; // array of 3D vertices int numNormals; // number of normal vertices for the mesh Vector3 *norm; // array of normals int numFaces; // number of faces in the mesh Face *face; // array of face data //… others to be added later public: Mesh( ); // constructor ~Mesh( ); // destructor int readFile(char *fileName); // to read in a filed mesh ….. other methods…. } Docsity.com Drawing Meshes Using SDL n Scene class reads SDL files n Accepts keyword Mesh n Example: n Pawn stored in mesh file pawn.3vn n Add line: • Push translate 3 5 4 scale 3 3 3 mesh pawn.3vn pop Docsity.com Creating Meshes n Simple meshes easy by hand n Complex meshes: n Mathematical functions n Algorithms n Digitize real objects n Libraries of meshes available n Mesh trends: n 3D scanning n Mesh Simplification Docsity.com 3D Simplification Example Original: 424,000 triangles 60,000 triangles (14%). 1000 triangles (0.2%) (courtesy of Michael Garland and Data courtesy of Iris Development.) Docsity.com