3D Modeling
3D modeling is the process of creating mathematical representations of 3D objects. Models can be defined using primitive shapes, polygon meshes, curves, or parametric surfaces.
Polygon Meshes
The most common representation. A mesh consists of vertices, edges, and faces (usually triangles or quads) that define the surface of an object.
Triangle Mesh:
Vertex List: Face List (indices):
V0 = (0, 0, 0) F0 = (0, 1, 2)
V1 = (1, 0, 0) F1 = (1, 2, 3)
V2 = (0, 1, 0)
V3 = (1, 1, 0)
V2----V3
|\ | Two triangles form a quad
| \ |
| \ |
| \ |
V0----V1
Indexed format:
vertices = [(0,0,0), (1,0,0), (0,1,0), (1,1,0)]
faces = [[0,1,2], [1,2,3]]
Geometric Primitives
Common primitives:
Cube: 8 vertices, 12 triangles (6 faces)
Sphere: Subdivided icosahedron or UV sphere
Cylinder: Circle extruded along axis
Torus: Donut shape (revolution surface)
Plane: Simple quad or grid
Normal Vectors
Normals define the direction a surface faces at each point. They are essential for lighting calculations and shading.
Face Normal (flat shading):
n = (V1 - V0) ร (V2 - V0)
n = normalize(n)
Vertex Normal (smooth shading):
Average of normals of adjacent faces:
n_v = (n_f1 + n_f2 + ... + n_fn) / n
n_v = normalize(n_v)
Example: Triangle normal
V0 = (0,0,0), V1 = (1,0,0), V2 = (0,1,0)
e1 = V1 - V0 = (1,0,0)
e2 = V2 - V0 = (0,1,0)
n = e1 ร e2 = (0,0,1)
Vertex Attributes
Each vertex can store:
- Position (x, y, z)
- Normal (nx, ny, nz)
- Color (r, g, b, a)
- Texture coordinates (u, v)
- Tangent (for normal mapping)
Vertex Buffer Layout:
[pos.x, pos.y, pos.z, norm.x, norm.y, norm.z, u, v]
|-------------| |-------------| |--------|
Position Normal TexCoord