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
1 change: 1 addition & 0 deletions lib/flowViewport/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(HEADERS
fvpUtils.h
global.h
tokens.h
fvpWireframeColorInterface.h
)

# -----------------------------------------------------------------------------
Expand Down
40 changes: 40 additions & 0 deletions lib/flowViewport/fvpWireframeColorInterface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef FLOW_VIEWPORT_WIREFRAME_COLOR_INTERFACE_H
#define FLOW_VIEWPORT_WIREFRAME_COLOR_INTERFACE_H

//Local headers
#include "flowViewport/api.h"

//Hydra headers
#include <pxr/usd/sdf/path.h>
#include <pxr/base/gf/vec4f.h>

namespace FVP_NS_DEF {


/// \class WireframeColorInterface
/// An interface to get the wireframe color from a prim
class WireframeColorInterface
{
public:
//Get the wireframe color of a primitive for selection highlighting
virtual PXR_NS::GfVec4f getWireframeColor(const PXR_NS::SdfPath& primPath) const = 0;
};

}//end of namespace FVP_NS_DEF

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

set(HEADERS
Expand All @@ -27,6 +28,7 @@ set(HEADERS
fvpDisplayStyleOverrideSceneIndex.h
fvpBBoxSceneIndex.h
fvpReprSelectorSceneIndex.h
fvpBlockPrimRemovalPropagationSceneIndex.h
)

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

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

//USD/Hydra headers
Expand Down Expand Up @@ -349,10 +348,10 @@ namespace
};
}

BboxSceneIndex::BboxSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const SelectionConstPtr& selection) :
BboxSceneIndex::BboxSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const WireframeColorInterface& wireframeColorInterface) :
ParentClass(inputSceneIndex),
InputSceneIndexUtils(inputSceneIndex),
_selection(selection)
_wireframeColorInterface(wireframeColorInterface)
{
}

Expand All @@ -361,7 +360,7 @@ HdSceneIndexPrim BboxSceneIndex::GetPrim(const SdfPath& primPath) const
HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(primPath);
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
const GfVec4f wireframeColor = _selection->GetWireframeColor(primPath);
const GfVec4f wireframeColor = _wireframeColorInterface.getWireframeColor(primPath);
prim.dataSource = _BoundsPrimDataSource::New(prim.dataSource, wireframeColor);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/flowViewport/sceneIndex/fvpBBoxSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//Local headers
#include "flowViewport/api.h"
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h"
#include "flowViewport/selection/fvpSelectionFwd.h"
#include "flowViewport/fvpWireframeColorInterface.h"

//Hydra headers
#include <pxr/base/tf/declarePtrs.h>
Expand All @@ -45,8 +45,8 @@ class BboxSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase
using PXR_NS::HdSingleInputFilteringSceneIndexBase::_GetInputSceneIndex;

FVP_API
static BboxSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const SelectionConstPtr& selection){
return PXR_NS::TfCreateRefPtr(new BboxSceneIndex(inputSceneIndex, selection));
static BboxSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const WireframeColorInterface& wireframeColorInterface){
return PXR_NS::TfCreateRefPtr(new BboxSceneIndex(inputSceneIndex, wireframeColorInterface));
}

// From HdSceneIndexBase
Expand All @@ -67,7 +67,7 @@ class BboxSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase
}

protected:
BboxSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const SelectionConstPtr& selection);
BboxSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const WireframeColorInterface& wireframeColorInterface);

//From HdSingleInputFilteringSceneIndexBase
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override;
Expand All @@ -90,7 +90,7 @@ class BboxSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase
}

std::set<PXR_NS::SdfPath> _excludedSceneRoots;
const SelectionConstPtr _selection;
const WireframeColorInterface& _wireframeColorInterface;
};

}//end of namespace FVP_NS_DEF
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

//Local headers
#include "fvpBlockPrimRemovalPropagationSceneIndex.h"


/// A filtering scene index that blocks prim removal propagation. Example usage is : we are re-creating
/// the filtering scene index chain hierarchy and don't want the prim removal to propagate to the linked
/// scene index.


namespace FVP_NS_DEF {

PXR_NAMESPACE_USING_DIRECTIVE

void BlockPrimRemovalPropagationSceneIndex::_PrimsRemoved(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries& entries)
{
if (!_IsObserved() || _blockPrimRemoval)return;
_SendPrimsRemoved(entries);
}

}//end of namespace FVP_NS_DEF
107 changes: 107 additions & 0 deletions lib/flowViewport/sceneIndex/fvpBlockPrimRemovalPropagationSceneIndex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//
// Copyright 2024 Autodesk
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef FLOW_VIEWPORT_SCENEINDEX_FVP_BLOCK_PRIM_REMOVAL_PROPAGATION_SCENE_INDEX_H
#define FLOW_VIEWPORT_SCENEINDEX_FVP_BLOCK_PRIM_REMOVAL_PROPAGATION_SCENE_INDEX_H

//Local headers
#include "flowViewport/api.h"
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h"
#include "flowViewport/selection/fvpSelectionFwd.h"
#include "flowViewport/sceneIndex/fvpPathInterface.h"

//Hydra headers
#include <pxr/base/tf/declarePtrs.h>
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
#include <pxr/imaging/hd/filteringSceneIndex.h>
#include <pxr/imaging/hd/retainedDataSource.h>
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved

namespace FVP_NS_DEF {

class BlockPrimRemovalPropagationSceneIndex;
typedef PXR_NS::TfRefPtr<BlockPrimRemovalPropagationSceneIndex> BlockPrimRemovalPropagationSceneIndexRefPtr;
typedef PXR_NS::TfRefPtr<const BlockPrimRemovalPropagationSceneIndex> BlockPrimRemovalPropagationSceneIndexConstRefPtr;

/// \class BlockPrimRemovalPropagationSceneIndex
///
/// A filtering scene index that blocks prim removal propagation. Example usage is : we are re-creating
/// the filtering scene index chain hierarchy and don't want the PrimRemoval to propagate to the linked
/// scene index.
class BlockPrimRemovalPropagationSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBase, public PathInterface //As a temp workaround we subclass PathInterface
, public Fvp::InputSceneIndexUtils<BlockPrimRemovalPropagationSceneIndex>
{
public:
using ParentClass = PXR_NS::HdSingleInputFilteringSceneIndexBase;
using PXR_NS::HdSingleInputFilteringSceneIndexBase::_GetInputSceneIndex;

FVP_API
static BlockPrimRemovalPropagationSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex){
return PXR_NS::TfCreateRefPtr(new BlockPrimRemovalPropagationSceneIndex(inputSceneIndex));
}

// From HdSceneIndexBase
FVP_API
PXR_NS::HdSceneIndexPrim GetPrim(const PXR_NS::SdfPath& primPath) const override{
return GetInputSceneIndex()->GetPrim(primPath);
}

FVP_API
PXR_NS::SdfPathVector GetChildPrimPaths(const PXR_NS::SdfPath& primPath) const override{
return GetInputSceneIndex()->GetChildPrimPaths(primPath);
}

FVP_API
~BlockPrimRemovalPropagationSceneIndex() override = default;

FVP_API
bool isPrimRemovalBlocked() const { return _blockPrimRemoval;}

FVP_API
void setPrimRemovalBlocked(bool blockPrimRemoval) { _blockPrimRemoval = blockPrimRemoval; }

//from PathInterface
FVP_API
PXR_NS::SdfPath SceneIndexPath(const Ufe::Path& appPath) const override{
auto pathInterface = dynamic_cast<const PathInterface*>(&*GetInputSceneIndex());
if (!pathInterface){
return {};
}
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved

return pathInterface->SceneIndexPath(appPath);
}

protected:

BlockPrimRemovalPropagationSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex)
: ParentClass(inputSceneIndex), InputSceneIndexUtils(inputSceneIndex){}

//From HdSingleInputFilteringSceneIndexBase
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{
if (!_IsObserved())return;
_SendPrimsAdded(entries);
}

void _PrimsDirtied(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries& entries)override{
if (!_IsObserved())return;
_SendPrimsDirtied(entries);
}

void _PrimsRemoved(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::RemovedPrimEntries& entries)override;

bool _blockPrimRemoval {false};
};

}//end of namespace FVP_NS_DEF

#endif //FLOW_VIEWPORT_SCENEINDEX_FVP_BLOCK_PRIM_REMOVAL_PROPAGATION_SCENE_INDEX_H
9 changes: 5 additions & 4 deletions lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

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

//USD/Hydra headers
Expand All @@ -42,6 +41,8 @@ TF_DEFINE_PRIVATE_TOKENS(
(overrideWireframeColor) // Works in HdStorm to override the wireframe color
);

//refined means that it supports a "refineLevel" attribute in the displayStyle to get a more refined drawing, valid range is from 0 to 8

//Wireframe on surface refined
const HdRetainedContainerDataSourceHandle sRefinedWireframeOnShadedDisplayStyleDataSource
= HdRetainedContainerDataSource::New(
Expand Down Expand Up @@ -72,10 +73,10 @@ const HdRetainedContainerDataSourceHandle sWireframeDisplayStyleDataSource

}//End of namespace

ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const SelectionConstPtr& selection)
ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const WireframeColorInterface& wireframeColorInterface)
: ParentClass(inputSceneIndex),
InputSceneIndexUtils(inputSceneIndex),
_selection(selection)
_wireframeColorInterface(wireframeColorInterface)
{
switch (type){
case RepSelectorType::WireframeRefined:
Expand Down Expand Up @@ -103,7 +104,7 @@ HdSceneIndexPrim ReprSelectorSceneIndex::GetPrim(const SdfPath& primPath) const
edited.Set(HdPrimvarsSchema::GetDefaultLocator().Append(_primVarsTokens->overrideWireframeColor),
Fvp::PrimvarDataSource::New(
HdRetainedTypedSampledDataSource<VtVec4fArray>::New(
VtVec4fArray{_selection->GetWireframeColor(primPath)}),
VtVec4fArray{_wireframeColorInterface.getWireframeColor(primPath)}),
HdPrimvarSchemaTokens->constant,
HdPrimvarSchemaTokens->color));
//Edit the cull style
Expand Down
12 changes: 6 additions & 6 deletions lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
//Local headers
#include "flowViewport/api.h"
#include "flowViewport/sceneIndex/fvpSceneIndexUtils.h"
#include "flowViewport/selection/fvpSelectionFwd.h"
#include "flowViewport/fvpWireframeColorInterface.h"

//Hydra headers
#include <pxr/base/tf/declarePtrs.h>
Expand All @@ -44,14 +44,14 @@ class ReprSelectorSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBa
using PXR_NS::HdSingleInputFilteringSceneIndexBase::_GetInputSceneIndex;

enum class RepSelectorType{
WireframeRefined, //Wireframe
WireframeRefined, //Refined wireframe (refined means that it supports a "refineLevel" attribute in the displayStyle to get a more refined drawing, valid range is from 0 to 8)
WireframeOnSurface, //Wireframe on surface not refined
WireframeOnSurfaceRefined,//Wireframe on surface refined
ppt-adsk marked this conversation as resolved.
Show resolved Hide resolved
};

FVP_API
static ReprSelectorSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const SelectionConstPtr& selection){
return PXR_NS::TfCreateRefPtr(new ReprSelectorSceneIndex(inputSceneIndex, type, selection));
static ReprSelectorSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const WireframeColorInterface& wireframeColorInterface){
return PXR_NS::TfCreateRefPtr(new ReprSelectorSceneIndex(inputSceneIndex, type, wireframeColorInterface));
}

// From HdSceneIndexBase
Expand All @@ -73,7 +73,7 @@ class ReprSelectorSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBa

protected:

ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const SelectionConstPtr& selection);
ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const WireframeColorInterface& wireframeColorInterface);

//From HdSingleInputFilteringSceneIndexBase
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{
Expand Down Expand Up @@ -101,7 +101,7 @@ ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, Re
std::set<PXR_NS::SdfPath> _excludedSceneRoots;

PXR_NS::HdRetainedContainerDataSourceHandle _wireframeTypeDataSource = nullptr;
const SelectionConstPtr _selection;
const WireframeColorInterface& _wireframeColorInterface;
};

}//end of namespace FVP_NS_DEF
Expand Down
Loading
Loading