-
Notifications
You must be signed in to change notification settings - Fork 202
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
Implement and test setMatrixCmd() for single matrix op prims. #1102
Changes from all commits
cdc1db9
56c2188
b04addb
4a6c729
ea3922f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,8 @@ | |
|
||
#include <mayaUsd/ufe/UsdSceneItem.h> | ||
#include <mayaUsd/ufe/Utils.h> | ||
#include <mayaUsd/undo/UsdUndoBlock.h> | ||
#include <mayaUsd/undo/UsdUndoableItem.h> | ||
|
||
#include <pxr/base/gf/rotation.h> | ||
#include <pxr/base/gf/transform.h> | ||
|
@@ -30,6 +32,7 @@ | |
|
||
namespace { | ||
|
||
using namespace MayaUsd; | ||
using namespace MayaUsd::ufe; | ||
|
||
VtValue getValue(const UsdAttribute& attr, const UsdTimeCode& time) | ||
|
@@ -76,6 +79,42 @@ computeLocalTransform(const UsdPrim& prim, const UsdGeomXformOp& op, const UsdTi | |
auto computeLocalInclusiveTransform = computeLocalTransform<true>; | ||
auto computeLocalExclusiveTransform = computeLocalTransform<false>; | ||
|
||
// Class for setMatrixCmd() implementation. UsdUndoBlock data member and | ||
// undo() / redo() should be factored out into a future command base class. | ||
class UsdSetMatrix4dUndoableCmd : public Ufe::SetMatrix4dUndoableCommand | ||
{ | ||
public: | ||
UsdSetMatrix4dUndoableCmd(const Ufe::Path& path, const Ufe::Matrix4d& newM) | ||
: Ufe::SetMatrix4dUndoableCommand(path) | ||
, _newM(newM) | ||
{ | ||
} | ||
|
||
~UsdSetMatrix4dUndoableCmd() override { } | ||
|
||
bool set(const Ufe::Matrix4d&) override | ||
{ | ||
// No-op: Maya does not set matrices through interactive manipulation. | ||
TF_WARN("Illegal call to UsdSetMatrix4dUndoableCmd::set()"); | ||
return true; | ||
} | ||
|
||
void execute() override | ||
{ | ||
UsdUndoBlock undoBlock(&_undoableItem); | ||
|
||
auto t3d = Ufe::Transform3d::transform3d(sceneItem()); | ||
t3d->setMatrix(_newM); | ||
} | ||
|
||
void undo() override { _undoableItem.undo(); } | ||
void redo() override { _undoableItem.redo(); } | ||
|
||
private: | ||
UsdUndoableItem _undoableItem; | ||
const Ufe::Matrix4d _newM; | ||
}; | ||
|
||
// Helper class to factor out common code for translate, rotate, scale | ||
// undoable commands. | ||
class UsdTRSUndoableCmdBase | ||
|
@@ -351,7 +390,7 @@ Ufe::ScaleUndoableCommand::Ptr UsdTransform3dMatrixOp::scaleCmd(double x, double | |
|
||
Ufe::SetMatrix4dUndoableCommand::Ptr UsdTransform3dMatrixOp::setMatrixCmd(const Ufe::Matrix4d& m) | ||
{ | ||
return nullptr; | ||
return std::make_shared<UsdSetMatrix4dUndoableCmd>(path(), m); | ||
} | ||
|
||
void UsdTransform3dMatrixOp::setMatrix(const Ufe::Matrix4d& m) { _op.Set(toUsd(m)); } | ||
|
@@ -402,20 +441,39 @@ UsdTransform3dMatrixOpHandler::create(const Ufe::Transform3dHandler::Ptr& nextHa | |
Ufe::Transform3d::Ptr | ||
UsdTransform3dMatrixOpHandler::transform3d(const Ufe::SceneItem::Ptr& item) const | ||
{ | ||
// This method can be used to edit the 3D transform of the argument, but at | ||
// time of writing this is not implemented in UsdTransform3dMatrixOp, and | ||
// our UsdTransform3dBaseHandler base class does not know how to edit the | ||
// argument either. Simply delegate to the next handler in the list. | ||
return _nextHandler->transform3d(item); | ||
// Remove code duplication with editTransform3d(). PPT, 21-Jan-2021. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Copy-paste from editTransform3d() a bit of a shame, hopefully can fix later. |
||
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item); | ||
TF_AXIOM(usdItem); | ||
|
||
auto opName = getMatrixOp(); | ||
UsdGeomXformable xformable(usdItem->prim()); | ||
bool unused; | ||
kxl-adsk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
auto xformOps = xformable.GetOrderedXformOps(&unused); | ||
auto i = std::find_if(xformOps.begin(), xformOps.end(), [opName](const UsdGeomXformOp& op) { | ||
return (op.GetOpType() == UsdGeomXformOp::TypeTransform) | ||
&& (!opName || std::string(opName) == op.GetOpName()); | ||
}); | ||
bool foundMatrix = (i != xformOps.end()); | ||
|
||
bool moreLocalNonMatrix = foundMatrix | ||
? (std::find_if( | ||
i, | ||
xformOps.end(), | ||
[](const UsdGeomXformOp& op) { | ||
return op.GetOpType() != UsdGeomXformOp::TypeTransform; | ||
}) | ||
!= xformOps.end()) | ||
: false; | ||
|
||
return (foundMatrix && !moreLocalNonMatrix) ? UsdTransform3dMatrixOp::create(usdItem, *i) | ||
: _nextHandler->transform3d(item); | ||
} | ||
|
||
Ufe::Transform3d::Ptr UsdTransform3dMatrixOpHandler::editTransform3d( | ||
const Ufe::SceneItem::Ptr& item UFE_V2(, const Ufe::EditTransform3dHint& hint)) const | ||
{ | ||
UsdSceneItem::Ptr usdItem = std::dynamic_pointer_cast<UsdSceneItem>(item); | ||
#if !defined(NDEBUG) | ||
assert(usdItem); | ||
#endif | ||
TF_AXIOM(usdItem); | ||
|
||
// Beware: the default UsdGeomXformOp constructor | ||
// https://github.com/PixarAnimationStudios/USD/blob/71b4baace2044ea4400ba802e91667f9ebe342f0/pxr/usd/usdGeom/xformOp.h#L148 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -162,21 +162,13 @@ createTransform3d(const Ufe::SceneItem::Ptr& item, NextTransform3dFn nextTransfo | |
return stackOps.empty() ? nextTransform3dFn() : UsdTransform3dMayaXformStack::create(usdItem); | ||
} | ||
|
||
// Class for setMatrixCmd() implementation. Should be rolled into a future | ||
// command class with full undo / redo support | ||
// Class for setMatrixCmd() implementation. UsdUndoBlock data member and | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to use new undo / redo framework. |
||
// undo() / redo() should be factored out into a future command base class. | ||
class UsdSetMatrix4dUndoableCmd : public Ufe::SetMatrix4dUndoableCommand | ||
{ | ||
public: | ||
UsdSetMatrix4dUndoableCmd( | ||
const Ufe::Path& path, | ||
const Ufe::Vector3d& oldT, | ||
const Ufe::Vector3d& oldR, | ||
const Ufe::Vector3d& oldS, | ||
const Ufe::Matrix4d& newM) | ||
UsdSetMatrix4dUndoableCmd(const Ufe::Path& path, const Ufe::Matrix4d& newM) | ||
: Ufe::SetMatrix4dUndoableCommand(path) | ||
, _oldT(oldT) | ||
, _oldR(oldR) | ||
, _oldS(oldS) | ||
{ | ||
// Decompose new matrix to extract TRS. Neither GfMatrix4d::Factor | ||
// nor GfTransform decomposition provide results that match Maya, | ||
|
@@ -206,23 +198,40 @@ class UsdSetMatrix4dUndoableCmd : public Ufe::SetMatrix4dUndoableCommand | |
return true; | ||
} | ||
|
||
void undo() override { perform(_oldT, _oldR, _oldS); } | ||
void redo() override { perform(_newT, _newR, _newS); } | ||
|
||
private: | ||
void perform(const Ufe::Vector3d& t, const Ufe::Vector3d& r, const Ufe::Vector3d& s) | ||
void execute() override | ||
{ | ||
UsdUndoBlock undoBlock(&_undoableItem); | ||
|
||
auto t3d = Ufe::Transform3d::transform3d(sceneItem()); | ||
t3d->translate(t.x(), t.y(), t.z()); | ||
t3d->rotate(r.x(), r.y(), r.z()); | ||
t3d->scale(s.x(), s.y(), s.z()); | ||
t3d->translate(_newT.x(), _newT.y(), _newT.z()); | ||
t3d->rotate(_newR.x(), _newR.y(), _newR.z()); | ||
t3d->scale(_newS.x(), _newS.y(), _newS.z()); | ||
|
||
#if !defined(REMOVE_PR122_WORKAROUND_MAYA_109685) | ||
_executeCalled = true; | ||
#endif | ||
} | ||
Ufe::Vector3d _oldT; | ||
Ufe::Vector3d _oldR; | ||
Ufe::Vector3d _oldS; | ||
Ufe::Vector3d _newT; | ||
Ufe::Vector3d _newR; | ||
Ufe::Vector3d _newS; | ||
|
||
void undo() override { _undoableItem.undo(); } | ||
void redo() override | ||
{ | ||
#if !defined(REMOVE_PR122_WORKAROUND_MAYA_109685) | ||
if (!_executeCalled) { | ||
execute(); | ||
return; | ||
} | ||
#endif | ||
_undoableItem.redo(); | ||
} | ||
|
||
private: | ||
#if !defined(REMOVE_PR122_WORKAROUND_MAYA_109685) | ||
bool _executeCalled { false }; | ||
#endif | ||
UsdUndoableItem _undoableItem; | ||
Ufe::Vector3d _newT; | ||
Ufe::Vector3d _newR; | ||
Ufe::Vector3d _newS; | ||
}; | ||
|
||
// Helper class to factor out common code for translate, rotate, scale | ||
|
@@ -698,8 +707,7 @@ UsdTransform3dMayaXformStack::pivotCmd(const TfToken& pvtOpSuffix, double x, dou | |
Ufe::SetMatrix4dUndoableCommand::Ptr | ||
UsdTransform3dMayaXformStack::setMatrixCmd(const Ufe::Matrix4d& m) | ||
{ | ||
return std::make_shared<UsdSetMatrix4dUndoableCmd>( | ||
path(), translation(), rotation(), scale(), m); | ||
return std::make_shared<UsdSetMatrix4dUndoableCmd>(path(), m); | ||
} | ||
|
||
UsdTransform3dMayaXformStack::SetXformOpOrderFn | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,16 +14,14 @@ | |
// limitations under the License. | ||
// | ||
|
||
#ifndef MAYAUSD_UNDO_UNDOABLE_BLOCK_H | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed copy-paste damage... Was causing really, really weird compilation errors for my local changes... |
||
#define MAYAUSD_UNDO_UNDOABLE_BLOCK_H | ||
#ifndef MAYAUSD_UNDO_UNDOABLE_ITEM_H | ||
#define MAYAUSD_UNDO_UNDOABLE_ITEM_H | ||
|
||
#include <mayaUsd/base/api.h> | ||
|
||
#include <functional> | ||
#include <vector> | ||
|
||
PXR_NAMESPACE_USING_DIRECTIVE | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No Pixar namespace declarations or definitions here, removed. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love it |
||
|
||
namespace MAYAUSD_NS_DEF { | ||
|
||
//! \brief UsdUndoableItem | ||
|
@@ -62,4 +60,4 @@ class MAYAUSD_CORE_PUBLIC UsdUndoableItem | |
|
||
} // namespace MAYAUSD_NS_DEF | ||
|
||
#endif // MAYAUSD_UNDO_UNDOABLE_BLOCK_H | ||
#endif // MAYAUSD_UNDO_UNDOABLE_ITEM_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.
Cleanup.