I'm trying to implement proper texturing of convex polygons. I have a polygon with n triangles, for each triangle i'm calculating barycentric coordinates which are uv of each one but in [0..1] of each triangle, not entire polygon. How to interpolate each uv so it stretches (wraps and not repeats as it is now) entire texture ?
Now it looks like this:
//region.triangulatedVectors = List<Vector2> // triangle points in CCW
//foreach triangle
for (int i = 0;i<region.triangulatedVectors.size();i+=3){
float aX = region.triangulatedVectors.get(i).x;
float aY = region.triangulatedVectors.get(i).y;
float bX = region.triangulatedVectors.get(i+1).x;
float bY = region.triangulatedVectors.get(i+1).y;
float cX = region.triangulatedVectors.get(i+2).x;
float cY = region.triangulatedVectors.get(i+2).y;
Vector2 bary0 = new Vector2();
Vector2 bary1 = new Vector2();
Vector2 bary2 = new Vector2();
Vector2 a = new Vector2(aX, aY);
Vector2 b = new Vector2(bX, bY);
Vector2 c = new Vector2(cX, cY);
GeometryUtils.barycentric(a, a, b, c, bary0);
GeometryUtils.barycentric(b, a, b, c, bary1);
GeometryUtils.barycentric(c, a, b, c, bary2);
//first point
texCoords[k++] = bary0.x;
texCoords[k++] = bary0.y;
texCoords[k++] = bary1.x;
texCoords[k++] = bary1.y;
texCoords[k++] = bary2.x;
texCoords[k++] = bary2.y;
//TODO , interpolate
}
It seems that there are 3 ways of dealing with 2D. Wachspress, Discrete harmonic and Mean value.