1 of 15

��� Chapter III�Modeling

All class materials including this PowerPoint file are available at

https://github.com/medialab-ku/openGLESbook

Introduction to Computer Graphics with OpenGL ES (J. Han)

2 of 15

Polygon Mesh

3-2

  • Implicit representation vs. explicit representation (in polygon mesh)

  • The polygon mesh representation is preferred in real-time applications because the GPU is optimized for processing polygons.
  • Note that the mesh vertices are the points that sample the smooth surface and therefore the polygon mesh is not an accurate representation but an approximate one.

Introduction to Computer Graphics with OpenGL ES (J. Han)

3 of 15

Polygon Mesh (cont’d)

3-3

  • A triangle is the simplest polygon and the triangle (or triangular) mesh is most popularly used.
  • In a typical closed mesh, the number of triangles is approximately twice the number of vertices, e.g., given 100 vertices, we have about 200 triangles.

  • Even though the triangle mesh is far more popular in general, the quad mesh is often preferred, especially for modeling step.

  • A straightforward method to convert a quad mesh into a triangle mesh is to split each quad into two triangles.

triangle mesh

quad mesh

Introduction to Computer Graphics with OpenGL ES (J. Han)

4 of 15

Polygon Mesh (cont’d)

3-4

  • Modeling with quad meshes (revisited)

Introduction to Computer Graphics with OpenGL ES (J. Han)

5 of 15

Polygon Mesh (cont’d)

3-5

simplification

refinement

  • The vertex count of a polygon mesh is described as a resolution or level of detail (LOD).
  • Tradeoff between accuracy and efficiency: As the resolution increases, the shape of the mesh becomes closer to the ‘original’ smooth surface, but the time needed for processing the mesh also increases.

Introduction to Computer Graphics with OpenGL ES (J. Han)

6 of 15

Polygon Mesh – Non-indexed Representation

3-6

  • The vertices are enumerated in a memory space, named vertex array.
  • Three vertices are read in linear order to make up a triangle.

  • It is inefficient because the vertex array contains redundant data, e.g., (1,0).

Introduction to Computer Graphics with OpenGL ES (J. Han)

7 of 15

Polygon Mesh – Indexed Representation

3-7

  • A better method is using a separate index array.
    • A vertex appears “only once” in the vertex array.
    • Three indices per triangle are stored in the index array.

  • The data stored in the vertex array are not restricted to vertex positions but include a lot of additional information. (All of these data will be presented one by one throughout this class.)
  • Therefore, the vertex array storage saved by removing the duplicate data outweighs the additional storage needed for the index array.

Introduction to Computer Graphics with OpenGL ES (J. Han)

8 of 15

Surface Normals

3-8

  • Surface normals play a key role in computer graphics.
  • Given triangle 〈p1, p2, p3〉, let v1 denote the vector connecting the first vertex (p1) and the second (p2). Similarly, the vector connecting the first vertex (p1) and the third (p3) is denoted by v2. Then, the triangle normal can be computed using the cross product based on the right-hand rule.

  • Every normal vector is made to be a unit vector by default.

  • Note that p1, p2 and p3 are ordered counter-clockwise (CCW).

Introduction to Computer Graphics with OpenGL ES (J. Han)

9 of 15

Surface Normals (cont’d)

3-9

  • What if the vertices are ordered clockwise (CW), i.e., 〈p1, p3, p2〉?
  • The vector connecting the first vertex (p1) and the second (p3) and that connecting the first vertex (p1) and the third (p2) define the triangle normal.

  • The normal is in the opposite direction!
  • The normal direction depends on the vertex order, i.e., whether 〈p1, p2, p3〉 or 〈p1, p3, p2〉.
  • In computer graphics, surface normals are supposed to point out of the polyhedron. For this, we need CCW ordering of the vertices, i.e., 〈p1, p2, p3〉, not 〈p1, p3, p2〉.

Introduction to Computer Graphics with OpenGL ES (J. Han)

10 of 15

Surface Normals (cont’d)

3-10

  • In the index array, the vertices are ordered CCW.

Introduction to Computer Graphics with OpenGL ES (J. Han)

11 of 15

Surface Normals (cont’d)

3-11

  • We have discussed the triangle normals, but more important are the vertex normals. A normal can be assigned to a vertex such that the vertex normal approximates the normal of the smooth surface’s point that the vertex samples.

  • A vertex normal can be defined by averaging the normals of all the triangles sharing the vertex.

  • Modeling packages such as 3ds Max do compute vertex normals.
  • Vertex normals are an indispensable component of the vertex array.

Introduction to Computer Graphics with OpenGL ES (J. Han)

12 of 15

Export and Import

3-12

  • Polygon meshes (and related data) created using off-line graphics packages, such as 3ds Max, are stored in files and passed to the 3D application programs such as game engines.
    • The process of outputting the data in a format suitable for other applications is called export.
    • On the other hand, taking such exported data is called import.

  • For exporting and importing, simple scripts or programs are used. For example, 3ds Max provides MAXScript so that an exporter can be written in MAXScript.
  • In 3ds Max, a lot of file formats are supported for export. Among the popular is .obj file.

file

export

import

application 2

application 1

Introduction to Computer Graphics with OpenGL ES (J. Han)

13 of 15

Export and Import (cont’d)

3-13

  • Consider a low-resolution mesh of a unit sphere.
    • The sphere surface is uniformly sampled at every 45 degrees along both latitude and longitude such that the mesh is composed of 26 vertices and 48 triangles.
    • Shown below are some snippets of the .obj file for the mesh.

Introduction to Computer Graphics with OpenGL ES (J. Han)

14 of 15

Export and Import (cont’d)

3-14

  • In the previous example, each vertex is associated with a distinct normal. However, multiple vertices may share a normal, and a vertex may be associated with multiple normals. In the example, three vertices of the blue triangle share the same normal, leading to f 23//12 24//12 25//12, for example.

Introduction to Computer Graphics with OpenGL ES (J. Han)

15 of 15

Export and Import (cont’d)

3-15

  • The mesh stored in the .obj file is imported into the vertex and index arrays of the 3D application. Parsing the .obj file, “a distinct pair” of vertex position and normal creates “a cell” in the vertex array (with no redundancy). When f 1//1 2//2 3//3 f 2//2 4//4 5//5 have been read, for example, five cells are created.
  • As the mesh is composed of 48 triangles, the index array has 144 (48 times 3) elements.

Introduction to Computer Graphics with OpenGL ES (J. Han)