42 #ifndef _CRT_SECURE_NO_WARNINGS
43 #define _CRT_SECURE_NO_WARNINGS
53 #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__ICL)
55 #define attribute_align(a) __declspec(align(a))
56 #elif defined(__GNUC__) || defined(__SNC__) || defined(__MWERKS__)
58 #define attribute_align(a) __attribute__ ((aligned(a)))
192 #define HEADERLENGTH 16
209 inline void Init(
const char *_Header)
211 #if (_MSC_VER == 1500)
212 strcpy(HeaderStr, _Header);
218 template<
typename HIKFile>
219 inline bool Write(HIKFile pFile)
const;
221 template<
typename HIKFile>
222 inline bool Read(HIKFile pFile);
225 template<
typename type>
bool Write(
const char* pFileName,
const type& pStream);
226 template<
typename type>
bool WriteBlock(
const char* pFileName,
const size_t& pElementSize,
const size_t& pElementCount,
type& pStream);
228 template<
typename type>
bool Read(
const char* pFileName,
type& pStream);
229 template<
typename type>
bool ReadBlock(
const char* pFileName,
const size_t pOffset,
const size_t& pElementSize,
const size_t& pElementCount,
type& pStream);
236 ToSwap[0] = ToSwap[3];
239 ToSwap[1] = ToSwap[2];
243 template<
typename type,
int count>
class Field
252 inline void Init(FieldType
pValue) { memset(mField, (
int)pValue,
sizeof(FieldType)*
eCount); }
254 template<
typename HIKFile>
255 inline bool Write(HIKFile pFile)
const;
257 template<
typename HIKFile>
258 inline bool Read(HIKFile pFile,
bool bSwap);
261 template<
typename type,
int count1,
int count2>
class Field2D
272 inline void Init(FieldType
pValue) { memset(mField, (
int)pValue,
sizeof(FieldType)*
eCount); }
274 template<
typename HIKFile>
275 inline bool Write(HIKFile pFile)
const;
277 template<
typename HIKFile>
278 inline bool Read(HIKFile pFile,
bool bSwap);
301 mParentTOffset.
Init(0.0f);
302 mParentQOffset.
Init(0.0f);
303 mParentSOffset.
Init(0.0f);
306 template<
typename HIKFile>
307 inline bool Write(HIKFile pFile)
const
311 lFlag = HIKCharHeader.
Write(pFile);
312 lFlag = lFlag && mNodeFlag.
Write(pFile);
313 lFlag = lFlag && mTOffset.
Write(pFile);
314 lFlag = lFlag && mQOffset.
Write(pFile);
315 lFlag = lFlag && mSOffset.
Write(pFile);
316 lFlag = lFlag && mParentTOffset.
Write(pFile);
317 lFlag = lFlag && mParentQOffset.
Write(pFile);
318 lFlag = lFlag && mParentSOffset.
Write(pFile);
323 template<
typename HIKFile>
324 inline bool Read(HIKFile pFile)
328 if(HIKCharHeader.
Read(pFile))
330 lFlag = mNodeFlag.
Read(pFile, HIKCharHeader.
bSwap);
331 lFlag = lFlag && mTOffset.
Read(pFile, HIKCharHeader.
bSwap);
332 lFlag = lFlag && mQOffset.
Read(pFile, HIKCharHeader.
bSwap);
333 lFlag = lFlag && mSOffset.
Read(pFile, HIKCharHeader.
bSwap);
334 lFlag = lFlag && mParentTOffset.
Read(pFile, HIKCharHeader.
bSwap);
335 lFlag = lFlag && mParentQOffset.
Read(pFile, HIKCharHeader.
bSwap);
336 lFlag = lFlag && mParentSOffset.
Read(pFile, HIKCharHeader.
bSwap);
352 if(
Read(pFileName, lStream))
361 const char* pValidationString,
372 if(
Read(pFileName, lStream))
441 return Write(pFileName, lStream);
454 mTransformMode.
Init(0);
456 mTransformData.
Init(0.0f);
460 template<
typename HIKFile>
461 inline bool Write(HIKFile pFile)
const
466 lFlag = lFlag && mTransformMode.
Write(pFile);
467 lFlag = lFlag && mNodeId.
Write(pFile);
473 template<
typename HIKFile>
474 inline bool Read(HIKFile pFile)
497 if(
Read(pFileName, lStateStream))
503 lDataDesc.mTransformSpace = lStateStream.
mTransformMode.
mField[0] == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;
504 lDataDesc.mTOffset = 0;
505 lDataDesc.mQOffset = 16;
506 lDataDesc.mSOffset = 32;
507 lDataDesc.mStride = 48;
522 lDataDesc.mTransformSpace = pTransformMode == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;
523 lDataDesc.mTOffset = 0;
524 lDataDesc.mQOffset = 16;
525 lDataDesc.mSOffset = 32;
526 lDataDesc.mStride = 48;
554 return Write(pFileName, lStateStream);
576 mHandPullHips.
Init(0.0f);
578 mFloorTQS.
Init(0.0f);
582 template<
typename HIKFile>
583 inline bool Write(HIKFile pFile)
const
587 lFlag = HIKEffectorHeader.
Write(pFile);
588 lFlag = lFlag && mReachT.
Write(pFile);
589 lFlag = lFlag && mReachR.
Write(pFile);
590 lFlag = lFlag && mResist.
Write(pFile);
591 lFlag = lFlag && mPull.
Write(pFile);
592 lFlag = lFlag && mHandPullHips.
Write(pFile);
593 lFlag = lFlag && mTQS.
Write(pFile);
594 lFlag = lFlag && mFloorTQS.
Write(pFile);
598 template<
typename HIKFile>
599 inline bool Read(HIKFile pFile)
603 if(HIKEffectorHeader.
Read(pFile))
605 lFlag = mReachT.
Read(pFile, HIKEffectorHeader.
bSwap);
606 lFlag = lFlag && mReachR.
Read(pFile, HIKEffectorHeader.
bSwap);
607 lFlag = lFlag && mResist.
Read(pFile, HIKEffectorHeader.
bSwap);
608 lFlag = lFlag && mPull.
Read(pFile, HIKEffectorHeader.
bSwap);
609 lFlag = lFlag && mHandPullHips.
Read(pFile, HIKEffectorHeader.
bSwap);
610 lFlag = lFlag && mTQS.
Read(pFile, HIKEffectorHeader.
bSwap);
611 lFlag = lFlag && mFloorTQS.
Read(pFile, HIKEffectorHeader.
bSwap);
623 lEffectorStream.
Init();
625 if(
Read(pFileName, lEffectorStream))
654 lEffectorStream.
Init();
681 return Write(pFileName, lEffectorStream);
698 template<
typename HIKFile>
699 inline bool Write(HIKFile pFile)
const
703 lFlag = HIKPropertySetHeader.
Write(pFile);
704 lFlag = lFlag && mMode.
Write(pFile);
705 lFlag = lFlag && mValue.
Write(pFile);
710 template<
typename HIKFile>
711 inline bool Read(HIKFile pFile)
715 if(HIKPropertySetHeader.
Read(pFile))
717 lFlag = mMode.
Read(pFile, HIKPropertySetHeader.
bSwap);
718 lFlag = lFlag && mValue.
Read(pFile, HIKPropertySetHeader.
bSwap);
733 if(
Read(pFileName, lStream))
793 return Write(pFileName, lStream);
809 mTransformSpace.
Init(0);
818 template<
typename HIKFile>
819 inline bool Write(HIKFile pFile)
const
823 lFlag = HIKDataBlockHeader.
Write(pFile);
824 lFlag = lFlag && mTransformSpace.
Write(pFile);
825 lFlag = lFlag && mTOffset.
Write(pFile);
826 lFlag = lFlag && mQOffset.
Write(pFile);
827 lFlag = lFlag && mSOffset.
Write(pFile);
828 lFlag = lFlag && mStride.
Write(pFile);
829 lFlag = lFlag && mHIKNodeId.
Write(pFile);
834 template<
typename HIKFile>
835 inline bool Read(HIKFile pFile)
839 if(HIKDataBlockHeader.
Read(pFile))
841 lFlag = mTransformSpace.
Read(pFile, HIKDataBlockHeader.
bSwap);
842 lFlag = lFlag && mTOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
843 lFlag = lFlag && mQOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
844 lFlag = lFlag && mSOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
845 lFlag = lFlag && mStride.
Read(pFile, HIKDataBlockHeader.
bSwap);
846 lFlag = lFlag && mHIKNodeId.
Read(pFile, HIKDataBlockHeader.
bSwap);
855 const size_t lPointerSize =
sizeof(
void*);
856 const size_t lRequestedSize = pSize + pAlignment - 1 + lPointerSize;
857 void* lRawPointer = (*pMalloc)(lRequestedSize);
858 void* lStart = (
char*)lRawPointer + lPointerSize;
859 void* lAligned = (
void*)(((
size_t)((
char*)lStart+pAlignment-1)) & ~(pAlignment-1));
860 *(
void**)((
char*)lAligned-lPointerSize) = lRawPointer;
866 void* lRawPointer = *(
void**)((
char*)pAligned-
sizeof(
void*));
867 (*pFree)(lRawPointer);
872 void *lDataBlock =
NULL;
876 if(
Read(pFileName, lStream))
878 pDataDesc.mTransformSpace = lStream.
mTransformSpace.
mField[0] == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;;
892 const size_t align = 16;
918 if(
Write(pFileName, lStream))
921 WriteBlock(pFileName, (
size_t)pDataDesc.mStride, (
size_t)(i-1), pDataBlock);
926 #if !defined(__ghs__) && ( defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__GNUC__) || defined(__SNC__) )
927 #include "hikdump_std.inl"
Defines the distance from the wrist to the inside edge of the model's hand (the side of the thumb)...
void HIKCharacterStateDestroy(HIKCharacterState *pCharacterState, HIKFree pFree)
Destroy HIKCharacterState pCharacterState.
float HIKGetRotationActive(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Reach Rotation constraint for Effector pEffectorIndex.
bool Write(HIKFile pFile) const
Defines the distance from the ankle to the inside edge of the model's foot (the instep).
HIKEffectorSetState * HIKEffectorSetStateCreate(HIKMalloc pMalloc)
Create a new HIKEffectorSetState.
HIKEffectorSetState * HIKLoadEffectorState(const char *pFileName, HIKMalloc pMalloc)
Load file pFileName, and create an HIKEffectorSetState object from its contents.
Defines the distance from the ankle to the middle of the model's foot (its ball, or toe base)...
const char HIKCHARACTERPROPERTY_HEADER[]
Field< int, LastNodeId > mNodeFlag
If your source and target character have their ankles at different heights above the floor...
Defines the distance from the wrist to the outside edge of the model's hand (the side with the pinky)...
bool HIKSaveCharacter(const char *pFileName, HIKCharacter *pCharacter, HIKMalloc pMalloc, HIKFree pFree, float pUnitScale=1.0f)
Save HIKCharacter pCharacter to file pFileName.
void HIKSetParentOffsetfv(HIKCharacter *pCharacter, int pNodeId, const float pParentTOffset[4], const float pParentQOffset[4], const float pParentSOffset[4])
Set the parent offset for Node pNodeId.
Field< float, 2 > mHandPullHips
Field2D< float, LastNodeId, 4 > mTOffset
int HIKGetPropertyMode(HIKPropertySetState *pState, int pPropertyId)
Retrieves the current mode set for property pPropertyId in HIKPropertySetState pState.
bool Write(const char *pFileName, const type &pStream)
Marks the end of the enumeration.
void(* HIKFree)(void *)
Memory de-allocator function.
void HIKGetDefaultState(const HIKCharacter *pCharacter, HIKCharacterState *pCharacterState)
Retrieve the default T-stance for character pCharacter, storing it in HIKCharacterState pCharacterSta...
Marks the end of the enumeration.
float HIKGetHandPullHips(const HIKEffectorSetState *pEffectorSetState, int pLeft)
Retrieve the amount of pull the left or right hand can exert on the hips.
Field< float, LastEffectorId > mResist
void SwapBytes4(char *ToSwap)
Defines the distance from the wrist to the bottom of the model's hand.
float HIKGetTranslationActive(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Reach Translation constraint for Effector pEffectorIndex.
FieldType mField[eCount1][eCount2]
Field< int, 1 > mTransformSpace
bool ReadBlock(const char *pFileName, const size_t pOffset, const size_t &pElementSize, const size_t &pElementCount, type &pStream)
attribute_align(16) Field2D< float
void HIKSetResist(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Resist constraint for Effector pEffectorIndex.
void HIKGetEffectorStateTQSfv(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pT[4], float pQ[4], float pS[4])
Retrieve the translation (T), quaternion rotation (Q) and scaling (S) in global space of Effector pEf...
HIKPropertySetState * HIKPropertySetStateCreate(HIKMalloc pMalloc)
Create a new HIKPropertySetState.
float HIKGetPropertyValue(HIKPropertySetState *pState, int pPropertyId)
Retrieves the current value set for property pPropertyId in HIKPropertySetState pState.
const char HIKCHARACTEREFFECTOR_HEADER[]
void HIKGetNodeStateTQSfv(const HIKCharacter *pCharacter, const HIKCharacterState *pCharacterState, int pNodeId, float pT[4], float pQ[4], float pS[4])
Retrieve the translation (T), quaternion rotation (Q) and scaling (S) in global space of Node pNodeId...
void * HIKDefaultAlignedMalloc(size_t pSize, size_t pAlignment, HIKMalloc pMalloc)
Allocates a data block aligned to the pAlignment pointer boundary.
Defines the distance from the ankle to the outside edge of the model's foot.
void Init(FieldType pValue)
Field2D< float, LastEffectorId, 12 > mTQS
void HIKSetCharacterizeNodeStateTQSfv(HIKCharacter *pCharacter, int pNodeId, const float pT[4], const float pQ[4], const float pS[4])
Set the translation, orientation and scaling for the Node pNodeId when the character is standing in t...
A description of a data set that contains separate translation, quaternion rotation, and scaling values for multiple different Nodes in an HIKCharacterState.
int HIKGetNodeUse(const HIKCharacter *pCharacter, int pNodeId)
Retrieve the characterization flag set for Node pNodeId in HIKCharacter pCharacter.
Defines an HIKEffectorSetState.
Defines the distance from the wrist to the back of the model's hand.
Field2D< float, LastNodeId, 4 > mSOffset
Indicates the end of the list of Nodes.
bool Write(HIKFile pFile) const
Field< int, LastNodeId > mHIKNodeId
bool WriteBlock(const char *pFileName, const size_t &pElementSize, const size_t &pElementCount, type &pStream)
float HIKGetPull(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Pull constraint for Effector pEffectorIndex.
bool Write(HIKFile pFile) const
void HIKSetPropertyValue(HIKPropertySetState *pState, int pPropertyId, float pValue)
Sets the current value for property pPropertyId in HIKPropertySetState pState.
Defines the distance from the wrist to the front end of the model's fingers.
void HIKSetEffectorStateTQSfv(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, const float pT[4], const float pQ[4], const float pS[4])
Set the translation (T), quaternion rotation (Q) and scaling (S) in global space of Effector pEffecto...
void Init(FieldType pValue)
bool HIKCharacterizeGeometry(HIKCharacter *pCharacter)
Set up and initialize character pCharacter for solving.
Field< float, LastEffectorId > mReachT
Header HIKCharStateHeader
The Hips and Chest Offset properties offset the translation of the character's hips and chest along e...
Adjusts the height of the target character's hips.
Field2D< float, HIKLastFloorId, 16 > mFloorTQS
Defines the distance from the ankle to the bottom of the model's foot.
Defines a character's properties.
Adjusts the spacing between the left and right ankles of the target character relative to the source ...
Field< int, HIKLastPropertyId > mMode
Defines the distance from the ankle to the back of the model's foot.
void HIKSetHandPullHips(HIKEffectorSetState *pEffectorSetState, int pLeft, float pValue)
Set the amount of pull the left or right hand can exert on the hips.
Field< float, LastEffectorId > mReachR
void HIKSetTranslationActive(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Reach Translation constraint for Effector pEffectorIndex.
HIKCharacterState * HIKLoadCharacterState(const char *pFileName, HIKCharacter *pCharacter, HIKMalloc pMalloc)
Load file pFileName, and create an HIKCharacterState object from its contents.
bool Write(HIKFile pFile) const
Field< float, LastEffectorId > mPull
Defines the distance from the wrist to the middle of the model's hand (its knuckles, or finger base).
void HIKGetParentOffsetfv(const HIKCharacter *pCharacter, int pNodeId, float pParentTOffset[4], float pParentQOffset[4], float pParentSOffset[4])
Retrieve the parent offset set for Node pNodeId.
HIKCharacter * HIKLoadCharacter(const char *pFileName, const char *pValidationString, HIKMalloc pMalloc)
Load file pFileName, and create an HIKCharacter object from its contents.
void * HIKLoadDataBlock(const char *pFileName, HIKDataDescription &pDataDesc, HIKMalloc pMalloc)
Load file pFileName, and create a data set from its contents according to the data description provid...
const char HIKCHARACTERSTATE_HEADER[]
bool Read(const char *pFileName, type &pStream)
Field2D< float, LastNodeId, 4 > mParentSOffset
Header HIKDataBlockHeader
Defines a pose for a character.
const char HIKCHARACTER_HEADER[]
HIKCharacterState * HIKCharacterStateCreate(const HIKCharacter *pCharacter, HIKMalloc pMalloc)
Create a new HIKCharacterState.
Field< int, 1 > mTransformMode
Field2D< float, LastNodeId, 4 > mQOffset
Defines the distance from the ankle to the front end of the model's toes.
float HIKGetResist(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Resist constraint for Effector pEffectorIndex.
Node has a parent unknown to HumanIK, used for local space transform and DoF.
void *(* HIKMalloc)(size_t)
Memory allocator function.
Header HIKPropertySetHeader
void HIKSetPull(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Pull constraint for Effector pEffectorIndex.
int strcpy_s(char *dst, size_t, const char *src)
Field< int, LastNodeId > mNodeId
bool HIKGetCharacterDefinitionFromDump(const char *pFileName, HIKCharacterDefinition &pDef)
const char HIKCHARACTERDATABLOCK_HEADER[]
Node is not characterized.
void HIKSaveDataBlock(const char *pFileName, const HIKDataDescription &pDataDesc, const void *pDataBlock)
Save the data set located in memory at pDataBlock to file pFileName.
bool Read(HIKFile pFile, bool bSwap)
void HIKSetPropertyMode(HIKPropertySetState *pState, int pPropertyId, int pMode)
Sets the current mode for property pPropertyId in HIKPropertySetState pState.
void HIKSetCharacterStateTransformTQS(const HIKCharacter *pCharacter, HIKCharacterState *pCharacterState, const HIKDataDescription *pDataDescription, const void *pDataSet)
Set the translation (T), quaternion rotation (Q) and scaling (S) of multiple Nodes from data set pDat...
void HIKDefaultAlignedFree(void *pAligned, HIKFree pFree)
Frees a data block allocated using HIKDefaultAlignedMalloc().
void HIKGetCharacterStateTransformTQS(const HIKCharacter *pCharacter, HIKCharacterState *pCharacterState, const HIKDataDescription *pDataDescription, void *pDataSet)
Retrieve the translation (T), quaternion rotation (Q) and scaling (S) of multiple Nodes from HIKChara...
Marks the end of the enumeration.
Defines which Nodes are to be used by an HIKCharacter.
Field2D< float, LastNodeId, 4 > mParentQOffset
Defines a character to be used with HumanIK.
bool Write(HIKFile pFile) const
bool Write(HIKFile pFile) const
void HIKSetRotationActive(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Reach Rotation constraint for Effector pEffectorIndex.
Field2D< float, LastNodeId, 4 > mParentTOffset
bool HIKSaveCharacterState(const char *pFileName, HIKCharacter *pCharacter, HIKCharacterState *pState, int pTransformMode, float pUnitScale=1.0f)
Save HIKCharacterState pState to file pFileName.
bool HIKSavePropertySetState(const char *pFileName, HIKPropertySetState *pState, float pUnitScale=1.0f)
Save HIKPropertySetState pState to file pFileName.
Field< float, HIKLastPropertyId > mValue
bool Write(HIKFile pFile) const
bool Read(HIKFile pFile, bool bSwap)
bool HIKSaveEffectorState(const char *pFileName, HIKEffectorSetState *pState, float pUnitScale=1.0f)
Save HIKEffectorSetState pState to file pFileName.
Marks the end of the enumeration.
HIKCharacter * HIKCharacterCreate(const HIKCharacterDefinition *pCharacterDefinition, HIKMalloc pMalloc, const char *pValidationString)
Create a new HIKCharacter.
HIKPropertySetState * HIKLoadPropertySetState(const char *pFileName, HIKMalloc pMalloc)
Load file pFileName, and create an HIKPropertySetState object from its contents.