Skip to content

Generate a triangle mesh from a parametric equation.

Notifications You must be signed in to change notification settings

ornata/paramesh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

paramesh

The bagel immersion of a Klein bottle

Generate a triangle mesh from a parametric equation. This is done by taking the surface and "cutting it up" into "rings" and "slices". Two angles, theta and phi step along the rings and the slices to form quads on the mesh, which are then broken up into two triangles.

For example, for a sphere we'd break it up like this:

More rings and slices will mean more triangles in the mesh. 32 rings and 32 slices seems to work pretty well for building a generally smooth mesh.

Thanks to Nicolas Guillemot (@nlguillemot) for pointing me towards this method for triangulating a sphere. I'm glad it generalizes so well to other surfaces!

Requirements

  • Some sort of vector math library. I used glm. You can easily sub your own in by editing mesh.hpp. (I'll make this more standalone when I have time; it's extracted from a much larger assignment, and it made more sense to use a separate library there!)
  • A C++ compiler that supports at least C++11.

Usage

mesh_generators.cpp contains some sample functions for generating meshes. You can easily create your own mesh-generating function (or a general function) by using those functions as a model.

Making a Mesh-Generating Function
  1. Create a list of vertices and triangles for the mesh
  2. Create a lambda vec3 f(float u, v) where u, v define angles in radians. u=theta is the angle between horizontal cuts in the surface, and v=phi is the angle between vertical cuts in the surface
  3. Call GeneratePoints with your lambda
  4. Call GenerateFaces to generate the triangles for the mesh
  5. Call GenerateVertexNormals
  6. Copy over the number of vertices, number of triangles, and the lists to the mesh

After, you can use the resulting TriangleMesh type directly, or you can output to a file by calling WriteMesh.

About

Generate a triangle mesh from a parametric equation.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages