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-106188 - As a user, I would like to activate and deactivate prims #773

Merged
merged 2 commits into from
Sep 15, 2020
Merged
Show file tree
Hide file tree
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
7 changes: 7 additions & 0 deletions lib/mayaUsd/ufe/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdUndoCreateGroupCommand.cpp
UsdUndoInsertChildCommand.cpp
)
if(UFE_PREVIEW_VERSION_NUM GREATER_EQUAL 2022)
target_sources(${PROJECT_NAME}
PRIVATE
UsdUIInfoHandler.cpp
)
endif()
endif()

set(HEADERS
Expand Down Expand Up @@ -83,6 +89,7 @@ if(CMAKE_UFE_V2_FEATURES_AVAILABLE)
UsdContextOpsHandler.h
UsdObject3d.h
UsdObject3dHandler.h
UsdUIInfoHandler.h
UsdUndoAddNewPrimCommand.h
UsdUndoCreateGroupCommand.h
UsdUndoInsertChildCommand.h
Expand Down
9 changes: 9 additions & 0 deletions lib/mayaUsd/ufe/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
#include <mayaUsd/ufe/UsdObject3dHandler.h>
#include <mayaUsd/ufe/UsdContextOpsHandler.h>
#include <mayaUsd/ufe/ProxyShapeContextOpsHandler.h>
#if UFE_PREVIEW_VERSION_NUM >= 2022
#include <mayaUsd/ufe/UsdUIInfoHandler.h>
#endif
#include <ufe/pathString.h>
#else
#include <mayaUsd/ufe/UfeVersionCompat.h>
Expand Down Expand Up @@ -115,11 +118,17 @@ MStatus initialize()
UFE_V2(auto usdAttributesHandler = UsdAttributesHandler::create();)
UFE_V2(auto usdObject3dHandler = UsdObject3dHandler::create();)
UFE_V2(auto usdContextOpsHandler = UsdContextOpsHandler::create();)
#if UFE_PREVIEW_VERSION_NUM >= 2022
UFE_V2(auto usdUIInfoHandler = UsdUIInfoHandler::create();)
#endif
g_USDRtid = Ufe::RunTimeMgr::instance().register_(
kUSDRunTimeName, usdHierHandler, usdTrans3dHandler,
usdSceneItemOpsHandler
UFE_V2(, usdAttributesHandler, usdObject3dHandler)
UFE_V2(, usdContextOpsHandler)
#if UFE_PREVIEW_VERSION_NUM >= 2022
UFE_V2(, usdUIInfoHandler)
#endif
);

#if !defined(NDEBUG)
Expand Down
49 changes: 45 additions & 4 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "ProxyShapeHierarchy.h"

#include <stdexcept>
#include <cassert>

#include <ufe/log.h>
#include <ufe/pathComponent.h>
Expand All @@ -32,6 +33,17 @@
#include <mayaUsd/ufe/UsdUndoCreateGroupCommand.h>
#endif

namespace {
UsdPrimSiblingRange getUSDFilteredChildren(const UsdPrim& prim, const Usd_PrimFlagsPredicate pred = UsdPrimDefaultPredicate)
{
// Since the equivalent of GetChildren is
// GetFilteredChildren( UsdPrimDefaultPredicate ),
// we will use that as the initial value.
//
return prim.GetFilteredChildren(pred);
}
}

MAYAUSD_NS_DEF {
namespace ufe {

Expand Down Expand Up @@ -119,7 +131,7 @@ bool ProxyShapeHierarchy::hasChildren() const
UFE_LOG("invalid root prim in ProxyShapeHierarchy::hasChildren()");
return false;
}
return !rootPrim.GetChildren().empty();
return !getUSDFilteredChildren(rootPrim).empty();
}

Ufe::SceneItemList ProxyShapeHierarchy::children() const
Expand All @@ -129,14 +141,43 @@ Ufe::SceneItemList ProxyShapeHierarchy::children() const
if (!rootPrim.IsValid())
return Ufe::SceneItemList();

auto usdChildren = rootPrim.GetChildren();
auto parentPath = fItem->path();
return createUFEChildList(getUSDFilteredChildren(rootPrim));
}

#ifdef UFE_V2_FEATURES_AVAILABLE
#if UFE_PREVIEW_VERSION_NUM >= 2022
Ufe::SceneItemList ProxyShapeHierarchy::filteredChildren(const ChildFilter& childFilter) const
{
// Return filtered children of the USD root.
const UsdPrim& rootPrim = getUsdRootPrim();
if (!rootPrim.IsValid())
return Ufe::SceneItemList();

// Note: for now the only child filter flag we support is "Inactive Prims".
// See UsdHierarchyHandler::childFilter()
if ((childFilter.size() == 1) && (childFilter.front().name == "InactivePrims"))
{
// See uniqueChildName() for explanation of USD filter predicate.
Usd_PrimFlagsPredicate flags = childFilter.front().value ? UsdPrimIsDefined && !UsdPrimIsAbstract
: UsdPrimDefaultPredicate;
return createUFEChildList(getUSDFilteredChildren(rootPrim, flags));
}

UFE_LOG("Unknown child filter");
return Ufe::SceneItemList();
}
#endif
#endif

// Return UFE child list from input USD child list.
Ufe::SceneItemList ProxyShapeHierarchy::createUFEChildList(const UsdPrimSiblingRange& range) const
{
// We must create selection items for our children. These will have as
// path the path of the proxy shape, with a single path segment of a
// single component appended to it.
auto parentPath = fItem->path();
Ufe::SceneItemList children;
for (const auto& child : usdChildren)
for (const auto& child : range)
{
children.emplace_back(UsdSceneItem::create(parentPath + Ufe::PathSegment(
Ufe::PathComponent(child.GetName().GetString()), g_USDRtid, '/'), child));
Expand Down
4 changes: 4 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy
Ufe::SceneItem::Ptr sceneItem() const override;
bool hasChildren() const override;
Ufe::SceneItemList children() const override;
#if UFE_PREVIEW_VERSION_NUM >= 2022
UFE_V2(Ufe::SceneItemList filteredChildren(const ChildFilter&) const override;)
#endif
Ufe::SceneItem::Ptr parent() const override;
#ifndef UFE_V2_FEATURES_AVAILABLE
Ufe::AppendedChild appendChild(const Ufe::SceneItem::Ptr& child) override;
Expand All @@ -84,6 +87,7 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchy : public Ufe::Hierarchy

private:
const UsdPrim& getUsdRootPrim() const;
Ufe::SceneItemList createUFEChildList(const UsdPrimSiblingRange& range) const;

private:
Ufe::SceneItem::Ptr fItem;
Expand Down
11 changes: 11 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeHierarchyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,16 @@ Ufe::SceneItem::Ptr ProxyShapeHierarchyHandler::createItem(const Ufe::Path& path
return fMayaHierarchyHandler->createItem(path);
}

#ifdef UFE_V2_FEATURES_AVAILABLE
#if UFE_PREVIEW_VERSION_NUM >= 2022
Ufe::Hierarchy::ChildFilter ProxyShapeHierarchyHandler::childFilter() const
{
Ufe::Hierarchy::ChildFilter childFilters;
childFilters.emplace_back("InactivePrims", "Inactive Prims", true);
return childFilters;
}
#endif
#endif

} // namespace ufe
} // namespace MayaUsd
3 changes: 3 additions & 0 deletions lib/mayaUsd/ufe/ProxyShapeHierarchyHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ class MAYAUSD_CORE_PUBLIC ProxyShapeHierarchyHandler : public Ufe::HierarchyHand
// Ufe::HierarchyHandler overrides
Ufe::Hierarchy::Ptr hierarchy(const Ufe::SceneItem::Ptr& item) const override;
Ufe::SceneItem::Ptr createItem(const Ufe::Path& path) const override;
#if UFE_PREVIEW_VERSION_NUM >= 2022
UFE_V2(Ufe::Hierarchy::ChildFilter childFilter() const override;)
#endif

private:
Ufe::HierarchyHandler::Ptr fMayaHierarchyHandler;
Expand Down
53 changes: 52 additions & 1 deletion lib/mayaUsd/ufe/UsdContextOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
//
#include "UsdContextOps.h"

#include "private/UfeNotifGuard.h"

#include <cassert>

#include <maya/MGlobal.h>
Expand Down Expand Up @@ -47,6 +49,9 @@ static constexpr char kUSDVariantSetsLabel[] = "Variant Sets";
static constexpr char kUSDToggleVisibilityItem[] = "Toggle Visibility";
static constexpr char kUSDMakeVisibleLabel[] = "Make Visible";
static constexpr char kUSDMakeInvisibleLabel[] = "Make Invisible";
static constexpr char kUSDToggleActiveStateItem[] = "Toggle Active State";
static constexpr char kUSDActivatePrimLabel[] = "Activate Prim";
static constexpr char kUSDDeactivatePrimLabel[] = "Deactivate Prim";
Comment on lines +52 to +54
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

New context menu item to activate/deactivate a prim

static constexpr char kUSDAddNewPrimItem[] = "Add New Prim";
static constexpr char kUSDAddNewPrimLabel[] = "Add New Prim";
static constexpr char kUSDDefPrimItem[] = "Def";
Expand Down Expand Up @@ -90,6 +95,45 @@ class SetVariantSelectionUndoableCommand : public Ufe::UndoableCommand
const std::string fNewSelection;
};

//! \brief Undoable command for prim active state change
class ToggleActiveStateCommand : public Ufe::UndoableCommand
{
public:
ToggleActiveStateCommand(const UsdPrim& prim)
{
_stage = prim.GetStage();
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: could have put everything in the constructor initializer list, rather than having the default constructor called, then doing the assignment:
ToggleActiveStateCommand(const UsdPrim& prim) : _stage(prim.GetStage()), _primPath(prim.GetPath()), _active(prim.IsActive) {}

_primPath = prim.GetPath();
_active = prim.IsActive();
}

void undo() override
{
if (_stage) {
UsdPrim prim = _stage->GetPrimAtPath(_primPath);
if (prim.IsValid()) {
MayaUsd::ufe::InAddOrDeleteOperation ad;
prim.SetActive(_active);
}
}
}

void redo() override
{
if (_stage) {
UsdPrim prim = _stage->GetPrimAtPath(_primPath);
if (prim.IsValid()) {
MayaUsd::ufe::InAddOrDeleteOperation ad;
prim.SetActive(!_active);
}
}
}

private:
PXR_NS::UsdStageWeakPtr _stage;
PXR_NS::SdfPath _primPath;
bool _active;
};

const char* selectUSDFileScript = R"(
global proc string SelectUSDFileForAddReference()
{
Expand Down Expand Up @@ -235,12 +279,14 @@ Ufe::ContextOps::Items UsdContextOps::getItems(
items.emplace_back(Ufe::ContextItem::kSeparator);
}

// Top-level items. Variant sets and visibility. Do not add for gateway type node.
// Top-level items (do not add for gateway type node):
if (!fIsAGatewayType) {
// Variant sets:
if (prim().HasVariantSets()) {
items.emplace_back(
kUSDVariantSetsItem, kUSDVariantSetsLabel, Ufe::ContextItem::kHasChildren);
}
// Visibility:
// If the item has a visibility attribute, add menu item to change visibility.
// Note: certain prim types such as shaders & materials don't support visibility.
auto attributes = Ufe::Attributes::attributes(sceneItem());
Expand All @@ -255,6 +301,8 @@ Ufe::ContextOps::Items UsdContextOps::getItems(
items.emplace_back(kUSDToggleVisibilityItem, l);
}
}
// Prim active state:
items.emplace_back(kUSDToggleActiveStateItem, prim().IsActive() ? kUSDDeactivatePrimLabel : kUSDActivatePrimLabel);
}

// Top level item - Add New Prim (for all context op types).
Expand Down Expand Up @@ -344,6 +392,9 @@ Ufe::UndoableCommand::Ptr UsdContextOps::doOpCmd(const ItemPath& itemPath)
return visibility->setCmd(
current == UsdGeomTokens->invisible ? UsdGeomTokens->inherited : UsdGeomTokens->invisible);
} // Visibility
else if (itemPath[0] == kUSDToggleActiveStateItem) {
return std::make_shared<ToggleActiveStateCommand>(prim());
} // ActiveState
else if (!itemPath.empty() && (itemPath[0] == kUSDAddNewPrimItem)) {
// Operation is to create a new prim of the type specified.
if (itemPath.size() != 2u) {
Expand Down
49 changes: 36 additions & 13 deletions lib/mayaUsd/ufe/UsdHierarchy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include <ufe/scene.h>
#include <ufe/sceneNotification.h>
#include <ufe/log.h>

#include <pxr/usd/usd/prim.h>
#include <pxr/usd/usd/stage.h>
Expand All @@ -41,19 +42,16 @@
#endif

namespace {
UsdPrimSiblingRange filteredChildren( const UsdPrim& prim )
UsdPrimSiblingRange getUSDFilteredChildren(const UsdPrim& prim, const Usd_PrimFlagsPredicate pred = UsdPrimDefaultPredicate)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added the predicate as input (with default) so that it can be used by new filtered children method.

{
// We need to be able to traverse down to instance proxies, so turn
// on that part of the predicate, since by default, it is off. Since
// the equivalent of GetChildren is
// GetFilteredChildren( UsdPrimDefaultPredicate ),
// we will use that as the initial value.
//
Usd_PrimFlagsPredicate predicate = UsdPrimDefaultPredicate;
predicate = predicate.TraverseInstanceProxies(true);
return prim.GetFilteredChildren(predicate);
return prim.GetFilteredChildren(UsdTraverseInstanceProxies(pred));
}

}

MAYAUSD_NS_DEF {
Expand Down Expand Up @@ -101,18 +99,43 @@ Ufe::SceneItem::Ptr UsdHierarchy::sceneItem() const

bool UsdHierarchy::hasChildren() const
{
return !filteredChildren(prim()).empty();
return !getUSDFilteredChildren(prim()).empty();
}

Ufe::SceneItemList UsdHierarchy::children() const
{
// Return USD children only, i.e. children within this run-time.
Ufe::SceneItemList children;
for (auto child : filteredChildren(prim()))
{
children.emplace_back(UsdSceneItem::create(fItem->path() + child.GetName(), child));
}
Comment on lines -110 to -114
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Moved this code into new private method createUFEChildList()

return children;
return createUFEChildList(getUSDFilteredChildren(prim()));
}

#ifdef UFE_V2_FEATURES_AVAILABLE
#if UFE_PREVIEW_VERSION_NUM >= 2022
Ufe::SceneItemList UsdHierarchy::filteredChildren(const ChildFilter& childFilter) const
{
// Note: for now the only child filter flag we support is "Inactive Prims".
// See UsdHierarchyHandler::childFilter()
if ((childFilter.size() == 1) && (childFilter.front().name == "InactivePrims"))
{
// See uniqueChildName() for explanation of USD filter predicate.
Usd_PrimFlagsPredicate flags = childFilter.front().value ? UsdPrimIsDefined && !UsdPrimIsAbstract
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Leave off the UsdPrimIsActive flag so we'll also get inactive prims.

: UsdPrimDefaultPredicate;
return createUFEChildList(getUSDFilteredChildren(prim(), flags));
}

UFE_LOG("Unknown child filter");
return Ufe::SceneItemList();
}
#endif
#endif

Ufe::SceneItemList UsdHierarchy::createUFEChildList(const UsdPrimSiblingRange& range) const
{
// Return UFE child list from input USD child list.
Ufe::SceneItemList children;
for (const auto& child : range)
{
children.emplace_back(UsdSceneItem::create(fItem->path() + child.GetName(), child));
}
return children;
}

Ufe::SceneItem::Ptr UsdHierarchy::parent() const
Expand Down
6 changes: 6 additions & 0 deletions lib/mayaUsd/ufe/UsdHierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class MAYAUSD_CORE_PUBLIC UsdHierarchy : public Ufe::Hierarchy
Ufe::SceneItem::Ptr sceneItem() const override;
bool hasChildren() const override;
Ufe::SceneItemList children() const override;
#if UFE_PREVIEW_VERSION_NUM >= 2022
UFE_V2(Ufe::SceneItemList filteredChildren(const ChildFilter&) const override;)
#endif
Ufe::SceneItem::Ptr parent() const override;
#ifndef UFE_V2_FEATURES_AVAILABLE
Ufe::AppendedChild appendChild(const Ufe::SceneItem::Ptr& child) override;
Expand All @@ -78,6 +81,9 @@ class MAYAUSD_CORE_PUBLIC UsdHierarchy : public Ufe::Hierarchy
) override;
#endif

private:
Ufe::SceneItemList createUFEChildList(const UsdPrimSiblingRange& range) const;

private:
UsdSceneItem::Ptr fItem;

Expand Down
11 changes: 11 additions & 0 deletions lib/mayaUsd/ufe/UsdHierarchyHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,16 @@ Ufe::SceneItem::Ptr UsdHierarchyHandler::createItem(const Ufe::Path& path) const
return prim.IsValid() ? UsdSceneItem::create(path, prim) : nullptr;
}

#ifdef UFE_V2_FEATURES_AVAILABLE
#if UFE_PREVIEW_VERSION_NUM >= 2022
Ufe::Hierarchy::ChildFilter UsdHierarchyHandler::childFilter() const
{
Ufe::Hierarchy::ChildFilter childFilters;
childFilters.emplace_back("InactivePrims", "Inactive Prims", true);
return childFilters;
}
#endif
#endif

} // namespace ufe
} // namespace MayaUsd
Loading