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); 

A modified cube with HEM_ChamferCorners.

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); 

A modified cube with HEM_ChamferEdges.

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); 

An extruded icosahedron.

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); 

A cube modified with the HEM_Lattice modifier.

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(000202020);
HEM_Slice slice = new HEM_Slice().setPlane(plane);
mesh.modify(slice); 

A geodesic sphere sliced in half with HEM_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[2];
planes[0] = new WB_Plane(000555);
planes[1] = new WB_Plane(000103050);
HEM_MultiSlice ms = new HEM_MultiSlice().setPlanes(planes);
mesh.modify(ms); 

A geodesic sphere sliced with two planes.

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(000502030);
HEM_SliceSurface slice = new HEM_SliceSurface().setPlane(plane);
mesh.modify(slice); 

A cube modified with SliceSurface. No faces are removed.

MultiSliceSurface

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

WB_Plane[] planes = new WB_Plane[2];
planes[0] = new WB_Plane(000502030);
planes[1] = new WB_Plane(0005020, -20);
HEM_MultiSliceSurface ms = new HEM_MultiSliceSurface().setPlanes(planes);
mesh.modify(ms); 

A cube modified with MultiSliceSurface. No faces are removed.

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(0000200);
WB_Point p = new WB_Point(10015030);
HEM_Skew skew = new HEM_Skew().setGroundPlane(plane).setSkewDirection(p).setSkewFactor(0.4);
mesh.modify(skew); 

A box modified with HEM_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); 

A box modified with HEM_Smooth.

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(0000200);
HEM_Stretch stretch = new HEM_Stretch().setGroundPlane(plane).setCompressionFactor(2).setStretchFactor(0.5);
mesh.modify(stretch); 

A box modified with HEM_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, -1000);
WB_Point p2 = new WB_Point(01000);
WB_Line l = new WB_Line(p1p2);
HEM_Twist twist = new HEM_Twist().setTwistAxis(l).setAngleFactor(15);
mesh.modify(twist); 

A box modified with HEM_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); 

A box modified with HEM_VertexExpand.

WireFrame & SmoothInset

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

Downloads

Download all examples from this tutorial on hemesh modifiers.

Tweet this article

Oldskool Comments (1)

Gravatar for Mark Webster

From: Mark Webster
Date: 28.12.2010

Thank you again Jan for this. Hemesh is a great library for creating new and complex 3D forms. Hope the New Year proves to be just as fruitful. regards Mark

Top · Permanent link to this comment