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

Proposal : Allow for the ability to see USD Stage materials as text #55

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/QuiltiX/quiltix.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,10 @@ def init_menu_bar(self):
show_mx_text.triggered.connect(self.show_mx_text_triggered)
self.file_menu.addAction(show_mx_text)

show_usd_text = QAction("Show USD as text...", self)
show_usd_text.triggered.connect(self.show_usd_text_triggered)
self.file_menu.addAction(show_usd_text)

self.file_menu.addSeparator()

show_mx_view = QAction("Open in MaterialX View...", self)
Expand Down Expand Up @@ -537,6 +541,27 @@ def show_mx_text_triggered(self):
te_text.resize(1000, 800)
te_text.show()

def print_usd_prim(self, prim):
assert isinstance(prim, Usd.Prim)
prim_stage = prim.GetStage()
prim_stage_id = prim_stage.GetRootLayer().identifier
stage = Usd.Stage.CreateInMemory()
target = stage.DefinePrim("/{}".format(prim.GetName()))
target.GetReferences().AddReference(prim_stage_id, prim.GetPath())
return stage.ExportToString()

def show_usd_text_triggered(self):
usdstage = self.stage_ctrl.stage
materials = usdstage.GetPrimAtPath("/MaterialX")
text = self.print_usd_prim(materials)
te_text = QTextEdit()
te_text.setText(text)
te_text.setReadOnly(True)
te_text.setParent(self, QtCore.Qt.Window)
te_text.setWindowTitle("USD text preview")
te_text.resize(1000, 800)
te_text.show()

def show_mx_view_triggered(self):
exe = os.getenv("MATERIALX_VIEW", "")
if not os.path.exists(exe):
Expand Down