Skip to content

Commit

Permalink
prevent recursion due to cycles on scene graph connections
Browse files Browse the repository at this point in the history
  • Loading branch information
chrizzFTD committed Jan 6, 2024
1 parent a50ace1 commit 07d1277
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 8 additions & 2 deletions grill/views/description.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,13 @@ def _add_edges(src_node, src_name, tgt_node, tgt_name):
}
table_row = '<tr><td port="{port}" border="0" bgcolor="{color}" style="ROUNDED">{text}</td></tr>'

traversed_prims = set()
def traverse(api: UsdShade.ConnectableAPI):
node_id = _get_node_id(api.GetPrim())
# label = f'<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="white" color="{outline_color}">'
current_prim = api.GetPrim()
if current_prim in traversed_prims:
return
traversed_prims.add(current_prim)
node_id = _get_node_id(current_prim)
label = f'<<table border="1" cellspacing="2" style="ROUNDED" bgcolor="{background_color}" color="{outline_color}">'
label += table_row.format(port="", color="white", text=f'<font color="{outline_color}"><b>{api.GetPrim().GetName()}</b></font>')
plugs = {"": 0} # {graphviz port name: port index order}
Expand Down Expand Up @@ -545,6 +549,8 @@ def __init__(self, parent=None, **kwargs):
def setPrim(self, prim):
if not prim:
return
type_text = "" if not (type_name:= prim.GetTypeName()) else f" {type_name}"
self.setWindowTitle(f"Scene Graph Connections From{type_text}: {prim.GetName()} ({prim.GetPath()})")
self._graph_view.graph = graph = _graph_from_connections(prim)
self._graph_view.view(graph.nodes.keys())

Expand Down
4 changes: 4 additions & 0 deletions tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ def test_connection_view(self):
pbrShader = UsdShade.Shader.Define(stage, '/TexModel/boardMat/PBRShader')
pbrShader.CreateInput("roughness", Sdf.ValueTypeNames.Float).Set(0.4)
material.CreateSurfaceOutput().ConnectToSource(pbrShader.ConnectableAPI(), "surface")
# Ensure cycles don't cause recursion
cycle_input = pbrShader.CreateInput("cycle_in", Sdf.ValueTypeNames.Float)
cycle_output = pbrShader.CreateOutput("cycle_out", Sdf.ValueTypeNames.Float)
cycle_output.ConnectToSource(cycle_input)
description._graph_from_connections(material)
viewer = description._ConnectableAPIViewer()
viewer.setPrim(material)
Expand Down

0 comments on commit 07d1277

Please sign in to comment.