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

MAYA-105577 MAYA-105597 Improve accessor plug name and cleanup tests #838

Merged
merged 4 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 11 additions & 0 deletions lib/mayaUsd/fileio/utils/readUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include <maya/MDoubleArray.h>
#include <maya/MFloatArray.h>
#include <maya/MFnAttribute.h>
#include <maya/MFnCompoundAttribute.h>
#include <maya/MFnDoubleArrayData.h>
#include <maya/MFnEnumAttribute.h>
#include <maya/MFnFloatArrayData.h>
Expand Down Expand Up @@ -150,6 +151,16 @@ _FindOrCreateMayaNumericAttr(
attr.setUsedAsColor(true);
}

const unsigned int numChildren = MFnCompoundAttribute(attrObj).numChildren();
if(numChildren < 4u) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can't be right, you must be off by one. If your tests didn't catch this, then I guess we're missing a bit of coverage :)

Copy link
Author

Choose a reason for hiding this comment

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

Ehh...late-night coding. Of course, it can't be right.

Copy link
Author

Choose a reason for hiding this comment

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

Done - 0dd8d8a

static MString suffix[4] = {" X", " Y", " Z", " W"};
for(unsigned int i = 0; i < numChildren; i++) {
MFnAttribute(attr.child(i)).setNiceNameOverride(niceName+suffix[i]);
}
} else {
TF_CODING_ERROR("Unexpected number of children on numeric attribute");
}

modifier.addAttribute(depNode.object(), attrObj);
modifier.doIt();
return attrObj;
Expand Down
20 changes: 10 additions & 10 deletions lib/mayaUsd/nodes/proxyAccessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,13 @@ MAYAUSD_NS_DEF
);

//! \brief Test if given plug name is matching the convention used by accessor plugs
bool isAccessorValuePlugName(const char* plugName)
bool isAccessorPlugName(const char* plugName)
{
return (strncmp(plugName, "AccessValue_", 12) == 0);
return (strncmp(plugName, "AP_", 3) == 0);
}

//! \brief Returns True is given plug is categorized as input plug, or False if output plug
bool isAccessorValueInputPlug(const MPlug& plug)
bool isAccessorInputPlug(const MPlug& plug)
{
if (plug.isDestination())
return true;
Expand Down Expand Up @@ -117,7 +117,7 @@ MAYAUSD_NS_DEF
object,
[](MNodeMessage::AttributeMessage msg, MPlug& plug, void* clientData) {
if (clientData) {
if (isAccessorValuePlugName(plug.partialName().asChar())) {
if (isAccessorPlugName(plug.partialName().asChar())) {
static_cast<ProxyAccessor*>(clientData)->invalidateAccessorItems();
}
}
Expand All @@ -135,7 +135,7 @@ MAYAUSD_NS_DEF
== 0)
return;

if (isAccessorValuePlugName(plug.partialName().asChar())) {
if (isAccessorPlugName(plug.partialName().asChar())) {
auto* accessor = static_cast<ProxyAccessor*>(clientData);
accessor->invalidateAccessorItems();

Expand Down Expand Up @@ -218,7 +218,7 @@ MAYAUSD_NS_DEF
continue;

MString name = attr.name();
if (!isAccessorValuePlugName(name.asChar()))
if (!isAccessorPlugName(name.asChar()))
continue;

MPlug valuePlug(node, attr.object());
Expand Down Expand Up @@ -268,7 +268,7 @@ MAYAUSD_NS_DEF
continue;
}

if (isAccessorValueInputPlug(valuePlug)) {
if (isAccessorInputPlug(valuePlug)) {
TF_DEBUG(USDMAYA_PROXYACCESSOR).Msg("Added INPUT '%s'\n", path.GetText());
_accessorInputItems.emplace_back(valuePlug, path, converter);
} else {
Expand All @@ -293,10 +293,10 @@ MAYAUSD_NS_DEF
if (_accessorInputItems.size() == 0 && _accessorOutputItems.size() == 0)
return MS::kUnknownParameter;

const bool accessorValuePlug = isAccessorValuePlugName(plug.partialName().asChar());
const bool isInputValuePlug = accessorValuePlug && isAccessorValueInputPlug(plug);
const bool accessorPlug = isAccessorPlugName(plug.partialName().asChar());
const bool isInputPlug = accessorPlug && isAccessorInputPlug(plug);

if (isInputValuePlug || !plug.isDynamic() || plug == _forceCompute) {
if (isInputPlug || !plug.isDynamic() || plug == _forceCompute) {
TF_DEBUG(USDMAYA_PROXYACCESSOR)
.Msg("Dirty all outputs from '%s'\n", plug.name().asChar());

Expand Down
3 changes: 2 additions & 1 deletion lib/mayaUsd/nodes/proxyAccessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import maya.cmds as cmds
import maya.OpenMaya as om
import ufe
import re

def getUfeSelection():
try:
Expand Down Expand Up @@ -57,7 +58,7 @@ def getSelectedDagAndPrim():
return getDagAndPrimFromUfe(getUfeSelection())

def getAccessPlugName(sdfPath):
plugNameValueAttr = 'AccessValue_' + str(sdfPath.__hash__())
plugNameValueAttr = 'AP_' + re.sub(r'[^a-zA-Z0-9_]',r'_',str(sdfPath))

return plugNameValueAttr

Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
add_subdirectory(lib)
add_subdirectory(testSamples)
add_subdirectory(testUtils)
Loading