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

EMSUSD-36 - As a user, I'd like options for how I 'Edit as Maya Data' #3188

Merged
merged 3 commits into from
Jul 4, 2023
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
51 changes: 45 additions & 6 deletions lib/mayaUsd/fileio/primUpdaterManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,49 @@ bool allowTopologyModifications(MDagPath& root)
return dgMod.doIt();
}

UsdMayaJobImportArgs CreateImportArgsForPullImport(const VtDictionary& basicUserArgs)
{
VtDictionary userArgs(basicUserArgs);

MString optionsString;
static const MString optionVarName("usdMaya_EditAsMayaDataOptions");
if (MGlobal::optionVarExists(optionVarName)) {
optionsString = MGlobal::optionVarStringValue(optionVarName);
}

bool readAnimData = true;
if (optionsString.length() > 0) {
MStringArray optionList;
MStringArray theOption;
optionsString.split(';', optionList);
for (int i = 0, n = optionList.length(); i < n; ++i) {
theOption.clear();
optionList[i].split('=', theOption);
if (theOption.length() != 2) {
continue;
}

std::string argName(theOption[0].asChar(), theOption[0].length());
if (argName == "readAnimData") {
readAnimData = (theOption[1].asInt() != 0);
} else {
userArgs[argName] = UsdMayaUtil::ParseArgumentValue(
argName, theOption[1].asChar(), UsdMayaJobImportArgs::GetGuideDictionary());
}
}
}

GfInterval timeInterval;
if (readAnimData) {
timeInterval = GfInterval::GetFullInterval();
}

return UsdMayaJobImportArgs::CreateFromDictionary(
userArgs,
/* importWithProxyShapes = */ false,
timeInterval);
}

//------------------------------------------------------------------------------
//
// Perform the import step of the pull (first step), with the argument
Expand All @@ -261,12 +304,8 @@ PullImportPaths pullImport(
userArgs[UsdMayaJobImportArgsTokens->pullImportStage] = PXR_NS::VtValue(context.GetUsdStage());
userArgs[UsdMayaJobImportArgsTokens->preserveTimeline] = true;

UsdMayaJobImportArgs jobArgs = UsdMayaJobImportArgs::CreateFromDictionary(
userArgs,
/* importWithProxyShapes = */ false,
GfInterval::GetFullInterval());

MayaUsd::ImportData importData(mFileName);
UsdMayaJobImportArgs jobArgs = CreateImportArgsForPullImport(userArgs);
MayaUsd::ImportData importData(mFileName);
importData.setRootPrimPath(pulledPrim.GetPath().GetText());

auto readJob = std::make_shared<UsdMaya_ReadJob>(importData, jobArgs);
Expand Down
78 changes: 77 additions & 1 deletion plugin/adsk/scripts/USDMenuProc.mel
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,81 @@ global proc mayaUsdMenu_unassignMaterial(string $ufePath)
}
}

global proc mayaUsdMenu_EditAsMayaDataOptionsCallback(string $optionsString)
{
optionVar -stringValue usdMaya_EditAsMayaDataOptions $optionsString;
}

global proc mayaUsdMenu_EditAsMayaDataOptionsReset(string $obj)
{
optionVar -remove usdMaya_EditAsMayaDataOptions;
mayaUsdMenu_EditAsMayaDataOptions($obj);
}

global proc mayaUsdMenu_ApplyEditAsMayaDataOptions(string $obj)
{
mayaUsdTranslatorImport ("", "query", "", "mayaUsdMenu_EditAsMayaDataOptionsCallback");
hideOptionBox;

if (size($obj)) {
waitCursor -state 1;
mayaUsdMenu_editAsMaya $obj;
waitCursor -state 0;
}
}

global proc mayaUsdMenu_EditAsMayaDataOptions(string $obj)
{
global string $gOptionBoxOptions;
$gOptionBoxOptions = "noToolAndAction";
string $layout = getOptionBox();
setParent $layout;

setUITemplate -pushTemplate DefaultTemplate;
setOptionBoxTitle(getMayaUsdString("kEditAsMayaDataOptions"));

string $optionsString = ";readAnimData=1";
if (`optionVar -exists usdMaya_EditAsMayaDataOptions`) {
$optionsString = `optionVar -query usdMaya_EditAsMayaDataOptions`;
}

string $optionsFrame = `frameLayout -collapsable false -labelVisible false -marginHeight 10 -borderVisible false editAsMayaDataOptionsFrame`;
mayaUsdTranslatorImport ($optionsFrame, "post", $optionsString, "mayaUsdMenu_EditAsMayaDataOptionsCallback");

string $applyCloseBtn = getOptionBoxApplyAndCloseBtn();
button -edit -label `getMayaUsdString("kEditAsMayaData")`
-command ("mayaUsdMenu_ApplyEditAsMayaDataOptions(\"" + $obj + "\");")
$applyCloseBtn;

string $applyBtn = getOptionBoxApplyBtn();
button -edit
-command ("mayaUsdMenu_ApplyEditAsMayaDataOptions(\"\");")
$applyBtn;

string $resetBtn = getOptionBoxResetBtn();
button -edit
-command ("mayaUsdMenu_EditAsMayaDataOptionsReset(\"" + $obj + "\");")
$resetBtn;

string $saveBtn = getOptionBoxSaveBtn();
button -edit
-command "mayaUsdTranslatorImport(\"\", \"query\", \"\", \"mayaUsdMenu_EditAsMayaDataOptionsCallback\")"
$saveBtn;

string $helpItem = getOptionBoxHelpItem();
if ($helpItem != "") {
menuItem -edit
-label `getMayaUsdString("kHelpOnEditAsMayaDataOptions")`
-command ( "showHelp UsdImportOptionsConfig" )
$helpItem;
}

showOptionBox();

global string $gOptionBox;
window -e -height 260 $gOptionBox;
}

// On right click in the viewport, either through selection or through a pick
// hit, Maya will look for a procedure called $runTimeName + "MenuProc".
// and call it. When the selection or pick hit is a USD prim, this calls the
Expand All @@ -201,7 +276,8 @@ global proc USDMenuProc(string $parent, string $obj)

setParent -menu ..;
if (canEditAsMaya($obj)) {
menuItem -label "Edit As Maya Data" -image "edit_as_Maya.png" -command ("{waitCursor -state 1; mayaUsdMenu_editAsMaya \"" + $obj + "\"; waitCursor -state 0;}");
menuItem -label `getMayaUsdString("kEditAsMayaData")` -image "edit_as_Maya.png" -command ("{waitCursor -state 1; mayaUsdMenu_editAsMaya \"" + $obj + "\"; waitCursor -state 0;}");
menuItem -command ("{mayaUsdMenu_EditAsMayaDataOptions \"" + $obj + "\";}") -optionBox true;
}
if (canDupAsMaya($obj)) {
menuItem -label "Duplicate As Maya Data" -command ("{waitCursor -state 1; mayaUsdMenu_duplicate \"" + $obj + "\"; waitCursor -state 0;}");
Expand Down
3 changes: 3 additions & 0 deletions plugin/adsk/scripts/mayaUSDRegisterStrings.mel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ global proc mayaUSDRegisterStrings()
register("kButtonCancel", "Cancel");
register("kCreateUsdStageFromFile", "Create USD Stage from File");
register("kCreateUsdStageFromFileOptions", "Create USD Stage from File Options");
register("kEditAsMayaData", "Edit As Maya Data");
register("kEditAsMayaDataOptions", "Edit As Maya Data Options");
register("kHelpOnEditAsMayaDataOptions", "Help on Edit As Maya Data Options");
register("kCreateStageFromFile", "Create Stage from File");
register("kCreateStage", "Create");
register("kDefaultPrim", "Default Prim");
Expand Down
22 changes: 15 additions & 7 deletions plugin/adsk/scripts/mayaUsdTranslatorImport.mel
Original file line number Diff line number Diff line change
Expand Up @@ -168,11 +168,14 @@ global proc int mayaUsdTranslatorImport (string $parent,
int $cw1 = 180;
int $cw2 = 300;
int $bw = 125;
int $forEditAsMaya = ($resultCallback == "mayaUsdMenu_EditAsMayaDataOptionsCallback") ? 1 : 0;

if ($action == "post") {
setParent $parent;

columnLayout -adj true -rs 5 mayaUsdTranslator_OptsCol;
int $columnSpacing = ($forEditAsMaya ? 12 : 5);
string $menuAnnotation = ($forEditAsMaya ? "EditAsMayaOptions" : "ImportOptions");
columnLayout -adj true -rs $columnSpacing -ann $menuAnnotation mayaUsdTranslator_OptsCol;

optionMenuGrp -l `getMayaUsdString("kImportJobContextLbl")` -cw 1 $cw1 -annotation `getMayaUsdString("kImportJobContextAnn")` -cc ("mayaUsdTranslatorImport_JobContextCB") mayaUsdTranslator_jobContextPopup;
menuItem -l `getMayaUsdString("kImportJobContextNoneLbl")` -ann "None";
Expand All @@ -187,7 +190,7 @@ global proc int mayaUsdTranslatorImport (string $parent,
}


if (`exists usdImportDialog`)
if (`exists usdImportDialog` && !$forEditAsMaya)
{
rowLayout -numberOfColumns 4 -cw 1 $cw1 -cat 1 "right" 0;
text -label `getMayaUsdString("kImportScopeVariantsLbl")`
Expand Down Expand Up @@ -279,11 +282,15 @@ global proc int mayaUsdTranslatorImport (string $parent,
string $currentOptions = "";
$currentOptions = mayaUsdTranslatorImport_AppendMaterialsFromCheckBoxGrp($currentOptions, "shadingMode", "mayaUsdTranslator_MaterialsCheckBox");
$currentOptions = mayaUsdTranslatorImport_AppendFromPopup($currentOptions, "preferredMaterial", "mayaUsdTranslator_MaterialsConversionMenu");
$currentOptions = mayaUsdTranslatorImport_AppendFromDialog($currentOptions, "primPath", "-primPath");
if (!$forEditAsMaya) {
$currentOptions = mayaUsdTranslatorImport_AppendFromDialog($currentOptions, "primPath", "-primPath");
}
$currentOptions = mayaUsdTranslatorImport_AppendFromCheckBoxGrp($currentOptions, "readAnimData", "mayaUsdTranslator_AnimDataCheckBox");
$currentOptions = mayaUsdTranslatorImport_AppendFromCheckBoxGrp($currentOptions, "useCustomFrameRange", "mayaUsdTranslator_CustomFrameRangeCheckBox");
$currentOptions = mayaUsdTranslatorImport_AppendFromIntFieldGrp($currentOptions, "startTime", 1, "mayaUsdTranslator_CustomFrameRange");
$currentOptions = mayaUsdTranslatorImport_AppendFromIntFieldGrp($currentOptions, "endTime", 2, "mayaUsdTranslator_CustomFrameRange");
if (!$forEditAsMaya) {
$currentOptions = mayaUsdTranslatorImport_AppendFromCheckBoxGrp($currentOptions, "useCustomFrameRange", "mayaUsdTranslator_CustomFrameRangeCheckBox");
$currentOptions = mayaUsdTranslatorImport_AppendFromIntFieldGrp($currentOptions, "startTime", 1, "mayaUsdTranslator_CustomFrameRange");
$currentOptions = mayaUsdTranslatorImport_AppendFromIntFieldGrp($currentOptions, "endTime", 2, "mayaUsdTranslator_CustomFrameRange");
}
$currentOptions = mayaUsdTranslatorImport_AppendFromCheckBoxGrp($currentOptions, "importUSDZTextures", "mayaUsdTranslator_ImportUSDZTexturesCheckBox");
$currentOptions = mayaUsdTranslatorImport_AppendJobContexts($currentOptions, "jobContext");

Expand Down Expand Up @@ -365,7 +372,8 @@ global proc mayaUsdTranslatorImport_SetMaterialsCheckBox(string $arg, int $enabl

global proc mayaUsdTranslatorImport_AnimationCB()
{
if (`checkBoxGrp -q -value1 mayaUsdTranslator_AnimDataCheckBox` == 1) {
int $forEditAsMaya = (`columnLayout -q -ann mayaUsdTranslator_OptsCol` == "EditAsMayaOptions") ? 1 : 0;
if ((`checkBoxGrp -q -value1 mayaUsdTranslator_AnimDataCheckBox` == 1) && !$forEditAsMaya) {
checkBoxGrp -e -vis true mayaUsdTranslator_CustomFrameRangeCheckBox;
int $vis = (`checkBoxGrp -q -value1 mayaUsdTranslator_CustomFrameRangeCheckBox` == 1);
intFieldGrp -e -vis $vis mayaUsdTranslator_CustomFrameRange;
Expand Down