Skip to content

Commit

Permalink
connect Maya time to USD Imaging SceneIndex
Browse files Browse the repository at this point in the history
  • Loading branch information
lilike-adsk committed Aug 24, 2023
1 parent 50a1883 commit 1e556a3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
25 changes: 24 additions & 1 deletion lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
#include <maya/MObjectHandle.h>
#include <maya/MSelectionList.h>
#include <maya/MString.h>
#include <maya/MEventMessage.h>
#include <ufe/rtid.h>

PXR_NAMESPACE_OPEN_SCOPE
Expand Down Expand Up @@ -282,9 +283,13 @@ MayaUsdProxyShapeSceneIndex::MayaUsdProxyShapeSceneIndex(
TfWeakPtr<MayaUsdProxyShapeSceneIndex> 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,
Expand All @@ -296,6 +301,22 @@ MayaUsdProxyShapeSceneIndexRefPtr MayaUsdProxyShapeSceneIndex::New(
sceneIndexChainLastElement, usdImagingStageSceneIndex, proxyShape));
}

void MayaUsdProxyShapeSceneIndex::onTimeChanged(void* data)
{
auto* instance = reinterpret_cast<MayaUsdProxyShapeSceneIndex*>(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)
Expand Down Expand Up @@ -339,6 +360,8 @@ void MayaUsdProxyShapeSceneIndex::Populate()
#endif
_populated = true;
}
// Set the initial time
UpdateTime();
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@

#include <ufe/path.h>

#include <maya/MMessage.h>

#include <memory>

//////////////////////////////////////////////////////////////// MayaUsdProxyShapeSceneIndexPlugin
Expand Down Expand Up @@ -92,6 +94,8 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase

virtual ~MayaUsdProxyShapeSceneIndex();

void UpdateTime();

private:
void ObjectsChanged(const MayaUsdProxyStageObjectsChangedNotice& notice);

Expand All @@ -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

Expand Down

0 comments on commit 1e556a3

Please sign in to comment.