Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache to USD dialog for Maya reference prim. #2054

Merged
merged 1 commit into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions lib/mayaUsd/fileio/fallbackPrimUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@

PXR_NAMESPACE_OPEN_SCOPE

FallbackPrimUpdater::FallbackPrimUpdater(const MFnDependencyNode& depNodeFn, const Ufe::Path& path)
: UsdMayaPrimUpdater(depNodeFn, path)
FallbackPrimUpdater::FallbackPrimUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path)
: UsdMayaPrimUpdater(context, depNodeFn, path)
{
}

Expand Down
5 changes: 4 additions & 1 deletion lib/mayaUsd/fileio/fallbackPrimUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ class FallbackPrimUpdater : public UsdMayaPrimUpdater
{
public:
MAYAUSD_CORE_PUBLIC
FallbackPrimUpdater(const MFnDependencyNode& depNodeFn, const Ufe::Path& path);
FallbackPrimUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path);

// clang errors if you use "= default" here, due to const SdfPath member
// see: http://open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#253
Expand Down
12 changes: 8 additions & 4 deletions lib/mayaUsd/fileio/primUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ using namespace MAYAUSD_NS_DEF;

PXR_NAMESPACE_OPEN_SCOPE

UsdMayaPrimUpdater::UsdMayaPrimUpdater(const MFnDependencyNode& depNodeFn, const Ufe::Path& path)
UsdMayaPrimUpdater::UsdMayaPrimUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path)
: _mayaObject(depNodeFn.object())
, _path(path)
, _context(&context)
{
}

Expand All @@ -73,9 +77,9 @@ bool UsdMayaPrimUpdater::canEditAsMaya() const
return (UsdMayaPrimReaderRegistry::Find(prim.GetTypeName()) != nullptr);
}

bool UsdMayaPrimUpdater::editAsMaya(const UsdMayaPrimUpdaterContext& context) { return true; }
bool UsdMayaPrimUpdater::editAsMaya() { return true; }

bool UsdMayaPrimUpdater::discardEdits(const UsdMayaPrimUpdaterContext& context)
bool UsdMayaPrimUpdater::discardEdits()
{
MObject objectToDelete = getMayaObject();
if (objectToDelete.isNull())
Expand All @@ -94,7 +98,7 @@ bool UsdMayaPrimUpdater::discardEdits(const UsdMayaPrimUpdaterContext& context)
return status == MS::kSuccess;
}

bool UsdMayaPrimUpdater::pushEnd(const UsdMayaPrimUpdaterContext& context)
bool UsdMayaPrimUpdater::pushEnd()
{
// Nothing. We rely on the PrimUpdaterManager to delete the nodes in the correct order.
return true;
Expand Down
17 changes: 13 additions & 4 deletions lib/mayaUsd/fileio/primUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ class UsdMayaPrimUpdater
{
public:
MAYAUSD_CORE_PUBLIC
UsdMayaPrimUpdater(const MFnDependencyNode& depNodeFn, const Ufe::Path& path);
UsdMayaPrimUpdater(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path);

// clang errors if you use "= default" here, due to const SdfPath member
// see: http://open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#253
Expand Down Expand Up @@ -91,17 +94,17 @@ class UsdMayaPrimUpdater
/// Customize the pulled prim after pull import. Default implementation in
/// this class is a no-op.
MAYAUSD_CORE_PUBLIC
virtual bool editAsMaya(const UsdMayaPrimUpdaterContext& context);
virtual bool editAsMaya();

/// Discard edits done in Maya. Implementation in this class removes the
/// Maya node.
MAYAUSD_CORE_PUBLIC
virtual bool discardEdits(const UsdMayaPrimUpdaterContext& context);
virtual bool discardEdits();

/// Clean up Maya data model at end of push. Implementation in this class
/// calls discardEdits().
MAYAUSD_CORE_PUBLIC
virtual bool pushEnd(const UsdMayaPrimUpdaterContext& context);
virtual bool pushEnd();

/// The MObject for the Maya node being updated by this updater.
MAYAUSD_CORE_PUBLIC
Expand All @@ -115,6 +118,9 @@ class UsdMayaPrimUpdater
MAYAUSD_CORE_PUBLIC
UsdPrim getUsdPrim() const;

MAYAUSD_CORE_PUBLIC
const UsdMayaPrimUpdaterContext* getContext() const { return _context; }

MAYAUSD_CORE_PUBLIC
static bool isAnimated(const MDagPath& path);

Expand All @@ -126,6 +132,9 @@ class UsdMayaPrimUpdater

/// The proxy shape and destination Sdf path if provided.
const Ufe::Path _path;

/// Context giving access to the manager update state
const UsdMayaPrimUpdaterContext* _context { nullptr };
};

using UsdMayaPrimUpdaterSharedPtr = std::shared_ptr<UsdMayaPrimUpdater>;
Expand Down
35 changes: 23 additions & 12 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,13 +428,13 @@ bool pullCustomize(const PullImportPaths& importedPaths, const UsdMayaPrimUpdate

auto registryItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(mayaTypeName);
auto factory = std::get<UsdMayaPrimUpdaterRegistry::UpdaterFactoryFn>(registryItem);
auto updater = factory(dgNodeFn, pulledUfePath);
auto updater = factory(context, dgNodeFn, pulledUfePath);

// The failure of a single updater causes failure of the whole
// customization step. This is a frequent difficulty for operations on
// multiple data, especially since we can't roll back the result of
// the execution of previous updaters. Revisit this. PPT, 15-Sep-2021.
if (!updater->editAsMaya(context)) {
if (!updater->editAsMaya()) {
return false;
}
}
Expand Down Expand Up @@ -576,7 +576,7 @@ UsdMayaPrimUpdaterSharedPtr createUpdater(
auto mayaDagPath = context.MapSdfPathToDagPath(srcPath);
MFnDependencyNode depNodeFn(mayaDagPath.isValid() ? mayaDagPath.node() : MObject());

return factory(depNodeFn, ufePath);
return factory(context, depNodeFn, ufePath);
}

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -673,7 +673,7 @@ bool pushCustomize(
}

// Report pushEnd() failure.
if (!updater->pushEnd(context)) {
if (!updater->pushEnd()) {
throw MayaUsd::TraversalFailure(std::string("PushEnd() failed."), srcPath);
}
};
Expand Down Expand Up @@ -840,7 +840,9 @@ bool PrimUpdaterManager::mergeToUsd(
}
}

auto ufeUsdItem = Ufe::Hierarchy::createItem(pulledPath);
// Some updaters (like MayaReference) may be writing and changing the variant during merge.
// This will change the hierarchy around pulled prim. Grab hierarchy from the parent.
auto ufeUsdItem = Ufe::Hierarchy::createItem(pulledPath.pop());
auto hier = Ufe::Hierarchy::hierarchy(ufeUsdItem);
if (TF_VERIFY(hier)) {
scene.notify(Ufe::SubtreeInvalidate(hier->defaultParent()));
Expand Down Expand Up @@ -918,11 +920,15 @@ bool PrimUpdaterManager::canEditAsMaya(const Ufe::Path& path) const
if (!prim) {
return false;
}

VtDictionary userArgs;
UsdMayaPrimUpdaterContext context(UsdTimeCode::Default(), prim.GetStage(), userArgs);

auto typeName = prim.GetTypeName();
auto regItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(typeName);
auto factory = std::get<UpdaterFactoryFn>(regItem);
// No Maya Dag path for the prim updater, so pass in a null MObject.
auto updater = factory(MFnDependencyNode(MObject()), path);
auto updater = factory(context, MFnDependencyNode(MObject()), path);
return updater ? updater->canEditAsMaya() : false;
}

Expand Down Expand Up @@ -971,9 +977,9 @@ bool PrimUpdaterManager::discardEdits(const Ufe::Path& pulledPath)

auto registryItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(mayaTypeName);
auto factory = std::get<UsdMayaPrimUpdaterRegistry::UpdaterFactoryFn>(registryItem);
auto updater = factory(dgNodeFn, Ufe::Path());
auto updater = factory(context, dgNodeFn, Ufe::Path());

updater->discardEdits(context);
updater->discardEdits();
}

FunctionUndoItem::execute(
Expand Down Expand Up @@ -1099,7 +1105,8 @@ void PrimUpdaterManager::onProxyContentChanged(

auto proxyShapeUfePath = proxyNotice.GetProxyShape().ufePath();

auto autoEditFn = [this, proxyShapeUfePath](const UsdPrim& prim) -> bool {
auto autoEditFn = [this, proxyShapeUfePath](
const UsdMayaPrimUpdaterContext& context, const UsdPrim& prim) -> bool {
TfToken typeName = prim.GetTypeName();

auto registryItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(typeName);
Expand All @@ -1113,7 +1120,7 @@ void PrimUpdaterManager::onProxyContentChanged(
const Ufe::Path path = proxyShapeUfePath + pathSegment;

auto factory = std::get<UpdaterFactoryFn>(registryItem);
auto updater = factory(MFnDependencyNode(MObject()), path);
auto updater = factory(context, MFnDependencyNode(MObject()), path);

if (updater && updater->shouldAutoEdit()) {
// TODO UNDO: is it okay to throw away the undo info in the change notification?
Expand All @@ -1131,6 +1138,10 @@ void PrimUpdaterManager::onProxyContentChanged(
Usd_PrimFlagsPredicate predicate = UsdPrimDefaultPredicate;

auto stage = notice.GetStage();

VtDictionary userArgs;
UsdMayaPrimUpdaterContext context(UsdTimeCode::Default(), stage, userArgs);

for (const auto& changedPath : notice.GetResyncedPaths()) {
if (changedPath == SdfPath::AbsoluteRootPath()) {
continue;
Expand All @@ -1141,7 +1152,7 @@ void PrimUpdaterManager::onProxyContentChanged(

for (auto it = range.begin(); it != range.end(); it++) {
const UsdPrim& prim = *it;
if (autoEditFn(prim)) {
if (autoEditFn(context, prim)) {
it.PruneChildren();
}
}
Expand All @@ -1153,7 +1164,7 @@ void PrimUpdaterManager::onProxyContentChanged(
const auto& changedPath = *it;
if (changedPath.IsPrimPropertyPath()) {
UsdPrim valueChangedPrim = stage->GetPrimAtPath(changedPath.GetPrimPath());
autoEditFn(valueChangedPrim);
autoEditFn(context, valueChangedPrim);
}
}
}
Expand Down
12 changes: 8 additions & 4 deletions lib/mayaUsd/fileio/primUpdaterRegistry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,10 @@ UsdMayaPrimUpdaterRegistry::FindOrFallback(const TfToken& usdTypeName)
// use fallback
ret = std::make_tuple(
UsdMayaPrimUpdater::Supports::All,
[](const MFnDependencyNode& depNodeFn, const Ufe::Path& path) {
return std::make_shared<FallbackPrimUpdater>(depNodeFn, path);
[](const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path) {
return std::make_shared<FallbackPrimUpdater>(context, depNodeFn, path);
});

_regTfType[typeName] = ret;
Expand All @@ -137,8 +139,10 @@ UsdMayaPrimUpdaterRegistry::FindOrFallback(const std::string& mayaTypeName)
// use fallback
ret = std::make_tuple(
UsdMayaPrimUpdater::Supports::All,
[](const MFnDependencyNode& depNodeFn, const Ufe::Path& path) {
return std::make_shared<FallbackPrimUpdater>(depNodeFn, path);
[](const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& depNodeFn,
const Ufe::Path& path) {
return std::make_shared<FallbackPrimUpdater>(context, depNodeFn, path);
});

_regMayaType[mayaTypeName] = ret;
Expand Down
12 changes: 8 additions & 4 deletions lib/mayaUsd/fileio/primUpdaterRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,10 @@ struct UsdMayaPrimUpdaterRegistry
{
/// Updater factory function, i.e. a function that creates a prim updater
/// for the given Maya node/USD paths and context.
using UpdaterFactoryFn
= std::function<UsdMayaPrimUpdaterSharedPtr(const MFnDependencyNode&, const Ufe::Path&)>;
using UpdaterFactoryFn = std::function<UsdMayaPrimUpdaterSharedPtr(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode&,
const Ufe::Path&)>;

using RegisterItem = std::tuple<UsdMayaPrimUpdater::Supports, UpdaterFactoryFn>;

Expand Down Expand Up @@ -155,8 +157,10 @@ struct UsdMayaPrimUpdaterRegistry
UsdMayaPrimUpdaterRegistry::Register<usdTypeName>( \
#mayaTypeName, \
supports, \
[](const MFnDependencyNode& depNodeFn, const Ufe::Path& path) { \
return std::make_shared<updaterClass>(depNodeFn, path); \
[](const UsdMayaPrimUpdaterContext& context, \
const MFnDependencyNode& depNodeFn, \
const Ufe::Path& path) { \
return std::make_shared<updaterClass>(context, depNodeFn, path); \
}); \
}

Expand Down
42 changes: 18 additions & 24 deletions lib/mayaUsd/python/wrapPrimUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,11 @@ class PrimUpdaterWrapper

PrimUpdaterWrapper() = default;

PrimUpdaterWrapper(const MFnDependencyNode& node, const Ufe::Path& path)
: UsdMayaPrimUpdater(node, path)
PrimUpdaterWrapper(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& node,
const Ufe::Path& path)
: UsdMayaPrimUpdater(context, node, path)
{
}

Expand Down Expand Up @@ -92,32 +95,20 @@ class PrimUpdaterWrapper
return this->CallVirtual<bool>("canEditAsMaya", &This::default_canEditAsMaya)();
}

bool default_editAsMaya(const UsdMayaPrimUpdaterContext& context)
bool default_editAsMaya() { return base_t::editAsMaya(); }
bool editAsMaya() override
{
return base_t::editAsMaya(context);
}
bool editAsMaya(const UsdMayaPrimUpdaterContext& context) override
{
return this->CallVirtual<bool>("editAsMaya", &This::default_editAsMaya)(context);
return this->CallVirtual<bool>("editAsMaya", &This::default_editAsMaya)();
}

bool default_discardEdits(const UsdMayaPrimUpdaterContext& context)
{
return base_t::discardEdits(context);
}
bool discardEdits(const UsdMayaPrimUpdaterContext& context) override
bool default_discardEdits() { return base_t::discardEdits(); }
bool discardEdits() override
{
return this->CallVirtual<bool>("discardEdits", &This::default_discardEdits)(context);
return this->CallVirtual<bool>("discardEdits", &This::default_discardEdits)();
}

bool default_pushEnd(const UsdMayaPrimUpdaterContext& context)
{
return base_t::pushEnd(context);
}
bool pushEnd(const UsdMayaPrimUpdaterContext& context) override
{
return this->CallVirtual<bool>("pushEnd", &This::default_pushEnd)(context);
}
bool default_pushEnd() { return base_t::pushEnd(); }
bool pushEnd() override { return this->CallVirtual<bool>("pushEnd", &This::default_pushEnd)(); }

//---------------------------------------------------------------------------------------------
/// \brief wraps a factory function that allows registering an updated Python class
Expand All @@ -128,14 +119,17 @@ class PrimUpdaterWrapper
// Instances of this class act as "function objects" that are fully compatible with the
// std::function requested by UsdMayaSchemaApiAdaptorRegistry::Register. These will create
// python wrappers based on the latest class registered.
UsdMayaPrimUpdaterSharedPtr operator()(const MFnDependencyNode& node, const Ufe::Path& path)
UsdMayaPrimUpdaterSharedPtr operator()(
const UsdMayaPrimUpdaterContext& context,
const MFnDependencyNode& node,
const Ufe::Path& path)
{
boost::python::object pyClass = GetPythonObject(_classIndex);
if (!pyClass) {
// Prototype was unregistered
return nullptr;
}
auto primUpdater = std::make_shared<This>(node, path);
auto primUpdater = std::make_shared<This>(context, node, path);
TfPyLock pyLock;
boost::python::object instance = pyClass((uintptr_t)&primUpdater);
boost::python::incref(instance.ptr());
Expand Down
13 changes: 13 additions & 0 deletions lib/mayaUsd/python/wrapUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#include <mayaUsd/fileio/jobs/jobArgs.h>
#include <mayaUsd/utils/util.h>

#include <pxr/base/tf/pyResultConversions.h>
Expand All @@ -31,11 +32,23 @@ namespace {
class UsdMayaUtilScope
{
};

VtDictionary getDictionaryFromEncodedOptions(const std::string& textOptions)
{
VtDictionary dictOptions;
auto status = UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
MString(textOptions.c_str()), &dictOptions, nullptr);
if (status != MS::kSuccess)
return VtDictionary();
return dictOptions;
}

} // namespace

void wrapUtil()
{
scope s(class_<UsdMayaUtilScope>("Util"));

def("IsAuthored", UsdMayaUtil::IsAuthored);
def("getDictionaryFromEncodedOptions", getDictionaryFromEncodedOptions);
}
Loading