Texture a cloud of 3D points

I have a cloud of 3D points. It is a 3D surface.
How to texture it ? :-?

Tagged:

Answers

  • Answer ✓

    Use the vertex() with 5 parameters.

  • I will try as soon as possible ;) Thanks.

  • I have some problem to find the values for u and v..... :(

  • Tell us more about the surface and the texture you want to apply.

    A runnable example would be best.

  • edited March 2016
    // cartesian coordinates of points
    float x, y, z;  
    // parameters superformula 1
    float r, r1, r2;
    float m1;
    float n11, n12, n13;
    float a1, b1;
    // parameters superformula 1
    float m2;
    float n21, n22, n23;
    float a2, b2;
    // scale factor
    float factor; 
    // canvas center
    float xc,yc;
    // step angles value (resolution)
    float step;
    
    // 3d movements parameters
    PMatrix3D matrix = new PMatrix3D();
    int tranX, tranY;
    int aa, bb;
    float cc, rotX;
    
    void setup()
    {
      size(800,800,P3D);
      noSmooth();
      background(0);
      init();
    }
    
    void init()
    {
      m1 = 6.0;
      n11 = 1.0;
      n12 = 1.0;
      n13 = 1.0;
      a1 = 1.0;
      b1 = 1.0;
    
      m2 = 3.0;
      n21 = 1.0;
      n22 = 1.0;
      n23 = 1.0;
      a2 = 1.0;
      b2 = 1.0;
    
      factor = 100.0;
      step = 0.1;
      xc = width/2;
      yc = height/2;
      stroke(240);
      fill(240);
    }
    
    void draw()
    {
      background(0);
      lights();
      //global affine transformations
      translate(tranX + xc, tranY + yc);
      rotateX(rotX);
      // scene translation
      if (mousePressed && mouseButton==LEFT) 
      {
        aa = mouseX - pmouseX;
        bb = mouseY - pmouseY;
      }
      tranX += aa;
      tranY += bb;
      // scene rotation
      if (mousePressed && mouseButton==RIGHT) 
      {
        matrix.rotateY(sin(radians((mouseX-pmouseX)/2)));
        cc = sin(radians(-(mouseY-pmouseY)/2));
      }
      rotX +=cc;
      //apply and draw
      applyMatrix(matrix);
      //draw function
      SuperFormula3D();
    }
    
    void mouseWheel(MouseEvent event) 
    {
      float e = event.getCount();
      factor = factor - 5*e;
    }  
    
    void mouseReleased() 
    {
      aa = 0;
      bb = 0;
      cc = 0;
    }
    
    void keyPressed() 
    {
      if (key == '+')  { step = step / 2.0; }
      if (key == '-')  { step = step * 2.0; }
      if (key == 'r')
      {
        matrix = new PMatrix3D();
        tranX = 0;
        tranY = 0;
        rotX = 0;
      }
    }
    
    void SuperFormula3D()
    {
      //beginShape();
      //texture(img);
      for(float theta = -PI; theta < PI; theta += step)
      { 
        for(float phi = -PI/2.0; phi < PI/2.0; phi += step)
        { 
          r1 =  pow( (pow(abs(cos(m1*theta/4.0)/a1), n12) + pow(abs(sin(m1*theta/4)/b1), n13)), -1.0/n11);
          r2 =  pow( (pow(abs(cos(m2*phi/4.0)/a2), n22) + pow(abs(sin(m2*phi/4)/b2), n23)), -1.0/n21);
          x = factor * r1 * cos(theta) * r2 * cos(phi); 
          y = factor * r1 * sin(theta) * r2 * cos(phi);
          z = factor * r2 * sin(phi);
          point(x, y, z);
          //vertex(x, y, z, u, v);
          //println(x,y,z);
        }
      }
      //endShape();
    }
    

    Rotate, translate and zoom with mouse.
    + and - to add more points.

    A uniform texture should be fine to start... :\">

  • Answer ✓

    you have points but for textures you need faces. connect 3 or 4 points as a triangle or a quad.

    generally you'd connect adjacent points on one row of the object with the same points on the next row down. but that doesn't work for all shapes. your double loop looks ok though.

  • Answer ✓

    (btw have you tried PeasyCam? it's good and takes literally 3 lines to give you complete 3d rotation)

  • edited March 2016
    import peasy.*;
    
    PeasyCam cam;
    
    // cartesian coordinates of points
    float x, y, z;  
    // parameters superformula 1
    float r, r1, r2;
    float m1;
    float n11, n12, n13;
    float a1, b1;
    // parameters superformula 1
    float m2;
    float n21, n22, n23;
    float a2, b2;
    // scale factor
    float factor; 
    // canvas center
    float xc, yc;
    // step angles value (resolution)
    float step;
    
    // 3d movements parameters
    PMatrix3D matrix = new PMatrix3D();
    int tranX, tranY;
    int aa, bb;
    float cc, rotX;
    
    void setup()
    {
      size(800, 800, P3D);
      noSmooth();
      background(0);
      init();
      cam = new PeasyCam(this, 300);
    }
    
    void init()
    {
      m1 = 6.0;
      n11 = 1.0;
      n12 = 1.0;
      n13 = 1.0;
      a1 = 1.0;
      b1 = 1.0;
    
      m2 = 3.0;
      n21 = 1.0;
      n22 = 1.0;
      n23 = 1.0;
      a2 = 1.0;
      b2 = 1.0;
    
      factor = 100.0;
      step = PI / 24;
      xc = width/2;
      yc = height/2;
      stroke(240);
      fill(240);
    }
    
    // NB probably some stuff here that we cam delete now that we're using peasycam
    void draw()
    {
      background(0);
      lights();
      //global affine transformations
      //translate(tranX + xc, tranY + yc);
      //rotateX(rotX);
      // scene translation
      if (mousePressed && mouseButton==LEFT) 
      {
        aa = mouseX - pmouseX;
        bb = mouseY - pmouseY;
      }
      tranX += aa;
      tranY += bb;
      // scene rotation
      if (mousePressed && mouseButton==RIGHT) 
      {
        matrix.rotateY(sin(radians((mouseX-pmouseX)/2)));
        cc = sin(radians(-(mouseY-pmouseY)/2));
      }
      rotX +=cc;
      //apply and draw
      applyMatrix(matrix);
      //draw function
      SuperFormula3D();
    }
    
    void mouseReleased() 
    {
      aa = 0;
      bb = 0;
      cc = 0;
    }
    
    void keyPressed() 
    {
      if (key == '+') { 
        step = step / 2.0;
      }
      if (key == '-') { 
        step = step * 2.0;
      }
      if (key == 'r')
      {
        matrix = new PMatrix3D();
        tranX = 0;
        tranY = 0;
        rotX = 0;
      }
    }
    
    void SuperFormula3D()
    {
      beginShape(QUADS);
      for (float theta = -PI; theta < PI; theta += step) { 
        for (float phi = -PI/2.0; phi < PI/2.0 - step; phi += step) {
          // quad
          pVertex(calcPoint(theta, phi));
          pVertex(calcPoint(theta + step, phi));
          pVertex(calcPoint(theta + step, phi + step));
          pVertex(calcPoint(theta, phi + step));
        }
      }
      endShape();
    }
    
    // call vertex with the pvector
    void pVertex(PVector p) {
      vertex(p.x, p.y, p.z);
    }
    
    // calculate the points, return in a pvector
    PVector calcPoint(float theta, float phi) {
      float r1 =  pow( (pow(abs(cos(m1*theta/4.0)/a1), n12) + pow(abs(sin(m1*theta/4)/b1), n13)), -1.0/n11);
      float r2 =  pow( (pow(abs(cos(m2*phi/4.0)/a2), n22) + pow(abs(sin(m2*phi/4)/b2), n23)), -1.0/n21);
      float x = factor * r1 * cos(theta) * r2 * cos(phi); 
      float y = factor * r1 * sin(theta) * r2 * cos(phi);
      float z = factor * r2 * sin(phi);
      return new PVector(x, y, z);
    }
    

    [edit - step fixed, peasycam distance fixed]

  • Thanks. I'll try your suggestions tomorrow.

  • shape is kinda dodgy at the start / end. probably because step isn't quite a factor of PI. try step = PI / 24; (needs to be divisible by 6)

  • @koogs: grazie mille =D>

Sign In or Register to comment.