Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an optional parameter to specify the tolerance for UsdSkelNormalizeWeights() #1667

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pxr/usd/usdSkel/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,8 @@ _ValidateArrayShape(size_t size, int numInfluencesPerComponent)

bool
UsdSkelNormalizeWeights(TfSpan<float> weights,
int numInfluencesPerComponent)
int numInfluencesPerComponent,
float eps)
{
TRACE_FUNCTION();

Expand All @@ -943,7 +944,7 @@ UsdSkelNormalizeWeights(TfSpan<float> weights,
sum += weightSet[j];
}

if (std::abs(sum) > std::numeric_limits<float>::epsilon()) {
if (std::abs(sum) > eps) {
for(int j = 0; j < numInfluencesPerComponent; ++j) {
weightSet[j] /= sum;
}
Expand Down
5 changes: 4 additions & 1 deletion pxr/usd/usdSkel/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -388,9 +388,12 @@ UsdSkelMakeTransforms(const GfVec3f* translations,

/// Helper method to normalize weight values across each consecutive run of
/// \p numInfluencesPerComponent elements.
/// If the total weight for a run of elements is smaller than \p eps, the
/// elements' weights are set to zero.
USDSKEL_API
bool
UsdSkelNormalizeWeights(TfSpan<float> weights, int numInfluencesPerComponent);
UsdSkelNormalizeWeights(TfSpan<float> weights, int numInfluencesPerComponent,
float eps = std::numeric_limits<float>::epsilon());


/// \overload
Expand Down
5 changes: 3 additions & 2 deletions pxr/usd/usdSkel/wrapUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,9 +346,10 @@ void wrapUsdSkelUtils()
(arg("translations"), arg("rotations"), arg("scales")));

def("NormalizeWeights",
static_cast<bool (*)(TfSpan<float>,int)>(
static_cast<bool (*)(TfSpan<float>,int,float)>(
&UsdSkelNormalizeWeights),
(arg("weights"), arg("numInfluencesPerComponent")));
(arg("weights"), arg("numInfluencesPerComponent"),
arg("eps")=std::numeric_limits<float>::epsilon()));

def("SortInfluences",
static_cast<bool (*)(TfSpan<int>, TfSpan<float>,int)>(
Expand Down