#ifndef __HIKHOSTMB__H_
#define __HIKHOSTMB__H_
#include "hikhost.h"
#define LEFT_EXTRA_COLLAR 0
#define RIGHT_EXTRA_COLLAR 1
K_STATIC_ASSERT( LastEffectorId + 1 < ( 1 << 10 ) );
K_STATIC_ASSERT( LastNodeId + 1 < ( 1 << 10 ) );
class AnimationNode_Id
{
int mId;
public:
AnimationNode_Id();
AnimationNode_Id(const AnimationNode_Id &pSource);
AnimationNode_Id(const int pSource);
AnimationNode_Id(HIKEffectorId pId);
AnimationNode_Id(HIKNodeId pId);
bool IsValid() const;
bool IsValidEffectorId() const;
bool IsValidNodeId() const;
bool IsValidType() const;
HIKEffectorId GetEffectorId() const;
HIKNodeId GetNodeId() const;
int GetType() const;
private:
static HIKEffectorId HIKNodeIdToHIKEffectorId_LastInChain(HIKNodeId pNodeId);
};
inline AnimationNode_Id::operator
int()
const
{
return mId;
}
{
if(IsValid())
{
return AnimationNode_Id((pConnectorType << 21) | mId);
}
else
{
return AnimationNode_Id();
}
}
inline bool AnimationNode_Id::IsValid() const
{
return ((mId & 0x1) != 0);
}
inline bool AnimationNode_Id::IsValidEffectorId() const
{
const int lId = GetEffectorId();
return ( lId >= 0 && lId < LastEffectorId);
}
inline bool AnimationNode_Id::IsValidNodeId() const
{
const int lId = GetNodeId();
return ( lId >= 0 && lId < LastNodeId);
}
inline bool AnimationNode_Id::IsValidType() const
{
const int lType = GetType();
}
inline HIKEffectorId AnimationNode_Id::GetEffectorId() const
{
if(IsValid())
{
return (HIKEffectorId)(((mId >> 11) & 0x3FF) - 1);
}
return LastEffectorId;
}
inline HIKNodeId AnimationNode_Id::GetNodeId() const
{
if(IsValid())
{
return (HIKNodeId)(((mId >> 1) & 0x3FF) - 1);
}
return LastNodeId;
}
inline int AnimationNode_Id::GetType() const
{
if(IsValid())
{
return (mId >> 21) & 0xF ;
}
return -1;
}
inline HIKEffectorId AnimationNode_Id::HIKNodeIdToHIKEffectorId_LastInChain(HIKNodeId pNodeId)
{
HIKEffectorId lChildEffector;
switch (pNodeId)
{
case HipsNodeId: { lChildEffector = HipsEffectorId; } break;
case LeftKneeRollNodeId:
case LeftAnkleNodeId:
{
lChildEffector = LeftAnkleEffectorId;
} break;
case RightKneeRollNodeId:
case RightAnkleNodeId:
{
lChildEffector = RightAnkleEffectorId;
} break;
case LeftElbowRollNodeId:
case LeftWristNodeId:
{
lChildEffector = LeftWristEffectorId;
} break;
case RightElbowRollNodeId:
case RightWristNodeId:
{
lChildEffector = RightWristEffectorId;
} break;
case LeftHipRollNodeId:
case LeftKneeNodeId:
{
lChildEffector = LeftKneeEffectorId;
} break;
case RightHipRollNodeId:
case RightKneeNodeId:
{
lChildEffector = RightKneeEffectorId;
} break;
case LeftShoulderRollNodeId:
case LeftElbowNodeId:
{
lChildEffector = LeftElbowEffectorId;
} break;
case RightShoulderRollNodeId:
case RightElbowNodeId:
{
lChildEffector = RightElbowEffectorId;
} break;
case WaistNodeId: { lChildEffector = ChestOriginEffectorId; } break;
case Spine1NodeId:
case Spine2NodeId:
case Spine3NodeId:
case Spine4NodeId:
case Spine5NodeId:
case Spine6NodeId:
case Spine7NodeId:
case Spine8NodeId:
case Spine9NodeId:
{
lChildEffector = ChestEndEffectorId;
} break;
case LeftFootNodeId: { lChildEffector = LeftFootEffectorId; } break;
case RightFootNodeId: { lChildEffector = RightFootEffectorId; } break;
case LeftShoulderNodeId:
case LeftCollarNodeId:
case LeftCollarExtraNodeId:
{
lChildEffector = LeftShoulderEffectorId;
} break;
case RightShoulderNodeId:
case RightCollarNodeId:
case RightCollarExtraNodeId:
{
lChildEffector = RightShoulderEffectorId;
} break;
case NeckNodeId:
case Neck1NodeId:
case Neck2NodeId:
case Neck3NodeId:
case Neck4NodeId:
case Neck5NodeId:
case Neck6NodeId:
case Neck7NodeId:
case Neck8NodeId:
case Neck9NodeId:
case HeadNodeId: { lChildEffector = HeadEffectorId; } break;
case LeftHipNodeId: { lChildEffector = LeftHipEffectorId; } break;
case RightHipNodeId: { lChildEffector = RightHipEffectorId; } break;
case LeftHandNodeId: { lChildEffector = LeftHandEffectorId; } break;
case RightHandNodeId: { lChildEffector = RightHandEffectorId; } break;
case LeftThumbInNodeId:
case LeftThumbANodeId:
case LeftThumbBNodeId:
case LeftThumbCNodeId:
case LeftThumbDNodeId:
{
lChildEffector = LeftHandThumbEffectorId;
} break;
case LeftIndexInNodeId:
case LeftIndexANodeId:
case LeftIndexBNodeId:
case LeftIndexCNodeId:
case LeftIndexDNodeId:
{
lChildEffector = LeftHandIndexEffectorId;
} break;
case LeftMiddleInNodeId:
case LeftMiddleANodeId:
case LeftMiddleBNodeId:
case LeftMiddleCNodeId:
case LeftMiddleDNodeId:
{
lChildEffector = LeftHandMiddleEffectorId;
} break;
case LeftRingInNodeId:
case LeftRingANodeId:
case LeftRingBNodeId:
case LeftRingCNodeId:
case LeftRingDNodeId:
{
lChildEffector = LeftHandRingEffectorId;
} break;
case LeftPinkyInNodeId:
case LeftPinkyANodeId:
case LeftPinkyBNodeId:
case LeftPinkyCNodeId:
case LeftPinkyDNodeId:
{
lChildEffector = LeftHandPinkyEffectorId;
} break;
case LeftExtraFingerInNodeId:
case LeftExtraFingerANodeId:
case LeftExtraFingerBNodeId:
case LeftExtraFingerCNodeId:
case LeftExtraFingerDNodeId:
{
lChildEffector = LeftHandExtraFingerEffectorId;
} break;
case RightThumbInNodeId:
case RightThumbANodeId:
case RightThumbBNodeId:
case RightThumbCNodeId:
case RightThumbDNodeId:
{
lChildEffector = RightHandThumbEffectorId;
} break;
case RightIndexInNodeId:
case RightIndexANodeId:
case RightIndexBNodeId:
case RightIndexCNodeId:
case RightIndexDNodeId:
{
lChildEffector = RightHandIndexEffectorId;
} break;
case RightMiddleInNodeId:
case RightMiddleANodeId:
case RightMiddleBNodeId:
case RightMiddleCNodeId:
case RightMiddleDNodeId:
{
lChildEffector = RightHandMiddleEffectorId;
} break;
case RightRingInNodeId:
case RightRingANodeId:
case RightRingBNodeId:
case RightRingCNodeId:
case RightRingDNodeId:
{
lChildEffector = RightHandRingEffectorId;
} break;
case RightPinkyInNodeId:
case RightPinkyANodeId:
case RightPinkyBNodeId:
case RightPinkyCNodeId:
case RightPinkyDNodeId:
{
lChildEffector = RightHandPinkyEffectorId;
} break;
case RightExtraFingerInNodeId:
case RightExtraFingerANodeId:
case RightExtraFingerBNodeId:
case RightExtraFingerCNodeId:
case RightExtraFingerDNodeId:
{
lChildEffector = RightHandExtraFingerEffectorId;
} break;
case LeftFootThumbInNodeId:
case LeftFootThumbANodeId:
case LeftFootThumbBNodeId:
case LeftFootThumbCNodeId:
case LeftFootThumbDNodeId:
{
lChildEffector = LeftFootThumbEffectorId;
} break;
case LeftFootIndexInNodeId:
case LeftFootIndexANodeId:
case LeftFootIndexBNodeId:
case LeftFootIndexCNodeId:
case LeftFootIndexDNodeId:
{
lChildEffector = LeftFootIndexEffectorId;
} break;
case LeftFootMiddleInNodeId:
case LeftFootMiddleANodeId:
case LeftFootMiddleBNodeId:
case LeftFootMiddleCNodeId:
case LeftFootMiddleDNodeId:
{
lChildEffector = LeftFootMiddleEffectorId;
} break;
case LeftFootRingInNodeId:
case LeftFootRingANodeId:
case LeftFootRingBNodeId:
case LeftFootRingCNodeId:
case LeftFootRingDNodeId:
{
lChildEffector = LeftFootRingEffectorId;
} break;
case LeftFootPinkyInNodeId:
case LeftFootPinkyANodeId:
case LeftFootPinkyBNodeId:
case LeftFootPinkyCNodeId:
case LeftFootPinkyDNodeId:
{
lChildEffector = LeftFootPinkyEffectorId;
} break;
case LeftExtraFootFingerInNodeId:
case LeftExtraFootFingerANodeId:
case LeftExtraFootFingerBNodeId:
case LeftExtraFootFingerCNodeId:
case LeftExtraFootFingerDNodeId:
{
lChildEffector = LeftFootExtraFingerEffectorId;
} break;
case RightFootThumbInNodeId:
case RightFootThumbANodeId:
case RightFootThumbBNodeId:
case RightFootThumbCNodeId:
case RightFootThumbDNodeId:
{
lChildEffector = RightFootThumbEffectorId;
} break;
case RightFootIndexInNodeId:
case RightFootIndexANodeId:
case RightFootIndexBNodeId:
case RightFootIndexCNodeId:
case RightFootIndexDNodeId:
{
lChildEffector = RightFootIndexEffectorId;
} break;
case RightFootMiddleInNodeId:
case RightFootMiddleANodeId:
case RightFootMiddleBNodeId:
case RightFootMiddleCNodeId:
case RightFootMiddleDNodeId:
{
lChildEffector = RightFootMiddleEffectorId;
} break;
case RightFootRingInNodeId:
case RightFootRingANodeId:
case RightFootRingBNodeId:
case RightFootRingCNodeId:
case RightFootRingDNodeId:
{
lChildEffector = RightFootRingEffectorId;
} break;
case RightFootPinkyInNodeId:
case RightFootPinkyANodeId:
case RightFootPinkyBNodeId:
case RightFootPinkyCNodeId:
case RightFootPinkyDNodeId:
{
lChildEffector = RightFootPinkyEffectorId;
} break;
case RightExtraFootFingerInNodeId:
case RightExtraFootFingerANodeId:
case RightExtraFootFingerBNodeId:
case RightExtraFootFingerCNodeId:
case RightExtraFootFingerDNodeId:
{
lChildEffector = RightFootExtraFingerEffectorId;
} break;
default:
{
lChildEffector = LastEffectorId;
} break;
}
return lChildEffector;
}
class HIKHostNodeMB
{
public:
FBModel *mNode;
FBAnimationNode* mDestTConn;
FBAnimationNode* mDestRConn;
FBAnimationNode* mDestSConn;
FBProperty* mReachT;
FBProperty* mReachR;
HIKHostNodeMB();
virtual void SetNode(FBModel *pNode, FBConstraint *pConstraint, AnimationNode_Id pConnectorId=0);
virtual void Clear();
virtual bool IsDestinationConn(FBAnimationNode* pConnector);
};
class HIKHostPropertyMB
{
public:
int mDefaultMode;
double mDefaultValue;
FBProperty* mModeP;
FBProperty* mValueP;
int mValueIndex;
double mValueScale;
bool mIsEnum;
HIKHostPropertyMB();
void Init(FBProperty *pModeP, FBProperty *pValueP,int pValueIndex,double pValueScale,bool pIsEnum);
};
template <> bool HIKHostNode<HIKHostNodeMB>::Valid();
template <> void HIKHostNode<HIKHostNodeMB>::ReadXForm(double *pXForm, FBEvaluateInfo* pEvalInfo);
template <> void HIKHostNode<HIKHostNodeMB>::WriteXForm(double *pXForm, FBEvaluateInfo* pEvalInfo);
template <> void HIKHostNode<HIKHostNodeMB>::WriteXFormCandidate(double *pXForm, FBEvaluateInfo* pEvalInfo);
template <>
void HIKHostNode<HIKHostNodeMB>::WriteTQSIfNotRecursive(
FBTVector &pT,
FBQuaternion &pQ,
FBVector4d &pS, FBEvaluateInfo* pEvalInfo,
int &pRecursivityInfo);
template <>
void HIKHostNode<HIKHostNodeMB>::WriteCandidateTQS(
const FBTVector &pT,
const FBQuaternion &pQ,
const FBVector4d &pS, FBEvaluateInfo* pEvalInfo);
template <> int HIKHostNode<HIKHostNodeMB>::IsEvaluationRecursiveTQS(FBEvaluateInfo* pEvalInfo);
template <> double HIKHostNode<HIKHostNodeMB>::ReadReachT( FBEvaluateInfo* pEvalInfo );
template <> double HIKHostNode<HIKHostNodeMB>::ReadReachR( FBEvaluateInfo* pEvalInfo );
template <> void HIKHostNode<HIKHostNodeMB>::ReadIKPivot(double *pIKPivot, FBEvaluateInfo* pEvalInfo);
template <> bool HIKHostNode<HIKHostNodeMB>::GetIKSync();
template <> bool HIKHostNode<HIKHostNodeMB>::GetUseRotationLimits();
template <> bool HIKHostNode<HIKHostNodeMB>::GetUseTranslationLimits();
template <> int HIKHostNode<HIKHostNodeMB>::GetRotationOrder();
template <> void HIKHostNode<HIKHostNodeMB>::GetPreQ(double *pPreQ);
template <> void HIKHostNode<HIKHostNodeMB>::GetPostQ(double *pPostQ);
template <> int HIKHostNode<HIKHostNodeMB>::GetRotationMinXYZ(double *pXYZ);
template <> int HIKHostNode<HIKHostNodeMB>::GetRotationMaxXYZ(double *pXYZ);
template <> int HIKHostProperty<HIKHostPropertyMB>::ReadMode( FBEvaluateInfo* pEvalInfo );
template <> double HIKHostProperty<HIKHostPropertyMB>::ReadValue( FBEvaluateInfo* pEvalInfo );
HIKNodeId ExtraIndexToHIKNodeId(int pExtraIndex);
int HIKNodeIdToExtraIndex(HIKNodeId pNodeId);
HIKFloorContact FBFloorContactIDToHIKLeftHandFloor(
FBFloorContactID pFloorContact);
bool GetNodeIdOrEffectIdFromModel( FBCharacterSolver* pSolver, FBModel* pModel,
int& pHIKNodeId,
int& pHIKEffectorId,
FBEffectorId& pEffectorId,
FBEffectorSetID& pPivotIndex );
int GetSolvingStepBasedOnActivePart(int pIndex);
void HIKHostPropertiesInit(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost);
void HIKHostPropertiesFromCharacter(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost, FBCharacter* pCharacter);
void HIKCharacterHostFromFBCharacter(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost, FBCharacter* pCharacter, bool pFloorContacts=false);
void HIKCharacterHostFromFBCharacterSolver(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost, FBCharacterSolver* pCharacterSolver, FBConstraint* pConstraint, bool pFloorContacts=false);
void HIKControlRigHostFromFBCharacterSolver(HIKControlRigHost<HIKHostNodeMB> &pHIKControlRigHost, FBCharacterSolver* pCharacterSolver, FBControlSet* pControlSet, FBConstraint* pConstraint);
void HIKCharacterHostFromFBCharacterPose(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost, FBCharacter* pPoseCharacter, FBCharacterPose* pPose);
void HIKCharacterFromFBCharacter(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost,HIKCharacter*& pHIKCharacter,FBCharacter* pCharacter);
void HIKCharacterFromFBCharacterSolver(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost,HIKCharacter*& pHIKCharacter, FBCharacterSolver* pCharacterSolver);
void HIKCharacterFromFBActor(HIKCharacter*& pHIKActorCharacter, FBActor* pActor);
void HIKCharacterFromFBCharacterPose(HIKCharacterHost<HIKHostNodeMB,HIKHostPropertyMB> &pHIKCharacterHost,HIKCharacter*& pHIKCharacter,FBCharacter* pPoseCharacter, FBCharacterPose* pPose);
void UndoSetup(FBCharacter* pCharacter);
void ResetControRigModelTransformation( HIKCharacter *pHIKCharacter, HIKEvaluationState* pStanceState, HIKNodeId pNodeId, FBModel* pModel );
void SetNormalizedNodeStateForHierarchy( HIKCharacter *pHIKCharacter, HIKCharacterState *pState, KHIKNodeState pDataSet[LastNodeId], HIKNodeId pNodeId,
inline void CopyNormalizedState(KHIKNodeState pDstDataSet[LastNodeId], KHIKNodeState pSrcDataSet[LastNodeId], HIKNodeId pNodeId)
{
pDstDataSet[pNodeId].mTfv[0] = pSrcDataSet[pNodeId].mTfv[0];
pDstDataSet[pNodeId].mTfv[1] = pSrcDataSet[pNodeId].mTfv[1];
pDstDataSet[pNodeId].mTfv[2] = pSrcDataSet[pNodeId].mTfv[2];
pDstDataSet[pNodeId].mTfv[3] = pSrcDataSet[pNodeId].mTfv[3];
pDstDataSet[pNodeId].mQfv[0] = pSrcDataSet[pNodeId].mQfv[0];
pDstDataSet[pNodeId].mQfv[1] = pSrcDataSet[pNodeId].mQfv[1];
pDstDataSet[pNodeId].mQfv[2] = pSrcDataSet[pNodeId].mQfv[2];
pDstDataSet[pNodeId].mQfv[3] = pSrcDataSet[pNodeId].mQfv[3];
pDstDataSet[pNodeId].mSfv[0] = pSrcDataSet[pNodeId].mSfv[0];
pDstDataSet[pNodeId].mSfv[1] = pSrcDataSet[pNodeId].mSfv[1];
pDstDataSet[pNodeId].mSfv[2] = pSrcDataSet[pNodeId].mSfv[2];
pDstDataSet[pNodeId].mSfv[3] = pSrcDataSet[pNodeId].mSfv[3];
}
inline void HIKFillCharacterDescription(HIKCharacter* pHIKCharacter, int* pNodeIdDesc)
{
for(int lNodeCounter = 0 ; lNodeCounter < LastNodeId ; lNodeCounter++)
{
if( HIKGetNodeUse(pHIKCharacter, lNodeCounter) )
{
pNodeIdDesc[lNodeCounter] = lNodeCounter;
}
else
{
pNodeIdDesc[lNodeCounter] = HIKNotUsed;
}
}
pNodeIdDesc[LastNodeId] = HIKLastNode;
}
inline void HIKEffectorStateCopy(HIKEffectorSetState* pDst, const HIKEffectorSetState* pSrc)
{
double lT[4];
double lQ[4];
double lS[4];
for(int lIter = HipsEffectorId; lIter < LastEffectorId; lIter++)
{
HIKGetEffectorStateTQSdv(pSrc, lIter, lT, lQ, lS );
HIKSetEffectorStateTQSdv(pDst, lIter, lT, lQ, lS );
}
}
inline void HIKEffectorStateWithOptionsCopy(HIKEffectorSetState* pDst, const HIKEffectorSetState* pSrc)
{
double lT[4];
double lQ[4];
double lS[4];
for(int lIter = HipsEffectorId; lIter < LastEffectorId; lIter++)
{
HIKSetRotationActive(pDst, lIter, HIKGetRotationActive(pSrc, lIter));
HIKSetTranslationActive(pDst, lIter, HIKGetTranslationActive(pSrc, lIter));
HIKSetPull(pDst, lIter, HIKGetPull(pSrc, lIter));
HIKSetResist(pDst, lIter, HIKGetResist(pSrc, lIter));
HIKGetEffectorStateTQSdv(pSrc, lIter, lT, lQ, lS );
HIKSetEffectorStateTQSdv(pDst, lIter, lT, lQ, lS );
}
for(int lFloorIter = 0; lFloorIter < HIKLastFloorId; lFloorIter++)
{
HIKGetEffectorFloorStateTQdv(pSrc,lFloorIter,lT, lQ);
HIKSetEffectorFloorStateTQdv(pDst,lFloorIter,lT, lQ);
}
HIKSetHandPullHips(pDst, true, HIKGetHandPullHips(pSrc, true));
HIKSetHandPullHips(pDst, false, HIKGetHandPullHips(pSrc, false));
HIKSetIKSolvingStep(pDst, HIKGetIKSolvingStep(pSrc));
}
#endif // __HIKHOSTMB__H_