Skip to content

Commit

Permalink
Merge pull request #1619 from dj-mcg/pr/Allow_usdReader_registration_…
Browse files Browse the repository at this point in the history
…for_TfType_tokens

Pr/allow usd reader registration for tf type tokens
  • Loading branch information
seando-adsk authored Aug 23, 2021
2 parents c7c49f1 + bac2095 commit 7469e10
Show file tree
Hide file tree
Showing 8 changed files with 326 additions and 170 deletions.
23 changes: 9 additions & 14 deletions lib/mayaUsd/fileio/primReaderRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,19 +91,6 @@ struct UsdMayaPrimReaderRegistry
MAYAUSD_CORE_PUBLIC
static void RegisterRaw(const TfType& type, ReaderFn fn);

/// \brief Wraps \p fn in a ReaderFactoryFn and registers that factory
/// function as a reader provider for \p T.
/// This is a helper method for the macro PXRUSDMAYA_DEFINE_READER;
/// you probably want to use PXRUSDMAYA_DEFINE_READER directly instead.
template <typename T> static void RegisterRaw(ReaderFn fn)
{
if (TfType t = TfType::Find<T>()) {
RegisterRaw(t, fn);
} else {
TF_CODING_ERROR("Cannot register unknown TfType: %s.", ArchGetDemangled<T>().c_str());
}
}

// takes a usdType (i.e. prim.GetTypeName())
/// \brief Finds a reader factory if one exists for \p usdTypeName.
///
Expand All @@ -121,11 +108,19 @@ struct UsdMayaPrimReaderRegistry
static ReaderFactoryFn FindOrFallback(const TfToken& usdTypeName);
};

// Lookup TfType by name instead of static C++ type when
// registering prim reader functions. This allows readers to be
// registered for codeless schemas, which are declared in the
// TfType system but have no corresponding C++ code.
#define PXRUSDMAYA_DEFINE_READER(T, argsVarName, ctxVarName) \
static bool UsdMaya_PrimReader_##T(const UsdMayaPrimReaderArgs&, UsdMayaPrimReaderContext&); \
TF_REGISTRY_FUNCTION_WITH_TAG(UsdMayaPrimReaderRegistry, T) \
{ \
UsdMayaPrimReaderRegistry::RegisterRaw<T>(UsdMaya_PrimReader_##T); \
if (TfType t = TfType::FindByName(#T)) { \
UsdMayaPrimReaderRegistry::RegisterRaw(t, UsdMaya_PrimReader_##T); \
} else { \
TF_CODING_ERROR("Cannot register unknown TfType: %s.", #T); \
} \
} \
bool UsdMaya_PrimReader_##T( \
const UsdMayaPrimReaderArgs& argsVarName, UsdMayaPrimReaderContext& ctxVarName)
Expand Down
Loading

0 comments on commit 7469e10

Please sign in to comment.