Toxiclibs + GPU (openGL) processing 3

A function that could be used to convert ToxicLibs meshes to PShape:

PShape toxicToPShapeSmooth(final Mesh3D m) {
    m.computeVertexNormals();
    Collection<Face> triangles = m.getFaces();

    shp = createShape();
    shp.setStroke(false);
    shp.beginShape(PConstants.TRIANGLES);
    shp.textureMode(PConstants.NORMAL);

    for (final Face t : triangles) {
        shp.normal(t.a.normal.x, t.a.normal.y, t.a.normal.z);
        shp.vertex(t.a.x, t.a.y, t.a.z, t.uvA.x, t.uvA.y);

        shp.normal(t.b.normal.x, t.b.normal.y, t.b.normal.z);
        shp.vertex(t.b.x, t.b.y, t.b.z, t.uvB.x, t.uvB.y);

        shp.normal(t.c.normal.x, t.c.normal.y, t.c.normal.z);
        shp.vertex(t.c.x, t.c.y, t.c.z, t.uvC.x, t.uvC.y);
    }
    shp.endShape();
    shp.setSpecular(0xFFFFFFFF);
    shp.setShininess(50);
}
2 Likes