Merge pull request #2706 from fuchuyuan/extrapolateBarycentricWeights

fix visual and sim mesh matching
This commit is contained in:
erwincoumans 2020-04-01 19:16:50 -07:00 committed by GitHub
commit 823d9c64ab
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1589,7 +1589,13 @@ void btSoftBodyHelpers::extrapolateBarycentricWeights(btSoftBody* psb)
{
new_min_bary_weight = btMin(new_min_bary_weight, bary[k]);
}
if (new_min_bary_weight > min_bary_weight)
// p is out of the current best triangle, we found a traingle that's better
bool better_than_closest_outisde = (new_min_bary_weight > min_bary_weight && min_bary_weight<0.);
// p is inside of the current best triangle, we found a triangle that's better
bool better_than_best_inside = (new_min_bary_weight>=0 && min_bary_weight>=0 && btFabs(dist)<btFabs(optimal_dist));
if (better_than_closest_outisde || better_than_best_inside)
{
btAlignedObjectArray<const btSoftBody::Node*> parents;
parents.push_back(f.m_n[0]);
@ -1599,11 +1605,6 @@ void btSoftBodyHelpers::extrapolateBarycentricWeights(btSoftBody* psb)
optimal_bary = bary;
optimal_dist = dist;
min_bary_weight = new_min_bary_weight;
// stop searching if the projected p is inside the triangle at hand
if (bary[0]>=0. && bary[1]>=0. && bary[2]>=0.)
{
break;
}
}
}
psb->m_renderNodesInterpolationWeights[i] = optimal_bary;