A simple HE_mesh to (toxiclibs) TriangleMesh conversion function

edited June 2014 in Share Your Work

I tried https://github.com/th0ma5w/rosettamesh but it's unfortunately not working from hemesh to toxi (the hemesh packages changed). Since I don't know clojure (yet) and I'm in a hurry, I wrote this. Maybe it's wrong, inefficient, or it's been written already 100 times :)

import java.util.Iterator;
import java.util.List;

import toxi.geom.Vec3D;
import toxi.geom.mesh.TriangleMesh;
import wblut.hemesh.HE_Face;
import wblut.hemesh.HE_Mesh;
import wblut.hemesh.HE_Vertex;

TriangleMesh hemesh2toxi(HE_Mesh m) {
        m.triangulate();

        TriangleMesh tmesh = new TriangleMesh("obj", m.numberOfVertices(),
                m.numberOfFaces());

        Iterator<HE_Face> fItr = m.fItr();
        HE_Face f;
        while (fItr.hasNext()) {
            f = fItr.next();
            List<HE_Vertex> v = f.getFaceVertices();
            tmesh.addFace(
                    new Vec3D(v.get(0).xf(), v.get(0).yf(), v.get(0).zf()),
                    new Vec3D(v.get(1).xf(), v.get(1).yf(), v.get(1).zf()),
                    new Vec3D(v.get(2).xf(), v.get(2).yf(), v.get(2).zf()));
        }
        return tmesh;
}
Sign In or Register to comment.