Skip to content

Instantly share code, notes, and snippets.

@arnaudjuracek
Last active April 26, 2016 18:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arnaudjuracek/8766cde42b0a4e3f7c88fd3dce1e64f3 to your computer and use it in GitHub Desktop.
Save arnaudjuracek/8766cde42b0a4e3f7c88fd3dce1e64f3 to your computer and use it in GitHub Desktop.
Toxiclibs<>HE_mesh : convert TriangleMesh to HE_mesh, and HE_mesh to TriangleMesh
import java.util.Iterator;
import java.util.List;
import wblut.processing.*;
import wblut.core.*;
import wblut.hemesh.*;
import wblut.geom.*;
import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;
TriangleMesh hemeshToToxi(HE_Mesh m){
m.triangulate();
TriangleMesh tmesh = new TriangleMesh();
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;
}
HE_Mesh toxiToHemesh(TriangleMesh m){
String path = "/tmp/processing_toxiToHemesh";
m.saveAsOBJ(path);
return new HE_Mesh(new HEC_FromOBJFile(path));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment