toxiclibs: from mesh to polygon2d

Hi! I have a TriangleMesh and I want to flat it on the x-z axis.

After some toxiclibs example it seems that TriangleMesh.pointTowards is the way to go. But I don't understand who in this sketch I see only one red line while I'm expecting a red quad (in the place of the white quad - that is the x-z translation of the tray quad):

import processing.opengl.*;

import toxi.geom.*;
import toxi.geom.mesh.*;
import toxi.processing.*;

Vec3D BOX_SIZE = new Vec3D(5, 5, 50);
float SCALE=200;

TriangleMesh[] boxes=new TriangleMesh[600];

ToxiclibsSupport gfx;

Polygon2D p ;
TriangleMesh tMesh = new TriangleMesh();
TriangleMesh tMeshOriginal = new TriangleMesh();
void setup() {
  size(600, 600, P3D);
  gfx=new ToxiclibsSupport(this);

  tMeshOriginal.addFace( new Vec3D(0.0, 0.0, 50.0), new Vec3D(50.0, 50.0, 50.0), new Vec3D( -50.0, 50.0, 50.0));
  tMeshOriginal.addFace( new Vec3D(0.0, 0.0, 50.0), new Vec3D(-50.0, 50.0, 50.0), new Vec3D( -50.0, -50.0, 50.0));
  tMeshOriginal.addFace( new Vec3D(0.0, 0.0, 50.0), new Vec3D(-50.0, -50.0, 50.0), new Vec3D( 50.0, -50.0, 50.0));
  tMeshOriginal.addFace( new Vec3D(0.0, 0.0, 50.0), new Vec3D(50.0, -50.0, 50.0), new Vec3D( 50.0, 50.0, 50.0));

  tMesh = tMeshOriginal.copy();

  tMesh.pointTowards(new Vec3D(0, 1, 0));

  p = new Polygon2D();
  for (Vertex v : tMesh.getVertices()) {
    System.out.println(v);
    p.add(new Vec2D(v.x, v.y));
  }
}

void draw() {
  background(51);
  lights();
  translate(width / 2, height / 2);
  rotateX(mouseY * 0.01f);
  rotateY(mouseX * 0.01f);

  fill(255);
  stroke(0);
  gfx.mesh(tMesh);
  fill(100, 100, 100);
  gfx.mesh(tMeshOriginal);
  strokeWeight(2);
  fill(255, 0, 0);
  stroke(255, 0, 0);
  gfx.polygon2D(p);
}
Tagged:

Answers

  • Ok I've done it. Both with toxiclibs and with HE_Mesh2014. It is slightly tricky, done with Quaternion things in toxiclibs and done with triangle and rectangular faces, but not hard to extend into polygonal faces (but toxiclibs only handle triangle faces).

    Ping me if you are interested!

Sign In or Register to comment.