Skip to content

Commit

Permalink
Merge pull request #55 from kwokcb/usd_text_preview
Browse files Browse the repository at this point in the history
Proposal : Allow for the ability to see USD Stage materials as text
  • Loading branch information
manuelkoester authored Feb 16, 2024
2 parents 0918d85 + 2e69ddc commit 76a2670
Showing 1 changed file with 25 additions and 0 deletions.
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

0 comments on commit 76a2670

Please sign in to comment.