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-123719 - Bringing back the display layers in EditAsMaya support by fixing the crash #2673

Merged
merged 3 commits into from
Oct 27, 2022
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
57 changes: 32 additions & 25 deletions lib/mayaUsd/ufe/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,27 @@ std::vector<std::string> splitString(const std::string& str, const std::string&
return split;
}

#ifdef MAYA_HAS_DISPLAY_LAYER_API
template <typename PathType>
void handleDisplayLayer(
const PathType& displayLayerPath,
const std::function<void(const MFnDisplayLayer&)>& handler)
{
MFnDisplayLayerManager displayLayerManager(
MFnDisplayLayerManager::currentDisplayLayerManager());

MObject displayLayerObj = displayLayerManager.getLayer(displayLayerPath);
if (displayLayerObj.hasFn(MFn::kDisplayLayer)) {
MFnDisplayLayer displayLayer(displayLayerObj);
// UFE display layers coming from referenced files are not yet supported in Maya
// and their usage leads to a crash, so skip those for the time being
if (!displayLayer.isFromReferencedFile()) {
handler(displayLayer);
}
}
}
#endif

void ReplicateExtrasFromUSD::initRecursive(Ufe::SceneItem::Ptr ufeItem) const
{
auto node = Ufe::Hierarchy::hierarchy(ufeItem);
Expand All @@ -912,29 +933,19 @@ void ReplicateExtrasFromUSD::initRecursive(Ufe::SceneItem::Ptr ufeItem) const
initRecursive(child);
}

// temporarily disable the feature to avoid the crash described in MAYA-125835
#if false
//#ifdef MAYA_HAS_DISPLAY_LAYER_API
// Prepare _displayLayerMap
MFnDisplayLayerManager displayLayerManager(
MFnDisplayLayerManager::currentDisplayLayerManager());

MObject displayLayerObj
= displayLayerManager.getLayer(Ufe::PathString::string(ufeItem->path()).c_str());
if (displayLayerObj.hasFn(MFn::kDisplayLayer)) {
MFnDisplayLayer displayLayer(displayLayerObj);
#ifdef MAYA_HAS_DISPLAY_LAYER_API
MString displayLayerPath(Ufe::PathString::string(ufeItem->path()).c_str());
handleDisplayLayer(displayLayerPath, [this, &ufeItem](const MFnDisplayLayer& displayLayer) {
if (displayLayer.name() != "defaultLayer") {
_displayLayerMap[ufeItem->path()] = displayLayerObj;
_displayLayerMap[ufeItem->path()] = displayLayer.object();
}
}
});
#endif
}

void ReplicateExtrasFromUSD::processItem(const Ufe::Path& path, const MObject& mayaObject) const
{
// temporarily disable the feature to avoid the crash described in MAYA-125835
#if false
//#ifdef MAYA_HAS_DISPLAY_LAYER_API
#ifdef MAYA_HAS_DISPLAY_LAYER_API
// Replicate display layer membership
auto it = _displayLayerMap.find(path);
if (it != _displayLayerMap.end() && it->second.hasFn(MFn::kDisplayLayer)) {
Expand All @@ -954,9 +965,7 @@ void ReplicateExtrasFromUSD::processItem(const Ufe::Path& path, const MObject& m

void ReplicateExtrasToUSD::processItem(const MDagPath& dagPath, const SdfPath& usdPath) const
{
// temporarily disable the feature to avoid the crash described in MAYA-125835
#if false
//#ifdef MAYA_HAS_DISPLAY_LAYER_API
#ifdef MAYA_HAS_DISPLAY_LAYER_API
// Populate display layer membership map

// Since multiple dag paths may lead to a single USD path (like transform and node),
Expand All @@ -969,18 +978,16 @@ void ReplicateExtrasToUSD::processItem(const MDagPath& dagPath, const SdfPath& u
}

if (!displayLayerAssigned) {
MFnDisplayLayerManager displayLayerManager(
MFnDisplayLayerManager::currentDisplayLayerManager());
_primToLayerMap[usdPath] = displayLayerManager.getLayer(dagPath);
handleDisplayLayer(dagPath, [this, &usdPath](const MFnDisplayLayer& displayLayer) {
_primToLayerMap[usdPath] = displayLayer.object();
});
}
#endif
}

void ReplicateExtrasToUSD::finalize(const Ufe::Path& stagePath, const std::string* renameRoot) const
{
// temporarily disable the feature to avoid the crash described in MAYA-125835
#if false
//#ifdef MAYA_HAS_DISPLAY_LAYER_API
#ifdef MAYA_HAS_DISPLAY_LAYER_API
// Replicate display layer membership
for (const auto& entry : _primToLayerMap) {
if (entry.second.hasFn(MFn::kDisplayLayer)) {
Expand Down
1 change: 0 additions & 1 deletion test/lib/ufe/testDisplayLayer.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,6 @@ def testDisplayLayerClear(self):
self.assertFalse(layer1.contains(self.CUBE1))
self.assertFalse(layer1.contains(self.INVALID_PRIM))

@unittest.skip("The feature was temporarily disabled so disable the autotest too")
def testDisplayLayerEditAsMaya(self):
'''Display layer membership in Edit As Maya workflow.'''

Expand Down