Skip to content

Commit

Permalink
MAYA-95136 consistent behavior with legacy VP1 selection (AnimalLogic#20
Browse files Browse the repository at this point in the history
)
  • Loading branch information
Huidong Chen authored and GitHub Enterprise committed Oct 25, 2018
1 parent 69253c4 commit 54b6b26
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 20 deletions.
7 changes: 0 additions & 7 deletions docs/build.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,6 @@ will force VP2 to use the "OpenGL -- Legacy" profile

see [Autodesk docs](https://knowledge.autodesk.com/support/maya/learn-explore/caas/CloudHelp/cloudhelp/2017/ENU/Maya/files/GUID-4928A912-DA6C-4734-863B-AB5959DA73C9-htm.html)

For selection to work, also need to set
```
MAYA_VP2_USE_VP1_SELECTION=1
```
as mentioned here:
http://help.autodesk.com/view/MAYAUL/2017/ENU/?guid=__files_GUID_343690A7_F76D_4CD2_A964_E10DA7B5BDF8_htm

## How to run the tests ##
Unit tests of AL_USDMaya have been wrapped into a regular maya plugin (_AL_USDMayaTestPlugin_). Its path simply needs to be part of the MAYA_PLUG_IN_PATH environment variable and then it can be loaded.

Expand Down
94 changes: 81 additions & 13 deletions lib/AL_USDMaya/AL/usdmaya/nodes/ProxyDrawOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include "AL/usdmaya/TypeIDs.h"
#include "pxr/base/arch/env.h"
#include "ufe/sceneItem.h"
#include "ufe/runTimeMgr.h"
#include "ufe/globalSelection.h"
#include "ufe/observableSelection.h"
#endif
Expand Down Expand Up @@ -721,9 +722,73 @@ bool ProxyDrawOverride::userSelect(
}
}

switch(mode)
#if defined(WANT_UFE_BUILD)
if (ArchHasEnv("MAYA_WANT_UFE_SELECTION"))
{
case MGlobal::kReplaceList:
// Get the Hierarchy Handler of USD - Id = 2
auto handler{ Ufe::RunTimeMgr::instance().hierarchyHandler(2) };
if (handler == nullptr)
{
MGlobal::displayError("USD Hierarchy handler has not been loaded - Picking is not possible");
return false;
}

Ufe::Selection dstSelection; // Only used for kReplaceList
// Get the paths
if (paths.size())
{
for (auto it : paths)
{
// Build a path segment of the USD picked object
Ufe::PathSegment ps_usd(it.GetText(), 2, '/');

// Create a sceneItem
const Ufe::SceneItem::Ptr& si{ handler->createItem(proxyShape->ufePath() + ps_usd) };

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

switch (mode)
{
case MGlobal::kReplaceList:
{
// Add the sceneItem to dstSelection
dstSelection.append(si);
}
break;
case MGlobal::kAddToList:
{
// Add the sceneItem to global selection
globalSelection->append(si);
}
break;
case MGlobal::kRemoveFromList:
{
// Remove the sceneItem to global selection
globalSelection->remove(si);
}
break;
case MGlobal::kXORWithList:
{
if (!globalSelection->remove(si)) {
globalSelection->append(si);
}
}
break;
}
}

if (mode == MGlobal::kReplaceList) {
// Add to Global selection
Ufe::GlobalSelection::get()->replaceWith(dstSelection);
}
}
}
else
{
#endif
switch (mode)
{
case MGlobal::kReplaceList:
{
MString command;
if(!proxyShape->selectedPaths().empty())
Expand Down Expand Up @@ -758,8 +823,8 @@ bool ProxyDrawOverride::userSelect(
}
break;

case MGlobal::kAddToHeadOfList:
case MGlobal::kAddToList:
case MGlobal::kAddToHeadOfList:
case MGlobal::kAddToList:
{
MString command;
if(paths.size())
Expand All @@ -785,7 +850,7 @@ bool ProxyDrawOverride::userSelect(
}
break;

case MGlobal::kRemoveFromList:
case MGlobal::kRemoveFromList:
{
if(!proxyShape->selectedPaths().empty() && paths.size())
{
Expand All @@ -806,7 +871,7 @@ bool ProxyDrawOverride::userSelect(
}
break;

case MGlobal::kXORWithList:
case MGlobal::kXORWithList:
{
auto& slpaths = proxyShape->selectedPaths();
bool hasSelectedItems = false;
Expand Down Expand Up @@ -859,14 +924,17 @@ bool ProxyDrawOverride::userSelect(
}
}
break;
}
}

MString final_command = "AL_usdmaya_ProxyShapePostSelect \"";
MFnDependencyNode fn(proxyShape->thisMObject());
final_command += fn.name();
final_command += "\"";
proxyShape->setChangedSelectionState(true);
MGlobal::executeCommandOnIdle(final_command, false);
MString final_command = "AL_usdmaya_ProxyShapePostSelect \"";
MFnDependencyNode fn(proxyShape->thisMObject());
final_command += fn.name();
final_command += "\"";
proxyShape->setChangedSelectionState(true);
MGlobal::executeCommandOnIdle(final_command, false);
#if defined(WANT_UFE_BUILD)
} // else MAYA_WANT_UFE_SELECTION
#endif
}

ProxyDrawOverrideSelectionHelper::m_paths.clear();
Expand Down

0 comments on commit 54b6b26

Please sign in to comment.