Skip to content

Commit 164601a

Browse files
authored
Merge pull request #3177 from Autodesk/gamaj/EMSUSD-193/reintroduce_legacy_smart_signaling_in_2024
EMSUSD-193 - Reintroduce legacy smart signaling in 2024
2 parents 50a1336 + 1b0af2c commit 164601a

File tree

3 files changed

+113
-0
lines changed

3 files changed

+113
-0
lines changed

lib/mayaUsd/nodes/proxyShapeBase.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ MObject MayaUsdProxyShapeBase::drawGuidePurposeAttr;
159159
MObject MayaUsdProxyShapeBase::sessionLayerNameAttr;
160160
MObject MayaUsdProxyShapeBase::rootLayerNameAttr;
161161
MObject MayaUsdProxyShapeBase::mutedLayersAttr;
162+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
163+
// Change counter attributes
164+
MObject MayaUsdProxyShapeBase::updateCounterAttr;
165+
MObject MayaUsdProxyShapeBase::resyncCounterAttr;
166+
#endif
162167
// Output attributes
163168
MObject MayaUsdProxyShapeBase::outTimeAttr;
164169
MObject MayaUsdProxyShapeBase::outStageDataAttr;
@@ -402,6 +407,28 @@ MStatus MayaUsdProxyShapeBase::initialize()
402407
retValue = addAttribute(outStageDataAttr);
403408
CHECK_MSTATUS_AND_RETURN_IT(retValue);
404409

410+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
411+
updateCounterAttr
412+
= numericAttrFn.create("updateId", "upid", MFnNumericData::kInt64, -1, &retValue);
413+
CHECK_MSTATUS_AND_RETURN_IT(retValue);
414+
numericAttrFn.setStorable(false);
415+
numericAttrFn.setWritable(false);
416+
numericAttrFn.setHidden(true);
417+
numericAttrFn.setInternal(true);
418+
retValue = addAttribute(updateCounterAttr);
419+
CHECK_MSTATUS_AND_RETURN_IT(retValue);
420+
421+
resyncCounterAttr
422+
= numericAttrFn.create("resyncId", "rsid", MFnNumericData::kInt64, -1, &retValue);
423+
CHECK_MSTATUS_AND_RETURN_IT(retValue);
424+
numericAttrFn.setStorable(false);
425+
numericAttrFn.setWritable(false);
426+
numericAttrFn.setHidden(true);
427+
numericAttrFn.setInternal(true);
428+
retValue = addAttribute(resyncCounterAttr);
429+
CHECK_MSTATUS_AND_RETURN_IT(retValue);
430+
#endif
431+
405432
outStageCacheIdAttr
406433
= numericAttrFn.create("outStageCacheId", "ostcid", MFnNumericData::kInt, -1, &retValue);
407434
CHECK_MSTATUS_AND_RETURN_IT(retValue);
@@ -568,6 +595,24 @@ void MayaUsdProxyShapeBase::postConstructor()
568595
}
569596
}
570597

598+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
599+
/* virtual */
600+
bool MayaUsdProxyShapeBase::getInternalValue(const MPlug& plug, MDataHandle& handle)
601+
{
602+
bool retVal = true;
603+
604+
if (plug == updateCounterAttr) {
605+
handle.set(_UsdStageUpdateCounter);
606+
} else if (plug == resyncCounterAttr) {
607+
handle.set(_UsdStageResyncCounter);
608+
} else {
609+
retVal = MPxSurfaceShape::getInternalValue(plug, handle);
610+
}
611+
612+
return retVal;
613+
}
614+
#endif
615+
571616
/* virtual */
572617
MStatus MayaUsdProxyShapeBase::compute(const MPlug& plug, MDataBlock& dataBlock)
573618
{
@@ -1998,10 +2043,19 @@ void MayaUsdProxyShapeBase::_OnStageObjectsChanged(const UsdNotice::ObjectsChang
19982043
MProfilingScope profilingScope(
19992044
_shapeBaseProfilerCategory, MProfiler::kColorB_L1, "Process USD objects changed");
20002045

2046+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
2047+
switch (UsdMayaStageNoticeListener::ClassifyObjectsChanged(notice)) {
2048+
case UsdMayaStageNoticeListener::ChangeType::kIgnored: return;
2049+
case UsdMayaStageNoticeListener::ChangeType::kResync: ++_UsdStageResyncCounter;
2050+
// [[fallthrough]]; // We want that fallthrough to have the update always triggered.
2051+
case UsdMayaStageNoticeListener::ChangeType::kUpdate: ++_UsdStageUpdateCounter; break;
2052+
}
2053+
#else
20012054
if (UsdMayaStageNoticeListener::ClassifyObjectsChanged(notice)
20022055
== UsdMayaStageNoticeListener::ChangeType::kIgnored) {
20032056
return;
20042057
}
2058+
#endif
20052059

20062060
// This will definitely force a BBox recomputation on "Frame All" or when framing a selected
20072061
// stage. Computing bounds in USD is expensive, so if it pops up in other frequently used

lib/mayaUsd/nodes/proxyShapeBase.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ class MayaUsdProxyShapeBase
126126
MAYAUSD_CORE_PUBLIC
127127
static MObject mutedLayersAttr;
128128

129+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
130+
// Change counter attributes
131+
MAYAUSD_CORE_PUBLIC
132+
static MObject updateCounterAttr;
133+
MAYAUSD_CORE_PUBLIC
134+
static MObject resyncCounterAttr;
135+
#endif
136+
129137
// Output attributes
130138
MAYAUSD_CORE_PUBLIC
131139
static MObject outTimeAttr;
@@ -171,6 +179,10 @@ class MayaUsdProxyShapeBase
171179

172180
MAYAUSD_CORE_PUBLIC
173181
void postConstructor() override;
182+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
183+
MAYAUSD_CORE_PUBLIC
184+
bool getInternalValue(const MPlug&, MDataHandle&) override;
185+
#endif
174186
MAYAUSD_CORE_PUBLIC
175187
MStatus compute(const MPlug& plug, MDataBlock& dataBlock) override;
176188
MAYAUSD_CORE_PUBLIC
@@ -406,6 +418,12 @@ class MayaUsdProxyShapeBase
406418
size_t _excludePrimPathsVersion { 1 };
407419
size_t _UsdStageVersion { 1 };
408420

421+
#if MAYA_API_VERSION >= 20240000 && MAYA_API_VERSION <= 20249999
422+
// Notification counters:
423+
MInt64 _UsdStageUpdateCounter { 1 };
424+
MInt64 _UsdStageResyncCounter { 1 };
425+
#endif
426+
409427
MayaUsd::ProxyAccessor::Owner _usdAccessor;
410428

411429
static ClosestPointDelegate _sharedClosestPointDelegate;

test/lib/ufe/testContextOps.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1492,6 +1492,27 @@ def testGeomCoponentAssignment(self):
14921492
self.assertEqual(topSubset.GetFamilyNameAttr().Get(), "componentTag")
14931493
self.assertFalse(topSubset.GetPrim().HasAPI(UsdShade.MaterialBindingAPI))
14941494

1495+
if mayaUtils.mayaMajorVersion() == 2024:
1496+
# We also can check the old sync counters:
1497+
counters= { "resync": cmds.getAttr(psPathStr + '.resyncId'),
1498+
"update" : cmds.getAttr(psPathStr + '.upid')}
1499+
1500+
def assertIsOnlyUpdate(self, counters, shapePathStr):
1501+
resyncCounter = cmds.getAttr(shapePathStr + '.resyncId')
1502+
updateCounter = cmds.getAttr(shapePathStr + '.updateId')
1503+
self.assertEqual(resyncCounter, counters["resync"])
1504+
self.assertGreater(updateCounter, counters["update"])
1505+
counters["resync"] = resyncCounter
1506+
counters["update"] = updateCounter
1507+
1508+
def assertIsResync(self, counters, shapePathStr):
1509+
resyncCounter = cmds.getAttr(shapePathStr + '.resyncId')
1510+
updateCounter = cmds.getAttr(shapePathStr + '.updateId')
1511+
self.assertGreater(resyncCounter, counters["resync"])
1512+
self.assertGreater(updateCounter, counters["update"])
1513+
counters["resync"] = resyncCounter
1514+
counters["update"] = updateCounter
1515+
14951516
messageHandler = mayaUtils.TestProxyShapeUpdateHandler(psPathStr)
14961517
messageHandler.snapshot()
14971518

@@ -1508,47 +1529,66 @@ def testGeomCoponentAssignment(self):
15081529

15091530
# We expect a resync after this assignment:
15101531
self.assertTrue(messageHandler.isResync())
1532+
if mayaUtils.mayaMajorVersion() == 2024:
1533+
assertIsResync(self, counters, psPathStr)
15111534

15121535
# setting a value the first time is a resync due to the creation of the attribute:
15131536
attrs = ufe.Attributes.attributes(shaderItem)
15141537
metallicAttr = attrs.attribute("inputs:metallic")
15151538
ufeCmd.execute(metallicAttr.setCmd(0.5))
15161539
self.assertTrue(messageHandler.isResync())
1540+
if mayaUtils.mayaMajorVersion() == 2024:
1541+
assertIsResync(self, counters, psPathStr)
15171542

15181543
# Subsequent changes are updates:
15191544
ufeCmd.execute(metallicAttr.setCmd(0.7))
15201545
self.assertTrue(messageHandler.isUpdate())
1546+
if mayaUtils.mayaMajorVersion() == 2024:
1547+
assertIsOnlyUpdate(self, counters, psPathStr)
15211548

15221549
# First undo is an update:
15231550
cmds.undo()
15241551
self.assertTrue(messageHandler.isUpdate())
1552+
if mayaUtils.mayaMajorVersion() == 2024:
1553+
assertIsOnlyUpdate(self, counters, psPathStr)
15251554

15261555
# Second undo is a resync:
15271556
cmds.undo()
15281557
self.assertTrue(messageHandler.isResync())
1558+
if mayaUtils.mayaMajorVersion() == 2024:
1559+
assertIsResync(self, counters, psPathStr)
15291560

15301561
# Third undo is also resync:
15311562
cmds.undo()
15321563
self.assertTrue(messageHandler.isResync())
1564+
if mayaUtils.mayaMajorVersion() == 2024:
1565+
assertIsResync(self, counters, psPathStr)
15331566

15341567
# First redo is resync:
15351568
cmds.redo()
15361569
self.assertTrue(messageHandler.isResync())
1570+
if mayaUtils.mayaMajorVersion() == 2024:
1571+
assertIsResync(self, counters, psPathStr)
15371572

15381573
# Second redo is resync:
15391574
cmds.redo()
15401575
self.assertTrue(messageHandler.isResync())
1576+
if mayaUtils.mayaMajorVersion() == 2024:
1577+
assertIsResync(self, counters, psPathStr)
15411578

15421579
# Third redo is update:
15431580
cmds.redo()
15441581
self.assertTrue(messageHandler.isUpdate())
1582+
if mayaUtils.mayaMajorVersion() == 2024:
1583+
assertIsOnlyUpdate(self, counters, psPathStr)
15451584
currentCacheId = messageHandler.getStageCacheId()
15461585

15471586
# Changing the whole stage is a resync:
15481587
testFile = testUtils.getTestScene("MaterialX", "MtlxValueTypes.usda")
15491588
cmds.setAttr('{}.filePath'.format(psPathStr), testFile, type='string')
15501589

15511590
self.assertTrue(messageHandler.isResync())
1591+
# The old smart signaling for Maya 2024 will not catch that.
15521592

15531593
# But that will be the last resync:
15541594
testFile = testUtils.getTestScene("MaterialX", "sin_compound.usda")
@@ -1564,6 +1604,7 @@ def testGeomCoponentAssignment(self):
15641604
cmds.setAttr('{}.filePath'.format(psPathStr), testFile, type='string')
15651605

15661606
self.assertTrue(messageHandler.isResync())
1607+
# The old smart signaling for Maya 2024 will not catch that.
15671608

15681609
messageHandler.terminate()
15691610

0 commit comments

Comments
 (0)