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

Enhancement: Prim Hierarchy Delegate and default prim / variant set features #21

Merged
merged 58 commits into from
Nov 29, 2023

Conversation

BigRoy
Copy link
Owner

@BigRoy BigRoy commented Nov 26, 2023

  • Add a style delegate to draw whether a prim is default prim DFT, has references/payloads REF and/or has variant sets VAR

image

usd_qtpy/prim_hierarchy.py Outdated Show resolved Hide resolved
Note: If moved to a PrimSpec path already existing in the target layer then any opinions on that PrimSpec or it children are removed. It replaces the prim spec - it does not 'merge' it into an existing prim spec.

This is an implementation and thus fix for #20
@BigRoy BigRoy linked an issue Nov 27, 2023 that may be closed by this pull request
@BigRoy BigRoy linked an issue Nov 27, 2023 that may be closed by this pull request
@BigRoy BigRoy marked this pull request as ready for review November 29, 2023 00:44
@BigRoy BigRoy added the enhancement New feature or request label Nov 29, 2023
@BigRoy
Copy link
Owner Author

BigRoy commented Nov 29, 2023

@Sasbom @MustafaJafar any chance you could give this PR a go and see what stands out?

The python -m usd_qtpy /path/to/file.usd should also be applying the style sheet to the editor.

Otherwise, this is roughly what I've been running to test with:

import logging
from pxr import Usd
from qtpy import QtWidgets

from usd_qtpy.editor import EditorWindow
from usd_qtpy.style import load_stylesheet

DEBUG = True
if DEBUG:
    # Clear all root logging handlers just to ensure our basic config is used
    root = logging.getLogger()
    if root.handlers:
        for handler in list(root.handlers):
            root.removeHandler(handler)
    logging.basicConfig(
        format=(
            '%(asctime)s,%(msecs)03d %(levelname)-8s '
            '[%(filename)s:%(lineno)d] %(name)s.%(funcName)s() '
            '%(message)s'
        ),
        datefmt='%Y-%m-%d:%H:%M:%S',
        level=logging.DEBUG
    )


filepath = r"C:\Users\User\Desktop\shot\shot.usda"
stage = Usd.Stage.Open(filepath)

app = QtWidgets.QApplication()
dialog = EditorWindow(stage=stage)
dialog.resize(1400, 800)
dialog.setStyleSheet(load_stylesheet())
dialog.show()
app.exec_()

@Sasbom
Copy link
Contributor

Sasbom commented Nov 29, 2023

I tried all the features, caching seems to be working OK!

However, the styling still has some issues here and there,
I suspect Qt is having some issues with styling the font in layer_editor.py,
I'm running the kitchen scene with hython, and Courier doesn't seem present.
Failed to compute left/right minimum bearings for "Courier"
is the message I am getting, and it seems to stem purely from Qt not being able to find the font.
These errors basically pop up so often when they happen that everything else spinlocks to a halt.

I found out that from Win-10 onwards, "Base" Courier isn't present by default, it has been replaced with "Courier New"
Changing:

text_edit.setStyleSheet('* { font-family: "Courier"; }')

and
text_edit.setStyleSheet('* { font-family: "Courier"; }')

to

text_edit.setStyleSheet('* { font-family: "Courier New"; }')

On my system helped, so it seems that some font environment checking for "Courier-like" fonts would be good,
then passing those in. It's not a guarantee that Courier will be present on Linux systems as well...

If all else fails, we should probably include a font backup!
For example, this one.

I find myself REAALLLY wanting:

  • selection syncing between menus
  • being able to focus the FreeCamera from UsdViewq on a selected object
  • Editing attributes on Xforms etc in an attribute editor window

after all of this, now it looks so neat and refined!

@BigRoy
Copy link
Owner Author

BigRoy commented Nov 29, 2023

I suspect Qt is having some issues with styling the font in layer_editor.py,
I'm running the kitchen scene with hython, and Courier doesn't seem present.
Failed to compute left/right minimum bearings for "Courier"

Could you try again with the latest commit 936c6c8 ?

I find myself REAALLLY wanting:

* selection syncing between menus

* being able to focus the FreeCamera from UsdViewq on a selected object

* Editing attributes on Xforms etc in an attribute editor window

after all of this, now it looks so neat and refined!

That'd be great - yes. A full blown USD editor. There goes the idea of just making some useful USD Python Qt widgets. We'll be competing with Maya next ;)

Anyway, thanks - those would definitely make for good issues to track interest in those. Will create those in a bit.

@Sasbom
Copy link
Contributor

Sasbom commented Nov 29, 2023

Could you try again with the latest commit 936c6c8 ?

Done did! It works as intended. Looking good.

Also:

After reading the prim hierarchy model and cache and how they interact,
one more point pops up:

Since we are allowing edits, are we going to support undo and redo?

It seems that the entire tree is cached in one HierarchyCache object, so I wonder if we could use this to implement an undo/redo stack. This would further improve the editability down the line, but we could also implement this using some way of collecting differences after each operation, since I reckon most operations aren't destructive (if they even can be, in USD). Either way, that'd be something to explore for a further future.

@BigRoy
Copy link
Owner Author

BigRoy commented Nov 29, 2023

Since we are allowing edits, are we going to support undo and redo?

It seems that the entire tree is cached in one HierarchyCache object, so I wonder if we could use this to implement an undo/redo stack. This would further improve the editability down the line, but we could also implement this using some way of collecting differences after each operation, since I reckon most operations aren't destructive (if they even can be, in USD). Either way, that'd be something to explore for a further future.

Have thought about that but oh boy - that's a whole different can of worms. Having a global Tf.Notice based undo stack based on just "differences" on a stage or per layer basis is likely the easiest + bonus points that it could e.g. even capture changes made in Maya to the stage as well. It would hardly be an optimized undo queue though.

Other only option I think is to wrap any change we make into a dedicated "command" that keeps track of the changes to undo/redo accordingly - but admittedly, I'd argue it's out of scope unless we're aiming to design a full blown USD Editor to compete with DCCs.

Anyway, will also create an issue to track this - but I wouldn't take it as a high priority.

@BigRoy BigRoy merged commit 3e27bd0 into main Nov 29, 2023
@BigRoy BigRoy deleted the enhancement/prim_hierarchy_delegate branch November 29, 2023 16:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment