diff --git a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp index edfd17ae1b..08f88961df 100644 --- a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp +++ b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp @@ -65,6 +65,7 @@ #include #include #include +#include #include PXR_NAMESPACE_OPEN_SCOPE @@ -282,9 +283,13 @@ MayaUsdProxyShapeSceneIndex::MayaUsdProxyShapeSceneIndex( TfWeakPtr ptr(this); TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::StageSet); TfNotice::Register(ptr, &MayaUsdProxyShapeSceneIndex::ObjectsChanged); + + _timeChangeCallbackId = MEventMessage::addEventCallback("timeChanged", onTimeChanged, this); } -MayaUsdProxyShapeSceneIndex::~MayaUsdProxyShapeSceneIndex() { } +MayaUsdProxyShapeSceneIndex::~MayaUsdProxyShapeSceneIndex() { + MMessage::removeCallback(_timeChangeCallbackId); +} MayaUsdProxyShapeSceneIndexRefPtr MayaUsdProxyShapeSceneIndex::New( MayaUsdProxyShapeBase* proxyShape, @@ -296,6 +301,22 @@ MayaUsdProxyShapeSceneIndexRefPtr MayaUsdProxyShapeSceneIndex::New( sceneIndexChainLastElement, usdImagingStageSceneIndex, proxyShape)); } +void MayaUsdProxyShapeSceneIndex::onTimeChanged(void* data) +{ + auto* instance = reinterpret_cast(data); + if (!TF_VERIFY(instance)) { + return; + } + instance->UpdateTime(); +} + +void MayaUsdProxyShapeSceneIndex::UpdateTime() +{ + if (_usdImagingStageSceneIndex && _proxyShape) { + _usdImagingStageSceneIndex->SetTime(_proxyShape->getTime()); + } +} + Ufe::Path MayaUsdProxyShapeSceneIndex::InterpretRprimPath( const HdSceneIndexBaseRefPtr& sceneIndex, const SdfPath& path) @@ -339,6 +360,8 @@ void MayaUsdProxyShapeSceneIndex::Populate() #endif _populated = true; } + // Set the initial time + UpdateTime(); } } } diff --git a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h index 0765172fe2..3cf2ca1489 100644 --- a/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h +++ b/lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h @@ -33,6 +33,8 @@ #include +#include + #include //////////////////////////////////////////////////////////////// MayaUsdProxyShapeSceneIndexPlugin @@ -92,6 +94,8 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase virtual ~MayaUsdProxyShapeSceneIndex(); + void UpdateTime(); + private: void ObjectsChanged(const MayaUsdProxyStageObjectsChangedNotice& notice); @@ -113,9 +117,12 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase const HdSceneIndexObserver::DirtiedPrimEntries& entries) override final; private: + static void onTimeChanged(void* data); + UsdImagingStageSceneIndexRefPtr _usdImagingStageSceneIndex; MayaUsdProxyShapeBase* _proxyShape { nullptr }; std::atomic_bool _populated { false }; + MCallbackId _timeChangeCallbackId; }; } // namespace MAYAUSD_NS_DEF