Skip to content

Commit c4089d5

Browse files
jufrantzclaude
andcommitted
fileio: ability for automatic loading for plugins that register an ExportChaser or ImportChaser.
- Refactors the shared plugin discovery/loading logic used by jobContext and shadingMode registries. - Reuses that logic for import and export chasers, triggering chaser plugin loading just before chasers are created. o CMakeLists. - Add strengthened LayerTreeView tests (mute/lock button-push, key Delete/R, add-parent, expand-children) and LayerEditorWidget tests (splitter/lazy-update/ save-stage button, GeneratedIconButton paint states). - Add SaveLayersDialog all-as-relative tests and an unguarded EF toggle-button test covering the runtime-gated edit-forwarding setup. - Export GeneratedIconButton (LayerEditorAPI) so its paint paths are testable. UsdLayerEditorNewTests: 438 tests, 437 pass, 1 expected skip. Lib coverage ~70%. TURE----- Merge pull request #4651 from Autodesk/barbalt/dev/EMSUSD-3311-remove-opinion EMSUSD-3311 - Add remove opinion + undoENEITEM_HAS_METADATA is no…both unchanged. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> eply@anthropic.com> hropic.com>
1 parent 334cae9 commit c4089d5

4 files changed

Lines changed: 84 additions & 70 deletions

File tree

lib/mayaUsd/fileio/chaser/exportChaserRegistry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ bool UsdMayaExportChaserRegistry::RegisterFactory(
6767
UsdMayaExportChaserRefPtr
6868
UsdMayaExportChaserRegistry::Create(const std::string& name, const FactoryContext& context) const
6969
{
70+
UsdMaya_RegistryHelper::LoadExportChaserPlugins();
7071
TfRegistryManager::GetInstance().SubscribeTo<UsdMayaExportChaserRegistry>();
72+
7173
if (UsdMayaExportChaserRegistry::FactoryFn fn = _factoryRegistry[name]) {
7274
return TfCreateRefPtr(fn(context));
7375
} else {

lib/mayaUsd/fileio/chaser/importChaserRegistry.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ bool UsdMayaImportChaserRegistry::RegisterFactory(const char* name, FactoryFn fn
8080
UsdMayaImportChaserRefPtr
8181
UsdMayaImportChaserRegistry::Create(const char* name, const FactoryContext& context) const
8282
{
83+
UsdMaya_RegistryHelper::LoadImportChaserPlugins();
8384
TfRegistryManager::GetInstance().SubscribeTo<UsdMayaImportChaserRegistry>();
85+
8486
if (UsdMayaImportChaserRegistry::FactoryFn fn = _factoryImportRegistry[name]) {
8587
return TfCreateRefPtr(fn(context));
8688
} else {

lib/mayaUsd/fileio/registryHelper.cpp

Lines changed: 56 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ TF_DEFINE_PRIVATE_TOKENS(
4242
(UsdMaya)
4343
(ShadingModePlugin)
4444
(JobContextPlugin)
45+
(ImportChaserPlugin)
46+
(ExportChaserPlugin)
4547
);
4648
// clang-format on
4749

@@ -140,6 +142,42 @@ static bool _HasMayaPlugin(
140142
return true;
141143
}
142144

145+
static void _FindAndLoadUsdMayaPlugins(const TfToken& pluginKey)
146+
{
147+
const std::vector<TfToken> scope { _tokens->UsdMaya, pluginKey };
148+
149+
for (const auto& plug : PlugRegistry::GetInstance().GetAllPlugins()) {
150+
std::string mayaPlugin;
151+
if (_HasMayaPlugin(plug, scope, &mayaPlugin)) {
152+
if (!mayaPlugin.empty()) {
153+
TF_DEBUG(PXRUSDMAYA_REGISTRY)
154+
.Msg(
155+
"Found %s %s: Loading via Maya API %s.\n",
156+
pluginKey.GetText(),
157+
plug->GetName().c_str(),
158+
mayaPlugin.c_str());
159+
std::string loadPluginCmd
160+
= TfStringPrintf("loadPlugin -quiet %s", mayaPlugin.c_str());
161+
if (MGlobal::executeCommand(loadPluginCmd.c_str())) {
162+
// Need to ensure Python script modules are loaded
163+
// properly for this library (Maya's loadPlugin will not
164+
// load script modules like TfDlopen would).
165+
TfScriptModuleLoader::GetInstance().LoadModules();
166+
} else {
167+
TF_CODING_ERROR("Unable to load mayaplugin %s\n", mayaPlugin.c_str());
168+
}
169+
} else {
170+
TF_DEBUG(PXRUSDMAYA_REGISTRY)
171+
.Msg(
172+
"Found %s %s: Loading via USD API.\n",
173+
pluginKey.GetText(),
174+
plug->GetName().c_str());
175+
plug->Load();
176+
}
177+
}
178+
}
179+
}
180+
143181
/* static */
144182
std::string _PluginDictScopeToDebugString(const std::vector<TfToken>& scope)
145183
{
@@ -202,81 +240,29 @@ void UsdMaya_RegistryHelper::FindAndLoadMayaPlug(
202240
/* static */
203241
void UsdMaya_RegistryHelper::LoadShadingModePlugins()
204242
{
205-
static std::once_flag _shadingModesLoaded;
206-
static std::vector<TfToken> scope = { _tokens->UsdMaya, _tokens->ShadingModePlugin };
207-
std::call_once(_shadingModesLoaded, []() {
208-
PlugPluginPtrVector plugins = PlugRegistry::GetInstance().GetAllPlugins();
209-
std::string mayaPlugin;
210-
TF_FOR_ALL(plugIter, plugins)
211-
{
212-
PlugPluginPtr plug = *plugIter;
213-
if (_HasMayaPlugin(plug, scope, &mayaPlugin)) {
214-
if (!mayaPlugin.empty()) {
215-
TF_DEBUG(PXRUSDMAYA_REGISTRY)
216-
.Msg(
217-
"Found shading mode plugin %s: Loading via Maya API %s.\n",
218-
plug->GetName().c_str(),
219-
mayaPlugin.c_str());
220-
std::string loadPluginCmd
221-
= TfStringPrintf("loadPlugin -quiet %s", mayaPlugin.c_str());
222-
if (MGlobal::executeCommand(loadPluginCmd.c_str())) {
223-
// Need to ensure Python script modules are loaded
224-
// properly for this library (Maya's loadPlugin will not
225-
// load script modules like TfDlopen would).
226-
TfScriptModuleLoader::GetInstance().LoadModules();
227-
} else {
228-
TF_CODING_ERROR("Unable to load mayaplugin %s\n", mayaPlugin.c_str());
229-
}
230-
} else {
231-
TF_DEBUG(PXRUSDMAYA_REGISTRY)
232-
.Msg(
233-
"Found shading mode plugin %s: Loading via USD API.\n",
234-
plug->GetName().c_str());
235-
plug->Load();
236-
}
237-
}
238-
}
239-
});
243+
static std::once_flag _loaded;
244+
std::call_once(_loaded, []() { _FindAndLoadUsdMayaPlugins(_tokens->ShadingModePlugin); });
240245
}
241246

242247
/* static */
243248
void UsdMaya_RegistryHelper::LoadJobContextPlugins()
244249
{
245-
static std::once_flag _jobContextsLoaded;
246-
static std::vector<TfToken> scope = { _tokens->UsdMaya, _tokens->JobContextPlugin };
247-
std::call_once(_jobContextsLoaded, []() {
248-
PlugPluginPtrVector plugins = PlugRegistry::GetInstance().GetAllPlugins();
249-
std::string mayaPlugin;
250-
TF_FOR_ALL(plugIter, plugins)
251-
{
252-
PlugPluginPtr plug = *plugIter;
253-
if (_HasMayaPlugin(plug, scope, &mayaPlugin)) {
254-
if (!mayaPlugin.empty()) {
255-
TF_DEBUG(PXRUSDMAYA_REGISTRY)
256-
.Msg(
257-
"Found job context plugin %s: Loading via Maya API %s.\n",
258-
plug->GetName().c_str(),
259-
mayaPlugin.c_str());
260-
std::string loadPluginCmd
261-
= TfStringPrintf("loadPlugin -quiet %s", mayaPlugin.c_str());
262-
if (MGlobal::executeCommand(loadPluginCmd.c_str())) {
263-
// Need to ensure Python script modules are loaded
264-
// properly for this library (Maya's loadPlugin will not
265-
// load script modules like TfDlopen would).
266-
TfScriptModuleLoader::GetInstance().LoadModules();
267-
} else {
268-
TF_CODING_ERROR("Unable to load mayaplugin %s\n", mayaPlugin.c_str());
269-
}
270-
} else {
271-
TF_DEBUG(PXRUSDMAYA_REGISTRY)
272-
.Msg(
273-
"Found job context plugin %s: Loading via USD API.\n",
274-
plug->GetName().c_str());
275-
plug->Load();
276-
}
277-
}
278-
}
279-
});
250+
static std::once_flag _loaded;
251+
std::call_once(_loaded, []() { _FindAndLoadUsdMayaPlugins(_tokens->JobContextPlugin); });
252+
}
253+
254+
/* static */
255+
void UsdMaya_RegistryHelper::LoadImportChaserPlugins()
256+
{
257+
static std::once_flag _loaded;
258+
std::call_once(_loaded, []() { _FindAndLoadUsdMayaPlugins(_tokens->ImportChaserPlugin); });
259+
}
260+
261+
/* static */
262+
void UsdMaya_RegistryHelper::LoadExportChaserPlugins()
263+
{
264+
static std::once_flag _loaded;
265+
std::call_once(_loaded, []() { _FindAndLoadUsdMayaPlugins(_tokens->ExportChaserPlugin); });
280266
}
281267

282268
/* static */

lib/mayaUsd/fileio/registryHelper.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,30 @@ struct UsdMaya_RegistryHelper
7474
/// usdMaya will try to load the "mayaPlugin" when job contexts are first accessed.
7575
static void LoadJobContextPlugins();
7676

77+
/// Searches the plugInfos and looks for ImportChaserPlugin.
78+
///
79+
/// "UsdMaya" : {
80+
/// "ImportChaserPlugin" : {
81+
/// "mayaPlugin" : "myImportChaserPlugin"
82+
/// }
83+
/// }
84+
///
85+
/// At that scope, it expects an optional "mayaPlugin" key.
86+
/// usdMaya will try to load the plugin when import chasers are first accessed.
87+
static void LoadImportChaserPlugins();
88+
89+
/// Searches the plugInfos and looks for ExportChaserPlugin.
90+
///
91+
/// "UsdMaya" : {
92+
/// "ExportChaserPlugin" : {
93+
/// "mayaPlugin" : "myExportChaserPlugin"
94+
/// }
95+
/// }
96+
///
97+
/// At that scope, it expects an optional "mayaPlugin" key.
98+
/// usdMaya will try to load the plugin when export chasers are first accessed.
99+
static void LoadExportChaserPlugins();
100+
77101
/// Searches the plugInfos for metadata dictionaries at the given \p scope,
78102
/// and composes them together.
79103
/// The scope are the nested keys to search through in the plugInfo (for

0 commit comments

Comments
 (0)