From 45bb9f37a600ea914d7133239adf5cc391dd64b9 Mon Sep 17 00:00:00 2001 From: Rakesh Roopavataram Date: Tue, 23 Jul 2024 16:49:17 -0400 Subject: [PATCH] First commit to introduce changes to allow Hydra prim dirtying instead of repeated Add/Removal of prims --- .../sceneIndex/fvpReprSelectorSceneIndex.cpp | 34 ++++++++-- .../sceneIndex/fvpReprSelectorSceneIndex.h | 13 +++- lib/mayaHydra/mayaPlugin/renderOverride.cpp | 64 +++++++++---------- lib/mayaHydra/mayaPlugin/renderOverride.h | 2 + 4 files changed, 70 insertions(+), 43 deletions(-) diff --git a/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp b/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp index b4081fe418..b2a69cb720 100644 --- a/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp +++ b/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.cpp @@ -24,7 +24,9 @@ #include #include #include +#include +#include // 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 @@ -73,13 +75,17 @@ const HdRetainedContainerDataSourceHandle sWireframeDisplayStyleDataSource }//End of namespace -ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, RepSelectorType type, const std::shared_ptr& wireframeColorInterface) +ReprSelectorSceneIndex::ReprSelectorSceneIndex(const HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr& 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; @@ -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); @@ -111,10 +135,8 @@ HdSceneIndexPrim ReprSelectorSceneIndex::GetPrim(const SdfPath& primPath) const //Edit the cull style edited.Set(HdLegacyDisplayStyleSchema::GetCullStyleLocator(), HdRetainedTypedSampledDataSource::New(HdCullStyleTokens->nothing));//No culling - prim.dataSource = HdOverlayContainerDataSource::New({ edited.Finish(), _wireframeTypeDataSource}); } - return prim; } diff --git a/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h b/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h index 632ae2cb1e..4d05f7804b 100644 --- a/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h +++ b/lib/flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h @@ -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){ - return PXR_NS::TfCreateRefPtr(new ReprSelectorSceneIndex(inputSceneIndex, type, wireframeColorInterface)); + static ReprSelectorSceneIndexRefPtr New(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr& wireframeColorInterface){ + return PXR_NS::TfCreateRefPtr(new ReprSelectorSceneIndex(inputSceneIndex, wireframeColorInterface)); } // From HdSceneIndexBase @@ -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); +ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, const std::shared_ptr& wireframeColorInterface); //From HdSingleInputFilteringSceneIndexBase void _PrimsAdded(const PXR_NS::HdSceneIndexBase& sender, const PXR_NS::HdSceneIndexObserver::AddedPrimEntries& entries) override{ @@ -99,6 +103,9 @@ ReprSelectorSceneIndex(const PXR_NS::HdSceneIndexBaseRefPtr& inputSceneIndex, Re } std::set _excludedSceneRoots; + + void _DirtyAllPrims(const PXR_NS::HdDataSourceLocatorSet locators); + bool _needsReprChanged {false}; PXR_NS::HdRetainedContainerDataSourceHandle _wireframeTypeDataSource = nullptr; std::shared_ptr _wireframeColorInterface; diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.cpp b/lib/mayaHydra/mayaPlugin/renderOverride.cpp index f614ce72e7..dfdae7a2c2 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.cpp +++ b/lib/mayaHydra/mayaPlugin/renderOverride.cpp @@ -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; @@ -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(mergingSceneIndex, _dirtyLeadObjectSceneIndex); } - - if (! _wireframeColorInterfaceImp){ - _wireframeColorInterfaceImp = std::make_shared(_selection, _leadObjectPathTracker); - } //Are we using Bounding Box display style ? if (currentDisplayStyle & MHWRender::MFrameContext::kBoundingBox){ @@ -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(_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::WireframeSelectionHighlightSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering, _selection, _wireframeColorInterfaceImp)); wfSi->SetDisplayName("Flow Viewport Wireframe Selection Highlight Scene Index"); diff --git a/lib/mayaHydra/mayaPlugin/renderOverride.h b/lib/mayaHydra/mayaPlugin/renderOverride.h index fc45e924ab..180f2fd627 100644 --- a/lib/mayaHydra/mayaPlugin/renderOverride.h +++ b/lib/mayaHydra/mayaPlugin/renderOverride.h @@ -49,6 +49,7 @@ #include #include #include +#include #include #include @@ -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;