Creating 3D Shapes with Hemesh
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.
Hemesh is a library for Processing created by Frederik Vanhoutte. In this article I’m going to show you how you can use this library to create complex 3D shapes with only a few lines of code. The libary does the heavy lifting for you. Download hemesh and install it in your Processing libraries folder to get started.
Creators
The HEC_Creator class is the base class for creating a mesh. All 3D shapes in the libary are based on this. I’m going to show you how you can construct most of the shapes in this library. You will usually start with creating a new object and call of the methods needed to setup the shape. The code needs to be called in the setup() function and will look somewhat like this:
HEC_Creator creator = new HEC_Modeltype(this).methodOne(200) ¬
.methodTwo(200);
Box
new HEC_Box(this)Constructor for the box.setWidth()Set the width of the box. (float)setHeight()Set the height of the box. (float)setDepth()Set the depth of the box. . (float)setWidthSegments()Set the number of segments for the width. (integer)setHeightSegments()Set the number of segments for the height. (integer)setDepthSegments()Set the number of segments for the depth. (integer)

The code to recreate this image can be found in the sketch hemesh_box.pde.
Cone
new HEC_Cone(this)Constructor for a cone.setFacets()Set the number of sides for the bottom face. (integer)setRadius()Set the radius of the bottom face. (float)setHeight()Set the height of the cone. (float)setSteps()Set the number of vertical divisions of the cone. (integer)

The code to recreate this image can be found in the sketch hemesh_cone.pde.
Cube
new HEC_Cube(this)Constructor for a cube.setEdge()Set the length of the edge of the cube. (float)setDepthSegments()Set the number of segments for the depth of the cube. (integer)setHeightSegments()Set the number of segments for the height of the cube. (integer)setWidthSegments()Set the number of segments for the width of the cube. (integer)

The code to recreate this image can be found in the sketch hemesh_cube.pde.
Cylinder
new HEC_Cylinder(this)Constructor for a cylinder.setFacets()Set the number of facets for the ground and top plane of the cylinder. (integer)setHeight()Set the height of the cylinder. (float)setRadius()If you use one parameter, it will be used to set the radius of both top and bottom planes, if you use two parameters, the first one will be used for the top plane, the second one for the bottom plane. (float)setSteps()Set the number of vertical divisions for the cylinder. (integer)

The code to recreate this image can be found in the sketch hemesh_cylinder.pde.
Dodecahedron
new HEC_Dodecahedron(this)Constructor for a dodecahedron.setEdge()Set the length of the edge of the dodecahedron. (float)

The code to recreate this image can be found in the sketch hemesh_dodecahedron.pde.
Geodesic
new HEC_Geodesic(this)Constructor for a geodesic sphere.setLevel()Set the level of recursive divisions. Don’t set this too high, try with a number below 10. (integer)setRadius()Set the radius for the geodesic sphere. (float)

The code to recreate this image can be found in the sketch hemesh_geodesic.pde.
Grid
new HEC_Grid(this)Constructor for a grid.setSizeU()Set the width of the plane. (float)setSizeV()Set the height of the plane. (float)setResU()Set the number of divisions for the width. (integer)setResV()Set the number of divisions for the height. (integer)

The code to recreate this image can be found in the sketch hemesh_grid.pde.
Icosahedron
HEC_Icosahedron(this)Constructor for an icosahedron.setEdge()Set the length of the edge for the icosahedron.

The code to recreate this image can be found in the sketch hemesh_icosahedron.pde.
Octahedron
HEC_Octahedron(this)Constructor for an octahedron.setEdge()Set the length of the edge for the octahedron. (float)

The code to recreate this image can be found in the sketch hemesh_octahedron.pde.
Sphere
HEC_Sphere(this)Constructor for a sphere.setRadius()Set the radius of the sphere. (float)setUFacets()Set the number of divisions along the equator of the sphere. (integer)setVFacets()Set the number of divisions along the meridian of the sphere. (integer)

The code to recreate this image can be found in the sketch hemesh_sphere.pde.
Tetrahedron
HEC_Tetrahedron(this)Constructor for an tetrahedron.setEdge()Set the length of the edge for the tetrahedron.

The code to recreate this image can be found in the sketch hemesh_tetrahedron.pde.
Display the Mesh
Initialize a variable before the setup() function.
HE_Mesh mesh;
Us a creator inside the setup and pass it to the new HE_Mesh object.
HEC_Creator creator = new HEC_Box(this);
mesh = new HE_Mesh( creator );
To display the mesh, you’ll need to add this to the draw function:
mesh.drawFaces();
Download
Download all examples from this tutorial on hemesh.
Related Articles
Browse Articles
Comments (8)
From:nikhil
Date:08.08.2011
I have imported hemesh and opengl in processing in the box example but still it can not recognize mesh.drawFaces()
sum1 plz help me out
From:Jan Vantomme
Date:08.08.2011
Nikhil,
Some things have changed in the latest version of the hemesh library. mesh.drawFaces() doesn’t exist anymore. All rendering is now done with the WB_Render class. I’ll post an article on the new way of rendering objects this week.
Jan
From:nikhil
Date:19.08.2011
When i create a mesh, how can i get the following information about any vertex which is a part of my mesh:
- all the vertex names(by default) and faces
- next vertex
- faces connected to vertex
- half edges corresponding the vertex
I am planning to use the above information for a different purpose. Any help in this matter will be appreciated.
From:Jan Vantomme
Date:19.08.2011
If you want to go through the vertices, you can use the vItr() method on your HE_Mesh object. To go through all faces, you can use the fItr() method. If you take a look in the tutorials folder of the library, you’ll find some sketches that use these methods.
- Sketches 006 and 007 will show you how to use the
vItr()method. - In sketch 009 you’ll learn how to access single elements from a mesh.
- Sketch 010 is all about the halfedges.
- Sketches 011, 012 and 013 will show you all methods you can use on faces, edges and vertices.
Hope this will help. I’m planning to write some tutorials on mesh selection. Will publish them online soon.
From:nikhil
Date:26.08.2011
If i load a .obj file into processing using a objloader, how do i declare it as a mesh?
Popular Articles
- Introduction to openFrameworks
- Creating 3D Shapes with Hemesh
- Mirroring Video with openFrameworks
- An Introduction to colorLib
- How to create a FullScreen iPhone Application
Popular Tags
- processing (95)
- software (50)
- art (48)
- web design (40)
- photography (39)
From:Jan Vantomme
Date:14.12.2010
No problem. I’m also writing articles about using subdividors and modifiers. Will publish them soon.
Top · Permanent link to this comment