PhysicsSetupUtils.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. #include <EMotionFX/Source/PhysicsSetup.h>
  9. #include <EMotionFX/Source/Actor.h>
  10. #include "PhysicsSetupUtils.h"
  11. namespace EMotionFX
  12. {
  13. size_t PhysicsSetupUtils::CountColliders(const Actor* actor, PhysicsSetup::ColliderConfigType colliderConfigType, bool ignoreShapeType, Physics::ShapeType shapeTypeToCount)
  14. {
  15. const AZStd::shared_ptr<PhysicsSetup>& physicsSetup = actor->GetPhysicsSetup();
  16. Physics::CharacterColliderConfiguration* colliderConfig = physicsSetup->GetColliderConfigByType(colliderConfigType);
  17. if (!colliderConfig)
  18. {
  19. return 0;
  20. }
  21. size_t result = 0;
  22. for (const Physics::CharacterColliderNodeConfiguration& nodeConfig : colliderConfig->m_nodes)
  23. {
  24. if (ignoreShapeType)
  25. {
  26. // Count in all colliders.
  27. result += nodeConfig.m_shapes.size();
  28. }
  29. else
  30. {
  31. // Count in only the given collider type.
  32. for (const AzPhysics::ShapeColliderPair& shapeConfigPair : nodeConfig.m_shapes)
  33. {
  34. if (shapeConfigPair.second->GetShapeType() == shapeTypeToCount)
  35. {
  36. result++;
  37. }
  38. }
  39. }
  40. }
  41. return result;
  42. }
  43. } //namespace EMotionFX