HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
GusdPrimWrapper Class Referenceabstract

A GT_Primitive that wraps a USD Prim. More...

#include <primWrapper.h>

+ Inheritance diagram for GusdPrimWrapper:

Classes

struct  AttrLastValueEntry
 

Public Types

typedef UT_Function
< GT_PrimitiveHandle(const
GT_PrimitiveHandle &, const
UsdStagePtr &, const SdfPath
&, const GusdContext &)> 
DefinitionForWriteFunction
 
typedef UT_Function
< GT_PrimitiveHandle(const
UsdGeomImageable
&, UsdTimeCode, GusdPurposeSet)> 
DefinitionForReadFunction
 
typedef UT_Function< bool(const
GT_PrimitiveHandle
&, std::string &primName)> 
GetPrimNameFunction
 
typedef UT_Function
< GT_DataArrayHandle(const
GT_DataArrayHandle &)> 
ResampleArrayFunction
 

Public Member Functions

 GusdPrimWrapper ()
 
 GusdPrimWrapper (const UsdTimeCode &time, const GusdPurposeSet &purposes)
 
 GusdPrimWrapper (const GusdPrimWrapper &in)
 
 ~GusdPrimWrapper () override
 
virtual bool isValid () const
 Return true if the underlying USD prim is valid. More...
 
virtual const UsdGeomImageable getUsdPrim () const =0
 
virtual bool unpack (UT_Array< GU_DetailHandle > &details, const UT_StringRef &fileName, const SdfPath &primPath, const UT_Matrix4D *xform, fpreal frame, const char *viewportLod, GusdPurposeSet purposes, const GT_RefineParms &rparms) const
 
virtual bool redefine (const UsdStagePtr &stage, const SdfPath &path, const GusdContext &ctxt, const GT_PrimitiveHandle &sourcePrim)
 Create a new USD prim to match GT primitive. More...
 
virtual bool updateFromGTPrim (const GT_PrimitiveHandle &sourcePrim, const UT_Matrix4D &houXform, const GusdContext &ctxt, GusdSimpleXformCache &xformCache)
 
virtual void addLeadingBookend (double curFrame, double startFrame)
 
virtual void addTrailingBookend (double curFrame)
 Add a sample at the current frame, invising this from. More...
 
void markVisible (bool in)
 Keep track of the visibility state of the prim for book marks. More...
 
bool isVisible () const
 
virtual void setVisibility (const TfToken &visibility, UsdTimeCode time)
 
void loadPrimvars (const UsdPrimDefinition &prim_defn, UsdTimeCode time, const GT_RefineParms *rparms, int minUniform, int minPoint, int minVertex, const std::string &primPath, GT_AttributeListHandle *vertex, GT_AttributeListHandle *point, GT_AttributeListHandle *primitive, GT_AttributeListHandle *constant, const GT_DataArrayHandle &remapIndicies=GT_DataArrayHandle()) const
 
- Public Member Functions inherited from GT_Primitive
 GT_Primitive ()
 
 GT_Primitive (const GT_Primitive &src)
 
virtual ~GT_Primitive ()
 
virtual const char * className () const =0
 
virtual int getPrimitiveType () const
 
virtual bool getUniqueID (int64 &id) const
 
virtual void enlargeBounds (UT_BoundingBox boxes[], int nsegments) const =0
 
virtual void enlargeRenderBounds (UT_BoundingBox boxes[], int nsegments) const
 
virtual void getVelocityRange (UT_Vector3 &min, UT_Vector3 &max, const UT_StringRef &attribute_name=GA_Names::v) const
 
virtual bool refine (GT_Refine &refiner, const GT_RefineParms *parms=NULL) const
 
virtual int getMotionSegments () const =0
 
virtual int64 getMemoryUsage () const =0
 
const GT_TransformHandlegetPrimitiveTransform () const
 
void setPrimitiveTransform (const GT_TransformHandle &x)
 Set the transform for a the primitive. More...
 
GT_PrimitiveHandle clone () const
 
virtual bool hasDataArray (const UT_StringRef &name, GT_Owner owner_scope[], int num_owners, GT_Storage *storage=NULL, GT_Size *tuple_size=NULL) const
 
virtual bool updateGeoPrim (const GU_ConstDetailHandle &dtl, const GT_RefineParms &parms)
 update any cached data for geometry and its attributes More...
 
void setStaticGeometry (bool static_geo)
 Return true if the primitive represents geometry at frame 'fr'. More...
 
bool isStaticGeometry () const
 
bool isFrameInfoAvailable () const
 
bool getDataIdHash (int64 &hash, int segment=0, bool cache_data_id=false) const
 
virtual bool getTopologyVersion (int64 &version) const
 Returns the topology version for the primitive. More...
 
GT_DataArrayHandle findAttribute (const UT_StringRef &name, GT_Owner &owner, int segment) const
 
void dumpAttributeLists (const char *label, bool data_too) const
 print out all attribute lists More...
 
void dumpPrimitive () const
 
bool saveAttributeLists (UT_JSONWriter &w) const
 
virtual bool save (UT_JSONWriter &w) const
 
virtual const
GT_ViewportRefineOptions
viewportRefineOptions () const
 
GT_PrimitiveHandle harden () const
 
GT_PrimitiveHandle copyTransformed (const GT_TransformHandle &x, bool force=false) const
 
void refineCopyTransformFrom (const GT_Primitive &src)
 
GT_PrimitiveHandle attributeMerge (const GT_Primitive &src, const UT_StringMMPattern *vertex_pattern, const UT_StringMMPattern *point_pattern, const UT_StringMMPattern *uniform_pattern, const UT_StringMMPattern *detail_pattern) const
 
virtual GT_PrimitiveHandle doHarden () const
 
virtual GT_PrimitiveHandle doSoftCopy () const =0
 
virtual GT_PrimitiveHandle doAttributeMerge (const GT_Primitive &src, const UT_StringMMPattern *vertex, const UT_StringMMPattern *point, const UT_StringMMPattern *uniform, const UT_StringMMPattern *detail) const
 The virtual implementation of attribute merging. More...
 
bool enlargeWidth (UT_BoundingBox boxes[], int nsegments, fpreal defwidth=-1) const
 
virtual const
GT_AttributeListHandle
getPointAttributes () const
 
virtual const
GT_AttributeListHandle
getVertexAttributes () const
 
virtual const
GT_AttributeListHandle
getUniformAttributes () const
 
virtual const
GT_AttributeListHandle
getDetailAttributes () const
 
const GT_AttributeListHandlegetAttributeList (GT_Owner owner) const
 
virtual const GT_DataArrayHandlegetVertexList () const
 
virtual GT_DataArrayHandle createPointNormals (int segment=0, const UT_StringRef &P=GA_Names::P, bool normalize=true, const fpreal32 *pntdata=NULL, GT_Storage store=GT_STORE_REAL32) const
 
virtual fpreal computePerimeter (int seg=0) const
 
virtual fpreal computeSurfaceArea (int seg=0) const
 
virtual fpreal computeVolume (const UT_Vector3 &ref_P, int seg=0) const
 
- Public Member Functions inherited from UT_IntrusiveRefCounter< GT_Primitive >
SYS_FORCE_INLINE UT_IntrusiveRefCounter () noexcept
 Default constructor: Sets counter to 0. More...
 
SYS_FORCE_INLINE UT_IntrusiveRefCounter (const UT_IntrusiveRefCounter &) noexcept
 Copy constructor: Sets counter to 0. More...
 
UT_IntrusiveRefCounteroperator= (const UT_IntrusiveRefCounter &) noexcept
 Assignment operator: Does not modify counter. More...
 
SYS_FORCE_INLINE uint32 use_count () const noexcept
 Return current counter. More...
 
SYS_FORCE_INLINE bool conditionalAddRef () noexcept
 

Static Public Member Functions

static GT_PrimitiveHandle defineForWrite (const GT_PrimitiveHandle &sourcePrim, const UsdStagePtr &stage, const SdfPath &path, const GusdContext &ctxt)
 Given a GT_Primitive, create a USD prim of the proper type. More...
 
static bool getPrimName (const GT_PrimitiveHandle &sourcePrim, std::string &primName)
 
static const char * getUsdName (int gtPrimId)
 
static bool isGroupType (int gtPrimId)
 
static GT_PrimitiveHandle defineForRead (const UsdGeomImageable &sourcePrim, UsdTimeCode time, GusdPurposeSet purposes)
 Given a USD prim, create a GusdPrimWrapper of the proper type. More...
 
static bool isPointInstancerPrim (const GT_PrimitiveHandle &prim, const GusdContext &ctxt)
 Is this gt prim a point instancer? More...
 
static bool registerPrimDefinitionFuncForWrite (int gtPrimId, DefinitionForWriteFunction function, GetPrimNameFunction getNameFunction=NULL, bool isGroupType=false, const char *usdName=NULL)
 
static bool registerPrimDefinitionFuncForRead (const TfToken &usdTypeName, DefinitionForReadFunction function)
 Register function for creating new GusdPrimWrappers from USD prim. More...
 
static bool isGTPrimSupported (const GT_PrimitiveHandle &prim)
 
static GT_DataArrayHandle convertPrimvarData (const UsdGeomPrimvar &primvar, UsdTimeCode time)
 
static GT_DataArrayHandle convertAttributeData (const UsdAttribute &attr, const VtValue &val)
 
static void loadSubsets (const UsdGeomImageable &prim, GT_FaceSetMapPtr &facesets, GT_AttributeListHandle &uniform_attribs, const GT_RefineParms *parms, const int numFaces, UsdTimeCode time)
 
- Static Public Member Functions inherited from GT_Primitive
static int createPrimitiveTypeId ()
 
static GT_AttributeListHandle mergeAttributeLists (bool &changed, const GT_AttributeListHandle &src, const GT_AttributeListHandle &merge, const UT_StringMMPattern *pattern, const UT_StringMMPattern *alternate=NULL)
 
static bool computeVelocityRange (UT_Vector3 &vmin, UT_Vector3 &vmax, const GT_DataArrayHandle &v)
 
static GT_PrimitiveHandle refineDetail (const GU_ConstDetailHandle &detail, const GT_RefineParms *parms)
 
static GT_PrimitiveHandle refinePrimitive (const GT_PrimitiveHandle &primh, const GT_RefineParms *parms)
 
static voidoperator new (size_t size)
 
static voidoperator new (size_t size, void *p)
 
static void operator delete (void *p, size_t size)
 

Static Public Attributes

static std::map< GT_Owner,
TfToken
s_ownerToUsdInterp
 
static std::map< GT_Owner,
TfToken
s_ownerToUsdInterpCurve
 

Protected Types

typedef std::pair< GT_Owner,
std::string
AttrLastValueKeyType
 
typedef UT_Map
< AttrLastValueKeyType,
AttrLastValueEntry
AttrLastValueDict
 

Protected Member Functions

void updateVisibilityFromGTPrim (const GT_PrimitiveHandle &sourcePrim, UsdTimeCode time, bool forceWrite=true)
 
void updateActiveFromGTPrim (const GT_PrimitiveHandle &sourcePrim, UsdTimeCode time)
 
void updateTransformFromGTPrim (const GfMatrix4d &xform, UsdTimeCode time, bool force)
 
bool updateAttributeFromGTPrim (GT_Owner owner, const std::string &name, const GT_DataArrayHandle &houAttr, UsdAttribute &usdAttr, UsdTimeCode time)
 
bool updatePrimvarFromGTPrim (const TfToken &name, const GT_Owner &owner, const TfToken &interpolation, UsdTimeCode time, const GT_DataArrayHandle &data)
 
bool updatePrimvarFromGTPrim (const GT_AttributeListHandle &gtAttrs, const GusdGT_AttrFilter &primvarFilter, const TfToken &interpolation, UsdTimeCode time)
 Write primvar values from a GT attribute list to USD. More...
 
void clearCaches ()
 
- Protected Member Functions inherited from GT_Primitive
void enlargeP (UT_BoundingBox &box, const GT_AttributeListHandle &list, int segment) const
 
void enlargeP (UT_BoundingBox &B, const GT_DataArrayHandle &P) const
 Convenience method to enlarge a bounding box given a position attribute. More...
 
void enlargePw (UT_BoundingBox &B, const GT_DataArrayHandle &P) const
 
- Protected Member Functions inherited from UT_IntrusiveRefCounter< GT_Primitive >
SYS_FORCE_INLINE ~UT_IntrusiveRefCounter ()
 Destructor: Only derived classes can destruct this. More...
 

Static Protected Member Functions

static GfMatrix4d computeTransform (const UsdPrim &prim, UsdTimeCode time, const UT_Matrix4D &houXform, const GusdSimpleXformCache &xformCache)
 

Protected Attributes

UsdTimeCode m_time
 
GusdPurposeSet m_purposes
 
bool m_visible
 
GfMatrix4d m_xformCache
 
UsdTimeCode m_lastXformSet
 
UsdTimeCode m_lastXformCompared
 
AttrLastValueDict m_lastAttrValueDict
 

Detailed Description

A GT_Primitive that wraps a USD Prim.

A GusdPrimWrapper is responsible for copying attribute data between USD and GT.

To write USD geometry, the following steps are taken:

The ROP uses GusdRefiner to refine the cooked geometry to GT primitive types that have a matching USD type.

For each GT primitive we create a primWrapper by calling the defineForWrite method. This will create a usd prim on the current stage.

On each frame updateFromGTPrim is called to copy attribtutes from the GT prim to the USD prim.

We support: Writing a sequence of frames from one process. Writing each frame of a sequence to a seperate file from a seperate process. Writing each frame of a sequence to a seperate file from one process.

When writing all frames to a single file, we try and compress attribtute values. The data we need to do this compression is kept in the prim wrapper.

In the rare case where we want to sequentially write a sequence to per frame files, we need the primWrapper to persist across the sequence so we can do the attribute compression. However, we need to create the USD prim on each per frame file. The "redefine" method is used for this.

To read USD geometry we start with a GusdGU_PackedUSD prim. A GusdGT_PrimCollect object has been registered to convert these prims to GT_Primitives for drawing in the view port. This object will call the "fullGT" method of the GU prim which in turn calls the "defineForRead" to create a GusdPrimWrapper. These prims can be refined into native GT_Primitives that the viewport can draw.

Definition at line 89 of file primWrapper.h.

Member Typedef Documentation

Definition at line 352 of file primWrapper.h.

Constructor & Destructor Documentation

GusdPrimWrapper::GusdPrimWrapper ( )
GusdPrimWrapper::GusdPrimWrapper ( const UsdTimeCode time,
const GusdPurposeSet purposes 
)
GusdPrimWrapper::GusdPrimWrapper ( const GusdPrimWrapper in)
GusdPrimWrapper::~GusdPrimWrapper ( )
override

Member Function Documentation

virtual void GusdPrimWrapper::addLeadingBookend ( double  curFrame,
double  startFrame 
)
virtual

Add a sample just before the current time that invises this prim. For points and instances this means writing a empty point attribute. Other prims set their visibility flag. It might be possible to avoid this if we are on the first frame.

virtual void GusdPrimWrapper::addTrailingBookend ( double  curFrame)
virtual

Add a sample at the current frame, invising this from.

void GusdPrimWrapper::clearCaches ( )
protected
static GfMatrix4d GusdPrimWrapper::computeTransform ( const UsdPrim prim,
UsdTimeCode  time,
const UT_Matrix4D houXform,
const GusdSimpleXformCache xformCache 
)
staticprotected

Compute a USD transform from a Houdini transform.

houXform is the transform from world to the prim's space in Houdini. This includes the object node transformation and the transform of any containing packed prim.

xformCache is a map of the transforms of any groups that have been written on the current frame.

static GT_DataArrayHandle GusdPrimWrapper::convertAttributeData ( const UsdAttribute attr,
const VtValue val 
)
static
static GT_DataArrayHandle GusdPrimWrapper::convertPrimvarData ( const UsdGeomPrimvar primvar,
UsdTimeCode  time 
)
static
static GT_PrimitiveHandle GusdPrimWrapper::defineForRead ( const UsdGeomImageable sourcePrim,
UsdTimeCode  time,
GusdPurposeSet  purposes 
)
static

Given a USD prim, create a GusdPrimWrapper of the proper type.

When reading a USD file, we call this function to create a Gusd_GTPrimitive for each USD prim, we then refine that to something that can be used in a detail.

static GT_PrimitiveHandle GusdPrimWrapper::defineForWrite ( const GT_PrimitiveHandle sourcePrim,
const UsdStagePtr &  stage,
const SdfPath path,
const GusdContext ctxt 
)
static

Given a GT_Primitive, create a USD prim of the proper type.

When writing a USD file, we refine the geometry to a set of prims that we can deal with then we call this method on each of those prims.

static bool GusdPrimWrapper::getPrimName ( const GT_PrimitiveHandle sourcePrim,
std::string primName 
)
static

If prim type can generate a useful name for a prim, sets primName and returns true. So far only F3D volumes do this. They can derive a name from meta data stored in the f3d file.

static const char* GusdPrimWrapper::getUsdName ( int  gtPrimId)
static
static bool GusdPrimWrapper::isGroupType ( int  gtPrimId)
static
static bool GusdPrimWrapper::isGTPrimSupported ( const GT_PrimitiveHandle prim)
static

Return true is the give prim can be supported directly in USD. This is used by the refiner to know when to stop refining.

static bool GusdPrimWrapper::isPointInstancerPrim ( const GT_PrimitiveHandle prim,
const GusdContext ctxt 
)
static

Is this gt prim a point instancer?

This is used to know if we need to write the instance prototypes.

bool GusdPrimWrapper::isVisible ( ) const
inline

Definition at line 230 of file primWrapper.h.

void GusdPrimWrapper::loadPrimvars ( const UsdPrimDefinition prim_defn,
UsdTimeCode  time,
const GT_RefineParms rparms,
int  minUniform,
int  minPoint,
int  minVertex,
const std::string primPath,
GT_AttributeListHandle vertex,
GT_AttributeListHandle point,
GT_AttributeListHandle primitive,
GT_AttributeListHandle constant,
const GT_DataArrayHandle remapIndicies = GT_DataArrayHandle() 
) const

Load primvars for prim from USD. remapIndicies is used to expand curve primvars into point attributes if needed.

static void GusdPrimWrapper::loadSubsets ( const UsdGeomImageable prim,
GT_FaceSetMapPtr facesets,
GT_AttributeListHandle uniform_attribs,
const GT_RefineParms parms,
const int  numFaces,
UsdTimeCode  time 
)
static

Import geometry subsets as either partition attributes or primitive groups.

void GusdPrimWrapper::markVisible ( bool  in)
inline

Keep track of the visibility state of the prim for book marks.

Definition at line 229 of file primWrapper.h.

virtual bool GusdPrimWrapper::redefine ( const UsdStagePtr &  stage,
const SdfPath path,
const GusdContext ctxt,
const GT_PrimitiveHandle sourcePrim 
)
virtual

Create a new USD prim to match GT primitive.

When writing per frame USD files, we need to recreate the stage and all the primitives on it each frame. However, there is some data we want to persist across frames. So we keep the GusdPrimWrappers and ask them to redefine their USD prims on each frame.

Reimplemented in GusdXformWrapper, GusdMeshWrapper, GusdInstancerWrapper, GusdPointsWrapper, GusdScopeWrapper, GusdCurvesWrapper, GusdNURBSCurvesWrapper, and GusdPackedUsdWrapper.

static bool GusdPrimWrapper::registerPrimDefinitionFuncForRead ( const TfToken usdTypeName,
DefinitionForReadFunction  function 
)
static

Register function for creating new GusdPrimWrappers from USD prim.

static bool GusdPrimWrapper::registerPrimDefinitionFuncForWrite ( int  gtPrimId,
DefinitionForWriteFunction  function,
GetPrimNameFunction  getNameFunction = NULL,
bool  isGroupType = false,
const char *  usdName = NULL 
)
static

Register function for creating new USD prims from GT_Primitives and, optionally, a function for giving these prims a name.

virtual void GusdPrimWrapper::setVisibility ( const TfToken visibility,
UsdTimeCode  time 
)
virtual
virtual bool GusdPrimWrapper::unpack ( UT_Array< GU_DetailHandle > &  details,
const UT_StringRef fileName,
const SdfPath primPath,
const UT_Matrix4D xform,
fpreal  frame,
const char *  viewportLod,
GusdPurposeSet  purposes,
const GT_RefineParms rparms 
) const
virtual
void GusdPrimWrapper::updateActiveFromGTPrim ( const GT_PrimitiveHandle sourcePrim,
UsdTimeCode  time 
)
protected

Look for a "usdactive" attribute on sourcePrim. UsdPrim::SetActive based on this value. If attribute doesn't exist, do nothing.

bool GusdPrimWrapper::updateAttributeFromGTPrim ( GT_Owner  owner,
const std::string name,
const GT_DataArrayHandle houAttr,
UsdAttribute usdAttr,
UsdTimeCode  time 
)
protected
virtual bool GusdPrimWrapper::updateFromGTPrim ( const GT_PrimitiveHandle sourcePrim,
const UT_Matrix4D houXform,
const GusdContext ctxt,
GusdSimpleXformCache xformCache 
)
virtual

Fill a USD prim's attribute samples for a frame from the attributes in a GT primitive.

If sourcePrim is an instance, localXform is the instance transform otherwise it is the primitive transform from the prim.

Reimplemented in GusdXformWrapper, GusdMeshWrapper, GusdInstancerWrapper, GusdPointsWrapper, GusdScopeWrapper, GusdCurvesWrapper, GusdNURBSCurvesWrapper, and GusdPackedUsdWrapper.

bool GusdPrimWrapper::updatePrimvarFromGTPrim ( const TfToken name,
const GT_Owner owner,
const TfToken interpolation,
UsdTimeCode  time,
const GT_DataArrayHandle data 
)
protected
bool GusdPrimWrapper::updatePrimvarFromGTPrim ( const GT_AttributeListHandle gtAttrs,
const GusdGT_AttrFilter primvarFilter,
const TfToken interpolation,
UsdTimeCode  time 
)
protected

Write primvar values from a GT attribute list to USD.

void GusdPrimWrapper::updateTransformFromGTPrim ( const GfMatrix4d xform,
UsdTimeCode  time,
bool  force 
)
protected
void GusdPrimWrapper::updateVisibilityFromGTPrim ( const GT_PrimitiveHandle sourcePrim,
UsdTimeCode  time,
bool  forceWrite = true 
)
protected

Look for "visible" attribute on sourcePrim. If it doesn't exist set a visibility sample based on isVisible()

Member Data Documentation

AttrLastValueDict GusdPrimWrapper::m_lastAttrValueDict
mutableprotected

Definition at line 355 of file primWrapper.h.

UsdTimeCode GusdPrimWrapper::m_lastXformCompared
protected

Definition at line 334 of file primWrapper.h.

UsdTimeCode GusdPrimWrapper::m_lastXformSet
protected

Definition at line 333 of file primWrapper.h.

GusdPurposeSet GusdPrimWrapper::m_purposes
protected

Definition at line 325 of file primWrapper.h.

UsdTimeCode GusdPrimWrapper::m_time
protected

Definition at line 324 of file primWrapper.h.

bool GusdPrimWrapper::m_visible
protected

Definition at line 327 of file primWrapper.h.

GfMatrix4d GusdPrimWrapper::m_xformCache
protected

Definition at line 332 of file primWrapper.h.

std::map<GT_Owner, TfToken> GusdPrimWrapper::s_ownerToUsdInterp
static

Definition at line 269 of file primWrapper.h.

std::map<GT_Owner, TfToken> GusdPrimWrapper::s_ownerToUsdInterpCurve
static

Definition at line 270 of file primWrapper.h.


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