test_chunks_builder.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. SPDX-License-Identifier: Apache-2.0 OR MIT
  5. """
  6. import azlmbr.scene as sceneApi
  7. from scene_api import scene_data as sceneData
  8. import uuid
  9. def update_manifest(scene):
  10. graph = sceneData.SceneGraph(scene.graph)
  11. rootNode = graph.get_root()
  12. kidNode = graph.get_node_child(rootNode)
  13. chunkNameList = []
  14. siblingNode = graph.get_node_child(kidNode)
  15. while siblingNode.IsValid():
  16. chunkGraphName = sceneData.SceneGraphName(graph.get_node_name(siblingNode))
  17. chunkName = chunkGraphName.get_name()
  18. chunkNameList.append(chunkName)
  19. siblingNode = graph.get_node_sibling(siblingNode)
  20. sceneManifest = sceneData.SceneManifest()
  21. for activeMeshIndex in range(len(chunkNameList)):
  22. chunkName = chunkNameList[activeMeshIndex]
  23. meshGroup = sceneManifest.add_mesh_group(chunkName)
  24. meshGroup['id'] = '{' + str(uuid.uuid5(uuid.NAMESPACE_DNS, scene.sourceFilename + chunkName)) + '}'
  25. sceneManifest.mesh_group_add_comment(meshGroup, 'auto generated by test_chunks_builder')
  26. sceneManifest.mesh_group_add_advanced_coordinate_system(meshGroup)
  27. for meshIndex in range(len(chunkNameList)):
  28. if (activeMeshIndex == meshIndex):
  29. sceneManifest.mesh_group_select_node(meshGroup, chunkNameList[meshIndex])
  30. else:
  31. sceneManifest.mesh_group_unselect_node(meshGroup, chunkNameList[meshIndex])
  32. return sceneManifest.export()
  33. mySceneJobHandler = None
  34. def on_update_manifest(args):
  35. scene = args[0]
  36. result = update_manifest(scene)
  37. global mySceneJobHandler
  38. # do not delete or set sceneJobHandler to None, just disconnect from it.
  39. # this call is occuring while the scene Job Handler itself is in the callstack, so deleting it here
  40. # would cause a crash.
  41. mySceneJobHandler.disconnect()
  42. return result
  43. def main():
  44. global mySceneJobHandler
  45. mySceneJobHandler = sceneApi.ScriptBuildingNotificationBusHandler()
  46. mySceneJobHandler.connect()
  47. mySceneJobHandler.add_callback('OnUpdateManifest', on_update_manifest)
  48. if __name__ == "__main__":
  49. main()