Skip to content

Commit

Permalink
HnSkinningComputation: added GetLastFrameXforms() method
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Nov 27, 2024
1 parent b2a66be commit 4f4b83d
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
1 change: 1 addition & 0 deletions Hydrogent/include/Computations/HnSkinningComputation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class HnSkinningComputation final : public HnExtComputationImpl
static bool IsCompatible(const HnExtComputation& Owner);

const pxr::VtMatrix4fArray& GetXforms() const { return m_Xforms[m_CurrXformsIdx]; }
const pxr::VtMatrix4fArray& GetLastFrameXforms() const { return m_Xforms[1 - m_CurrXformsIdx]; }
size_t GetXformsHash() const { return m_XformsHash; }

const float4x4& GetPrimWorldToLocal() const { return m_PrimWorldToLocal; }
Expand Down
7 changes: 4 additions & 3 deletions Hydrogent/interface/HnMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,10 @@ class HnMesh final : public pxr::HdMesh

struct Skinning
{
const pxr::VtMatrix4fArray* Xforms = nullptr;
size_t XformsHash = 0;
float4x4 GeomBindXform = float4x4::Identity();
const pxr::VtMatrix4fArray* Xforms = nullptr;
const pxr::VtMatrix4fArray* LastFrameXforms = nullptr;
size_t XformsHash = 0;
float4x4 GeomBindXform = float4x4::Identity();

explicit operator bool() const { return Xforms != nullptr; }
};
Expand Down
9 changes: 7 additions & 2 deletions Hydrogent/src/Computations/HnSkinningComputation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,15 @@ void HnSkinningComputation::Sync(pxr::HdSceneDelegate* SceneDelegate,
pxr::VtValue SkinningXformsVal = SceneDelegate->GetExtComputationInput(Id, HnSkinningComputationPrivateTokens->skinningXforms);
if (SkinningXformsVal.IsHolding<pxr::VtMatrix4fArray>())
{
m_CurrXformsIdx = (m_CurrXformsIdx + 1) % m_Xforms.size();
pxr::VtMatrix4fArray& LastXforms = m_Xforms[m_CurrXformsIdx];
VERIFY_EXPR(m_Xforms.size() == 2);
m_CurrXformsIdx = 1 - m_CurrXformsIdx;
pxr::VtMatrix4fArray& Xforms = m_Xforms[m_CurrXformsIdx];

Xforms = SkinningXformsVal.UncheckedGet<pxr::VtMatrix4fArray>();
Xforms = SkinningXformsVal.UncheckedGet<pxr::VtMatrix4fArray>();
if (LastXforms.empty())
LastXforms = Xforms;

m_XformsHash = pxr::TfHash{}(Xforms);

const HnRenderDelegate* RenderDelegate = static_cast<const HnRenderDelegate*>(SceneDelegate->GetRenderIndex().GetRenderDelegate());
Expand Down
5 changes: 3 additions & 2 deletions Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -915,8 +915,9 @@ void HnMesh::UpdateSkinningPrimvars(pxr::HdSceneDelegate&

if (const HnSkinningComputation* SkinningCompImpl = SkinningComp->GetImpl<HnSkinningComputation>())
{
SkinningData.Xforms = &SkinningCompImpl->GetXforms();
SkinningData.XformsHash = SkinningCompImpl->GetXformsHash();
SkinningData.Xforms = &SkinningCompImpl->GetXforms();
SkinningData.LastFrameXforms = &SkinningCompImpl->GetLastFrameXforms();
SkinningData.XformsHash = SkinningCompImpl->GetXformsHash();

const float4x4& SkelLocalToPrimLocal = SkinningCompImpl->GetSkelLocalToPrimLocal();
if (SkelLocalToPrimLocal != m_SkelLocalToPrimLocal)
Expand Down

0 comments on commit 4f4b83d

Please sign in to comment.