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

HYDRA-310 : Support wireframe and wire on shaded and support selection highlight with the right colors #118

Merged
merged 12 commits into from
May 6, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ PXR_NAMESPACE_OPEN_SCOPE
(wireframeSelectionSecondary) \
(vertexSelection) \
(edgeSelection) \
(faceSelection)
(faceSelection) \
(polymeshDormant)
// clang-format on

TF_DECLARE_PUBLIC_TOKENS(FvpColorPreferencesTokens, FVP_API, FVP_COLOR_PREFERENCES_TOKENS);
Expand Down
54 changes: 54 additions & 0 deletions lib/flowViewport/fvpUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
#include <pxr/imaging/hd/sceneIndex.h>
#endif

#include <pxr/imaging/hd/tokens.h>
#include <pxr/imaging/hd/retainedDataSource.h>
#include <pxr/imaging/hd/primvarsSchema.h>

namespace FVP_NS_DEF {

// At time of writing, the last reference removal causing destruction of a
Expand All @@ -35,6 +39,56 @@ namespace FVP_NS_DEF {
void FVP_API leakSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& si);
#endif

/// A convenience data source implementing the primvar schema from
/// a triple of primvar value, interpolation and role. The latter two
/// are given as tokens. The value can be given either as data source
/// or as thunk returning a data source which is evaluated on each
/// Get.
class PrimvarDataSource final : public PXR_NS::HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(PrimvarDataSource);

PXR_NS::TfTokenVector GetNames() override {
return {PXR_NS::HdPrimvarSchemaTokens->primvarValue,
PXR_NS::HdPrimvarSchemaTokens->interpolation,
PXR_NS::HdPrimvarSchemaTokens->role};
}

PXR_NS::HdDataSourceBaseHandle Get(const PXR_NS::TfToken &name) override {
if (name == PXR_NS::HdPrimvarSchemaTokens->primvarValue) {
return _primvarValueSrc;
}
if (name == PXR_NS::HdPrimvarSchemaTokens->interpolation) {
return
PXR_NS::HdPrimvarSchema::BuildInterpolationDataSource(
_interpolation);
}
if (name == PXR_NS::HdPrimvarSchemaTokens->role) {
return
PXR_NS::HdPrimvarSchema::BuildRoleDataSource(
_role);
}

return nullptr;
}

private:
PrimvarDataSource(
const PXR_NS::HdDataSourceBaseHandle &primvarValueSrc,
const PXR_NS::TfToken &interpolation,
const PXR_NS::TfToken &role)
: _primvarValueSrc(primvarValueSrc)
, _interpolation(interpolation)
, _role(role)
{
}

PXR_NS::HdDataSourceBaseHandle _primvarValueSrc;
PXR_NS::TfToken _interpolation;
PXR_NS::TfToken _role;
};

} // namespace FVP_NS_DEF

#endif // FVP_UTILS_H
2 changes: 2 additions & 0 deletions lib/flowViewport/sceneIndex/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ target_sources(${TARGET_NAME}
fvpWireframeSelectionHighlightSceneIndex.cpp
fvpDisplayStyleOverrideSceneIndex.cpp
fvpBBoxSceneIndex.cpp
fvpReprSelectorSceneIndex.cpp
)

set(HEADERS
Expand All @@ -25,6 +26,7 @@ set(HEADERS
fvpWireframeSelectionHighlightSceneIndex.h
fvpDisplayStyleOverrideSceneIndex.h
fvpBBoxSceneIndex.h
fvpReprSelectorSceneIndex.h
)

# -----------------------------------------------------------------------------
Expand Down
131 changes: 43 additions & 88 deletions lib/flowViewport/sceneIndex/fvpBBoxSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

//Local headers
#include "fvpBBoxSceneIndex.h"
#include "flowViewport/selection/fvpSelection.h"
#include "flowViewport/fvpUtils.h"

//USD/Hydra headers
#include <pxr/base/gf/bbox3d.h>
Expand All @@ -34,6 +36,7 @@
#include <pxr/imaging/hd/legacyDisplayStyleSchema.h>
#include <pxr/imaging/hd/basisCurvesTopologySchema.h>
#include <pxr/imaging/hd/basisCurvesSchema.h>
#include <pxr/imaging/hd/primOriginSchema.h>


// This class is a filtering scene index that converts the geometries into a bounding box using the extent attribute.
Expand All @@ -55,56 +58,6 @@ namespace
return result;
}

/// A convenience data source implementing the primvar schema from
/// a triple of primvar value, interpolation and role. The latter two
/// are given as tokens. The value can be given either as data source
/// or as thunk returning a data source which is evaluated on each
/// Get.
class _PrimvarDataSource final : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(_PrimvarDataSource);

TfTokenVector GetNames() override {
return {HdPrimvarSchemaTokens->primvarValue,
HdPrimvarSchemaTokens->interpolation,
HdPrimvarSchemaTokens->role};
}

HdDataSourceBaseHandle Get(const TfToken &name) override {
if (name == HdPrimvarSchemaTokens->primvarValue) {
return _primvarValueSrc;
}
if (name == HdPrimvarSchemaTokens->interpolation) {
return
HdPrimvarSchema::BuildInterpolationDataSource(
_interpolation);
}
if (name == HdPrimvarSchemaTokens->role) {
return
HdPrimvarSchema::BuildRoleDataSource(
_role);
}

return nullptr;
}

private:
_PrimvarDataSource(
const HdDataSourceBaseHandle &primvarValueSrc,
const TfToken &interpolation,
const TfToken &role)
: _primvarValueSrc(primvarValueSrc)
, _interpolation(interpolation)
, _role(role)
{
}

HdDataSourceBaseHandle _primvarValueSrc;
TfToken _interpolation;
TfToken _role;
};

/// Base class for container data sources providing primvars.
///
/// Provides primvars common to bounding boxes display:
Expand All @@ -120,40 +73,27 @@ namespace

HdDataSourceBaseHandle Get(const TfToken &name) override {
if (name == HdTokens->displayColor) {
//Get the color from the displayColor attribute of the prim
//Works only for maya native data at this time...
GfVec4f color(0,1,0,1);
HdSampledDataSourceHandle valueDs = HdSampledDataSource::Cast(_primSource->Get(name));
if (valueDs) {
const VtValue value = valueDs->GetValue(0);
if (value.IsHolding<GfVec4f>()){
color = value.UncheckedGet<GfVec4f>();
}else
if (value.IsHolding<GfVec3f>()){
auto color3 = value.UncheckedGet<GfVec3f>();
color = GfVec4f(color3[0], color3[1], color3[2], 1.0f);
}

HdDataSourceBaseHandle const src =
_PrimvarDataSource::New(
HdRetainedTypedSampledDataSource<VtVec3fArray>::New(
VtVec3fArray{{color[0], color[1], color[2]}}),
HdPrimvarSchemaTokens->constant,
HdPrimvarSchemaTokens->color);
return src;
}
HdDataSourceBaseHandle const src =
Fvp::PrimvarDataSource::New(
HdRetainedTypedSampledDataSource<VtVec3fArray>::New(
VtVec3fArray{{_wireframeColor[0], _wireframeColor[1], _wireframeColor[2]}}),
HdPrimvarSchemaTokens->constant,
HdPrimvarSchemaTokens->color);
return src;
}
return nullptr;
}

protected:
_PrimvarsDataSource(
const HdContainerDataSourceHandle &primSource)
: _primSource(primSource)
const HdContainerDataSourceHandle &primSource, const GfVec4f& wireframeColor)
: _primSource(primSource),
_wireframeColor(wireframeColor)
{
}

HdContainerDataSourceHandle _primSource;
GfVec4f _wireframeColor;
};

/// Base class for prim data sources.
Expand All @@ -164,6 +104,7 @@ namespace
/// - visibility (from the given prim data source)
/// - displayStyle (constant)
/// - instancedBy
/// - primOrigin (for selection picking to work on usd prims in bounding box display mode)
///
class _PrimDataSource : public HdContainerDataSource
{
Expand All @@ -175,14 +116,16 @@ namespace
HdPurposeSchemaTokens->purpose,
HdVisibilitySchemaTokens->visibility,
HdInstancedBySchemaTokens->instancedBy,
HdLegacyDisplayStyleSchemaTokens->displayStyle };
HdLegacyDisplayStyleSchemaTokens->displayStyle,
HdPrimOriginSchemaTokens->primOrigin};
}

HdDataSourceBaseHandle Get(const TfToken &name) override {
if (name == HdXformSchemaTokens->xform ||
name == HdPurposeSchemaTokens->purpose ||
name == HdVisibilitySchemaTokens->visibility ||
name == HdInstancedBySchemaTokens->instancedBy) {
name == HdInstancedBySchemaTokens->instancedBy ||
name == HdPrimOriginSchemaTokens->primOrigin) {
if (_primSource) {
return _primSource->Get(name);
}
Expand All @@ -193,7 +136,7 @@ namespace
HdLegacyDisplayStyleSchema::Builder()
.SetCullStyle(
HdRetainedTypedSampledDataSource<TfToken>::New(
HdCullStyleTokens->back))
HdCullStyleTokens->nothing))//No culling
.Build();
return src;
}
Expand Down Expand Up @@ -294,7 +237,7 @@ namespace
class _BoundsPrimvarsDataSource final : public _PrimvarsDataSource
{
public:
HD_DECLARE_DATASOURCE(_BoundsPrimvarsDataSource);
HD_DECLARE_DATASOURCE(_BoundsPrimvarsDataSource)

TfTokenVector GetNames() override {
static const TfTokenVector result = _Concat(
Expand All @@ -305,7 +248,7 @@ namespace

HdDataSourceBaseHandle Get(const TfToken &name) override {
if (name == HdPrimvarsSchemaTokens->points) {
return _PrimvarDataSource::New(
return Fvp::PrimvarDataSource::New(
_BoundsPointsPrimvarValueDataSource::New(_primSource),
HdPrimvarSchemaTokens->vertex,
HdPrimvarSchemaTokens->point);
Expand All @@ -314,9 +257,8 @@ namespace
}

private:
_BoundsPrimvarsDataSource(
const HdContainerDataSourceHandle &primSource)
: _PrimvarsDataSource(primSource)
_BoundsPrimvarsDataSource(const HdContainerDataSourceHandle &primSource, const GfVec4f& wireframeColor)
: _PrimvarsDataSource(primSource, wireframeColor)
{
}
};
Expand Down Expand Up @@ -364,7 +306,7 @@ namespace
class _BoundsPrimDataSource : public _PrimDataSource
{
public:
HD_DECLARE_DATASOURCE(_BoundsPrimDataSource);
HD_DECLARE_DATASOURCE(_BoundsPrimDataSource)

TfTokenVector GetNames() override {
static const TfTokenVector result = _Concat(
Expand All @@ -384,7 +326,7 @@ namespace
return basisCurvesSrc;
}
if (name == HdPrimvarsSchemaTokens->primvars) {
return _BoundsPrimvarsDataSource::New(_primSource);
return _BoundsPrimvarsDataSource::New(_primSource, _wireframeColor);
}
if (name == HdExtentSchemaTokens->extent) {
if (_primSource) {
Expand All @@ -397,26 +339,39 @@ namespace

private:
_BoundsPrimDataSource(
const HdContainerDataSourceHandle &primSource)
: _PrimDataSource(primSource)
const HdContainerDataSourceHandle &primSource, const GfVec4f& wireframeColor)
: _PrimDataSource(primSource),
_wireframeColor(wireframeColor)
{
}

GfVec4f _wireframeColor;
};
}

BboxSceneIndex::BboxSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr<const Selection>& selection) :
ParentClass(inputSceneIndex),
InputSceneIndexUtils(inputSceneIndex),
_selection(selection)
{
}

HdSceneIndexPrim BboxSceneIndex::GetPrim(const SdfPath& primPath) const
{
HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(primPath);
if (prim.dataSource && ((prim.primType == HdPrimTypeTokens->mesh) || (prim.primType == HdPrimTypeTokens->basisCurves)) ){
if (prim.dataSource && ! _isExcluded(primPath) && ((prim.primType == HdPrimTypeTokens->mesh) || (prim.primType == HdPrimTypeTokens->basisCurves)) ){
prim.primType = HdPrimTypeTokens->basisCurves;//Convert to basisCurve for displaying a bounding box
prim.dataSource = _BoundsPrimDataSource::New(prim.dataSource);
const GfVec4f wireframeColor = _selection->GetWireframeColor(primPath);
prim.dataSource = _BoundsPrimDataSource::New(prim.dataSource, wireframeColor);
}

return prim;
}

void BboxSceneIndex::_PrimsAdded(const HdSceneIndexBase& sender, const HdSceneIndexObserver::AddedPrimEntries& entries)
{
if (!_IsObserved())return;

HdSceneIndexObserver::AddedPrimEntries newEntries;
for (const HdSceneIndexObserver::AddedPrimEntry &entry : entries) {
const SdfPath &path = entry.primPath;
Expand Down
Loading
Loading