@ -32,10 +32,6 @@
namespace EMotionFX
{
float RagdollNodeInspectorPlugin : : s_scale = 0.1f ;
AZ : : u32 RagdollNodeInspectorPlugin : : s_angularSubdivisions = 32 ;
AZ : : u32 RagdollNodeInspectorPlugin : : s_radialSubdivisions = 2 ;
RagdollNodeInspectorPlugin : : RagdollNodeInspectorPlugin ( )
: EMStudio : : DockWidgetPlugin ( )
, m_nodeWidget ( nullptr )
@ -520,7 +516,6 @@ namespace EMotionFX
const Node * ragdollParentNode = physicsSetup - > FindRagdollParentNode ( joint ) ;
if ( ragdollParentNode )
{
LegacyRenderJointLimit ( * jointLimitConfig , actorInstance , joint , ragdollParentNode , renderPlugin , renderInfo , finalColor ) ;
LegacyRenderJointFrame ( * jointLimitConfig , actorInstance , joint , ragdollParentNode , renderInfo , finalColor ) ;
}
}
@ -528,54 +523,6 @@ namespace EMotionFX
}
}
void RagdollNodeInspectorPlugin : : LegacyRenderJointLimit (
const AzPhysics : : JointConfiguration & configuration ,
const ActorInstance * actorInstance ,
const Node * node ,
const Node * parentNode ,
EMStudio : : RenderPlugin * renderPlugin ,
EMStudio : : EMStudioPlugin : : RenderInfo * renderInfo ,
const MCore : : RGBAColor & color )
{
const EMStudio : : RenderOptions * renderOptions = renderPlugin - > GetRenderOptions ( ) ;
const MCore : : RGBAColor violatedColor = renderOptions - > GetViolatedJointLimitColor ( ) ;
const size_t nodeIndex = node - > GetNodeIndex ( ) ;
const size_t parentNodeIndex = parentNode - > GetNodeIndex ( ) ;
const Transform & actorInstanceWorldTransform = actorInstance - > GetWorldSpaceTransform ( ) ;
const Pose * currentPose = actorInstance - > GetTransformData ( ) - > GetCurrentPose ( ) ;
const AZ : : Quaternion & parentOrientation = currentPose - > GetModelSpaceTransform ( parentNodeIndex ) . m_rotation ;
const AZ : : Quaternion & childOrientation = currentPose - > GetModelSpaceTransform ( nodeIndex ) . m_rotation ;
m_vertexBuffer . clear ( ) ;
m_indexBuffer . clear ( ) ;
m_lineBuffer . clear ( ) ;
m_lineValidityBuffer . clear ( ) ;
if ( auto * jointHelpers = AZ : : Interface < AzPhysics : : JointHelpersInterface > : : Get ( ) )
{
jointHelpers - > GenerateJointLimitVisualizationData (
configuration , parentOrientation , childOrientation , s_scale , s_angularSubdivisions , s_radialSubdivisions , m_vertexBuffer ,
m_indexBuffer , m_lineBuffer , m_lineValidityBuffer ) ;
}
Transform jointModelSpaceTransform = currentPose - > GetModelSpaceTransform ( parentNodeIndex ) ;
jointModelSpaceTransform . m_position = currentPose - > GetModelSpaceTransform ( nodeIndex ) . m_position ;
const Transform jointGlobalTransformNoScale = jointModelSpaceTransform * actorInstanceWorldTransform ;
MCommon : : RenderUtil * renderUtil = renderInfo - > m_renderUtil ;
const size_t numLineBufferEntries = m_lineBuffer . size ( ) ;
if ( m_lineValidityBuffer . size ( ) * 2 ! = numLineBufferEntries )
{
AZ_ErrorOnce ( " EMotionFX " , false , " Unexpected buffer size in joint limit visualization for node %s " , node - > GetName ( ) ) ;
return ;
}
for ( size_t i = 0 ; i < numLineBufferEntries ; i + = 2 )
{
renderUtil - > RenderLine ( jointGlobalTransformNoScale . TransformPoint ( m_lineBuffer [ i ] ) ,
jointGlobalTransformNoScale . TransformPoint ( m_lineBuffer [ i + 1 ] ) , m_lineValidityBuffer [ i / 2 ] ? color : violatedColor ) ;
}
}
void RagdollNodeInspectorPlugin : : LegacyRenderJointFrame (
const AzPhysics : : JointConfiguration & configuration ,
const ActorInstance * actorInstance ,
@ -594,192 +541,4 @@ namespace EMotionFX
renderInfo - > m_renderUtil - > RenderArrow ( 0.1f , jointChildWorldSpaceTransformNoScale . m_position , MCore : : GetRight ( jointChildWorldSpaceTransformNoScale . ToAZTransform ( ) ) , color ) ;
}
void RagdollNodeInspectorPlugin : : Render ( EMotionFX : : ActorRenderFlags renderFlags )
{
const bool renderColliders = AZ : : RHI : : CheckBitsAny ( renderFlags , EMotionFX : : ActorRenderFlags : : RagdollColliders ) ;
const bool renderJointLimits = AZ : : RHI : : CheckBitsAny ( renderFlags , EMotionFX : : ActorRenderFlags : : RagdollJointLimits ) ;
if ( ! renderColliders & & ! renderJointLimits )
{
return ;
}
const size_t actorInstanceCount = GetActorManager ( ) . GetNumActorInstances ( ) ;
for ( size_t i = 0 ; i < actorInstanceCount ; + + i )
{
ActorInstance * actorInstance = GetActorManager ( ) . GetActorInstance ( i ) ;
RenderRagdoll ( actorInstance , renderColliders , renderJointLimits ) ;
}
}
void RagdollNodeInspectorPlugin : : RenderRagdoll (
ActorInstance * actorInstance ,
bool renderColliders ,
bool renderJointLimits )
{
const Actor * actor = actorInstance - > GetActor ( ) ;
const Skeleton * skeleton = actor - > GetSkeleton ( ) ;
const size_t numNodes = skeleton - > GetNumNodes ( ) ;
const AZStd : : shared_ptr < EMotionFX : : PhysicsSetup > & physicsSetup = actor - > GetPhysicsSetup ( ) ;
const Physics : : RagdollConfiguration & ragdollConfig = physicsSetup - > GetRagdollConfig ( ) ;
const AZStd : : vector < Physics : : RagdollNodeConfiguration > & ragdollNodes = ragdollConfig . m_nodes ;
const Physics : : CharacterColliderConfiguration & colliderConfig = ragdollConfig . m_colliders ;
const RagdollInstance * ragdollInstance = actorInstance - > GetRagdollInstance ( ) ;
const AZ : : Render : : RenderActorSettings & settings = EMotionFX : : GetRenderActorSettings ( ) ;
const AZ : : Color & violatedColor = settings . m_violatedJointLimitColor ;
const AZ : : Color & defaultColor = settings . m_ragdollColliderColor ;
const AZ : : Color & selectedColor = settings . m_selectedRagdollColliderColor ;
const AZStd : : unordered_set < size_t > & selectedJointIndices = EMStudio : : GetManager ( ) - > GetSelectedJointIndices ( ) ;
for ( size_t nodeIndex = 0 ; nodeIndex < numNodes ; + + nodeIndex )
{
const Node * joint = skeleton - > GetNode ( nodeIndex ) ;
const size_t jointIndex = joint - > GetNodeIndex ( ) ;
AZ : : Outcome < size_t > ragdollNodeIndex = AZ : : Failure ( ) ;
if ( ragdollInstance )
{
ragdollNodeIndex = ragdollInstance - > GetRagdollNodeIndex ( jointIndex ) ;
}
else
{
ragdollNodeIndex = ragdollConfig . FindNodeConfigIndexByName ( joint - > GetNameString ( ) ) ;
}
if ( ! ragdollNodeIndex . IsSuccess ( ) )
{
continue ;
}
const bool jointSelected = selectedJointIndices . empty ( ) | | selectedJointIndices . find ( jointIndex ) ! = selectedJointIndices . end ( ) ;
AZ : : Color finalColor ;
if ( jointSelected )
{
finalColor = selectedColor ;
}
else
{
finalColor = defaultColor ;
}
const Physics : : RagdollNodeConfiguration & ragdollNode = ragdollNodes [ ragdollNodeIndex . GetValue ( ) ] ;
if ( renderColliders )
{
const Physics : : CharacterColliderNodeConfiguration * colliderNodeConfig =
colliderConfig . FindNodeConfigByName ( joint - > GetNameString ( ) ) ;
if ( colliderNodeConfig )
{
const AzPhysics : : ShapeColliderPairList & colliders = colliderNodeConfig - > m_shapes ;
ColliderContainerWidget : : RenderColliders ( colliders , actorInstance , joint , finalColor ) ;
}
}
if ( renderJointLimits & & jointSelected )
{
const AZStd : : shared_ptr < AzPhysics : : JointConfiguration > & jointLimitConfig = ragdollNode . m_jointConfig ;
if ( jointLimitConfig )
{
const Node * ragdollParentNode = physicsSetup - > FindRagdollParentNode ( joint ) ;
if ( ragdollParentNode )
{
RenderJointLimit ( * jointLimitConfig , actorInstance , joint , ragdollParentNode , finalColor , violatedColor ) ;
RenderJointFrame ( * jointLimitConfig , actorInstance , joint , ragdollParentNode , finalColor ) ;
}
}
}
}
}
void RagdollNodeInspectorPlugin : : RenderJointLimit (
const AzPhysics : : JointConfiguration & configuration ,
const ActorInstance * actorInstance ,
const Node * node ,
const Node * parentNode ,
const AZ : : Color & regularColor ,
const AZ : : Color & violatedColor )
{
const size_t nodeIndex = node - > GetNodeIndex ( ) ;
const size_t parentNodeIndex = parentNode - > GetNodeIndex ( ) ;
const Transform & actorInstanceWorldTransform = actorInstance - > GetWorldSpaceTransform ( ) ;
const Pose * currentPose = actorInstance - > GetTransformData ( ) - > GetCurrentPose ( ) ;
const AZ : : Quaternion & parentOrientation = currentPose - > GetModelSpaceTransform ( parentNodeIndex ) . m_rotation ;
const AZ : : Quaternion & childOrientation = currentPose - > GetModelSpaceTransform ( nodeIndex ) . m_rotation ;
m_vertexBuffer . clear ( ) ;
m_indexBuffer . clear ( ) ;
m_lineBuffer . clear ( ) ;
m_lineValidityBuffer . clear ( ) ;
if ( auto * jointHelpers = AZ : : Interface < AzPhysics : : JointHelpersInterface > : : Get ( ) )
{
jointHelpers - > GenerateJointLimitVisualizationData (
configuration , parentOrientation , childOrientation , s_scale , s_angularSubdivisions , s_radialSubdivisions , m_vertexBuffer ,
m_indexBuffer , m_lineBuffer , m_lineValidityBuffer ) ;
}
Transform jointModelSpaceTransform = currentPose - > GetModelSpaceTransform ( parentNodeIndex ) ;
jointModelSpaceTransform . m_position = currentPose - > GetModelSpaceTransform ( nodeIndex ) . m_position ;
const Transform jointGlobalTransformNoScale = jointModelSpaceTransform * actorInstanceWorldTransform ;
const size_t numLineBufferEntries = m_lineBuffer . size ( ) ;
if ( m_lineValidityBuffer . size ( ) * 2 ! = numLineBufferEntries )
{
AZ_ErrorOnce ( " EMotionFX " , false , " Unexpected buffer size in joint limit visualization for node %s " , node - > GetName ( ) ) ;
return ;
}
AZ : : s32 viewportId = - 1 ;
EMStudio : : ViewportPluginRequestBus : : BroadcastResult ( viewportId , & EMStudio : : ViewportPluginRequestBus : : Events : : GetViewportId ) ;
AzFramework : : DebugDisplayRequestBus : : BusPtr debugDisplayBus ;
AzFramework : : DebugDisplayRequestBus : : Bind ( debugDisplayBus , viewportId ) ;
AzFramework : : DebugDisplayRequests * debugDisplay = nullptr ;
debugDisplay = AzFramework : : DebugDisplayRequestBus : : FindFirstHandler ( debugDisplayBus ) ;
if ( ! debugDisplay )
{
return ;
}
for ( size_t i = 0 ; i < numLineBufferEntries ; i + = 2 )
{
const AZ : : Color & lineColor = m_lineValidityBuffer [ i / 2 ] ? regularColor : violatedColor ;
debugDisplay - > DrawLine (
jointGlobalTransformNoScale . TransformPoint ( m_lineBuffer [ i ] ) ,
jointGlobalTransformNoScale . TransformPoint ( m_lineBuffer [ i + 1 ] ) , lineColor . GetAsVector4 ( ) , lineColor . GetAsVector4 ( )
) ;
}
}
void RagdollNodeInspectorPlugin : : RenderJointFrame (
const AzPhysics : : JointConfiguration & configuration ,
const ActorInstance * actorInstance ,
const Node * node ,
const Node * parentNode ,
const AZ : : Color & color )
{
AZ_UNUSED ( parentNode ) ;
const Transform & actorInstanceWorldSpaceTransform = actorInstance - > GetWorldSpaceTransform ( ) ;
const Pose * currentPose = actorInstance - > GetTransformData ( ) - > GetCurrentPose ( ) ;
const Transform childJointLocalSpaceTransform ( AZ : : Vector3 : : CreateZero ( ) , configuration . m_childLocalRotation ) ;
const Transform childModelSpaceTransform =
childJointLocalSpaceTransform * currentPose - > GetModelSpaceTransform ( node - > GetNodeIndex ( ) ) ;
const Transform jointChildWorldSpaceTransformNoScale = ( childModelSpaceTransform * actorInstanceWorldSpaceTransform ) ;
AZ : : Vector3 dir = jointChildWorldSpaceTransformNoScale . ToAZTransform ( ) . GetBasisX ( ) ;
AZ : : s32 viewportId = - 1 ;
EMStudio : : ViewportPluginRequestBus : : BroadcastResult ( viewportId , & EMStudio : : ViewportPluginRequestBus : : Events : : GetViewportId ) ;
AzFramework : : DebugDisplayRequestBus : : BusPtr debugDisplayBus ;
AzFramework : : DebugDisplayRequestBus : : Bind ( debugDisplayBus , viewportId ) ;
AzFramework : : DebugDisplayRequests * debugDisplay = nullptr ;
debugDisplay = AzFramework : : DebugDisplayRequestBus : : FindFirstHandler ( debugDisplayBus ) ;
if ( ! debugDisplay )
{
return ;
}
debugDisplay - > SetColor ( color ) ;
debugDisplay - > DrawArrow ( jointChildWorldSpaceTransformNoScale . m_position , jointChildWorldSpaceTransformNoScale . m_position + dir , 0.1f ) ;
}
} // namespace EMotionFX