How modify a triangolation 3d mesh from beginShape()?

edited January 2015 in Questions about Code

Ciao everyone! I want modify a surface give from a beginShape(TRIANGLES) created from a double cycle for of x,y of points (vertex). I would like to extrude some triangles on z axis, but when i try, it create just a triangle flat on z and it loose the connection surface with near points. I am building the surface like that:

for (int y=0; y < steps; y+=steps;) {

for(int x=0;x < kdw-steps;x+=steps;)
{
  i00 = x + y * maxY;
  i01 = x + y + steps_* maxY;
  i10 = (x + steps) + y * maxY;
  i11 = (x + steps) +y + steps_* maxY;

  p00 = totalPoints[i00];
  p01 = totalPoints[i01];
  p10 = totalPoints[i10];
  p11 = totalPoints[i11];

  beginShape(TRIANGLES);  

  if ((p00.z > 0) && (p01.z > 0) && (p10.z > 0) && // check for non valid values
      (abs(p00.z-p01.z) < max_edge_len) && (abs(p10.z-p01.z) < max_edge_len)) { // check for edge length

        vertex(p00.x,p00.y,p00.z);
        vertex(p01.x,p01.y,p01.z);
        vertex(p10.x,p10.y,p10.z);
      }

  if ((p11.z > 0) && (p01.z > 0) && (p10.z > 0) &&
      (abs(p11.z-p01.z) < 50) && (abs(p10.z-p01.z) < max_edge_len)) {
        vertex(p01.x,p01.y,p01.z);
        vertex(p11.x,p11.y,p11.z);
        vertex(p10.x,p10.y,p10.z);
      }
  endShape(); }}

Any help please?

Comments

  • could you show the entire code pls?

  • edited January 2015

    did you read the tutorial?

    https://www.processing.org/tutorials/pshape/

    very last section

    Manipulating the Vertices of a PShape in Real-Time

    After about five minutes of working with PShape, the question inevitably arises: "What do I do if I want to wiggle all of my vertices?" PShape allows you to dynamically access and alter the vertices through the methods getVertex() and setVertex().

    To iterate over the vertices of a PShape, you can loop from 0 to the total number of vertices (getVertexCount()). Assuming a PShape "s", this would look something like:

    for (int i = 0; i < s.getVertexCount(); i++) {
    }
    

    The vertices can be retrieved as PVector objects with getVertexCount().

    for (int i = 0; i < s.getVertexCount(); i++) {
      PVector v = s.getVertex(i);
    }
    

    You could then move that vertex by manipulating the PVector and setting new values with setVertex().

    for (int i = 0; i < s.getVertexCount(); i++) {
      PVector v = s.getVertex(i);
      v.x += random(-1,1);
      v.y += random(-1,1);
      s.setVertex(i,v.x,v.y);
    }
    

    For an example that wiggles a polygon's vertices using Perlin noise, see "WigglePShape" (under File > Examples > Topics > Create Shapes).

Sign In or Register to comment.