scene_export_utils.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #
  2. # Copyright (c) Contributors to the Open 3D Engine Project.
  3. # For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. import traceback, sys, uuid, os, json
  9. #
  10. # Utility methods for processing scenes
  11. #
  12. def log_exception_traceback():
  13. exc_type, exc_value, exc_tb = sys.exc_info()
  14. data = traceback.format_exception(exc_type, exc_value, exc_tb)
  15. print(str(data))
  16. def get_node_names(sceneGraph, nodeTypeName, testEndPoint = False, validList = None):
  17. import azlmbr.scene.graph
  18. import scene_api.scene_data
  19. node = sceneGraph.get_root()
  20. nodeList = []
  21. children = []
  22. paths = []
  23. while node.IsValid():
  24. # store children to process after siblings
  25. if sceneGraph.has_node_child(node):
  26. children.append(sceneGraph.get_node_child(node))
  27. nodeName = scene_api.scene_data.SceneGraphName(sceneGraph.get_node_name(node))
  28. paths.append(nodeName.get_path())
  29. include = True
  30. if (validList is not None):
  31. include = False # if a valid list filter provided, assume to not include node name
  32. name_parts = nodeName.get_path().split('.')
  33. for valid in validList:
  34. if (valid in name_parts[-1]):
  35. include = True
  36. break
  37. # store any node that has provides specifc data content
  38. nodeContent = sceneGraph.get_node_content(node)
  39. if include and nodeContent.CastWithTypeName(nodeTypeName):
  40. if testEndPoint is not None:
  41. include = sceneGraph.is_node_end_point(node) is testEndPoint
  42. if include:
  43. if (len(nodeName.get_path())):
  44. nodeList.append(scene_api.scene_data.SceneGraphName(sceneGraph.get_node_name(node)))
  45. # advance to next node
  46. if sceneGraph.has_node_sibling(node):
  47. node = sceneGraph.get_node_sibling(node)
  48. elif children:
  49. node = children.pop()
  50. else:
  51. node = azlmbr.scene.graph.NodeIndex()
  52. return nodeList, paths