How to color triangles in mesh (toxiclibs)

edited November 2014 in Library Questions

Hi, I am trying to color a mesh taken from a Kinect using toxiclibs. I cant find the way for coloring each triangle independently. Using fill before adding each face doesnt work, and i have not fount the way for adding a color to a face.

Here is part of my code:

int[]   depthMap = context.userMap();
  PVector p00;
  PVector p01;
  PVector p10;
  PVector p11;

  mesh = new TriangleMesh();
  for (int i = 0 ; i < wk - stepX  ; i += stepX ) { 
    for (int j = 0 ; j < hk - stepY ; j += stepY ) {

      int index00 = j*wk + i;
      int index01 = j*wk + i + stepX;
      int index10 = (j + stepY)*wk + i;
      int index11 = (j + stepY)*wk + i + stepX;

      if (depthMap[index00] > 0) {
        p00 = context.depthMapRealWorld()[index00];
        p01 = context.depthMapRealWorld()[index01]; 
        p10 = context.depthMapRealWorld()[index10];
        p11 = context.depthMapRealWorld()[index11];

        p00.mult( scaleFactor ); // probably a bad a idea
        p01.mult( scaleFactor );
        p10.mult( scaleFactor );
        p11.mult( scaleFactor );


        if (p00.z > 0 && p01.z > 0 && p10.z > 0 && p11.z > 0) {
          if (abs(p00.z - p01.z) < meshThreshold && abs(p00.z - p10.z) < meshThreshold) {

            fill( 255*noise( noiseScaleX * p00.x));//, noiseScaleY * p00.y ) ); // DOESNT WORK
            //fill(random(255)); // DOESNT WORK EITHER

            mesh.addFace(  toxiVec(p10) , toxiVec(p01), toxiVec(p00) ); 
            mesh.addFace( toxiVec(p11), toxiVec(p10), toxiVec(p01) );
          }
        }
      }
     }
    }
gfx.mesh(mesh);
Tagged:

Answers

  • edited November 2014 Answer ✓

    TriangleMesh does not support colored faces. You have to either extend the class or store this information externally and then draw each face individually with it's connected color.

  • Thanks Amnon! Maybe another library may support it? Perhaps GLGraphics?

  • Hemesh has recently added native color support for meshes.

Sign In or Register to comment.