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) { strcpy(HeaderStr, _Header); }
211 template<
typename HIKFile>
212 inline bool Write(HIKFile pFile)
const;
214 template<
typename HIKFile>
215 inline bool Read(HIKFile pFile);
218 template<
typename type>
bool Write(
const char* pFileName,
const type& pStream);
219 template<
typename type>
bool WriteBlock(
const char* pFileName,
const size_t& pElementSize,
const size_t& pElementCount,
type& pStream);
221 template<
typename type>
bool Read(
const char* pFileName,
type& pStream);
222 template<
typename type>
bool ReadBlock(
const char* pFileName,
const size_t pOffset,
const size_t& pElementSize,
const size_t& pElementCount,
type& pStream);
229 ToSwap[0] = ToSwap[3];
232 ToSwap[1] = ToSwap[2];
236 template<
typename type,
int count>
class Field
245 inline void Init(FieldType
pValue) { memset(mField, (
int)pValue,
sizeof(FieldType)*
eCount); }
247 template<
typename HIKFile>
248 inline bool Write(HIKFile pFile)
const;
250 template<
typename HIKFile>
251 inline bool Read(HIKFile pFile,
bool bSwap);
254 template<
typename type,
int count1,
int count2>
class Field2D
265 inline void Init(FieldType
pValue) { memset(mField, (
int)pValue,
sizeof(FieldType)*
eCount); }
267 template<
typename HIKFile>
268 inline bool Write(HIKFile pFile)
const;
270 template<
typename HIKFile>
271 inline bool Read(HIKFile pFile,
bool bSwap);
294 mParentTOffset.
Init(0.0f);
295 mParentQOffset.
Init(0.0f);
296 mParentSOffset.
Init(0.0f);
299 template<
typename HIKFile>
300 inline bool Write(HIKFile pFile)
const
304 lFlag = HIKCharHeader.
Write(pFile);
305 lFlag = lFlag && mNodeFlag.
Write(pFile);
306 lFlag = lFlag && mTOffset.
Write(pFile);
307 lFlag = lFlag && mQOffset.
Write(pFile);
308 lFlag = lFlag && mSOffset.
Write(pFile);
309 lFlag = lFlag && mParentTOffset.
Write(pFile);
310 lFlag = lFlag && mParentQOffset.
Write(pFile);
311 lFlag = lFlag && mParentSOffset.
Write(pFile);
316 template<
typename HIKFile>
317 inline bool Read(HIKFile pFile)
321 if(HIKCharHeader.
Read(pFile))
323 lFlag = mNodeFlag.
Read(pFile, HIKCharHeader.
bSwap);
324 lFlag = lFlag && mTOffset.
Read(pFile, HIKCharHeader.
bSwap);
325 lFlag = lFlag && mQOffset.
Read(pFile, HIKCharHeader.
bSwap);
326 lFlag = lFlag && mSOffset.
Read(pFile, HIKCharHeader.
bSwap);
327 lFlag = lFlag && mParentTOffset.
Read(pFile, HIKCharHeader.
bSwap);
328 lFlag = lFlag && mParentQOffset.
Read(pFile, HIKCharHeader.
bSwap);
329 lFlag = lFlag && mParentSOffset.
Read(pFile, HIKCharHeader.
bSwap);
345 if(
Read(pFileName, lStream))
354 const char* pValidationString,
365 if(
Read(pFileName, lStream))
434 return Write(pFileName, lStream);
447 mTransformMode.
Init(0);
449 mTransformData.
Init(0.0f);
453 template<
typename HIKFile>
454 inline bool Write(HIKFile pFile)
const
459 lFlag = lFlag && mTransformMode.
Write(pFile);
460 lFlag = lFlag && mNodeId.
Write(pFile);
466 template<
typename HIKFile>
467 inline bool Read(HIKFile pFile)
490 if(
Read(pFileName, lStateStream))
496 lDataDesc.mTransformSpace = lStateStream.
mTransformMode.
mField[0] == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;
497 lDataDesc.mTOffset = 0;
498 lDataDesc.mQOffset = 16;
499 lDataDesc.mSOffset = 32;
500 lDataDesc.mStride = 48;
515 lDataDesc.mTransformSpace = pTransformMode == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;
516 lDataDesc.mTOffset = 0;
517 lDataDesc.mQOffset = 16;
518 lDataDesc.mSOffset = 32;
519 lDataDesc.mStride = 48;
547 return Write(pFileName, lStateStream);
569 mHandPullHips.
Init(0.0f);
571 mFloorTQS.
Init(0.0f);
575 template<
typename HIKFile>
576 inline bool Write(HIKFile pFile)
const
580 lFlag = HIKEffectorHeader.
Write(pFile);
581 lFlag = lFlag && mReachT.
Write(pFile);
582 lFlag = lFlag && mReachR.
Write(pFile);
583 lFlag = lFlag && mResist.
Write(pFile);
584 lFlag = lFlag && mPull.
Write(pFile);
585 lFlag = lFlag && mHandPullHips.
Write(pFile);
586 lFlag = lFlag && mTQS.
Write(pFile);
587 lFlag = lFlag && mFloorTQS.
Write(pFile);
591 template<
typename HIKFile>
592 inline bool Read(HIKFile pFile)
596 if(HIKEffectorHeader.
Read(pFile))
598 lFlag = mReachT.
Read(pFile, HIKEffectorHeader.
bSwap);
599 lFlag = lFlag && mReachR.
Read(pFile, HIKEffectorHeader.
bSwap);
600 lFlag = lFlag && mResist.
Read(pFile, HIKEffectorHeader.
bSwap);
601 lFlag = lFlag && mPull.
Read(pFile, HIKEffectorHeader.
bSwap);
602 lFlag = lFlag && mHandPullHips.
Read(pFile, HIKEffectorHeader.
bSwap);
603 lFlag = lFlag && mTQS.
Read(pFile, HIKEffectorHeader.
bSwap);
604 lFlag = lFlag && mFloorTQS.
Read(pFile, HIKEffectorHeader.
bSwap);
616 lEffectorStream.
Init();
618 if(
Read(pFileName, lEffectorStream))
647 lEffectorStream.
Init();
674 return Write(pFileName, lEffectorStream);
691 template<
typename HIKFile>
692 inline bool Write(HIKFile pFile)
const
696 lFlag = HIKPropertySetHeader.
Write(pFile);
697 lFlag = lFlag && mMode.
Write(pFile);
698 lFlag = lFlag && mValue.
Write(pFile);
703 template<
typename HIKFile>
704 inline bool Read(HIKFile pFile)
708 if(HIKPropertySetHeader.
Read(pFile))
710 lFlag = mMode.
Read(pFile, HIKPropertySetHeader.
bSwap);
711 lFlag = lFlag && mValue.
Read(pFile, HIKPropertySetHeader.
bSwap);
726 if(
Read(pFileName, lStream))
786 return Write(pFileName, lStream);
802 mTransformSpace.
Init(0);
811 template<
typename HIKFile>
812 inline bool Write(HIKFile pFile)
const
816 lFlag = HIKDataBlockHeader.
Write(pFile);
817 lFlag = lFlag && mTransformSpace.
Write(pFile);
818 lFlag = lFlag && mTOffset.
Write(pFile);
819 lFlag = lFlag && mQOffset.
Write(pFile);
820 lFlag = lFlag && mSOffset.
Write(pFile);
821 lFlag = lFlag && mStride.
Write(pFile);
822 lFlag = lFlag && mHIKNodeId.
Write(pFile);
827 template<
typename HIKFile>
828 inline bool Read(HIKFile pFile)
832 if(HIKDataBlockHeader.
Read(pFile))
834 lFlag = mTransformSpace.
Read(pFile, HIKDataBlockHeader.
bSwap);
835 lFlag = lFlag && mTOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
836 lFlag = lFlag && mQOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
837 lFlag = lFlag && mSOffset.
Read(pFile, HIKDataBlockHeader.
bSwap);
838 lFlag = lFlag && mStride.
Read(pFile, HIKDataBlockHeader.
bSwap);
839 lFlag = lFlag && mHIKNodeId.
Read(pFile, HIKDataBlockHeader.
bSwap);
848 const size_t lPointerSize =
sizeof(
void*);
849 const size_t lRequestedSize = pSize + pAlignment - 1 + lPointerSize;
850 void* lRawPointer = (*pMalloc)(lRequestedSize);
851 void* lStart = (
char*)lRawPointer + lPointerSize;
852 void* lAligned = (
void*)(((
size_t)((
char*)lStart+pAlignment-1)) & ~(pAlignment-1));
853 *(
void**)((
char*)lAligned-lPointerSize) = lRawPointer;
859 void* lRawPointer = *(
void**)((
char*)pAligned-
sizeof(
void*));
860 (*pFree)(lRawPointer);
865 void *lDataBlock =
NULL;
869 if(
Read(pFileName, lStream))
871 pDataDesc.mTransformSpace = lStream.
mTransformSpace.
mField[0] == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;;
885 const size_t align = 16;
911 if(
Write(pFileName, lStream))
914 WriteBlock(pFileName, (
size_t)pDataDesc.mStride, (
size_t)(i-1), pDataBlock);
919 #if !defined(__ghs__) && ( defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__GNUC__) || defined(__SNC__) )
920 #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.
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.