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

dual selection mode for adaptors #6103

Open
masterkeech opened this issue Oct 21, 2024 · 2 comments
Open

dual selection mode for adaptors #6103

masterkeech opened this issue Oct 21, 2024 · 2 comments

Comments

@masterkeech
Copy link

masterkeech commented Oct 21, 2024

Summary

the ability to overwrite selection (SelectionTool.registerSelectMode ) is very useful but may not work for all situations, eg. if you're altering the scene graph via the use of an adaptor. we're currently using an adaptor to auomatically generate all of the USD instances in the viewer which is very handy but we lose the ability to select the prototypes from the view and vice versa.

User story

What

On selection of an expanded instance in the viewer, the corresponding prototype should be picked in the hierarchy view. And when the prototype in the hierarchy view is selected that all corresponding prototypes get selected.

#### Viewer Selection ####
current implementation for viewer selection is implemented in the following way, which works great but the mesh doesn't stay selected alongside the prototype in the hierarchy.

def usd_instance_selection(scene: GafferScene.ScenePlug, path: str) -> str:
    """
    Updates the selection to the hierarchy to match the prototype but this causes the veiwer to get deselected
    """
    match = re.match("(.*/instances/[a-zA-Z0-9_]+_\d+)/\d+/.*", path)
    if match:
        return match.group(1).replace("instances", "Prototypes")
    return path

 GafferSceneUI.SelectionTool.registerSelectMode("Instances/Prototypes", usd_instance_selection)

/Standard selection
Screenshot 2024-10-21 at 17 57 10

Instances/Prototypes selection
Screenshot 2024-10-21 at 17 56 55

#### Hierarchy Selection ####
hierarchy selection is done through a pop-up context menu on the hierarchy view which works and selects the instances but then deselects the prototype in the hierarchy view.

def __select_usd_instances(selection:IECore.PathMatcher, script:Gaffer.ScriptNode):
    results = []
    for path in selection.paths():
        match = re.match("(.*)/[Pp]rototypes/([a-zA-Z0-9_]+_\d+)", path)
        results.append(f"{match.group(1)}/instances/{match.group(2)}/*/*")
    GafferSceneUI.ScriptNodeAlgo.setSelectedPaths(script, IECore.PathMatcher(results))


def __custom_context_menu(column: GafferUI.StandardPathColumn, path_listing_widget: GafferUI.PathListingWidget, menu_definition: IECore.MenuDefinition):
    hierarchy_view_widget = path_listing_widget.ancestor(GafferSceneUI.HierarchyView)
    scene_plug = hierarchy_view_widget.scene()
    if scene_plug is None:
        return
    selection: IECore.PathMatcher = path_listing_widget.getSelection()
    if selection.isEmpty():
        return
    else:
        menu_definition.append(
            "Select Instances",
            {
                "command": functools.partial(__select_usd_instances, selection, hierarchy_view_widget.scriptNode()),
                # disable the menu if multiple selection
                "active": not selection.isEmpty() and selection.size() == len(
                    [s for s in selection.paths() if "Prototypes/prototype_" in s]
                ),
            },
        )


def __hierarchy_view_created(hierarchy_view: GafferSceneUI.HierarchyView):
    hierarchy_view.sceneListing().columnContextMenuSignal().connect(__custom_context_menu, scoped=False)

GafferSceneUI.HierarchyView.instanceCreatedSignal().connect(__hierarchy_view_created, scoped=False)

Screenshot 2024-10-21 at 18 01 11
Screenshot 2024-10-21 at 18 08 01

Why

This is the current behaviour when using a USDInstancer in the graph so replication of the behaviour is needed as not to introduce a less equivalent workflow.

Feature proposal

being able to maintain or return multiple selections would be one possible solution. and have a similar feature for hierarchy view so that we don't have to use a context menu.

Example scenario(s)

Both scenarios would allow us to put in a hook/callback so that selection would be maintained in the current hierarchy views structure and the hidden that exists from the adaptor adapting the scene graph.

Implementation notes

(Optional) Add any relevant technical notes.

@ericmehl
Copy link
Collaborator

I've been thinking about this some this afternoon and have a few follow-up questions.

If you select a prototype in the viewer and drag onto a node, say an Isolate node, to set its PathFilter, what would you want to be dropped into that filter? Would it be the prototype, /MediterraneanHills/Buildings/Prototypes/prototype_0? Or would you want the scene paths generated by the instancer, something like /MediterraneanHills/Buildings/instances/prototype_0/0, /MediterraneanHills/Buildings/instances/prototype_0/1, etc. all the way up to the number of instances?

I suspect that what you want to get when dragging from the viewer would be the same as when dragging from the hierarchy view, is that correct?

And similar considerations for things like using transforms in the viewer or making edits in Edit Scopes. If you select something in the hierarchy view or viewer, what should those changes be applied to?

I think it would make sense in most (all?) cases to be dealing with prototypes for the actual stored selection, since that's all that users will be able to affect since they're upstream of the adapter. But I want to make sure I understand your setup.

@masterkeech
Copy link
Author

i think you're right, that we'd want to drag the prototype. We're definining a new selection mode called 'Instancer/Prototypes` so that makes sense for this case and if the artist wants to select and drag the instancer path then they would use the standard selection mode.

And for the hierarchy view we'd expect the selection to the the location of the prototype, so pretty much the same.

Hopefully that helps outline our workflow a little more clearly, let me know if you have any other questions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: On the Radar
Development

No branches or pull requests

2 participants