**Examples for Assignment 2** Transformations ======================================================================== Rotation ------------------------------------------------------------------------ `rotate( mesh, rotate )` Rotates a mesh ( or a selected part ) around an axis by number specified in the sliders. The unit used for rotation is radians.   Warps ======================================================================== Twist ------------------------------------------------------------------------ `twist( mesh, factor )` Rotates all vertices `v` along the `Y` axis by `v.position.y * factor`. The units are again radians.   Inflate ------------------------------------------------------------------------ `inflate( mesh, factor )` Moves all vertices in the direction of their respective vertex normals, proportional to a `factor`. For the cube, this operation will give a scaling effect.     It is possible to augment this operation by `averageEdgeLength`. This will give nicer results for the inflated hand - the creases are better preserved, and the inflate operation is now aware of the mesh scale.     Filters ======================================================================== Noise ------------------------------------------------------------------------ `Noise( mesh, factor )` Moves all vertices in the direction of their respective vertex normals, proportional to `mesh.averageEdgeLength(v) * factor * randomIn( -1, 1 )`.   Uniform Laplacian Smoothing ------------------------------------------------------------------------ `smooth( mesh, iter, delta, curvFlow, scaleDep, implicit )` This operation needs to be applied `iter` number of times. For each iteration, each vertex should be moved towards the average of itself and its neighbors. In other words, for a vertex `V` with `N` neighbors, its updated position (`V_new`) should be `V_new = V + (sum(n_i)-N*V)*delta`, where `n_i` are the neighboring vertices. Be careful when updating the position. During a single iteration you want to use original positions throughout the entire computation. Update the actual positions of the vertices only after all new locations have been calculated. This uniform weighting scheme should be active if `curvFlow` is false. In this example, the weights are not normalized to sum to `1`, hence small deltas should be used, as can be seen in the images below.     Curvature-flow Laplacian Smoothing ------------------------------------------------------------------------ `smooth( mesh, iter, delta, curvFlow, scaleDep, implicit )` The same as uniform sampling, but with a different weighting scheme, which can be applied only to triangles. In this case, the update rule is `V_new = V + (sum(w_i * n_i) - sum(w_i)*V)*delta`, where the weights `w_i` are the cotangent weights explained in the slides. Use when `curvFlow` is true. As can be seen (especially in the cut between the two resolutions of the sphere example), this scheme preserves triangle shapes well, and thus preserves features better, but it is still sensitive to triangle sizes. Note that this scheme is even more sesitive to `delta` values then the uniform one. Also note that this scheme is sensitive to long and thin triangles. To overcome this problem on bad meshes, either add checks in the code, or run a few uniform iterations before using this scheme, as was used in the hand example.     Scale-Dependent Smoothing ------------------------------------------------------------------------ `smooth( mesh, iter, delta, curvFlow, scaleDep, implicit )` No matter the weighting scheme, when `scaleDep` is true you should multiply the vertex offset (or matrix row) by the *scale dependent* term. That is,the update rule is `V_new = V + M*(sum(w_i * n_i) - sum(w_i)*V)*delta`, where M is `average(A_v)/A_v' (average of the 1ring area of all vertices over the 1ring of `V`: the sum of areas of the faces adjacent to it). For convenience, you may want to scale the mesh to its original size after each iteration (could be done by keepying the bounding box diagonal to be the same length).     Implicit Smoothing ------------------------------------------------------------------------ `smooth( mesh, iter, delta, curvFlow, scaleDep, implicit )` Regardless of the choice of the actual Laplacian, if `implicit` is true, you should formulate the previous computations in a matricial form and solve the linear system 'V = V_new - M*L*delta*V_new'. For further reading refer to [this paper](http://w.multires.caltech.edu/pubs/ImplicitFairing.pdf). An implicit solution is completely robust to `delta` sizes, so you typically don't need more than one iteration. Use the `.lup()` method of 'math.js' to decompose the matrix, and reuse the decomposition 3 times, to solve for the `x`, `y` and `z` axes. Note that the decomposition is slow, so you may want to stick to low vertex-count meshes such as `hand-simple`, `teapot` and `cheetah'. Using better optimized packages (or languages) would render this operation immediate.     Sharpen ------------------------------------------------------------------------ `sharpen( mesh, iter, delta )` This operation needs to be applied `iter` number of times, similarly to Uniform Laplacian Smoothing. It is the exact same behavior, only in the opposite direction. Note that this operation is very sesitive to `delta` values.    Curvature ------------------------------------------------------------------------ `curvature( mesh )` Depending on your choice of visualization, your results might vary greatly from this. However for the cheetah, what you should be seeing is high curvature values (bright yellow in our visualization) in places like the claws, nostrils or ears, and low curvature values (blue in our visualization) around the claws. This is due to the fact that Gaussian curvature is defined as product of principal curvatures. Your final colors will vary depending on what method you use to map the curvature to a suitable range for the colors. Notice that for the cube, all the vertices have the same value so they are all mapped to mid gray.    Topology ======================================================================== Truncate ------------------------------------------------------------------------ `truncate( mesh, factor )` Creates an effect where each vertex is "cut off". It is possible to accomplish this using the `splitEdge()` and `splitFace()` functions. Topologically we are only adding vertices, so there is no need to remove any vertices. Think about the necessary topological and geometrical changes.    Extrude ------------------------------------------------------------------------ `extrude( mesh, factor )` The vertices of each face should be duplicated and moved along the normal of the face. The original face should be attached to the duplicated vertices. The set of original vertices and duplicated vertices should be connected together by new faces. This feature requires you to modify the half edge data structure by using the `splitFaceMakeEdge(...)`, `joinEdgeKillVertex( v1, v2, v3 )`, and `splitEdgeMakeVertex( v1, v2, f )` functions. Make sure you familiarize yourself with these functions before starting to code this one!   Split Long Edges ------------------------------------------------------------------------ `splitLong( mesh, factor )` Splits the longest edge in the mesh. Depending on the choice of which vertices you selected to connect to a newly created one, you can obtain different results. Notice that as you go through the iterations one of the newly added edges might be the longest one.    Triangle Topology ------------------------------------------------------------------------ `triSubdiv( mesh, levels )` Splits each face into triangles. This effect is applied `levels` number of times. The mesh should be triangulated before using this function.   Subdivision ======================================================================== Loop Subdivision ------------------------------------------------------------------------ `loop( mesh, levels )` Splits each face into triangles. This effect is applied `levels` number of times. The mesh should be triangulated before using this function. In the example images, we have used Warren weights.         Quad Topology ------------------------------------------------------------------------ `quadSubdiv( mesh, levels )` Splits each face into quads. This effect is applied `levels` number of times.       Catmull-Clark Subdivision ------------------------------------------------------------------------ `catmullClark( mesh, levels )` Splits each face into quads. This effect is applied `levels` number of times. Users update the rules as described in the lecture and precept slides. The order in which you should apply the geometrical changes is: modify the positions of the new edge midpoints, modify the positions of the newly created face centroids, modify the positions of the old vertices. *Tip*: When calculating the locations for the edge midpoints, take the average of the vertices' positions of that edge, and the average of centroids of adjacent faces.            