Skip to content

Commit

Permalink
usd: Send notification when bits of runtime state (that is, state not…
Browse files Browse the repository at this point in the history
… authored

in scene description) change that can affect computed values or the set of
objects on the stage.

Fixes #1139

(Internal change: 2050905)
  • Loading branch information
gitamohr authored and pixar-oss committed Mar 25, 2020
1 parent 79d432e commit 67cf735
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
20 changes: 18 additions & 2 deletions pxr/usd/usd/stage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,13 @@ UsdStage::SetLoadRules(UsdStageLoadRules const &rules)
PcpChanges changes;
changes.DidChangeSignificantly(_cache.get(), SdfPath::AbsoluteRootPath());
_Recompose(changes);

// Notify.
UsdStageWeakPtr self(this);
UsdNotice::ObjectsChanged::_PathsToChangesMap resyncChanges, infoChanges;
resyncChanges[SdfPath::AbsoluteRootPath()];
UsdNotice::ObjectsChanged(self, &resyncChanges, &infoChanges).Send(self);
UsdNotice::StageContentsChanged(self).Send(self);
}

void
Expand All @@ -2259,6 +2266,13 @@ UsdStage::SetPopulationMask(UsdStagePopulationMask const &mask)
PcpChanges changes;
changes.DidChangeSignificantly(_cache.get(), SdfPath::AbsoluteRootPath());
_Recompose(changes);

// Notify.
UsdStageWeakPtr self(this);
UsdNotice::ObjectsChanged::_PathsToChangesMap resyncChanges, infoChanges;
resyncChanges[SdfPath::AbsoluteRootPath()];
UsdNotice::ObjectsChanged(self, &resyncChanges, &infoChanges).Send(self);
UsdNotice::StageContentsChanged(self).Send(self);
}

void
Expand Down Expand Up @@ -8416,9 +8430,11 @@ UsdStage::SetInterpolationType(UsdInterpolationType interpolationType)
if (_interpolationType != interpolationType) {
_interpolationType = interpolationType;

// Emit StageContentsChanged, as interpolated attributes values
// have likely changed.
// Notify, as interpolated attributes values have likely changed.
UsdStageWeakPtr self(this);
UsdNotice::ObjectsChanged::_PathsToChangesMap resyncChanges, infoChanges;
resyncChanges[SdfPath::AbsoluteRootPath()];
UsdNotice::ObjectsChanged(self, &resyncChanges, &infoChanges).Send(self);
UsdNotice::StageContentsChanged(self).Send(self);
}
}
Expand Down
47 changes: 46 additions & 1 deletion pxr/usd/usd/testenv/testUsdStageNotification.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,18 @@ typedef std::function<bool (const UsdNotice::ObjectsChanged &)> TestFn;

struct _NoticeTester : public TfWeakBase
{
_NoticeTester(const UsdStageWeakPtr &stage) : _stage(stage) {
_NoticeTester(const UsdStageWeakPtr &stage)
: _stage(stage)
, _invokedTestFunctions(false) {
TfNotice::Register(
TfCreateWeakPtr(this), &_NoticeTester::_Handle, stage);
}

~_NoticeTester() {
// Ensure that any test functions were invoked at least once.
TF_AXIOM(_testFns.empty() || _invokedTestFunctions);
}

template <class Fn>
void AddTest(const Fn &testFn) { _testFns.push_back(testFn); }

Expand Down Expand Up @@ -90,10 +97,12 @@ struct _NoticeTester : public TfWeakBase
for (const auto& fn : _testFns) {
TF_AXIOM(fn(n));
}
_invokedTestFunctions = true;
}

UsdStageWeakPtr _stage;
std::vector<TestFn> _testFns;
bool _invokedTestFunctions;
};

void
Expand Down Expand Up @@ -506,6 +515,42 @@ TestObjectsChanged()
});
rel.AddTarget(SdfPath("/bar"));
}

// Assert that modifying runtime state (i.e. not scene description) on
// UsdStage that affects the set of objects on the stage or computed values
// sends notification.
{
printf("Changing load rules, population mask, interpolation type "
"should notify\n");

{
_NoticeTester tester(stage);
tester.AddTest([](Notice const &n) {
return TF_AXIOM(!n.GetResyncedPaths().empty());
});
stage->SetLoadRules(UsdStageLoadRules::LoadNone());
stage->SetLoadRules(UsdStageLoadRules::LoadAll());
}

{
_NoticeTester tester(stage);
tester.AddTest([](Notice const &n) {
return TF_AXIOM(!n.GetResyncedPaths().empty());
});
UsdStagePopulationMask nothingMask({ SdfPath("/no/such/prim") });
stage->SetPopulationMask(nothingMask);
stage->SetPopulationMask(UsdStagePopulationMask::All());
}

{
_NoticeTester tester(stage);
tester.AddTest([](Notice const &n) {
return TF_AXIOM(!n.GetResyncedPaths().empty());
});
stage->SetInterpolationType(UsdInterpolationTypeHeld);
stage->SetInterpolationType(UsdInterpolationTypeLinear);
}
}
}

int main()
Expand Down

0 comments on commit 67cf735

Please sign in to comment.