|
|
|
|
@ -6,6 +6,8 @@
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <AzFramework/Entity/EntityDebugDisplayBus.h>
|
|
|
|
|
|
|
|
|
|
#include <AtomActorDebugDraw.h>
|
|
|
|
|
#include <Atom/RPI.Public/Scene.h>
|
|
|
|
|
#include <Atom/RPI.Public/AuxGeom/AuxGeomDraw.h>
|
|
|
|
|
@ -25,6 +27,7 @@
|
|
|
|
|
namespace AZ::Render
|
|
|
|
|
{
|
|
|
|
|
AtomActorDebugDraw::AtomActorDebugDraw(AZ::EntityId entityId)
|
|
|
|
|
: m_entityId(entityId)
|
|
|
|
|
{
|
|
|
|
|
m_auxGeomFeatureProcessor = RPI::Scene::GetFeatureProcessorForEntity<RPI::AuxGeomFeatureProcessorInterface>(entityId);
|
|
|
|
|
}
|
|
|
|
|
@ -42,9 +45,11 @@ namespace AZ::Render
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(instance->GetEntityId());
|
|
|
|
|
const RPI::Scene* scene = RPI::Scene::GetSceneForEntityId(m_entityId);
|
|
|
|
|
const RPI::ViewportContextPtr viewport = AZ::Interface<AZ::RPI::ViewportContextRequestsInterface>::Get()->GetViewportContextByScene(scene);
|
|
|
|
|
AzFramework::DebugDisplayRequests* debugDisplay = GetDebugDisplay(viewport->GetId());
|
|
|
|
|
const AZ::Render::RenderActorSettings& renderActorSettings = EMotionFX::GetRenderActorSettings();
|
|
|
|
|
const float scaleMultiplier = CalculateScaleMultiplier(instance);
|
|
|
|
|
|
|
|
|
|
// Render aabb
|
|
|
|
|
if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_AABB])
|
|
|
|
|
@ -75,6 +80,12 @@ namespace AZ::Render
|
|
|
|
|
RenderEMFXDebugDraw(instance);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render
|
|
|
|
|
if (renderFlags[EMotionFX::ActorRenderFlag::RENDER_NODEORIENTATION])
|
|
|
|
|
{
|
|
|
|
|
RenderNodeOrientations(instance, debugDisplay, renderActorSettings.m_nodeOrientationScale * scaleMultiplier);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render vertex normal, face normal, tagent and wireframe.
|
|
|
|
|
const bool renderVertexNormals = renderFlags[EMotionFX::ActorRenderFlag::RENDER_VERTEXNORMALS];
|
|
|
|
|
const bool renderFaceNormals = renderFlags[EMotionFX::ActorRenderFlag::RENDER_FACENORMALS];
|
|
|
|
|
@ -87,7 +98,6 @@ namespace AZ::Render
|
|
|
|
|
const EMotionFX::Pose* pose = instance->GetTransformData()->GetCurrentPose();
|
|
|
|
|
const size_t geomLODLevel = instance->GetLODLevel();
|
|
|
|
|
const size_t numEnabled = instance->GetNumEnabledNodes();
|
|
|
|
|
const float scaleMultiplier = CalculateScaleMultiplier(instance);
|
|
|
|
|
for (size_t i = 0; i < numEnabled; ++i)
|
|
|
|
|
{
|
|
|
|
|
EMotionFX::Node* node = instance->GetActor()->GetSkeleton()->GetNode(instance->GetEnabledNode(i));
|
|
|
|
|
@ -175,6 +185,13 @@ namespace AZ::Render
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AzFramework::DebugDisplayRequests* AtomActorDebugDraw::GetDebugDisplay(AzFramework::ViewportId viewportId)
|
|
|
|
|
{
|
|
|
|
|
AzFramework::DebugDisplayRequestBus::BusPtr debugDisplayBus;
|
|
|
|
|
AzFramework::DebugDisplayRequestBus::Bind(debugDisplayBus, viewportId);
|
|
|
|
|
return AzFramework::DebugDisplayRequestBus::FindFirstHandler(debugDisplayBus);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AtomActorDebugDraw::RenderAABB(EMotionFX::ActorInstance* instance, const AZ::Color& aabbColor)
|
|
|
|
|
{
|
|
|
|
|
RPI::AuxGeomDrawPtr auxGeom = m_auxGeomFeatureProcessor->GetDrawQueue();
|
|
|
|
|
@ -610,4 +627,89 @@ namespace AZ::Render
|
|
|
|
|
m_fontDrawInterface->DrawScreenAlignedText3d(m_drawParams, joint->GetName());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AtomActorDebugDraw::RenderNodeOrientations(EMotionFX::ActorInstance* actorInstance,
|
|
|
|
|
AzFramework::DebugDisplayRequests* debugDisplay, float scale)
|
|
|
|
|
{
|
|
|
|
|
// Get the actor and the transform data
|
|
|
|
|
const float unitScale =
|
|
|
|
|
1.0f / (float)MCore::Distance::ConvertValue(1.0f, MCore::Distance::UNITTYPE_METERS, EMotionFX::GetEMotionFX().GetUnitType());
|
|
|
|
|
const EMotionFX::Actor* actor = actorInstance->GetActor();
|
|
|
|
|
const EMotionFX::Skeleton* skeleton = actor->GetSkeleton();
|
|
|
|
|
const EMotionFX::TransformData* transformData = actorInstance->GetTransformData();
|
|
|
|
|
const EMotionFX::Pose* pose = transformData->GetCurrentPose();
|
|
|
|
|
const float constPreScale = scale * unitScale * 3.0f;
|
|
|
|
|
|
|
|
|
|
const size_t numEnabled = actorInstance->GetNumEnabledNodes();
|
|
|
|
|
for (size_t i = 0; i < numEnabled; ++i)
|
|
|
|
|
{
|
|
|
|
|
EMotionFX::Node* joint = skeleton->GetNode(actorInstance->GetEnabledNode(i));
|
|
|
|
|
const size_t jointIndex = joint->GetNodeIndex();
|
|
|
|
|
|
|
|
|
|
static const float axisBoneScale = 50.0f;
|
|
|
|
|
const float size = CalculateBoneScale(actorInstance, joint) * constPreScale * axisBoneScale;
|
|
|
|
|
AZ::Transform worldTM = pose->GetWorldSpaceTransform(jointIndex).ToAZTransform();
|
|
|
|
|
RenderLineAxis(debugDisplay, worldTM, size, false /*selected*/);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AtomActorDebugDraw::RenderLineAxis(
|
|
|
|
|
AzFramework::DebugDisplayRequests* debugDisplay,
|
|
|
|
|
AZ::Transform worldTM,
|
|
|
|
|
float size,
|
|
|
|
|
bool selected,
|
|
|
|
|
bool renderAxisName)
|
|
|
|
|
{
|
|
|
|
|
const float axisHeight = size * 0.7f;
|
|
|
|
|
const float frontSize = size * 5.0f + 0.2f;
|
|
|
|
|
const AZ::Vector3 position = worldTM.GetTranslation();
|
|
|
|
|
|
|
|
|
|
// Render x axis
|
|
|
|
|
{
|
|
|
|
|
AZ::Color xSelectedColor = selected ? AZ::Colors::Orange : AZ::Colors::Red;
|
|
|
|
|
|
|
|
|
|
const AZ::Vector3 xAxisDir = (worldTM.TransformPoint(AZ::Vector3(size, 0.0f, 0.0f)) - position).GetNormalized();
|
|
|
|
|
const AZ::Vector3 xAxisArrowStart = position + xAxisDir * axisHeight;
|
|
|
|
|
debugDisplay->SetColor(xSelectedColor);
|
|
|
|
|
debugDisplay->DrawArrow(position, xAxisArrowStart, size);
|
|
|
|
|
|
|
|
|
|
if (renderAxisName)
|
|
|
|
|
{
|
|
|
|
|
const AZ::Vector3 xNamePos = position + xAxisDir * (size * 1.15f);
|
|
|
|
|
debugDisplay->DrawTextLabel(xNamePos, frontSize, "X");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render y axis
|
|
|
|
|
{
|
|
|
|
|
AZ::Color ySelectedColor = selected ? AZ::Colors::Orange : AZ::Colors::Blue;
|
|
|
|
|
|
|
|
|
|
const AZ::Vector3 yAxisDir = (worldTM.TransformPoint(AZ::Vector3(0.0f, size, 0.0f)) - position).GetNormalized();
|
|
|
|
|
const AZ::Vector3 yAxisArrowStart = position + yAxisDir * axisHeight;
|
|
|
|
|
debugDisplay->SetColor(ySelectedColor);
|
|
|
|
|
debugDisplay->DrawArrow(position, yAxisArrowStart, size);
|
|
|
|
|
|
|
|
|
|
if (renderAxisName)
|
|
|
|
|
{
|
|
|
|
|
const AZ::Vector3 yNamePos = position + yAxisDir * (size * 1.15f);
|
|
|
|
|
debugDisplay->DrawTextLabel(yNamePos, frontSize, "Y");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Render z axis
|
|
|
|
|
{
|
|
|
|
|
AZ::Color zSelectedColor = selected ? AZ::Colors::Orange : AZ::Colors::Green;
|
|
|
|
|
|
|
|
|
|
const AZ::Vector3 zAxisDir = (worldTM.TransformPoint(AZ::Vector3(0.0f, 0.0f, size)) - position).GetNormalized();
|
|
|
|
|
const AZ::Vector3 zAxisArrowStart = position + zAxisDir * axisHeight;
|
|
|
|
|
debugDisplay->SetColor(zSelectedColor);
|
|
|
|
|
debugDisplay->DrawArrow(position, zAxisArrowStart, size);
|
|
|
|
|
|
|
|
|
|
if (renderAxisName)
|
|
|
|
|
{
|
|
|
|
|
const AZ::Vector3 zNamePos = position + zAxisDir * (size * 1.15f);
|
|
|
|
|
debugDisplay->DrawTextLabel(zNamePos, frontSize, "Z");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} // namespace AZ::Render
|
|
|
|
|
|