From 49c4204d9704e8cf1df878cd7e212f70bbce0d16 Mon Sep 17 00:00:00 2001 From: Cameron White Date: Mon, 25 Oct 2021 17:34:39 -0400 Subject: [PATCH] Add an optional parameter to specify the tolerance for UsdSkelNormalizeWeights() --- pxr/usd/usdSkel/utils.cpp | 5 +++-- pxr/usd/usdSkel/utils.h | 5 ++++- pxr/usd/usdSkel/wrapUtils.cpp | 5 +++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/pxr/usd/usdSkel/utils.cpp b/pxr/usd/usdSkel/utils.cpp index 652ccab0ba..b861b5d620 100644 --- a/pxr/usd/usdSkel/utils.cpp +++ b/pxr/usd/usdSkel/utils.cpp @@ -920,7 +920,8 @@ _ValidateArrayShape(size_t size, int numInfluencesPerComponent) bool UsdSkelNormalizeWeights(TfSpan weights, - int numInfluencesPerComponent) + int numInfluencesPerComponent, + float eps) { TRACE_FUNCTION(); @@ -943,7 +944,7 @@ UsdSkelNormalizeWeights(TfSpan weights, sum += weightSet[j]; } - if (std::abs(sum) > std::numeric_limits::epsilon()) { + if (std::abs(sum) > eps) { for(int j = 0; j < numInfluencesPerComponent; ++j) { weightSet[j] /= sum; } diff --git a/pxr/usd/usdSkel/utils.h b/pxr/usd/usdSkel/utils.h index 7aa2ebb16d..d70587e0dd 100644 --- a/pxr/usd/usdSkel/utils.h +++ b/pxr/usd/usdSkel/utils.h @@ -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 weights, int numInfluencesPerComponent); +UsdSkelNormalizeWeights(TfSpan weights, int numInfluencesPerComponent, + float eps = std::numeric_limits::epsilon()); /// \overload diff --git a/pxr/usd/usdSkel/wrapUtils.cpp b/pxr/usd/usdSkel/wrapUtils.cpp index 8b3b406ed4..c011d7d753 100644 --- a/pxr/usd/usdSkel/wrapUtils.cpp +++ b/pxr/usd/usdSkel/wrapUtils.cpp @@ -346,9 +346,10 @@ void wrapUsdSkelUtils() (arg("translations"), arg("rotations"), arg("scales"))); def("NormalizeWeights", - static_cast,int)>( + static_cast,int,float)>( &UsdSkelNormalizeWeights), - (arg("weights"), arg("numInfluencesPerComponent"))); + (arg("weights"), arg("numInfluencesPerComponent"), + arg("eps")=std::numeric_limits::epsilon())); def("SortInfluences", static_cast, TfSpan,int)>(