hydra_SubID_NoChange_MeshChanged.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. import assetpipeline.ap_fixtures.ap_idle_fixture
  7. class Tests:
  8. asset_id_no_change = (
  9. "Model AssetId matches after changes",
  10. "P0: Model AssetId does not match expected output")
  11. def SubID_NoChange_MeshChanged():
  12. """
  13. Summary:
  14. Opens a level with an entity containing a mesh component.
  15. Verify updating a scene file where the product's asset subid remains the same still updates the mesh component.
  16. Expected Behavior:
  17. The updated asset's subid remains the same while the mesh referenced in the mesh component updates.
  18. Test Steps:
  19. 1) Load the level
  20. 2) Start the Tracer to catch any errors and warnings
  21. 3) Record the original asset's subid and vert count
  22. 4) Add a scene settings file to update the scene products
  23. 5) Reload the level
  24. 6) Record the updated asset's subid and vert count
  25. 7) Verify there are no errors and warnings in the logs
  26. 8) Verify the subids match while the vert counts do not
  27. 9) Close the editor
  28. :return: None
  29. """
  30. import os
  31. import shutil
  32. import time
  33. from pathlib import Path
  34. import azlmbr.bus
  35. import azlmbr.editor as editor
  36. from Atom.atom_utils.atom_constants import AtomComponentProperties
  37. from EditorPythonTestTools.editor_python_test_tools.editor_entity_utils import EditorEntity
  38. from EditorPythonTestTools.editor_python_test_tools.utils import Report, TestHelper, Tracer
  39. from EditorPythonTestTools.editor_python_test_tools.asset_utils import Asset
  40. from assetpipeline.ap_fixtures.check_model_ready_fixture import OnModelReloaded
  41. with Tracer() as error_tracer:
  42. # -- Test Setup Begins --
  43. # Test Setup: Wait for Editor idle before loading the level and executing python hydra scripts.
  44. TestHelper.init_idle()
  45. TestHelper.open_level("AssetPipeline", "SceneTests")
  46. # Test Setup: Set source and destination paths for assetinfo file.
  47. dirpath = editor.EditorToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'GetGameFolder')
  48. src = os.path.join(dirpath, 'Objects', 'ShaderBall_simple', 'shaderball_simple_MeshChange_SameID.fbx.assetinfo')
  49. dst = os.path.join(dirpath, 'Objects', 'shaderball_simple.fbx.assetinfo')
  50. # Test Setup: Find the asset by asset path
  51. model_path = os.path.join('objects', 'shaderball_simple.fbx.azmodel')
  52. model = Asset.find_asset_by_path(model_path)
  53. # Test Setup: Ensure there is no assetinfo file in the dst path, if there is, remove it.
  54. checkModel = OnModelReloaded()
  55. if os.path.exists(dst):
  56. os.remove(dst)
  57. checkModel.wait_for_on_model_reloaded(model.id)
  58. # Test Setup: Find the entity, and it's mesh component, within the level.
  59. find_entity = EditorEntity.find_editor_entity(AtomComponentProperties.mesh())
  60. find_component = find_entity.get_components_of_type([AtomComponentProperties.mesh()])[0]
  61. #Test Setup: Record the initial values for the Model Asset and the Vertex Count of LOD0.
  62. original_component_id = find_component.get_component_property_value(AtomComponentProperties.mesh('Model Asset'))
  63. original_vert_count = find_component.get_component_property_value(AtomComponentProperties.mesh('Vertex Count LOD0'))
  64. # -- Test Begins --
  65. # 1. Copy an assetinfo file to change scene output.
  66. shutil.copyfile(src, dst)
  67. checkModel.wait_for_on_model_reloaded(model.id)
  68. # 2. Reload the level to reflect changes.
  69. TestHelper.open_level("", "Base")
  70. time.sleep(0.2)
  71. TestHelper.open_level("AssetPipeline", "SceneTests")
  72. time.sleep(0.2)
  73. # 3. Record the current values for the Model Asset and the Vertex Count of LOD0.
  74. current_component_id = find_component.get_component_property_value(AtomComponentProperties.mesh('Model Asset'))
  75. current_vert_count = find_component.get_component_property_value(AtomComponentProperties.mesh('Vertex Count LOD0'))
  76. result = current_component_id == original_component_id and original_vert_count != current_vert_count
  77. # 4. Look for errors or asserts.
  78. TestHelper.wait_for_condition(lambda: error_tracer.has_errors or error_tracer.has_asserts, 1.0)
  79. for error_info in error_tracer.errors:
  80. Report.info(f"Error: {error_info.filename} {error_info.function} | {error_info.message}")
  81. for assert_info in error_tracer.asserts:
  82. Report.info(f"Assert: {assert_info.filename} {assert_info.function} | {assert_info.message}")
  83. # 5. Clean-up.
  84. os.remove(dst)
  85. checkModel.wait_for_on_model_reloaded(model.id)
  86. # 6. Report the test results gathered and end the test.
  87. Report.critical_result(Tests.asset_id_no_change, result)
  88. if __name__ == "__main__":
  89. from editor_python_test_tools.utils import Report
  90. Report.start_test(SubID_NoChange_MeshChanged)