Skip to content

Commit

Permalink
EMSUSD-1612 allow duplicating material to USD
Browse files Browse the repository at this point in the history
Refactor the prim update manager:
- Refactor the duplicate function into two functions: duplicateToMaya and duplicateToUsd.
- The duplicateToUsd function takes a Maya node instead of a UFE path to support Maya materials, which are not DAG objects.
- Support non-DAG object in the pushExport function when creating the full object list.
- This is necessary so that the material-only export correctly identify the material as being in the selection.

Improve the duplicate command:
- Support parsing pure Maya object names as the first argument to the duplicate command.
- When the first argument cannot be parsed as UFE then directly call the USD duplicate function with teh Maya object instead of the UFE path.

Add a unit test for duplicating to USD a material.
  • Loading branch information
pierrebai-adsk committed Sep 10, 2024
1 parent 3bdf504 commit 8db3de1
Show file tree
Hide file tree
Showing 5 changed files with 235 additions and 146 deletions.
28 changes: 21 additions & 7 deletions lib/mayaUsd/commands/PullPushCommands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,19 @@ MStatus parseUfePathArg(
return parseArgAsUfePath(text, outputPath);
}

MStatus parseDagPathArg(const MArgParser& argParser, int index, MDagPath& outputDagPath)
MStatus parseObjectArg(const MArgParser& argParser, int index, MObject& outputObject)
{
MString text;
MStatus status = parseTextArg(argParser, index, text);
CHECK_MSTATUS_AND_RETURN_IT(status);

return PXR_NS::UsdMayaUtil::GetMObjectByName(text, outputObject);
}

MStatus parseDagPathArg(const MArgParser& argParser, int index, MDagPath& outputDagPath)
{
MObject obj;
status = PXR_NS::UsdMayaUtil::GetMObjectByName(text, obj);
MStatus status = parseObjectArg(argParser, index, obj);
CHECK_MSTATUS_AND_RETURN_IT(status);

return MDagPath::getAPathTo(obj, outputDagPath);
Expand Down Expand Up @@ -428,11 +433,18 @@ MStatus DuplicateCommand::doIt(const MArgList& argList)
MArgParser argParser(syntax(), argList, &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

status = parseUfePathArg(argParser, 0, _srcPath);
if (status != MS::kSuccess)
return reportError(status);
MObject srcMayaObject;
Ufe::Path srcPath;
status = parseUfePathArg(argParser, 0, srcPath);
if (status != MS::kSuccess) {
status = parseObjectArg(argParser, 0, srcMayaObject);
if (status != MS::kSuccess) {
return reportError(status);
}
}

status = parseUfePathArg(argParser, 1, _dstPath, true /*allowEmpty*/);
Ufe::Path dstPath;
status = parseUfePathArg(argParser, 1, dstPath, true /*allowEmpty*/);
if (status != MS::kSuccess)
return reportError(status);

Expand All @@ -452,7 +464,9 @@ MStatus DuplicateCommand::doIt(const MArgList& argList)
OpUndoItemRecorder undoRecorder(_undoItemList);

auto& manager = PXR_NS::PrimUpdaterManager::getInstance();
auto dstUfePaths = manager.duplicate(_srcPath, _dstPath, userArgs);
auto dstUfePaths = srcPath.empty()
? manager.duplicateToUsd(srcMayaObject, dstPath, userArgs)
: manager.duplicate(srcPath, dstPath, userArgs);

if (dstUfePaths.size() > 0) {
// Select the duplicate.
Expand Down
3 changes: 0 additions & 3 deletions lib/mayaUsd/commands/PullPushCommands.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,6 @@ class DuplicateCommand : public PullPushBaseCommand
private:
// Make sure callers need to call creator().
DuplicateCommand();

Ufe::Path _srcPath;
Ufe::Path _dstPath;
};

} // namespace ufe
Expand Down
Loading

0 comments on commit 8db3de1

Please sign in to comment.