Lecture 7 Notes: Models and Polygon Meshes

Week 4 & 5

  • New lecturer from week 7 to 10.

Models

  • Outline:

    • Polygon Mesh

    • Triangle Mesh

    • OpenGL Functions

Polygon Mesh

  • Continuous objects are modeled using polygon approximations.

  • Object surfaces are approximated using attached polygons.

  • Referred to as "mesh" because of its appearance.

  • Opaque objects: Surface is crucial for light interaction.

  • More polygons lead to more detailed surface modeling but are computationally expensive.

  • Meshes are named as such due to their resemblance to meshes when polygons are viewed without color or shading.

Types of Polygons:
  • Triangle mesh (3 vertices).

  • Quadrilateral mesh (4 vertices).

  • Larger polygons.

  • This module primarily deals with triangle meshes.

Defining a Polygon Mesh:

  • Each polygon requires a certain number of points (vertices).

  • Each vertex in 3D space is defined by three coordinates: X, Y, and Z.

  • A set of vertices is needed to create an object.

  • Edges are line segments connecting two vertices.

  • Chained edges share at least one vertex.

  • Faces (polygons) are formed by connecting all vertices with edges.

  • Simple polygons are made of three or four vertices forming triangle or quadrangle meshes.

Normals:
  • A normal is a direction perpendicular to the surface at a point and defined for each vertex.

  • For a face, the normal can be averaged from the normals of its vertices.

  • Normals are essential for rendering to determine light interaction with the surface.

  • Light interaction depends on the angles between the normal, the light direction, and the view direction.

Properties of Polygon Meshes:

  • Any two faces of the mesh either don't share any nodes, or share one vertex, or share one edge.

  • Manifold meshes: Every edge is shared by exactly two faces, except for border edges.

  • Normals must be consistent in direction (either facing outwards or inwards).

  • Mobius strip is an example that doesn't satisfy normals as they are non consistant.

Approximating Curves with Line Segments (2D Example):

  • Curves can be approximated using line segments.

  • Increasing the number of vertices improves the approximation of the curve.

  • As the number of segments approaches infinity, the approximation gets closer to the true curve.

Mathematical Explanation:
  • Approximating the area of a circle with radius 1.

  • Divide the circle into nn segments.

  • Angle of each segment: α=2πn\alpha = \frac{2\pi}{n}

  • Area of each segment: sin(α)2\frac{\sin(\alpha)}{2}

  • Total area using nn segments: A=nsin(α)2=n2sin(2πn)=πsin(2πn)2πnA = n \cdot \frac{\sin (\alpha)}{2} = \frac{n}{2} \sin \left( \frac{2\pi}{n} \right) = \pi \frac{\sin \left( \frac{2\pi}{n} \right)}{\frac{2\pi}{n}}

  • As nn approaches infinity, 2πn\frac{2\pi}{n} approaches 0.

  • limx0sin(x)x=1\lim_{x \to 0} \frac{\sin(x)}{x} = 1

  • Therefore, limninfA=π\lim_{n \to \inf} A = \pi

  • This proves that increasing the number of vertices to infinity results in the true approximation of the circle.

Approximating Spheres with Polygons (3D Example):

  • Smaller number of polygons results in a rough approximation of the sphere.

  • Increasing the number of polygons gets closer to a true sphere.

  • Complex objects require more polygons for detailed representation.

  • Adapt the number of polygons based on the complexity of different parts of the object.

  • Use a moderate number of polygons for less complex parts and more polygons for more complex parts.

Approximating a Circle in OpenGL (Older Version):

  • Origin at (0,0)(0, 0), radius is 1.

  • Angle of each slice: 2πn\frac{2\pi}{n}

  • Use GLLineLoop to create a loop of line segments.

  • The X and Y coordinates for each point are:

    • X=rcos(θ)X = r \cdot \cos(\theta)

    • Y=rsin(θ)Y = r \cdot \sin(\theta)

    • Where rr is the radius and θ\theta is the angle of the slice.

  • Increasing nn gets closer to the true approximation.

Triangle Mesh in OpenGL:

  • GL_BEGIN and GL_END define the start and end of drawing.

  • GL_VERTEX inputs the vertex values.

  • GL_TRIANGLES: Draws individual triangles.

  • GL_TRIANGLE_STRIP: Creates a strip of triangles by reusing the last two vertices of the previous triangle.

  • GL_TRIANGLE_FAN: Shares the first vertex among all triangles.

Redundant vs. Shared Representation:

  • Redundant method: Uses GL_TRIANGLES and inputs all vertices for each face, even if they are repeated.

  • Shared method: Uses strips or fans to reuse vertices.

Explicit Representation (Redundant):

  • Each triangle requires three vertices.

  • For nn faces, requires 9n9n floats (3 values for each vertex).

  • Vertices are defined as (v<em>0,v</em>1,v2)(v<em>0, v</em>1, v_2)

  • Example:

    • Triangle 1: (1,1,1),(1,1,1),(1,1,1)(1, 1, 1), (1, -1, 1), (-1, 1, 1)

    • Triangle 2: (1,1,1),(1,1,1),(1,1,1)(-1, 1, 1), (-1, -1, 1), (1, -1, 1)

Vertex Array Capability:

  • Enable with GL_ENABLE_CLIENT_STATE.

  • Draw arrays using glDrawArrays.

  • Define the primitive type (GL_TRIANGLES).

  • Specify the starting vertex and the number of vertices to use.

Vertex Buffer Objects (VBOs):

  • Objects created to store arrays in memory for drawing.

  • Used in both explicit and shared representation.

Initializing VBOs:
  • glGenBuffers: Generate the buffer.

  • glBindBuffer: Bind the buffer with an array (GL_ARRAY_BUFFER).

  • glBufferData: Input data into the buffer (vertex array).

  • GL_STATIC_DRAW: Argument when the data is not dynamic.

  • To draw the explicit representation, input triangles as such.

  • Function :glDrawArrays

Shared Representation (Non-Redundant):

  • Assigns an index to each vertex.

  • Refers to the index when defining triangles rather than repeating vertex values.

Example:
  • Vertex (1,1,1)(1, 1, 1) gets index 0.

  • Vertex (1,1,1)(1, -1, 1) gets index 1.

  • Triangle 1: Use indices 0, 1, and 2.

  • Triangle 2: Use indices 1, 2, and 3.

  • Number of floats required becomes much less than explicit representation.

  • With mm vertices, each having 3 numbers, requires 3m3m floats.

  • With nn triangles, requires 3n3n integers for indices.

Shared Representation in OpenGL:

  • For explicit representation:

    • Generate buffer using glGenBuffers.

    • Bind buffer using glBindBuffer.

    • Input using glBufferData.

  • For shared representation:

    • Create an index buffer.

    • Bind buffer with GL_ELEMENT_ARRAY_BUFFER.

    • Input data using glBufferData with the array of indices.

  • To Draw function :glDrawElements

Information for each Vertex:

  • Vertex position (X, Y, Z values).

  • Color information (RGB values).

  • Normal (NX, NY, NZ values) for light interactions, texture mapping, etc.

  • Light source information (type, position).

  • Surface material (reflectivity, absorption).

  • Connectivity.

  • Transparency (alpha channel).

Shading Methods:

  • Flat shading: Fill each face with a single color, leading to visible boundaries and contrast.

  • Interpolated shading: Interpolate values from one edge to another for a smoother color transition across the face.

  • Different shading methods have varying complexity based on the scene and objects.

  • Treats the object in different ways.