2

I have a list of vertices, of N size, and a weight gradient(which can be any length) defined as:

float[] weight_distribution = { 0f, 1f, 0f };

which says that the first and last vertices will have less weight and the middle vertices will have full. Like a black and white gradient with keys defined like the array.

This is based on the Y-axis for a plane of many segments that is to be weighted for procedural rigging based on the gradient. The list is sorted based on the vertices' Y values, so that the lowest vertices are found at the start of the list and highest last.

I don't know how to calculate the weight for a given vertex with this kind of gradient. Any pointers would be really helpful.

I tried a few different things to find values regarding the current vertex, but I don't know how to extract the weight from the gradient for this position.

This is probably just garbage, but I'll put it here anyway in case it can help.

// find unique Ys
List<float> ys = new List<float>();
for (int i = 0; i < list.Count; i++)  { 
    if (!ys.Contains(list[i].y)) { ys.Add(list[i].y); } 
}
float min = ys[0];
float max = ys[ys.Count - 1];
int levels = (ys.Count - 1);
float levelStep = (gradient.Length * 1f / levels * 1f);
float currentY = ys[0];

// set weights here
for (int i = 0; i < list.Count; i++)
{
     // find current pos/value based on gradient somehow?
     if(list[i].y > currentY ) { currentY = list[i].y; yindex++; }
     float pos = ((yindex * levelStep) / levels * 1f);
     float lerped = Mathf.Lerp(list[i].y, max, pos);

     // ... calculate weight
}
Alx
  • 651
  • 1
  • 9
  • 26
  • It would really help if you provided an example of the kind of output and input you want. Suppose there are 5 vertices: (0,0), (0,2),(0,3) (0,5) and (0,10). and there are 3 weights: (0,1,0.5). What should the weights be for each of those vertices? It seems obvious that the weight for (0,0) is 0, and the weight for (0,10) is 0.5. But what about the other 3? Is 1 the weight of (0,5) because its equidistant from the first and last y components, or is 1 the weight of (0,3) because it's equidistant by position in the sorted list? – Ruzihm Jul 16 '19 at 16:41

0 Answers0