# Modifying a Mesh with Hemesh

Posted by Jan Vantomme on 28 December 2010.
Tags: , ,

EDIT: Some things have changed in the latest version of Hemesh. These examples don’t work with this version. I wrote an article that explains how to use the new WB_Render class to draw the meshes to the screen. Read it over here.

In this second article about the hemesh library, I’m going to show you how to use some of the modifiers. These modifiers can be used to create more interesting shapes. All examples to recreate the images are available for download at the bottom of the article.

## Modifiers

Start by creating a mesh with any of the creators I’ve shown in the previous article. When you have created a mesh from the creator, you can use any of the modifiers to change the mesh using the `modify()` method.

### ChamferCorners

This modifier adds a 45° chamfer to the corners of the the cube. Using the `setDistance()` method, you can specify the size of the chamfer.

``` HEC_Cube cube = new HEC_Cube(this).setEdge(100);mesh = new HE_Mesh(cube);HEM_ChamferCorners cc = new HEM_ChamferCorners().setDistance(10);mesh.modify(cc);  ``` ### ChamferEdges

This modifier adds a 45° chamfer to the edges of the the cube. Using the `setDistance()` method, you can specify the size of the chamfer.

``` HEM_ChamferEdges ce = new HEM_ChamferEdges().setDistance(10);mesh.modify(ce);  ``` ### Extrude

The HEM_Extrude modifier extrudes all faces of your 3D mesh along their face normal. The `setDistance()` method is used to specify the extrusion distance.

``` HEC_Icosahedron icosahedron = new HEC_Icosahedron(this).setEdge(60);mesh = new HE_Mesh(icosahedron);HEM_Extrude extrude = new HEM_Extrude().setDistance(20);mesh.modify(extrude);  ``` ### Lattice

The lattice modifier cuts holes in each face of the mesh. The `setDepth()` and `setWidth()` methods are used to set the depth and width of the remaining structure.

``` HEC_Cube cube = new HEC_Cube(this).setEdge(100).setWidthSegments(2).setHeightSegments(2).setDepthSegments(2);mesh = new HE_Mesh(cube);HEM_Lattice lattice = new HEM_Lattice().setDepth(10).setWidth(10);mesh.modify(lattice);  ``` ### Slice

The slice modifier can be used to cut your mesh. You need to define a plane first with the `WB_Plane()` constructor.

``` HEC_Geodesic geodesic = new HEC_Geodesic(this).setRadius(80).setLevel(2);mesh = new HE_Mesh(geodesic);WB_Plane plane = new WB_Plane(0, 0, 0, 20, 20, 20);HEM_Slice slice = new HEM_Slice().setPlane(plane);mesh.modify(slice);  ``` ### MultiSlice

MultiSlice does the same thing as slice, but you can use more planes to cut your mesh. You’ll need to create an array of planes.

``` WB_Plane[] planes = new WB_Plane;planes = new WB_Plane(0, 0, 0, 5, 5, 5);planes = new WB_Plane(0, 0, 0, 10, 30, 50);HEM_MultiSlice ms = new HEM_MultiSlice().setPlanes(planes);mesh.modify(ms);  ``` ### SliceSurface

SliseSurface does the same as Slice, but doesn’t remove faces. I’ve used a cube so you would better see that the shape is cut in two pieces.

``` WB_Plane plane = new WB_Plane(0, 0, 0, 50, 20, 30);HEM_SliceSurface slice = new HEM_SliceSurface().setPlane(plane);mesh.modify(slice);  ``` ### MultiSliceSurface

MultiSliceSurface does the same as MultiSlice, but doesn’t remove faces.

``` WB_Plane[] planes = new WB_Plane;planes = new WB_Plane(0, 0, 0, 50, 20, 30);planes = new WB_Plane(0, 0, 0, 50, 20, -20);HEM_MultiSliceSurface ms = new HEM_MultiSliceSurface().setPlanes(planes);mesh.modify(ms);  ``` ### Skew

Skewing a mesh in a certain direction. You’ll need to define a ground plane and a point for the skew direction.

``` HEC_Box b = new HEC_Box(this).setWidth(100).setHeight(200).setDepth(100).setWidthSegments(4).setHeightSegments(8).setDepthSegments(4);mesh = new HE_Mesh(b);WB_Plane plane = new WB_Plane(0, 0, 0, 0, 20, 0);WB_Point p = new WB_Point(100, 150, 30);HEM_Skew skew = new HEM_Skew().setGroundPlane(plane).setSkewDirection(p).setSkewFactor(0.4);mesh.modify(skew);  ``` ### Smooth

The smooth modifier adds a simple Laplacian smoothing to the corners of the mesh.

``` HEC_Box b = new HEC_Box(this).setWidth(100).setHeight(200).setDepth(100).setWidthSegments(8).setHeightSegments(16).setDepthSegments(8);mesh = new HE_Mesh(b);HEM_Smooth sm = new HEM_Smooth();mesh.modify(sm);  ``` ### Stretch

This modifier is used to stretch a mesh. The normal of the ground plane is used as the stretch direction.

``` WB_Plane plane = new WB_Plane(0, 0, 0, 0, 20, 0);HEM_Stretch stretch = new HEM_Stretch().setGroundPlane(plane).setCompressionFactor(2).setStretchFactor(0.5);mesh.modify(stretch);  ``` ### Twist

You’ll need to define line with the `WB_Line()` constructor and set an angle in degrees to twist a mesh.

``` WB_Point p1 = new WB_Point(0, -100, 0);WB_Point p2 = new WB_Point(0, 100, 0);WB_Line l = new WB_Line(p1, p2);HEM_Twist twist = new HEM_Twist().setTwistAxis(l).setAngleFactor(15);mesh.modify(twist);  ``` ### VertexExpand

This modifier expands all vertices in the mesh along their vertex normals. If you want to contract them, you can use a negative number in the `setDistance()` method.

``` HEM_VertexExpand ve = new HEM_VertexExpand().setDistance(50);mesh.modify(ve);  ``` ### WireFrame & SmoothInset

I found these two modifiers in the documentation but they don’t seem work with the current available library. 