public int GetNearestJoint(int a, int b, int c)
{
int i, bestJoint, vertNum, weightVertCount;
float bestWeight;
// duplicated vertices might not have weights
if((a >= 0) && (a < _texCoords.Length))
{
vertNum = a;
}
else if((b >= 0) && (b < _texCoords.Length))
{
vertNum = b;
}
else if((c >= 0) && (c < _texCoords.Length))
{
vertNum = c;
}
else
{
// all vertices are duplicates which shouldn't happen
return 0;
}
// find the first weight for this vertex
weightVertCount = 0;
for(i = 0; weightVertCount < vertNum; i++)
{
weightVertCount += _weightIndex[i * 2 + 1];
}
// get the joint for the largest weight
bestWeight = _scaledWeights[i].W;
bestJoint = _weightIndex[i * 2 + 0];
for(; _weightIndex[i * 2 + 1] == 0; i++)
{
if(_scaledWeights[i].W > bestWeight)
{
bestWeight = _scaledWeights[i].W;
bestJoint = _weightIndex[i * 2 + 0];
}
}
return bestJoint;
}