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

EMS-310 Usd Context Ops, fixed toggle visibility to used computed visibile + expose isRootChild as a DCC function. #3266

Merged
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
2 changes: 2 additions & 0 deletions lib/usdUfe/ufe/Global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ Ufe::Rtid initialize(
UsdUfe::setIsAttributeLockedFn(dccFunctions.isAttributeLockedFn);
if (dccFunctions.saveStageLoadRulesFn)
UsdUfe::setSaveStageLoadRulesFn(dccFunctions.saveStageLoadRulesFn);
if (dccFunctions.isRootChildFn)
UsdUfe::setIsRootChildFn(dccFunctions.isRootChildFn);

// Create a default stages subject if none is provided.
if (nullptr == ss) {
Expand Down
1 change: 1 addition & 0 deletions lib/usdUfe/ufe/Global.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct USDUFE_PUBLIC DCCFunctions
// Optional: default values will be used if no function is supplied.
IsAttributeLockedFn isAttributeLockedFn = nullptr;
SaveStageLoadRulesFn saveStageLoadRulesFn = nullptr;
IsRootChildFn isRootChildFn = nullptr;
};

/*! Ufe runtime handlers used to initialize the plugin.
Expand Down
19 changes: 14 additions & 5 deletions lib/usdUfe/ufe/UsdContextOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,15 @@ Ufe::ContextOps::Items UsdContextOps::getItems(const Ufe::ContextOps::ItemPath&
if (object3dHndlr) {
auto object3d = object3dHndlr->object3d(sceneItem());
if (object3d) {
auto visibility = object3d->visibility();
const auto l = visibility ? std::string(kUSDMakeInvisibleLabel)
: std::string(kUSDMakeVisibleLabel);
items.emplace_back(kUSDToggleVisibilityItem, l);
// Don't actually use UsdObject3d::visibility() - it looks at the authored
// visibility attribute. Instead, compute the effective visibility to decide on
// the label to use.
const auto imageable = UsdGeomImageable(prim());
const auto visibility
= imageable.ComputeVisibility() != UsdGeomTokens->invisible;
const auto label = visibility ? std::string(kUSDMakeInvisibleLabel)
: std::string(kUSDMakeVisibleLabel);
items.emplace_back(kUSDToggleVisibilityItem, label);
}
}
// Prim active state:
Expand Down Expand Up @@ -433,7 +438,11 @@ Ufe::UndoableCommand::Ptr UsdContextOps::doOpCmd(const ItemPath& itemPath)
auto object3d = UsdObject3d::create(fItem);
if (!TF_VERIFY(object3d))
return nullptr;
auto current = object3d->visibility();
// Don't use UsdObject3d::visibility() - it looks at the authored visibility
// attribute. Instead, compute the effective visibility, which is what we want
// to toggle.
const auto imageable = UsdGeomImageable(prim());
const auto current = imageable.ComputeVisibility() != UsdGeomTokens->invisible;
return object3d->setVisibleCmd(!current);
} // Visibility
else if (itemPath[0] == kUSDToggleActiveStateItem) {
Expand Down
35 changes: 24 additions & 11 deletions lib/usdUfe/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ UsdUfe::UfePathToPrimFn gUfePathToPrimFn = nullptr;
UsdUfe::TimeAccessorFn gTimeAccessorFn = nullptr;
UsdUfe::IsAttributeLockedFn gIsAttributeLockedFn = nullptr;
UsdUfe::SaveStageLoadRulesFn gSaveStageLoadRulesFn = nullptr;
UsdUfe::IsRootChildFn gIsRootChildFn = nullptr;

} // anonymous namespace

Expand Down Expand Up @@ -231,6 +232,29 @@ void saveStageLoadRules(const PXR_NS::UsdStageRefPtr& stage)
gSaveStageLoadRulesFn(stage);
}

void setIsRootChildFn(IsRootChildFn fn)
{
// This function is allowed to be null in which case, the default implementation
// is used (isRootChildDefault()).
gIsRootChildFn = fn;
}

bool isRootChild(const Ufe::Path& path)
{
return gIsRootChildFn ? gIsRootChildFn(path) : isRootChildDefault(path);
}

bool isRootChildDefault(const Ufe::Path& path)
{
// When called we make the assumption that we are given a valid
// path and we are only testing whether or not we are a root child.
auto segments = path.getSegments();
if (segments.size() != 2) {
TF_RUNTIME_ERROR(kIllegalUFEPath, path.string().c_str());
}
return (segments[1].size() == 1);
}

int ufePathToInstanceIndex(const Ufe::Path& path, UsdPrim* prim)
{
int instanceIndex = UsdImagingDelegate::ALL_INSTANCES;
Expand All @@ -254,17 +278,6 @@ int ufePathToInstanceIndex(const Ufe::Path& path, UsdPrim* prim)
return instanceIndex;
}

bool isRootChild(const Ufe::Path& path)
{
// When called we make the assumption that we are given a valid
// path and we are only testing whether or not we are a root child.
auto segments = path.getSegments();
if (segments.size() != 2) {
TF_RUNTIME_ERROR(kIllegalUFEPath, path.string().c_str());
}
return (segments[1].size() == 1);
}

std::string uniqueName(const TfToken::HashSet& existingNames, std::string srcName)
{
// Compiled regular expression to find a numerical suffix to a path component.
Expand Down
14 changes: 14 additions & 0 deletions lib/usdUfe/ufe/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ typedef PXR_NS::UsdPrim (*UfePathToPrimFn)(const Ufe::Path&);
typedef PXR_NS::UsdTimeCode (*TimeAccessorFn)(const Ufe::Path&);
typedef bool (*IsAttributeLockedFn)(const PXR_NS::UsdAttribute& attr, std::string* errMsg);
typedef void (*SaveStageLoadRulesFn)(const PXR_NS::UsdStageRefPtr&);
typedef bool (*IsRootChildFn)(const Ufe::Path& path);

//------------------------------------------------------------------------------
// Helper functions
Expand Down Expand Up @@ -137,9 +138,22 @@ void saveStageLoadRules(const PXR_NS::UsdStageRefPtr& stage);
USDUFE_PUBLIC
int ufePathToInstanceIndex(const Ufe::Path& path, PXR_NS::UsdPrim* prim = nullptr);

//! Set the DCC specific "isRootChild" test function.
//! Use of this function is optional, if one is not supplied then
//! a default implementation of isRootChild is used..
USDUFE_PUBLIC
void setIsRootChildFn(IsRootChildFn fn);

//! Returns true if the path corresponds to an item at the root of a runtime.
//! Implementation can be set by the DCC.
USDUFE_PUBLIC
bool isRootChild(const Ufe::Path& path);

//! Default isRootChild() implementation. Assumes 2 segments. Will report a root child
//! if the second segment has a single component.
USDUFE_PUBLIC
bool isRootChildDefault(const Ufe::Path& path);

//! Split the source name into a base name and a numerical suffix (set to
//! 1 if absent). Increment the numerical suffix until name is unique.
USDUFE_PUBLIC
Expand Down