Skip to content

Commit 8b7497b

Browse files
authored
HYDRA-1286 : Support displacement on GeomSubset wireframe highlights (#242)
1 parent 00624d5 commit 8b7497b

File tree

13 files changed

+423
-186
lines changed

13 files changed

+423
-186
lines changed

lib/flowViewport/fvpUtils.cpp

+52
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616
#include "fvpUtils.h"
1717

1818
#include <pxr/imaging/hd/instanceIndicesSchema.h>
19+
#include <pxr/imaging/hd/materialBindingsSchema.h>
1920
#include <pxr/imaging/hd/selectionSchema.h>
2021

22+
PXR_NAMESPACE_USING_DIRECTIVE
23+
2124
namespace FVP_NS_DEF {
2225

2326
#ifdef CODE_COVERAGE_WORKAROUND
@@ -56,4 +59,53 @@ PXR_NS::HdDataSourceBaseHandle createSelectionDataSource(const Fvp::PrimSelectio
5659
return PXR_NS::HdDataSourceBase::Cast(selectionBuilder.Build());
5760
}
5861

62+
Fvp::PrimSelection ConvertHydraToFvpSelection(const SdfPath& primPath, const HdSelectionSchema& selectionSchema) {
63+
Fvp::PrimSelection primSelection;
64+
primSelection.primPath = primPath;
65+
66+
auto nestedInstanceIndicesSchema =
67+
#if HD_API_VERSION < 66
68+
const_cast<HdSelectionSchema&>(selectionSchema).GetNestedInstanceIndices();
69+
#else
70+
selectionSchema.GetNestedInstanceIndices();
71+
#endif
72+
for (size_t iNestedInstanceIndices = 0; iNestedInstanceIndices < nestedInstanceIndicesSchema.GetNumElements(); iNestedInstanceIndices++) {
73+
HdInstanceIndicesSchema instanceIndicesSchema = nestedInstanceIndicesSchema.GetElement(iNestedInstanceIndices);
74+
auto instanceIndices = instanceIndicesSchema.GetInstanceIndices()->GetTypedValue(0);
75+
primSelection.nestedInstanceIndices.push_back(
76+
{
77+
instanceIndicesSchema.GetInstancer()->GetTypedValue(0),
78+
instanceIndicesSchema.GetPrototypeIndex()->GetTypedValue(0),
79+
std::vector<int>(instanceIndices.begin(), instanceIndices.end())
80+
}
81+
);
82+
}
83+
84+
return primSelection;
85+
}
86+
87+
SdfPath GetMaterialPath(const PXR_NS::HdContainerDataSourceHandle& primDataSource)
88+
{
89+
if (!primDataSource) {
90+
return {};
91+
}
92+
93+
HdMaterialBindingsSchema materialBindingsSchema = HdMaterialBindingsSchema::GetFromParent(primDataSource);
94+
if (!materialBindingsSchema.IsDefined()) {
95+
return {};
96+
}
97+
98+
HdMaterialBindingSchema materialBindingSchema = materialBindingsSchema.GetMaterialBinding();
99+
if (!materialBindingSchema) {
100+
return {};
101+
}
102+
103+
HdPathDataSourceHandle bindingPathDataSource = materialBindingSchema.GetPath();
104+
if (!bindingPathDataSource) {
105+
return {};
106+
}
107+
108+
return bindingPathDataSource->GetTypedValue(0);
109+
}
110+
59111
} // namespace FVP_NS_DEF

lib/flowViewport/fvpUtils.h

+7
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
#include <pxr/imaging/hd/tokens.h>
2626
#include <pxr/imaging/hd/retainedDataSource.h>
27+
#include <pxr/imaging/hd/selectionSchema.h>
2728
#include <pxr/imaging/hd/primvarsSchema.h>
2829

2930
namespace FVP_NS_DEF {
@@ -125,6 +126,12 @@ auto FindSelfOrFirstChild(const PXR_NS::SdfPath& path, const std::map<PXR_NS::Sd
125126
return pathMap.cend();
126127
}
127128

129+
// Return a Fvp::PrimSelection equivalent to the given Hydra selection
130+
Fvp::PrimSelection ConvertHydraToFvpSelection(const PXR_NS::SdfPath& primPath, const PXR_NS::HdSelectionSchema& selectionSchema);
131+
132+
// Get the path to the prim's bound material.
133+
PXR_NS::SdfPath GetMaterialPath(const PXR_NS::HdContainerDataSourceHandle& primDataSource);
134+
128135
} // namespace FVP_NS_DEF
129136

130137
#endif // FVP_UTILS_H

0 commit comments

Comments
 (0)