2

I've built this L-System in Processing using toxiclib and I want to connect each point which is specified to each intersection in the branching of the tree. I've written a separate sketch in which I'm trying to create a triangle mesh by connecting the three closest points, I've been able to connect three points but I want it to be able to go through all the Vertices in an arraylist and then connect three closest points until I have a mesh out of all the vertices in the array. I also need to be able to convert this whole sketch into a function where by I can feed it into my L-System and then it will return the whole system with all the points connected in order to create a mesh. Essentially this is so I can then texture and maybe possibly apply Shaders to it if possible. I think that I might be attempting a harder way of approaching this for I believe toxiclibs or HEMESH libraries could do all of this for me, but I've been unable to figure it out. Any help would be much appreciated.

Here's the code for the sketch I wrote to try and connect all the points into a mesh.

import peasy.*;

float min = 1000;
ArrayList <PVector> loc = new ArrayList <PVector> ();
ArrayList <PVector> locSort = new ArrayList <PVector> ();
float [] minDists;
int  [] minIdxs;

PeasyCam cam;



void setup() {
  size(600, 600, OPENGL);
  cam = new PeasyCam(this, 100);
  for (int i=0; i<50; i++) {
    loc.add(new PVector(random(-50, 50), random(-50, 50), random(-50, 50)));
  }

  minDists = new float[3];
  minIdxs = new int[3];

  for (int i = 0; i < 3; i ++)minDists[i] = 1000;

  for (int i=0; i<loc.size(); i++) {
    for (int j=0; j<loc.size (); j++) {

      PVector vi= loc.get(i);
      // loc.remove(i);
      PVector vj= loc.get(j);
      // loc.remove(j);
      float c = vi.dist(vj);

      for (int k = 0; k < 3; k++) {
        if (c < minDists[k] && c > 0) {

          if (k == 0) {
            minDists[2] = minDists[1];
            minDists[1] = minDists[0];
          } else if (k == 1) {
            minDists[2] = minDists[1];
          }
          println(k, c);
          minDists[k] = c;
          minIdxs[k] = j;
          break;
        }
      }
    }
  }
}

void draw() {
  background(255);


  for (PVector v : loc) {
    pushMatrix();
    translate(v.x, v.y, v.z);
    fill(0);
    noStroke();
    sphere(1);
    popMatrix();
  }

  for (int i = 0; i < 3; i ++) {
    PVector p1 = loc.get(minIdxs[i]);
    PVector p2 = loc.get(minIdxs[(i+1)%3]);
    stroke(255, 0, 0);
    line(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z);
  }
}

Also the L-System was created by following this tutorial: https://www.youtube.com/watch?v=qF8LGLVrwfo

Ceramicwhite
  • 57
  • 1
  • 6

0 Answers0