BigRoy / usd-qtpy

Python Qt components for building custom USD tools.
MIT License
57 stars 8 forks source link

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

Closed BigRoy closed 7 months ago

BigRoy commented 7 months ago

image

BigRoy commented 7 months ago

I still need to implement/fix:

BigRoy commented 7 months ago

@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 commented 7 months ago

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: https://github.com/BigRoy/usd-qtpy/blob/f7235b0381e7c0cd2efc48ce075f03312e747e52/usd_qtpy/layer_editor.py#L606 and https://github.com/BigRoy/usd-qtpy/blob/f7235b0381e7c0cd2efc48ce075f03312e747e52/usd_qtpy/layer_diff.py#L63 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:

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

BigRoy commented 7 months ago

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 https://github.com/BigRoy/usd-qtpy/pull/21/commits/936c6c8a88dabfb952b3080d3120d9b76ecdfb80 ?

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 commented 7 months ago

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 commented 7 months ago

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.