scene_export_motion.py 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. import traceback, sys, uuid, os, json
  9. import scene_export_utils
  10. import scene_api.motion_group
  11. #
  12. # Example for exporting MotionGroup scene rules
  13. #
  14. def update_manifest(scene):
  15. import azlmbr.scene.graph
  16. import scene_api.scene_data
  17. # create a SceneManifest
  18. sceneManifest = scene_api.scene_data.SceneManifest()
  19. # create a MotionGroup
  20. motionGroup = scene_api.motion_group.MotionGroup()
  21. motionGroup.name = os.path.basename(scene.sourceFilename.replace('.', '_'))
  22. motionAdditiveRule = scene_api.motion_group.MotionAdditiveRule()
  23. motionAdditiveRule.sampleFrame = 2
  24. motionGroup.add_rule(motionAdditiveRule)
  25. motionScaleRule = motionGroup.create_rule(scene_api.motion_group.MotionScaleRule())
  26. motionScaleRule.scaleFactor = 1.1
  27. motionGroup.add_rule(motionScaleRule)
  28. # add motion group to scene manifest
  29. sceneManifest.add_motion_group(motionGroup)
  30. # Convert the manifest to a JSON string and return it
  31. return sceneManifest.export()
  32. sceneJobHandler = None
  33. def on_update_manifest(args):
  34. try:
  35. scene = args[0]
  36. return update_manifest(scene)
  37. except RuntimeError as err:
  38. print (f'ERROR - {err}')
  39. scene_export_utils.log_exception_traceback()
  40. except:
  41. scene_export_utils.log_exception_traceback()
  42. finally:
  43. global sceneJobHandler
  44. # do not delete or set sceneJobHandler to None, just disconnect from it.
  45. # this call is occuring while the scene Job Handler itself is in the callstack, so deleting it here
  46. # would cause a crash.
  47. sceneJobHandler.disconnect()
  48. # try to create SceneAPI handler for processing
  49. try:
  50. import azlmbr.scene
  51. sceneJobHandler = azlmbr.scene.ScriptBuildingNotificationBusHandler()
  52. sceneJobHandler.connect()
  53. sceneJobHandler.add_callback('OnUpdateManifest', on_update_manifest)
  54. except:
  55. sceneJobHandler = None