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

MAYA-106477 selection and point snapping support for mtoh #776

Merged
merged 6 commits into from
Sep 30, 2020

Conversation

huidong-chen
Copy link

The change requires new Maya APIs and needs to be merged after Maya PR119 is published.

@huidong-chen huidong-chen added mtoh Related to legacy Maya to Hydra plugin. do-not-merge-yet Development is not finished, PR not ready for merge pending beta This issue or PR will be testable in next beta release labels Sep 16, 2020
@kxl-adsk
Copy link

kxl-adsk commented Sep 18, 2020

@marsupial can you review this change since you reported the missing API? I can't set you as a reviewer.

Copy link
Contributor

@marsupial marsupial left a comment

Choose a reason for hiding this comment

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

Overall, good to see some movement here.
I'm curious how the point-snapping and collection API is going to play with renderers other than Storm.


SdfPath usdPath = objectId.ReplacePrefix(delegateId, SdfPath::AbsoluteRootPath());

printf("usdPath: %s\n", usdPath.GetText());
Copy link
Contributor

Choose a reason for hiding this comment

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

Should get commented out.

Copy link
Author

Choose a reason for hiding this comment

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

This should have been removed by commit 9afde83.

{
if (selectInfo.pointSnapping()) {
for (const HdxPickHit& hit : hits) {
std::lock_guard<std::mutex> lock(_allAdaptersMutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the lock be acquired outside the for loop, or a comment stating why not.

const SdfPath& objectId = hit.objectId;
const int instanceIndex = hit.instanceIndex;

std::lock_guard<std::mutex> lock(_allAdaptersMutex);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can the lock be moved out of the for-loop? There's very-likely little contention for it, but avoiding the lock/unlock cycle for every hit seems better for code triggered from UI.

Copy link
Author

Choose a reason for hiding this comment

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

Good catch! I think it is better to move it outside of the for loop.

@kxl-adsk Can you confirm?

Choose a reason for hiding this comment

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

Of course, this makes perfect sense.

@huidong-chen
Copy link
Author

I'm curious how the point-snapping and collection API is going to play with renderers other than Storm.

Good question. I tested HdStorm and HdEmbree, which also helps me understand the responsibility of each component.

  • The maya-to-hydra layer (which is TMK the render override code) manages the collections based on maya's frame context and selection info, then it executes the Hydra engine for the picking task.
  • The picking task is done by different render delegates/backends, and it should provide the hit result. We can compare the hit result of each render delegate here and identify bugs of different render delegates.
  • The maya-to-hydra layer will need to interpret the hit result and generate selection list (either Maya selection list or UFE selection list).

@marsupial
Copy link
Contributor

I'm not sure 2. is accurate (or maybe it's just a semantic point), the Hydra pick-task is different between Storm & EverythingElse, but delegates don't really implement it...they push buffers compatible with what the Hydra pick-task would like.

That said, if Embree is doing what you want already, it's a pretty good sign. Waiting to get 119 installed so can check this out further.

@huidong-chen
Copy link
Author

I didn't dig into how the pick task is implemented inside Hydra and/or render delegates, so 2. is more of a high-level concept.

@huidong-chen huidong-chen added ready-for-merge Development process is finished, PR is ready for merge and removed do-not-merge-yet Development is not finished, PR not ready for merge pending beta This issue or PR will be testable in next beta release labels Sep 24, 2020
@huidong-chen
Copy link
Author

@marsupial Do you plan to test before approving the PR?

@marsupial
Copy link
Contributor

I don't think I am an approver anyway, but starting to build/test now.

@huidong-chen
Copy link
Author

Thanks. I see you are in the reviewers list, which is confusing.

@kxl-adsk
Copy link

@marsupial see my earlier comment - #776 (comment)

@marsupial
Copy link
Contributor

Overall working great. There is an issue with instances though, what I wound up doing was replacing these lines:

auto proxyAdapter = findResult->second;
selectedSdfPaths.push_back(proxyAdapter->ConvertCachePathToIndexPath(
SdfPath(usdPathSegment.string())));
selection->AddRprim(
HdSelection::HighlightModeSelect, selectedSdfPaths.back());
TF_DEBUG(HDMAYA_AL_SELECTION)
.Msg(
"HdMayaProxyDelegate::PopulateSelectedPaths - selecting %s\n",
selectedSdfPaths.back().GetText());

With the following (the HdMayaProxyAdapter::delegate() method would need to be added as well):

 if (auto delegate = findResult->second->delegate())
    delegate->PopulateSelection(HdSelection::HighlightModeSelect, SdfPath(usdPathSegment.string()), usdImagingDelegate::ALL_INSTANCES, selection);

@pmolodo might have more info, but the original code was probably an older version of USD where instance-selection was much less robust then it currently is.

We've been using the PopulateSelection() call in this place for months, and should work for > 20.x (hopefully 19.11 too).

@marsupial
Copy link
Contributor

Two outstanding issues related to selection (which I don't think should hold this up):

  1. Really want this tied into the USD assembly, component selection mode in Maya (selecting leaf items is rarely what we want)
  2. Out implementation also hooked this up to proxySelection via Storm when mtoh was not involved (otherwise the Storm selection selects the full usdProxyShape).

@huidong-chen huidong-chen removed the ready-for-merge Development process is finished, PR is ready for merge label Sep 25, 2020
@huidong-chen
Copy link
Author

@marsupial Thanks for pointing out the selection highlight issue and providing the code. I just pushed a new commit that follows your suggestion.

For the two outstanding issues, our priority for this task is to fix the blocking part, which is the missing API in maya for selection. For legacy issues and feature improvement, we will most likely rely on partners to do it. Hope it makes sense.

@huidong-chen
Copy link
Author

We've been using the PopulateSelection() call in this place for months, and should work for > 20.x (hopefully 19.11 too).

Yes, the function has also been used in VP2RenderDelegate since last August.

@marsupial
Copy link
Contributor

As noted, not an approver, but LGTM!
Agreed a great first step on the new API...just wanted to point out the other 2 points to where we'll still need to go, to try and minimize duplicate efforts.

@kxl-adsk
Copy link

@marsupial Re minimalizing duplicated efforts. We have no plans in near future to work on select by kind support in mtoh.

If I understood your second point correctly, you are talking about draw override integration of Storm (not mtoh). This is a legacy drawing routine and we are not investing in it. We are focusing on VP2RenderDelegate which removes a number of limitations like shadows across two data models, screen-space effects, etc. In which scenarios you are using this legacy rendering mode?

@marsupial
Copy link
Contributor

@kxl-adsk: The 'legacy' rendering mode is the fallback for us. The VP2RenderDelegate is still quite a ways off from being useable. From prior conversations and the file we sent you:

  • 40 minutes to load a files vs 40 sec with other delegates
  • UI very unresponsive when load completes
  • Everything is blue anyway

@kxl-adsk
Copy link

@marsupial Many materials problem you reported is next in line to look at. Good to know that it's the only adoption blocker you have.

Copy link
Contributor

@pmolodo pmolodo left a comment

Choose a reason for hiding this comment

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

Looks good. I think we might make situationally better use of the resolveMode, but I suppose that falls more under the class of an optimization.

pickParams.resolution.Set(view_w, view_h);
pickParams.viewMatrix.Set(viewMatrix.matrix);
pickParams.projectionMatrix.Set(projMatrix.matrix);
pickParams.resolveMode = HdxPickTokens->resolveUnique;
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we probably want to vary this depending on what selectInfo.singleSelection and selectInfo.selectClosest return. resolveUnique makes sense for a marquee-selection scenario (within the limits under discussion here), but probably doesn't for single select.

Copy link
Author

Choose a reason for hiding this comment

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

Maybe, but I haven't seen issue for single selection when testing the code. With the code merged, I am sure there are still some improvements in the plugin side as we iterate over time. So maybe something for future?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, like I said, this falls more under the class of an optimization. It's a pretty easy check to make, and you'd then be able to skip the ResolveUniqueHits_Workaround if you were doing resolveNearestToCenter or resolveNearestToCamera... but you're likely also right, in that it may not be noticeable for single select, since the pick region is generally going to be pretty small. So your call.

@@ -175,6 +184,11 @@ class MtohRenderOverride : public MHWRender::MRenderOverride {
HdRprimCollection _selectionCollection{
HdReprTokens->wire, HdReprSelector(HdReprTokens->wire)
};
HdRprimCollection _pointSnappingCollection{
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be worth also hiding this one behind a 20210000 version guard, since it's only used there.

Copy link
Author

Choose a reason for hiding this comment

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

Good point.

@huidong-chen huidong-chen added the ready-for-merge Development process is finished, PR is ready for merge label Sep 29, 2020
@huidong-chen
Copy link
Author

@kxl-adsk Please merge. Thanks.

@kxl-adsk kxl-adsk merged commit 2400a86 into dev Sep 30, 2020
@kxl-adsk kxl-adsk deleted the HdC-adsk/MAYA-106477/mtoh-selection branch September 30, 2020 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
mtoh Related to legacy Maya to Hydra plugin. 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.

5 participants