Skip to content

Commit

Permalink
HnMesh: improved handling of geometry subset items
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMostDiligent committed Jan 20, 2025
1 parent 935b165 commit 6d7d1be
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 24 deletions.
7 changes: 4 additions & 3 deletions Hydrogent/interface/HnMesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ class HnMesh final : public pxr::HdMesh
// is used.
virtual void _InitRepr(const pxr::TfToken& reprToken, pxr::HdDirtyBits* dirtyBits) override final;

void UpdateReprMaterials(pxr::HdSceneDelegate* SceneDelegate,
pxr::HdRenderParam* RenderParam);
void UpdateReprMaterials(const pxr::HdRenderIndex& RenderIndex,
pxr::HdRenderParam* RenderParam);

private:
HnMesh(const pxr::TfToken& typeId,
Expand Down Expand Up @@ -237,7 +237,8 @@ class HnMesh final : public pxr::HdMesh
const pxr::TfToken& ReprToken,
HdMeshTopologyWrapper& MeshTopology);

void AddGeometrySubsetDrawItems(const pxr::HdMeshReprDesc& ReprDesc,
void AddGeometrySubsetDrawItems(const pxr::HdRenderIndex& RenderIndex,
const pxr::HdMeshReprDesc& ReprDesc,
pxr::HdRepr& Repr);
void UpdateDrawItemsForGeometrySubsets(pxr::HdSceneDelegate& SceneDelegate,
pxr::HdRenderParam* RenderParam);
Expand Down
32 changes: 11 additions & 21 deletions Hydrogent/src/HnMesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,9 @@ void HnMesh::ProcessDrawItems(HandleDrawItemFuncType&& HandleDrawItem,
}
}

void HnMesh::UpdateReprMaterials(pxr::HdSceneDelegate* SceneDelegate,
pxr::HdRenderParam* RenderParam)
void HnMesh::UpdateReprMaterials(const pxr::HdRenderIndex& RenderIndex,
pxr::HdRenderParam* RenderParam)
{
const pxr::HdRenderIndex& RenderIndex = SceneDelegate->GetRenderIndex();

ProcessDrawItems(
[&](HnDrawItem& DrawItem) {
SetDrawItemMaterial(RenderIndex, DrawItem, GetMaterialId());
Expand Down Expand Up @@ -212,23 +210,19 @@ void HnMesh::Sync(pxr::HdSceneDelegate* Delegate,
UpdateMaterials = true;
*DirtyBits &= ~pxr::HdChangeTracker::DirtyMaterialId;
}

if ((*DirtyBits & pxr::HdChangeTracker::DirtyDisplayStyle) != 0)
{
UpdateMaterials = true;
*DirtyBits &= ~pxr::HdChangeTracker::DirtyDisplayStyle;
}

const bool IsNewRepr = (*DirtyBits & pxr::HdChangeTracker::NewRepr) != 0;
// UpdateRepr() clears the NewRepr bit
const bool ReprUpdated = UpdateRepr(*Delegate, RenderParam, *DirtyBits, ReprToken);
if (IsNewRepr && ReprUpdated)
{
UpdateMaterials = true;
}

// Update materials after the repr is updated, so that the draw items are created
if (UpdateMaterials)
{
UpdateReprMaterials(Delegate, RenderParam);
UpdateReprMaterials(Delegate->GetRenderIndex(), RenderParam);
}

const bool DirtyDoubleSided = (*DirtyBits & pxr::HdChangeTracker::DirtyDoubleSided) != 0;
Expand Down Expand Up @@ -273,16 +267,16 @@ pxr::HdDirtyBits HnMesh::_PropagateDirtyBits(pxr::HdDirtyBits bits) const
return bits;
}

void HnMesh::AddGeometrySubsetDrawItems(const pxr::HdMeshReprDesc& ReprDesc, pxr::HdRepr& Repr)
void HnMesh::AddGeometrySubsetDrawItems(const pxr::HdRenderIndex& RenderIndex, const pxr::HdMeshReprDesc& ReprDesc, pxr::HdRepr& Repr)
{
if (ReprDesc.geomStyle == pxr::HdMeshGeomStyleInvalid ||
ReprDesc.geomStyle == pxr::HdMeshGeomStylePoints)
return;

const size_t NumGeomSubsets = m_Topology.Subsets.size();
for (size_t i = 0; i < NumGeomSubsets; ++i)
for (const Topology::Subset& Subset : m_Topology.Subsets)
{
pxr::HdRepr::DrawItemUniquePtr Item = std::make_unique<HnDrawItem>(_sharedData, *this);
std::unique_ptr<HnDrawItem> Item = std::make_unique<HnDrawItem>(_sharedData, *this);
SetDrawItemMaterial(RenderIndex, *Item, Subset.MaterialId);
Repr.AddGeomSubsetDrawItem(std::move(Item));
}
}
Expand All @@ -308,11 +302,7 @@ void HnMesh::_InitRepr(const pxr::TfToken& ReprToken, pxr::HdDirtyBits* DirtyBit
Repr.AddDrawItem(std::make_unique<HnDrawItem>(_sharedData, *this));
}

// Note that geometry susbset items may change later.
for (const pxr::HdMeshReprDesc& Desc : ReprDescs)
{
AddGeometrySubsetDrawItems(Desc, Repr);
}
// Geometry susbset items will be added after the topology is updated.
}

void HnMesh::Invalidate()
Expand Down Expand Up @@ -635,7 +625,7 @@ void HnMesh::UpdateDrawItemsForGeometrySubsets(pxr::HdSceneDelegate& SceneDelega
Repr->ClearGeomSubsetDrawItems();
for (const pxr::HdMeshReprDesc& Desc : Descs)
{
AddGeometrySubsetDrawItems(Desc, *Repr);
AddGeometrySubsetDrawItems(SceneDelegate.GetRenderIndex(), Desc, *Repr);
}
}
}
Expand Down

0 comments on commit 6d7d1be

Please sign in to comment.