Skip to content

Commit

Permalink
[Usd] Add load option to stage creation functions.
Browse files Browse the repository at this point in the history
  • Loading branch information
superfunc committed Jan 28, 2018
1 parent 8804e9c commit 55ce920
Show file tree
Hide file tree
Showing 3 changed files with 103 additions and 54 deletions.
46 changes: 28 additions & 18 deletions pxr/usd/lib/usd/stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -648,107 +648,117 @@ _CreateNewLayer(const std::string &identifier)

/* static */
UsdStageRefPtr
UsdStage::CreateNew(const std::string& identifier)
UsdStage::CreateNew(const std::string& identifier,
InitialLoadSet load)
{
TfAutoMallocTag2 tag("Usd", _StageTag(identifier));

if (SdfLayerRefPtr layer = _CreateNewLayer(identifier))
return Open(layer, _CreateAnonymousSessionLayer(layer));
return Open(layer, _CreateAnonymousSessionLayer(layer), load);
return TfNullPtr;
}

/* static */
UsdStageRefPtr
UsdStage::CreateNew(const std::string& identifier,
const SdfLayerHandle& sessionLayer)
const SdfLayerHandle& sessionLayer,
InitialLoadSet load)
{
TfAutoMallocTag2 tag("Usd", _StageTag(identifier));

if (SdfLayerRefPtr layer = _CreateNewLayer(identifier))
return Open(layer, sessionLayer);
return Open(layer, sessionLayer, load);
return TfNullPtr;
}

/* static */
UsdStageRefPtr
UsdStage::CreateNew(const std::string& identifier,
const ArResolverContext& pathResolverContext)
const ArResolverContext& pathResolverContext,
InitialLoadSet load)
{
TfAutoMallocTag2 tag("Usd", _StageTag(identifier));

if (SdfLayerRefPtr layer = _CreateNewLayer(identifier))
return Open(layer, pathResolverContext);
return Open(layer, pathResolverContext, load);
return TfNullPtr;
}

/* static */
UsdStageRefPtr
UsdStage::CreateNew(const std::string& identifier,
const SdfLayerHandle& sessionLayer,
const ArResolverContext& pathResolverContext)
const ArResolverContext& pathResolverContext,
InitialLoadSet load)
{
TfAutoMallocTag2 tag("Usd", _StageTag(identifier));

if (SdfLayerRefPtr layer = _CreateNewLayer(identifier))
return Open(layer, sessionLayer, pathResolverContext);
return Open(layer, sessionLayer, pathResolverContext, load);
return TfNullPtr;
}

/* static */
UsdStageRefPtr
UsdStage::CreateInMemory()
UsdStage::CreateInMemory(InitialLoadSet load)
{
// Use usda file format if an identifier was not provided.
//
// In regards to "tmp.usda" below, SdfLayer::CreateAnonymous always
// prefixes the identifier with the layer's address in memory, so using the
// same identifier multiple times still produces unique layers.
return CreateInMemory("tmp.usda");
return CreateInMemory("tmp.usda", load);
}

/* static */
UsdStageRefPtr
UsdStage::CreateInMemory(const std::string& identifier)
UsdStage::CreateInMemory(const std::string& identifier,
InitialLoadSet load)
{
return Open(SdfLayer::CreateAnonymous(identifier));
return Open(SdfLayer::CreateAnonymous(identifier), load);
}

/* static */
UsdStageRefPtr
UsdStage::CreateInMemory(const std::string& identifier,
const ArResolverContext& pathResolverContext)
const ArResolverContext& pathResolverContext,
InitialLoadSet load)
{
// CreateAnonymous() will transform 'identifier', so don't bother
// using it as a tag
TfAutoMallocTag tag("Usd");

return Open(SdfLayer::CreateAnonymous(identifier), pathResolverContext);
return Open(SdfLayer::CreateAnonymous(identifier),
pathResolverContext, load);
}

/* static */
UsdStageRefPtr
UsdStage::CreateInMemory(const std::string& identifier,
const SdfLayerHandle &sessionLayer)
const SdfLayerHandle &sessionLayer,
InitialLoadSet load)
{
// CreateAnonymous() will transform 'identifier', so don't bother
// using it as a tag
TfAutoMallocTag tag("Usd");

return Open(SdfLayer::CreateAnonymous(identifier), sessionLayer);
return Open(SdfLayer::CreateAnonymous(identifier),
sessionLayer, load);
}

/* static */
UsdStageRefPtr
UsdStage::CreateInMemory(const std::string& identifier,
const SdfLayerHandle &sessionLayer,
const ArResolverContext& pathResolverContext)
const ArResolverContext& pathResolverContext,
InitialLoadSet load)
{
// CreateAnonymous() will transform 'identifier', so don't bother
// using it as a tag
TfAutoMallocTag tag("Usd");

return Open(SdfLayer::CreateAnonymous(identifier),
sessionLayer, pathResolverContext);
sessionLayer, pathResolverContext, load);
}

static
Expand Down
51 changes: 33 additions & 18 deletions pxr/usd/lib/usd/stage.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,16 @@ class UsdStage : public TfRefBase, public TfWeakBase {
/// \name Lifetime Management
/// @{
// --------------------------------------------------------------------- //

/// \enum InitialLoadSet
///
/// Specifies the initial set of prims to load when opening a UsdStage.
///
enum InitialLoadSet
{
LoadAll, ///< Load all loadable prims
LoadNone ///< Load no loadable prims
};

/// Create a new stage with root layer \p identifier, destroying
/// potentially existing files with that identifer; it is considered an
Expand All @@ -157,6 +167,9 @@ class UsdStage : public TfRefBase, public TfWeakBase {
/// create a stage with an anonymous in-memory session layer. To create a
/// stage without a session layer, pass TfNullPtr (or None in python) as the
/// \p sessionLayer argument.
//
/// The initial set of prims to load on the stage can be specified
/// using the \p load parameter. \sa UsdStage::InitialLoadSet.
///
/// Note that the \p pathResolverContext passed here will apply to all path
/// resolutions for this stage, regardless of what other context may be
Expand All @@ -166,23 +179,27 @@ class UsdStage : public TfRefBase, public TfWeakBase {
/// path.
USD_API
static UsdStageRefPtr
CreateNew(const std::string& identifier);
CreateNew(const std::string& identifier,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateNew(const std::string& identifier,
const SdfLayerHandle& sessionLayer);
const SdfLayerHandle& sessionLayer,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateNew(const std::string& identifier,
const SdfLayerHandle& sessionLayer,
const ArResolverContext& pathResolverContext);
const ArResolverContext& pathResolverContext,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateNew(const std::string& identifier,
const ArResolverContext& pathResolverContext);
const ArResolverContext& pathResolverContext,
InitialLoadSet load = LoadAll);

/// Creates a new stage only in memory, analogous to creating an
/// anonymous SdfLayer.
Expand All @@ -192,43 +209,41 @@ class UsdStage : public TfRefBase, public TfWeakBase {
/// bound at resolve time. If no context is passed in here, Usd will create
/// one by calling \sa ArResolver::CreateDefaultContext.
///
/// The initial set of prims to load on the stage can be specified
/// using the \p load parameter. \sa UsdStage::InitialLoadSet.
///
/// Invoking an overload that does not take a \p sessionLayer argument will
/// create a stage with an anonymous in-memory session layer. To create a
/// stage without a session layer, pass TfNullPtr (or None in python) as the
/// \p sessionLayer argument.
USD_API
static UsdStageRefPtr
CreateInMemory();
CreateInMemory(InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateInMemory(const std::string& identifier);
CreateInMemory(const std::string& identifier,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateInMemory(const std::string& identifier,
const ArResolverContext& pathResolverContext);
const ArResolverContext& pathResolverContext,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateInMemory(const std::string& identifier,
const SdfLayerHandle &sessionLayer);
const SdfLayerHandle &sessionLayer,
InitialLoadSet load = LoadAll);
/// \overload
USD_API
static UsdStageRefPtr
CreateInMemory(const std::string& identifier,
const SdfLayerHandle &sessionLayer,
const ArResolverContext& pathResolverContext);
const ArResolverContext& pathResolverContext,
InitialLoadSet load = LoadAll);

/// \enum InitialLoadSet
///
/// Specifies the initial set of prims to load when opening a UsdStage.
///
enum InitialLoadSet
{
LoadAll, ///< Load all loadable prims
LoadNone ///< Load no loadable prims
};

/// Attempt to find a matching existing stage in a cache if
/// UsdStageCacheContext objects exist on the stack. Failing that, create a
Expand Down
60 changes: 42 additions & 18 deletions pxr/usd/lib/usd/wrapStage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,56 +197,80 @@ void wrapUsdStage()
.def(TfPyRefAndWeakPtr())
.def("__repr__", __repr__)

.def("CreateNew", (UsdStageRefPtr (*)(const string &))
.def("CreateNew", (UsdStageRefPtr (*)(const string &,
UsdStage::InitialLoadSet))
&UsdStage::CreateNew,
(arg("identifier")),
(arg("identifier"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateNew", (UsdStageRefPtr (*)(const string &,
const SdfLayerHandle &))
const SdfLayerHandle &,
UsdStage::InitialLoadSet))
&UsdStage::CreateNew,
(arg("identifier"), arg("sessionLayer")),
(arg("identifier"),
arg("sessionLayer"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateNew", (UsdStageRefPtr (*)(const string &,
const ArResolverContext &))
const ArResolverContext &,
UsdStage::InitialLoadSet))
&UsdStage::CreateNew,
(arg("identifier"), arg("pathResolverContext")),
(arg("identifier"),
arg("pathResolverContext"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateNew", (UsdStageRefPtr (*)(const string &,
const SdfLayerHandle &,
const ArResolverContext &))
const ArResolverContext &,
UsdStage::InitialLoadSet))
&UsdStage::CreateNew,
(arg("identifier"), arg("sessionLayer"),
arg("pathResolverContext")),
(arg("identifier"),
arg("sessionLayer"),
arg("pathResolverContext"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.staticmethod("CreateNew")

.def("CreateInMemory", (UsdStageRefPtr (*)())
.def("CreateInMemory", (UsdStageRefPtr (*)(
UsdStage::InitialLoadSet))
&UsdStage::CreateInMemory,
(arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateInMemory", (UsdStageRefPtr (*)(const string &))
.def("CreateInMemory", (UsdStageRefPtr (*)(
const string &,
UsdStage::InitialLoadSet))
&UsdStage::CreateInMemory,
(arg("identifier")),
(arg("identifier"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateInMemory", (UsdStageRefPtr (*)(
const string &,
const ArResolverContext &))
const ArResolverContext &,
UsdStage::InitialLoadSet))
&UsdStage::CreateInMemory,
(arg("identifier"), arg("pathResolverContext")),
(arg("identifier"),
arg("pathResolverContext"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateInMemory", (UsdStageRefPtr (*)(
const string &,
const SdfLayerHandle &))
const SdfLayerHandle &,
UsdStage::InitialLoadSet))
&UsdStage::CreateInMemory,
(arg("identifier"), arg("sessionLayer")),
(arg("identifier"),
arg("sessionLayer"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.def("CreateInMemory", (UsdStageRefPtr (*)(
const string &,
const SdfLayerHandle &,
const ArResolverContext &))
const ArResolverContext &,
UsdStage::InitialLoadSet))
&UsdStage::CreateInMemory,
(arg("identifier"),
arg("sessionLayer"),
arg("pathResolverContext")),
arg("pathResolverContext"),
arg("load")=UsdStage::LoadAll),
return_value_policy<TfPyRefPtrFactory<> >())
.staticmethod("CreateInMemory")

Expand Down

0 comments on commit 55ce920

Please sign in to comment.