Exploring the Hemesh WB_Render Class
Posted on 2011-08-11 by Jan Vantomme
Tags:
processing, tutorial
Hemesh has changed a lot since the last tutorials I wrote about Creating Shapes, Modifying a Mesh and Subdividing a Mesh. The examples in these articles don't work with the latest version of the libary. In the previous version, you needed to render your mesh to the screen using mesh.drawFaces()
, in the latest version, the new WB_Render class does all the hard work. To use the class, you need to declare a WB_Render object and create it in setup()
. This is the code you need to get started.
WB_Render render;
HE_Mesh mesh;
void setup()
{
size(450, 400);
HEC_Geodesic geo = new HEC_Geodesic(60, 1);
mesh = new HE_Mesh( geo );
render = new WB_Render( this );
}
All the code to render the mesh to the screen goes inside draw()
. This is a list with the descriptions of the most important methods for the WB_Render class. I've used them all to create the image below.
render.drawFaces( mesh )
- Draw the faces of the mesh object. You'll normally use this withfill()
andnoStroke()
.render.drawFacesSmooth( mesh )
- Draw the faces using the vertex normals. This is a great method if you need to render a really smooth organic shape. You'll normally use this withfill()
andnoStroke()
.render.drawFaceNormals( 20, mesh )
- Draw the face normals of the mesh. The first parameter is the length of the normal. You'll normally use this withnoFill()
andstroke()
. This is a useful method for debugging.render.drawEdges( mesh )
- Draw the edges of the mesh. You'll normally use this withnoFill()
andstroke()
.render.drawVertices( 10, mesh )
- Draw the vertices of the mesh, a useful method for debugging if you want to create your own meshes from scratch. The vertices are rendered as cubes, the first parameter sets the size for these cubes. You'll normally use this withnoFill()
andstroke()
.render.drawHalfedges( 10, mesh )
- Draw the halfedges of the mesh, again a useful method for debugging. The vertices are rendered as cubes, the first parameter sets the size for these cubes.
Download
Download the example for rendering with the WB_Render class.