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-105277: Initial work to support None-destructive reorder ( move ) of prims relative to their siblings. #867

Merged
merged 8 commits into from
Oct 28, 2020

Conversation

HamedSabri-adsk
Copy link
Contributor

This PR is the initial work to support None-destructive reorder (move) of USD prim(s) relative to their siblings based on Maya's native reorder command.

Supported features:

  • Drag/Drop in outliner
  • Undo/Redo single/multiple items

To see how reorder command works: https://download.autodesk.com/us/maya/2011help/CommandsPython/reorder.html

Demo:

reorder

@HamedSabri-adsk HamedSabri-adsk added ufe-usd Related to UFE-USD plugin in Maya-Usd workflows Related to in-context workflows labels Oct 25, 2020
Copy link
Collaborator

@ppt-adsk ppt-adsk left a comment

Choose a reason for hiding this comment

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

Looking good! A few minor things to fix up, but otherwise really close.

// Ufe::Hierarchy::insertChildCmd() returns a base class
// Ufe::UndoableCommand::Ptr object, from which we can't retrieve the added
// child. PPT, 13-Jul-2020.
#ifdef UFE_V2_FEATURES_AVAILABLE
Copy link
Collaborator

Choose a reason for hiding this comment

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

You sure about this macro? There is no Hierarchy::insertChild() in UFE v1.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch. Yes this #ifdef is redundant. Addressed in 0977cf1

// in order to get the parent out of it.
const auto& childPrim = downcast((*orderedList.begin()))->prim();

return UsdUndoReorderCommand::create(childPrim, orderedTokens);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is confusing to me: in the UsdUndoReorderCommand, all we do with this childPrim is to get its parent, as far as I can tell. Then why not give the parent directly, especially here since we know the parent is the pseudo-root.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can't agree more... passing parent is more appropriate. Addressed in 0977cf1

// Ufe::Hierarchy::insertChildCmd() returns a base class
// Ufe::UndoableCommand::Ptr object, from which we can't retrieve the added
// child. PPT, 13-Jul-2020.
#ifdef UFE_V2_FEATURES_AVAILABLE
Copy link
Collaborator

Choose a reason for hiding this comment

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

Again, insertChild() doesn't exist in UFE v1, so pretty sure this ifdef is incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 0977cf1

orderedTokens.emplace_back(downcast(item)->prim().GetPath().GetNameToken());
}

// TODO HS Oct 23, 2020, grab any child and pass it to UsdUndoReorderCommand
Copy link
Collaborator

Choose a reason for hiding this comment

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

Since the first argument is the parent, it's the scene item of the Hierarchy interface, so this is just

return UsdUndoReorderCommand::create(downcast(sceneItem()), orderedTokens);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk
But downcast(sceneItem()) doesn't give me the parent and rather the item that I am moving.

e.g
/Xform1/pSphere1

What I want is the parent (/Xform1) since that's the one whose spec is going to call the SetNameChildrenOrder.

see 0977cf1

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, I'm confused! Isn't this a method that is called on the parent, to reorder its children? I.e. you're calling it on /Xform1's hierarchy interface, to reorder its children, so Hierarchy::sceneItem() will in fact give you the parent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhh.. sorry about the confusion. Now I see it... :) I was calling the the command on a wrong hierarchy interface.

I have it fixed soon on the data model side and then make this change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk addressed in 520b36d

) override;

Ufe::SceneItem::Ptr insertChild(const Ufe::SceneItem::Ptr& child,const Ufe::SceneItem::Ptr& pos) override;
Ufe::InsertChildCommand::Ptr insertChildCmd(const Ufe::SceneItem::Ptr& child, const Ufe::SceneItem::Ptr& pos) override;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Funky indentation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup... all of the code base under lib/mayaUsd/ufe has a mix of spaces and tabs. I can't wait for @kxl-adsk to apply the clang format on the repo :) .

#include <ufe/undoableCommand.h>

#include <mayaUsd/base/api.h>
#include <mayaUsd/ufe/UsdSceneItem.h>
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we need to include UsdSceneItem.h?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. Not at all. This header came from my copy-paste of another class. UsdSceneItem.h brings in #include <pxr/usd/usd/prim.h> and that what we need here.

Addressed in 0977cf1

@@ -0,0 +1,53 @@
#usda 1.0
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit-pick, but seems like such a simple file, we could just create the scene on the fly in the test, I would think.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree with you. primitives.usda has a very simple hierarchy and I could have created it on the fly. I admit being lazy here :)

@@ -164,6 +164,10 @@ def openGroupBallsScene():
filePath = os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "testSamples", "groupBalls", "ballset.ma" )
cmds.file(filePath, force=True, open=True)

def openPrimitivesScene():
Copy link
Collaborator

Choose a reason for hiding this comment

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

Have a look at the recent improvement that SPI put in for data file path access.

And I can't help to re-iterate that if you created the scene on the fly, you wouldn't need to do this :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

See
#868

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 0977cf1

''' Reorder (a.k.a move) objects relative to their siblings.
For relative moves, both positive and negative numbers may be specified.
'''
shapeSegment = mayaUtils.createUfePathSegment("|world|Primitives_usd|Primitives_usdShape")
Copy link
Collaborator

Choose a reason for hiding this comment

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

Because this test won't be executed for UFE v1, it would be much clearer and more maintainable to use UFE path strings:
cylinderPath = ufe.PathString.path('Primitives_usd|Primitives_usdShape,/Xform1/Cylinder1')

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks. Great point.

Addressed in 0977cf1

Reorder (a.k.a move) to front and back of the sibling list
'''
shapeSegment = mayaUtils.createUfePathSegment("|world|Primitives_usd|Primitives_usdShape")
cylinderPath = ufe.Path([shapeSegment, usdUtils.createUfePathSegment("/Xform1/Cylinder1")])
Copy link
Collaborator

Choose a reason for hiding this comment

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

Use path strings.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 0977cf1


return UsdUndoReorderCommand::create(childPrim, orderedTokens);
return UsdUndoReorderCommand::create(parentPrim, orderedTokens);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Of course there's nothing wrong with this, but you can avoid the downcast and the call to childPrim.GetParent(), because here you know the parent prim is the pseudo-root, so you can just pass it:

return UsdUndoReorderCommand::create(getUsdRootPrim(), orderedTokens);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@ppt-adsk addressed in 520b36d

@HamedSabri-adsk HamedSabri-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Oct 28, 2020
@kxl-adsk kxl-adsk merged commit f144c43 into dev Oct 28, 2020
@kxl-adsk kxl-adsk deleted the sabri/MAYA-105277/reorder_support_ufe branch October 28, 2020 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge ufe-usd Related to UFE-USD plugin in Maya-Usd workflows Related to in-context workflows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants