Hemesh : a 3D mesh library for Processing
Coded, recoded, lost, recoded and recoded … hemesh, the half-edge mesh library for Processing has slowly accreted to a state that warrants a release. A release in more than one way. In retrospect, the current functionality looks depressingly small, especially compared to the hundreds of hours that already went into coding it. But like a broke home-owner with a basement and a half-finished first floor, I comfort myself with the thought that at least it holds potential for growth.
What is hemesh?
hemesh is an implementation of a half-edge datastructure for manipulating 3D meshes in Processing. Basically it’s a toolset to extend my Processing sandbox to a proper playground.
Generating and displaying a mesh requires nothing more than a list of vertices and a list of faces connecting them. This hardly requires a special dataset. However, manipulating a mesh in any but a trivial way requires a lot of connectivity information: neighboring vertices, neighboring faces, shared edges,… Keeping track of this in a simple facelist type structure is difficult. Hence the need for a datastructure that incorporates connectivity information in an efficient way: the half-edge mesh.
What can hemesh do?
The library is currently focused on the stuff I coded it for: 3D voronoi and random plane divisions. So with hemesh we can create 3D meshes. Several primitives are built-in, but any kind of 2-manifold mesh can be turned into a half-edge mesh from its vertices and facelist. The weight of the implementation lies in closed meshes but open surfaces are handled as well.
Creating meshes is cool (for a given amount of cool) but destroying them is cooler. Several modifiers are provided, either as part of the basic mesh functionality or as separate modifier classes. Subdividors are a special class of modifier oriented towards subdivisions. (The names might not be original but I guess it’s easier to remember than quaghot and umpsink.)
What hemesh can’t do…
The half-edge datastructure has a few limitations in itself. In practice, each edge in a mesh can be shared by at most two faces. The implementation is strongly face-based, isolated vertices and edges are not supported and will lead to ouchie.
The initial intent of hemesh was to build a system to prototype geometric play. So large-scale systems were never a goal. Several implemented algorithms are O(n²) and use a lot of storage. Connaiseurs and lectors in computational geometry are advised to avoid perusing the code, bleeding eyes often offend. On the positive side, there’s room for improvement…
Getting hemesh
The library is maintained at code.google.com. hemesh is currently at beta version 1.1.0 Download and extract the archive inside the Processing ‘libraries’ folder. The ‘hemesh’ subfolder contains several examples. A Processing version supporting JAVA 1.5 syntax is recommended, Rev 180 or higher. In the coming days, I’ll post some tutorials and spielerei to illustrate further use.
Future
At this time, the library reflects my current interests. If you want it to do something else, have a suggestion or hemesh goes haywire on you, let me know! One major addition is already planned: boolean mesh operations. This is a small step away from completion.
import processing.opengl.*;
import wblut.hemesh.*;
import wblut.geom.*;
HE_Mesh box;
void setup(){
size(600,600,OPENGL);
hint(ENABLE_OPENGL_4X_SMOOTH);
HEC_Box boxCreator=new HEC_Box(this).setWidth(400).setWidthSegments(10)
.setHeight(200).setHeightSegments(4)
.setDepth(200).setDepthSegments(4);
boxCreator.setCenter(100,100,0).setAxis(1,1,1);
box=new HE_Mesh(boxCreator);
HEM_Lattice lattice=new HEM_Lattice().setDepth(10).setWidth(10)
.setFuse(true).setThresholdAngle(HALF_PI);
box.modify(lattice);
}
void draw(){
background(120);
lights();
translate(300,300,0);
rotateY(mouseX*1.0f/width*TWO_PI);
rotateX(mouseY*1.0f/height*TWO_PI);
noStroke();
box.drawFaces();
stroke(0);
box.drawEdges();
}
Trinity
Complexity, evolution, homeostasis … If I had to pick the three things that intrigue me the most, these would be the ones. I’m rather fond of them, and protective. It’s time to rant about misuse, abuse and curious lack-of-use.
Complexity needs no introduction. Any open-minded math or science course finds some room for esthetic and pseudo-philosophical ramblings on the damn thing. I guess it’s safe to say that complexity and its bastard child emergence have, more than any other idea, attracted flies looking for a trendy, post-modern justification of furry thinking. Well, at least former runner-ups quantum physics and chaos theory can get a rest from harassment by quacks and get back to creating interesting t-shirts.
For the record, I don’t believe in emergence in simple systems. Agreed, the unpredictable patterns created by Langton’s Ant are interesting but the only way to explain them is by running through the simple steps of the algorithm. There’s no higher level of explanation, nothing beyond the blind following of the rules, no meta system. I wouldn’t call that emergence. A real-life ant-hill is another bucket of invertebrates, the many complex interactions between the ants result in an entity that can almost be explained as a single organism, mrs. Hill. Even without knowledge of the algorithm, pheromones mostly, we can sensibly predict the behavior of an ant-hill. Getting swarmed and bitten in the unmentionables, now that’s what I call emergence! And the human ant-hill, we’re probably up five meta’s (ask any sociologist to explain the behavior of a mob by electromagnetic interactions). As a plus, swarming and unmentionable biting are far less common…
Nevertheless, complexity in its simplest form, small piecewise algorithms building complex forms, is a valuable paradigm of generative art. There’s something satisfying in creating a set of rules and the beautiful images that sprout from them. The question whether art in generative art refers to the code, or to the results of the code, is a fun one to discuss in mixed company. However further depth cannot be found in fast-and-cheap emergence. As in any art, meaning and significance are to be found in the artist and her intentions. I for one keep to constructs, devoid of meaning. Yep, I’m shallow.
Richard Dawkins refers to Darwin’s idea of evolution as an eye-opener, an idea so profound it changes the way you look at the entire world. I know it did for me. The idea itself is remarkably simple: any replicating system will favor the replicator that euh, replicates the most succesfully. I guess it’s more catchy if it involves a gazillion species of Galapagos finches… It resonates with generative creation, imagery beyond the control of the coder. A system that evolves will suit itself to purpose and circumstance in ways a designer could never imagine. Not only will the system work but it’ll keep working after some parts are removed, at least up to a certain level. It will adapt to changing requirements. If properly cared for, it will wag its posterior appendage and shed fur all over your furniture.
Yet, despite genetic algorithms and their like, human endeavor has only scratched the surface. Not only does evolution shape organisms, it shapes the environment around them. That’s another meta… The closest I’ve seen art approach this level is in interactive installations. These change the behavior of the people around them, at least very locally, and in turn they affect the installation. So, if you’ve ever build one of these, I guess you’re entitled to a bit of smugness. Good for you!
I encountered the concept of homeostasis only late in my academic pursuits. The ability of a living organism to maintain a stable, constant condition was the skeleton onto which my professor physiology built a clear picture of our inner workings (most of them rather yucky). Instead of a random collection of biochemical systems, the body suddenly made sense. The sheer elegance of the various systems that balance each other is an eye-opener of the same magnitude as Darwin’s idea. In fact, one could claim that homeostasis is a direct consequence of evolution, as any organism that can’t maintain its own condition is … doomed. And damnation tends to hamper procreation.
<sidetrack> Why hasn’t anyone written a general audience book on physiology? I mean, cosmology, check, evolution, check, pi, check, our own bodies, not a sausage. Com’on funky scientist/surfer charismatic dudes out there, there’s a goldmine of wonders in there, get writing… (I accept Amazon gift certificates). </sidetrack>
<sidetrack> The university I went to made religion, psychology and philosophy a mandatory part of every curriculum. At this stage I’m wondering if it wouldn’t be a good idea to add some modern biology and physiology. And something arty as well, if you insist. </sidetrack>
I’m not really plugged in into any scene, but so far I haven’t heard of homeostasis as a concept in modern design culture. As a buzzword it definitely has potential. A hint of biomimicry, a hint of complexity, a tad of evolution, touches of dynamism and intelligence. A post-modernist delight. I wish I had an academic career to spend exploring homeostatic structures. Buildings dynamically and intelligently, sorry, redistributing stress after some part fails (i.e. a floor drops out). Heating/cooling systems adapting to supply and demand, not just any plain-old adapting, no, homeostatic adapting! Traffic mimicing blood flow, self-regulating its pressure (and viciously attacking annoyances as-per-spec). Bookshelves changing shape!!! I could even get some eco in there. Now that would be a very lucrative book, the ecohomeostatic design paradigm. Pity, I have no time to write it.
Ooh, ooh, ooh! 3D Voronoi!
I’m sorry, I got a bit excited. But I never thought I’d get this far: actual, geometrically correct 3D Voronoi subdivision. Following my shotgun approach to 3D Voronoi subdivisions in the voronoiBall, it was time to reconsider the problem.
A 3D Voronoi subdivision is not that hard to imagine. Consider 2 lonely points in a box. A good way of dividing the box is splitting it with the bisector plane. This plane is perpendicular to the line connecting the two points and put exactly halfway between them.
There’s no need to limit ourselves to two points. Once we can split by a plane, we can repeat this as often as we like. With three points…
or ten (the madness!)..
Anyway you got the idea. Now, if you cut by more than one plane, you need some way of selecting the proper segments. Otherwise you end up with a mess of planes cutting planes. It’s an interesting mess and I might get back to it one day, but it’s not what we’re looking for today. If done properly you end up with the Voronoi subdivision of the points bounded by the cube. In analogy with my dabblings in 2D Voronoi, I thought this selection was going to be the tough part. Boy, was I wrong…
To be continued. (In the meantime, feel free to explore the code.)
Voronoi showcase
The voronoi fractal sketch has gotten some extra attention lately: 1, 2 and 3. So I got sidetracked from my current project. It’s fun to get some feedback, but it’s also a bit worrying. The code I write was never meant for close scrutiny. It’s shared like pages from a scrapbook lying in a puddle in the street, kind of.
I guess it’s time to document and clean up the code. In the meantime, some sample images from the variations that inevitably show up when rewriting something.
Please enable Javascript and Flash to view this Flash video.


























