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

connect Maya Time to USD Imaging SceneIndex #3296

Merged
merged 3 commits into from
Aug 25, 2023
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
26 changes: 25 additions & 1 deletion lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#endif
#endif

#include <maya/MEventMessage.h>
#include <maya/MObject.h>
#include <maya/MObjectHandle.h>
#include <maya/MSelectionList.h>
Expand Down Expand Up @@ -282,9 +283,14 @@ 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 +302,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 +361,8 @@ void MayaUsdProxyShapeSceneIndex::Populate()
#endif
_populated = true;
}
// Set the initial time
UpdateTime();
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions lib/mayaUsd/sceneIndex/proxyShapeSceneIndexPlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <pxr/usd/sdf/path.h>
#include <pxr/usdImaging/usdImaging/stageSceneIndex.h>

#include <maya/MMessage.h>
#include <ufe/path.h>

#include <memory>
Expand Down Expand Up @@ -92,6 +93,8 @@ class MayaUsdProxyShapeSceneIndex : public HdSingleInputFilteringSceneIndexBase

virtual ~MayaUsdProxyShapeSceneIndex();

void UpdateTime();

private:
void ObjectsChanged(const MayaUsdProxyStageObjectsChangedNotice& notice);

Expand All @@ -113,9 +116,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