Вы находитесь на странице: 1из 9

# Polygon Mesh?

## A surface made up of a collection of polygon

Computer Graphics
Lecture #6: Complex 3D Modeling with Polygon Mesh

faces.

Meshes in Modeling
Can be used to create the skin of a solid
object.

Cube Example

Not a solid.... Solid! [Note] some meshes can represent solid or non solid shapes depending on which polygons are shaded in

Simple solids are really just polygon meshes as their faces are polygons (with the exception of real sphere or cone). have created a solid.

## Dening a Polygon Mesh

There are several ways of dening mesh. For the cube we could list each polygon:

the vertices location and normals for each vertex. total: 24 vertices and 24 normals for the 6 faces.

## Dening a Polygon Mesh

A Better Way: Create 3 lists

one for vertices one for faces one for normals

## For the cube there are:

8 vertices, 6 faces, 6 normals

## Dening a Polygon Mesh

vertex 0 1 2 3 4 5 6 7 x, y, z -1.0,-1.0, 1.0 1.0,-1.0, 1.0 1.0, 1.0, 1.0 -1.0, 1.0, 1.0 -1.0,-1.0,-1.0 -1.0, 1.0,-1.0 1.0, 1.0,-1.0 1.0,-1.0,-1.0 vertices, 0,1,2,3 4,5,6,7 5,3,2,6 4,7,1,0 7,6,2,1 4,0,3,5 normal 0 1 2 3 4 5 nx, ny, nz 0.0, 0.0, 1.0 0.0, 0.0,-1.0 0.0, 1.0, 0.0 0.0,-1.0, 0.0 1.0, 0.0, 0.0 -1.0, 0.0, 0.0

## Dening a Polygon Mesh

Traversing a face:

to determine the interior of the polygon to determine the outside of the solid to determine where the normal is pointing

## normals 0,0,0,0 1,1,1,1 2,2,2,2 3,3,3,3 4,4,4,4 5,5,5,5

Traverse a face counterclockwise as seen from the outside of the object. your left.

## The inside of the polygon will always be on

Calculating Normals
Why do we need the normals?

Normal tells us which is the outside of the face. The normal is used for calculating how much light falls on the outside surface. The normal determines how smoothly textures are rendered on the surfaces.

Finding Normals #1
Find the cross product using 3 points on the
surface:

However: If the vectors are almost parallel .. the cross product will be small and inaccuracies will occur! The polygon may not be a perfect planar.
n

Finding Normals #2
Using (Martin) Newells method:
mx = !N1 (yi ynext i )(zi + znexti ) i=0 my = !N1 (zi znext i )(xi + xnexti ) i=0
N1 mz = !i=0 (xi xnext i )(yi + ynexti )

Example:
Consider the polygon with vertices Find the normal to this polygon with
Newells method

## ,z ) where (x , y next isj the jposition ofNthe i-th = ( + 1) mod

i i i

vertex, and is the index of the next vertex around the face.

## Calculating the Normals

Now I have the normals, what am I going to
do with them?

## Applying to our cube

Lets plot the same cube as before, but turn the lights on it. As we expected, the cube is bathed in the same amount of light on each face and therefore appear at.

OpenGL uses the normals to determine where the outside face of the mesh is, and how to light it.

With Normals
glBegin(GL_QUADS); // Start Drawing Quads // Front Face // Normal pointing towards viewer glNormal3f( 0.0f, 0.0f, 1.0f); glVertex3f(-1.0f, -1.0f, 1.0f); glVertex3f( 1.0f, -1.0f, 1.0f); glVertex3f( 1.0f, 1.0f, 1.0f); glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face // Normal pointing glNormal3f( 0.0f, glVertex3f(-1.0f, glVertex3f(-1.0f, glVertex3f( 1.0f, glVertex3f( 1.0f, glEnd(); away from viewer 0.0f,-1.0f); -1.0f, -1.0f); 1.0f, -1.0f); 1.0f, -1.0f); -1.0f, -1.0f);

Properties of Meshes
Solidity

Connectedness

## represents a solid object if faces enclose a positive and nite space.

connected if an unbroken path along polygon edges exists (if nor connected it is more than one object)

Properties of Meshes
Simplicity Planarity

simple, if it is a solid with no holes planar if every face of the object represent a plane: the vertices of each face then lie in a single plane.

## Working with Mesh

//################# VertexID ################### class VertexID{ ! public: ! ! int vertIndex; // index of this vert 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 }; //###################### Mesh ####################### class Mesh{ private: ! int numVerts;! // number of vertices in the mesh ! Point3* pt;! // array of 3D vertices ! int numNormals; // number of normal vectors 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 ! //.. others .. };!

Convexity

convex and concave. The mesh represents a convex object if the line connecting any two points within the object lies wholly inside the object.

## From: Computer Graphics using OpenGL, F.S. Hill JR.

Drawing Mesh

Polyhedra
A polyhedra is a connected mesh of simple
planar polygons enclosing a nite amount of space.

## From: Computer Graphics using OpenGL, F.S. Hill JR.

Simple Polyhedra
A simple polyhedra satises Eulers equation
V E +F = 2

Complex Polyhedra
Eulers formala for complex equation with
holes
V E + F H = 2(C G)
V=24 E=36 F=15 H=3 (number of holes in faces C=1 (number of parts) G=1 (number of through holes)

## V=8 E=12 F=6

Schlegel Diagram
A 2D diagram of a 3D polyhedra as seen in
perspective

A Polyhedra Model
A Model is the unfolded representation of a
solid

## Prisms and Antiprisms

A prism is a polyhedra that embodies certain symmetries and therefore is quite simple to describe. A prism is dened as a sweep or extrusion of a polygon along a straight line.

## Prisms and Antiprisms

An antiprism has a top and bottom of the same polygon. However, the bottom polygon is rotated through n/180 degrees.

Extruded Shapes
Creating Prisms

We take a basic polygon and use it for the top. Then extrude the vertices in some direction for some length.

Example: Arrow

Both the front and back are the same polygon. However, their normals will be in opposite directions.

Example: Tube
A tube can be created by extruding a
polyhedra along a spine.

Tube

## Ex: we can take a simple sphere and drawing

it as it moves around a helix.

But each time the sphere moves, the old sphere is left in the image...

Tubes

By varying the x, y, and z values for the center of the sphere along spiral formulae, we can come up with all kinds of interesting shapes.

Swept surfaces
A swept surface take a simple or complex
2D polygon and rotates it.

Smooth Surfaces
A polygon mesh can also be used to create
smooth surfaces

## step 1: program a data structure to hold the

mesh coordinates.

## Mesh Surface: Step 1

Mesh data structure:
GLfloat Mesh[Height][Width][3]; Vector3 Normals[Height][Width];
(Mesh[3][0][0], Mesh[3][0][1],Mesh[3][0][2])

## Mesh Surface: Step 2

Populate the mesh with coordinates
for(int i = 0; i < Height; i++) { for(int j = 0; j < Width; j++) { Mesh[i][j][0] = j; Mesh[i][j][1] = i; Mesh[i][j][2] = 1; } }

(Mesh[0][0][0], Mesh[0][0][1],Mesh[0][0][2])

## Mesh Surface: Step 3

Draw it :-)
void drawMesh() { for(int i = 0; i < MH-1; i++) { for(int j = 0; j < MW-1; j++) { glBegin(GL_LINE_STRIP); glVertex3f(Mesh[i][j][0],Mesh[i][j][1],Mesh[i][j][2]); glVertex3f(Mesh[i+1][j][0],Mesh[i+1][j][1],Mesh[i+1][j][2]); glVertex3f(Mesh[i+1][j+1][0],Mesh[i+1][j+1][1],Mesh[i+1][j+1][2]); glVertex3f(Mesh[i][j+1][0],Mesh[i][j+1][1],Mesh[i][j+1][2]); glVertex3f(Mesh[i][j][0],Mesh[i][j][1],Mesh[i][j][2]); glEnd(); } } }

## Mesh Surface: Step 4

Create a height map.

## Modify the value of z. (currently 1)

Mesh[i][j][2] = cos(j/2.0)*2;

## Example: Table Cloth

Ingredience:

1 Mesh 1 Bitmap (preferable the same size as the mesh dimension).

Mesh[i][j][2] = pow(x,2) + pow(y,2); // for x and y between -1 and 1 Mesh[i][j][2] = (sin(3.14*x)/3.14*x + sin(3.14*y)/3.14*y);

200x200 mesh

200x200 bitmap

Step 1:
Applying the bitmap to the mesh:
glBegin(GL_QUADS); glNormal3f(Normals[i][j].x, Normals[i][j].y, Normals[i][j].z); glTexCoord2f(j/(float)Width,i/(float)Height); glVertex3f(Mesh[i][j][0],Mesh[i][j][1],Mesh[i][j][2]);

Step 2:
Shape the table cloth.

ripple: y = cos(z)

## drape: y = 1 - pow(x, 4) - pow(z, 4)

Step 3:
Flatten the top
if (Mesh[i][j][1] > 0.5) Mesh[i][j][1] = 0.5; else Mesh[i][j][1] = Mesh[i][j][1];

Step 4:

## Next Class :-D

Procedural Texturing Techniques How do we generate Texture?

Remaining Topics
Curves and Surfaces Fractals Terrain Particle System Ray Tracing

Homework:
[self] try reading BMP les with rgbpixmap.h
library
http://www.cs.su.ac.th/~rawitat/classes/graphics/code/rgbpixmap.h

Homework
Penny Follow todays handouts (bycurtainsBaillie-de Byl) and create mesh-based and table-cloth into your scene from previous homework.

create some objects and map the BMP texture onto it.

Tuesday

## [self] study this:

http://216.249.163.93/bob.pilgrim/515/openGL_programming_04.html

Assignment #2 :-(
Use your imagination. What can you do with your current ability? Modeling a house on a hill, ... We can walk in, and see some nice dining
table and bed? (and probably replace?) person to 3rd person with a key!

## Нижнее меню

### Получите наши бесплатные приложения

Авторское право © 2021 Scribd Inc.