Skip to content

Commit

Permalink
Adding GfMatrix4f versions of all computations on UsdSkelSkeletonQuer…
Browse files Browse the repository at this point in the history
…y, UsdSkelAnimQuery and UsdSkelSkinningQuery.

Updating UsdSkel's utility methods to work with arbitrary containers as well as both GfMatrix4d and GfMatrix4f types.
Misc code cleanup

(Internal change: 1940812)
(Internal change: 1940994)
(Internal change: 1940995)
  • Loading branch information
sgustafso authored and pixar-oss committed Feb 20, 2019
1 parent 077007c commit e380a5c
Show file tree
Hide file tree
Showing 20 changed files with 1,813 additions and 885 deletions.
18 changes: 15 additions & 3 deletions pxr/usd/lib/usdSkel/animMapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
//
#include "pxr/usd/usdSkel/animMapper.h"

#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/matrix4f.h"
#include "pxr/base/tf/type.h"

#include <algorithm>
Expand Down Expand Up @@ -226,16 +228,26 @@ BOOST_PP_SEQ_FOR_EACH(_UNTYPED_REMAP, ~, SDF_VALUE_TYPES);
}


template <typename Matrix4>
bool
UsdSkelAnimMapper::RemapTransforms(const VtMatrix4dArray& source,
VtMatrix4dArray* target,
UsdSkelAnimMapper::RemapTransforms(const VtArray<Matrix4>& source,
VtArray<Matrix4>* target,
int elementSize) const
{
static const GfMatrix4d identity(1);
static const Matrix4 identity(1);
return Remap(source, target, elementSize, &identity);
}


template USDSKEL_API bool
UsdSkelAnimMapper::RemapTransforms(const VtMatrix4dArray&,
VtMatrix4dArray*, int) const;

template USDSKEL_API bool
UsdSkelAnimMapper::RemapTransforms(const VtMatrix4fArray&,
VtMatrix4fArray*, int) const;


bool
UsdSkelAnimMapper::operator==(const UsdSkelAnimMapper& o) const
{
Expand Down
9 changes: 6 additions & 3 deletions pxr/usd/lib/usdSkel/animMapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"

#include "pxr/base/vt/array.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/matrix4f.h"
#include "pxr/base/tf/span.h"
#include "pxr/base/vt/array.h"
#include "pxr/usd/sdf/types.h"

#include <type_traits>
Expand Down Expand Up @@ -97,9 +99,10 @@ class UsdSkelAnimMapper {
/// Convenience method for the common task of remapping transform arrays.
/// This performs the same operation as Remap(), but sets the matrix
/// identity as the default value.
template <typename Matrix4>
USDSKEL_API
bool RemapTransforms(const VtMatrix4dArray& source,
VtMatrix4dArray* target,
bool RemapTransforms(const VtArray<Matrix4>& source,
VtArray<Matrix4>* target,
int elementSize=1) const;

/// Returns true if this is an identity map.
Expand Down
17 changes: 15 additions & 2 deletions pxr/usd/lib/usdSkel/animQuery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "pxr/usd/usd/attribute.h"

#include "pxr/base/gf/interval.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/matrix4f.h"


PXR_NAMESPACE_OPEN_SCOPE
Expand All @@ -42,8 +44,9 @@ UsdSkelAnimQuery::GetPrim() const
}


template <typename Matrix4>
bool
UsdSkelAnimQuery::ComputeJointLocalTransforms(VtMatrix4dArray* xforms,
UsdSkelAnimQuery::ComputeJointLocalTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time) const
{
if(TF_VERIFY(IsValid(), "invalid anim query.")) {
Expand All @@ -53,6 +56,15 @@ UsdSkelAnimQuery::ComputeJointLocalTransforms(VtMatrix4dArray* xforms,
}


template USDSKEL_API bool
UsdSkelAnimQuery::ComputeJointLocalTransforms(
VtArray<GfMatrix4d>*, UsdTimeCode) const;

template USDSKEL_API bool
UsdSkelAnimQuery::ComputeJointLocalTransforms(
VtArray<GfMatrix4f>*, UsdTimeCode) const;


bool
UsdSkelAnimQuery::ComputeJointLocalTransformComponents(
VtVec3fArray* translations,
Expand Down Expand Up @@ -140,7 +152,8 @@ UsdSkelAnimQuery::GetBlendShapeOrder() const


bool
UsdSkelAnimQuery::GetBlendShapeWeightTimeSamples(std::vector<double>* times) const
UsdSkelAnimQuery::GetBlendShapeWeightTimeSamples(
std::vector<double>* times) const
{
return GetBlendShapeWeightTimeSamplesInInterval(
GfInterval::GetFullInterval(), times);
Expand Down
3 changes: 2 additions & 1 deletion pxr/usd/lib/usdSkel/animQuery.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,10 @@ class UsdSkelAnimQuery
/// Compute joint transforms in joint-local space.
/// Transforms are returned in the order specified by the joint ordering
/// of the animation primitive itself.
template <typename Matrix4>
USDSKEL_API
bool ComputeJointLocalTransforms(
VtMatrix4dArray* xforms,
VtArray<Matrix4>* xforms,
UsdTimeCode time=UsdTimeCode::Default()) const;

/// Compute translation,rotation,scale components of the joint transforms
Expand Down
67 changes: 45 additions & 22 deletions pxr/usd/lib/usdSkel/animQueryImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
//
#include "pxr/usd/usdSkel/animQueryImpl.h"

#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/matrix4f.h"

#include "pxr/usd/usd/attributeQuery.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/attribute.h"
Expand Down Expand Up @@ -52,7 +55,12 @@ class UsdSkel_SkelAnimationQueryImpl : public UsdSkel_AnimQueryImpl
virtual UsdPrim GetPrim() const override { return _anim.GetPrim(); }

bool ComputeJointLocalTransforms(VtMatrix4dArray* xforms,
UsdTimeCode time) const override;
UsdTimeCode time) const override
{ return _ComputeJointLocalTransforms(xforms, time); }

bool ComputeJointLocalTransforms(VtMatrix4fArray* xforms,
UsdTimeCode time) const override
{ return _ComputeJointLocalTransforms(xforms, time); }

bool ComputeJointLocalTransformComponents(
VtVec3fArray* translations,
Expand All @@ -78,6 +86,10 @@ class UsdSkel_SkelAnimationQueryImpl : public UsdSkel_AnimQueryImpl

bool BlendShapeWeightsMightBeTimeVarying() const override;

private:
template <typename Matrix4>
bool _ComputeJointLocalTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time) const;

private:
UsdSkelAnimation _anim;
Expand All @@ -93,43 +105,54 @@ UsdSkel_SkelAnimationQueryImpl::UsdSkel_SkelAnimationQueryImpl(
_scales(anim.GetScalesAttr()),
_blendShapeWeights(anim.GetBlendShapeWeightsAttr())
{
if(TF_VERIFY(anim)) {
if (TF_VERIFY(anim)) {
anim.GetJointsAttr().Get(&_jointOrder);
anim.GetBlendShapesAttr().Get(&_blendShapeOrder);
}
}


template <typename Matrix4>
bool
UsdSkel_SkelAnimationQueryImpl::ComputeJointLocalTransforms(
VtMatrix4dArray* xforms,
UsdSkel_SkelAnimationQueryImpl::_ComputeJointLocalTransforms(
VtArray<Matrix4>* xforms,
UsdTimeCode time) const
{
TRACE_FUNCTION();

if (!xforms) {
TF_CODING_ERROR("'xforms' is null");
return false;
}

VtVec3fArray translations;
VtQuatfArray rotations;
VtVec3hArray scales;

if(ComputeJointLocalTransformComponents(&translations, &rotations,
if (ComputeJointLocalTransformComponents(&translations, &rotations,
&scales, time)) {

if(UsdSkelMakeTransforms(translations, rotations, scales, xforms)) {
if(xforms->size() == _jointOrder.size()) {
xforms->resize(translations.size());
if (UsdSkelMakeTransforms(translations, rotations,
scales, *xforms)) {

if (xforms->size() == _jointOrder.size()) {
return true;
} else {
if(xforms->size() == 0) {
// XXX: If the size of all components was zero, we
// infer that the arrays were *intentionally* authored as
// empty, to nullify the animation. Since this is
// suspected to be intentional, we emit no warning.
return false;
}
TF_WARN("%s -- size of transform component arrays [%zu] "
"!= joint order size [%zu].",
_anim.GetPrim().GetPath().GetText(),
xforms->size(), _jointOrder.size());
} else if (xforms->empty()) {
// If all transform components were empty, that could mean:
// - the attributes were never authored
// - the attributes were blocked
// - the attributes were authored with empty arrays
// (possibly intentionally)

// In many of these cases, we should expect the animation
// to be silently ignored, so throw no warning.
return false;
}
TF_WARN("%s -- size of transform component arrays [%zu] "
"!= joint order size [%zu].",
_anim.GetPrim().GetPath().GetText(),
xforms->size(), _jointOrder.size());
} else {
TF_WARN("%s -- failed composing transforms from components.",
_anim.GetPrim().GetPath().GetText());
Expand Down Expand Up @@ -190,7 +213,7 @@ UsdSkel_SkelAnimationQueryImpl::ComputeBlendShapeWeights(
VtFloatArray* weights,
UsdTimeCode time) const
{
if(TF_VERIFY(_anim, "PackedJointAnimation schema object is invalid.")) {
if (TF_VERIFY(_anim, "PackedJointAnimation schema object is invalid.")) {
return _blendShapeWeights.Get(weights, time);
}
return false;
Expand All @@ -214,14 +237,14 @@ UsdSkel_SkelAnimationQueryImpl::BlendShapeWeightsMightBeTimeVarying() const


// --------------------------------------------------
// UsdSkel_AnimQuery
// UsdSkel_AnimQueryImpl
// --------------------------------------------------


UsdSkel_AnimQueryImplRefPtr
UsdSkel_AnimQueryImpl::New(const UsdPrim& prim)
{
if(prim.IsA<UsdSkelAnimation>()) {
if (prim.IsA<UsdSkelAnimation>()) {
return TfCreateRefPtr(new UsdSkel_SkelAnimationQueryImpl(
UsdSkelAnimation(prim)));
}
Expand Down
3 changes: 3 additions & 0 deletions pxr/usd/lib/usdSkel/animQueryImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class UsdSkel_AnimQueryImpl : public TfRefBase
virtual bool ComputeJointLocalTransforms(VtMatrix4dArray* xforms,
UsdTimeCode time) const = 0;

virtual bool ComputeJointLocalTransforms(VtMatrix4fArray* xforms,
UsdTimeCode time) const = 0;

virtual bool ComputeJointLocalTransformComponents(
VtVec3fArray* translations,
VtQuatfArray* rotations,
Expand Down
Loading

0 comments on commit e380a5c

Please sign in to comment.