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-1057 : GeomSubsets wireframe highlighting #148

Merged
merged 46 commits into from
Jul 30, 2024

Conversation

debloip-adsk
Copy link
Collaborator

@debloip-adsk debloip-adsk commented Jul 16, 2024

This PR adds selection highlighting for GeomSubsets.

A brief overview of the thought process behind the implementation : previously, non-instanced meshes were highlighted through the refinedWireOnSurf display style. However, this does not allow us to create a wireframe for a subset of the mesh. So the idea is to instead use the existing architecture that maintains a selection highlight mirror hierarchy, and have a mirror prim of the mesh with a refinedWire display style. We can then edit this mirror mesh to only contain the topology related to the selected GeomSubsets. However, to do so, it is much simpler and more consistent to move away from refinedWireOnSurf entirely, and just have mesh selections also use mirror prims : this way, we can use the selection highlight mirror hierarchy for everything, and we only have one consistent (though somewhat complex) way of handling all highlights.

@debloip-adsk debloip-adsk marked this pull request as ready for review July 16, 2024 20:47
@debloip-adsk debloip-adsk force-pushed the debloip/HYDRA-1057/geomsubset-highlighting branch from ad05cf6 to 2ccb0b0 Compare July 18, 2024 19:07
Comment on lines -54 to -60
const HdRetainedContainerDataSourceHandle sRefinedWireOnSurfaceDisplayStyleDataSource
= HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->displayStyle,
HdRetainedContainerDataSource::New(
HdLegacyDisplayStyleSchemaTokens->reprSelector,
HdRetainedTypedSampledDataSource<VtArray<TfToken>>::New(
{ HdReprTokens->refinedWireOnSurf, TfToken(), TfToken() })));
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything now uses separate prims with refinedWire only

// Computes the mask to use for an instancer's selection highlight mirror
// based on the instancer's topology and its selections. This allows
// highlighting only specific instances in the case of instance selections.
VtBoolArray _GetSelectionHighlightMask(const HdInstancerTopologySchema& originalInstancerTopology, const HdSelectionsSchema& selections)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a method


// Returns the overall data source for an instancer's selection highlight mirror.
// This replaces the mask data source and blocks the selections data source.
HdContainerDataSourceHandle _GetSelectionHighlightInstancerDataSource(const HdContainerDataSourceHandle& originalDataSource)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to a method

return VtBoolArray(nbInstances, false);
}();

if (!selections.IsDefined()) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the newly handled case and why this function and _GetSelectionHighlightInstancerDataSource was moved to a method, in order to call GetSelectionHighlightPath

Comment on lines +522 to +523
// There already exists an explicit selection highlight mirror for this child (e.g. point instance prototypes),
// so don't create a duplicate implicit one.
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just to avoid overdraw, as without the check everything still works, but a highlight could be drawn more than once

affectedOriginalPrimPaths.insert(affectedOriginalPrimPaths.end(), instancingRelatedPaths.begin(), instancingRelatedPaths.end());
return false; // We have found an instancer, don't process its children (nested instancers will be processed through the instancing-related paths).
if (prim.primType == HdPrimTypeTokens->instancer || prim.primType == HdPrimTypeTokens->mesh) {
if (direction & SelectionHighlightsCollectionDirection::Prototypes) {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Splitting the instancing-related paths in two prevents us from always traversing the entire instancing graph, and inadvertently creating selection highlights for non-selected prims. Without this, selecting an instanced mesh would create a highlight mirror for the mesh, then a highlight mirror for the instancer, but in creating the highlight mirror for the instancer and collecting its instancing paths, we would collect its other prototype paths, and then create highlight mirrors for those as well, even if they weren't actually selected.

@@ -1894,6 +1894,7 @@ void MtohRenderOverride::_PickByRegion(
pickParams.viewMatrix.Set(viewMatrix.matrix);
pickParams.projectionMatrix.Set(adjustedProjMatrix.matrix);
pickParams.collection = _renderCollection;
pickParams.collection.SetExcludePaths(_wireframeSelectionHighlightSceneIndex->GetSelectionHighlightMirrorPaths());
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to exclude selection highlight prims. If we don't, selecting the highlight mirror of a mesh that is trimmed by a GeomSubset selection ends up selecting the original mesh, instead of selecting the GeomSubset.

// This method takes in a path to a prim in a selection highlight hierarchy and ensures that
// the selection highlight graph is structured properly, and that the leaf mesh prims have
// the proper display style.
void assertSelectionHighlightCorrectness(
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted and slightly tweaked from testPointInstancingWireframeHighlight.cpp

Copy link
Collaborator

@ppt-adsk ppt-adsk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't say I delved very deeply into the logic, but the tests pass, so that works for me.

As discussed, agree that the approach is the right one, and is the way to get the draw flexibility we need, but concerned about z-fighting and resulting decrease in quality. Can be addressed at a later time.

@debloip-adsk debloip-adsk added the ready-for-merge Development process is finished, PR is ready for merge label Jul 22, 2024
@roopavr-adsk roopavr-adsk merged commit 2331b62 into dev Jul 30, 2024
10 checks passed
@roopavr-adsk roopavr-adsk deleted the debloip/HYDRA-1057/geomsubset-highlighting branch July 30, 2024 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-for-merge Development process is finished, PR is ready for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants