Skip to content

Commit

Permalink
MAYA-94667 deselect USD objs by clicking void area (AnimalLogic#21)
Browse files Browse the repository at this point in the history
* MAYA-94667 deselect USD objs by clicking void area

* MAYA-94667 code review suggestions

* MAYA-94667 code review suggestion
  • Loading branch information
Huidong Chen authored and GitHub Enterprise committed Oct 26, 2018
1 parent 54b6b26 commit 54c91f7
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
122 changes: 61 additions & 61 deletions lib/AL_USDMaya/AL/usdmaya/nodes/ProxyDrawOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ ProxyDrawOverride::ProxyDrawOverride(const MObject& obj)
#else
: MHWRender::MPxDrawOverride(obj, draw)
#endif
, fSelectionListAdjustmentMode(MGlobal::kReplaceList)
{
TF_DEBUG(ALUSDMAYA_DRAW).Msg("ProxyDrawOverride::ProxyDrawOverride\n");
}
Expand Down Expand Up @@ -492,6 +493,52 @@ SdfPathVector ProxyDrawOverrideSelectionHelper::m_paths;


#if MAYA_API_VERSION >= 20190000
//----------------------------------------------------------------------------------------------------------------------
// Maya calls this function during the pre-filtering phase of Viewport 2.0 selection
// in order to setup the selection context of the given DAG object.
//
// However, we override this function for a different purpose, i.e. to clear the
// Ufe::GlobalSelection in advance if we are going to replace the selection list.
// Later if the bounds of the proxy shape passes the selection region culling
// test, userSelect() will be called and we will add new hit paths; otherwise
// userSelect() will not be called and we can de-select USD objects.
//
void ProxyDrawOverride::updateSelectionGranularity(
const MDagPath& path,
MSelectionContext& selectionContext)
{
// Maya determines the selection list adjustment mode by Ctrl/Shift modifiers.
int modifiers = 0;
MGlobal::executeCommand("getModifiers", modifiers);

const bool shiftHeld = (modifiers % 2);
const bool ctrlHeld = (modifiers / 4 % 2);

if (shiftHeld && ctrlHeld)
{
fSelectionListAdjustmentMode = MGlobal::kAddToList;
}
else if (ctrlHeld)
{
fSelectionListAdjustmentMode = MGlobal::kRemoveFromList;
}
else if (shiftHeld)
{
fSelectionListAdjustmentMode = MGlobal::kXORWithList;
}
else
{
fSelectionListAdjustmentMode = MGlobal::kReplaceList;

#if defined(WANT_UFE_BUILD)
if (ArchHasEnv("MAYA_WANT_UFE_SELECTION"))
{
Ufe::GlobalSelection::get()->clear();
}
#endif
}
}

//----------------------------------------------------------------------------------------------------------------------
bool ProxyDrawOverride::userSelect(
const MHWRender::MSelectionInfo& selectInfo,
Expand Down Expand Up @@ -602,24 +649,8 @@ bool ProxyDrawOverride::userSelect(
{
if(hitSelected)
{
int mods;
MString cmd = "getModifiers";
MGlobal::executeCommand(cmd, mods);

bool shiftHeld = (mods % 2);
bool ctrlHeld = (mods / 4 % 2);
MGlobal::ListAdjustment mode = MGlobal::kReplaceList;
if(shiftHeld && ctrlHeld)
mode = MGlobal::kAddToList;
else
if(ctrlHeld)
mode = MGlobal::kRemoveFromList;
else
if(shiftHeld)
mode = MGlobal::kXORWithList;

MString command = "AL_usdmaya_ProxyShapeSelect";
switch(mode)
switch(fSelectionListAdjustmentMode)
{
case MGlobal::kReplaceList: command += " -r"; break;
case MGlobal::kRemoveFromList: command += " -d"; break;
Expand Down Expand Up @@ -654,22 +685,6 @@ bool ProxyDrawOverride::userSelect(
}
else
{
int mods;
MString cmd = "getModifiers";
MGlobal::executeCommand(cmd, mods);

bool shiftHeld = (mods % 2);
bool ctrlHeld = (mods / 4 % 2);
MGlobal::ListAdjustment mode = MGlobal::kReplaceList;
if(shiftHeld && ctrlHeld)
mode = MGlobal::kAddToList;
else
if(ctrlHeld)
mode = MGlobal::kRemoveFromList;
else
if(shiftHeld)
mode = MGlobal::kXORWithList;

SdfPathVector paths;
if (!hitBatch.empty())
{
Expand Down Expand Up @@ -733,10 +748,10 @@ bool ProxyDrawOverride::userSelect(
return false;
}

Ufe::Selection dstSelection; // Only used for kReplaceList
// Get the paths
if (paths.size())
{
auto globalSelection = Ufe::GlobalSelection::get();

for (auto it : paths)
{
// Build a path segment of the USD picked object
Expand All @@ -745,48 +760,33 @@ bool ProxyDrawOverride::userSelect(
// Create a sceneItem
const Ufe::SceneItem::Ptr& si{ handler->createItem(proxyShape->ufePath() + ps_usd) };

auto globalSelection = Ufe::GlobalSelection::get();

switch (mode)
switch (fSelectionListAdjustmentMode)
{
case MGlobal::kReplaceList:
{
// Add the sceneItem to dstSelection
dstSelection.append(si);
}
break;
// The list has been cleared in earlier phase - updateSelectionGranularity(),
// therefore we can add the new hit paths directly.
globalSelection->append(si);
break;
case MGlobal::kAddToList:
{
// Add the sceneItem to global selection
globalSelection->append(si);
}
break;
break;
case MGlobal::kRemoveFromList:
{
// Remove the sceneItem to global selection
globalSelection->remove(si);
}
break;
break;
case MGlobal::kXORWithList:
{
if (!globalSelection->remove(si)) {
if (!globalSelection->remove(si))
{
globalSelection->append(si);
}
break;
}
break;
}
}

if (mode == MGlobal::kReplaceList) {
// Add to Global selection
Ufe::GlobalSelection::get()->replaceWith(dstSelection);
}
}
}
else
{
#endif
switch (mode)
switch (fSelectionListAdjustmentMode)
{
case MGlobal::kReplaceList:
{
Expand Down
9 changes: 8 additions & 1 deletion lib/AL_USDMaya/AL/usdmaya/nodes/ProxyDrawOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include "../Api.h"

#include "maya/MGlobal.h"
#include "maya/MPxDrawOverride.h"
#include "AL/usdmaya/ForwardDeclares.h"

Expand Down Expand Up @@ -121,8 +122,14 @@ class ProxyDrawOverride

private:
static MUint64 s_lastRefreshFrameStamp;


MGlobal::ListAdjustment fSelectionListAdjustmentMode;

#if MAYA_API_VERSION >= 20190000
void updateSelectionGranularity(
const MDagPath& path,
MSelectionContext& selectionContext) override;

bool wantUserSelection() const override {return true;}

bool userSelect(
Expand Down

0 comments on commit 54c91f7

Please sign in to comment.