add usd-21-05-win64_py37

This commit is contained in:
Sébastien Albert committed 2021-12-07 17:16:25 +01:00
1 parent 41d23e71ba
commit 66bc054336
15675 files changed
+3061008

No files matched your search

+263
View File
@@ -0,0 +1,263 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_ANIM_MAPPER_H
#define PXR_USD_USD_SKEL_ANIM_MAPPER_H
/// \file usdSkel/animMapper.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.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>
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
using UsdSkelAnimMapperRefPtr = std::shared_ptr<class UsdSkelAnimMapper>;
/// \class UsdSkelAnimMap
///
/// Helper class for remapping vectorized animation data from
/// one ordering of tokens to another.
class UsdSkelAnimMapper {
public:
/// Construct a null mapper.
USDSKEL_API
UsdSkelAnimMapper();
/// Construct an identity mapper for remapping a range of \p size elems.
/// An identity mapper is used to indicate that no remapping is required.
USDSKEL_API
UsdSkelAnimMapper(size_t size);
/// Construct a mapper for mapping data from \p sourceOrder to
/// \p targetOrder.
USDSKEL_API
UsdSkelAnimMapper(const VtTokenArray& sourceOrder,
const VtTokenArray& targetOrder);
/// Construct a mapper for mapping data from \p sourceOrder to
/// \p targetOrder, each being arrays of size \p sourceOrderSize
/// and \p targetOrderSize, respectively.
USDSKEL_API
UsdSkelAnimMapper(const TfToken* sourceOrder, size_t sourceOrderSize,
const TfToken* targetOrder, size_t targetOrderSize);
/// Typed remapping of data in an arbitrary, stl-like container.
/// 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 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>
bool Remap(const Container& source,
Container* target,
int elementSize=1,
const typename Container::value_type*
defaultValue=nullptr) const;
/// Type-erased remapping of data from \p source into \p target.
/// The \p source array provides a run of \p elementSize elements 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 targetOrder (as given at mapper construction time) multiplied by
/// the \p elementSize. New elements created in the array are initialized
/// to \p defaultValue, if provided.
/// Remapping is supported for registered Sdf array value types only.
USDSKEL_API
bool Remap(const VtValue& source, VtValue* target,
int elementSize=1, const VtValue& defaultValue=VtValue()) const;
/// 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 VtArray<Matrix4>& source,
VtArray<Matrix4>* target,
int elementSize=1) const;
/// Returns true if this is an identity map.
/// The source and target orders of an identity map are identical.
USDSKEL_API
bool IsIdentity() const;
/// Returns true if this is a sparse mapping.
/// A sparse mapping means that not all target values will be overridden
/// by source values, when mapped with Remap().
USDSKEL_API
bool IsSparse() const;
/// Returns true if this is a null mapping.
/// No source elements of a null map are mapped to the target.
USDSKEL_API
bool IsNull() const;
/// Get the size of the output array that this mapper expects to
/// map data into.
USDSKEL_API
size_t size() const { return _targetSize; }
bool operator==(const UsdSkelAnimMapper& o) const;
bool operator!=(const UsdSkelAnimMapper& o) const {
return !(*this == o);
}
private:
template <typename T>
bool _UntypedRemap(const VtValue& source, VtValue* target,
int elementSize, const VtValue& defaultValue) const;
template <typename T>
static void _ResizeContainer(VtArray<T>* array,
size_t size,
const T& defaultValue);
template <typename Container>
static void _ResizeContainer(
Container* container,
size_t size,
const typename Container::value_type& defaultValue,
typename std::enable_if<
!VtIsArray<Container>::value,
Container>::type* = 0)
{ container->resize(size, defaultValue); }
USDSKEL_API
bool _IsOrdered() const;
/// Size of the output map.
size_t _targetSize;
/// For ordered mappings, an offset into the output array at which
/// to map the source data.
size_t _offset;
/// For unordered mappings, an index map, mapping from source
/// indices to target indices.
VtIntArray _indexMap;
int _flags;
};
template <typename T>
void
UsdSkelAnimMapper::_ResizeContainer(VtArray<T>* array, size_t size,
const T& defaultValue)
{
// XXX: VtArray::resize() doesn't take an default value atm.
// We should fix this...
const size_t prevSize = array->size();
array->resize(size);
auto span = TfMakeSpan(*array);
for(size_t i = prevSize; i < size; ++i) {
span[i] = defaultValue;
}
}
template <typename Container>
bool
UsdSkelAnimMapper::Remap(const Container& source,
Container* target,
int elementSize,
const typename Container::value_type* defaultValue) const
{
using _ValueType = typename Container::value_type;
if (!target) {
TF_CODING_ERROR("'target' is null");
return false;
}
if (elementSize <= 0) {
TF_WARN("Invalid elementSize [%d]: "
"size must be greater than zero.", elementSize);
return false;
}
const size_t targetArraySize = _targetSize*elementSize;
if (IsIdentity() && source.size() == targetArraySize) {
// Can make copy of the array.
*target = source;
return true;
}
// Resize the target array to the expected size.
_ResizeContainer(target, targetArraySize,
defaultValue ? *defaultValue : _ValueType());
if (IsNull()) {
return true;
} else if (_IsOrdered()) {
size_t copyCount =
std::min(source.size(), targetArraySize - _offset*elementSize);
std::copy(source.cdata(), source.cdata()+copyCount,
target->data() + _offset*elementSize);
} else {
const _ValueType* sourceData = source.cdata();
_ValueType* targetData = target->data();
size_t copyCount = std::min(source.size()/elementSize,
_indexMap.size());
const int* indexMap = _indexMap.data();
for (size_t i = 0; i < copyCount; ++i) {
int targetIdx = indexMap[i];
if (targetIdx >= 0 &&
static_cast<size_t>(targetIdx) < target->size()) {
TF_DEV_AXIOM(i*elementSize < source.size());
TF_DEV_AXIOM((i+1)*elementSize <= source.size());
TF_DEV_AXIOM(static_cast<size_t>((targetIdx+1)*elementSize)
<= target->size());
std::copy(sourceData + i*elementSize,
sourceData + (i+1)*elementSize,
targetData + targetIdx*elementSize);
}
}
}
return true;
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_ANIM_MAPPER_H
+198
View File
@@ -0,0 +1,198 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_ANIM_QUERY_H
#define PXR_USD_USD_SKEL_ANIM_QUERY_H
/// \file usdSkel/animQuery.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/vt/types.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/timeCode.h"
PXR_NAMESPACE_OPEN_SCOPE
class GfMatrix4d;
class UsdAttribute;
class UsdSkelCache;
TF_DECLARE_REF_PTRS(UsdSkel_AnimQueryImpl);
/// \class UsdSkelAnimQuery
///
/// Class providing efficient queries of primitives that provide skel animation.
class UsdSkelAnimQuery
{
public:
USDSKEL_API
UsdSkelAnimQuery() {}
/// Return true if this query is valid.
bool IsValid() const { return (bool)_impl; }
/// Boolean conversion operator. Equivalent to IsValid().
explicit operator bool() const { return IsValid(); }
/// Equality comparison. Return true if \a lhs and \a rhs represent the
/// same UsdSkelAnimQuery, false otherwise.
friend bool operator==(const UsdSkelAnimQuery& lhs,
const UsdSkelAnimQuery& rhs) {
return lhs.GetPrim() == rhs.GetPrim();
}
/// Inequality comparison. Return false if \a lhs and \a rhs represent the
/// same UsdSkelAnimQuery, true otherwise.
friend bool operator!=(const UsdSkelAnimQuery& lhs,
const UsdSkelAnimQuery& rhs) {
return !(lhs == rhs);
}
// hash_value overload for std/boost hash.
friend size_t hash_value(const UsdSkelAnimQuery& query) {
return hash_value(query.GetPrim());
}
/// Return the primitive this anim query reads from.
USDSKEL_API
UsdPrim GetPrim() const;
/// 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(
VtArray<Matrix4>* xforms,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Compute translation,rotation,scale components of the joint transforms
/// in joint-local space. This is provided to facilitate direct streaming
/// of animation data in a form that can efficiently be processed for
/// animation blending.
USDSKEL_API
bool ComputeJointLocalTransformComponents(
VtVec3fArray* translations,
VtQuatfArray* rotations,
VtVec3hArray* scales,
UsdTimeCode time=UsdTimeCode::Default()) const;
USDSKEL_API
bool ComputeBlendShapeWeights(
VtFloatArray* weights,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Get the time samples at which values contributing to joint transforms
/// are set. This only computes the time samples for sampling transforms in
/// joint-local space, and does not include time samples affecting the
/// root transformation.
///
/// \sa UsdAttribute::GetTimeSamples
USDSKEL_API
bool GetJointTransformTimeSamples(std::vector<double>* times) const;
/// Get the time samples at which values contributing to joint transforms
/// are set, over \p interval. This only computes the time samples for
/// sampling transforms in joint-local space, and does not include time
/// samples affecting the root transformation.
///
/// \sa UsdAttribute::GetTimeSamplesInInterval
USDSKEL_API
bool GetJointTransformTimeSamplesInInterval(const GfInterval& interval,
std::vector<double>* times) const;
/// Get the attributes contributing to JointTransform computations
USDSKEL_API
bool GetJointTransformAttributes(std::vector<UsdAttribute>* attrs) const;
/// Return true if it possible, but not certain, that joint transforms
/// computed through this animation query change over time, false otherwise.
///
/// \sa UsdAttribute::ValueMightBeTimeVayring
USDSKEL_API
bool JointTransformsMightBeTimeVarying() const;
/// Get the time samples at which values contributing to blend shape weights
/// have been set.
///
/// \sa UsdAttribute::GetTimeSamples
USDSKEL_API
bool GetBlendShapeWeightTimeSamples(std::vector<double>* attrs) const;
/// Get the time samples at which values contributing to blend shape weights
/// are set, over \p interval.
///
/// \sa UsdAttribute::GetTimeSamplesInInterval
USDSKEL_API
bool GetBlendShapeWeightTimeSamplesInInterval(const GfInterval& interval,
std::vector<double>* times) const;
/// Get the attributes contributing to blendshape weight computations.
USDSKEL_API
bool GetBlendShapeWeightAttributes(std::vector<UsdAttribute>* attrs) const;
/// Return true if it possible, but not certain, that the blend shape
/// weights computed through this animation query change over time,
/// false otherwise.
///
/// \sa UsdAttribute::ValueMightBeTimeVayring
USDSKEL_API
bool BlendShapeWeightsMightBeTimeVarying() const;
/// Returns an array of tokens describing the ordering of joints in the
/// animation.
///
/// \sa UsdSkelSkeleton::GetJointOrder
USDSKEL_API
VtTokenArray GetJointOrder() const;
/// Returns an array of tokens describing the ordering of blend shape
/// channels in the animation.
USDSKEL_API
VtTokenArray GetBlendShapeOrder() const;
USDSKEL_API
std::string GetDescription() const;
private:
UsdSkelAnimQuery(const UsdSkel_AnimQueryImplRefPtr& impl)
: _impl(impl) {}
UsdSkel_AnimQueryImplRefPtr _impl;
friend class UsdSkel_CacheImpl;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_ANIM_QUERY_H
+343
View File
@@ -0,0 +1,343 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_ANIMATION_H
#define USDSKEL_GENERATED_ANIMATION_H
/// \file usdSkel/animation.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdSkel/tokens.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// SKELANIMATION //
// -------------------------------------------------------------------------- //
/// \class UsdSkelAnimation
///
/// Describes a skel animation, where joint animation is stored in a
/// vectorized form.
///
/// See the extended \ref UsdSkel_SkelAnimation "Skel Animation"
/// documentation for more information.
///
///
class UsdSkelAnimation : public UsdTyped
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdSkelAnimation on UsdPrim \p prim .
/// Equivalent to UsdSkelAnimation::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelAnimation(const UsdPrim& prim=UsdPrim())
: UsdTyped(prim)
{
}
/// Construct a UsdSkelAnimation on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelAnimation(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelAnimation(const UsdSchemaBase& schemaObj)
: UsdTyped(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelAnimation();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelAnimation holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelAnimation(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelAnimation
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSKEL_API
static UsdSkelAnimation
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// JOINTS
// --------------------------------------------------------------------- //
/// Array of tokens identifying which joints this animation's
/// data applies to. The tokens for joints correspond to the tokens of
/// Skeleton primitives. The order of the joints as listed here may
/// vary from the order of joints on the Skeleton itself.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] joints` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetJointsAttr() const;
/// See GetJointsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// TRANSLATIONS
// --------------------------------------------------------------------- //
/// Joint-local translations of all affected joints. Array length
/// should match the size of the *joints* attribute.
///
/// | ||
/// | -- | -- |
/// | Declaration | `float3[] translations` |
/// | C++ Type | VtArray<GfVec3f> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Float3Array |
USDSKEL_API
UsdAttribute GetTranslationsAttr() const;
/// See GetTranslationsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateTranslationsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// ROTATIONS
// --------------------------------------------------------------------- //
/// Joint-local unit quaternion rotations of all affected joints,
/// in 32-bit precision. Array length should match the size of the
/// *joints* attribute.
///
/// | ||
/// | -- | -- |
/// | Declaration | `quatf[] rotations` |
/// | C++ Type | VtArray<GfQuatf> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->QuatfArray |
USDSKEL_API
UsdAttribute GetRotationsAttr() const;
/// See GetRotationsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateRotationsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// SCALES
// --------------------------------------------------------------------- //
/// Joint-local scales of all affected joints, in
/// 16 bit precision. Array length should match the size of the *joints*
/// attribute.
///
/// | ||
/// | -- | -- |
/// | Declaration | `half3[] scales` |
/// | C++ Type | VtArray<GfVec3h> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Half3Array |
USDSKEL_API
UsdAttribute GetScalesAttr() const;
/// See GetScalesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateScalesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// BLENDSHAPES
// --------------------------------------------------------------------- //
/// Array of tokens identifying which blend shapes this
/// animation's data applies to. The tokens for blendShapes correspond to
/// the tokens set in the *skel:blendShapes* binding property of the
/// UsdSkelBindingAPI.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] blendShapes` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetBlendShapesAttr() const;
/// See GetBlendShapesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateBlendShapesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// BLENDSHAPEWEIGHTS
// --------------------------------------------------------------------- //
/// Array of weight values for each blend shape. Each weight value
/// is associated with the corresponding blend shape identified within the
/// *blendShapes* token array, and therefore must have the same length as
/// *blendShapes.
///
/// | ||
/// | -- | -- |
/// | Declaration | `float[] blendShapeWeights` |
/// | C++ Type | VtArray<float> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
USDSKEL_API
UsdAttribute GetBlendShapeWeightsAttr() const;
/// See GetBlendShapeWeightsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateBlendShapeWeightsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Convenience method for querying resolved transforms at \p time.
/// Note that it is more efficient to query transforms through
/// UsdSkelAnimQuery or UsdSkelSkeletonQuery.
USDSKEL_API
bool GetTransforms(VtMatrix4dArray* xforms,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Convenience method for setting an array of transforms.
/// The given transforms must be _orthogonal_.
USDSKEL_API
bool SetTransforms(const VtMatrix4dArray& xforms,
UsdTimeCode time=UsdTimeCode::Default()) const;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+47
View File
@@ -0,0 +1,47 @@
//
// Copyright 2017 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_API_H
#define USDSKEL_API_H
#include "pxr/base/arch/export.h"
#if defined(PXR_STATIC)
# define USDSKEL_API
# define USDSKEL_API_TEMPLATE_CLASS(...)
# define USDSKEL_API_TEMPLATE_STRUCT(...)
# define USDSKEL_LOCAL
#else
# if defined(USDSKEL_EXPORTS)
# define USDSKEL_API ARCH_EXPORT
# define USDSKEL_API_TEMPLATE_CLASS(...) ARCH_EXPORT_TEMPLATE(class, __VA_ARGS__)
# define USDSKEL_API_TEMPLATE_STRUCT(...) ARCH_EXPORT_TEMPLATE(struct, __VA_ARGS__)
# else
# define USDSKEL_API ARCH_IMPORT
# define USDSKEL_API_TEMPLATE_CLASS(...) ARCH_IMPORT_TEMPLATE(class, __VA_ARGS__)
# define USDSKEL_API_TEMPLATE_STRUCT(...) ARCH_IMPORT_TEMPLATE(struct, __VA_ARGS__)
# endif
# define USDSKEL_LOCAL ARCH_HIDDEN
#endif
#endif
+168
View File
@@ -0,0 +1,168 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_BAKE_SKINNING_H
#define PXR_USD_USD_SKEL_BAKE_SKINNING_H
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/gf/interval.h"
#include "pxr/base/vt/array.h"
#include "pxr/base/vt/types.h"
#include "pxr/usd/sdf/layer.h"
#include "pxr/usd/usdSkel/binding.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
class UsdPrimRange;
class UsdSkelCache;
class UsdSkelRoot;
/// Parameters for configuring UsdSkelBakeSkinning.
struct UsdSkelBakeSkinningParms
{
/// Flags for identifying different deformation paths.
enum DeformationFlags {
DeformPointsWithLBS = 1 << 0,
DeformNormalsWithLBS = 1 << 1,
DeformXformWithLBS = 1 << 2,
DeformPointsWithBlendShapes = 1 << 3,
DeformNormalsWithBlendShapes = 1 << 4,
DeformWithLBS = (DeformPointsWithLBS|
DeformNormalsWithLBS|
DeformXformWithLBS),
DeformWithBlendShapes = (DeformPointsWithBlendShapes|
DeformNormalsWithBlendShapes),
DeformAll = DeformWithLBS|DeformWithBlendShapes,
/// Flags indicating which components of skinned prims may be
/// modified, based on the active deformations.
ModifiesPoints = DeformPointsWithLBS|DeformPointsWithBlendShapes,
ModifiesNormals = DeformNormalsWithLBS|DeformNormalsWithBlendShapes,
ModifiesXform = DeformXformWithLBS
};
/// Flags determining which deformation paths are enabled.
int deformationFlags = DeformAll;
/// Determines whether or not layers are saved during skinning.
/// If disabled, all skinning data is kept in-memory, and it is up
/// to the caller to save or export the affected layers.
bool saveLayers = true;
/// Memory limit for pending stage writes, given in bytes.
/// If zero, memory limits are ignored. Otherwise, output stages
/// are flushed each time pending writes exceed this amount.
/// Note that at least one frame of data for *all* skinned prims
/// will be held in memory prior to values being written to disk,
/// regardless of this memory limit.
/// Since flushing pending changes requires layers to be saved,
/// memory limiting is only active when _saveLayers_ is enabled.
size_t memoryLimit = 0;
/// If true, extents of UsdGeomPointBased-derived prims are updated
/// as new skinned values are produced. This is made optional
/// in case an alternate procedure is being used to compute
/// extents elsewhere.
bool updateExtents = true;
/// If true, extents hints of models that already stored
/// an extentsHint are updated to reflect skinning changes.
/// All extent hints are authored to the stage's current edit target.
bool updateExtentHints = true;
/// The set of bindings to bake.
std::vector<UsdSkelBinding> bindings;
/// Data layers being written to.
/// Layer authoring is not thread-safe, but if multiple layers are
/// provided, then each of those layers may be written to on separate
/// threads, improving parallelism of writes.
/// Note that each layer must already be in the layer stack of the stage on
/// which the _bindings_ are defined *before* running baking. This is
/// necessary in order for composition of some properties during the
/// baking process. If this is not done, then extents of some models
/// may be incorrect.
std::vector<SdfLayerHandle> layers;
/// Array providing an index per elem in _bindings_, indicating
/// which layer the skinned result of the binding should be written to.
/// The length of this array must be equal to the length of
/// the _bindings_ array.
VtUIntArray layerIndices;
};
/// Bake the effect of skinning prims directly into points and transforms,
/// over \p interval.
/// This is intended to serve as a complete reference implementation,
/// providing a ground truth for testing and validation purposes.
///
/// Although this process attempts to bake skinning as efficiently as possible,
/// beware that this will undo the IO gains that deferred deformations provide.
/// A USD file, once skinning has been baked, may easily see an increase of 100x
/// in disk usage, if not more. The render-time costs of invoking skinning
/// tend to be low relative to the IO gains, so there is little render-time
/// benefit in baking the result down. Whatever wins are achieved may in fact
/// be undone by the increased IO costs.
/// The intent of the UsdSkel encoding is to defer skinning until as late in
/// the pipeline as possible (I.e., render time), partially for the sake of
/// improving IO in distributed renderings contexts. We encourage users to
/// bring similar deferred-deformation capabalities to their renderer, rather
/// than relying on baking data down.
USDSKEL_API
bool
UsdSkelBakeSkinning(const UsdSkelCache& skelCache,
const UsdSkelBakeSkinningParms& parms,
const GfInterval& interval=GfInterval::GetFullInterval());
/// Overload of UsdSkelBakeSkinning, which bakes the effect of skinning prims
/// directly into points and transforms, for all skels bound beneath \p root,
/// over \p interval.
/// Skinning is baked into the current edit target. The edit target is *not*
/// saved during skinning: the caller should Save() or Export() the result.
USDSKEL_API
bool
UsdSkelBakeSkinning(const UsdSkelRoot& root,
const GfInterval& interval=GfInterval::GetFullInterval());
/// Overload of UsdSkelBakeSkinning, which bakes the effect of skinning prims
/// directly into points and transforms, for all SkelRoot prims in \p range,
/// over \p interval.
/// Skinning is baked into the current edit target. The edit target is *not*
/// saved during skinning: the caller should Save() or Export() the result.
USDSKEL_API
bool
UsdSkelBakeSkinning(const UsdPrimRange& range,
const GfInterval& interval=GfInterval::GetFullInterval());
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_BAKE_SKINNING_H
+68
View File
@@ -0,0 +1,68 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_BINDING_H
#define PXR_USD_USD_SKEL_BINDING_H
/// \file usdSkel/binding.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usdSkel/skeleton.h"
#include "pxr/usd/usdSkel/skinningQuery.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class UsdSkelBinding
///
/// Helper object that describes the binding of a skeleton to a set of
/// skinnable objects. The set of skinnable objects is given as
/// UsdSkelSkinningQuery prims, which can be used both to identify the
/// skinned prim as well compute skinning properties of the prim.
class UsdSkelBinding
{
public:
UsdSkelBinding() {}
UsdSkelBinding(const UsdSkelSkeleton& skel,
const VtArray<UsdSkelSkinningQuery>& skinningQueries)
: _skel(skel), _skinningQueries(skinningQueries) {}
/// Returns the bound skeleton.
const UsdSkelSkeleton& GetSkeleton() const { return _skel; }
/// Returns the set skinning targets.
const VtArray<UsdSkelSkinningQuery>& GetSkinningTargets() const
{ return _skinningQueries; }
private:
UsdSkelSkeleton _skel;
VtArray<UsdSkelSkinningQuery> _skinningQueries;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // USDSKEL_SKINNING_MAP
+443
View File
@@ -0,0 +1,443 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_BINDINGAPI_H
#define USDSKEL_GENERATED_BINDINGAPI_H
/// \file usdSkel/bindingAPI.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/apiSchemaBase.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdSkel/tokens.h"
#include "pxr/base/tf/span.h"
#include "pxr/usd/usdGeom/primvar.h"
#include "pxr/usd/usdSkel/skeleton.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// SKELBINDINGAPI //
// -------------------------------------------------------------------------- //
/// \class UsdSkelBindingAPI
///
/// Provides API for authoring and extracting all the skinning-related
/// data that lives in the "geometry hierarchy" of prims and models that want
/// to be skeletally deformed.
///
/// See the extended \ref UsdSkel_BindingAPI "UsdSkelBindingAPI schema"
/// documentation for more about bindings and how they apply in a scene graph.
///
///
class UsdSkelBindingAPI : public UsdAPISchemaBase
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::SingleApplyAPI;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::SingleApplyAPI;
/// Construct a UsdSkelBindingAPI on UsdPrim \p prim .
/// Equivalent to UsdSkelBindingAPI::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelBindingAPI(const UsdPrim& prim=UsdPrim())
: UsdAPISchemaBase(prim)
{
}
/// Construct a UsdSkelBindingAPI on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelBindingAPI(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelBindingAPI(const UsdSchemaBase& schemaObj)
: UsdAPISchemaBase(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelBindingAPI();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelBindingAPI holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelBindingAPI(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelBindingAPI
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Applies this <b>single-apply</b> API schema to the given \p prim.
/// This information is stored by adding "SkelBindingAPI" to the
/// token-valued, listOp metadata \em apiSchemas on the prim.
///
/// \return A valid UsdSkelBindingAPI object is returned upon success.
/// An invalid (or empty) UsdSkelBindingAPI object is returned upon
/// failure. See \ref UsdPrim::ApplyAPI() for conditions
/// resulting in failure.
///
/// \sa UsdPrim::GetAppliedSchemas()
/// \sa UsdPrim::HasAPI()
/// \sa UsdPrim::ApplyAPI()
/// \sa UsdPrim::RemoveAPI()
///
USDSKEL_API
static UsdSkelBindingAPI
Apply(const UsdPrim &prim);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// GEOMBINDTRANSFORM
// --------------------------------------------------------------------- //
/// Encodes the bind-time world space transforms of the prim.
/// If the transform is identical for a group of gprims that share a common
/// ancestor, the transform may be authored on the ancestor, to "inherit"
/// down to all the leaf gprims. If this transform is unset, an identity
/// transform is used instead.
///
/// | ||
/// | -- | -- |
/// | Declaration | `matrix4d primvars:skel:geomBindTransform` |
/// | C++ Type | GfMatrix4d |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Matrix4d |
USDSKEL_API
UsdAttribute GetGeomBindTransformAttr() const;
/// See GetGeomBindTransformAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateGeomBindTransformAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// JOINTS
// --------------------------------------------------------------------- //
/// An (optional) array of tokens defining the list of
/// joints to which jointIndices apply. If not defined, jointIndices applies
/// to the ordered list of joints defined in the bound Skeleton's *joints*
/// attribute. If undefined on a primitive, the primitive inherits the
/// value of the nearest ancestor prim, if any.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] skel:joints` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetJointsAttr() const;
/// See GetJointsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// JOINTINDICES
// --------------------------------------------------------------------- //
/// Indices into the *joints* attribute of the closest
/// (in namespace) bound Skeleton that affect each point of a PointBased
/// gprim. The primvar can have either *constant* or *vertex* interpolation.
/// This primvar's *elementSize* will determine how many joint influences
/// apply to each point. Indices must point be valid. Null influences should
/// be defined by setting values in jointWeights to zero.
/// See UsdGeomPrimvar for more information on interpolation and
/// elementSize.
///
/// | ||
/// | -- | -- |
/// | Declaration | `int[] primvars:skel:jointIndices` |
/// | C++ Type | VtArray<int> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->IntArray |
USDSKEL_API
UsdAttribute GetJointIndicesAttr() const;
/// See GetJointIndicesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointIndicesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// JOINTWEIGHTS
// --------------------------------------------------------------------- //
/// Weights for the joints that affect each point of a PointBased
/// gprim. The primvar can have either *constant* or *vertex* interpolation.
/// This primvar's *elementSize* will determine how many joints influences
/// apply to each point. The length, interpolation, and elementSize of
/// *jointWeights* must match that of *jointIndices*. See UsdGeomPrimvar
/// for more information on interpolation and elementSize.
///
/// | ||
/// | -- | -- |
/// | Declaration | `float[] primvars:skel:jointWeights` |
/// | C++ Type | VtArray<float> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->FloatArray |
USDSKEL_API
UsdAttribute GetJointWeightsAttr() const;
/// See GetJointWeightsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointWeightsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// BLENDSHAPES
// --------------------------------------------------------------------- //
/// An array of tokens defining the order onto which blend shape
/// weights from an animation source map onto the *skel:blendShapeTargets*
/// rel of a binding site. If authored, the number of elements must be equal
/// to the number of targets in the _blendShapeTargets_ rel. This property
/// is not inherited hierarchically, and is expected to be authored directly
/// on the skinnable primitive to which the blend shapes apply.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] skel:blendShapes` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetBlendShapesAttr() const;
/// See GetBlendShapesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateBlendShapesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// ANIMATIONSOURCE
// --------------------------------------------------------------------- //
/// Animation source to be bound to Skeleton primitives at or
/// beneath the location at which this property is defined.
///
///
USDSKEL_API
UsdRelationship GetAnimationSourceRel() const;
/// See GetAnimationSourceRel(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
USDSKEL_API
UsdRelationship CreateAnimationSourceRel() const;
public:
// --------------------------------------------------------------------- //
// SKELETON
// --------------------------------------------------------------------- //
/// Skeleton to be bound to this prim and its descendents that
/// possess a mapping and weighting to the joints of the identified
/// Skeleton.
///
USDSKEL_API
UsdRelationship GetSkeletonRel() const;
/// See GetSkeletonRel(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
USDSKEL_API
UsdRelationship CreateSkeletonRel() const;
public:
// --------------------------------------------------------------------- //
// BLENDSHAPETARGETS
// --------------------------------------------------------------------- //
/// Ordered list of all target blend shapes. This property is not
/// inherited hierarchically, and is expected to be authored directly on
/// the skinnable primitive to which the the blend shapes apply.
///
USDSKEL_API
UsdRelationship GetBlendShapeTargetsRel() const;
/// See GetBlendShapeTargetsRel(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create
USDSKEL_API
UsdRelationship CreateBlendShapeTargetsRel() const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Convenience function to get the jointIndices attribute as a primvar.
///
/// \sa GetJointIndicesAttr, GetInheritedJointWeightsPrimvar
USDSKEL_API
UsdGeomPrimvar GetJointIndicesPrimvar() const;
/// Convenience function to create the jointIndices primvar, optionally
/// specifying elementSize.
/// If \p constant is true, the resulting primvar is configured
/// with 'constant' interpolation, and describes a rigid deformation.
/// Otherwise, the primvar is configured with 'vertex' interpolation,
/// and describes joint influences that vary per point.
///
/// \sa CreateJointIndicesAttr(), GetJointIndicesPrimvar()
USDSKEL_API
UsdGeomPrimvar CreateJointIndicesPrimvar(bool constant,
int elementSize=-1) const;
/// Convenience function to get the jointWeights attribute as a primvar.
///
/// \sa GetJointWeightsAttr, GetInheritedJointWeightsPrimvar
USDSKEL_API
UsdGeomPrimvar GetJointWeightsPrimvar() const;
/// Convenience function to create the jointWeights primvar, optionally
/// specifying elementSize.
/// If \p constant is true, the resulting primvar is configured
/// with 'constant' interpolation, and describes a rigid deformation.
/// Otherwise, the primvar is configured with 'vertex' interpolation,
/// and describes joint influences that vary per point.
///
/// \sa CreateJointWeightsAttr(), GetJointWeightsPrimvar()
USDSKEL_API
UsdGeomPrimvar CreateJointWeightsPrimvar(bool constant,
int elementSize=-1) const;
/// Convenience method for defining joints influences that
/// make a primitive rigidly deformed by a single joint.
USDSKEL_API
bool SetRigidJointInfluence(int jointIndex, float weight=1) const;
/// Convenience method to query the Skeleton bound on this prim.
/// Returns true if a Skeleton binding is defined, and sets \p skel to
/// the target skel. The resulting Skeleton may still be invalid,
/// if the Skeleton has been explicitly *unbound*.
///
/// This does not resolved inherited skeleton bindings.
USDSKEL_API
bool GetSkeleton(UsdSkelSkeleton* skel) const;
/// Convenience method to query the animation source bound on this prim.
/// Returns true if an animation source binding is defined, and sets
/// \p prim to the target prim. The resulting primitive may still be
/// invalid, if the prim has been explicitly *unbound*.
///
/// This does not resolved inherited animation source bindings.
USDSKEL_API
bool GetAnimationSource(UsdPrim* prim) const;
/// Returns the skeleton bound at this prim, or one of its ancestors.
USDSKEL_API
UsdSkelSkeleton GetInheritedSkeleton() const;
/// Returns the animation source bound at this prim, or one of
/// its ancestors.
USDSKEL_API
UsdPrim GetInheritedAnimationSource() const;
/// Validate an array of joint indices.
/// This ensures that all indices are the in the range [0, numJoints).
/// Returns true if the indices are valid, or false otherwise.
/// If invalid and \p reason is non-null, an error message describing
/// the first validation error will be set.
USDSKEL_API
static bool ValidateJointIndices(TfSpan<const int> indices,
size_t numJoints,
std::string* reason=nullptr);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+320
View File
@@ -0,0 +1,320 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_BLENDSHAPE_H
#define USDSKEL_GENERATED_BLENDSHAPE_H
/// \file usdSkel/blendShape.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/typed.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdSkel/tokens.h"
#include "pxr/base/tf/span.h"
#include "pxr/usd/usdSkel/inbetweenShape.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// BLENDSHAPE //
// -------------------------------------------------------------------------- //
/// \class UsdSkelBlendShape
///
/// Describes a target blend shape, possibly containing inbetween
/// shapes.
///
/// See the extended \ref UsdSkel_BlendShape "Blend Shape Schema
/// documentation for information.
///
///
class UsdSkelBlendShape : public UsdTyped
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdSkelBlendShape on UsdPrim \p prim .
/// Equivalent to UsdSkelBlendShape::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelBlendShape(const UsdPrim& prim=UsdPrim())
: UsdTyped(prim)
{
}
/// Construct a UsdSkelBlendShape on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelBlendShape(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelBlendShape(const UsdSchemaBase& schemaObj)
: UsdTyped(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelBlendShape();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelBlendShape holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelBlendShape(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelBlendShape
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSKEL_API
static UsdSkelBlendShape
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// OFFSETS
// --------------------------------------------------------------------- //
/// **Required property**. Position offsets which, when added to the
/// base pose, provides the target shape.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform vector3f[] offsets` |
/// | C++ Type | VtArray<GfVec3f> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetOffsetsAttr() const;
/// See GetOffsetsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateOffsetsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// NORMALOFFSETS
// --------------------------------------------------------------------- //
/// **Required property**. Normal offsets which, when added to the
/// base pose, provides the normals of the target shape.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform vector3f[] normalOffsets` |
/// | C++ Type | VtArray<GfVec3f> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Vector3fArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetNormalOffsetsAttr() const;
/// See GetNormalOffsetsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateNormalOffsetsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// POINTINDICES
// --------------------------------------------------------------------- //
/// **Optional property**. Indices into the original mesh that
/// correspond to the values in *offsets* and of any inbetween shapes. If
/// authored, the number of elements must be equal to the number of elements
/// in the *offsets* array.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform int[] pointIndices` |
/// | C++ Type | VtArray<int> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->IntArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetPointIndicesAttr() const;
/// See GetPointIndicesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreatePointIndicesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Author scene description to create an attribute on this prim that
/// will be recognized as an Inbetween (i.e. will present as a valid
/// UsdSkelInbetweenShape).
///
/// The name of the created attribute or may or may not be the specified
/// \p attrName, due to the possible need to apply property namespacing.
/// Creation may fail and return an invalid Inbetwen if \p attrName
/// contains a reserved keyword.
///
/// \return an invalid UsdSkelInbetweenShape if we failed to create a valid
/// attribute, a valid UsdSkelInbetweenShape otherwise. It is not an error
/// to create over an existing, compatible attribute.
///
/// \sa UsdSkelInbetweenShape::IsInbetween()
USDSKEL_API
UsdSkelInbetweenShape CreateInbetween(const TfToken& name) const;
/// Return the Inbetween corresponding to the attribute named \p name,
/// which will be valid if an Inbetween attribute definition already exists.
///
/// Name lookup will account for Inbetween namespacing, which means that
/// this method will succeed in some cases where
/// `UsdSkelInbetweenShape(prim->GetAttribute(name))` will not, unless
/// \p name has the proper namespace prefix.
///
/// \sa HasInbetween()
USDSKEL_API
UsdSkelInbetweenShape GetInbetween(const TfToken& name) const;
/// Return true if there is a defined Inbetween named \p name on this prim.
///
/// Name lookup will account for Inbetween namespacing.
///
/// \sa GetInbetween()
USDSKEL_API
bool HasInbetween(const TfToken& name) const;
/// Return valid UsdSkelInbetweenShape objects for all defined Inbetweens on
/// this prim.
USDSKEL_API
std::vector<UsdSkelInbetweenShape> GetInbetweens() const;
/// Like GetInbetweens(), but exclude inbetwens that have no authored scene
//// description.
USDSKEL_API
std::vector<UsdSkelInbetweenShape> GetAuthoredInbetweens() const;
/// Validates a set of point indices for a given point count.
/// This ensures that all point indices are in the range [0, numPoints).
/// Returns true if the indices are valid, or false otherwise.
/// If invalid and \p reason is non-null, an error message describing
/// the first validation error will be set.
USDSKEL_API
static bool ValidatePointIndices(TfSpan<const int> indices,
size_t numPoints,
std::string* reason=nullptr);
private:
std::vector<UsdSkelInbetweenShape>
_MakeInbetweens(const std::vector<UsdProperty>& props) const;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+225
View File
@@ -0,0 +1,225 @@
//
// Copyright 2019 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
#define PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
/// \file usdSkel/blendShapeQuery.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usdSkel/blendShape.h"
#include "pxr/usd/usdSkel/inbetweenShape.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/tf/span.h"
#include "pxr/base/vt/array.h"
PXR_NAMESPACE_OPEN_SCOPE
class UsdSkelBindingAPI;
/// \class UsdSkelBlendShapeQuery
///
/// Helper class used to resolve blend shape weights, including
/// inbetweens.
class UsdSkelBlendShapeQuery
{
public:
UsdSkelBlendShapeQuery() = default;
USDSKEL_API UsdSkelBlendShapeQuery(const UsdSkelBindingAPI& binding);
/// Return true if this query is valid.
bool IsValid() const { return bool(_prim); }
/// Boolean conversion operator. Equivalent to IsValid().
explicit operator bool() const { return IsValid(); }
/// Returns the prim the blend shapes apply to.
const UsdPrim& GetPrim() const { return _prim; }
/// Returns the blend shape corresponding to \p blendShapeIndex.
USDSKEL_API UsdSkelBlendShape GetBlendShape(size_t blendShapeIndex) const;
/// Returns the inbetween shape corresponding to sub-shape \p i, if any.
USDSKEL_API UsdSkelInbetweenShape GetInbetween(size_t subShapeIndex) const;
/// Returns the blend shape index corresponding to the \p i'th sub-shape.
USDSKEL_API size_t GetBlendShapeIndex(size_t subShapeIndex) const;
size_t GetNumBlendShapes() const { return _blendShapes.size(); }
size_t GetNumSubShapes() const { return _subShapes.size(); }
/// Compute an array holding the point indices of all shapes.
/// This is indexed by the _blendShapeIndices_ returned by
/// ComputeSubShapes().
/// Since the _pointIndices_ property of blend shapes is optional,
/// some of the arrays may be empty.
USDSKEL_API std::vector<VtIntArray>
ComputeBlendShapePointIndices() const;
/// Compute an array holding the point offsets of all sub-shapes.
/// This includes offsets of both primary shapes -- those stored directly
/// on a BlendShape primitive -- as well as those of inbetween shapes.
/// This is indexed by the _subShapeIndices_ returned by
/// ComputeSubShapeWeights().
USDSKEL_API std::vector<VtVec3fArray>
ComputeSubShapePointOffsets() const;
/// Compute an array holding the normal offsets of all sub-shapes.
/// This includes offsets of both primary shapes -- those stored directly
/// on a BlendShape primitive -- as well as those of inbetween shapes.
/// This is indexed by the _subShapeIndices_ returned by
/// ComputeSubShapeWeights().
/// Normal offsets are optional. An empty array is stored for shapes that
/// do not specify normal offsets.
USDSKEL_API std::vector<VtVec3fArray>
ComputeSubShapeNormalOffsets() const;
/// Compute the resolved weights for all sub-shapes bound to this prim.
/// The \p weights values are initial weight values, ordered according
/// to the _skel:blendShapeTargets_ relationship of the prim this query
/// is associated with. If there are any inbetween shapes, a new set
/// of weights is computed, providing weighting of the relevant inbetweens.
///
/// All computed arrays shared the same size. Elements of the same index
/// identify which sub-shape of which blend shape a given weight value
/// is mapped to.
USDSKEL_API bool
ComputeSubShapeWeights(const TfSpan<const float>& weights,
VtFloatArray* subShapeWeights,
VtUIntArray* blendShapeIndices,
VtUIntArray* subShapeIndices) const;
/// Compute a flattened array of weights for all sub-shapes.
USDSKEL_API bool
ComputeFlattenedSubShapeWeights(const TfSpan<const float>& weights,
VtFloatArray* subShapeWeights) const;
/// Deform \p points using the resolved sub-shapes given by
/// \p subShapeWeights, \p blendShapeIndices and \p subShapeIndices.
/// The \p blendShapePointIndices and \p blendShapePointOffsets
/// arrays both provide the pre-computed point offsets and indices
/// of each sub-shape, as computed by ComputeBlendShapePointIndices()
/// and ComputeSubShapePointOffsets().
USDSKEL_API bool
ComputeDeformedPoints(
const TfSpan<const float> subShapeWeights,
const TfSpan<const unsigned> blendShapeIndices,
const TfSpan<const unsigned> subShapeIndices,
const std::vector<VtIntArray>& blendShapePointIndices,
const std::vector<VtVec3fArray>& subShapePointOffsets,
TfSpan<GfVec3f> points) const;
/// Deform \p normals using the resolved sub-shapes given by
/// \p subShapeWeights, \p blendShapeIndices and \p subShapeIndices.
/// The \p blendShapePointIndices and \p blendShapeNormalOffsets
/// arrays both provide the pre-computed normal offsets and indices
/// of each sub-shape, as computed by ComputeBlendShapePointIndices()
/// and ComputeSubShapeNormalOffsets().
/// This is equivalent to ComputeDeformedPoints(), except that the
/// resulting points are normalized after deformation.
USDSKEL_API bool
ComputeDeformedNormals(
const TfSpan<const float> subShapeWeights,
const TfSpan<const unsigned> blendShapeIndices,
const TfSpan<const unsigned> subShapeIndices,
const std::vector<VtIntArray>& blendShapePointIndices,
const std::vector<VtVec3fArray>& subShapeNormalOffsets,
TfSpan<GfVec3f> noramls) const;
/// Compute a packed shape table combining all sub-shapes.
/// This is intended to help encode blend shapes in a GPU-friendly form.
/// The resulting \p offsets array holds contiguous runs of
/// offsets for every point. The array holds all of the offsets of
/// every blend shape for point 0, followed by the offset of every
/// blend shape for point 1, and so forth.
/// Offsets are stored as a GfVec4f. The first three components of each
/// offset holds the actual offset value, while the last value holds
/// the sub-shape index, as a float. The sub-shape index can be used
/// to lookup a corresponding weight value in the 'subShapeWeights'
/// array returned by ComputeSubShapeWeights.
USDSKEL_API bool
ComputePackedShapeTable(VtVec4fArray* offsets,
VtVec2iArray* ranges) const;
USDSKEL_API
std::string GetDescription() const;
private:
/// Object identifying a general subshape.
struct _SubShape {
_SubShape() = default;
_SubShape(unsigned blendShapeIndex, int inbetweenIndex, float weight)
: _blendShapeIndex(blendShapeIndex),
_inbetweenIndex(inbetweenIndex),
_weight(weight) {}
unsigned GetBlendShapeIndex() const { return _blendShapeIndex; }
int GetInbetweenIndex() const { return _inbetweenIndex; }
bool IsInbetween() const { return _inbetweenIndex >= 0; }
bool IsNullShape() const { return _weight == 0.0f; }
bool IsPrimaryShape() const { return _weight == 1.0f; }
float GetWeight() const { return _weight; }
private:
unsigned _blendShapeIndex = 0;
int _inbetweenIndex = 0;
float _weight = 0;
};
struct _SubShapeCompareByWeight {
bool operator()(const _SubShape& lhs, const _SubShape& rhs) const
{ return lhs.GetWeight() < rhs.GetWeight(); }
bool operator()(float lhs, const _SubShape& rhs) const
{ return lhs < rhs.GetWeight(); }
};
struct _BlendShape {
UsdSkelBlendShape shape;
size_t firstSubShape = 0;
size_t numSubShapes = 0;
};
UsdPrim _prim;
std::vector<_SubShape> _subShapes;
std::vector<_BlendShape> _blendShapes;
std::vector<UsdSkelInbetweenShape> _inbetweens;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_BLEND_SHAPE_QUERY_H
+134
View File
@@ -0,0 +1,134 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_CACHE_H
#define PXR_USD_USD_SKEL_CACHE_H
/// \file usdSkel/cache.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/primFlags.h"
#include "pxr/usd/usdSkel/animQuery.h"
#include "pxr/usd/usdSkel/binding.h"
#include <memory>
PXR_NAMESPACE_OPEN_SCOPE
class UsdSkelRoot;
class UsdSkelAnimation;
class UsdSkelSkeleton;
class UsdSkelSkeletonQuery;
class UsdSkelSkinningQuery;
TF_DECLARE_REF_PTRS(UsdSkelBinding);
/// Thread-safe cache for accessing query objects for evaluating skeletal data.
///
/// This provides caching of major structural components, such as skeletal
/// topology. In a streaming context, this cache is intended to persist.
class UsdSkelCache
{
public:
USDSKEL_API
UsdSkelCache();
USDSKEL_API
void Clear();
/// Populate the cache for the skeletal data beneath prim \p root,
/// as traversed using \p predicate.
///
/// Population resolves inherited skel bindings set using the
/// UsdSkelBindingAPI, making resolved bindings available through
/// GetSkinningQuery(), ComputeSkelBdining() and ComputeSkelBindings().
USDSKEL_API
bool Populate(const UsdSkelRoot& root,
Usd_PrimFlagsPredicate predicate) const;
/// Get a skel query for computing properties of \p skel.
///
/// This does not require Populate() to be called on the cache.
USDSKEL_API
UsdSkelSkeletonQuery GetSkelQuery(const UsdSkelSkeleton& skel) const;
/// Get an anim query corresponding to \p anim.
///
/// This does not require Populate() to be called on the cache.
USDSKEL_API
UsdSkelAnimQuery GetAnimQuery(const UsdSkelAnimation& anim) const;
/// \overload
/// \deprecated
USDSKEL_API
UsdSkelAnimQuery GetAnimQuery(const UsdPrim& prim) const;
/// Get a skinning query at \p prim.
///
/// Skinning queries are defined at any skinnable prims (I.e., boundable
/// prims with fully defined joint influences).
///
/// The caller must first Populate() the cache with the skel root containing
/// \p prim, with a predicate that will visit \p prim, in order for a
/// skinning query to be discoverable.
USDSKEL_API
UsdSkelSkinningQuery GetSkinningQuery(const UsdPrim& prim) const;
/// Compute the set of skeleton bindings beneath \p skelRoot,
/// as discovered through a traversal using \p predicate.
///
/// Skinnable prims are only discoverable by this method if Populate()
/// has already been called for \p skelRoot, with an equivalent predicate.
USDSKEL_API
bool ComputeSkelBindings(const UsdSkelRoot& skelRoot,
std::vector<UsdSkelBinding>* bindings,
Usd_PrimFlagsPredicate predicate) const;
/// Compute the bindings corresponding to a single skeleton, bound beneath
/// \p skelRoot, as discovered through a traversal using \p predicate.
///
/// Skinnable prims are only discoverable by this method if Populate()
/// has already been called for \p skelRoot, with an equivalent predicate.
USDSKEL_API
bool ComputeSkelBinding(const UsdSkelRoot& skelRoot,
const UsdSkelSkeleton& skel,
UsdSkelBinding* binding,
Usd_PrimFlagsPredicate predicate) const;
private:
std::shared_ptr<class UsdSkel_CacheImpl> _impl;
friend class UsdSkelAnimQuery;
friend class UsdSkelSkeletonQuery;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // USDSKEL_EVALCACHE_H
+43
View File
@@ -0,0 +1,43 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_DEBUG_CODES_H
#define PXR_USD_USD_SKEL_DEBUG_CODES_H
#include "pxr/pxr.h"
#include "pxr/base/tf/debug.h"
PXR_NAMESPACE_OPEN_SCOPE
TF_DEBUG_CODES(
USDSKEL_CACHE,
USDSKEL_BAKESKINNING
);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_DEBUG_CODES_H
+201
View File
@@ -0,0 +1,201 @@
//
// Copyright 2018 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
#define PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/usd/usdSkel/tokens.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class UsdSkelInbetweenShape
///
/// Schema wrapper for UsdAttribute for authoring and introspecting attributes
/// that serve as inbetween shapes of a UsdSkelBlendShape.
///
/// Inbetween shapes allow an explicit shape to be specified when the blendshape
/// to which it's bound is evaluated at a certain weight. For example, rather
/// than performing piecewise linear interpolation between a primary shape and
/// the rest shape at weight 0.5, an inbetween shape could be defined at the
/// weight. For weight values greater than 0.5, a shape would then be resolved
/// by linearly interpolating between the inbetween shape and the primary
/// shape, while for weight values less than or equal to 0.5, the shape is
/// resolved by linearly interpolating between the inbetween shape and the
/// primary shape.
class UsdSkelInbetweenShape
{
public:
/// Default constructor returns an invalid inbetween shape.
UsdSkelInbetweenShape() {}
/// Speculative constructor that will produce a valid UsdSkelInbetweenShape
/// when \p attr already represents an attribute that is an Inbetween, and
/// produces an \em invalid Inbetween otherwise (i.e.
/// \ref UsdSkelInbetweenShape_bool "operator bool()" will return false).
///
/// Calling \c UsdSkelInbetweenShape::IsInbetween(attr) will return the same
/// truth value as this constructor, but if you plan to subsequently use the
/// Inbetween anyways, just use this constructor.
USDSKEL_API
explicit UsdSkelInbetweenShape(const UsdAttribute& attr);
/// Return the location at which the shape is applied.
USDSKEL_API
bool GetWeight(float* weight) const;
/// Set the location at which the shape is applied.
USDSKEL_API
bool SetWeight(float weight) const;
/// Has a weight value been explicitly authored on this shape?
///
/// \sa GetWeight()
USDSKEL_API
bool HasAuthoredWeight() const;
/// Get the point offsets corresponding to this shape.
USDSKEL_API
bool GetOffsets(VtVec3fArray* offsets) const;
/// Set the point offsets corresponding to this shape.
USDSKEL_API
bool SetOffsets(const VtVec3fArray& offsets) const;
/// Returns a valid normal offsets attribute if the shape has normal
/// offsets. Returns an invalid attribute otherwise.
USDSKEL_API
UsdAttribute GetNormalOffsetsAttr() const;
/// Returns the existing normal offsets attribute if the shape has
/// normal offsets, or creates a new one.
USDSKEL_API
UsdAttribute
CreateNormalOffsetsAttr(const VtValue &defaultValue = VtValue()) const;
/// Get the normal offsets authored for this shape.
/// Normal offsets are optional, and may be left unspecified.
USDSKEL_API
bool GetNormalOffsets(VtVec3fArray* offsets) const;
/// Set the normal offsets authored for this shape.
USDSKEL_API
bool SetNormalOffsets(const VtVec3fArray& offsets) const;
/// Test whether a given UsdAttribute represents a valid Inbetween, which
/// implies that creating a UsdSkelInbetweenShape from the attribute will
/// succeed.
///
/// Succes implies that \c attr.IsDefined() is true.
USDSKEL_API
static bool IsInbetween(const UsdAttribute& attr);
// ---------------------------------------------------------------
/// \name UsdAttribute API
// ---------------------------------------------------------------
/// @{
/// Allow UsdSkelInbetweenShape to auto-convert to UsdAttribute,
/// so you can pass a UsdSkelInbetweenShape to any function that
/// accepts a UsdAttribute or const-ref thereto.
operator UsdAttribute const& () const { return _attr; }
/// Explicit UsdAttribute extractor.
UsdAttribute const &GetAttr() const { return _attr; }
/// Return true if the wrapped UsdAttribute::IsDefined(), and in
/// addition the attribute is identified as an Inbetween.
bool IsDefined() const { return IsInbetween(_attr); }
/// \anchor UsdSkelInbetweenShape_bool
/// Return true if this Inbetween is valid for querying and
/// authoring values and metadata, which is identically equivalent
/// to IsDefined().
explicit operator bool() const {
return IsDefined() ? (bool)_attr : 0;
}
bool operator==(const UsdSkelInbetweenShape& o) const {
return _attr == o._attr;
}
bool operator!=(const UsdSkelInbetweenShape& o) const {
return !(*this == o);
}
/// @}
private:
friend class UsdSkelBlendShape;
/// Validate that the given \p name is a valid attribute name for
/// an inbetween.
static bool _IsValidInbetweenName(const std::string& name,
bool quiet=false);
/// Validate that the given \p name contains the inbetweens namespace.
/// Does not validate \p name as a legal property identifier.
static bool _IsNamespaced(const TfToken& name);
/// Return \p name prepended with the proper inbetween namespace, if
/// it is not already prefixed.
///
/// Does not validate \p name as a legal property identifier, but will
/// verify that \p name contains no reserved keywords, and will return
/// an empty TfToken if it does. If \p quiet is true, the verification
/// will be silent.
static TfToken _MakeNamespaced(const TfToken& name, bool quiet=false);
static const TfToken& _GetNamespacePrefix();
static const TfToken& _GetNormalOffsetsSuffix();
UsdAttribute _GetNormalOffsetsAttr(bool create) const;
/// Factory for UsdBlendShape's use, so that we can encapsulate the
/// logic of what discriminates an Inbetween in this class, while
/// preserving the pattern that attributes can only be created via
/// their container objects.
///
/// The name of the created attribute may or may not be the specified
/// \p attrName, due to the possible need to apply property namespacing.
///
/// \return an invalid Inbetween if we failed to create a valid
/// attribute, o ra valid Inbetween otherwise. It is not an error
/// to create over an existing, compatible attribute.
///
/// \sa UsdPrim::CreateAttribute()
static UsdSkelInbetweenShape _Create(const UsdPrim& prim,
const TfToken& name);
UsdAttribute _attr;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_INBETWEEN_SHAPE_H
@@ -0,0 +1,177 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_PACKEDJOINTANIMATION_H
#define USDSKEL_GENERATED_PACKEDJOINTANIMATION_H
/// \file usdSkel/packedJointAnimation.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usdSkel/animation.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// PACKEDJOINTANIMATION //
// -------------------------------------------------------------------------- //
/// \class UsdSkelPackedJointAnimation
///
/// Deprecated. Please use SkelAnimation instead.
///
class UsdSkelPackedJointAnimation : public UsdSkelAnimation
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdSkelPackedJointAnimation on UsdPrim \p prim .
/// Equivalent to UsdSkelPackedJointAnimation::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelPackedJointAnimation(const UsdPrim& prim=UsdPrim())
: UsdSkelAnimation(prim)
{
}
/// Construct a UsdSkelPackedJointAnimation on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelPackedJointAnimation(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelPackedJointAnimation(const UsdSchemaBase& schemaObj)
: UsdSkelAnimation(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelPackedJointAnimation();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelPackedJointAnimation holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelPackedJointAnimation(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelPackedJointAnimation
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSKEL_API
static UsdSkelPackedJointAnimation
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+188
View File
@@ -0,0 +1,188 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_ROOT_H
#define USDSKEL_GENERATED_ROOT_H
/// \file usdSkel/root.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usdGeom/boundable.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// SKELROOT //
// -------------------------------------------------------------------------- //
/// \class UsdSkelRoot
///
/// Boundable prim type used to identify a scope beneath which
/// skeletally-posed primitives are defined.
///
/// A SkelRoot must be defined at or above a skinned primitive for any skinning
/// behaviors in UsdSkel.
///
/// See the extended \ref UsdSkel_SkelRoot "Skel Root Schema" documentation for
/// more information.
///
class UsdSkelRoot : public UsdGeomBoundable
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdSkelRoot on UsdPrim \p prim .
/// Equivalent to UsdSkelRoot::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelRoot(const UsdPrim& prim=UsdPrim())
: UsdGeomBoundable(prim)
{
}
/// Construct a UsdSkelRoot on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelRoot(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelRoot(const UsdSchemaBase& schemaObj)
: UsdGeomBoundable(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelRoot();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelRoot holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelRoot(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelRoot
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSKEL_API
static UsdSkelRoot
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
/// Returns the skel root at or above \p prim, or an invalid schema object
/// if no ancestor prim is defined as a skel root.
USDSKEL_API
static UsdSkelRoot Find(const UsdPrim& prim);
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+287
View File
@@ -0,0 +1,287 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_GENERATED_SKELETON_H
#define USDSKEL_GENERATED_SKELETON_H
/// \file usdSkel/skeleton.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usdGeom/boundable.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/stage.h"
#include "pxr/usd/usdSkel/tokens.h"
#include "pxr/usd/usdSkel/topology.h"
#include "pxr/base/vt/value.h"
#include "pxr/base/gf/vec3d.h"
#include "pxr/base/gf/vec3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/tf/token.h"
#include "pxr/base/tf/type.h"
PXR_NAMESPACE_OPEN_SCOPE
class SdfAssetPath;
// -------------------------------------------------------------------------- //
// SKELETON //
// -------------------------------------------------------------------------- //
/// \class UsdSkelSkeleton
///
/// Describes a skeleton.
///
/// See the extended \ref UsdSkel_Skeleton "Skeleton Schema" documentation for
/// more information.
///
///
class UsdSkelSkeleton : public UsdGeomBoundable
{
public:
/// Compile time constant representing what kind of schema this class is.
///
/// \sa UsdSchemaKind
static const UsdSchemaKind schemaKind = UsdSchemaKind::ConcreteTyped;
/// \deprecated
/// Same as schemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
static const UsdSchemaKind schemaType = UsdSchemaKind::ConcreteTyped;
/// Construct a UsdSkelSkeleton on UsdPrim \p prim .
/// Equivalent to UsdSkelSkeleton::Get(prim.GetStage(), prim.GetPath())
/// for a \em valid \p prim, but will not immediately throw an error for
/// an invalid \p prim
explicit UsdSkelSkeleton(const UsdPrim& prim=UsdPrim())
: UsdGeomBoundable(prim)
{
}
/// Construct a UsdSkelSkeleton on the prim held by \p schemaObj .
/// Should be preferred over UsdSkelSkeleton(schemaObj.GetPrim()),
/// as it preserves SchemaBase state.
explicit UsdSkelSkeleton(const UsdSchemaBase& schemaObj)
: UsdGeomBoundable(schemaObj)
{
}
/// Destructor.
USDSKEL_API
virtual ~UsdSkelSkeleton();
/// Return a vector of names of all pre-declared attributes for this schema
/// class and all its ancestor classes. Does not include attributes that
/// may be authored by custom/extended methods of the schemas involved.
USDSKEL_API
static const TfTokenVector &
GetSchemaAttributeNames(bool includeInherited=true);
/// Return a UsdSkelSkeleton holding the prim adhering to this
/// schema at \p path on \p stage. If no prim exists at \p path on
/// \p stage, or if the prim at that path does not adhere to this schema,
/// return an invalid schema object. This is shorthand for the following:
///
/// \code
/// UsdSkelSkeleton(stage->GetPrimAtPath(path));
/// \endcode
///
USDSKEL_API
static UsdSkelSkeleton
Get(const UsdStagePtr &stage, const SdfPath &path);
/// Attempt to ensure a \a UsdPrim adhering to this schema at \p path
/// is defined (according to UsdPrim::IsDefined()) on this stage.
///
/// If a prim adhering to this schema at \p path is already defined on this
/// stage, return that prim. Otherwise author an \a SdfPrimSpec with
/// \a specifier == \a SdfSpecifierDef and this schema's prim type name for
/// the prim at \p path at the current EditTarget. Author \a SdfPrimSpec s
/// with \p specifier == \a SdfSpecifierDef and empty typeName at the
/// current EditTarget for any nonexistent, or existing but not \a Defined
/// ancestors.
///
/// The given \a path must be an absolute prim path that does not contain
/// any variant selections.
///
/// If it is impossible to author any of the necessary PrimSpecs, (for
/// example, in case \a path cannot map to the current UsdEditTarget's
/// namespace) issue an error and return an invalid \a UsdPrim.
///
/// Note that this method may return a defined prim whose typeName does not
/// specify this schema class, in case a stronger typeName opinion overrides
/// the opinion at the current EditTarget.
///
USDSKEL_API
static UsdSkelSkeleton
Define(const UsdStagePtr &stage, const SdfPath &path);
protected:
/// Returns the kind of schema this class belongs to.
///
/// \sa UsdSchemaKind
USDSKEL_API
UsdSchemaKind _GetSchemaKind() const override;
/// \deprecated
/// Same as _GetSchemaKind, provided to maintain temporary backward
/// compatibility with older generated schemas.
USDSKEL_API
UsdSchemaKind _GetSchemaType() const override;
private:
// needs to invoke _GetStaticTfType.
friend class UsdSchemaRegistry;
USDSKEL_API
static const TfType &_GetStaticTfType();
static bool _IsTypedSchema();
// override SchemaBase virtuals.
USDSKEL_API
const TfType &_GetTfType() const override;
public:
// --------------------------------------------------------------------- //
// JOINTS
// --------------------------------------------------------------------- //
/// An array of path tokens identifying the set of joints that make
/// up the skeleton, and their order. Each token in the array must be valid
/// when parsed as an SdfPath. The parent-child relationships of the
/// corresponding paths determine the parent-child relationships of each
/// joint. It is not required that the name at the end of each path be
/// unique, but rather only that the paths themselves be unique.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] joints` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetJointsAttr() const;
/// See GetJointsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// JOINTNAMES
// --------------------------------------------------------------------- //
/// If authored, provides a unique name per joint. This may be
/// optionally set to provide better names when translating to DCC apps
/// that require unique joint names.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform token[] jointNames` |
/// | C++ Type | VtArray<TfToken> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->TokenArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetJointNamesAttr() const;
/// See GetJointNamesAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateJointNamesAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// BINDTRANSFORMS
// --------------------------------------------------------------------- //
/// Specifies the bind-pose transforms of each joint in
/// **world space**, in the ordering imposed by *joints*.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform matrix4d[] bindTransforms` |
/// | C++ Type | VtArray<GfMatrix4d> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Matrix4dArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetBindTransformsAttr() const;
/// See GetBindTransformsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateBindTransformsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// --------------------------------------------------------------------- //
// RESTTRANSFORMS
// --------------------------------------------------------------------- //
/// Specifies the rest-pose transforms of each joint in
/// **local space**, in the ordering imposed by *joints*. This provides
/// fallback values for joint transforms when a Skeleton either has no
/// bound animation source, or when that animation source only contains
/// animation for a subset of a Skeleton's joints.
///
/// | ||
/// | -- | -- |
/// | Declaration | `uniform matrix4d[] restTransforms` |
/// | C++ Type | VtArray<GfMatrix4d> |
/// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Matrix4dArray |
/// | \ref SdfVariability "Variability" | SdfVariabilityUniform |
USDSKEL_API
UsdAttribute GetRestTransformsAttr() const;
/// See GetRestTransformsAttr(), and also
/// \ref Usd_Create_Or_Get_Property for when to use Get vs Create.
/// If specified, author \p defaultValue as the attribute's default,
/// sparsely (when it makes sense to do so) if \p writeSparsely is \c true -
/// the default for \p writeSparsely is \c false.
USDSKEL_API
UsdAttribute CreateRestTransformsAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const;
public:
// ===================================================================== //
// Feel free to add custom code below this line, it will be preserved by
// the code generator.
//
// Just remember to:
// - Close the class declaration with };
// - Close the namespace with PXR_NAMESPACE_CLOSE_SCOPE
// - Close the include guard with #endif
// ===================================================================== //
// --(BEGIN CUSTOM CODE)--
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+244
View File
@@ -0,0 +1,244 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_SKELETON_QUERY_H
#define PXR_USD_USD_SKEL_SKELETON_QUERY_H
/// \file usdSkel/skeletonQuery.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/tf/declarePtrs.h"
#include "pxr/base/vt/types.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usdSkel/animMapper.h"
#include "pxr/usd/usdSkel/animQuery.h"
PXR_NAMESPACE_OPEN_SCOPE
class UsdGeomXformCache;
class UsdSkelSkeleton;
class UsdSkelTopology;
TF_DECLARE_REF_PTRS(UsdSkel_SkelDefinition);
/// \class UsdSkelSkeletonQuery
///
/// Primary interface to reading *bound* skeleton data.
/// This is used to query properties such as resolved transforms and animation
/// bindings, as bound through the UsdSkelBindingAPI.
///
/// A UsdSkelSkeletonQuery can not be constructed directly, and instead must be
/// constructed through a UsdSkelCache instance. This is done as follows:
///
/// \code
/// // Global cache, intended to persist.
/// UsdSkelCache skelCache;
/// // Populate the cache for a skel root.
/// skelCache.Populate(UsdSkelRoot(skelRootPrim));
///
/// if (UsdSkelSkeletonQuery skelQuery = skelCache.GetSkelQuery(skelPrim)) {
/// ...
/// }
/// \endcode
///
class UsdSkelSkeletonQuery
{
public:
UsdSkelSkeletonQuery() {}
/// Return true if this query is valid.
bool IsValid() const { return _definition; }
/// Boolean conversion operator. Equivalent to IsValid().
explicit operator bool() const { return IsValid(); }
/// Equality comparison. Return true if \a lhs and \a rhs represent the
/// same UsdSkelSkeletonQuery, false otherwise.
friend bool operator==(const UsdSkelSkeletonQuery& lhs,
const UsdSkelSkeletonQuery& rhs) {
return lhs._definition == rhs._definition &&
lhs._animQuery == rhs._animQuery;
}
/// Inequality comparison. Return false if \a lhs and \a rhs represent the
/// same UsdSkelSkeletonQuery, true otherwise.
friend bool operator!=(const UsdSkelSkeletonQuery& lhs,
const UsdSkelSkeletonQuery& rhs) {
return !(lhs == rhs);
}
/// Returns \c true if the size of the array returned by
/// skeleton::GetBindTransformsAttr() matches the number of joints in the skeleton.
USDSKEL_API
bool HasBindPose() const;
/// Returns \c true if the size of the array returned by
/// skeleton::GetRestTransformsAttr() matches the number of joints in the skeleton.
USDSKEL_API
bool HasRestPose() const;
// hash_value overload for std/boost hash.
USDSKEL_API
friend size_t hash_value(const UsdSkelSkeletonQuery& query);
/// Returns the underlying Skeleton primitive corresponding to the
/// bound skeleton instance, if any.
USDSKEL_API
UsdPrim GetPrim() const;
/// Returns the bound skeleton instance, if any.
USDSKEL_API
const UsdSkelSkeleton& GetSkeleton() const;
/// Returns the animation query that provides animation for the
/// bound skeleton instance, if any.
USDSKEL_API
const UsdSkelAnimQuery& GetAnimQuery() const;
/// Returns the topology of the bound skeleton instance, if any.
USDSKEL_API
const UsdSkelTopology& GetTopology() const;
/// Returns a mapper for remapping from the bound animation, if any,
/// to the Skeleton.
USDSKEL_API
const UsdSkelAnimMapper& GetMapper() const;
/// Returns an arrray of joint paths, given as tokens, describing
/// the order and parent-child relationships of joints in the skeleton.
///
/// \sa UsdSkelSkeleton::GetJointOrder
USDSKEL_API
VtTokenArray GetJointOrder() const;
/// Compute joint transforms in joint-local space, at \p time.
/// This returns transforms in joint order of the skeleton.
/// If \p atRest is false and an animation source is bound, local transforms
/// defined by the animation are mapped into the skeleton's joint order.
/// Any transforms not defined by the animation source use the transforms
/// from the rest pose as a fallback value.
/// If valid transforms cannot be computed for the animation source, the
/// \p xforms are instead set to the rest transforms.
template <typename Matrix4>
USDSKEL_API
bool ComputeJointLocalTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time,
bool atRest=false) const;
/// Compute joint transforms in skeleton space, at \p time.
/// This concatenates joint transforms as computed from
/// ComputeJointLocalTransforms(). If \p atRest is true, any bound animation
/// source is ignored, and transforms are computed from the rest pose.
/// The skeleton-space transforms of the rest pose are cached internally.
template <typename Matrix4>
USDSKEL_API
bool ComputeJointSkelTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time,
bool atRest=false) const;
/// Compute joint transforms which, when concatenated against the rest pose,
/// produce joint transforms in joint-local space. More specifically, this
/// computes *restRelativeTransform* in:
/// \code
/// restRelativeTransform * restTransform = jointLocalTransform
/// \endcode
template <typename Matrix4>
USDSKEL_API
bool ComputeJointRestRelativeTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time) const;
/// Compute joint transforms in world space, at whatever time is configured
/// on \p xfCache.
/// This is equivalent to computing skel-space joint transforms with
/// CmoputeJointSkelTransforms(), and then concatenating all transforms
/// by the local-to-world transform of the Skeleton prim.
/// If \p atRest is true, any bound animation source is ignored, and
/// transforms are computed from the rest pose.
template <typename Matrix4>
USDSKEL_API
bool ComputeJointWorldTransforms(VtArray<Matrix4>* xforms,
UsdGeomXformCache* xfCache,
bool atRest=false) const;
/// Compute transforms representing the change in transformation
/// of a joint from its rest pose, in skeleton space.
///
/// I.e.,
/// \code
/// inverse(bindTransform)*jointTransform
/// \endcode
///
/// These are the transforms usually required for skinning.
template <typename Matrix4>
USDSKEL_API
bool ComputeSkinningTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time) const;
/// Returns the world space joint transforms at bind time.
template <typename Matrix4>
USDSKEL_API
bool GetJointWorldBindTransforms(VtArray<Matrix4>* xforms) const;
USDSKEL_API
std::string GetDescription() const;
private:
USDSKEL_API
UsdSkelSkeletonQuery(const UsdSkel_SkelDefinitionRefPtr& definition,
const UsdSkelAnimQuery& anim=UsdSkelAnimQuery());
bool _HasMappableAnim() const;
template <typename Matrix4>
bool _ComputeJointLocalTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time,
bool atRest=false) const;
template <typename Matrix4>
bool _ComputeJointSkelTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time,
bool atRest=false) const;
template <typename Matrix4>
bool _ComputeSkinningTransforms(VtArray<Matrix4>* xforms,
UsdTimeCode time) const;
private:
UsdSkel_SkelDefinitionRefPtr _definition;
UsdSkelAnimQuery _animQuery;
UsdSkelAnimMapper _animToSkelMapper;
friend class UsdSkel_CacheImpl;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_SKELETON_QUERY_H
+280
View File
@@ -0,0 +1,280 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_SKINNING_QUERY_H
#define PXR_USD_USD_SKEL_SKINNING_QUERY_H
/// \file usdSkel/skinningQuery.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/usd/usd/attribute.h"
#include "pxr/usd/usd/prim.h"
#include "pxr/usd/usd/relationship.h"
#include "pxr/usd/usdGeom/primvar.h"
#include "pxr/usd/usdSkel/animMapper.h"
PXR_NAMESPACE_OPEN_SCOPE
class UsdGeomBoundable;
/// \class UsdSkelSkinningQuery
///
/// Object used for querying resolved bindings for skinning.
class UsdSkelSkinningQuery
{
public:
USDSKEL_API
UsdSkelSkinningQuery();
/// Construct a new skining query for the resolved properties
/// set through the UsdSkelBindingAPI, as inherited on \p prim.
/// The resulting query will be marked valid only if the inherited
/// properties provide proper valid joint influences.
USDSKEL_API
UsdSkelSkinningQuery(const UsdPrim& prim,
const VtTokenArray& skelJointOrder,
const VtTokenArray& blendShapeOrder,
const UsdAttribute& jointIndices,
const UsdAttribute& jointWeights,
const UsdAttribute& geomBindTransform,
const UsdAttribute& joints,
const UsdAttribute& blendShapes,
const UsdRelationship& blendShapeTargets);
/// Returns true if this query is valid.
bool IsValid() const { return bool(_prim); }
/// Boolean conversion operator. Equivalent to IsValid().
explicit operator bool() const { return IsValid(); }
const UsdPrim& GetPrim() const { return _prim; }
/// Returns true if there are blend shapes associated with this prim.
USDSKEL_API
bool HasBlendShapes() const;
/// Returns true if joint influence data is associated with this prim.
USDSKEL_API
bool HasJointInfluences() const;
/// Returns the number of influences encoded for each component.
/// If the prim defines rigid joint influences, then this returns
/// the number of influences that map to every point. Otherwise,
/// this provides the number of influences per point.
/// \sa IsRigidlyDeformed
int GetNumInfluencesPerComponent() const {
return _numInfluencesPerComponent;
}
const TfToken& GetInterpolation() const { return _interpolation; }
/// Returns true if the held prim has the same joint influences
/// across all points, or false otherwise.
USDSKEL_API
bool IsRigidlyDeformed() const;
const UsdAttribute& GetGeomBindTransformAttr() const {
return _geomBindTransformAttr;
}
const UsdGeomPrimvar& GetJointIndicesPrimvar() const {
return _jointIndicesPrimvar;
}
const UsdGeomPrimvar& GetJointWeightsPrimvar() const {
return _jointWeightsPrimvar;
}
const UsdAttribute& GetBlendShapesAttr() const {
return _blendShapes;
}
const UsdRelationship& GetBlendShapeTargetsRel() const {
return _blendShapeTargets;
}
/// Return a mapper for remapping from the joint order of the skeleton
/// to the local joint order of this prim, if any. Returns a null
/// pointer if the prim has no custom joint orer.
/// The mapper maps data from the order given by the \em joints order
/// on the Skeleton to the order given by the \em skel:joints property,
/// as optionally set through the UsdSkelBindingAPI.
const UsdSkelAnimMapperRefPtr& GetJointMapper() const {
return _jointMapper;
}
/// \deprecated Use GetJointMapper.
const UsdSkelAnimMapperRefPtr& GetMapper() const { return _jointMapper; }
/// Return the mapper for remapping blend shapes from the order of the
/// bound SkelAnimation to the local blend shape order of this prim.
/// Returns a null reference if the underlying prim has no blend shapes.
/// The mapper maps data from the order given by the \em blendShapes order
/// on the SkelAnimation to the order given by the \em skel:blendShapes
/// property, as set through the UsdSkelBindingAPI.
const UsdSkelAnimMapperRefPtr& GetBlendShapeMapper() const {
return _blendShapeMapper;
}
/// Get the custom joint order for this skinning site, if any.
USDSKEL_API
bool GetJointOrder(VtTokenArray* jointOrder) const;
/// Get the blend shapes for this skinning site, if any.
USDSKEL_API
bool GetBlendShapeOrder(VtTokenArray* blendShapes) const;
/// Populate \p times with the union of time samples for all properties
/// that affect skinning, independent of joint transforms and any
/// other prim-specific properties (such as points).
///
/// \sa UsdAttribute::GetTimeSamples
USDSKEL_API
bool GetTimeSamples(std::vector<double>* times) const;
/// Populate \p times with the union of time samples within \p interval,
/// for all properties that affect skinning, independent of joint
/// transforms and any other prim-specific properties (such as points).
///
/// \sa UsdAttribute::GetTimeSamplesInInterval
USDSKEL_API
bool GetTimeSamplesInInterval(const GfInterval& interval,
std::vector<double>* times) const;
/// Convenience method for computing joint influences.
/// In addition to querying influences, this will also perform
/// validation of the basic form of the weight data -- although
/// the array contents is not validated.
USDSKEL_API
bool ComputeJointInfluences(VtIntArray* indices,
VtFloatArray* weights,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Convenience method for computing joint influence, where constant
/// influences are expanded to hold values per point.
/// In addition to querying influences, this will also perform
/// validation of the basic form of the weight data -- although
/// the array contents is not validated.
USDSKEL_API
bool ComputeVaryingJointInfluences(
size_t numPoints,
VtIntArray* indices,
VtFloatArray* weights,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Compute skinned points using linear blend skinning.
/// Both \p xforms and \p points are given in _skeleton space_,
/// using the joint order of the bound skeleton.
/// Joint influences and the (optional) binding transform are computed
/// at time \p time (which will typically be unvarying).
///
/// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
template <typename Matrix4>
USDSKEL_API
bool ComputeSkinnedPoints(const VtArray<Matrix4>& xforms,
VtVec3fArray* points,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Compute skinned normals using linear blend skinning.
/// Both \p xforms and \p points are given in _skeleton space_,
/// using the joint order of the bound skeleton.
/// Joint influences and the (optional) binding transform are computed
/// at time \p time (which will typically be unvarying).
///
/// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
template <typename Matrix4>
USDSKEL_API
bool ComputeSkinnedNormals(const VtArray<Matrix4>& xforms,
VtVec3fArray* points,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Compute a skinning transform using linear blend skinning.
/// The \p xforms are given in _skeleton space_, using the joint order of
/// the bound skeleton.
/// Joint influences and the (optional) binding transform are computed
/// at time \p time (which will typically be unvarying).
/// If this skinning query holds non-constant joint influences,
/// no transform will be computed, and the function will return false.
///
/// \sa UsdSkelSkeletonQuery::ComputeSkinningTransforms
template <typename Matrix4>
USDSKEL_API
bool ComputeSkinnedTransform(const VtArray<Matrix4>& xforms,
Matrix4* xform,
UsdTimeCode time=UsdTimeCode::Default()) const;
/// Helper for computing an *approximate* padding for use in extents
/// computations. The padding is computed as the difference between the
/// pivots of the \p skelRestXforms -- _skeleton space_ joint transforms
/// at rest -- and the extents of the skinned primitive.
/// This is intended to provide a suitable, constant metric for padding
/// joint extents as computed by UsdSkelComputeJointsExtent.
template <typename Matrix4>
USDSKEL_API
float ComputeExtentsPadding(const VtArray<Matrix4>& skelRestXforms,
const UsdGeomBoundable& boundable) const;
USDSKEL_API
GfMatrix4d
GetGeomBindTransform(UsdTimeCode time=UsdTimeCode::Default()) const;
USDSKEL_API
std::string GetDescription() const;
private:
void _InitializeJointInfluenceBindings(
const UsdAttribute& jointIndices,
const UsdAttribute& jointWeights);
void _InitializeBlendShapeBindings(
const UsdAttribute& blendShapes,
const UsdRelationship& blendShapeTargets);
UsdPrim _prim;
int _numInfluencesPerComponent = 1;
int _flags = 0;
TfToken _interpolation;
UsdGeomPrimvar _jointIndicesPrimvar;
UsdGeomPrimvar _jointWeightsPrimvar;
UsdAttribute _geomBindTransformAttr;
UsdAttribute _blendShapes;
UsdRelationship _blendShapeTargets;
UsdSkelAnimMapperRefPtr _jointMapper;
UsdSkelAnimMapperRefPtr _blendShapeMapper;
boost::optional<VtTokenArray> _jointOrder;
boost::optional<VtTokenArray> _blendShapeOrder;
};
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_SKINNING_QUERY_H
+161
View File
@@ -0,0 +1,161 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef USDSKEL_TOKENS_H
#define USDSKEL_TOKENS_H
/// \file usdSkel/tokens.h
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
//
// This is an automatically generated file (by usdGenSchema.py).
// Do not hand-edit!
//
// XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/tf/staticData.h"
#include "pxr/base/tf/token.h"
#include <vector>
PXR_NAMESPACE_OPEN_SCOPE
/// \class UsdSkelTokensType
///
/// \link UsdSkelTokens \endlink provides static, efficient
/// \link TfToken TfTokens\endlink for use in all public USD API.
///
/// These tokens are auto-generated from the module's schema, representing
/// property names, for when you need to fetch an attribute or relationship
/// directly by name, e.g. UsdPrim::GetAttribute(), in the most efficient
/// manner, and allow the compiler to verify that you spelled the name
/// correctly.
///
/// UsdSkelTokens also contains all of the \em allowedTokens values
/// declared for schema builtin attributes of 'token' scene description type.
/// Use UsdSkelTokens like so:
///
/// \code
/// gprim.GetMyTokenValuedAttr().Set(UsdSkelTokens->bindTransforms);
/// \endcode
struct UsdSkelTokensType {
USDSKEL_API UsdSkelTokensType();
/// \brief "bindTransforms"
///
/// UsdSkelSkeleton
const TfToken bindTransforms;
/// \brief "blendShapes"
///
/// UsdSkelAnimation
const TfToken blendShapes;
/// \brief "blendShapeWeights"
///
/// UsdSkelAnimation
const TfToken blendShapeWeights;
/// \brief "jointNames"
///
/// UsdSkelSkeleton
const TfToken jointNames;
/// \brief "joints"
///
/// UsdSkelAnimation, UsdSkelSkeleton
const TfToken joints;
/// \brief "normalOffsets"
///
/// UsdSkelBlendShape
const TfToken normalOffsets;
/// \brief "offsets"
///
/// UsdSkelBlendShape
const TfToken offsets;
/// \brief "pointIndices"
///
/// UsdSkelBlendShape
const TfToken pointIndices;
/// \brief "primvars:skel:geomBindTransform"
///
/// UsdSkelBindingAPI
const TfToken primvarsSkelGeomBindTransform;
/// \brief "primvars:skel:jointIndices"
///
/// UsdSkelBindingAPI
const TfToken primvarsSkelJointIndices;
/// \brief "primvars:skel:jointWeights"
///
/// UsdSkelBindingAPI
const TfToken primvarsSkelJointWeights;
/// \brief "restTransforms"
///
/// UsdSkelSkeleton
const TfToken restTransforms;
/// \brief "rotations"
///
/// UsdSkelAnimation
const TfToken rotations;
/// \brief "scales"
///
/// UsdSkelAnimation
const TfToken scales;
/// \brief "skel:animationSource"
///
/// UsdSkelBindingAPI
const TfToken skelAnimationSource;
/// \brief "skel:blendShapes"
///
/// UsdSkelBindingAPI
const TfToken skelBlendShapes;
/// \brief "skel:blendShapeTargets"
///
/// UsdSkelBindingAPI
const TfToken skelBlendShapeTargets;
/// \brief "skel:joints"
///
/// UsdSkelBindingAPI
const TfToken skelJoints;
/// \brief "skel:skeleton"
///
/// UsdSkelBindingAPI
const TfToken skelSkeleton;
/// \brief "translations"
///
/// UsdSkelAnimation
const TfToken translations;
/// \brief "weight"
///
/// UsdSkelInbetweenShape - The weight location at which the inbetween shape applies.
const TfToken weight;
/// A vector of all of the tokens listed above.
const std::vector<TfToken> allTokens;
};
/// \var UsdSkelTokens
///
/// A global variable with static, efficient \link TfToken TfTokens\endlink
/// for use in all public USD API. \sa UsdSkelTokensType
extern USDSKEL_API TfStaticData<UsdSkelTokensType> UsdSkelTokens;
PXR_NAMESPACE_CLOSE_SCOPE
#endif
+109
View File
@@ -0,0 +1,109 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_TOPOLOGY_H
#define PXR_USD_USD_SKEL_TOPOLOGY_H
/// \file usdSkel/topology.h
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/tf/span.h"
#include "pxr/usd/sdf/path.h"
#include "pxr/usd/sdf/types.h"
PXR_NAMESPACE_OPEN_SCOPE
/// \class UsdSkelTopology
///
/// Object holding information describing skeleton topology.
/// This provides the hierarchical information needed to reason about joint
/// relationships in a manner suitable to computations.
class UsdSkelTopology
{
public:
/// Construct an empty topology.
UsdSkelTopology() = default;
/// Construct a skel topology from \p paths, an array holding ordered joint
/// paths as tokens.
/// Internally, each token must be converted to an SdfPath. If SdfPath
/// objects are already accessible, it is more efficient to use the
/// construct taking an SdfPath array.
USDSKEL_API
UsdSkelTopology(TfSpan<const TfToken> paths);
/// Construct a skel topology from \p paths, an array of joint paths.
USDSKEL_API
UsdSkelTopology(TfSpan<const SdfPath> paths);
/// Construct a skel topology from an array of parent indices.
/// For each joint, this provides the parent index of that
/// joint, or -1 if none.
USDSKEL_API
UsdSkelTopology(const VtIntArray& parentIndices);
/// Validate the topology.
/// If validation is unsuccessful, a reason
/// why will be written to \p reason, if provided.
USDSKEL_API
bool Validate(std::string* reason=nullptr) const;
const VtIntArray& GetParentIndices() const { return _parentIndices; }
size_t GetNumJoints() const { return size(); }
size_t size() const { return _parentIndices.size(); }
/// Returns the parent joint of the \p index'th joint,
/// Returns -1 for joints with no parent (roots).
inline int GetParent(size_t index) const;
/// Returns true if the \p index'th joint is a root joint.
bool IsRoot(size_t index) const { return GetParent(index) < 0; }
bool operator==(const UsdSkelTopology& o) const;
bool operator!=(const UsdSkelTopology& o) const {
return !(*this == o);
}
private:
VtIntArray _parentIndices;
};
int
UsdSkelTopology::GetParent(size_t index) const
{
TF_DEV_AXIOM(index < _parentIndices.size());
return _parentIndices[index];
}
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_TOPOLOGY_H
+667
View File
@@ -0,0 +1,667 @@
//
// Copyright 2016 Pixar
//
// Licensed under the Apache License, Version 2.0 (the "Apache License")
// with the following modification; you may not use this file except in
// compliance with the Apache License and the following modification to it:
// Section 6. Trademarks. is deleted and replaced with:
//
// 6. Trademarks. This License does not grant permission to use the trade
// names, trademarks, service marks, or product names of the Licensor
// and its affiliates, except as required to comply with Section 4(c) of
// the License and to reproduce the content of the NOTICE file.
//
// You may obtain a copy of the Apache License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Apache License with the above modification is
// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the Apache License for the specific
// language governing permissions and limitations under the Apache License.
//
#ifndef PXR_USD_USD_SKEL_UTILS_H
#define PXR_USD_USD_SKEL_UTILS_H
/// \file usdSkel/utils.h
///
/// Collection of utility methods.
///
#include "pxr/pxr.h"
#include "pxr/usd/usdSkel/api.h"
#include "pxr/base/gf/quatf.h"
#include "pxr/base/gf/matrix3d.h"
#include "pxr/base/gf/matrix3f.h"
#include "pxr/base/gf/matrix4d.h"
#include "pxr/base/gf/matrix4f.h"
#include "pxr/base/gf/vec3h.h"
#include "pxr/base/gf/vec3h.h"
#include "pxr/base/tf/span.h"
#include "pxr/base/vt/array.h"
#include "pxr/base/vt/types.h"
#include "pxr/usd/sdf/path.h"
#include <cstddef>
// XXX: Included for backwards compatibility.
#include "pxr/usd/usdSkel/bakeSkinning.h"
PXR_NAMESPACE_OPEN_SCOPE
class GfMatrix3f;
class GfRange3f;
class GfRotation;
class UsdPrim;
class UsdPrimRange;
class UsdRelationship;
class UsdSkelRoot;
class UsdSkelTopology;
/// \defgroup UsdSkel_Utils Utilities
/// @{
/// Returns true if \p prim is a valid skel animation source.
USDSKEL_API
bool
UsdSkelIsSkelAnimationPrim(const UsdPrim& prim);
/// Returns true if \p prim is considered to be a skinnable primitive.
/// Whether or not the prim is actually skinned additionally depends on whether
/// or not the prim has a bound skeleton, and prop joint influences.
USDSKEL_API
bool
UsdSkelIsSkinnablePrim(const UsdPrim& prim);
/// \defgroup UsdSkel_JointTransformUtils Joint Transform Utilities
/// Utilities for working with vectorized joint transforms.
/// @{
/// Compute joint transforms in joint-local space.
/// Transforms are computed from \p xforms, holding concatenated
/// joint transforms, and \p inverseXforms, providing the inverse
/// of each of those transforms. The resulting local space transforms
/// are written to \p jointLocalXforms, which must be the same size
/// as \p topology.
/// If the root joints include an additional, external transformation
/// -- eg., such as the skel local-to-world transformation -- then the
/// inverse of that transform should be passed as \p rootInverseXform.
/// If no \p rootInverseXform is provided, then \p xform and \p inverseXforms
/// should be based on joint transforms computed in skeleton space.
/// Each transform array must be sized to the number of joints from \p topology.
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4d> xforms,
TfSpan<const GfMatrix4d> inverseXforms,
TfSpan<GfMatrix4d> jointLocalXforms,
const GfMatrix4d* rootInverseXform=nullptr);
/// \overload
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4f> xforms,
TfSpan<const GfMatrix4f> inverseXforms,
TfSpan<GfMatrix4f> jointLocalXforms,
const GfMatrix4f* rootInverseXform=nullptr);
/// Compute joint transforms in joint-local space.
/// This is a convenience overload, which computes the required inverse
/// transforms internally.
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4d> xforms,
TfSpan<GfMatrix4d> jointLocalXforms,
const GfMatrix4d* rootInverseXform=nullptr);
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4f> xforms,
TfSpan<GfMatrix4f> jointLocalXforms,
const GfMatrix4f* rootInverseXform=nullptr);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
const VtMatrix4dArray& xforms,
const VtMatrix4dArray& inverseXforms,
VtMatrix4dArray* jointLocalXforms,
const GfMatrix4d* rootInverseXform=nullptr);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
const VtMatrix4dArray& xforms,
VtMatrix4dArray* jointLocalXforms,
const GfMatrix4d* rootInverseXform=nullptr);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelComputeJointLocalTransforms(const UsdSkelTopology& topology,
const GfMatrix4d* xforms,
const GfMatrix4d* inverseXforms,
GfMatrix4d* jointLocalXforms,
const GfMatrix4d* rootInverseXform=nullptr);
/// Compute concatenated joint transforms.
/// This concatenates transforms from \p jointLocalXforms, providing joint
/// transforms in joint-local space. The resulting transforms are written to
/// \p jointLocalXforms, which must be the same size as \p topology.
/// If \p rootXform is not provided, or is the identity, the resulting joint
/// transforms will be given in skeleton space. Any additional transformations
/// may be provided on \p rootXform if an additional level of transformation
/// -- such as the skel local to world transform -- are desired.
/// Each transform array must be sized to the number of joints from \p topology.
USDSKEL_API
bool
UsdSkelConcatJointTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4d> jointLocalXforms,
TfSpan<GfMatrix4d> xforms,
const GfMatrix4d* rootXform=nullptr);
/// \overload
USDSKEL_API
bool
UsdSkelConcatJointTransforms(const UsdSkelTopology& topology,
TfSpan<const GfMatrix4f> jointLocalXforms,
TfSpan<GfMatrix4f> xforms,
const GfMatrix4f* rootXform=nullptr);
/// \overload
/// \deprecated Use the function form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelConcatJointTransforms(const UsdSkelTopology& topology,
const VtMatrix4dArray& jointLocalXforms,
VtMatrix4dArray* xforms,
const GfMatrix4d* rootXform=nullptr);
/// \overload
/// \deprecated Use the form that takes a TfSpan argument.
USDSKEL_API
bool
UsdSkelConcatJointTransforms(const UsdSkelTopology& topology,
const GfMatrix4d* jointLocalXforms,
GfMatrix4d* xforms,
const GfMatrix4d* rootXform=nullptr);
/// Compute an extent from a set of skel-space joint transform.
/// The \p rootXform may also be set to provide an additional root
/// transformation on top of all joints, which is useful for computing
/// extent relative to a different space.
template <typename Matrix4>
USDSKEL_API
bool
UsdSkelComputeJointsExtent(TfSpan<const Matrix4> joints,
GfRange3f* extent,
float pad=0.0f,
const Matrix4* rootXform=nullptr);
/// \overload
/// \deprecated Use form that takes a TfSpan.
USDSKEL_API
bool
UsdSkelComputeJointsExtent(const VtMatrix4dArray& joints,
VtVec3fArray* extent,
float pad=0.0f,
const GfMatrix4d* rootXform=nullptr);
/// \overload
/// \deprecated Use form that takes a TfSpan.
USDSKEL_API
bool
UsdSkelComputeJointsExtent(const GfMatrix4d* xforms,
size_t numXforms,
VtVec3fArray* extent,
float pad=0.0f,
const GfMatrix4d* rootXform=nullptr);
/// @}
/// \defgroup UsdSkel_TransformCompositionUtils Transform Composition Utils
/// Utiltiies for converting transforms to and from component (translate,
/// rotate, scale) form.
/// @{
/// Decompose a transform into translate/rotate/scale components.
/// The transform order for decomposition is scale, rotate, translate.
template <typename Matrix4>
USDSKEL_API
bool
UsdSkelDecomposeTransform(const Matrix4& xform,
GfVec3f* translate,
GfRotation* rotate,
GfVec3h* scale);
/// \overload
template <typename Matrix4>
USDSKEL_API
bool
UsdSkelDecomposeTransform(const Matrix4& xform,
GfVec3f* translate,
GfQuatf* rotate,
GfVec3h* scale);
/// Decompose an array of transforms into translate/rotate/scale components.
/// All spans must be the same size.
USDSKEL_API
bool
UsdSkelDecomposeTransforms(TfSpan<const GfMatrix4d> xforms,
TfSpan<GfVec3f> translations,
TfSpan<GfQuatf> rotations,
TfSpan<GfVec3h> scales);
/// \overload
USDSKEL_API
bool
UsdSkelDecomposeTransforms(TfSpan<const GfMatrix4f> xforms,
TfSpan<GfVec3f> translations,
TfSpan<GfQuatf> rotations,
TfSpan<GfVec3h> scales);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelDecomposeTransforms(const VtMatrix4dArray& xforms,
VtVec3fArray* translations,
VtQuatfArray* rotations,
VtVec3hArray* scales);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelDecomposeTransforms(const GfMatrix4d* xforms,
GfVec3f* translations,
GfQuatf* rotations,
GfVec3h* scales,
size_t count);
/// Create a transform from translate/rotate/scale components.
/// This performs the inverse of UsdSkelDecomposeTransform.
template <typename Matrix4>
USDSKEL_API
void
UsdSkelMakeTransform(const GfVec3f& translate,
const GfMatrix3f& rotate,
const GfVec3h& scale,
Matrix4* xform);
/// \overload
template <typename Matrix4>
USDSKEL_API
void
UsdSkelMakeTransform(const GfVec3f& translate,
const GfQuatf& rotate,
const GfVec3h& scale,
Matrix4* xform);
/// Create transforms from arrays of components.
/// All spans must be the same size.
USDSKEL_API
bool
UsdSkelMakeTransforms(TfSpan<const GfVec3f> translations,
TfSpan<const GfQuatf> rotations,
TfSpan<const GfVec3h> scales,
TfSpan<GfMatrix4d> xforms);
/// \overload
USDSKEL_API
bool
UsdSkelMakeTransforms(TfSpan<const GfVec3f> translations,
TfSpan<const GfQuatf> rotations,
TfSpan<const GfVec3h> scales,
TfSpan<GfMatrix4f> xforms);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelMakeTransforms(const VtVec3fArray& translations,
const VtQuatfArray& rotations,
const VtVec3hArray& scales,
VtMatrix4dArray* xforms);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelMakeTransforms(const GfVec3f* translations,
const GfQuatf* rotations,
const GfVec3h* scales,
GfMatrix4d* xforms,
size_t count);
/// @}
/// \defgroup UsdSkel_JointInfluenceUtils Joint Influence Utils
/// Collection of methods for working \ref UsdSkel_Terminology_JointInfluences
/// "joint influences", as stored through UsdSkelBindingAPI.`
/// @{
/// Helper method to normalize weight values across each consecutive run of
/// \p numInfluencesPerComponent elements.
USDSKEL_API
bool
UsdSkelNormalizeWeights(TfSpan<float> weights, int numInfluencesPerComponent);
/// \overload
/// \deprecated Use form that takes a TfSpan.
USDSKEL_API
bool
UsdSkelNormalizeWeights(VtFloatArray* weights, int numInfluencesPerComponent);
/// Sort joint influences such that highest weight values come first.
USDSKEL_API
bool
UsdSkelSortInfluences(TfSpan<int> indices, TfSpan<float> weights,
int numInfluencesPerComponent);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelSortInfluences(VtIntArray* indices, VtFloatArray* weights,
int numInfluencesPerComponent);
/// Convert an array of constant influences (joint weights or indices)
/// to an array of varying influences.
/// The \p size should match the size of required for 'vertex' interpolation
/// on the type geometry primitive. Typically, this is the number of points.
/// This is a convenience function for clients that don't understand
/// constant (rigid) weighting.
USDSKEL_API
bool
UsdSkelExpandConstantInfluencesToVarying(VtIntArray* indices, size_t size);
/// \overload
USDSKEL_API
bool
UsdSkelExpandConstantInfluencesToVarying(VtFloatArray* weights, size_t size);
/// Resize the number of influences per component in a weight or indices array,
/// which initially has \p srcNumInfluencesPerComponent influences to have
/// no more than \p newNumInfluencesPerComponent influences per component.
/// If the size decreases, influences are additionally re-normalized.
/// This is a convenience method for clients that require a fixed number of
/// of influences.
USDSKEL_API
bool
UsdSkelResizeInfluences(VtIntArray* indices,
int srcNumInfluencesPerComponent,
int newNumInfluencesPerComponent);
/// \overload
USDSKEL_API
bool
UsdSkelResizeInfluences(VtFloatArray* weights,
int srcNumInfluencesPerComponent,
int newNumInfluencesPerComponent);
/// Combine arrays of joint indices and weights into interleaved
/// (index,weight) vectors.
USDSKEL_API
bool
UsdSkelInterleaveInfluences(const TfSpan<const int>& indices,
const TfSpan<const float>& weights,
TfSpan<GfVec2f> interleavedInfluences);
/// @}
/// \defgroup UsdSkel_SkinningUtils Skinning Implementations
/// Reference skinning implementations for skinning points and transforms.
/// @{
/// Skin points using linear blend skinning (LBS).
/// The \p jointXforms are \ref UsdSkel_Term_SkinningTransforms
/// "skinning transforms", given in _skeleton space_, while the
/// \p geomBindTransform provides the transform that transforms the initial
/// \p points into the same _skeleton space_ that the skinning transforms
/// were computed in.
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
TfSpan<const GfMatrix4d> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
int numInfluencesPerPoint,
TfSpan<GfVec3f> points,
bool inSerial=false);
/// \overload
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4f& geomBindTransform,
TfSpan<const GfMatrix4f> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
int numInfluencesPerPoint,
TfSpan<GfVec3f> points,
bool inSerial=false);
/// Skin points using linear blend skinning, with interleaved influences.
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
TfSpan<const GfMatrix4d> jointXforms,
TfSpan<const GfVec2f> influences,
int numInfluencesPerPoint,
TfSpan<GfVec3f> points,
bool inSerial=false);
/// \overload
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4f& geomBindTransform,
TfSpan<const GfMatrix4f> jointXforms,
TfSpan<const GfVec2f> influences,
int numInfluencesPerPoint,
TfSpan<GfVec3f> points,
bool inSerial=false);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
const VtMatrix4dArray& jointXforms,
const VtIntArray& jointIndices,
const VtFloatArray& jointWeights,
int numInfluencesPerPoint,
VtVec3fArray* points);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelSkinPointsLBS(const GfMatrix4d& geomBindTransform,
const GfMatrix4d* jointXforms,
size_t numJoints,
const int* jointIndices,
const float* jointWeights,
size_t numInfluences,
int numInfluencesPerPoint,
GfVec3f* points,
size_t numPoints,
bool inSerial=false);
/// Skin normals using linear blend skinning (LBS).
/// Currently, this is restricted to skinning of normals stored using
/// _vertex_ primvar interpolation.
/// The \p jointXforms are the *inverse transposes* of the 3x3 component
/// of the \ref UsdSkel_Term_SkinningTransforms" "skinning transforms",
/// given in _skeleton space_. The \p geomBindTransform is the
/// *inverse transpose* of the matrix that transforms points from a
/// bind pose ino the same _skeleton space_ that the skinning tranforms
/// were computed in.
USDSKEL_API
bool
UsdSkelSkinNormalsLBS(const GfMatrix3d& geomBindTransform,
TfSpan<const GfMatrix3d> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
int numInfluencesPerPoint,
TfSpan<GfVec3f> normals,
bool inSerial=false);
/// \overload
USDSKEL_API
bool
UsdSkelSkinNormalsLBS(const GfMatrix3f& geomBindTransform,
TfSpan<const GfMatrix3f> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
int numInfluencesPerPoint,
TfSpan<GfVec3f> normals,
bool inSerial=false);
/// \overload
USDSKEL_API
bool
UsdSkelSkinNormalsLBS(const GfMatrix3d& geomBindTransform,
TfSpan<const GfMatrix3d> jointXforms,
TfSpan<const GfVec2f> influences,
int numInfluencesPerPoint,
TfSpan<GfVec3f> normals,
bool inSerial=false);
/// \overload
USDSKEL_API
bool
UsdSkelSkinNormalsLBS(const GfMatrix3f& geomBindTransform,
TfSpan<const GfMatrix3f> jointXforms,
TfSpan<const GfVec2f> influences,
int numInfluencesPerPoint,
TfSpan<GfVec3f> normals,
bool inSerial=false);
/// Skin a transform using linear blend skinning (LBS).
/// The \p jointXforms are \ref UsdSkel_Term_SkinningTransforms
/// "skinning transforms", given in _skeleton space_, while the
/// \p geomBindTransform provides the transform that initially places
/// a primitive in that same _skeleton space_.
USDSKEL_API
bool
UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
TfSpan<const GfMatrix4d> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
GfMatrix4d* xform);
/// \overload
USDSKEL_API
bool
UsdSkelSkinTransformLBS(const GfMatrix4f& geomBindTransform,
TfSpan<const GfMatrix4f> jointXforms,
TfSpan<const int> jointIndices,
TfSpan<const float> jointWeights,
GfMatrix4f* xform);
/// Overload taking interleaved joint influences.
/// \overload
USDSKEL_API
bool
UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
TfSpan<const GfMatrix4d> jointXforms,
TfSpan<const GfVec2f> influences,
GfMatrix4d* xform);
/// \overload
USDSKEL_API
bool
UsdSkelSkinTransformLBS(const GfMatrix4f& geomBindTransform,
TfSpan<const GfMatrix4f> jointXforms,
TfSpan<const GfVec2f> influences,
GfMatrix4f* xform);
/// \overload
/// \deprecated Use form that takes TfSpan arguments.
USDSKEL_API
bool
UsdSkelSkinTransformLBS(const GfMatrix4d& geomBindTransform,
const GfMatrix4d* jointXforms,
size_t numJoints,
const int* jointIndices,
const float* jointWeights,
size_t numInfluences,
GfMatrix4d* xform);
/// Apply a single blend shape to \p points.
/// The shape is given as a span of \p offsets. If the \p indices span is not
/// empty, it provides the index into the \p points span at which each offset
/// should be mapped. Otherwise, the \p offsets span must be the same size as
/// the \p points span.
USDSKEL_API
bool
UsdSkelApplyBlendShape(const float weight,
const TfSpan<const GfVec3f> offsets,
const TfSpan<const int> indices,
TfSpan<GfVec3f> points);
PXR_NAMESPACE_CLOSE_SCOPE
#endif // PXR_USD_USD_SKEL_UTILS_H