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

Tremblp/maya 114982/maya reference 00 #1973

Merged
merged 5 commits into from
Jan 11, 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
6 changes: 4 additions & 2 deletions lib/mayaUsd/fileio/primUpdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,17 @@ bool UsdMayaPrimUpdater::pushEnd(const UsdMayaPrimUpdaterContext& context)
return true;
}

bool UsdMayaPrimUpdater::pushCopySpecs(
UsdMayaPrimUpdater::PushCopySpecs UsdMayaPrimUpdater::pushCopySpecs(
UsdStageRefPtr srcStage,
SdfLayerRefPtr srcLayer,
const SdfPath& srcSdfPath,
UsdStageRefPtr dstStage,
SdfLayerRefPtr dstLayer,
const SdfPath& dstSdfPath)
{
return MayaUsdUtils::mergePrims(srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPath);
return MayaUsdUtils::mergePrims(srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPath)
? PushCopySpecs::Continue
: PushCopySpecs::Failed;
}

const MObject& UsdMayaPrimUpdater::getMayaObject() const { return _mayaObject; }
Expand Down
11 changes: 10 additions & 1 deletion lib/mayaUsd/fileio/primUpdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,19 @@ class UsdMayaPrimUpdater
All = Push | Pull | Clear
};

// pushCopySpecs result code. Prune means success, but no further
// traversal should take place.
enum class PushCopySpecs
{
Failed,
Continue,
Prune
};

// Copy the pushed prim from the temporary srcLayer where it has been
// exported by push into the destination dstLayer which is in the scene.
MAYAUSD_CORE_PUBLIC
virtual bool pushCopySpecs(
virtual PushCopySpecs pushCopySpecs(
UsdStageRefPtr srcStage,
SdfLayerRefPtr srcLayer,
const SdfPath& srcSdfPath,
Expand Down
71 changes: 48 additions & 23 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,12 @@ SdfPath ufeToSdfPath(const Ufe::Path& usdPath)
return SdfPath(segments[1].string());
}

SdfPath makeDstPath(const SdfPath& dstRootParentPath, const SdfPath& srcPath)
{
auto relativeSrcPath = srcPath.MakeRelativePath(SdfPath::AbsoluteRootPath());
return dstRootParentPath.AppendPath(relativeSrcPath);
}

//------------------------------------------------------------------------------
//
// The UFE path and the prim refer to the same object: the prim is passed in as
Expand Down Expand Up @@ -575,33 +581,48 @@ SdfPath getDstSdfPath(const Ufe::Path& ufePulledPath, const SdfPath& srcSdfPath,
//------------------------------------------------------------------------------
//
UsdMayaPrimUpdaterSharedPtr createUpdater(
const Ufe::Path& ufePulledPath,
const SdfLayerRefPtr& srcLayer,
const SdfPath& primSpecPath,
const SdfPath& srcPath,
const SdfLayerRefPtr& dstLayer,
const SdfPath& dstPath,
const UsdMayaPrimUpdaterContext& context)
{
// Get the primSpec from the src layer.
auto primSpec = srcLayer->GetPrimAtPath(primSpecPath);
// The root of the pulled hierarchy is crucial for determining push
// behavior. When pulling, we may have created a Maya pull hierarchy root
// node whose type does not map to the same prim updater as the original
// USD prim, i.e. multiple USD prim types can map to the same pulled Maya
// node type (e.g. transform, which is the fallback Maya node type for many
// USD prim types). Therefore, if we're at the root of the src hierarchy,
// use the prim at the pulled path to create the prim updater; this will
// occur on push, when the srcPath is in the temporary layer.
const bool usePulledPrim = (srcPath.GetPathElementCount() == 1);

auto primSpec = srcLayer->GetPrimAtPath(srcPath);
if (!TF_VERIFY(primSpec)) {
return nullptr;
}

TfToken typeName = primSpec->GetTypeName();
auto regItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(typeName);
auto factory = std::get<UpdaterFactoryFn>(regItem);
TfToken typeName = usePulledPrim ? MayaUsd::ufe::ufePathToPrim(ufePulledPath).GetTypeName()
: primSpec->GetTypeName();
auto regItem = UsdMayaPrimUpdaterRegistry::FindOrFallback(typeName);
auto factory = std::get<UpdaterFactoryFn>(regItem);

// Create the UFE path corresponding to the primSpecPath, as required
// by the prim updater factory.
// We cannot use the srcPath to create the UFE path, as this path is in the
// in-memory stage in the temporary srcLayer and does not exist in UFE.
// Use the dstPath instead, which can be validly added to the proxy shape
// path to form a proper UFE path.
auto psPath = MayaUsd::ufe::stagePath(context.GetUsdStage());
Ufe::Path::Segments segments { psPath.getSegments()[0],
MayaUsd::ufe::usdPathToUfePathSegment(primSpecPath) };
MayaUsd::ufe::usdPathToUfePathSegment(dstPath) };
Ufe::Path ufePath(std::move(segments));

// Get the Maya object corresponding to the SdfPath. As of 19-Oct-2021,
// the export write job only registers Maya Dag path to SdfPath
// correspondence, so prims that correspond to Maya DG nodes (e.g. material
// networks) don't have a corresponding Dag path. The prim updater
// receives a null MObject in this case.
auto mayaDagPath = context.MapSdfPathToDagPath(primSpecPath);
auto mayaDagPath = context.MapSdfPathToDagPath(srcPath);
MFnDependencyNode depNodeFn(mayaDagPath.isValid() ? mayaDagPath.node() : MObject());

return factory(depNodeFn, ufePath);
Expand Down Expand Up @@ -634,7 +655,8 @@ bool pushCustomize(
// Traverse the layer, creating a prim updater for each primSpec
// along the way, and call PushCopySpec on the prim.
auto pushCopySpecsFn
= [&context, srcStage, srcLayer, dstLayer, dstRootParentPath](const SdfPath& srcPath) {
= [&context, &ufePulledPath, srcStage, srcLayer, dstLayer, dstRootParentPath](
const SdfPath& srcPath) {
// We can be called with a primSpec path that is not a prim path
// (e.g. a property path like "/A.xformOp:translate"). This is not an
// error, just prune the traversal. FIXME Is this still true? We
Expand All @@ -643,7 +665,9 @@ bool pushCustomize(
return false;
}

auto updater = createUpdater(srcLayer, srcPath, context);
auto dstPath = makeDstPath(dstRootParentPath, srcPath);
auto updater
= createUpdater(ufePulledPath, srcLayer, srcPath, dstLayer, dstPath, context);
// If we cannot find an updater for the srcPath, prune the traversal.
if (!updater) {
TF_WARN(
Expand All @@ -652,17 +676,16 @@ bool pushCustomize(
srcPath.GetText());
return false;
}
auto relativeSrcPath = srcPath.MakeRelativePath(SdfPath::AbsoluteRootPath());
auto dstPath = dstRootParentPath.AppendPath(relativeSrcPath);

// Report PushCopySpecs() failure.
if (!updater->pushCopySpecs(
srcStage, srcLayer, srcPath, context.GetUsdStage(), dstLayer, dstPath)) {
auto result = updater->pushCopySpecs(
srcStage, srcLayer, srcPath, context.GetUsdStage(), dstLayer, dstPath);
if (result == UsdMayaPrimUpdater::PushCopySpecs::Failed) {
throw MayaUsd::TraversalFailure(std::string("PushCopySpecs() failed."), srcPath);
}

// Continue normal traversal without pruning.
return true;
// If we don't continue, we prune.
return result == UsdMayaPrimUpdater::PushCopySpecs::Continue;
};

if (!MayaUsd::traverseLayer(srcLayer, srcRootPath, pushCopySpecsFn)) {
Expand All @@ -679,26 +702,28 @@ bool pushCustomize(

// SdfLayer::TraversalFn does not return a status, so must report
// failure through an exception.
auto pushEndFn = [&context, srcLayer](const SdfPath& primSpecPath) {
auto pushEndFn = [&context, &ufePulledPath, srcLayer, dstLayer, dstRootParentPath](
const SdfPath& srcPath) {
// We can be called with a primSpec path that is not a prim path
// (e.g. a property path like "/A.xformOp:translate"). This is not an
// error, just a no-op.
if (!primSpecPath.IsPrimPath()) {
if (!srcPath.IsPrimPath()) {
return;
}

auto updater = createUpdater(srcLayer, primSpecPath, context);
auto dstPath = makeDstPath(dstRootParentPath, srcPath);
auto updater = createUpdater(ufePulledPath, srcLayer, srcPath, dstLayer, dstPath, context);
if (!updater) {
TF_WARN(
"Could not create a prim updater for path %s during PushEnd() traversal, pruning "
"at that point.",
primSpecPath.GetText());
srcPath.GetText());
return;
}

// Report pushEnd() failure.
if (!updater->pushEnd(context)) {
throw MayaUsd::TraversalFailure(std::string("PushEnd() failed."), primSpecPath);
throw MayaUsd::TraversalFailure(std::string("PushEnd() failed."), srcPath);
}
};

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

virtual ~PrimUpdaterWrapper() = default;

bool default_pushCopySpecs(
PushCopySpecs default_pushCopySpecs(
UsdStageRefPtr srcStage,
SdfLayerRefPtr srcLayer,
const SdfPath& srcSdfPath,
Expand All @@ -66,15 +66,15 @@ class PrimUpdaterWrapper
return base_t::pushCopySpecs(
srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPath);
}
bool pushCopySpecs(
PushCopySpecs pushCopySpecs(
UsdStageRefPtr srcStage,
SdfLayerRefPtr srcLayer,
const SdfPath& srcSdfPath,
UsdStageRefPtr dstStage,
SdfLayerRefPtr dstLayer,
const SdfPath& dstSdfPath) override
{
return this->CallVirtual<bool>("pushCopySpecs", &This::default_pushCopySpecs)(
return this->CallVirtual<PushCopySpecs>("pushCopySpecs", &This::default_pushCopySpecs)(
srcStage, srcLayer, srcSdfPath, dstStage, dstLayer, dstSdfPath);
}

Expand Down Expand Up @@ -179,6 +179,10 @@ TF_REGISTRY_FUNCTION(TfEnum)
TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::Supports::Clear, "Clear");
TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::Supports::AutoPull, "AutoPull");
TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::Supports::All, "All");

TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::PushCopySpecs::Failed, "Failed");
TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::PushCopySpecs::Continue, "Continue");
TF_ADD_ENUM_NAME(UsdMayaPrimUpdater::PushCopySpecs::Prune, "Prune");
}

//----------------------------------------------------------------------------------------------------------------------
Expand All @@ -192,6 +196,7 @@ void wrapPrimUpdater()
boost::python::scope s(c);

TfPyWrapEnum<UsdMayaPrimUpdater::Supports>();
TfPyWrapEnum<UsdMayaPrimUpdater::PushCopySpecs>();

c.def("__init__", make_constructor(&PrimUpdaterWrapper::New))
.def("pushCopySpecs", &This::pushCopySpecs, &PrimUpdaterWrapper::default_pushCopySpecs)
Expand Down
1 change: 1 addition & 0 deletions lib/mayaUsd/resources/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(ae)
add_subdirectory(icons)
add_subdirectory(scripts)
8 changes: 8 additions & 0 deletions lib/mayaUsd/resources/scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
list(APPEND scripts_src
mayaUsdAddMayaReference.mel
mayaUsdAddMayaReference.py
)

install(FILES ${scripts_src}
DESTINATION ${CMAKE_INSTALL_PREFIX}/scripts
)
Loading