From b427c920c9bd4b5082307406087adcf9938a3d23 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 29 Jun 2023 08:36:57 -0400 Subject: [PATCH 1/2] Edit As Maya Data Options --- lib/mayaUsd/fileio/primUpdaterManager.cpp | 51 +++++++++++-- plugin/adsk/scripts/USDMenuProc.mel | 75 ++++++++++++++++++- .../adsk/scripts/mayaUSDRegisterStrings.mel | 3 + .../adsk/scripts/mayaUsdTranslatorImport.mel | 22 ++++-- 4 files changed, 137 insertions(+), 14 deletions(-) diff --git a/lib/mayaUsd/fileio/primUpdaterManager.cpp b/lib/mayaUsd/fileio/primUpdaterManager.cpp index efef508d08..ed87141fb1 100644 --- a/lib/mayaUsd/fileio/primUpdaterManager.cpp +++ b/lib/mayaUsd/fileio/primUpdaterManager.cpp @@ -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 @@ -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(importData, jobArgs); diff --git a/plugin/adsk/scripts/USDMenuProc.mel b/plugin/adsk/scripts/USDMenuProc.mel index 01c7c0e95a..0d465ba474 100644 --- a/plugin/adsk/scripts/USDMenuProc.mel +++ b/plugin/adsk/scripts/USDMenuProc.mel @@ -184,6 +184,78 @@ 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 40 -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(); +} + // 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 @@ -201,7 +273,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;}"); diff --git a/plugin/adsk/scripts/mayaUSDRegisterStrings.mel b/plugin/adsk/scripts/mayaUSDRegisterStrings.mel index 98877d9783..6431eb56bb 100644 --- a/plugin/adsk/scripts/mayaUSDRegisterStrings.mel +++ b/plugin/adsk/scripts/mayaUSDRegisterStrings.mel @@ -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"); diff --git a/plugin/adsk/scripts/mayaUsdTranslatorImport.mel b/plugin/adsk/scripts/mayaUsdTranslatorImport.mel index dbd9483e07..796755fb08 100644 --- a/plugin/adsk/scripts/mayaUsdTranslatorImport.mel +++ b/plugin/adsk/scripts/mayaUsdTranslatorImport.mel @@ -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"; @@ -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")` @@ -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"); @@ -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; From c59d6dfd88884f792de8d8ceb819f4d6a03006a5 Mon Sep 17 00:00:00 2001 From: Ivan Vlasov Date: Thu, 29 Jun 2023 15:36:25 -0400 Subject: [PATCH 2/2] Fixing window size --- plugin/adsk/scripts/USDMenuProc.mel | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugin/adsk/scripts/USDMenuProc.mel b/plugin/adsk/scripts/USDMenuProc.mel index 0d465ba474..aeb9314b67 100644 --- a/plugin/adsk/scripts/USDMenuProc.mel +++ b/plugin/adsk/scripts/USDMenuProc.mel @@ -222,7 +222,7 @@ global proc mayaUsdMenu_EditAsMayaDataOptions(string $obj) $optionsString = `optionVar -query usdMaya_EditAsMayaDataOptions`; } - string $optionsFrame = `frameLayout -collapsable false -labelVisible false -marginHeight 40 -borderVisible false editAsMayaDataOptionsFrame`; + string $optionsFrame = `frameLayout -collapsable false -labelVisible false -marginHeight 10 -borderVisible false editAsMayaDataOptionsFrame`; mayaUsdTranslatorImport ($optionsFrame, "post", $optionsString, "mayaUsdMenu_EditAsMayaDataOptionsCallback"); string $applyCloseBtn = getOptionBoxApplyAndCloseBtn(); @@ -254,6 +254,9 @@ global proc mayaUsdMenu_EditAsMayaDataOptions(string $obj) } showOptionBox(); + + global string $gOptionBox; + window -e -height 260 $gOptionBox; } // On right click in the viewport, either through selection or through a pick