# Some problems Using HE\_Mesh library

**URL:** <https://discourse.processing.org/t/some-problems-using-he-mesh-library/14689>\
**Category:** Libraries\
**Created:** [October 14, 2019, 12:32pm UTC](https://discourse.processing.org/t/some-problems-using-he-mesh-library/14689 "2019-10-14T12:32:21Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jlnsrtr](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jlnsrtr](https://discourse.processing.org/u/jlnsrtr)\
**Post date:** [October 14, 2019, 12:32pm UTC](https://discourse.processing.org/t/some-problems-using-he-mesh-library/14689/1 "2019-10-14T12:32:21Z")

</div>

Hi guys!  
Just started working with Processing for my thesis project, a research on generative and procedural expressions used in graphic design.  
I’m using the CANGenerativeTypography by Anon Owen folder to make some examples of this kind of generative typography to include in my research.  
Only got one problem when I started to mess with the HEMesh library, as it was included in the folder.

I have this code:

import geomerative._; // geomerative library for text manipulation and point extraction  
import wblut.hemesh._; // hemesh library section with main HE\_Mesh class  
import wblut.geom.\*; // hemesh library section with geometry classes

RFont font; // geomerative font used for creating the 3D text  
PShape shapeOriginal; // the PShape to store the original 3D mesh for fast display on the GPU  
PShape shapeDeconstructed; // the PShape to store the deconstructed 3D mesh for fast display on the GPU  
String input = “TYPE”; // the input string that is transformed into a 3D mesh

color[] colors = { #FAFAD2, #EEE8AA, #F0E68C, #DAA520, #FFD700, #FFA500, #FF8C00, #CD853F, #D2691E, #8B4513,#A0522D }; // gold

void setup() {  
// Processing  
size(1280, 720, P3D); // of course we need the 3D renderer  
smooth(16); // nice and smooth! 😉

// Geomerative  
RG.init(this); // initialize the Geomerative library  
RCommand.setSegmentator(RCommand.UNIFORMSTEP); // settings for the generated shape density  
RCommand.setSegmentStep(3); // settings for the generated shape density  
font = new RFont("…/…/Fonts/FreeSans.ttf", 350); // create the font used by Geomerative

// call the methods (see below) that do the actual work in this sketch  
HE\_Mesh mesh = createHemeshFromString(input); // create a 3D mesh from an input string (using Geomerative & Hemesh)  
shapeOriginal = createPShapeFromHemesh(mesh, false); // store the original HE\_Mesh in a PShape for fast display on the GPU  
manipulateMesh(mesh); // apply modifiers to the HE\_Mesh to subdivide and distort it  
shapeDeconstructed = createPShapeFromHemesh(mesh, true); // store the deconstructed HE\_Mesh in a PShape for fast display on the GPU  
println(“Done.”);  
}

void draw() {  
background(0); // clear the background  
perspective(PI/3.0, (float) width/height, 1, 1000000); // wide clipping planes  
directionalLight(255, 255, 255, 1, 1, -1); // custom lights for more contrast  
directionalLight(127, 127, 127, -1, -1, 1); // custom lights for more contrast  
translate(width/2, height/2, map(mouseY, 0, height, 450, -100)); // center the shape on screen, zoom with mouseY  
rotateY(map(mouseX, 0, width, -PI, PI)); // rotate around the Y axis with mouseX  
shape(shapeOriginal); // display the original PShape  
shape(shapeDeconstructed); // display the deconstucted PShape  
}

// Turn a string into a 3D HE\_Mesh  
HE\_Mesh createHemeshFromString(String s) {  
println(“Creating mesh.”);

RMesh rmesh = font.toGroup(s).toMesh(); // create a 2D mesh from a text  
rmesh.translate(-rmesh.getWidth()/2, rmesh.getHeight()/2); // center the mesh

ArrayList \<WB\_Triangle\> triangles = new ArrayList \<WB\_Triangle\> (); // holds the original 2D text mesh  
ArrayList \<WB\_Triangle\> trianglesFlipped = new ArrayList \<WB\_Triangle\> (); // holds the flipped 2D text mesh  
RPoint[] pnts;  
WB\_Triangle t, tFlipped;  
WB\_Point a, b, c;  
// extract the triangles from geomerative’s 2D text mesh, then place them  
// as hemesh’s 3D WB\_Triangle’s in their respective lists (normal & flipped)  
for (int i=0; i\<rmesh.strips.length; i++) {  
pnts = rmesh.strips[i].getPoints();  
for (int j=2; j\<pnts.length; j++) {  
a = new WB\_Point(pnts[j-2].x, pnts[j-2].y, 0);  
b = new WB\_Point(pnts[j-1].x, pnts[j-1].y, 0);  
c = new WB\_Point(pnts[j].x, pnts[j].y, 0);  
if (j % 2 == 0) {  
t = new WB\_Triangle(a, b, c);  
tFlipped = new WB\_Triangle(c, b, a);  
} else {  
t = new WB\_Triangle(c, b, a);  
tFlipped = new WB\_Triangle(a, b, c);  
}  
// add the original and the flipped triangle (to close the 3D shape later on) to their respective lists  
triangles.add(t);  
trianglesFlipped.add(tFlipped);  
}  
}

HE\_Mesh tmesh = new HE\_Mesh(new HEC\_FromTriangles().setTriangles(triangles));  
tmesh.modify(new HEM\_Extrude().setDistance(100));  
tmesh.add(new HE\_Mesh(new HEC\_FromTriangles().setTriangles(trianglesFlipped)));  
tmesh.clean();  
return tmesh;  
}

// only the deconstructed mesh is manipulated  
void manipulateMesh(HE\_Mesh mesh) {  
println(“Modifying mesh.”);

// modify all  
mesh.modify(new HEM\_VertexExpand().setDistance(-1)); // vertex expand all (to prevent z-fighting)  
mesh.subdivide(new HES\_CatmullClark()); // subdivide all

// modify selection  
HE\_Selection selection = getRandomSelection(mesh, 0.09); // get selection  
mesh.modifySelected(new HEM\_Extrude().setDistance(4).setRelative(true).setChamfer(0.2), selection); // extrude selection  
mesh.subdivideSelected(new HES\_CatmullClark(), selection); // subdivide selection  
mesh.modifySelected(new HEM\_VertexExpand().setDistance(6), selection); // vertex expand selection  
mesh.subdivideSelected(new HES\_CatmullClark(), selection); // subdivide selection

// modify random selection  
mesh.modifySelected(new HEM\_Extrude().setDistance(3).setRelative(true).setChamfer(0.35), getRandomSelection(mesh, 0.05)); // extrude random selection  
mesh.modifySelected(new HEM\_VertexExpand().setDistance(5), getRandomSelection(mesh, 0.075)); // vertex expand random selection  
}

// get a random selection of faces from the mesh, given a certain threshold  
HE\_Selection getRandomSelection(HE\_Mesh mesh, float threshold) {  
HE\_Selection selection = new HE\_Selection(mesh);  
for (HE\_Face face : mesh.getFacesAsArray()) {  
if (random(1) \< threshold) selection.add(face);  
}  
return selection;  
}

// store the geometry from a HE\_Mesh in a PShape for quick display on the GPU  
// in this sketch the per-vertex normals option is replaced with some convenience code  
// to change the appearance of the two generated shapes from within this PShape creation method  
PShape createPShapeFromHemesh(HE\_Mesh mesh, boolean deconstructed) {  
println(“Triangulating mesh.”);  
mesh.triangulate(); // ensure it’s triangles only (CPU-intensive, but necessary)

// get all the shape data from the HE\_Mesh  
int[][] facesHemesh = mesh.getFacesAsInt();  
float[][] verticesHemesh = mesh.getVerticesAsFloat();  
HE\_Face[] faceArray = mesh.getFacesAsArray();  
WB\_Coord normal = null;

println(“Storing mesh in PShape.”);  
// create a PShape from the HE\_Mesh shape data  
PShape shape = createShape();  
shape.beginShape(TRIANGLES);  
if (deconstructed) {  
shape.stroke(0, 125);  
shape.strokeWeight(0.5);  
} else {  
shape.noStroke();  
shape.fill(colors[4]);  
}  
for (int i=0; i\<facesHemesh.length; i++) {  
normal = faceArray[i].getFaceNormal();  
if (deconstructed) { shape.fill(colors[int(random(colors.length))]); }  
for (int j = 0; j \< 3; j++) {  
int index = facesHemesh[i][j];  
float[] vertexHemesh = verticesHemesh[index];  
shape.normal(normal.xf(), normal.yf(), normal.zf());  
shape.vertex(vertexHemesh[0], vertexHemesh[1], vertexHemesh[2]);  
}  
}  
shape.endShape();

// return the PShape  
return shape;  
}

When I try to run it I keep getting the same error message "the function modifySelected (HEM\_Extrude , HE\_Selection) does not exist.

I know it may seem as a noob question but I’m really trying to figure out what the problem is and I know I can find help on this forum so thanks a lot in advance!

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [October 14, 2019, 1:50pm UTC](https://discourse.processing.org/t/some-problems-using-he-mesh-library/14689/2 "2019-10-14T13:50:04Z")

</div>

Hi @jlnsrtr,

Hemesh library has recently been updated and rewritten for the occasion. Most of the past example sketches relying on it are now broken. I would suggest to:

- look at the source code and example sketches [here](https://github.com/wblut/HE_Mesh/search?q=modify%28new+HEM_VertexExpand%28%29&unscoped_q=modify%28new+HEM_VertexExpand%28%29) to see how these `modifier` functions have changed
- ask @wblut for his help there if necessary

Here below a revised version of the problematic snippet

```auto
// modify selection
  HE_Selection selection = getRandomSelection(mesh, 0.09); // get selection
  mesh.getSelection("extruded").modify(new HEM_Extrude().setDistance(4).setRelative(true).setChamfer(0.2)); // extrude selection
  mesh.subdivideThreaded(new HES_CatmullClark()); // subdivide selection
  mesh.modify(new HEM_VertexExpand().setDistance(6)); // vertex expand selection
  mesh.subdivideThreaded(new HES_CatmullClark()); // subdivide selection

  // modify random selection
  mesh.getSelection("extruded").modify(new HEM_Extrude().setDistance(3).setRelative(true).setChamfer(0.35)); // extrude random selection
  mesh.modify(new HEM_VertexExpand().setDistance(5)); // vertex expand random selection
}

```

Unfortunately I don’t have the font file needed to run the code so I can’t test it for you. One thing is certain though, you need to figure out how to call the `getRandomSelection()` function from these modifiers.

---

<div class="post-metadata">

**Author:** ![jlnsrtr](https://avatars.discourse-cdn.com/v4/letter/j/91b2a8/32.png) [@jlnsrtr](https://discourse.processing.org/u/jlnsrtr)\
**Post date:** [October 14, 2019, 1:58pm UTC](https://discourse.processing.org/t/some-problems-using-he-mesh-library/14689/3 "2019-10-14T13:58:43Z")

</div>

Thanks a lot, will change that asap with the font loaded and see how it works, i thought that was a compatibility problem as this example is from 2015 or something like that and the library has been updated recently, also being new to processing didnt make things easier for me!  
Thanks a lot!
