Skip to content

Commit

Permalink
Merge branch 'dev' into roopavr/HYDRA-1036/refactorReprSceneIndexForD…
Browse files Browse the repository at this point in the history
…irtyingNotification
  • Loading branch information
roopavr-adsk authored Jul 30, 2024
2 parents 437340f + a08e890 commit 75363a1
Show file tree
Hide file tree
Showing 34 changed files with 1,017 additions and 340 deletions.
1 change: 0 additions & 1 deletion cmake/modules/FindUSD.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ find_package_handle_standard_args(USD
REQUIRED_VARS
PXR_USD_LOCATION
USD_INCLUDE_DIR
USD_LIBRARY_DIR
USD_GENSCHEMA
USD_CONFIG_FILE
USD_VERSION
Expand Down
644 changes: 432 additions & 212 deletions lib/flowViewport/sceneIndex/fvpWireframeSelectionHighlightSceneIndex.cpp

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include "flowViewport/fvpWireframeColorInterface.h"

#include <pxr/imaging/hd/filteringSceneIndex.h>
#include <pxr/imaging/hd/instancerTopologySchema.h>
#include <pxr/imaging/hd/retainedDataSource.h>
#include <pxr/imaging/hd/selectionsSchema.h>

#include <functional>
#include <set>
Expand All @@ -37,6 +39,13 @@ class WireframeSelectionHighlightSceneIndex;
typedef PXR_NS::TfRefPtr<WireframeSelectionHighlightSceneIndex> WireframeSelectionHighlightSceneIndexRefPtr;
typedef PXR_NS::TfRefPtr<const WireframeSelectionHighlightSceneIndex> WireframeSelectionHighlightSceneIndexConstRefPtr;

enum SelectionHighlightsCollectionDirection {
None = 0,
Prototypes = 1 << 0,
InstancedBy = 1 << 1,
Bidirectional = Prototypes | InstancedBy
};

/// \class WireframeSelectionHighlightSceneIndex
///
/// Uses Hydra HdRepr to add wireframe representation to selected objects
Expand Down Expand Up @@ -81,6 +90,10 @@ class WireframeSelectionHighlightSceneIndex
FVP_API
PXR_NS::SdfPath GetSelectionHighlightPath(const PXR_NS::SdfPath& path) const;

// Returns the paths to all selection highlight mirrors
FVP_API
PXR_NS::SdfPathVector GetSelectionHighlightMirrorPaths() const;

protected:

FVP_API
Expand Down Expand Up @@ -109,6 +122,9 @@ class WireframeSelectionHighlightSceneIndex

bool _IsExcluded(const PXR_NS::SdfPath& sceneRoot) const;

PXR_NS::VtBoolArray _GetSelectionHighlightMask(const PXR_NS::HdInstancerTopologySchema& originalInstancerTopology, const PXR_NS::HdSelectionsSchema& selections) const;
PXR_NS::HdContainerDataSourceHandle _GetSelectionHighlightInstancerDataSource(const PXR_NS::HdContainerDataSourceHandle& originalDataSource) const;

void _DirtySelectionHighlightRecursive(
const PXR_NS::SdfPath& primPath,
PXR_NS::HdSceneIndexObserver::DirtiedPrimEntries* highlightEntries
Expand All @@ -120,48 +136,61 @@ class WireframeSelectionHighlightSceneIndex
const PXR_NS::HdContainerDataSourceHandle& highlightDataSource
) const;

#if PXR_VERSION >= 2403
PXR_NS::HdContainerDataSourceHandle _TrimMeshForSelectedGeomSubsets(const PXR_NS::HdContainerDataSourceHandle& originalDataSource, const PXR_NS::SdfPath& originalPrimPath) const;
#endif

void _ForEachPrimInHierarchy(const PXR_NS::SdfPath& hierarchyRoot, const std::function<bool(const PXR_NS::SdfPath&, const PXR_NS::HdSceneIndexPrim&)>& operation);

PXR_NS::SdfPath _FindSelectionHighlightMirrorAncestor(const PXR_NS::SdfPath& path) const;

void _CollectSelectionHighlightMirrors(
const PXR_NS::SdfPath& originalPrimPath,
SelectionHighlightsCollectionDirection direction,
PXR_NS::SdfPathSet& outSelectionHighlightMirrors,
PXR_NS::HdSceneIndexObserver::AddedPrimEntries& outAddedPrims
);
void _AddInstancerHighlightUser(const PXR_NS::SdfPath& instancerPath, const PXR_NS::SdfPath& userPath);
void _RemoveInstancerHighlightUser(const PXR_NS::SdfPath& instancerPath, const PXR_NS::SdfPath& userPath);
void _RebuildInstancerHighlight(const PXR_NS::SdfPath& instancerPath);
void _DeleteInstancerHighlight(const PXR_NS::SdfPath& instancerPath);

void _CreateInstancerHighlightsForInstancer(const PXR_NS::HdSceneIndexPrim& instancerPrim, const PXR_NS::SdfPath& instancerPath);
bool _SelectionHighlightMirrorExists(const PXR_NS::SdfPath& selectionHighlightMirrorPath) const;

void _IncrementSelectionHighlightMirrorUseCounter(const PXR_NS::SdfPath& selectionHighlightMirrorPath);
void _DecrementSelectionHighlightMirrorUseCounter(const PXR_NS::SdfPath& selectionHighlightMirrorPath);

void _AddSelectionHighlightUser(const PXR_NS::SdfPath& primPath, const PXR_NS::SdfPath& userPath);
void _RemoveSelectionHighlightUser(const PXR_NS::SdfPath& primPath, const PXR_NS::SdfPath& userPath);
void _RebuildSelectionHighlight(const PXR_NS::SdfPath& primPath);
void _DeleteSelectionHighlight(const PXR_NS::SdfPath& primPath);

void _CreateSelectionHighlightsForInstancer(const PXR_NS::HdSceneIndexPrim& instancerPrim, const PXR_NS::SdfPath& instancerPath);
void _CreateSelectionHighlightsForMesh(const PXR_NS::HdSceneIndexPrim& meshPrim, const PXR_NS::SdfPath& meshPath);
void _CreateSelectionHighlightsForGeomSubset(const PXR_NS::SdfPath& geomSubsetPath);

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

const SelectionConstPtr _selection;
const std::shared_ptr<WireframeColorInterface> _wireframeColorInterface;

// The following three data members (_selectionHighlightMirrorsByInstancer, _selectionHighlightMirrorUseCounters and
// _instancerHighlightUsersByInstancer) hold the data required to properly manage the selection highlight mirror graph/hierarchy.
// The following three data members (_selectionHighlightMirrorsByPrim, _selectionHighlightMirrorUseCounters and
// _selectionHighlightUsersByPrim) hold the data required to properly manage the selection highlight mirror graph/hierarchy.
// A potential idea to support multiple wireframe colors for point instancer and instance selections could be to use
// a different mirror hierarchy for each color; in such a case, we could wrap these data members in a struct, and have
// one instance of this new struct for each differently colored selection highlight mirror hierarchy.

// Maps an instancer's path to its required selection highlight mirror paths.
std::unordered_map<PXR_NS::SdfPath, PXR_NS::SdfPathSet, PXR_NS::SdfPath::Hash> _selectionHighlightMirrorsByInstancer;
// Maps a prim's path to its required selection highlight mirror paths.
std::unordered_map<PXR_NS::SdfPath, PXR_NS::SdfPathSet, PXR_NS::SdfPath::Hash> _selectionHighlightMirrorsByPrim;

// "Ref-counting" of selection highlight mirror prims, which are shared across instancer highlights.
// "Ref-counting" of selection highlight mirror prims, which are shared across prim highlights.
std::unordered_map<PXR_NS::SdfPath, size_t, PXR_NS::SdfPath::Hash> _selectionHighlightMirrorUseCounters;

// Tracks which prims contributes to using this instancer's selection highlight.
// Why? Suppose the following scenario : we have two selections that each would lead to highlighting the same instancer.
// Since both would increment the use counts of the instancer's corresponding selection highlight mirrors, we would
// Tracks which prims contributes to using this prim's selection highlight (including itself).
// Why? Suppose the following scenario : we have two selections that each would lead to highlighting the same prim.
// Since both would increment the use counts of the prim's corresponding selection highlight mirrors, we would
// need to also decrement the use counts symetrically. However, what happens if we receive a PrimRemoved notification
// on a parent prim (of all contributing selected prims and the instancer itself)? We couldn't just decrement the
// instancer's selection highlight mirrors by one, or they could end up floating around in memory forever. However,
// we would have no way of knowing how many times this instancer actually uses its selection highlight mirrors.
// Keeping track of which selected prims contribute to the instancer's highlight solves this problem.
std::unordered_map<PXR_NS::SdfPath, PXR_NS::SdfPathSet, PXR_NS::SdfPath::Hash> _instancerHighlightUsersByInstancer;
// on a parent prim (of all contributing selected prims and the prim itself)? We couldn't just decrement the
// prim's selection highlight mirrors by one, or they could end up floating around in memory forever. However,
// we would have no way of knowing how many times this prim actually uses its selection highlight mirrors.
// Keeping track of which selected prims contribute to the prim's highlight solves this problem.
std::unordered_map<PXR_NS::SdfPath, PXR_NS::SdfPathSet, PXR_NS::SdfPath::Hash> _selectionHighlightUsersByPrim;
};

}
Expand Down
9 changes: 6 additions & 3 deletions lib/mayaHydra/hydraExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,14 @@ mayaHydra_compile_config(${TARGET_NAME})
# include directories
# -----------------------------------------------------------------------------
target_include_directories(${TARGET_NAME}
PUBLIC
SYSTEM PUBLIC
${PXR_INCLUDE_DIRS}
${MAYA_INCLUDE_DIRS}
)
target_include_directories(${TARGET_NAME}
PUBLIC
${PYTHON_INCLUDE_DIR}
${PXR_INCLUDE_DIRS}
${BOOST_INCLUDE_DIR}
${BOOST_INCLUDE_DIR}
${CMAKE_BINARY_DIR}/include
PRIVATE
$<$<BOOL:${UFE_FOUND}>:${UFE_INCLUDE_DIR}>
Expand Down
16 changes: 10 additions & 6 deletions lib/mayaHydra/mayaPlugin/renderOverride.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,22 +1151,22 @@ void MtohRenderOverride::_CreateSceneIndicesChainAfterMergingSceneIndex(const MH
if (! _wireframeColorInterfaceImp){
_wireframeColorInterfaceImp = std::make_shared<MAYAHYDRA_NS_DEF::MhWireframeColorInterfaceImp>(_selection, _leadObjectPathTracker);
}

// Repr selector Scene Index
_lastFilteringSceneIndexBeforeCustomFiltering = _reprSelectorSceneIndex =
Fvp::ReprSelectorSceneIndex::New(_lastFilteringSceneIndexBeforeCustomFiltering,
_wireframeColorInterfaceImp);
_reprSelectorSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT);
_reprSelectorSceneIndex->SetReprType(Fvp::ReprSelectorSceneIndex::RepSelectorType::Default, false, _globals.delegateParams.refineLevel);

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

// At time of writing, wireframe selection highlighting of Maya native data
// is done by Maya at render item creation time, so avoid double wireframe
// selection highlighting.
wfSi->addExcludedSceneRoot(MAYA_NATIVE_ROOT);
_lastFilteringSceneIndexBeforeCustomFiltering = wfSi;
_wireframeSelectionHighlightSceneIndex->addExcludedSceneRoot(MAYA_NATIVE_ROOT);
_lastFilteringSceneIndexBeforeCustomFiltering = _wireframeSelectionHighlightSceneIndex;

#ifdef CODE_COVERAGE_WORKAROUND
Fvp::leakSceneIndex(_lastFilteringSceneIndexBeforeCustomFiltering);
Expand Down Expand Up @@ -1422,6 +1422,7 @@ void MtohRenderOverride::_PickByRegion(
pickParams.viewMatrix.Set(viewMatrix.matrix);
pickParams.projectionMatrix.Set(adjustedProjMatrix.matrix);
pickParams.collection = _renderCollection;
pickParams.collection.SetExcludePaths(_wireframeSelectionHighlightSceneIndex->GetSelectionHighlightMirrorPaths());
pickParams.outHits = &outHits;

if (geomSubsetsPickMode == GeomSubsetsPickModeTokens->Faces) {
Expand All @@ -1433,7 +1434,10 @@ void MtohRenderOverride::_PickByRegion(

// Exclude selected Rprims to avoid self-snapping issue.
pickParams.collection = _pointSnappingCollection;
pickParams.collection.SetExcludePaths(_selectionSceneIndex->GetFullySelectedPaths());
auto excludePaths = _selectionSceneIndex->GetFullySelectedPaths();
auto selectionHighlightPaths = _wireframeSelectionHighlightSceneIndex->GetSelectionHighlightMirrorPaths();
excludePaths.insert(excludePaths.end(), selectionHighlightPaths.begin(), selectionHighlightPaths.end());
pickParams.collection.SetExcludePaths(excludePaths);
}

// Execute picking tasks.
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 @@ -51,6 +51,7 @@
#include <flowViewport/sceneIndex/fvpDefaultMaterialSceneIndex.h>
#include <flowViewport/sceneIndex/fvpReprSelectorSceneIndex.h>
#include <flowViewport/sceneIndex/fvpBlockPrimRemovalPropagationSceneIndex.h>
#include <flowViewport/sceneIndex/fvpWireframeSelectionHighlightSceneIndex.h>

#include <pxr/base/tf/singleton.h>
#include <pxr/imaging/hd/driver.h>
Expand Down Expand Up @@ -266,6 +267,7 @@ class MtohRenderOverride : public MHWRender::MRenderOverride,
Fvp::SelectionTrackerSharedPtr _fvpSelectionTracker;
Fvp::SelectionSceneIndexRefPtr _selectionSceneIndex;
Fvp::SelectionPtr _selection;
Fvp::WireframeSelectionHighlightSceneIndexRefPtr _wireframeSelectionHighlightSceneIndex;
Fvp::BlockPrimRemovalPropagationSceneIndexRefPtr _blockPrimRemovalPropagationSceneIndex;
// Naming this identifier _ufeSelection clashes with UFE's selection.h
// include guard and produces
Expand Down
7 changes: 6 additions & 1 deletion lib/mayaHydra/ufeExtensions/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ mayaHydra_compile_config(${TARGET_NAME})
# -----------------------------------------------------------------------------
target_include_directories(${TARGET_NAME}
PUBLIC
${PXR_INCLUDE_DIRS}
)

target_include_directories(${TARGET_NAME}
SYSTEM PUBLIC
${MAYA_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/include
$<$<BOOL:${UFE_FOUND}>:${UFE_INCLUDE_DIR}>
Expand Down Expand Up @@ -110,4 +115,4 @@ if(IS_WINDOWS)
install(FILES $<TARGET_PDB_FILE:${TARGET_NAME}>
DESTINATION ${CMAKE_INSTALL_PREFIX}/lib OPTIONAL)
endif()
endif()
endif()
1 change: 1 addition & 0 deletions plugin/mayaHydraSceneBrowser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ target_compile_definitions(${TARGET_NAME}
# -----------------------------------------------------------------------------
target_include_directories(${TARGET_NAME}
PUBLIC
${PXR_INCLUDE_DIRS}
${MAYA_INCLUDE_DIRS}
)

Expand Down
5 changes: 3 additions & 2 deletions plugin/mayaHydraSceneBrowserTest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ mayaHydra_compile_config(${TARGET_NAME})
# include directories
# -----------------------------------------------------------------------------
target_include_directories(${TARGET_NAME}
PUBLIC
${MAYA_INCLUDE_DIRS}
SYSTEM PUBLIC
${PXR_INCLUDE_DIRS}
${MAYA_INCLUDE_DIRS}
)

# -----------------------------------------------------------------------------
Expand Down
5 changes: 3 additions & 2 deletions test/lib/mayaUsd/render/mayaToHydra/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testObjectTemplate.py
testStandardSurface.py
testFlowViewportAPI.py
testStageVariants.py
testStageVariants.py|skipOnPlatform:osx # HYDRA-1127 : refinedWire not working on OSX
testStagePayloadsReferences.py
testNurbsPrimitives.py
testCurveTools.py
Expand All @@ -43,7 +43,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
testGrid.py
testUsdTextureToggle.py
# To be reenabled after investigation
testDataProducerSelHighlight.py|skipOnPlatform:osx
testDataProducerSelHighlight.py|skipOnPlatform:osx # HYDRA-1127 : refinedWire not working on OSX
testPassingNormalsOnMayaNative.py
testViewportFilters.py
testMayaComponentsPicking.py
Expand Down Expand Up @@ -76,6 +76,7 @@ set(INTERACTIVE_TEST_SCRIPT_FILES
cpp/testGeomSubsetsPicking.py
cpp/testSinglePicking.py
cpp/testSceneIndexDirtying.py
cpp/testGeomSubsetsWireframeHighlight.py
)

#Add this test only if the MayaUsd_FOUND (so also MAYAUSDAPI_LIBRARY) has been found during compile time.
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions test/lib/mayaUsd/render/mayaToHydra/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ target_sources(${TARGET_NAME}
testGeomSubsetsPicking.cpp
testSinglePicking.cpp
testSceneIndexDirtying.cpp
testGeomSubsetsWireframeHighlight.cpp
)

# -----------------------------------------------------------------------------
Expand Down
Loading

0 comments on commit 75363a1

Please sign in to comment.