AtomActorDebugDraw.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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. #pragma once
  9. #include <AzCore/std/containers/vector.h>
  10. #include <AzCore/Math/Color.h>
  11. #include <AzFramework/Font/FontInterface.h>
  12. #include <AzFramework/Physics/DebugDraw/CharacterPhysicsDebugDraw.h>
  13. #include <Integration/Rendering/RenderFlag.h>
  14. #include <Integration/Rendering/RenderActorInstance.h>
  15. #include <Atom/RPI.Public/ViewportContext.h>
  16. namespace AzFramework
  17. {
  18. class DebugDisplayRequests;
  19. }
  20. namespace EMotionFX
  21. {
  22. class Mesh;
  23. class ActorInstance;
  24. }
  25. namespace AZ::RPI
  26. {
  27. class AuxGeomDraw;
  28. class AuxGeomFeatureProcessorInterface;
  29. }
  30. namespace AZ::Render
  31. {
  32. // Ultility class for atom debug render on actor
  33. class AtomActorDebugDraw
  34. {
  35. public:
  36. AZ_CLASS_ALLOCATOR(AtomActorDebugDraw, AZ::SystemAllocator)
  37. struct TrajectoryPathParticle
  38. {
  39. EMotionFX::Transform m_worldTm;
  40. };
  41. struct TrajectoryTracePath
  42. {
  43. AZ_CLASS_ALLOCATOR(AtomActorDebugDraw::TrajectoryTracePath, AZ::SystemAllocator)
  44. AZStd::vector<TrajectoryPathParticle> m_traceParticles;
  45. const EMotionFX::ActorInstance* m_actorInstance = nullptr;
  46. float m_timePassed = 0.0f;
  47. };
  48. AtomActorDebugDraw(AZ::EntityId entityId);
  49. void UpdateActorInstance(EMotionFX::ActorInstance* actorInstance, float deltaTime);
  50. void DebugDraw(const EMotionFX::ActorRenderFlags& renderFlags, EMotionFX::ActorInstance* instance);
  51. private:
  52. float CalculateBoneScale(EMotionFX::ActorInstance* actorInstance, EMotionFX::Node* node);
  53. float CalculateScaleMultiplier(EMotionFX::ActorInstance* instance) const;
  54. void PrepareForMesh(EMotionFX::Mesh* mesh, const AZ::Transform& worldTM);
  55. AzFramework::DebugDisplayRequests* GetDebugDisplay(AzFramework::ViewportId viewportId);
  56. void RenderAABB(EMotionFX::ActorInstance* instance,
  57. bool enableNodeAabb,
  58. const AZ::Color& nodeAabbColor,
  59. bool enableMeshAabb,
  60. const AZ::Color& meshAabbColor,
  61. bool enableStaticAabb,
  62. const AZ::Color& staticAabbColor);
  63. void RenderLineSkeleton(AzFramework::DebugDisplayRequests* debugDisplay,
  64. EMotionFX::ActorInstance* instance,
  65. const AZ::Color& skeletonColor) const;
  66. void RenderSkeleton(AzFramework::DebugDisplayRequests* debugDisplay,
  67. EMotionFX::ActorInstance* instance,
  68. const AZ::Color& color);
  69. void RenderEMFXDebugDraw(EMotionFX::ActorInstance* instance);
  70. void RenderNormals(
  71. EMotionFX::Mesh* mesh,
  72. const AZ::Transform& worldTM,
  73. bool vertexNormals,
  74. bool faceNormals,
  75. float vertexNormalsScale,
  76. float faceNormalsScale,
  77. float scaleMultiplier,
  78. const AZ::Color& vertexNormalsColor,
  79. const AZ::Color& faceNormalsColor);
  80. void RenderTangents(
  81. EMotionFX::Mesh* mesh, const AZ::Transform& worldTM, float tangentsScale, float scaleMultiplier,
  82. const AZ::Color& tangentsColor, const AZ::Color& mirroredBitangentsColor, const AZ::Color& bitangentsColor);
  83. void RenderWireframe(EMotionFX::Mesh* mesh, const AZ::Transform& worldTM,
  84. float scale, const AZ::Color& color);
  85. void RenderJointNames(EMotionFX::ActorInstance* actorInstance, RPI::ViewportContextPtr viewportContext, const AZ::Color& jointNameColor);
  86. void RenderNodeOrientations(EMotionFX::ActorInstance* actorInstance, AzFramework::DebugDisplayRequests* debugDisplay, float scale = 1.0f);
  87. void RenderLineAxis(
  88. AzFramework::DebugDisplayRequests* debugDisplay,
  89. AZ::Transform worldTM, //!< The world space transformation matrix to visualize. */
  90. float size, //!< The size value in units is used to control the scaling of the axis. */
  91. bool selected, //!< Set to true if you want to render the axis using the selection color. */
  92. bool renderAxisName = false);
  93. void RenderTrajectoryPath(
  94. AzFramework::DebugDisplayRequests* debugDisplay,
  95. const EMotionFX::ActorInstance* actorInstance,
  96. const AZ::Color& headColor,
  97. const AZ::Color& pathColor);
  98. void RenderRootMotion(
  99. AzFramework::DebugDisplayRequests* debugDisplay,
  100. const EMotionFX::ActorInstance* actorInstance,
  101. const AZ::Color& rootColor);
  102. // Return a non-owning trajectory path pointer.
  103. TrajectoryTracePath* FindTrajectoryPath(const EMotionFX::ActorInstance* actorInstance);
  104. EMotionFX::Mesh* m_currentMesh = nullptr; //!< A pointer to the mesh whose world space positions are in the pre-calculated positions buffer.
  105. //!< NULL in case we haven't pre-calculated any positions yet.
  106. AZStd::vector<AZ::Vector3> m_worldSpacePositions; //!< The buffer used to store world space positions for rendering normals
  107. //!< tangents and the wireframe.
  108. //! Checks if a joint is selected or hovered and updates the color appropriately.
  109. AZ::Color GetModifiedColor(
  110. const AZ::Color& color,
  111. size_t jointIndex,
  112. const AZStd::unordered_set<size_t>* cachedSelectedJointIndices,
  113. size_t cachedHoveredJointIndex) const;
  114. static constexpr float BaseFontSize = 0.7f;
  115. const Vector3 TopRightBorderPadding = AZ::Vector3(-40.0f, 22.0f, 0.0f);
  116. const AZ::Color SelectedColor = AZ::Color{ 1.0f, 0.67f, 0.0f, 1.0f };
  117. const AZ::Color HoveredColor = AZ::Color{ 0.78f, 1.0f, 0.67f, 1.0f };
  118. RPI::AuxGeomFeatureProcessorInterface* m_auxGeomFeatureProcessor = nullptr;
  119. AZStd::vector<AZ::Vector3> m_auxVertices;
  120. AZStd::vector<AZ::Color> m_auxColors;
  121. EntityId m_entityId;
  122. Physics::CharacterPhysicsDebugDraw m_characterPhysicsDebugDraw;
  123. // Motion extraction paths
  124. AZStd::vector<AZStd::unique_ptr<TrajectoryTracePath>> m_trajectoryTracePaths;
  125. AzFramework::TextDrawParameters m_drawParams;
  126. AzFramework::FontDrawInterface* m_fontDrawInterface = nullptr;
  127. };
  128. }