Returns the first ComputeGraph found in selected_paths.
If no graph is found and create_new_graph is true, a new graph will be created and its
path appended to created_paths (if provided).
Source code in omnigibson/utils/deprecated_utils.py
| def get_compute_graph(self, selected_paths, create_new_graph=True, created_paths=None):
"""
Returns the first ComputeGraph found in selected_paths.
If no graph is found and create_new_graph is true, a new graph will be created and its
path appended to created_paths (if provided).
"""
graph = None
graph_paths = [path for path in selected_paths
if self.stage.GetPrimAtPath(path).GetTypeName() == "ComputeGraph"]
if len(graph_paths) > 0:
graph = ogc.get_graph_by_path(graph_paths[0])
if len(graph_paths) > 1:
carb.log_warn(f"Multiple ComputeGraph prims selected. Only the first will be used: {graph.get_path_to_graph()}")
elif create_new_graph:
# If no graph was found in the selected prims, we'll make a new graph.
graph_path = Sdf.Path(f"/OmniGraph/{self.particle_system_name}").MakeAbsolutePath(Sdf.Path.absoluteRootPath)
graph_path = ou.get_stage_next_free_path(self.stage, graph_path, True)
# prim = self.stage.GetDefaultPrim()
# path = str(prim.GetPath()) if prim else ""
self.stage.DefinePrim("/OmniGraph", "Scope")
container_graphs = ogc.get_global_container_graphs()
# FIXME: container_graphs[0] should be the simulation orchestration graph, but this may change in the future.
container_graph = container_graphs[0]
result, wrapper_node = ogc.cmds.CreateGraphAsNode(
graph=container_graph,
node_name=Sdf.Path(graph_path).name,
graph_path=graph_path,
evaluator_name="push",
is_global_graph=True,
backed_by_usd=True,
fc_backing_type=ogc.GraphBackingType.GRAPH_BACKING_TYPE_FLATCACHE_SHARED,
pipeline_stage=ogc.GraphPipelineStage.GRAPH_PIPELINE_STAGE_SIMULATION
)
graph = wrapper_node.get_wrapped_graph()
if created_paths is not None:
created_paths.append(graph.get_path_to_graph())
carb.log_info(f"No ComputeGraph selected. A new graph has been created at {graph.get_path_to_graph()}")
return graph
|