ScriptCanvas_PostPhysicsUpdate.py 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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 : C14902098
  7. # Test Case Title : Check that force region simulation with Postsimulate works independently from rendering tick
  8. # fmt: off
  9. class Tests():
  10. enter_game_mode = ("Entered game mode", "Failed to enter game mode")
  11. find_sphere = ("Sphere found", "Sphere not found")
  12. find_force_region = ("Force Region is found", "Force Region is not found")
  13. exit_game_mode = ("Exited game mode", "Couldn't exit game mode")
  14. # fmt: on
  15. class LogLines:
  16. """
  17. These lines are added to the expected lines in the test suite.
  18. """
  19. expected_lines = [
  20. "OnTick Event: The Sphere position did not change from previous position",
  21. "OnTick Event: The Sphere position changed from previous position",
  22. "OnPostPhysicsSubtick Event: The Sphere position changed from previous position",
  23. ]
  24. unexpected_lines = ["OnPostPhysicsSubtick Event: The Sphere position did not change from previous position"]
  25. def ScriptCanvas_PostPhysicsUpdate():
  26. """
  27. Summary:
  28. Check that force region simulation with Postsimulate works independently from rendering tick.
  29. Level Description:
  30. A Sphere is placed inside a Force Region. The "Fixed Time Step" in PhysX Configuration is set to 0.05.
  31. ForceRegion (entity) - Entity with PhysX Collider, PhysX Force Region (World Space force with magnitude 5.0) and
  32. Box Shape components
  33. Sphere (entity) - Entity with PhysX Rigid Body, PhysX Collider, Mesh and 2 Script Canvas components
  34. Script Canvas:
  35. onpostphysicsupdate - The script checks the position of the sphere on every On Postsimulate event and prints
  36. debug statements as per the position of the sphere relative to its previous position.
  37. ontick - The script checks the position of the sphere on every On Tick event and prints
  38. debug statements as per the position of the sphere relative to its previous position.
  39. Expected Behavior:
  40. The position of the sphere needs to be changed relative to its previous position for every
  41. OnPostPhysicsSubtick event.
  42. The position of the sphere sometimes change and sometimes remains in the same position as before
  43. for OnTick event.
  44. Test Steps:
  45. 1) Open level
  46. 2) Enter game mode
  47. 3) Retrieve and validate entities
  48. 4) Wait for WAIT_TIME for the events to occur
  49. 5) Exit game mode
  50. 6) Close the editor
  51. Note:
  52. - This test file must be called from the Open 3D Engine Editor command terminal
  53. - Any passed and failed tests are written to the Editor.log file.
  54. Parsing the file or running a log_monitor are required to observe the test results.
  55. :return: None
  56. """
  57. import os
  58. import sys
  59. from editor_python_test_tools.utils import Report
  60. from editor_python_test_tools.utils import TestHelper as helper
  61. import azlmbr.legacy.general as general
  62. # Constants
  63. WAIT_TIME = 0.5
  64. helper.init_idle()
  65. # 1) Open level
  66. helper.open_level("Physics", "ScriptCanvas_PostPhysicsUpdate")
  67. # 2) Enter game mode
  68. helper.enter_game_mode(Tests.enter_game_mode)
  69. # 3) Retrieve and validate entities
  70. sphere_id = general.find_game_entity("Sphere")
  71. Report.critical_result(Tests.find_sphere, sphere_id.IsValid())
  72. force_region_id = general.find_game_entity("ForceRegion")
  73. Report.critical_result(Tests.find_force_region, force_region_id.IsValid())
  74. # 4) Wait for WAIT_TIME for the events to occur
  75. general.idle_wait(WAIT_TIME)
  76. # 5) Exit game mode
  77. helper.exit_game_mode(Tests.exit_game_mode)
  78. if __name__ == "__main__":
  79. from editor_python_test_tools.utils import Report
  80. Report.start_test(ScriptCanvas_PostPhysicsUpdate)