WhiteBox_SetDefaultShape.py 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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. # Test case ID : C29279329
  7. # Test Case Title : White Box mesh shape can be changed with the Default Shape dropdown on the Component
  8. # fmt:off
  9. class Tests():
  10. default_shape_cube = ("Default shape set to cube", "Default shape is not set to cube")
  11. default_shape_tetrahedron = ("Default shape changed to tetrahedron", "Failed to change default shape to tetrahedron")
  12. default_shape_icosahedron = ("Default shape changed to icosahedron", "Failed to change default shape to icosahedron")
  13. default_shape_cylinder = ("Default shape changed to cylinder", "Failed to change default shape to cylinder")
  14. default_shape_sphere = ("Default shape changed to sphere", "Failed to change default shape to sphere")
  15. # fmt:on
  16. critical_shape_check = ("Default shape has more than 0 sides", "default shape has 0 sides")
  17. def C29279329_WhiteBox_SetDefaultShape():
  18. import azlmbr.bus as bus
  19. import editor_python_test_tools.hydra_editor_utils as hydra
  20. import WhiteBoxInit as init
  21. from editor_python_test_tools.utils import Report
  22. def check_shape_result(success_fail_tuple, condition):
  23. result = Report.result(success_fail_tuple, condition)
  24. if not result:
  25. face_count = white_box_handle.MeshFaceCount()
  26. Report.critical_result(critical_shape_check, face_count > 0)
  27. Report.info(f"Face count = {face_count}")
  28. shape_types = azlmbr.globals.property
  29. # expected results
  30. expected_results = {
  31. shape_types.CUBE: 12,
  32. shape_types.TETRAHEDRON: 4,
  33. shape_types.ICOSAHEDRON: 20,
  34. shape_types.CYLINDER: 64,
  35. shape_types.SPHERE: 320
  36. }
  37. # open level
  38. hydra.open_base_level()
  39. # create white box entity and attach component
  40. white_box_entity = init.create_white_box_entity()
  41. white_box_mesh_component = init.create_white_box_component(white_box_entity)
  42. white_box_handle = init.create_white_box_handle(white_box_mesh_component)
  43. # verify results
  44. # cube
  45. check_shape_result(
  46. Tests.default_shape_cube,
  47. white_box_handle.MeshFaceCount() == expected_results.get(shape_types.CUBE))
  48. # tetrahedron
  49. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(
  50. bus.Event, 'SetDefaultShape', white_box_mesh_component, shape_types.TETRAHEDRON)
  51. check_shape_result(
  52. Tests.default_shape_tetrahedron,
  53. white_box_handle.MeshFaceCount() == expected_results.get(shape_types.TETRAHEDRON))
  54. # icosahedron
  55. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(
  56. bus.Event, 'SetDefaultShape', white_box_mesh_component, shape_types.ICOSAHEDRON)
  57. check_shape_result(
  58. Tests.default_shape_icosahedron,
  59. white_box_handle.MeshFaceCount() == expected_results.get(shape_types.ICOSAHEDRON))
  60. # cylinder
  61. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(
  62. bus.Event, 'SetDefaultShape', white_box_mesh_component, shape_types.CYLINDER)
  63. check_shape_result(
  64. Tests.default_shape_cylinder,
  65. white_box_handle.MeshFaceCount() == expected_results.get(shape_types.CYLINDER))
  66. # sphere
  67. azlmbr.whitebox.request.bus.EditorWhiteBoxComponentRequestBus(
  68. bus.Event, 'SetDefaultShape', white_box_mesh_component, shape_types.SPHERE)
  69. check_shape_result(
  70. Tests.default_shape_sphere,
  71. white_box_handle.MeshFaceCount() == expected_results.get(shape_types.SPHERE))
  72. if __name__ == "__main__":
  73. from editor_python_test_tools.utils import Report
  74. Report.start_test(C29279329_WhiteBox_SetDefaultShape)