MaterialProperty_ProcPrefabWorks.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. def ReportError(msg):
  7. from editor_python_test_tools.utils import Report
  8. Report.result(msg, False)
  9. raise Exception(msg)
  10. def MaterialProperty_ProcPrefabWorks():
  11. # Description: the AutomatedTesting\Assets\ap_test_assets\default_mat.fbx
  12. # source asset should produce a procedural prefab named
  13. # 'assets/ap_test_assets/default_mat_fbx.procprefab' which is a JSON
  14. # file. In that JSON file, there should be a field named 'assetHint' and
  15. # have the value 'gem/sponza/assets/objects/sponza_mat_bricks.azmaterial'
  16. # This test validates these data points.
  17. from editor_python_test_tools.utils import Report
  18. from editor_python_test_tools.utils import TestHelper
  19. import azlmbr.legacy.general
  20. import azlmbr.prefab
  21. import json
  22. # Required for automated tests
  23. TestHelper.init_idle()
  24. # Open the test level
  25. TestHelper.open_level(directory="", level="Base")
  26. azlmbr.legacy.general.idle_wait_frames(1)
  27. templateId = azlmbr.prefab.LoadTemplate('assets/ap_test_assets/default_mat_fbx.procprefab')
  28. jsonTemplate = azlmbr.prefab.SaveTemplateToString(templateId)
  29. if (len(jsonTemplate) == 0):
  30. ReportError('Could not load JSON template for default_mat_fbx.procprefab')
  31. foundItems = []
  32. def find_azmaterial(d, foundItems):
  33. a_list = d.items() if isinstance(d, dict) else enumerate(d)
  34. for k, v in a_list:
  35. if isinstance(v, dict) or isinstance(v, list):
  36. find_azmaterial(v, foundItems)
  37. elif (k == 'assetHint' and v == 'gem/sponza/assets/objects/sponza_mat_bricks.azmaterial'):
  38. foundItems.append(True)
  39. find_azmaterial(json.loads(jsonTemplate), foundItems)
  40. if (len(foundItems) == 0):
  41. ReportError('Could not find material asset in prefab template')
  42. # all tests worked
  43. Report.result("Found the expected fields in the default_mat_fbx.procprefab", True)
  44. if __name__ == "__main__":
  45. from editor_python_test_tools.utils import Report
  46. Report.start_test(MaterialProperty_ProcPrefabWorks)