Collider_MultipleSurfaceSlots.py 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  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 : C4044695
  6. Test Case Title : Verify that when you add a multiple surface fbx in PxMesh in PhysxMeshCollider,
  7. multiple number of Material Slots populate in the Materials Section
  8. """
  9. # fmt: off
  10. class Tests():
  11. create_entity = ("Created test entity", "Failed to create test entity")
  12. mesh_added = ("Added Mesh component", "Failed to add Mesh component")
  13. physx_collider_added = ("Added PhysX Mesh Collider component", "Failed to add PhysX Mesh Collider component")
  14. assign_model_asset = ("Assigned Model asset to Mesh component", "Failed to assign model asset to Mesh component")
  15. assign_px_mesh_asset = ("Assigned PxMesh asset to Collider component", "Failed to assign PxMesh asset to Collider component")
  16. count_mesh_surface = ("Multiple slots show under materials", "Failed to show required surface materials")
  17. # fmt: on
  18. def Collider_MultipleSurfaceSlots():
  19. """
  20. Summary:
  21. Create entity with Mesh and PhysX Mesh Collider components and assign a fbx file in both the components.
  22. Verify that the fbx is properly fitting the mesh.
  23. Expected Behavior:
  24. 1) The fbx is properly fitting the mesh.
  25. 2) Multiple material slots show up under Materials section in the PhysX Mesh Collider component and that
  26. they correspond to the number of surfaces as designed in the mesh.
  27. Test Steps:
  28. 1) Load the empty level
  29. 2) Create an entity
  30. 3) Add Mesh and Physics collider components
  31. 4) Assign the fbx file in PhysX Mesh and Mesh component
  32. 5) Check if multiple material slots show up under Materials section in the PhysX Mesh Collider component
  33. :return: None
  34. """
  35. # Builtins
  36. import os
  37. # Helper Files
  38. from editor_python_test_tools.editor_entity_utils import EditorEntity as Entity
  39. from editor_python_test_tools.utils import Report
  40. from editor_python_test_tools.utils import TestHelper as helper
  41. from editor_python_test_tools.asset_utils import Asset
  42. from consts.physics import PHYSX_MESH_COLLIDER
  43. import editor_python_test_tools.hydra_editor_utils as hydra
  44. # Constants
  45. SURFACE_TAG_COUNT = 4 # Number of surface tags included in used asset
  46. # Asset paths
  47. STATIC_MESH = os.path.join("assets", "Physics", "Collider_MultipleSurfaceSlots", "test.fbx.azmodel")
  48. PHYSX_MESH = os.path.join("assets", "Physics","Collider_MultipleSurfaceSlots", "test.fbx.pxmesh")
  49. # 1) Load the empty level
  50. hydra.open_base_level()
  51. # 2) Create an entity
  52. test_entity = Entity.create_editor_entity("test_entity")
  53. test_entity.add_component("PhysX Static Rigid Body")
  54. Report.result(Tests.create_entity, test_entity.id.IsValid())
  55. # 3) Add Mesh and Physics Mesh Collider components
  56. mesh_component = test_entity.add_component("Mesh")
  57. Report.result(Tests.mesh_added, test_entity.has_component("Mesh"))
  58. collider_component = test_entity.add_component(PHYSX_MESH_COLLIDER)
  59. Report.result(Tests.physx_collider_added, test_entity.has_component(PHYSX_MESH_COLLIDER))
  60. # 4) Assign the fbx file in PhysX Mesh and Mesh component
  61. px_asset = Asset.find_asset_by_path(PHYSX_MESH)
  62. collider_component.set_component_property_value("Shape Configuration|Asset|PhysX Mesh", px_asset.id)
  63. px_asset.id = collider_component.get_component_property_value("Shape Configuration|Asset|PhysX Mesh")
  64. Report.result(Tests.assign_px_mesh_asset, px_asset.get_path().lower() == PHYSX_MESH.replace(os.sep, "/").lower())
  65. model_asset = Asset.find_asset_by_path(STATIC_MESH)
  66. mesh_component.set_component_property_value("Controller|Configuration|Model Asset", model_asset.id)
  67. model_asset.id = mesh_component.get_component_property_value("Controller|Configuration|Model Asset")
  68. Report.result(Tests.assign_model_asset, model_asset.get_path().lower() == STATIC_MESH.replace(os.sep, "/").lower())
  69. # 5) Check if multiple material slots show up under Materials section in the PhysX Mesh Collider component
  70. pte = collider_component.get_property_tree()
  71. def get_surface_count():
  72. count = pte.get_container_count("Collider Configuration|Physics Materials|Slots")
  73. return count.GetValue()
  74. Report.result(
  75. Tests.count_mesh_surface, helper.wait_for_condition(lambda: get_surface_count() == SURFACE_TAG_COUNT, 1.0)
  76. )
  77. if __name__ == "__main__":
  78. from editor_python_test_tools.utils import Report
  79. Report.start_test(Collider_MultipleSurfaceSlots)