Skip to content

Commit

Permalink
First commit to introduce changes to allow Hydra prim dirtying instea…
Browse files Browse the repository at this point in the history
…d of repeated Add/Removal of prims
  • Loading branch information
roopavr-adsk committed Jul 23, 2024
1 parent 827a42e commit 45bb9f3
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 43 deletions.
34 changes: 28 additions & 6 deletions lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
#include <pxr/imaging/hd/containerDataSourceEditor.h>
#include <pxr/imaging/hd/legacyDisplayStyleSchema.h>
#include <pxr/imaging/hd/primvarsSchema.h>
#include <pxr/imaging/hd/sceneIndexPrimView.h>

#include <iostream>

// This class is a filtering scene index that that applies a different RepSelector on geometries (such as wireframe or wireframe on shaded)
// and also applies an overrideWireframecolor for HdStorm
Expand Down Expand Up @@ -73,13 +75,17 @@ const HdRetainedContainerDataSourceHandle sWireframeDisplayStyleDataSource

}//End of namespace

ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const std::shared_ptr<WireframeColorInterface>& wireframeColorInterface)
ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr<WireframeColorInterface>& wireframeColorInterface)
: ParentClass(inputSceneIndex),
InputSceneIndexUtils(inputSceneIndex),
_wireframeColorInterface(wireframeColorInterface)
{
TF_AXIOM(_wireframeColorInterface);
switch (type){
}

void ReprSelectorSceneIndex::SetReprType(RepSelectorType reprType, bool needsReprChanged)
{
switch (reprType){
case RepSelectorType::WireframeRefined:
_wireframeTypeDataSource = sWireframeDisplayStyleDataSource;
break;
Expand All @@ -90,13 +96,31 @@ ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inp
_wireframeTypeDataSource = sRefinedWireframeOnShadedDisplayStyleDataSource;
break;
}

const HdDataSourceLocatorSet locators{
HdLegacyDisplayStyleSchema::GetDefaultLocator()
};
_needsReprChanged = needsReprChanged;
_DirtyAllPrims(locators);
}

void
ReprSelectorSceneIndex::_DirtyAllPrims(
const HdDataSourceLocatorSet locators)
{
HdSceneIndexObserver::DirtiedPrimEntries entries;
for (const SdfPath &path : HdSceneIndexPrimView(GetInputSceneIndex())) {
entries.push_back({path, locators});
}
_SendPrimsDirtied(entries);
}

HdSceneIndexPrim ReprSelectorSceneIndex::GetPrim(const SdfPath& primPath) const
{
HdSceneIndexPrim prim = GetInputSceneIndex()->GetPrim(primPath);
if (prim.dataSource && !_isExcluded(primPath) && (prim.primType == HdPrimTypeTokens->mesh) ){

if (prim.dataSource && !_isExcluded(primPath) &&
(prim.primType == HdPrimTypeTokens->mesh) && _needsReprChanged){

//Edit the dataSource as an overlay will not replace any existing attribute value.
// So we need to edit the _primVarsTokens->overrideWireframeColor attribute as they may already exist in the prim
auto edited = HdContainerDataSourceEditor(prim.dataSource);
Expand All @@ -111,10 +135,8 @@ HdSceneIndexPrim ReprSelectorSceneIndex::GetPrim(const SdfPath& primPath) const
//Edit the cull style
edited.Set(HdLegacyDisplayStyleSchema::GetCullStyleLocator(),
HdRetainedTypedSampledDataSource<TfToken>::New(HdCullStyleTokens->nothing));//No culling

prim.dataSource = HdOverlayContainerDataSource::New({ edited.Finish(), _wireframeTypeDataSource});
}

return prim;
}

Expand Down
13 changes: 10 additions & 3 deletions lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,12 @@ class ReprSelectorSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBa
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
None,
};

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

// From HdSceneIndexBase
Expand All @@ -70,10 +71,13 @@ class ReprSelectorSceneIndex : public PXR_NS::HdSingleInputFilteringSceneIndexBa
void addExcludedSceneRoot(const PXR_NS::SdfPath& sceneRoot) {
_excludedSceneRoots.emplace(sceneRoot);
}

FVP_API
void SetReprType(RepSelectorType, bool);

protected:

ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const std::shared_ptr<WireframeColorInterface>& wireframeColorInterface);
ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr<WireframeColorInterface>& wireframeColorInterface);

//From HdSingleInputFilteringSceneIndexBase
void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{
Expand All @@ -99,6 +103,9 @@ ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, Re
}

std::set<PXR_NS::SdfPath> _excludedSceneRoots;

void _DirtyAllPrims(const PXR_NS::HdDataSourceLocatorSet locators);
bool _needsReprChanged {false};

PXR_NS::HdRetainedContainerDataSourceHandle _wireframeTypeDataSource = nullptr;
std::shared_ptr<WireframeColorInterface> _wireframeColorInterface;
Expand Down
64 changes: 30 additions & 34 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,6 +738,27 @@ MStatus MtohRenderOverride::Render(
_defaultMaterialSceneIndex->Enable(currentUseDefaultMaterial);
_useDefaultMaterial = currentUseDefaultMaterial;
}

const MFrameContext::WireOnShadedMode wireOnShadedMode = MFrameContext::wireOnShadedMode();//Get the user preference
if ( _reprSelectorSceneIndex && (currentDisplayStyle !=_oldDisplayStyle)){
if( (currentDisplayStyle & MHWRender::MFrameContext::kWireFrame) &&
((currentDisplayStyle & MHWRender::MFrameContext::kGouraudShaded) ||
(currentDisplayStyle & MHWRender::MFrameContext::kTextured)) ) {
// Wireframe on top of shaded
// Reduced quality
if (MFrameContext::WireOnShadedMode::kWireFrameOnShadedReduced == wireOnShadedMode ){
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeOnSurface, true);
} else {//Full quality
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeOnSurfaceRefined, true);
}
}
else if( (currentDisplayStyle & MHWRender::MFrameContext::kWireFrame) ){
//wireframe only, not on top of shaded
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeRefined, true);
}
else // Shaded mode
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::Default, false);
}

HdxRenderTaskParams params;
params.enableLighting = true;
Expand Down Expand Up @@ -1107,16 +1128,11 @@ void MtohRenderOverride::_CreateSceneIndicesChainAfterMergingSceneIndex(const MH
_mayaHydraSceneIndex ? _mayaHydraSceneIndex->GetDefaultMaterialExclusionPaths(): SdfPathVector());

const unsigned int currentDisplayStyle = drawContext.getDisplayStyle();
const MFrameContext::WireOnShadedMode wireOnShadedMode = MFrameContext::wireOnShadedMode();//Get the user preference

auto mergingSceneIndex = _renderIndexProxy->GetMergingSceneIndex();
if(! _leadObjectPathTracker){
_leadObjectPathTracker = std::make_shared<MAYAHYDRA_NS_DEF::MhLeadObjectPathTracker>(mergingSceneIndex, _dirtyLeadObjectSceneIndex);
}

if (! _wireframeColorInterfaceImp){
_wireframeColorInterfaceImp = std::make_shared<MAYAHYDRA_NS_DEF::MhWireframeColorInterfaceImp>(_selection, _leadObjectPathTracker);
}

//Are we using Bounding Box display style ?
if (currentDisplayStyle & MHWRender::MFrameContext::kBoundingBox){
Expand All @@ -1125,37 +1141,17 @@ void MtohRenderOverride::_CreateSceneIndicesChainAfterMergingSceneIndex(const MH
bboxSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT); // Maya native prims are already converted by OGS
_lastFilteringSceneIndexBeforeCustomFiltering = bboxSceneIndex;
}
else if (currentDisplayStyle & MHWRender::MFrameContext::kWireFrame){//Are we using wireframe somehow ?

if( (currentDisplayStyle & MHWRender::MFrameContext::kGouraudShaded) || (currentDisplayStyle & MHWRender::MFrameContext::kTextured)){
// Wireframe on top of shaded
//Reduced quality
if (MFrameContext::WireOnShadedMode::kWireFrameOnShadedReduced == wireOnShadedMode ){
//Insert the reprselector filtering scene index which updates the repr selector on geometries
auto reprSelectorSceneIndex = Fvp::ReprSelectorSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering,
Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeOnSurface, _wireframeColorInterfaceImp);
reprSelectorSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT); // Maya native prims are already converted by OGS
_lastFilteringSceneIndexBeforeCustomFiltering = reprSelectorSceneIndex;
} else {//Full quality
//Should we support kWireFrameOnShadedNone and do not display any wireframe ?
//Insert the reprselector filtering scene index which updates the repr selector on geometries
auto reprSelectorSceneIndex = Fvp::ReprSelectorSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering,
Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeOnSurfaceRefined, _wireframeColorInterfaceImp);
reprSelectorSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT); // Maya native prims are already converted by OGS
_lastFilteringSceneIndexBeforeCustomFiltering = reprSelectorSceneIndex;
}
}
else{
//wireframe only, not on top of shaded

//Insert the reprselector filtering scene index which updates the repr selector on geometries
auto reprSelectorSceneIndex = Fvp::ReprSelectorSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering,
Fvp::ReprSelectorSceneIndex::RepSelectorType::WireframeRefined, _wireframeColorInterfaceImp);
reprSelectorSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT); // Maya native prims are already converted by OGS
_lastFilteringSceneIndexBeforeCustomFiltering = reprSelectorSceneIndex;
}

if (! _wireframeColorInterfaceImp){
_wireframeColorInterfaceImp = std::make_shared<MAYAHYDRA_NS_DEF::MhWireframeColorInterfaceImp>(_selection, _leadObjectPathTracker);
}

// Repr selector Scene Index
_lastFilteringSceneIndexBeforeCustomFiltering = _reprSelectorSceneIndex =
Fvp::ReprSelectorSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering,
_wireframeColorInterfaceImp);
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::None,false);

auto wfSi = TfDynamic_cast<Fvp::WireframeSelectionHighlightSceneIndexRefPtr>(Fvp::WireframeSelectionHighlightSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering, _selection, _wireframeColorInterfaceImp));
wfSi->SetDisplayName("Flow Viewport Wireframe Selection Highlight Scene Index");

Expand Down
2 changes: 2 additions & 0 deletions lib/mayaHydra/mayaPlugin/renderOverride.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
#include <flowViewport/sceneIndex/fvpDisplayStyleOverrideSceneIndex.h>
#include <flowViewport/sceneIndex/fvpPruneTexturesSceneIndex.h>
#include <flowViewport/sceneIndex/fvpDefaultMaterialSceneIndex.h>
#include <flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h>
#include <flowViewport/sceneIndex/fvpBlockPrimRemovalPropagationSceneIndex.h>

#include <pxr/base/tf/singleton.h>
Expand Down Expand Up @@ -259,6 +260,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride,
HdSceneIndexBaseRefPtr _inputSceneIndexOfFilteringSceneIndicesChain {nullptr};
Fvp::DisplayStyleOverrideSceneIndexRefPtr _displayStyleSceneIndex;
Fvp::PruneTexturesSceneIndexRefPtr _pruneTexturesSceneIndex;
Fvp::ReprSelectorSceneIndexRefPtr _reprSelectorSceneIndex;
Fvp::DefaultMaterialSceneIndexRefPtr _defaultMaterialSceneIndex;
HdRenderIndex* _renderIndex = nullptr;
Fvp::SelectionTrackerSharedPtr _fvpSelectionTracker;
Expand Down

0 comments on commit 45bb9f3

Please sign in to comment.