JointsHelper.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. from editor_python_test_tools.utils import Report
  7. import azlmbr.legacy.general as general
  8. import azlmbr.bus
  9. def vector3SmallerThanScalar(vec3Value, scalarValue):
  10. return (vec3Value.x < scalarValue and
  11. vec3Value.y < scalarValue and
  12. vec3Value.z < scalarValue)
  13. def vector3LargerThanScalar(vec3Value, scalarValue):
  14. return (vec3Value.x > scalarValue and
  15. vec3Value.y > scalarValue and
  16. vec3Value.z > scalarValue)
  17. def getRelativeVector(vecA, vecB):
  18. relativeVec = vecA
  19. relativeVec.x = relativeVec.x - vecB.x
  20. relativeVec.y = relativeVec.y - vecB.y
  21. relativeVec.z = relativeVec.z - vecB.z
  22. return relativeVec
  23. # Entity class for joints tests
  24. class JointEntity:
  25. def criticalEntityFound(self): # For overriding in sub-classes so that can report if entities are found using their own dictionary of entities
  26. pass
  27. def __init__(self, name):
  28. self.id = general.find_game_entity(name)
  29. self.name = name
  30. self.criticalEntityFound()
  31. @property
  32. def position(self):
  33. # type () -> Vector3
  34. return azlmbr.components.TransformBus(azlmbr.bus.Event, "GetWorldTranslation", self.id)
  35. # Entity class that sets a flag when an instance receives collision events.
  36. class JointEntityCollisionAware(JointEntity):
  37. def on_collision_begin(self, args):
  38. self.collided = True
  39. def on_collision_persist(self, args):
  40. self.collided = True
  41. def on_collision_end(self, args):
  42. self.collided = True
  43. def __init__(self, name):
  44. self.id = general.find_game_entity(name)
  45. self.name = name
  46. self.criticalEntityFound()
  47. self.collided = False
  48. # Set up collision notification handler
  49. self.handler = azlmbr.physics.CollisionNotificationBusHandler()
  50. self.handler.connect(self.id)
  51. self.handler.add_callback("OnCollisionBegin", self.on_collision_begin)
  52. self.handler.add_callback("OnCollisionPresist", self.on_collision_persist)
  53. self.handler.add_callback("OnCollisionEnd", self.on_collision_end)