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-125028 add layer muting serialization to the proxy shape #2580

Merged
merged 4 commits into from
Oct 6, 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
32 changes: 32 additions & 0 deletions lib/mayaUsd/listeners/stageNoticeListener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@ void UsdMayaStageNoticeListener::SetStageObjectsChangedCallback(
_UpdateStageContentsChangedRegistration();
}

void UsdMayaStageNoticeListener::SetStageLayerMutingChangedCallback(
const StageLayerMutingChangedCallback& callback)
{
_stageLayerMutingChangedCallback = callback;

_UpdateStageContentsChangedRegistration();
}

void UsdMayaStageNoticeListener::_UpdateStageContentsChangedRegistration()
{
if (_stage && _stageContentsChangedCallback) {
Expand Down Expand Up @@ -85,6 +93,22 @@ void UsdMayaStageNoticeListener::_UpdateStageContentsChangedRegistration()
TfNotice::Revoke(_stageObjectsChangedKey);
}
}

if (_stage && _stageLayerMutingChangedCallback) {
// Register for notices if we're not already listening.
if (!_stageLayerMutingChangedKey.IsValid()) {
_stageLayerMutingChangedKey = TfNotice::Register(
TfCreateWeakPtr(this),
&UsdMayaStageNoticeListener::_OnStageLayerMutingChanged,
_stage);
}
} else {
// Either the stage or the callback is invalid, so stop listening for
// notices.
if (_stageLayerMutingChangedKey.IsValid()) {
TfNotice::Revoke(_stageLayerMutingChangedKey);
}
}
}

void UsdMayaStageNoticeListener::_OnStageContentsChanged(
Expand All @@ -104,4 +128,12 @@ void UsdMayaStageNoticeListener::_OnStageObjectsChanged(
}
}

void UsdMayaStageNoticeListener::_OnStageLayerMutingChanged(
const UsdNotice::LayerMutingChanged& notice) const
{
if (notice.GetStage() == _stage && _stageLayerMutingChangedCallback) {
_stageLayerMutingChangedCallback(notice);
}
}

PXR_NAMESPACE_CLOSE_SCOPE
11 changes: 11 additions & 0 deletions lib/mayaUsd/listeners/stageNoticeListener.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class UsdMayaStageNoticeListener : public TfWeakBase
= std::function<void(const UsdNotice::StageContentsChanged& notice)>;
using StageObjectsChangedCallback
= std::function<void(const UsdNotice::ObjectsChanged& notice)>;
using StageLayerMutingChangedCallback
= std::function<void(const UsdNotice::LayerMutingChanged& notice)>;

/// Sets the callback to be invoked when the listener receives a
/// StageContentsChanged notice.
Expand All @@ -63,6 +65,11 @@ class UsdMayaStageNoticeListener : public TfWeakBase
MAYAUSD_CORE_PUBLIC
void SetStageObjectsChangedCallback(const StageObjectsChangedCallback& callback);

/// Sets the callback to be invoked when the listener receives a
/// ObjectsChanged notice.
MAYAUSD_CORE_PUBLIC
void SetStageLayerMutingChangedCallback(const StageLayerMutingChangedCallback& callback);

private:
UsdMayaStageNoticeListener(const UsdMayaStageNoticeListener&) = delete;
UsdMayaStageNoticeListener& operator=(const UsdMayaStageNoticeListener&) = delete;
Expand All @@ -76,8 +83,12 @@ class UsdMayaStageNoticeListener : public TfWeakBase
TfNotice::Key _stageObjectsChangedKey {};
StageObjectsChangedCallback _stageObjectsChangedCallback {};

TfNotice::Key _stageLayerMutingChangedKey {};
StageLayerMutingChangedCallback _stageLayerMutingChangedCallback {};

void _UpdateStageContentsChangedRegistration();
void _OnStageContentsChanged(const UsdNotice::StageContentsChanged& notice) const;
void _OnStageLayerMutingChanged(const UsdNotice::LayerMutingChanged& notice) const;
void _OnStageObjectsChanged(
const UsdNotice::ObjectsChanged& notice,
const UsdStageWeakPtr& sender) const;
Expand Down
4 changes: 2 additions & 2 deletions lib/mayaUsd/nodes/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ target_sources(${PROJECT_NAME}
pointBasedDeformerNode.cpp
proxyAccessor.cpp
proxyShapeBase.cpp
proxyShapeLoadRules.cpp
proxyShapePlugin.cpp
proxyShapeStageExtraData.cpp
stageData.cpp
stageNode.cpp
usdPrimProvider.cpp
Expand All @@ -19,9 +19,9 @@ set(HEADERS
pointBasedDeformerNode.h
proxyAccessor.h
proxyShapeBase.h
proxyShapeLoadRules.h
proxyShapePlugin.h
proxyStageProvider.h
proxyShapeStageExtraData.h
stageData.h
stageNode.h
usdPrimProvider.h
Expand Down
69 changes: 61 additions & 8 deletions lib/mayaUsd/nodes/proxyShapeBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@

#include <mayaUsd/base/debugCodes.h>
#include <mayaUsd/base/tokens.h>
#include <mayaUsd/fileio/utils/readUtil.h>
#include <mayaUsd/fileio/utils/writeUtil.h>
#include <mayaUsd/listeners/proxyShapeNotice.h>
#include <mayaUsd/nodes/proxyShapeLoadRules.h>
#include <mayaUsd/nodes/proxyShapeStageExtraData.h>
#include <mayaUsd/nodes/stageData.h>
#include <mayaUsd/utils/customLayerData.h>
#include <mayaUsd/utils/layerMuting.h>
#include <mayaUsd/utils/loadRules.h>
#include <mayaUsd/utils/query.h>
#include <mayaUsd/utils/stageCache.h>
Expand Down Expand Up @@ -73,6 +76,7 @@
#include <maya/MFnNumericAttribute.h>
#include <maya/MFnPluginData.h>
#include <maya/MFnReference.h>
#include <maya/MFnStringArrayData.h>
#include <maya/MFnStringData.h>
#include <maya/MFnTypedAttribute.h>
#include <maya/MFnUnitAttribute.h>
Expand Down Expand Up @@ -115,9 +119,10 @@ TF_DEFINE_PUBLIC_TOKENS(MayaUsdProxyShapeBaseTokens, MAYAUSD_PROXY_SHAPE_BASE_TO
MayaUsdProxyShapeBase::ClosestPointDelegate MayaUsdProxyShapeBase::_sharedClosestPointDelegate
= nullptr;

const std::string kAnonymousLayerName { "anonymousLayer1" };
const std::string kSessionLayerPostfix { "-session" };
const std::string kUnsharedStageLayerName { "unshareableLayer" };
const std::string kAnonymousLayerName { "anonymousLayer1" };
const std::string kSessionLayerPostfix { "-session" };
const std::string kUnsharedStageLayerName { "unshareableLayer" };
static const char* kMutedLayersAttrName = "mutedLayers";

// ========================================================

Expand Down Expand Up @@ -145,6 +150,7 @@ MObject MayaUsdProxyShapeBase::drawProxyPurposeAttr;
MObject MayaUsdProxyShapeBase::drawGuidePurposeAttr;
MObject MayaUsdProxyShapeBase::sessionLayerNameAttr;
MObject MayaUsdProxyShapeBase::rootLayerNameAttr;
MObject MayaUsdProxyShapeBase::mutedLayersAttr;
// Output attributes
MObject MayaUsdProxyShapeBase::outTimeAttr;
MObject MayaUsdProxyShapeBase::outStageDataAttr;
Expand Down Expand Up @@ -388,6 +394,15 @@ MStatus MayaUsdProxyShapeBase::initialize()
retValue = addAttribute(rootLayerNameAttr);
CHECK_MSTATUS_AND_RETURN_IT(retValue);

mutedLayersAttr = typedAttrFn.create(
kMutedLayersAttrName, "mla", MFnData::kStringArray, MObject::kNullObj, &retValue);
typedAttrFn.setStorable(true);
typedAttrFn.setWritable(true);
typedAttrFn.setReadable(true);
CHECK_MSTATUS_AND_RETURN_IT(retValue);
retValue = addAttribute(mutedLayersAttr);
CHECK_MSTATUS_AND_RETURN_IT(retValue);

//
// add attribute dependencies
//
Expand Down Expand Up @@ -706,7 +721,7 @@ MStatus MayaUsdProxyShapeBase::computeInStageDataCached(MDataBlock& dataBlock)
// If there is a dynamic attribute containing the exact load rules
// for payload, start by loading nothing. The correct payload will
// be loaded by the load rules.
if (hasLoadRulesAttribute(thisMObject()))
if (hasLoadRulesAttribute(*this))
loadSet = UsdStage::InitialLoadSet::LoadNone;

// If inData has an incoming connection, then use it. Otherwise generate stage from the filepath
Expand Down Expand Up @@ -937,7 +952,8 @@ MStatus MayaUsdProxyShapeBase::computeInStageDataCached(MDataBlock& dataBlock)

if (finalUsdStage) {
primPath = finalUsdStage->GetPseudoRoot().GetPath();
copyLoadRulesFromAttribute(thisMObject(), *finalUsdStage);
copyLoadRulesFromAttribute(*this, *finalUsdStage);
copyLayerMutingFromAttribute(*this, *finalUsdStage);
updateShareMode(sharedUsdStage, unsharedUsdStage, loadSet);
}

Expand Down Expand Up @@ -1136,6 +1152,11 @@ MStatus MayaUsdProxyShapeBase::computeOutStageData(MDataBlock& dataBlock)
return _OnStageObjectsChanged(notice);
});

_stageNoticeListener.SetStageLayerMutingChangedCallback(
[this](const UsdNotice::LayerMutingChanged& notice) {
return _OnLayerMutingChanged(notice);
});

MayaUsdProxyStageSetNotice(*this).Send();
}

Expand Down Expand Up @@ -1571,6 +1592,29 @@ UsdPrim MayaUsdProxyShapeBase::_GetUsdPrim(MDataBlock dataBlock) const
return usdPrim;
}

std::vector<std::string> MayaUsdProxyShapeBase::getMutedLayers() const
{
MStatus status;
MFnDependencyNode depNode(thisMObject(), &status);
CHECK_MSTATUS_AND_RETURN(status, std::vector<std::string>());

std::vector<std::string> muted;
UsdMayaWriteUtil::ReadMayaAttribute(depNode, kMutedLayersAttrName, &muted);
return muted;
}

MStatus MayaUsdProxyShapeBase::setMutedLayers(const std::vector<std::string>& muted)
{
MStatus status;
MFnDependencyNode depNode(thisMObject(), &status);
CHECK_MSTATUS_AND_RETURN_IT(status);

MPlug mutedLayersPlug = depNode.findPlug(mutedLayersAttr, true);
VtStringArray mutedArray(muted.begin(), muted.end());
return UsdMayaReadUtil::SetMayaAttr(mutedLayersPlug, VtValue(mutedArray)) ? MStatus::kSuccess
: MStatus::kFailure;
}

int MayaUsdProxyShapeBase::getComplexity() const
{
return _GetComplexity(const_cast<MayaUsdProxyShapeBase*>(this)->forceCache());
Expand Down Expand Up @@ -1737,7 +1781,7 @@ MayaUsdProxyShapeBase::MayaUsdProxyShapeBase(
if (useLoadRulesHandling) {
// Register with the load-rules handling used to transfer load rules
// between the USD stage and a dynamic attribute on the proxy shape.
MayaUsdProxyShapeLoadRules::addProxyShape(*this);
MayaUsdProxyShapeStageExtraData::addProxyShape(*this);
}
}

Expand All @@ -1746,7 +1790,7 @@ MayaUsdProxyShapeBase::~MayaUsdProxyShapeBase()
{
// Deregister from the load-rules handling used to transfer load rules
// between the USD stage and a dynamic attribute on the proxy shape.
MayaUsdProxyShapeLoadRules::removeProxyShape(*this);
MayaUsdProxyShapeStageExtraData::removeProxyShape(*this);
}

MSelectionMask MayaUsdProxyShapeBase::getShapeSelectionMask() const
Expand Down Expand Up @@ -1785,6 +1829,15 @@ void MayaUsdProxyShapeBase::_OnStageContentsChanged(const UsdNotice::StageConten
MHWRender::MRenderer::setGeometryDrawDirty(thisMObject());
}

void MayaUsdProxyShapeBase::_OnLayerMutingChanged(const UsdNotice::LayerMutingChanged& notice)
{
const auto stage = getUsdStage();
if (!stage)
return;

copyLayerMutingToAttribute(*stage, *this);
}

void MayaUsdProxyShapeBase::_OnStageObjectsChanged(const UsdNotice::ObjectsChanged& notice)
{
MProfilingScope profilingScope(
Expand Down
9 changes: 9 additions & 0 deletions lib/mayaUsd/nodes/proxyShapeBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ class MayaUsdProxyShapeBase
static MObject sessionLayerNameAttr;
MAYAUSD_CORE_PUBLIC
static MObject rootLayerNameAttr;
MAYAUSD_CORE_PUBLIC
static MObject mutedLayersAttr;

// Output attributes
MAYAUSD_CORE_PUBLIC
Expand Down Expand Up @@ -197,6 +199,12 @@ class MayaUsdProxyShapeBase
MAYAUSD_CORE_PUBLIC
int getComplexity() const;

MAYAUSD_CORE_PUBLIC
std::vector<std::string> getMutedLayers() const;

MAYAUSD_CORE_PUBLIC
MStatus setMutedLayers(const std::vector<std::string>& muted);

MAYAUSD_CORE_PUBLIC
UsdTimeCode getTime() const override;
MAYAUSD_CORE_PUBLIC
Expand Down Expand Up @@ -381,6 +389,7 @@ class MayaUsdProxyShapeBase

void _OnStageContentsChanged(const UsdNotice::StageContentsChanged& notice);
void _OnStageObjectsChanged(const UsdNotice::ObjectsChanged& notice);
void _OnLayerMutingChanged(const UsdNotice::LayerMutingChanged& notice);

UsdMayaStageNoticeListener _stageNoticeListener;

Expand Down
6 changes: 3 additions & 3 deletions lib/mayaUsd/nodes/proxyShapePlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#include <mayaUsd/nodes/hdImagingShape.h>
#include <mayaUsd/nodes/pointBasedDeformerNode.h>
#include <mayaUsd/nodes/proxyShapeBase.h>
#include <mayaUsd/nodes/proxyShapeLoadRules.h>
#include <mayaUsd/nodes/proxyShapeStageExtraData.h>
#include <mayaUsd/nodes/stageData.h>
#include <mayaUsd/nodes/stageNode.h>
#include <mayaUsd/render/pxrUsdMayaGL/hdImagingShapeDrawOverride.h>
Expand Down Expand Up @@ -159,7 +159,7 @@ MStatus MayaUsdProxyShapePlugin::initialize(MFnPlugin& plugin)
PxrMayaHdImagingShapeDrawOverride::creator);
CHECK_MSTATUS(status);

status = MAYAUSD_NS::MayaUsdProxyShapeLoadRules::initialize();
status = MAYAUSD_NS::MayaUsdProxyShapeStageExtraData::initialize();
CHECK_MSTATUS(status);

return status;
Expand All @@ -186,7 +186,7 @@ MStatus MayaUsdProxyShapePlugin::finalize(MFnPlugin& plugin)
MStatus status = HdVP2ShaderFragments::deregisterFragments();
CHECK_MSTATUS(status);

status = MAYAUSD_NS::MayaUsdProxyShapeLoadRules::finalize();
status = MAYAUSD_NS::MayaUsdProxyShapeStageExtraData::finalize();
CHECK_MSTATUS(status);

status = MHWRender::MDrawRegistry::deregisterDrawOverrideCreator(
Expand Down
Loading