Skip to content

Commit cfe8396

Browse files
authored
Merge pull request #3676 from Autodesk/bailp/EMSUSD-1038/import-plugin-config
EMSUSD-1038 import plugin config UI
2 parents b311cd5 + f3d2dc9 commit cfe8396

File tree

16 files changed

+687
-85
lines changed

16 files changed

+687
-85
lines changed

README_DOC.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
## Core Modules
77
+ [Common Plug-in Base Commands](lib/mayaUsd/commands/Readme.md)
88
+ [Managing Translation (Import/Export) Options](lib/mayaUsd/fileio/doc/Managing_export_options_via_JobContext_in_Python.md)
9-
+ [Example Export Plugin in Python](tutorials/export-plugin/README.md)
9+
+ [Example Import and Export Plugin in Python](tutorials/import-export-plugin/README.md)
1010
+ [SchemaAPI Translators](lib/mayaUsd/fileio/doc/SchemaAPI_Import_Export_in_Python.md)
1111
+ [UFE Transform](lib/mayaUsd/ufe/UsdTransform3d.md)
1212
+ [Undo/Redo Support](lib/mayaUsd/undo/README.md)

lib/mayaUsd/commands/baseListJobContextsCommand.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ const char* _exportAnnotationStr = "exportAnnotation";
7373
const char* _exportArgumentsStr = "exportArguments";
7474
const char* _hasExportUIStr = "hasExportUI";
7575
const char* _showExportUIStr = "showExportUI";
76+
const char* _hasImportUIStr = "hasImportUI";
77+
const char* _showImportUIStr = "showImportUI";
7678
const char* _importStr = "import";
7779
const char* _importAnnotationStr = "importAnnotation";
7880
const char* _importArgumentsStr = "importArguments";
@@ -128,6 +130,29 @@ MStatus MayaUSDListJobContextsCommand::doIt(const MArgList& args)
128130

129131
setResult(convertDictionaryToText(
130132
info.exportUICallback(info.jobContext, parentUIStr.asChar(), inputSettings)));
133+
} else if (argData.isFlagSet(_hasImportUIStr)) {
134+
auto const& info = _GetInfo(argData, _hasImportUIStr);
135+
setResult(bool(info.importUICallback != nullptr));
136+
} else if (argData.isFlagSet(_showImportUIStr)) {
137+
auto const& info = _GetInfo(argData, _showImportUIStr);
138+
if (!info.importUICallback)
139+
return MS::kInvalidParameter;
140+
141+
MString parentUIStr;
142+
if (argData.getFlagArgument(_showImportUIStr, 1, parentUIStr) != MS::kSuccess)
143+
return MS::kInvalidParameter;
144+
145+
MString settingsStr;
146+
if (argData.getFlagArgument(_showImportUIStr, 2, settingsStr) != MS::kSuccess)
147+
return MS::kInvalidParameter;
148+
149+
VtDictionary inputSettings;
150+
if (UsdMayaJobImportArgs::GetDictionaryFromEncodedOptions(settingsStr, &inputSettings)
151+
!= MS::kSuccess)
152+
return MS::kInvalidParameter;
153+
154+
setResult(convertDictionaryToText(
155+
info.importUICallback(info.jobContext, parentUIStr.asChar(), inputSettings)));
131156
} else if (argData.isFlagSet(_importStr)) {
132157
for (auto const& c : UsdMayaJobContextRegistry::ListJobContexts()) {
133158
auto const& info = UsdMayaJobContextRegistry::GetJobContextInfo(c);
@@ -163,6 +188,8 @@ MSyntax MayaUSDListJobContextsCommand::createSyntax()
163188
syntax.addFlag("-eg", "-exportArguments", MSyntax::kString);
164189
syntax.addFlag("-heu", "-hasExportUI", MSyntax::kString);
165190
syntax.addFlag("-seu", "-showExportUI", MSyntax::kString, MSyntax::kString, MSyntax::kString);
191+
syntax.addFlag("-hiu", "-hasImportUI", MSyntax::kString);
192+
syntax.addFlag("-siu", "-showImportUI", MSyntax::kString, MSyntax::kString, MSyntax::kString);
166193
syntax.addFlag("-im", "-import", MSyntax::kNoArg);
167194
syntax.addFlag("-ia", "-importAnnotation", MSyntax::kString);
168195
syntax.addFlag("-ig", "-importArguments", MSyntax::kString);

lib/mayaUsd/fileio/jobContextRegistry.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,29 @@ void UsdMayaJobContextRegistry::RegisterImportJobContext(
159159
}
160160
}
161161

162+
void UsdMayaJobContextRegistry::SetImportOptionsUI(
163+
const std::string& jobContext,
164+
UIFn uiFct,
165+
bool fromPython)
166+
{
167+
const ContextInfo key { TfToken(jobContext), {}, {}, {}, {}, {} };
168+
auto iter = _jobContextReg.find(key);
169+
if (iter == _jobContextReg.end()) {
170+
TF_CODING_ERROR("Import job context %s does not exist", jobContext.c_str());
171+
return;
172+
}
173+
174+
// Note: the container for the plugin info is a set so it cannot be modified.
175+
// We need to copy the entry, modify the copy, remove the old entry and
176+
// insert the newly updated entry.
177+
178+
ContextInfo updatedInfo(*iter);
179+
updatedInfo.importUICallback = uiFct;
180+
UsdMaya_RegistryHelper::AddUnloader([key]() { _jobContextReg.erase(key); }, fromPython);
181+
_jobContextReg.erase(iter);
182+
_jobContextReg.insert(updatedInfo);
183+
}
184+
162185
TfTokenVector UsdMayaJobContextRegistry::_ListJobContexts()
163186
{
164187
UsdMaya_RegistryHelper::LoadJobContextPlugins();

lib/mayaUsd/fileio/jobContextRegistry.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class UsdMayaJobContextRegistry : public TfWeakBase
103103
UIFn exportUICallback;
104104
TfToken importDescription;
105105
EnablerFn importEnablerCallback;
106+
UIFn importUICallback;
106107

107108
ContextInfo() = default;
108109

@@ -176,6 +177,17 @@ class UsdMayaJobContextRegistry : public TfWeakBase
176177
EnablerFn enablerFct,
177178
bool fromPython = false);
178179

180+
/// Registers an import job context UI dialog.
181+
///
182+
/// The \p jobContext name will be used directly in the render option string as one of
183+
/// the valid values of the job context option.
184+
///
185+
/// The \p uiFct will be called to show a modal dialog to modify options by the user.
186+
///
187+
/// The \p fromPython flag indicates the function is a Python function.
188+
MAYAUSD_CORE_PUBLIC
189+
void SetImportOptionsUI(const std::string& jobContext, UIFn uiFct, bool fromPython = false);
190+
179191
MAYAUSD_CORE_PUBLIC
180192
static UsdMayaJobContextRegistry& GetInstance();
181193

lib/mayaUsd/fileio/jobs/jobArgs.cpp

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -834,7 +834,7 @@ MStatus UsdMayaJobExportArgs::GetDictionaryFromEncodedOptions(
834834
MStringArray optionList;
835835
MStringArray theOption;
836836
optionsString.split(';', optionList);
837-
for (int i = 0; i < (int)optionList.length(); ++i) {
837+
for (unsigned int i = 0; i < optionList.length(); ++i) {
838838
theOption.clear();
839839
optionList[i].split('=', theOption);
840840
if (theOption.length() != 2) {
@@ -1216,6 +1216,39 @@ UsdMayaJobImportArgs UsdMayaJobImportArgs::CreateFromDictionary(
12161216
return UsdMayaJobImportArgs(allUserArgs, importWithProxyShapes, timeInterval);
12171217
}
12181218

1219+
/* static */
1220+
MStatus UsdMayaJobImportArgs::GetDictionaryFromEncodedOptions(
1221+
const MString& optionsString,
1222+
VtDictionary* toFill)
1223+
{
1224+
if (!toFill)
1225+
return MS::kFailure;
1226+
1227+
VtDictionary& userArgs = *toFill;
1228+
1229+
// Get the options
1230+
if (optionsString.length() > 0) {
1231+
MStringArray optionList;
1232+
MStringArray theOption;
1233+
optionsString.split(';', optionList);
1234+
for (unsigned int i = 0; i < optionList.length(); ++i) {
1235+
theOption.clear();
1236+
optionList[i].split('=', theOption);
1237+
if (theOption.length() != 2) {
1238+
continue;
1239+
}
1240+
1241+
// Note: if some argument needs special handling, do like in the
1242+
// same function in the export version in UsdMayaJobExportArgs
1243+
std::string argName(theOption[0].asChar());
1244+
userArgs[argName] = UsdMayaUtil::ParseArgumentValue(
1245+
argName, theOption[1].asChar(), UsdMayaJobExportArgs::GetGuideDictionary());
1246+
}
1247+
}
1248+
1249+
return MS::kSuccess;
1250+
}
1251+
12191252
/* static */
12201253
const VtDictionary& UsdMayaJobImportArgs::GetDefaultDictionary()
12211254
{

lib/mayaUsd/fileio/jobs/jobArgs.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,14 @@ struct UsdMayaJobImportArgs
405405
const bool importWithProxyShapes = false,
406406
const GfInterval& timeInterval = GfInterval::GetFullInterval());
407407

408+
/// Fills a VtDictionary from the given text-encoded options.
409+
/// Issues runtime errors if some options contain values of the wrong format.
410+
///
411+
/// The text encoding is in the form: name1=value1;name2=value2;...
412+
MAYAUSD_CORE_PUBLIC
413+
static MStatus
414+
GetDictionaryFromEncodedOptions(const MString& optionsString, VtDictionary* toFill);
415+
408416
/// Gets the default arguments dictionary for UsdMayaJobImportArgs.
409417
MAYAUSD_CORE_PUBLIC
410418
static const VtDictionary& GetDefaultDictionary();

lib/mayaUsd/python/wrapJobContextRegistry.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,22 @@ class JobContextRegistry
8989
true);
9090
}
9191

92+
static void SetImportOptionsUI(const std::string& jobContext, boost::python::object uiFct)
93+
{
94+
if (!PyCallable_Check(uiFct.ptr()))
95+
TF_CODING_ERROR(
96+
"Parameter uiFct should be a callable function returning a dictionary.");
97+
98+
UsdMayaJobContextRegistry::GetInstance().SetImportOptionsUI(
99+
jobContext,
100+
[=](const TfToken& jobContext,
101+
const std::string& parentUI,
102+
const VtDictionary& settings) {
103+
return callUIFn(uiFct, jobContext, parentUI, settings);
104+
},
105+
true);
106+
}
107+
92108
private:
93109
static VtDictionary callEnablerFn(boost::python::object fnc)
94110
{
@@ -119,5 +135,7 @@ void wrapJobContextRegistry()
119135
.def("RegisterExportJobContext", &JobContextRegistry::RegisterExportJobContext)
120136
.staticmethod("RegisterExportJobContext")
121137
.def("SetExportOptionsUI", &JobContextRegistry::SetExportOptionsUI)
122-
.staticmethod("SetExportOptionsUI");
138+
.staticmethod("SetExportOptionsUI")
139+
.def("SetImportOptionsUI", &JobContextRegistry::SetImportOptionsUI)
140+
.staticmethod("SetImportOptionsUI");
123141
}

plugin/adsk/scripts/mayaUSDRegisterStrings.mel

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ global proc mayaUSDRegisterStrings()
172172
register("kExportPluginConfigAnn", "Turn on the plug-ins you wish to include for this process.\n" +
173173
"When turned on, plug-ins (like Arnold) can modify or create data to ensure compatibility.\n" +
174174
"Plug-ins may have extra settings you can adjust.");
175-
register("kExportPluginConfigButtonLbl", "Options");
175+
register("kExportPluginConfigButtonAnn", "Options");
176176
register("kExportMaterialsAnn", "Select the material(s) to bind to prims for export. With USD, you can bind multiple materials to prims.");
177177
register("kExportMaterialsDefaultScopeName", "mtl");
178178
register("kExportMergeShapesAnn", "Merges Maya transform and shape nodes into a single USD prim.");
@@ -254,6 +254,12 @@ global proc mayaUSDRegisterStrings()
254254
register("kImportUSDZTxtAnn", "When a .usdz file is chosen and this is selected, .usdz texture files are imported and copied to new files on disk. To locate these files, navigate to the current Maya workspace /sourceimages directory.");
255255
register("kImportUSDZTxtLbl", "USDZ Texture Import");
256256
register("kImportVariantsInScopeNumLbl", "Variants Switched in Scope:");
257+
register("kImportPluginConfigLbl", "Plug-in Configurations");
258+
register("kImportPluginConfigAnn", "Turn on the plug-ins you wish to include for this process.\n" +
259+
"When turned on, plug-ins (like Arnold) can modify or create data to ensure compatibility.\n" +
260+
"Plug-ins may have extra settings you can adjust.");
261+
register("kImportPluginConfigButtonAnn", "Options");
262+
257263
register("kMayaDiscardEdits", "Discard Maya Edits");
258264
register("kMayaRefDiscardEdits", "Cancel Editing as Maya Data");
259265
register("kMayaRefDuplicateAsUsdData", "Duplicate As USD Data");

plugin/adsk/scripts/mayaUsdTranslatorExport.mel

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@ proc mayaUsdTranslatorExport_createContextOptions(string $parent, string $sectio
388388
text -label $contextLabel -ann $tooltip -align "left";
389389
iconTextButton
390390
-w 16 -h 16 -style "iconAndTextVertical"
391-
-image1 "menu_options" -label "" -ann `getMayaUsdString("kExportPluginConfigButtonLbl")`
391+
-image1 "menu_options" -label "" -ann `getMayaUsdString("kExportPluginConfigButtonAnn")`
392392
-command ("mayaUsdTranslatorExport_contextOptionsButtonCB(\"" + $contextLabel + "\")") $buttonName;
393393

394394
rowLayout -width 2 -height $rowHeight -backgroundColor $color[0] $color[1] $color[2];
@@ -745,7 +745,7 @@ global proc mayaUsdTranslatorExport_EnableAllControls() {
745745
global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $enable, int $processJobContext) {
746746
string $optionList[];
747747
string $optionBreakDown[];
748-
string $jobContext = "";
748+
string $listOfJobContexts = "";
749749
int $index;
750750

751751
if (size($currentOptions) > 0) {
@@ -802,7 +802,7 @@ global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $
802802
mayaUsdTranslatorExport_SetCheckbox($optionBreakDown[1], $enable, "exportComponentTagsCheckBox");
803803
} else if ($optionBreakDown[0] == "jobContext" && $processJobContext == 1) {
804804
// Must be kept last, and only done on main options:
805-
$jobContext = $optionBreakDown[1];
805+
$listOfJobContexts = $optionBreakDown[1];
806806
} else if ($optionBreakDown[0] == "defaultMeshScheme") {
807807
mayaUsdTranslatorExport_SetOptionMenuByAnnotation($optionBreakDown[1], $enable, "defaultMeshSchemePopup");
808808
} else if ($optionBreakDown[0] == "defaultUSDFormat") {
@@ -857,8 +857,8 @@ global proc mayaUsdTranslatorExport_SetFromOptions(string $currentOptions, int $
857857
mayaUsdTranslatorExport_MeshCB();
858858
}
859859

860-
if ($jobContext != "" && $processJobContext == 1) {
861-
mayaUsdTranslatorExport_fillContextOptionsUI($jobContext);
860+
if ($listOfJobContexts != "" && $processJobContext == 1) {
861+
mayaUsdTranslatorExport_fillContextOptionsUI($listOfJobContexts);
862862
}
863863
if ($processJobContext == 0 && $supportsMultiExport == 0) {
864864
mayaUsdTranslatorExport_DisableConvertMaterialsToCheckboxes();

0 commit comments

Comments
 (0)