Autodesk / maya-usd

A common USD (Universal Scene Description) plugin for Autodesk Maya
762 stars 202 forks source link

Prim highlighted in Outliner after clearing UFE selection on `SelectionReplaced` notification #2473

Open wiremas opened 2 years ago

wiremas commented 2 years ago

Hi all,

We're encountering an issue with selection highlighting in the Outliner when we clear the UFE selection inside a ufe.SelectionReplaced notification. The Outliner is still highlighting the selected prim despite nothing is actually selected. Note that we only see this issue when selecting a prim in the Outliner. When selecting a prim in the view port the selection is cleared as expected and nothing is highlighted in the Outliner.

Steps to reproduce

  1. Create a stage with a new layer & add a prim in the Outliner (context menu > Add New Prim).
  2. Add MySelectionObserver to the global selection:
    
    import ufe

class MySelectionObserver(ufe.Observer): def call(self, notification): if isinstance(notification, ufe.SelectionReplaced): self._clearSelection(notification)

def _clearSelection(notification):
    selection = ufe.GlobalSelection.get()
    selection.clear()

observer = MySelectionObserver() selection = ufe.GlobalSelection.get() selection.addObserver(observer)

3. Select the previously created prim in the Outliner. Note that Outliner is still highlighting the selection. However, the prim's parents are not indicating the selection as it would be expected usually.
4. Query the global selection and notice that nothing is selected even though the Outliner is highlighting the selected prim.
```python
>>> print(item.path() for item in ufe.GlobalSelection.get())
[]

Specs (if applicable):

ppt-adsk commented 2 years ago

Hi @wiremas, thanks for your report. I'd like to know what you're trying to do. What you're currently doing is changing the selection from a selection replaced callback, which is not good. The reason is that if there are many selection observers in Maya, those before you will see a selection replaced notification, and those after you would see a selection cleared notification --- if this works at all, which from your report appears that it doesn't.

In general, the philosophy of callbacks when a given datum changes is that you should update viewers and your data structures within the callback, but not change the datum itself, because at that point you're doing a callback order dependant re-entrant change, which makes the entire system unpredictable and hard to understand.

Is there a reason why you want the selection to be cleared when you see that it's been replaced?

wiremas commented 2 years ago

Thanks @ppt-adsk for your quick reply.

We're currently investigating the switch form the AL_usd_maya to the mayaUSD plugin. For our environment authoring workflow we want to restrict artists from selecting certain prims that are not meant to be manipulated. Up until now we were using a customized version of the Luma Outliner to selectively display components relevant to environment authoring. Moving forward we're aiming for a more Maya native approach to ease the learning curve for new artists and remove clutter from the interface. To achieve this we have a few different ideas floating around - see separate discussion here.

The idea behind this particular issue was to remap the Outliner selection to relevant prims on the selection changed notification similar to the usd selection mode in the view port. However, the usd selection mode might not be ideal for us for two reasons:

Ideally, we'd be able to take full control over the remap behavior regardless whether an artist selects a prim in the view port, the Outliner or by whichever other means.

Just to entertain the idea of remapping prim selection on the selection changed notification for a little longer: Is there some kind of transaction manager in the UFE notice system that would allow us to "silence" or queue up notifications? (Even though this might be a bad idea and come with a whole set of other problems)