Skip to content

Commit

Permalink
Merge pull request PixarAnimationStudios#791 from elrond79/pr/fix_may…
Browse files Browse the repository at this point in the history
…a_skel_import_joint_remapping

[usdSkel] [usdMaya] fix skin import with explicit joint orders

(Internal change: 1950045)
  • Loading branch information
pixar-oss committed Mar 22, 2019
2 parents b90b2d9 + 516e9c1 commit d58dae2
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 10 deletions.
10 changes: 3 additions & 7 deletions pxr/usd/lib/usdSkel/animMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,14 @@ UsdSkelAnimMapper::UsdSkelAnimMapper(const TfToken* sourceOrder,
sourceOrder[0]);
const size_t pos = it - targetOrder;
if((pos + sourceOrderSize) <= targetOrderSize) {
const size_t compareCount =
std::min(sourceOrderSize, targetOrderSize-pos);
if(std::equal(sourceOrder, sourceOrder+compareCount, it)) {
if(std::equal(sourceOrder, sourceOrder+sourceOrderSize, it)) {
_offset = pos;

_flags = _OrderedMap;
_flags = _OrderedMap | _AllSourceValuesMapToTarget;

if(pos == 0 && compareCount == targetOrderSize) {
if(pos == 0 && sourceOrderSize == targetOrderSize) {
_flags |= _SourceOverridesAllTargetValues;
}
_flags |= compareCount == sourceOrderSize ?
_AllSourceValuesMapToTarget : _SomeSourceValuesMapToTarget;
return;
}
}
Expand Down
4 changes: 2 additions & 2 deletions pxr/usd/lib/usdSkel/animMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,11 @@ class UsdSkelAnimMapper {
const TfToken* targetOrder, size_t targetOrderSize);

/// Typed remapping of data in an arbitrary, stl-like container.
/// The \p sourc earray provides a run of \p elementSize for each path in
/// The \p source array provides a run of \p elementSize for each path in
/// the \\em sourceOrder. These elements are remapped and copied over the
/// \p target array.
/// Prior to remapping, the \p target array is resized to the size of the
/// \\ em targetOrdre (as given at mapper construction time) multiplied by
/// \\em targetOrder (as given at mapper construction time) multiplied by
/// the \p elementSize. New element created in the array are initialized
/// to \p defaultValue, if provided.
template <typename Container>
Expand Down
25 changes: 24 additions & 1 deletion third_party/maya/lib/usdMaya/translatorSkel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,27 @@ UsdMayaTranslatorSkel::CreateSkinCluster(
if (!skelQuery.GetJointWorldBindTransforms(&bindXforms)) {
return false;
}
VtMatrix4dArray remappedBindXforms;
const auto& mapper = skinningQuery.GetMapper();
if (mapper && !mapper->IsNull()) {
if (mapper->IsSparse()) {
TF_WARN("Error - not all joints for the skinned object %s could "
"be found in the skeleton %s",
primToSkin.GetPath().GetText(),
skelQuery.GetPrim().GetPath().GetText());
return false;
}
mapper->RemapTransforms(bindXforms, &remappedBindXforms);
}

if (joints.size() > bindXforms.size()) {
TF_WARN("Error - skinned object (%s) had more joints (%lu) "
"than the skeleton (%s) had bind xforms (%lu)",
primToSkin.GetPath().GetText(), joints.size(),
skelQuery.GetPrim().GetPath().GetText(),
bindXforms.size());
return false;
}

MPlug skinClusterMatrix =
skinClusterDep.findPlug(_MayaTokens->matrix, &status);
Expand Down Expand Up @@ -1408,8 +1429,10 @@ UsdMayaTranslatorSkel::CreateSkinCluster(
MPlug bindPreMatrixI =
bindPreMatrix.elementByLogicalIndex(i, &status);
CHECK_MSTATUS_AND_RETURN(status, false);
const auto& bindXform = remappedBindXforms.size() > 0 ?
remappedBindXforms[i] : bindXforms[i];
if (!UsdMayaUtil::setPlugMatrix(
bindXforms[i].GetInverse(), bindPreMatrixI)) {
bindXform.GetInverse(), bindPreMatrixI)) {
return false;
}
}
Expand Down

0 comments on commit d58dae2

Please sign in to comment.