Loading...
Searching...
No Matches
UsdUtilsSparseAttrValueWriter Class Reference

A utility class for authoring time-varying attribute values with simple run-length encoding, by skipping any redundant time-samples. More...

#include <sparseValueWriter.h>

Public Member Functions

USDUTILS_API UsdUtilsSparseAttrValueWriter (const UsdAttribute &attr, const VtValue &defaultValue=VtValue())
 The constructor initializes the data required for run-length encoding of time-samples.
 
USDUTILS_API UsdUtilsSparseAttrValueWriter (const UsdAttribute &attr, VtValue *defaultValue)
 The constructor initializes the data required for run-length encoding of time-samples.
 
USDUTILS_API bool SetTimeSample (const VtValue &value, const UsdTimeCode time)
 Sets a new time-sample on the attribute with given value at the given time.
 
USDUTILS_API bool SetTimeSample (VtValue *value, const UsdTimeCode time)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.For efficiency, this function swaps out the given value, leaving it empty.
 
const UsdAttributeGetAttr () const
 Returns the attribute that's held in the sparse value writer.
 

Detailed Description

A utility class for authoring time-varying attribute values with simple run-length encoding, by skipping any redundant time-samples.

Time-samples that are close enough to each other, with relative difference smaller than a fixed epsilon value are considered to be equivalent. This is to avoid unnecessary authoring of time-samples caused by numerical fuzz in certain computations.

For vectors, matrices, and other composite types (like quaternions and arrays), each component is compared with the corresponding component for closeness. The chosen epsilon value for double precision floating point numbers is 1e-12. For single-precision, it is 1e-6 and for half-precision, it is 1e-2.

Example c++ usage:

UsdGeomSphere sphere = UsdGeomSphere::Define(stage, SdfPath("/Sphere"));
UsdAttribute radius = sphere.CreateRadiusAttr();
UsdUtilsSparseAttrValueWriter attrValueWriter(radius,
/*defaultValue*/ VtValue(1.0));
attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(1.0));
attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(2.0));
attrValueWriter.SetTimeSample(VtValue(10.0), UsdTimeCode(3.0));
attrValueWriter.SetTimeSample(VtValue(20.0), UsdTimeCode(4.0));
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:290
Scenegraph object for authoring and retrieving numeric, string, and array valued data,...
Definition: attribute.h:176
Defines a primitive sphere centered at the origin.
Definition: sphere.h:61
static USDGEOM_API UsdGeomSphere Define(const UsdStagePtr &stage, const SdfPath &path)
Attempt to ensure a UsdPrim adhering to this schema at path is defined (according to UsdPrim::IsDefin...
USDGEOM_API UsdAttribute CreateRadiusAttr(VtValue const &defaultValue=VtValue(), bool writeSparsely=false) const
See GetRadiusAttr(), and also Create vs Get Property Methods for when to use Get vs Create.
Represent a time value, which may be either numeric, holding a double value, or a sentinel value UsdT...
Definition: timeCode.h:84
A utility class for authoring time-varying attribute values with simple run-length encoding,...
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:164

Equivalent python example:

sphere = UsdGeom.Sphere.Define(stage, Sdf.Path("/Sphere"))
radius = sphere.CreateRadiusAttr()
attrValueWriter = UsdUtils.SparseAttrValueWriter(radius, defaultValue=1.0)
attrValueWriter.SetTimeSample(10.0, 1.0)
attrValueWriter.SetTimeSample(10.0, 2.0)
attrValueWriter.SetTimeSample(10.0, 3.0)
attrValueWriter.SetTimeSample(20.0, 4.0)

In the above examples, the specified default value of radius (1.0) will not be authored into scene description since it matches the fallback value. Additionally, the time-sample authored at time=2.0 will be skipped since it is redundant. Also note that for correct behavior, the calls to SetTimeSample() must be made with sequentially increasing time values. If not, a coding error is issued and the authored animation may be incorrect.

Definition at line 88 of file sparseValueWriter.h.

Constructor & Destructor Documentation

◆ UsdUtilsSparseAttrValueWriter() [1/2]

USDUTILS_API UsdUtilsSparseAttrValueWriter ( const UsdAttribute attr,
const VtValue defaultValue = VtValue() 
)

The constructor initializes the data required for run-length encoding of time-samples.

It also sets the default value of attr to defaultValue, if defaultValue is non-empty and different from the existing default value of attr.

defaultValue can be unspecified (or left empty) if you don't care about authoring a default value. In this case, the sparse authoring logic is initialized with the existing authored default value or the fallback value, if attr has one.

◆ UsdUtilsSparseAttrValueWriter() [2/2]

USDUTILS_API UsdUtilsSparseAttrValueWriter ( const UsdAttribute attr,
VtValue defaultValue 
)

The constructor initializes the data required for run-length encoding of time-samples.

It also sets the default value of attr to defaultValue, if defaultValue is non-empty and different from the existing default value of attr.

It defaultValue is null or points to an empty VtValue, the sparse authoring logic is initialized with the existing authored default value or the fallback value, if attr has one.

For efficiency, this function swaps out the given defaultValue, leaving it empty.

Member Function Documentation

◆ GetAttr()

const UsdAttribute & GetAttr ( ) const
inline

Returns the attribute that's held in the sparse value writer.

Definition at line 139 of file sparseValueWriter.h.

◆ SetTimeSample() [1/2]

USDUTILS_API bool SetTimeSample ( const VtValue value,
const UsdTimeCode  time 
)

Sets a new time-sample on the attribute with given value at the given time.

The time-sample is only authored if it's different from the previously set time-sample, in which case the previous time-sample is also authored, in order to to end the previous run of contiguous identical values and start a new run.

This incurs a copy of value. Also, the value will be held in memory at least until the next time-sample is written or until the SparseAttrValueWriter instance is destroyed.

◆ SetTimeSample() [2/2]

USDUTILS_API bool SetTimeSample ( VtValue value,
const UsdTimeCode  time 
)

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.For efficiency, this function swaps out the given value, leaving it empty.

The value will be held in memory at least until the next time-sample is written or until the SparseAttrValueWriter instance is destroyed.


The documentation for this class was generated from the following file: