Collider_PxMeshNotAutoAssignedWhenNoPhysicsFbx.py 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 : C14861504
  6. Test Case Title : Verify if Rendering Mesh does not have a PhysX Collision Mesh fbx, then PxMesh is not auto-assigned
  7. """
  8. # fmt: off
  9. class Tests():
  10. create_entity = ("Created test entity", "Failed to create test entity")
  11. mesh_added = ("Added Mesh component", "Failed to add Mesh component")
  12. physx_collider_added = ("Added PhysX Mesh Collider component", "Failed to add PhysX Mesh Collider component")
  13. assign_model_asset = ("Assigned Model asset to Mesh component", "Failed to assign model asset to Mesh component")
  14. shape_not_assigned = ("Shape is not auto assigned", "Shape auto assigned unexpectedly")
  15. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  16. warnings_found = ("Warnings found in logs", "No warnings found in logs")
  17. # fmt: on
  18. def Collider_PxMeshNotAutoAssignedWhenNoPhysicsFbx():
  19. """
  20. Summary:
  21. Create entity with Mesh component and assign a render mesh that has no physics asset to the Mesh component.
  22. Add Physics Mesh Collider component and Verify that the physics mesh asset is not auto-assigned.
  23. Expected Behavior:
  24. Following warning is logged in Game mode:
  25. "(PhysX) - EditorMeshColliderComponent::BuildGameEntity. No asset assigned to Collider Component. Entity: <Entity Name>"
  26. Test Steps:
  27. 1) Load the empty level
  28. 2) Create an entity
  29. 3) Add Mesh component
  30. 4) Assign a render model asset to Mesh component (the fbx mesh having only Static mesh and no PxMesh)
  31. 5) Add PhysX Mesh Collider component
  32. 6) The physics asset in PhysX Mesh Collider component is not auto-assigned.
  33. 7) Enter GameMode and check for warnings
  34. Note:
  35. - This test file must be called from the Open 3D Engine Editor command terminal
  36. - Any passed and failed tests are written to the Editor.log file.
  37. Parsing the file or running a log_monitor are required to observe the test results.
  38. :return: None
  39. """
  40. # Builtins
  41. import os
  42. # Helper Files
  43. from editor_python_test_tools.editor_entity_utils import EditorEntity as Entity
  44. from editor_python_test_tools.utils import Report
  45. from editor_python_test_tools.utils import TestHelper as helper
  46. from editor_python_test_tools.utils import Tracer
  47. from editor_python_test_tools.asset_utils import Asset
  48. from consts.physics import PHYSX_MESH_COLLIDER
  49. import editor_python_test_tools.hydra_editor_utils as hydra
  50. # Open 3D Engine Imports
  51. import azlmbr.asset as azasset
  52. # Asset paths
  53. STATIC_MESH = os.path.join("assets", "Physics", "Collider_PxMeshNotAutoAssignedWhenNoPhysicsFbx", "test_asset.fbx.azmodel")
  54. # 1) Load the empty level
  55. hydra.open_base_level()
  56. # 2) Create an entity
  57. test_entity = Entity.create_editor_entity("test_entity")
  58. test_entity.add_component("PhysX Static Rigid Body")
  59. Report.result(Tests.create_entity, test_entity.id.IsValid())
  60. # 3) Add Mesh component
  61. mesh_component = test_entity.add_component("Mesh")
  62. Report.result(Tests.mesh_added, test_entity.has_component("Mesh"))
  63. # 4) Assign a render model asset to Mesh component (the fbx mesh having both Static mesh and PhysX collision Mesh)
  64. model_asset = Asset.find_asset_by_path(STATIC_MESH)
  65. mesh_component.set_component_property_value("Controller|Configuration|Model Asset", model_asset.id)
  66. model_asset.id = mesh_component.get_component_property_value("Controller|Configuration|Model Asset")
  67. Report.result(Tests.assign_model_asset, model_asset.get_path().lower() == STATIC_MESH.replace(os.sep, "/").lower())
  68. # 5) Add PhysX Mesh Collider component
  69. test_component = test_entity.add_component(PHYSX_MESH_COLLIDER)
  70. Report.result(Tests.physx_collider_added, test_entity.has_component(PHYSX_MESH_COLLIDER))
  71. # 6) The physics asset in PhysX Mesh Collider component is not auto-assigned.
  72. asset_id = test_component.get_component_property_value("Shape Configuration|Asset|PhysX Mesh")
  73. # Comparing asset_id with Null/Invalid asset azlmbr.asset.AssetId() to check that asset is not auto assigned
  74. Report.result(Tests.shape_not_assigned, asset_id == azasset.AssetId())
  75. # 7) Enter GameMode and check for warnings
  76. with Tracer() as section_tracer:
  77. helper.enter_game_mode(Tests.enter_game_mode)
  78. # Checking if warning exist and the exact warning is caught in the expected lines in Test file
  79. Report.result(Tests.warnings_found, section_tracer.has_warnings)
  80. if __name__ == "__main__":
  81. from editor_python_test_tools.utils import Report
  82. Report.start_test(Collider_PxMeshNotAutoAssignedWhenNoPhysicsFbx)