-
Notifications
You must be signed in to change notification settings - Fork 203
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-110706: Block attribute edits for the remaining transformation stacks (UsdTransform3dCommonAPI, UsdTransform3dMatrixOp) #1308
Conversation
…e remaining transformation stacks ( UsdTransform3dCommonAPI, UsdTransform3dMatrixOp )
|
||
return true; | ||
} | ||
|
||
} // namespace |
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.
Re-factored isAttributeEditAllowed(const PXR_NS::UsdPrim& prim, const std::string& tokenName)
and moved it to lib/mayaUsd/ufe/Utils.cpp
to avoid code duplication.
if (!isAttributeEditAllowed(prim(), "xformOp:translate:pivot")) { | ||
return nullptr; | ||
} | ||
|
||
return std::make_shared<UsdTranslatePivotUndoableCmd>(usdSceneItem(), UsdTimeCode::Default()); | ||
} |
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.
Blocking support for UsdTransform3dCommonAPI.
if (!isAttributeEditAllowed(prim(), "xformOp:scale")) { | ||
return nullptr; | ||
} | ||
|
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.
Blocking support for UsdTransform3dMatrixOp.cpp.
|
||
# authoring new transformation edit is allowed. | ||
self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(transformAttr)) | ||
|
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.
@ppt-adsk Unit test to cover attribute blocking using UsdTransform3dMatrixOp.
# create a xformable and give it a matrix4d xformOp:transform | ||
# This will match the UsdTransform3dMatrixOp, but not the Maya API. | ||
cylinderXformable = UsdGeom.Xformable(cylinderPrim) | ||
transformOp = cylinderXformable.AddTransformOp() | ||
xform = Gf.Matrix4d(1.0).SetTranslate(Gf.Vec3d(10, 20, 30)) | ||
transformOp.Set(xform) | ||
self.assertTrue(cylinderPrim.GetPrim().HasAttribute("xformOp:transform")) |
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.
Line 298 to 304: I create a matrix4d xformOp:transform
with the initial translate values set to [10, 20, 30]
to match the 3dMatrixOp.
cmds.move(65, 20, 10) | ||
self.assertEqual(cylinderXformable.GetXformOpOrderAttr().Get(), | ||
Vt.TokenArray(('xformOp:transform', ))) | ||
|
||
# validate the Matrix4d entires | ||
actual = cylinderXformable.GetLocalTransformation() | ||
expected = Gf.Matrix4d( 1, 0, 0, 0, | ||
0, 1, 0, 0, | ||
0, 0, 1, 0, | ||
65, 20, 10, 1) | ||
|
||
self.assertTrue(Gf.IsClose(actual, expected, 1e-5)) |
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.
Line 321 to 332: Set the translate to a new value [65, 20, 10]
and check the 4x4 affine matrix with the newly translate values.
cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerC) | ||
|
||
# check if transform attribute is editable | ||
transformAttr = cylinderPrim.GetAttribute('xformOp:transform') | ||
self.assertIsNotNone(transformAttr) | ||
|
||
# authoring new transformation edit is not allowed. | ||
self.assertFalse(mayaUsdUfe.isAttributeEditAllowed(transformAttr)) | ||
|
||
# set the edit target to a stronger layer (LayerA) | ||
cmds.mayaUsdEditTarget(proxyShapePath, edit=True, editTarget=subLayerA) | ||
|
||
# authoring new transformation edit is allowed. | ||
self.assertTrue(mayaUsdUfe.isAttributeEditAllowed(transformAttr)) |
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.
Line 335 to 348: tests blocking attribute authoring in weaker or stronger layers for the xformOp:transform
.
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.
Great test! Just a couple of minor details and we're done.
lib/mayaUsd/ufe/Utils.cpp
Outdated
@@ -420,6 +420,27 @@ bool isAttributeEditAllowed(const PXR_NS::UsdAttribute& attr, std::string* errMs | |||
return true; | |||
} | |||
|
|||
bool isAttributeEditAllowed(const PXR_NS::UsdPrim& prim, const std::string& tokenName) |
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.
Instead of taking a string argument and converting to a TfToken for the call to GetAttribute(), we should probably take a const TfToken& directly.
lib/mayaUsd/ufe/Utils.cpp
Outdated
|
||
// check for xformOp:tokenName in XformOpOrderAttr first | ||
UsdGeomXformable xformable(prim); | ||
if (!isAttributeEditAllowed(xformable.GetXformOpOrderAttr(), &errMsg)) { |
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.
This feels funky --- we're testing if attribute editing is allowed on the xformOpOrder attribute for any attribute. However, for non xform op attributes, this would be incorrect. We should only be testing xformOpOrder if the attribute is an xformOp --- can use UsdGeomXformOp::IsXformOp(nameToken) for that.
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.
std::string errMsg; | ||
|
||
// check for xformOp:tokenName in XformOpOrderAttr first | ||
UsdGeomXformable xformable(prim); |
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.
What if the prim doesn't support the UsdGeomXformable schema? We should check for that.
lib/mayaUsd/ufe/Utils.h
Outdated
@@ -129,6 +129,9 @@ PXR_NS::TfTokenVector getProxyShapePurposes(const Ufe::Path& path); | |||
MAYAUSD_CORE_PUBLIC | |||
bool isAttributeEditAllowed(const PXR_NS::UsdAttribute& attr, std::string* errMsg = nullptr); | |||
|
|||
MAYAUSD_CORE_PUBLIC | |||
bool isAttributeEditAllowed(const PXR_NS::UsdPrim& prim, const std::string& tokenName); |
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.
As per comment in .cpp file, should take a const TfToken& directly, instead of converting to string.
@@ -19,6 +19,8 @@ | |||
|
|||
#include <pxr/usd/usdGeom/xformCache.h> | |||
|
|||
#include <maya/MGlobal.h> |
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.
Don't think this one is needed.
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.
Addressed in 0164510
@@ -264,22 +266,38 @@ void UsdTransform3dCommonAPI::scale(double x, double y, double z) | |||
Ufe::TranslateUndoableCommand::Ptr | |||
UsdTransform3dCommonAPI::translateCmd(double x, double y, double z) | |||
{ | |||
if (!isAttributeEditAllowed(prim(), "xformOp:translate")) { |
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 pass a TfToken.
I noticed last night that
|
Ack, I should have realized this and told you about it. UFE v1 supports the common transform API only, so you can't run the matrix transform op test for UFE v1 --- you'll have to skip it under those circumstances. |
lib/mayaUsd/ufe/Utils.cpp
Outdated
{ | ||
std::string errMsg; | ||
if (prim.IsA<UsdGeomXformable>()) { |
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.
As you have it now, the code is UsdGeomXformable centric, and it doesn't need to be --- we currently return true if it's not a UsdGeomXformable. Seems to me we could have something like:
UsdGeomXformable xformable(prim);
if (xformable) { // bool operator on schema returns true if valid
if (UsdGeomXformOp::IsXformOp(attrName) {
// Check xformOpOrder
}
}
// Then check the attribute itself.
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.
lib/mayaUsd/ufe/Utils.cpp
Outdated
MGlobal::displayError(errMsg.c_str()); | ||
return false; | ||
} else { | ||
// check for xformOp:tokenName | ||
if (UsdGeomXformOp::IsXformOp(attrName)) { |
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.
I think this test should be done to gate whether we do the xformOpOrder check: if the attrName is an xform op, do the extra check, otherwise just do a single test on the attribute itself.
This PR completes the blocking of attribute edits for the remaining transformation stacks ( UsdTransform3dCommonAPI, UsdTransform3dMatrixOp )