如何根据梯度从顶点计算/分配权重

时间:2019-07-16 13:41:06

标签: c# unity3d linear-interpolation

我有一个N个大小的顶点列表,以及一个权重梯度(可以是任意长度),定义为:

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

表示第一个和最后一个顶点的权重较小,而中间的顶点将占满。就像黑白渐变,其键定义为数组一样。

这是基于许多段的平面的Y轴,这些段将根据梯度加权以进行程序装配。 根据顶点的Y值对列表进行排序,以便在列表的开头找到最低的顶点,在顶点的最后找到最高的顶点。

我不知道如何使用这种梯度来计算给定顶点的权重。任何指针都将非常有帮助。

我尝试了一些其他操作来查找有关当前顶点的值,但是我不知道如何从该位置的梯度中提取权重。

这可能只是垃圾,但是无论如何我都会把它放在这里,以防万一。

// 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
}

0 个答案:

没有答案