Esempio n. 1
0
  /**
   * Aligns and scales a UGeo instance so that the result geometry lies along the vector given by
   * the input vertices. <code>geo</code> is assumed to be facing "forward" along the positive Z
   * axis and will be scaled along that axis to match the length of the input vector, leaving the X
   * and Y dimensions unchanged.
   *
   * @param geo
   * @param v1
   * @param v2
   * @return
   */
  public static UGeo align(UGeo geo, UVertex v1, UVertex v2, float extend) {
    UVertex dir = v2.copy().sub(v1);
    UHeading h = new UHeading(dir);

    //    UMB.log(dir.mag()+" "+geo.dimZ());
    float m = dir.mag();
    if (extend > 0) m += extend * 2;

    geo.center().scale(1, 1, m / geo.dimZ());

    h.align(geo.getV());
    geo.translate(dir.mult(0.5f).add(v1));
    return geo;
  }
Esempio n. 2
0
  void build() {
    filename = "my_tile2.svg";
    shp = RG.loadShape(path + filename);
    shp = RG.centerIn(shp, g, 100);
    UVertexList vl, vl2;
    vl = new UVertexList();
    for (int i = 0; i < 5; i++) vl.add(i, 0);

    vl.close();
    vl.insert(2, vl.get(1));
    println(UMB.str(vl.removeDuplID()));

    println(vl.str());

    // We decided the separation between the polygon points dependent of the mouseX
    float pointSeparation = map(constrain(mouseX, 100, width - 100), 100, width - 100, 4, 20);

    //     We create the polygonized version
    RG.setPolygonizer(RG.UNIFORMLENGTH);
    RG.setPolygonizerLength(pointSeparation);

    polyshp = RG.polygonize(shp);
    poly = polyshp.toPolygon();

    ArrayList<UVertexList> cont = UGeomerative.fromRContour(poly.contours);
    println("contours " + cont.size());

    //    for(UVertexList tmp:cont) {
    //      tmp.removeDupl(true);
    ////      println("isClockwise "+tmp.isClockwise());
    //    }

    //    PGraphicsPDF pdf=(PGraphicsPDF)createGraphics(1000,1000,PDF,path+"test1.pdf");
    //  UMB.setGraphics(pdf);
    //  pdf.beginDraw();
    //  pdf.translate(500,500);
    //  pdf.stroke(0);
    //  geo.draw();
    //  pdf.endDraw();
    //  pdf.flush();
    //  pdf.dispose();

    geo2 = UPoly2Tri.triangulate(cont);

    geo = geo2.copy();
    geo.extrudeSelf(50, true);

    //    geo.removeDuplV().regenerateFaceData();
    geo.writeSTL(path + "test1.stl");
  }
Esempio n. 3
0
  public void draw() {
    background(255);

    translate(width / 2, height / 2);
    nav.doTransforms();

    noFill();
    stroke(0);

    if (mousePressed) {
      int cnt = 0;
      geo2.draw().drawVertexNormals(10);
    } else {
      fill(0, 255, 255);

      geo.draw().drawVertexNormals(10);
    }
    //    RG.shape(polyshp);
  }
  public void draw() {

    p.translate(p.width / 2, p.height / 2);
    p.lights();
    main.nav.doTransforms();

    p.stroke(255);
    //    UMB.ppush().protX(HALF_PI).prect(1000,1000).ppop();
    p.noFill();

    if (f != null) {
      UMB.ppush();
      f.draw().drawNormal(100);
      //      f.pline(f.getV()[0], f.centroid());
      //      f.pline(f.getV()[1], f.centroid());
      //      f.pline(f.getV()[2], f.centroid());
      UMB.ppop();
    }

    if (fv != null) {
      int cnt = 0;
      for (UVertex vv : fv)
        if (vv != null) {
          UMB.pstroke(p.color(255, (cnt++) % 2 * 255, 0));
          UMB.pline(vv, new UVertex());

          UMB.ppush().pstroke(0xffffffff).pfill(0xffff000).pellipse(vv, R, R).ppop();
        }
    }

    plane.draw();
    if (lines != null) drawLines();
    else {

    }
  }
Esempio n. 5
0
 public static UGeo cylVector(UVertex v1, UVertex v2, float thickness, float extend, int steps) {
   return align(UGeo.cyl(thickness, 100, steps).rotX(HALF_PI), v1, v2, extend);
 }
Esempio n. 6
0
 public static UGeo boxVector(UVertex v1, UVertex v2, float thickness, float extend) {
   return align(UGeo.box(thickness), v1, v2, extend);
 }
Esempio n. 7
0
 public UGeo align(UGeo geo) {
   align(geo.getV());
   return geo;
 }