C4982803_Enable_PxMesh_Option.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. Test case ID : C4982803
  6. Test Case Title : Verify that when the shape Physics Asset is selected,
  7. PxMesh option gets enabled and a Px Mesh can be selected and assigned to the object
  8. """
  9. # fmt: off
  10. class Tests():
  11. create_collider_entity = ("Entity created successfully", "Failed to create Entity")
  12. mesh_added = ("Added Mesh component", "Failed to add Mesh component")
  13. physx_collider_added = ("Added PhysX Collider component", "Failed to add PhysX Collider component")
  14. physx_rigid_body_added = ("Added PhysX Rigid Body component", "Failed to add PhysX Rigid Body component")
  15. add_physics_asset_shape = ("Added shape as physics asset", "Failed to add shape ")
  16. assign_fbx_mesh = ("Assigned fbx mesh", "Failed to assign fbx mesh")
  17. create_terrain = ("Terrain entity created successfully", "Failed to create Terrain Entity")
  18. add_physx_shape_collider = ("Added PhysX Shape Collider", "Failed to add PhysX Shape Collider")
  19. add_box_shape = ("Added Box Shape", "Failed to add Box Shape")
  20. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  21. exit_game_mode = ("Exited game mode", "Failed to exit game mode")
  22. test_collision = ("Entity collided with terrain", "Failed to collide with terrain")
  23. # fmt: on
  24. def C4982803_Enable_PxMesh_Option():
  25. """
  26. Summary:
  27. Load level with Entity above ground having PhysX Collider, PhysX Rigid Body and Mesh components.
  28. Verify that the entity falls on the ground and collides with the terrain when fbx convex mesh is added to collider.
  29. Expected Behavior:
  30. The entity falls on the ground and collides with the terrain.
  31. Test Steps:
  32. 1) Load the level
  33. 2) Create test entity above the ground
  34. 3) Add PhysX Collider, PhysX Rigid Body and Mesh components.
  35. 4) Add the Shape as PhysicsAsset and select fbx convex mesh in PhysX Collider component.
  36. 5) Create terrain entity with physx terrain
  37. 6) Enter game mode
  38. 7) Verify that the entity falls on the ground and collides with the terrain.
  39. Note:
  40. - This test file must be called from the Open 3D Engine Editor command terminal
  41. - Any passed and failed tests are written to the Editor.log file.
  42. Parsing the file or running a log_monitor are required to observe the test results.
  43. :return: None
  44. """
  45. # Builtins
  46. import os
  47. # Helper Files
  48. import ImportPathHelper as imports
  49. imports.init()
  50. from editor_python_test_tools.editor_entity_utils import EditorEntity
  51. from editor_python_test_tools.utils import Report
  52. from editor_python_test_tools.utils import TestHelper as helper
  53. from asset_utils import Asset
  54. import azlmbr.math as math
  55. # Open 3D Engine Imports
  56. import azlmbr
  57. import azlmbr.legacy.general as general
  58. # Constants
  59. PHYSICS_ASSET_INDEX = 7 # Hardcoded enum index value for Shape property
  60. MESH_ASSET_PATH = os.path.join("assets", "c4982803_enable_pxmesh_option", "spherebot", "r0-b_body.pxmesh")
  61. TIMEOUT = 2.0
  62. helper.init_idle()
  63. # 1) Load the level
  64. helper.open_level("Physics", "Base")
  65. # 2) Create test entity
  66. collider = EditorEntity.create_editor_entity_at([512.0, 512.0, 33.0], "Collider")
  67. Report.result(Tests.create_collider_entity, collider.id.IsValid())
  68. # 3) Add PhysX Collider, PhysX Rigid Body and Mesh components.
  69. collider_component = collider.add_component("PhysX Collider")
  70. Report.result(Tests.physx_collider_added, collider.has_component("PhysX Collider"))
  71. collider.add_component("PhysX Rigid Body")
  72. Report.result(Tests.physx_rigid_body_added, collider.has_component("PhysX Rigid Body"))
  73. collider.add_component("Mesh")
  74. Report.result(Tests.mesh_added, collider.has_component("Mesh"))
  75. # 4) Add the Shape as PhysicsAsset and select fbx convex mesh in PhysX Collider component.
  76. collider_component.set_component_property_value("Shape Configuration|Shape", PHYSICS_ASSET_INDEX)
  77. value_to_test = collider_component.get_component_property_value("Shape Configuration|Shape")
  78. Report.result(Tests.add_physics_asset_shape, value_to_test == PHYSICS_ASSET_INDEX)
  79. mesh_asset = Asset.find_asset_by_path(MESH_ASSET_PATH)
  80. collider_component.set_component_property_value("Shape Configuration|Asset|PhysX Mesh", mesh_asset.id)
  81. mesh_asset.id = collider_component.get_component_property_value("Shape Configuration|Asset|PhysX Mesh")
  82. Report.result(Tests.assign_fbx_mesh, mesh_asset.get_path() == MESH_ASSET_PATH.replace(os.sep, "/"))
  83. # 5) Create terrain entity with physx terrain
  84. terrain = EditorEntity.create_editor_entity_at([512.0, 512.0, 31.0], "Terrain")
  85. Report.result(Tests.create_terrain, terrain.id.IsValid())
  86. terrain.add_component("PhysX Shape Collider")
  87. Report.result(Tests.add_physx_shape_collider, terrain.has_component("PhysX Shape Collider"))
  88. box_shape_component = terrain.add_component("Box Shape")
  89. Report.result(Tests.add_box_shape, terrain.has_component("Box Shape"))
  90. box_shape_component.set_component_property_value("Box Shape|Box Configuration|Dimensions",
  91. math.Vector3(1024.0, 1024.0, 1.0))
  92. # 6) Enter game mode
  93. helper.enter_game_mode(Tests.enter_game_mode)
  94. # 7) Verify that the entity falls on the ground and collides with the terrain
  95. class Collider:
  96. id = general.find_game_entity("Collider")
  97. touched_ground = False
  98. terrain_id = general.find_game_entity("Terrain")
  99. def on_collision_begin(args):
  100. other_id = args[0]
  101. if other_id.Equal(terrain_id):
  102. Report.info("Touched ground")
  103. Collider.touched_ground = True
  104. handler = azlmbr.physics.CollisionNotificationBusHandler()
  105. handler.connect(Collider.id)
  106. handler.add_callback("OnCollisionBegin", on_collision_begin)
  107. helper.wait_for_condition(lambda: Collider.touched_ground, TIMEOUT)
  108. Report.result(Tests.test_collision, Collider.touched_ground)
  109. # 8) Exit game mode
  110. helper.exit_game_mode(Tests.exit_game_mode)
  111. if __name__ == "__main__":
  112. import ImportPathHelper as imports
  113. imports.init()
  114. from editor_python_test_tools.utils import Report
  115. Report.start_test(C4982803_Enable_PxMesh_Option)