3D printable mesh from GPS points
in
Contributed Library Questions
•
7 months ago
So, my project is to take GPS points I've mapped out and turn them into a digital sculpture (either 3D printed or CNC machined, or both). At this point I've cobbled together some code to make a Voronoi mesh based on the GPS points, but I'd like to be able to add the elevation data to make it 3D. I've taken the code from another post here on how to add Terrain values to a mesh, but I'm getting an error that says "the elevation array doesn't match the Terrain". Am I headed down the right road here? I.E. what is the best way to add height/elevation to a mesh (preferably using Toxi as that's what I've slogged through over the last week, though it seems like HE-Mesh would work).
Here is the code so far:
- import processing.dxf.*;
- import toxi.processing.*;
- import toxi.geom.*;
- import toxi.geom.Vec3D;
- import toxi.geom.Vec2D;
- import toxi.geom.mesh.*;
- import toxi.util.*;
- import toxi.util.datatypes.*;
- import toxi.geom.mesh2d.*;
- import processing.pdf.*;
- import processing.dxf.*;
- import processing.opengl.*;
- import tomc.gpx.*;
- // declare a GPX object
- GPX gpx;
- // various recording objects
- boolean record;
- boolean pdfrecord;
- PGraphicsPDF pdf;
- // variables
- float x, y;
- int z;
- int rad;
- // toxi
- Voronoi voronoi;
- ToxiclibsSupport gfx;
- TriangleMesh mesh;
- // optional polygon clipper
- PolygonClipper2D clip;
- float xpos[] = new float[9799];
- float ypos[] = new float[9799];
- float zpos[] = new float[9799];
- void setup(){
- size(700, 600, P3D);
- // smooth();
- //initialise the GPX object
- gpx = new GPX(this);
- // parse test.gpx from the sketch data folder
- gpx.parse("MasterTest02.gpx"); // or a URL
- //pdf Object
- pdf = (PGraphicsPDF) createGraphics((width), (height), PDF, "line.pdf");
- //Toxi
- voronoi = new Voronoi();
- gfx = new ToxiclibsSupport(this);
- clip=new SutherlandHodgemanClipper(new Rect(width, height, width, height));
- mesh=new TriangleMesh();
- }
- void draw(){
- background(255);
- rectMode(CENTER);
- ellipseMode(CENTER);
- for (int i = 0; i < gpx.getTrackCount(); i++) {
- GPXTrack trk = gpx.getTrack(i);
- // do something with trk.name
- for (int j = 0; j < trk.size(); j++) {
- //
- GPXTrackSeg trkseg = trk.getTrackSeg(j);
- for (int k = 0; k < trkseg.size(); k++) {
- GPXPoint pt = trkseg.getPoint(k);
- //println(trkseg.size()+ "," + k);
- rad = ((int)pt.ele/60);
- float wStart = -72.894420;
- float wEnd = -72.930099;
- float hStart = 44.125515;
- float hEnd = 44.148290;
- x = map((float)pt.lon, wStart, wEnd, 0, width);
- y = map((float)pt.lat, hStart, hEnd, 0, height);
- z = (int)pt.ele/15;
- xpos[k] = x;
- ypos[k] = y;
- zpos[k] = z;
- }
- for (Polygon2D poly : voronoi.getRegions()){
- gfx.polygon2D(clip.clipPolygon(poly));
- }
- beginShape(TRIANGLES);
- for (Triangle2D t : voronoi.getTriangles()){
- gfx.triangle(t, false);
- }
- endShape();
- for (int b = 0; b < 1000; b++){
- //noStroke();
- stroke(0, 50);
- voronoi.addPoint(new Vec2D(xpos[b], ypos[b]));
- //println(b);
- }
- //
- // for (Vec2D c : voronoi.getSites()){
- // fill(255, 0, 255);
- // ellipse(c.x, c.y, 1, 1);
- // noFill();
- // }
- Terrain terrain = new Terrain(width, height, zpos.length);
- terrain.setElevation(zpos);
- terrain.toMesh(mesh, 10);
- for (Triangle2D t : voronoi.getTriangles()) {
- mesh.addFace(t.a.to3DXY(), t.b.to3DXY(), t.c.to3DXY());
- }
- }}
- }
1