All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
UsdUtilsSparseValueWriter Class Reference

Utility class that manages sparse authoring of a set of UsdAttributes. More...

Public Member Functions

USDUTILS_API bool SetAttribute (const UsdAttribute &attr, const VtValue &value, const UsdTimeCode time=UsdTimeCode::Default())
 Sets the value of attr to value at time time. More...
 
USDUTILS_API bool SetAttribute (const UsdAttribute &attr, VtValue *value, const UsdTimeCode time=UsdTimeCode::Default())
 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. More...
 
template<typename T >
bool SetAttribute (const UsdAttribute &attr, T &value, const UsdTimeCode time=UsdTimeCode::Default())
 
USDUTILS_API void Clear ()
 Clears the internal map, thereby releasing all the memory used by the sparse value-writers. More...
 

Detailed Description

Utility class that manages sparse authoring of a set of UsdAttributes.

It does this by maintaining a map of UsdAttributes to their corresponding UsdUtilsSparseAttrValueWriter objects.

To use this class, simply instantiate an instance of it and invoke the SetAttribute() method with various attributes and their associated time-samples.

Note
If the attribute has a default value, SetAttribute() must be called with time=Default first (multiple times, if necessary), followed by calls to author time-samples in sequentially increasing time order.
This class is not threadsafe. In general, authoring to a single USD layer from multiple threads isn't threadsafe. Hence, there is little value in making this class threadsafe.

Example c++ usage:

* UsdGeomCylinder cylinder = UsdGeomCylinder::Define(stage, SdfPath("/Cylinder"));
* UsdAttribute radius = cylinder.CreateRadiusAttr();
* UsdAttribute height = cylinder.CreateHeightAttr();
* valueWriter.SetAttribute(radius, 2.0, UsdTimeCode::Default());
* valueWriter.SetAttribute(height, 2.0, UsdTimeCode::Default());
*
* valueWriter.SetAttribute(radius, 10.0, UsdTimeCode(1.0));
* valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(2.0));
* valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(3.0));
* valueWriter.SetAttribute(radius, 20.0, UsdTimeCode(4.0));
*
* valueWriter.SetAttribute(height, 2.0, UsdTimeCode(1.0));
* valueWriter.SetAttribute(height, 2.0, UsdTimeCode(2.0));
* valueWriter.SetAttribute(height, 3.0, UsdTimeCode(3.0));
* valueWriter.SetAttribute(height, 3.0, UsdTimeCode(4.0));
*

Equivalent python code:

1 * cylinder = UsdGeom.Cylinder.Define(stage, Sdf.Path("/Cylinder"))
2 * radius = cylinder.CreateRadiusAttr()
3 * height = cylinder.CreateHeightAttr()
4 * valueWriter = UsdUtils.SparseValueWriter()
5 * valueWriter.SetAttribute(radius, 2.0, Usd.TimeCode.Default())
6 * valueWriter.SetAttribute(height, 2.0, Usd.TimeCode.Default())
7 *
8 * valueWriter.SetAttribute(radius, 10.0, 1.0)
9 * valueWriter.SetAttribute(radius, 20.0, 2.0)
10 * valueWriter.SetAttribute(radius, 20.0, 3.0)
11 * valueWriter.SetAttribute(radius, 20.0, 4.0)
12 *
13 * valueWriter.SetAttribute(height, 2.0, 1.0)
14 * valueWriter.SetAttribute(height, 2.0, 2.0)
15 * valueWriter.SetAttribute(height, 3.0, 3.0)
16 * valueWriter.SetAttribute(height, 3.0, 4.0)
17 *

In the above example,

  • The default value of the "height" attribute is not authored into scene description since it matches the fallback value.
  • Time-samples at time=3.0 and time=4.0 will be skipped for the radius attribute.
  • For the "height" attribute, the first timesample at time=1.0 will be skipped since it matches the default value.
  • The last time-sample at time=4.0 will also be skipped for "height" since it matches the previously written value at time=3.0.

Definition at line 229 of file sparseValueWriter.h.

Member Function Documentation

USDUTILS_API void Clear ( )
inline

Clears the internal map, thereby releasing all the memory used by the sparse value-writers.

Definition at line 264 of file sparseValueWriter.h.

USDUTILS_API bool SetAttribute ( const UsdAttribute attr,
const VtValue value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)

Sets the value of attr to value at time time.

The value is written sparsely, i.e., the default value is authored only if it is different from the fallback value or the existing default value, and any redundant time-samples are skipped when the attribute value does not change significantly between consecutive time-samples.

USDUTILS_API bool SetAttribute ( const UsdAttribute attr,
VtValue value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)

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.

bool SetAttribute ( const UsdAttribute attr,
T &  value,
const UsdTimeCode  time = UsdTimeCode::Default() 
)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Definition at line 253 of file sparseValueWriter.h.


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