Subdividing a Mesh with Hemesh
Posted on 2011-01-07 by Jan Vantomme
Tags:
processing, tutorial
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 third article, I'm going to take a look at the different ways to subdivide a mesh with Hemesh. The mesh.subdivide()
method takes two parameters. The first one is the kind of subdividor, the second one is the level of subdivision. Be careful when you set the level parameter. Try setting it to 200 if you want to crash Processing.
I've used a cube and rendered it five times so you can see what the subdivision does when you set it to a higher level. Each example shows levels 0 to 4.
CatmullClark
Read about Catmull-Clark subdivision at Wikipedia.
for (int i = 0; i < 5; i++) {
HEC_Cube cube = new HEC_Cube(this).setEdge(100);
mesh[i] = new HE_Mesh(cube);
HES_CatmullClark cc = new HES_CatmullClark();
mesh[i].subdivide( cc, i );
}
DooSabin
Read about Doo-Sabin subdivision at Wikipedia.
for (int i = 0; i < 5; i++) {
HEC_Cube cube = new HEC_Cube(this).setEdge(100);
mesh[i] = new HE_Mesh(cube);
HES_DooSabin ds = new HES_DooSabin().setFactors(0.4, 0.6);
mesh[i].subdivide( ds, i );
}
Planar
for (int i = 0; i < 5; i++) {
HEC_Cube cube = new HEC_Cube(this).setEdge(100);
mesh[i] = new HE_Mesh(cube);
HES_Planar planar = new HES_Planar().setRandom(true) ¬
.setRange(0.6);
mesh[i].subdivide( planar, i );
}
PlanarMidEdge
for (int i = 0; i < 5; i++) {
HEC_Cube cube = new HEC_Cube(this).setEdge(100);
mesh[i] = new HE_Mesh(cube);
HES_PlanarMidEdge planar = new HES_PlanarMidEdge();
mesh[i].subdivide( planar, i );
}
Smooth
for (int i = 0; i < 5; i++) {
HEC_Cube cube = new HEC_Cube(this).setEdge(100);
mesh[i] = new HE_Mesh(cube);
HES_Smooth sm = new HES_Smooth();
mesh[i].subdivide( sm, i );
}
Download
Download all Hemesh subdivision examples used in this article.