Mesh geometry 2
Last updated
Last updated
Working with raw mesh face indices gets old pretty fast. We can use range logic to assemble meshes in a procedural fashion. In this section we will construct conic and loft surfaces in the form of meshes. The same techniques can be used to define all kinds of surfaces including sweeps and revolves.
Below we segment a curve into a list of points and append one additional external point at the end of the vertex list. We can build conic mesh surfaces by connecting each segment with the apex.
We use a technique similar to the cycling and sequential patterns developed for the cube’s faces. For all triangles “A” is the last point’s index in the vertex list. For “B” we use a range up to but not including the last point of the curve and for “C” we use a range from the second all the way to the last point of the curve.
Symbolically we can define a range “[0, n – 1]” for the curve points. In the vertex list we insert the apex at position “n”. Therefore, “A = n”, “B = [0, n – 2]” i.e. without the last point, and “C = B + 1 = [1, n – 1]” i.e. without the first point.
Here we generate two sequences of points from two different curves and link them with quads. The indexing logic is exactly the same as used for the side edges of the cube example.
Symbolically, we define the range R = [0, n – 1]
for the “n” points of each curve. We merge the two lists such that the first curve’s points are now in the range “R” while the second shifts to “n + R”. Therefore, we can index the points using the following expressions A = R
, B = ( R + 1 ) % n
, C = n + B
and finally D = n + A
.
Practice
We do not typically have to construct meshes in this rather tedious manner. Instead we may facet a smooth surface or solid using the existing meshing components. Here we will import a surface, create a parametric mesh and visualize the original surface’s curvatures by colour coding the mesh vertices.
The logic of the graph is pretty simple: first we perform polygonization using the “mesh surface” component which creates a iso-parametric grid of points at regular intervals across the surface’s domain. We then extract mesh’s vertices using the “deconstruct mesh” component. Using the “surface closest point” component we compute the “uv” coordinates of the spatial mesh points. Curvature for each point is then compute using the “surface curvature” component.
The range of curvature values are in an unknown range so we construct a domain using the “bounds” component. We deconstruct the domain such that we can use the minimum and maximum values, along side with the curvature values, to linearly interpolate into the colour gradient component. The final piece of the puzzle comes as we re-assemble the original mesh without any modifications apart from supplying a list of colours per point.
Practice
Map the vertical height from the XY-plane for each point of the surface to create elevation contours type of visualization.
Unlike surfaces, for meshes there two kinds of normal vectors. In the section where we constructed a cube, by manually assembling its face indices, we introduced face normals. In addition, we can define mesh “vertex” normals i.e. one for each point. Those are computed typically by first collecting all faces connected to a point and then averaging their face normals.
The figure illustrates plotting the mesh vertex normals colour coded using the vector components. Unit vectors can take values in [-1, 1] for each component, therefore scaling by 0.5 takes us to [-0.5, 0.5] and adding 0.5 to [0, 1] which we can use for RGB colours defined by [0, 1] components.
The reason we need vertex normals is for light shading. The graph below illustrates this using a “sunlight” direction, defined by spherical coordinates, to compute the light levels on a sphere representing earth.
Practice
Try using the absolute value of the dot product to create an opposite symmetric light source to back light the mesh.
Experiment with multiple light sources. You can use a weighted sum strategy to combine multiple light surfaces where the weights represent light intensities.
Another very typical application in computer graphics is using the vertex normals for producing geometric as opposed to pixel colour effects. In the graph below we use the vertex normals to displace each vertex towards a random direction. This produces effects ranging from subtle noise to crumbed paper taken to the extreme.
Practice
Develop different mesh vertex displacement techniques. You may use any functional relationship that outputs one vector per vertex.
If we use the “unweld mesh” component we force faces to become unlinked from one another. The result of displacing the unwelded version of the original sphere is something like a fracture-like effect seen below.
The inverse of mesh face unwelding is mesh welding. Both operations are controlled by an angle parameter. This expresses the relative angle between adjacent faces to be either welded or unwelded. To completely weld or unweld a mesh we use “π”.
To explain the operations involved in unwelding let’s consider the cube example with eight points and six faces. In the earlier construction we shared the points among several faces by re-using the same index in the faces definition. In fact each point is exactly reused three times because it is connected with three faces of the cube.
Now we will temporarily express faces using directly points instead of integer indices. For example the first face’s “A” index is “4”; we replace it with the point “[-1, -1, 1]”. The result of this in-place substitution for all faces is seen below. Notice that we no longer need the vertex list, as all geometric information is contained in this new list.
Now we will revert back to the vertex and face index list style of mesh description by replacing each point with a consecutive number from zero to twenty three. The result is seen below.
Notice that there are no points shared among faces anymore but at the same time there is tons of duplication. This exactly the reason the vertex list and face indices is the preferred description style i.e. because of the lower memory footprint.
Because mesh colours and normals are defined per vertex, for welded meshes those quantities are also shared among faces. This results to colour bleeding and shading artifacts. However, using unweld meshes allows us to define solid colours and non-averaged normals per face. In conclusion, there are pros and cons for each style of mesh representation.
We can morph between meshes using the linear interpolation approach employed extensively in previous sessions. In the construction below we smoothly transition between a cube and a sphere. The interesting aspect of this sphere is that unlike the polar coordinates globe-like sphere which features two poles i.e. north and south, this one has eight poles because of the corners of the initial cube.
The construction is simple: first we create a box mesh centred about [0,0,0] ie. the world’s origin and extracts its components. We interpret its vertices as vectors from the origin and normalize them. This is equivalent of projection on to the unit sphere. We may call this transform as “spherification”. Finally we scale the vectors to a larger sphere and use linear interpolation to morph between the cube and spherical state.
Practice
Try morphing between meshes that are not so similar to one another. As long as two meshes have the same number of points, no matter if their face configuration is not the same, it is possible to interpolate between them.
Develop a swept surface scheme [] using one curve as spine and the normal vector per point as the profile.
Develop a surface of revolution scheme [] using the world X-axis and 360 degrees. Hint: You may approach it either via rotation or lofting circles.
Map the normal’s angle from the vertical Z-direction per surface point to create a “draft angle” [] visualization of the surface.
The approach is general i.e. it is not only relevant to spherical light probes. Below we imported the Blender’s [] monkey model and replaced the sphere.
Use a gray scale raster image to read off values and displace a mesh along its normals. This is known in computer graphics as bump mapping [] or normal mapping [] but applied per pixel rather than vertex.
Experiment with spherifying different types of triangulated meshes to create geodesic type of domes []. Is it possible to achieve a sphere which features equally sized triangles?