Last active
February 18, 2020 16:52
-
-
Save companje/780f0a2a99a983aaa856ef5b63ca67c6 to your computer and use it in GitHub Desktop.
Load Points and Triangles from textfile with Processing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//points = loadPoints("points.txt"); | |
//triangles = loadTriangles("triangles.txt", points); | |
class Triangle { | |
PVector p[] = new PVector[3]; | |
} | |
ArrayList<PVector> loadPoints(String filename) { | |
ArrayList<PVector> points = new ArrayList(); | |
for (String line : loadStrings(filename)) { | |
float f[] = float(split(line, ",")); | |
points.add(new PVector(f[0], f[1], f[2])); | |
} | |
return points; | |
} | |
ArrayList<Triangle> loadTriangles(String filename, ArrayList<PVector> points) { | |
ArrayList<Triangle> triangles = new ArrayList(); | |
for (String line : loadStrings(filename)) { | |
int indices[] = int(split(line, ",")); | |
Triangle t = new Triangle(); | |
for (int i=0; i<3; i++) t.p[i] = points.get(indices[i]); | |
triangles.add(t); | |
} | |
return triangles; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment