script_reinsert.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. #
  5. # SPDX-License-Identifier: Apache-2.0 OR MIT
  6. #
  7. #
  8. sceneJobHandler = None
  9. def clear_sceneJobHandler():
  10. global sceneJobHandler
  11. # do not delete or set sceneJobHandler to None, just disconnect from it.
  12. # this call is occuring while the scene Job Handler itself is in the callstack, so deleting it here
  13. # would cause a crash.
  14. sceneJobHandler.disconnect()
  15. def on_prepare_for_export(args):
  16. print (f'on_prepare_for_export')
  17. import azlmbr.scene
  18. import azlmbr.object
  19. import azlmbr.paths
  20. import json, os
  21. import azlmbr.math
  22. scene = args[0] # azlmbr.scene.Scene
  23. outputDirectory = args[1] # string
  24. # write out a fake export product asset so that it can be found and tested
  25. jsonFilename = os.path.basename(scene.sourceFilename)
  26. jsonFilename = os.path.join(outputDirectory, jsonFilename + '.fake_asset')
  27. # prepare output folder
  28. basePath, _ = os.path.split(jsonFilename)
  29. outputPath = os.path.join(outputDirectory, basePath)
  30. if not os.path.exists(outputPath):
  31. os.makedirs(outputPath, False)
  32. # write out a JSON file
  33. with open(jsonFilename, "w") as jsonFile:
  34. jsonFile.write("{}")
  35. clear_sceneJobHandler()
  36. exportProduct = azlmbr.scene.ExportProduct()
  37. exportProduct.filename = jsonFilename
  38. exportProduct.sourceId = scene.sourceGuid
  39. exportProduct.subId = 2
  40. exportProductList = azlmbr.scene.ExportProductList()
  41. exportProductList.AddProduct(exportProduct)
  42. return exportProductList
  43. def on_update_manifest(args):
  44. print (f'on_update_manifest')
  45. data = """{
  46. "values": [
  47. {
  48. "$type": "{07B356B7-3635-40B5-878A-FAC4EFD5AD86} MeshGroup",
  49. "name": "fake",
  50. "nodeSelectionList": { "selectedNodes": ["RootNode"] }
  51. }
  52. ]
  53. }"""
  54. clear_sceneJobHandler()
  55. return data
  56. # try to create SceneAPI handler for processing
  57. try:
  58. import azlmbr.scene as sceneApi
  59. sceneJobHandler = sceneApi.ScriptBuildingNotificationBusHandler()
  60. sceneJobHandler.connect()
  61. sceneJobHandler.add_callback('OnUpdateManifest', on_update_manifest)
  62. sceneJobHandler.add_callback('OnPrepareForExport', on_prepare_for_export)
  63. except:
  64. sceneJobHandler = None