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

Added USD pick mode fixes for VP2 #1731

Merged
merged 1 commit into from
Oct 15, 2021
Merged
Changes from all commits
Commits
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
52 changes: 50 additions & 2 deletions plugin/al/lib/AL_USDMaya/AL/usdmaya/nodes/ProxyDrawOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,42 @@
#include <pxr/base/arch/env.h>
#endif

#include <pxr/usd/usd/modelAPI.h>

namespace AL {
namespace usdmaya {
namespace nodes {
namespace {
//----------------------------------------------------------------------------------------------------------------------
/// \brief Retarget a prim based on the AL_USDMaya's pick mode settings. This will either return new
/// prim to select,
/// or the original prim if no re-targetting occurred.
/// \param prim Attempt to retarget this prim.
/// \return The retargetted prim, or the original.
UsdPrim retargetSelectPrim(const UsdPrim& prim)
{
switch (ProxyShape::PickMode(MGlobal::optionVarIntValue("AL_usdmaya_pickMode"))) {

// Read up prim hierarchy and return first Model kind ancestor as the target prim
case ProxyShape::PickMode::kModels: {
UsdPrim tmpPrim = prim;
while (tmpPrim.IsValid()) {
if (UsdModelAPI(tmpPrim).IsModel()) {
return tmpPrim;
}
tmpPrim = tmpPrim.GetParent();
}
}

case ProxyShape::PickMode::kPrims:
case ProxyShape::PickMode::kInstances:
default: {
break;
}
}
return prim;
}

//----------------------------------------------------------------------------------------------------------------------
/// \brief user data struct - holds the info needed to render the scene
//----------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -578,8 +610,13 @@ bool ProxyDrawOverride::userSelect(
MGlobal::executeCommand(command, nodes, false, true);

for (const auto& it : hitBatch) {
auto path = it.first;
auto obj = proxyShape->findRequiredPath(path);
// Retarget hit path based on pick mode policy. The retargeted prim must
// align with the path used in the 'AL_usdmaya_ProxyShapeSelect' command.
const SdfPath hitPath = it.first;
const UsdPrim retargetedHitPrim
= retargetSelectPrim(proxyShape->getUsdStage()->GetPrimAtPath(hitPath));
const MObject obj = proxyShape->findRequiredPath(retargetedHitPrim.GetPath());

if (obj != MObject::kNullObj) {
MFnDagNode dagNode(obj);
MDagPath dg;
Expand Down Expand Up @@ -702,6 +739,17 @@ bool ProxyDrawOverride::userSelect(
}
} else {
#endif

// Massage hit paths to align with pick mode policy
for (std::size_t i = 0; i < paths.size(); ++i) {
const SdfPath& path = paths[i];
const UsdPrim retargetedPrim
= retargetSelectPrim(proxyShape->getUsdStage()->GetPrimAtPath(path));
if (retargetedPrim.GetPath() != path) {
paths[i] = retargetedPrim.GetPath();
}
}

switch (listAdjustment) {
case MGlobal::kReplaceList: {
MString command;
Expand Down