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

HYDRA-1058/HYDRA-970 : GeomSubsets picking filter + Fix multi-selection when single-picking #143

Merged
merged 76 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
6a408af
HYDRA-1058 : Rough basic structure for GeomSubset picking
debloip-adsk Jun 27, 2024
8411237
HYDRA-1058 : Attempt to add menu item to USD selection mode menu
debloip-adsk Jun 27, 2024
d22f028
HYDRA-1058 : Functioning registering of menu items in USD selection menu
debloip-adsk Jun 28, 2024
498894a
HYDRA-1058 : Functional picking mode menu
debloip-adsk Jun 28, 2024
aa1cd64
HYDRA-1058 : Cleanup picking code
debloip-adsk Jun 28, 2024
2a7cc0f
HYDRA-1058 : Cleanup pick interpretation code
debloip-adsk Jun 28, 2024
10a0657
HYDRA-1058 : Move comment
debloip-adsk Jun 28, 2024
1af6821
HYDRA-1058 : Avoid unnecessary idle events to create pick mode UI
debloip-adsk Jun 28, 2024
1e8ed39
HYDRA-1058 : Move all GeomSubset MEL code into same script
debloip-adsk Jun 28, 2024
aa48112
HYDRA-1058 : Cleanup GeomSubsets UI setup code
debloip-adsk Jun 28, 2024
98445a4
HYDRA-1058 : Tear down UI on plugin unload and if MayaUSD is unloaded…
debloip-adsk Jun 28, 2024
ce3a01d
HYDRA-1058 : Simplify data keeping for UI teardown
debloip-adsk Jun 28, 2024
b81e164
HYDRA-1058 : Remove print debugging statements
debloip-adsk Jun 28, 2024
828fbea
HYDRA-1058 : Reorder operations
debloip-adsk Jun 28, 2024
0e37282
HYDRA-1058 : Cleanup headers and rename method
debloip-adsk Jun 28, 2024
7f790ac
HYDRA-1058 : Add comments to explain how the pick mode menu is hooked up
debloip-adsk Jun 28, 2024
ba06415
HYDRA-1058 : Remove headers
debloip-adsk Jun 28, 2024
238cdb0
HYDRA-1058 : Rename prims picking mode
debloip-adsk Jun 28, 2024
3b1cf87
HYDRA-1058 : Adjust UI label
debloip-adsk Jun 28, 2024
6037212
HYDRA-1058 : Clarify naming
debloip-adsk Jun 29, 2024
696fdea
HYDRA-1058 : Add comments
debloip-adsk Jun 29, 2024
3b6e56f
HYDRA-1058 : Handle single selection pick mode
debloip-adsk Jul 2, 2024
a0dc0a4
HYDRA-1058 : Fix UI deletion and re-creation
debloip-adsk Jul 2, 2024
a04b5b6
HYDRA-1058 : Remove select menu callback on UI teardown
debloip-adsk Jul 2, 2024
21b6ce9
HYDRA-1058 : Fix callbacks clear command
debloip-adsk Jul 2, 2024
a6d40de
HYDRA-1058 : Fix UI deletion on plugin unload and re-load
debloip-adsk Jul 2, 2024
da990fb
HYDRA-1058 : Remove prints
debloip-adsk Jul 2, 2024
193d5ff
HYDRA-1058 : Extend check for UI creation for consistency
debloip-adsk Jul 2, 2024
a8dedc2
HYDRA-1058 : Add example scene
debloip-adsk Jul 2, 2024
02e3337
HYDRA-1058 : Fix GeomSubsets pick resolution for Xform parent
debloip-adsk Jul 2, 2024
ea54d9e
HYDRA-1058 : Use anonymous namespace variables instead of static
debloip-adsk Jul 2, 2024
0e9e601
HYDRA-1058 : Refactor plugin loading callbacks registration
debloip-adsk Jul 2, 2024
68d0a55
HYDRA-1058 : Remove superfluous UI code changes
debloip-adsk Jul 2, 2024
3919d7b
HYDRA-1058 : Add upper half geom subset sphere scene
debloip-adsk Jul 2, 2024
f712c28
HYDRA-1058 : Simplify GeomSubset prim
debloip-adsk Jul 2, 2024
168ef78
HYDRA-1058 : Add upper half geom subset cube scene
debloip-adsk Jul 2, 2024
6b5f1d2
HYDRA-1058 : Simplify cube scene
debloip-adsk Jul 2, 2024
74a39a7
HYDRA-1058 : Fixup
debloip-adsk Jul 2, 2024
0c2f0ee
HYDRA-1058 : Scene with instancing and materials
debloip-adsk Jul 2, 2024
706cf20
HYDRA-1058 : Adjust scene
debloip-adsk Jul 2, 2024
9d3a68b
HYDRA-1058 : Add test files
debloip-adsk Jul 2, 2024
b5a5598
HYDRA-1058 : Adjust test scene
debloip-adsk Jul 3, 2024
86a7ae1
HYDRA-1058 : GeomSubsets picking marquee select test
debloip-adsk Jul 3, 2024
15fe9ac
HYDRA-1058 : GeomSubset picking test
debloip-adsk Jul 3, 2024
0521787
HYDRA-1058 : Fallback picking test
debloip-adsk Jul 3, 2024
d269647
HYDRA-1058 : Instance GeomSubset picking test
debloip-adsk Jul 3, 2024
d6a774d
HYDRA-1058 : Instance fallback picking test
debloip-adsk Jul 3, 2024
f93a62e
HYDRA-1058 : Refactor and cleanup testUtils
debloip-adsk Jul 3, 2024
0c15712
HYDRA-1058 : Cleanup testGeomSubsetsPicking.py
debloip-adsk Jul 3, 2024
dc3720d
HYDRA-1058 : Remove dead code
debloip-adsk Jul 3, 2024
3574410
HYDRA-1058 : Fixup
debloip-adsk Jul 3, 2024
44d7aba
HYDRA-1058 : Extract out common test code
debloip-adsk Jul 4, 2024
a2d2314
HYDRA-1058 : Extract out common test code for instance tests
debloip-adsk Jul 4, 2024
9d4a414
HYDRA-1058 : Cleanup tests
debloip-adsk Jul 4, 2024
514fa73
HYDRA-1058 : Cleanup test headers and increase thoroughness
debloip-adsk Jul 4, 2024
f2b8201
HYDRA-1058 : Remove unused file
debloip-adsk Jul 4, 2024
502d69c
HYDRA-1058 : Rename picking modes and use token-based approach for ex…
debloip-adsk Jul 4, 2024
5b8fcc4
HYDRA-1058 : Small touchups
debloip-adsk Jul 4, 2024
c642055
Merge branch 'dev' into debloip/HYDRA-1058/geomsubset-picking
debloip-adsk Jul 4, 2024
cabdfab
HYDRA-1058 : Cleanup GeomSubsets mel file
debloip-adsk Jul 4, 2024
22333dd
HYDRA-1058 : Add localization support
debloip-adsk Jul 4, 2024
7469854
HYDRA-1058 : Add copyright notices
debloip-adsk Jul 4, 2024
d580ab8
HYDRA-1058 : Add comments in test
debloip-adsk Jul 4, 2024
d7ff4e3
HYDRA-1058 : Handle build support for USD < 2403
debloip-adsk Jul 4, 2024
84545f2
HYDRA-1058 : Skip GeomSubset picking tests if USD version does not su…
debloip-adsk Jul 4, 2024
b174995
HYDRA-1058 : Debug OSX and Linux failure #1
debloip-adsk Jul 4, 2024
8d0e85d
HYDRA-1058 : Debug OSX and Linux #2
debloip-adsk Jul 4, 2024
eb9ef75
MAYA-xxxx <one line description>
debloip-adsk Jul 4, 2024
829244b
HYDRA-1058 : Debug OSX #1
debloip-adsk Jul 5, 2024
dbfd624
HYDRA-1058 : Adjust test setup to use markers for clicking
debloip-adsk Jul 5, 2024
a3b032a
HYDRA-1058 : Rename resolvePrimAndInstancePicking
debloip-adsk Jul 5, 2024
8b12c6f
HYDRA-1058 : Fix typo
debloip-adsk Jul 5, 2024
66f6d14
HYDRA-1058 : Revert obsolete changes
debloip-adsk Jul 5, 2024
fc5eb3f
HYDRA-1058 : Cleanup testGeomSubsetsPicking.cpp
debloip-adsk Jul 5, 2024
b83f710
HYDRA-1058 : Add link to MayaUSD register strings MEL file
debloip-adsk Jul 5, 2024
d4768e8
HYDRA-1058 : Add comment
debloip-adsk Jul 5, 2024
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
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,11 @@ if(BUILD_HDSB_PLUGIN)
endif()
endif()

#------------------------------------------------------------------------------
# scripts
#------------------------------------------------------------------------------
add_subdirectory(scripts)

#------------------------------------------------------------------------------
# install
#------------------------------------------------------------------------------
Expand Down
110 changes: 97 additions & 13 deletions lib/mayaHydra/mayaPlugin/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@

#include <maya/MFnPlugin.h>
#include <maya/MGlobal.h>
#include <maya/MSceneMessage.h>

#include <memory>
#include <vector>
Expand All @@ -46,13 +47,6 @@

using namespace MayaHydra;

// Don't use smart pointers in the static vector: when Maya is doing its
// default "quick exit" that does not uninitialize plugins, the atexit
// destruction of the overrides in the vector will crash on destruction,
// because Hydra has already destroyed structures these rely on. Simply leak
// the render overrides in this case.
static std::vector<PXR_NS::MtohRenderOverride*> gsRenderOverrides;

#if defined(MAYAHYDRA_VERSION)
#define STRINGIFY(x) #x
#define TOSTRING(x) STRINGIFY(x)
Expand All @@ -62,6 +56,20 @@ static std::vector<PXR_NS::MtohRenderOverride*> gsRenderOverrides;
#define PLUGIN_VERSION "Maya-Hydra experimental"
#endif

namespace {
const std::string kMayaHydraPluginName = "mayaHydra";
const std::string kMayaUsdPluginName = "mayaUsdPlugin";

// Don't use smart pointers in the static vector: when Maya is doing its
// default "quick exit" that does not uninitialize plugins, the atexit
// destruction of the overrides in the vector will crash on destruction,
// because Hydra has already destroyed structures these rely on. Simply leak
// the render overrides in this case.
std::vector<PXR_NS::MtohRenderOverride*> _renderOverrides;

std::vector<MCallbackId> _pluginLoadingCallbackIds;
}

void initialize()
{
Fvp::InitializationParams fvpInitParams;
Expand All @@ -83,6 +91,35 @@ void finalize()
MayaHydra::MayaColorPreferencesTranslator::deleteInstance();
}

void afterPluginLoadCallback( const MStringArray& strs, void* clientData )
{
for (const auto& str : strs) {
// If MayaUSD is being loaded, set up our GeomSubsets picking mode UI.
// This will re-create the "Select" menu callback if it has been previously torn down.
if (str.asChar() == kMayaUsdPluginName) {
MGlobal::executeCommand("if (`exists mayaHydra_GeomSubsetsPickMode_SetupUI`) { mayaHydra_GeomSubsetsPickMode_SetupUI; }");
break;
}
}
}

void beforePluginUnloadCallback( const MStringArray& strs, void* clientData )
{
for (const auto& str : strs) {
// If MayaUSD is being unloaded, tear down our GeomSubsets picking mode UI.
// This resets the variables used to keep track of the UI elements' existence,
// and allows us to recreate them if MayaUSD is reloaded.
// We also do the same if mayaHydra is about to be unloaded : we can't rely on
// the deletion procedure registered through registerUI, as it seems the global
// variables tracking our UI elements have been reset at that point for some reason.
auto strChar = str.asChar();
if (strChar == kMayaUsdPluginName || strChar == kMayaHydraPluginName) {
MGlobal::executeCommand("mayaHydra_GeomSubsetsPickMode_TeardownUI");
break;
}
}
}

PLUGIN_EXPORT MStatus initializePlugin(MObject obj)
{
MString experimental("mayaHydra is experimental.");
Expand Down Expand Up @@ -118,11 +155,54 @@ PLUGIN_EXPORT MStatus initializePlugin(MObject obj)
auto mtohRenderer = std::make_unique<PXR_NS::MtohRenderOverride>(desc);
MStatus status = renderer->registerOverride(mtohRenderer.get());
if (status == MS::kSuccess) {
gsRenderOverrides.push_back(mtohRenderer.release());
_renderOverrides.push_back(mtohRenderer.release());
}
}
}

if (!plugin.registerUIStrings(nullptr, "mayaHydra_registerUIStrings")) {
ret = MS::kFailure;
ret.perror("Error registering mayaHydra UI string resources.");
return ret;
}

if (!plugin.registerUI(
"mayaHydra_registerUI_load",
"mayaHydra_registerUI_unload",
"mayaHydra_registerUI_batch_load",
"mayaHydra_registerUI_batch_unload"))
{
ret = MS::kFailure;
ret.perror("Error registering mayaHydra UI procedures.");
return ret;
}

auto registerPluginLoadingCallback = [&](MSceneMessage::Message pluginLoadingMessage, MMessage::MStringArrayFunction callback) {
MStatus callbackStatus;
MCallbackId callbackId = MSceneMessage::addStringArrayCallback(
pluginLoadingMessage,
callback,
nullptr,
&callbackStatus);
if (callbackStatus) {
_pluginLoadingCallbackIds.push_back(callbackId);
} else {
ret = MS::kFailure;
ret.perror("Error registering mayaHydra plugin loading callback.");
}
};

std::vector<std::pair<MSceneMessage::Message, MMessage::MStringArrayFunction>> pluginLoadingCallbacks = {
{MSceneMessage::Message::kAfterPluginLoad, afterPluginLoadCallback},
{MSceneMessage::Message::kBeforePluginUnload, beforePluginUnloadCallback}
};
for (const auto& pluginLoadingCallback : pluginLoadingCallbacks) {
registerPluginLoadingCallback(pluginLoadingCallback.first, pluginLoadingCallback.second);
if (!ret) {
return ret;
}
}

initialize();

return ret;
Expand All @@ -132,19 +212,23 @@ PLUGIN_EXPORT MStatus uninitializePlugin(MObject obj)
{
finalize();

for (const auto& callbackId : _pluginLoadingCallbackIds) {
MSceneMessage::removeCallback(callbackId);
}

MFnPlugin plugin(obj, "Autodesk", PLUGIN_VERSION, "Any");
MStatus ret = MS::kSuccess;
if (auto* renderer = MHWRender::MRenderer::theRenderer()) {
for (unsigned int i = 0; i < gsRenderOverrides.size(); i++) {
renderer->deregisterOverride(gsRenderOverrides[i]);
delete gsRenderOverrides[i];
for (unsigned int i = 0; i < _renderOverrides.size(); i++) {
renderer->deregisterOverride(_renderOverrides[i]);
delete _renderOverrides[i];
}
}

gsRenderOverrides.clear();
_renderOverrides.clear();

// Clear any registered callbacks
MGlobal::executeCommand("callbacks -cc mayaHydra;");
MGlobal::executeCommand("callbacks -cc -owner mayaHydra;");
Copy link
Collaborator Author

@debloip-adsk debloip-adsk Jul 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the following error that was raised when trying to unload mayaHydra : When clearing callbacks, the owner must be specified. Note that mayaHydra still doesn't unload properly (and already didn't before this PR, even with this fix), but at least that's one issue down.


if (!plugin.deregisterCommand(MtohViewCmd::name)) {
ret = MS::kFailure;
Expand Down
Loading