-
Notifications
You must be signed in to change notification settings - Fork 201
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
MAYA-106075 - USD selection highlighting doesn't take Color Settings into consideration #2033
Changes from all commits
16f6157
08a95c8
33baf46
dede536
8469047
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
#include <pxr/usd/usd/prim.h> | ||
#include <pxr/usdImaging/usdImaging/delegate.h> | ||
|
||
#include <maya/MColorPickerUtilities.h> | ||
#include <maya/MEventMessage.h> | ||
#include <maya/MFileIO.h> | ||
#include <maya/MFnPluginData.h> | ||
|
@@ -1485,7 +1486,7 @@ GfVec3f ProxyRenderDelegate::GetCurveDefaultColor() | |
{ | ||
MDoubleArray curveColorResult; | ||
{ | ||
std::lock_guard<std::mutex> _(_mayaCommandEngineMutex); | ||
std::lock_guard<std::mutex> mutexGuard(_mayaCommandEngineMutex); | ||
MGlobal::executeCommand( | ||
"int $index = `displayColor -q -dormant \"curve\"`; colorIndex -q $index;", | ||
curveColorResult); | ||
|
@@ -1494,18 +1495,75 @@ GfVec3f ProxyRenderDelegate::GetCurveDefaultColor() | |
if (curveColorResult.length() == 3) { | ||
return GfVec3f(curveColorResult[0], curveColorResult[1], curveColorResult[2]); | ||
} else { | ||
TF_WARN("Failed to obtain curve default color"); | ||
// In case of an error, return the default navy-blue color | ||
return GfVec3f(0.000f, 0.016f, 0.376f); | ||
} | ||
} | ||
|
||
//! \brief | ||
const MColor& ProxyRenderDelegate::GetSelectionHighlightColor(bool lead) const | ||
MColor ProxyRenderDelegate::GetSelectionHighlightColor(const TfToken& className) | ||
{ | ||
static const MColor kLeadColor(0.056f, 1.0f, 0.366f, 1.0f); | ||
static const MColor kActiveColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
static const MColor kDefaultLeadColor(0.056f, 1.0f, 0.366f, 1.0f); | ||
static const MColor kDefaultActiveColor(1.0f, 1.0f, 1.0f, 1.0f); | ||
|
||
// Prepare to construct the query command. | ||
bool fromPalette = true; | ||
const char* queryName = "unsupported"; | ||
if (className.IsEmpty()) { | ||
fromPalette = false; | ||
queryName = "lead"; | ||
} else if (className == HdPrimTypeTokens->mesh) { | ||
fromPalette = false; | ||
queryName = "polymeshActive"; | ||
} else if (className == HdPrimTypeTokens->basisCurves) { | ||
queryName = "curve"; | ||
} | ||
|
||
// Construct the query command string. | ||
MString queryCommand; | ||
if (fromPalette) { | ||
queryCommand = "int $index = `displayColor -q -active \""; | ||
queryCommand += queryName; | ||
queryCommand += "\"`; colorIndex -q $index;"; | ||
} else { | ||
queryCommand = "displayRGBColor -q \""; | ||
queryCommand += queryName; | ||
queryCommand += "\""; | ||
} | ||
|
||
// Query and return the selection color. | ||
{ | ||
MDoubleArray colorResult; | ||
std::lock_guard<std::mutex> mutexGuard(_mayaCommandEngineMutex); | ||
MGlobal::executeCommand(queryCommand, colorResult); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a caller passes in a className which isn't valid do we get some kind of error we can warn about? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. executeCommand runs with displayEnabled = false, so I guess it will not write any error info into log. I think it would be good to set displayEnabled to true here |
||
|
||
if (colorResult.length() == 3) { | ||
MColor color(colorResult[0], colorResult[1], colorResult[2]); | ||
|
||
if (className.IsEmpty()) { | ||
// The 'lead' color is returned in display space, so we need to convert it to | ||
// rendering space. However, function MColorPickerUtilities::applyViewTransform | ||
// is supported only starting from Maya 2023, so in opposite case we just return | ||
// the default lead color. | ||
#if MAYA_API_VERSION >= 20230000 | ||
return MColorPickerUtilities::applyViewTransform( | ||
color, MColorPickerUtilities::kInverse); | ||
#else | ||
return kDefaultLeadColor; | ||
#endif | ||
} else { | ||
return color; | ||
} | ||
} else { | ||
TF_WARN( | ||
"Failed to obtain selection highlight color for '%s' objects", | ||
className.IsEmpty() ? "lead" : className.GetString().c_str()); | ||
} | ||
} | ||
|
||
return lead ? kLeadColor : kActiveColor; | ||
// In case of any failure, return the default color | ||
return className.IsEmpty() ? kDefaultLeadColor : kDefaultActiveColor; | ||
} | ||
|
||
bool ProxyRenderDelegate::DrawRenderTag(const TfToken& renderTag) const | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this little bit of logic deciding which color to use based on the selection status move into a common location? I'm not sure if it makes sense on drawScene, maybe if we do a shared parentClass for rprims this logic could live there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think I will address that as part of my future work on points.