HIK2014/humanik/hikdump.h Source File

hikdump.h
Go to the documentation of this file.
1 
11 /**************************************************************************************
12 
13 Copyright (C) 2009 Autodesk, Inc.
14 All Rights Reserved.
15 
16 The coded instructions, statements, computer programs, and/or related material (collectively "Data")
17 in these files contain unpublished information proprietary to Autodesk, Inc., ("Autodesk") which is
18 protected by Canada and United States of America federal copyright law and by international treaties.
19 
20 The Data may not be disclosed or distributed to third parties, in whole or in part, without the prior
21 written consent of Autodesk.
22 
23 THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY. ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED.
24 AUTODESK MAKES NO WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING BY CUSTOM
25 OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY OR
26 FITNESS FOR A PARTICULAR PURPOSE OR USE. WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT
27 THE OPERATION OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE.
28 
29 IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS OR SUPPLIERS ("AUTODESK GROUP")
30 BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR
31 MULTIPLE DAMAGES OR OTHER SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
32 OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND), HOWEVER CAUSED, AND REGARDLESS
33 OF THE THEORY OF LIABILITY, WHETHER DERIVED FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO,
34 NEGLIGENCE), OR OTHERWISE, ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
35 WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS OR DAMAGE.
36 
37 **************************************************************************************/
38 
39 #ifndef HUMANIK_DUMP
40 #define HUMANIK_DUMP
41 
42 #ifndef _CRT_SECURE_NO_WARNINGS
43 #define _CRT_SECURE_NO_WARNINGS
44 #endif
45 
46 #include "humanik.h"
47 #include "hikproperty.h"
48 
49 #include <stdio.h>
50 #include <stddef.h>
51 #include <string.h>
52 
53 #if defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__ICL)
54  #include <malloc.h>
55  #define attribute_align(a) __declspec(align(a))
56 #elif defined(__GNUC__) || defined(__SNC__) || defined(__MWERKS__)
57  #include <stdlib.h>
58  #define attribute_align(a) __attribute__ ((aligned(a)))
59 #endif
60 
61 
62 
63 /* *********************************************** */
80 HIKCharacter* HIKLoadCharacter(const char* pFileName, const char* pValidationString, HIKMalloc pMalloc);
81 
93 bool HIKSaveCharacter(const char* pFileName, HIKCharacter* pCharacter, HIKMalloc pMalloc, HIKFree pFree, float pUnitScale = 1.0f);
94 
103 HIKCharacterState* HIKLoadCharacterState(const char* pFileName, HIKCharacter* pCharacter, HIKMalloc pMalloc);
104 
114 bool HIKSaveCharacterState(const char* pFileName, HIKCharacter* pCharacter, HIKCharacterState* pState, int pTransformMode, float pUnitScale = 1.0f);
115 
122 HIKEffectorSetState* HIKLoadEffectorState(const char* pFileName, HIKMalloc pMalloc);
123 
130 bool HIKSaveEffectorState(const char* pFileName, HIKEffectorSetState* pState, float pUnitScale = 1.0f);
131 
138 HIKPropertySetState* HIKLoadPropertySetState(const char* pFileName, HIKMalloc pMalloc);
139 
146 bool HIKSavePropertySetState(const char* pFileName, HIKPropertySetState* pState, float pUnitScale = 1.0f);
147 
158 void* HIKLoadDataBlock(const char* pFileName, HIKDataDescription& pDataDesc, HIKMalloc pMalloc);
159 
170 void* HIKDefaultAlignedMalloc(size_t pSize, size_t pAlignment, HIKMalloc pMalloc);
171 
178 void HIKDefaultAlignedFree(void* pAligned, HIKFree pFree);
179 
189 void HIKSaveDataBlock(const char* pFileName, const HIKDataDescription& pDataDesc, const void* pDataBlock);
190 
191 //Headers are 16 characters long
192 #define HEADERLENGTH 16
193 //123456789012345
194 const char HIKCHARACTER_HEADER[] = "HIKCHARACTER000\0";
195 const char HIKCHARACTERSTATE_HEADER[] = "HIKSTATE0000000\0";
196 const char HIKCHARACTEREFFECTOR_HEADER[] = "HIKEFFECTOR0000\0";
197 const char HIKCHARACTERPROPERTY_HEADER[] = "HIKPROPERTY0000\0";
198 const char HIKCHARACTERDATABLOCK_HEADER[] = "HIKDATABLOCK000\0";
199 const int MagicNumber = 0xabcdef12;
200 
201 class Header
202 {
203  char HeaderStr[HEADERLENGTH];
204 
205 public:
206  bool bSwap;
207 
208  Header():bSwap(false) {}
209  inline void Init(const char *_Header) { strcpy(HeaderStr, _Header); }
210 
211  template<typename HIKFile>
212  inline bool Write(HIKFile pFile) const;
213 
214  template<typename HIKFile>
215  inline bool Read(HIKFile pFile);
216 };
217 
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);
220 
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);
223 
224 inline void SwapBytes4(char* ToSwap)
225 {
226  char temp;
227 
228  temp = ToSwap[0];
229  ToSwap[0] = ToSwap[3];
230  ToSwap[3] = temp;
231  temp = ToSwap[1];
232  ToSwap[1] = ToSwap[2];
233  ToSwap[2] = temp;
234 }
235 
236 template<typename type, int count> class Field
237 {
238 public:
239  typedef type FieldType;
240  enum{
242  };
243  FieldType mField[eCount];
244 
245  inline void Init(FieldType pValue) { memset(mField, (int)pValue, sizeof(FieldType)*eCount); }
246 
247  template<typename HIKFile>
248  inline bool Write(HIKFile pFile) const;
249 
250  template<typename HIKFile>
251  inline bool Read(HIKFile pFile, bool bSwap);
252 };
253 
254 template<typename type, int count1, int count2> class Field2D
255 {
256 public:
257  typedef type FieldType;
258  enum{
259  eCount1 = count1,
260  eCount2 = count2,
262  };
263  FieldType mField[eCount1][eCount2];
264 
265  inline void Init(FieldType pValue) { memset(mField, (int)pValue, sizeof(FieldType)*eCount); }
266 
267  template<typename HIKFile>
268  inline bool Write(HIKFile pFile) const;
269 
270  template<typename HIKFile>
271  inline bool Read(HIKFile pFile, bool bSwap);
272 };
273 
275 {
276 public:
285 
286  inline void Init()
287  {
288  HIKCharHeader.Init(HIKCHARACTER_HEADER);
289 
290  mNodeFlag.Init(HIKNodeNotUsed);
291  mTOffset.Init(0.0f);
292  mQOffset.Init(0.0f);
293  mSOffset.Init(0.0f);
294  mParentTOffset.Init(0.0f);
295  mParentQOffset.Init(0.0f);
296  mParentSOffset.Init(0.0f);
297  }
298 
299  template<typename HIKFile>
300  inline bool Write(HIKFile pFile) const
301  {
302  bool lFlag = false;
303 
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);
312 
313  return lFlag;
314  }
315 
316  template<typename HIKFile>
317  inline bool Read(HIKFile pFile)
318  {
319  bool lFlag = false;
320 
321  if(HIKCharHeader.Read(pFile))
322  {
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);
330  }
331 
332  return lFlag;
333  }
334 };
335 
336 inline bool HIKGetCharacterDefinitionFromDump(const char* pFileName, HIKCharacterDefinition& pDef)
337 {
338  // First let retrieve data
339  // We need characterization flag, Default stance pose and Parent offset
340  HIKCharacterStream lStream;
341 
342  lStream.Init();
343 
344  // Load all the data
345  if(Read(pFileName, lStream))
346  {
347  memcpy(pDef.mUsedNodes, lStream.mNodeFlag.mField, sizeof(int)*lStream.mNodeFlag.eCount);
348  return true;
349  }
350  return false;
351 }
352 
353 inline HIKCharacter* HIKLoadCharacter(const char* pFileName,
354  const char* pValidationString,
355  HIKMalloc pMalloc)
356 {
357  // First let retrieve data
358  // We need characterization flag, Default stance pose and Parent offset
359  HIKCharacterStream lStream;
360  HIKCharacter* lCharacter = NULL;
361 
362  lStream.Init();
363 
364  // Load all the data
365  if(Read(pFileName, lStream))
366  {
368 
369  memcpy(lDef.mUsedNodes, lStream.mNodeFlag.mField, sizeof(int)*lStream.mNodeFlag.eCount);
370 
371  lCharacter = HIKCharacterCreate(&lDef, pMalloc, pValidationString);
372  if (!lCharacter)
373  return NULL;
374  int i;
375  for(i=0;i<LastNodeId;i++)
376  {
377  if(lDef.mUsedNodes[i] & HIKNodeUsed)
378  {
379  HIKSetCharacterizeNodeStateTQSfv(lCharacter, i, &lStream.mTOffset.mField[i][0], &lStream.mQOffset.mField[i][0], &lStream.mSOffset.mField[i][0]);
380  }
381 
382  if(lDef.mUsedNodes[i] & HIKNodeParentOffset)
383  {
384  HIKSetParentOffsetfv(lCharacter, i, &lStream.mParentTOffset.mField[i][0], &lStream.mParentQOffset.mField[i][0], &lStream.mParentSOffset.mField[i][0]);
385  }
386  }
387 
388  HIKCharacterizeGeometry(lCharacter);
389  }
390  return lCharacter;
391 }
392 
393 inline bool HIKSaveCharacter(const char* pFileName, HIKCharacter* pCharacter, HIKMalloc pMalloc, HIKFree pFree, float pUnitScale)
394 {
395  // First let prepare data to save
396  // We need characterization flag, Default stance pose and Parent offset
397  HIKCharacterStream lStream;
398 
399  lStream.Init();
400 
401  int i;
402  for(i=0;i<LastNodeId;i++)
403  {
404  lStream.mNodeFlag.mField[i] = HIKGetNodeUse(pCharacter, i);
405  }
406 
407  for(i=0;i<LastNodeId;i++)
408  {
409  if(lStream.mNodeFlag.mField[i] & HIKNodeParentOffset)
410  {
411  HIKGetParentOffsetfv(pCharacter, i, &lStream.mParentTOffset.mField[i][0], &lStream.mParentQOffset.mField[i][0], &lStream.mParentSOffset.mField[i][0]);
412  lStream.mParentTOffset.mField[i][0] *= pUnitScale;
413  lStream.mParentTOffset.mField[i][1] *= pUnitScale;
414  lStream.mParentTOffset.mField[i][2] *= pUnitScale;
415  }
416  }
417 
418  HIKCharacterState* lState = HIKCharacterStateCreate(pCharacter, pMalloc);
419  HIKGetDefaultState(pCharacter, lState);
420 
421  for(i=0;i<LastNodeId;i++)
422  {
423  if(lStream.mNodeFlag.mField[i] & HIKNodeUsed)
424  {
425  HIKGetNodeStateTQSfv(pCharacter, lState, i, &lStream.mTOffset.mField[i][0], &lStream.mQOffset.mField[i][0], &lStream.mSOffset.mField[i][0]);
426  lStream.mTOffset.mField[i][0] *= pUnitScale;
427  lStream.mTOffset.mField[i][1] *= pUnitScale;
428  lStream.mTOffset.mField[i][2] *= pUnitScale;
429  }
430  }
431 
432  HIKCharacterStateDestroy(lState , pFree);
433 
434  return Write(pFileName, lStream);
435 }
436 
438 {
439 public:
444 
445  inline void Init()
446  {
447  mTransformMode.Init(0);
448  mNodeId.Init(HIKLastNode);
449  mTransformData.Init(0.0f);
450  HIKCharStateHeader.Init(HIKCHARACTERSTATE_HEADER);
451  }
452 
453  template<typename HIKFile>
454  inline bool Write(HIKFile pFile) const
455  {
456  bool lFlag = false;
457 
458  lFlag = HIKCharStateHeader.Write(pFile);
459  lFlag = lFlag && mTransformMode.Write(pFile);
460  lFlag = lFlag && mNodeId.Write(pFile);
461  lFlag = lFlag && mTransformData.Write(pFile);
462 
463  return lFlag;
464  }
465 
466  template<typename HIKFile>
467  inline bool Read(HIKFile pFile)
468  {
469  bool lFlag = false;
470 
471  if(HIKCharStateHeader.Read(pFile))
472  {
473  lFlag = mTransformMode.Read(pFile, HIKCharStateHeader.bSwap);
474  lFlag = lFlag && mNodeId.Read(pFile, HIKCharStateHeader.bSwap);
475  lFlag = lFlag && mTransformData.Read(pFile, HIKCharStateHeader.bSwap);
476  }
477 
478  return lFlag;
479  }
480 };
481 
482 
483 inline HIKCharacterState* HIKLoadCharacterState(const char* pFileName, HIKCharacter* pCharacter, HIKMalloc pMalloc)
484 {
485  HIKCharacterStateStream lStateStream;
486  HIKCharacterState* lState = NULL;
487 
488  lStateStream.Init();
489 
490  if(Read(pFileName, lStateStream))
491  {
492  lState = HIKCharacterStateCreate(pCharacter, pMalloc);
493 
494  HIKDataDescription lDataDesc;
495 
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;
501  lDataDesc.mHIKNodeId = &lStateStream.mNodeId.mField[0];
502 
503  HIKSetCharacterStateTransformTQS(pCharacter, lState, &lDataDesc, &lStateStream.mTransformData);
504  }
505  return lState;
506 }
507 
508 inline bool HIKSaveCharacterState(const char* pFileName, HIKCharacter* pCharacter, HIKCharacterState* pState, int pTransformMode, float pUnitScale)
509 {
510  HIKCharacterStateStream lStateStream;
511  HIKDataDescription lDataDesc;
512 
513  lStateStream.Init();
514 
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;
520  lDataDesc.mHIKNodeId = &lStateStream.mNodeId.mField[0];
521 
522  // First let prepare data to save
523  // We need transform mode and all joint transform
524  int i, lLastId = 0;
525  for(i=0;i<LastNodeId;i++)
526  {
527  if( HIKGetNodeUse(pCharacter, i) & HIKNodeUsed)
528  {
529  lStateStream.mNodeId.mField[lLastId++] = i;
530  }
531  }
532 
533  lStateStream.mNodeId.mField[lLastId] = HIKLastNode;
534  lStateStream.mTransformMode.mField[0] = pTransformMode;
535 
536  HIKGetCharacterStateTransformTQS(pCharacter, pState, &lDataDesc, &lStateStream.mTransformData);
537  for(i=0;i<LastNodeId;i++)
538  {
539  //if(HIKGetNodeUse(pCharacter, i) & HIKNodeUsed)
540  {
541  lStateStream.mTransformData.mField[i][0] *= pUnitScale;
542  lStateStream.mTransformData.mField[i][1] *= pUnitScale;
543  lStateStream.mTransformData.mField[i][2] *= pUnitScale;
544  }
545  }
546 
547  return Write(pFileName, lStateStream);
548 }
549 
551 {
552 public:
558 
562 
563  inline void Init()
564  {
565  mReachT.Init(0.0f);
566  mReachR.Init(0.0f);
567  mResist.Init(0.0f);
568  mPull.Init(0.0f);
569  mHandPullHips.Init(0.0f);
570  mTQS.Init(0.0f);
571  mFloorTQS.Init(0.0f);
572  HIKEffectorHeader.Init(HIKCHARACTEREFFECTOR_HEADER);
573  }
574 
575  template<typename HIKFile>
576  inline bool Write(HIKFile pFile) const
577  {
578  bool lFlag = false;
579 
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);
588  return lFlag;
589  }
590 
591  template<typename HIKFile>
592  inline bool Read(HIKFile pFile)
593  {
594  bool lFlag = false;
595 
596  if(HIKEffectorHeader.Read(pFile))
597  {
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);
605  }
606 
607  return lFlag;
608  }
609 };
610 
611 inline HIKEffectorSetState* HIKLoadEffectorState(const char* pFileName, HIKMalloc pMalloc)
612 {
613  HIKEffectorSetStateStream lEffectorStream;
614  HIKEffectorSetState* lState = NULL;
615 
616  lEffectorStream.Init();
617 
618  if(Read(pFileName, lEffectorStream))
619  {
620  lState = HIKEffectorSetStateCreate(pMalloc);
621 
622  int i;
623  for(i=0;i<LastEffectorId;i++)
624  {
625  HIKSetTranslationActive(lState, i, lEffectorStream.mReachT.mField[i]);
626  HIKSetRotationActive(lState, i, lEffectorStream.mReachR.mField[i]);
627  HIKSetResist(lState, i, lEffectorStream.mResist.mField[i]);
628  HIKSetPull(lState, i, lEffectorStream.mPull.mField[i]);
629  HIKSetEffectorStateTQSfv(lState, i, &lEffectorStream.mTQS.mField[i][0],&lEffectorStream.mTQS.mField[i][4], &lEffectorStream.mTQS.mField[i][8]);
630  }
631 
632  HIKSetHandPullHips(lState, 0, lEffectorStream.mHandPullHips.mField[0]);
633  HIKSetHandPullHips(lState, 1, lEffectorStream.mHandPullHips.mField[1]);
634 
635  for(i=0;i<HIKLastFloorId;i++)
636  {
637  HIKSetEffectorFloorStatefv(lState, i, &lEffectorStream.mFloorTQS.mField[i][0]);
638  }
639 
640  }
641  return lState;
642 }
643 
644 inline bool HIKSaveEffectorState(const char* pFileName, HIKEffectorSetState* pState, float pUnitScale)
645 {
646  HIKEffectorSetStateStream lEffectorStream;
647  lEffectorStream.Init();
648 
649  int i;
650  for(i=0;i<LastEffectorId;i++)
651  {
652  lEffectorStream.mReachT.mField[i] = HIKGetTranslationActive(pState, i);
653  lEffectorStream.mReachR.mField[i] = HIKGetRotationActive(pState, i);
654  lEffectorStream.mResist.mField[i] = HIKGetResist(pState, i);
655  lEffectorStream.mPull.mField[i] = HIKGetPull(pState, i);
656 
657  HIKGetEffectorStateTQSfv(pState, i, &lEffectorStream.mTQS.mField[i][0], &lEffectorStream.mTQS.mField[i][4], &lEffectorStream.mTQS.mField[i][8]);
658  lEffectorStream.mTQS.mField[i][0] *= pUnitScale;
659  lEffectorStream.mTQS.mField[i][1] *= pUnitScale;
660  lEffectorStream.mTQS.mField[i][2] *= pUnitScale;
661  }
662 
663  lEffectorStream.mHandPullHips.mField[0] = HIKGetHandPullHips(pState, 0);
664  lEffectorStream.mHandPullHips.mField[1] = HIKGetHandPullHips(pState, 1);
665 
666  for(i=0;i<HIKLastFloorId;i++)
667  {
668  HIKGetEffectorFloorStatefv(pState, i, &lEffectorStream.mFloorTQS.mField[i][0]);
669  lEffectorStream.mFloorTQS.mField[i][0] *= pUnitScale;
670  lEffectorStream.mFloorTQS.mField[i][1] *= pUnitScale;
671  lEffectorStream.mFloorTQS.mField[i][2] *= pUnitScale;
672  }
673 
674  return Write(pFileName, lEffectorStream);
675 }
676 
678 {
679 public:
683 
684  inline void Init()
685  {
686  mMode.Init(0);
687  mValue.Init(0.0f);
688  HIKPropertySetHeader.Init(HIKCHARACTERPROPERTY_HEADER);
689  }
690 
691  template<typename HIKFile>
692  inline bool Write(HIKFile pFile) const
693  {
694  bool lFlag = false;
695 
696  lFlag = HIKPropertySetHeader.Write(pFile);
697  lFlag = lFlag && mMode.Write(pFile);
698  lFlag = lFlag && mValue.Write(pFile);
699 
700  return lFlag;
701  }
702 
703  template<typename HIKFile>
704  inline bool Read(HIKFile pFile)
705  {
706  bool lFlag = false;
707 
708  if(HIKPropertySetHeader.Read(pFile))
709  {
710  lFlag = mMode.Read(pFile, HIKPropertySetHeader.bSwap);
711  lFlag = lFlag && mValue.Read(pFile, HIKPropertySetHeader.bSwap);
712  }
713 
714  return lFlag;
715  }
716 
717 };
718 
719 inline HIKPropertySetState* HIKLoadPropertySetState(const char* pFileName, HIKMalloc pMalloc)
720 {
721  HIKPropertySetStream lStream;
722  HIKPropertySetState* lState = NULL;
723 
724  lStream.Init();
725 
726  if(Read(pFileName, lStream))
727  {
728  lState = HIKPropertySetStateCreate(pMalloc);
729 
730  int i;
731  for(i=0;i<HIKLastPropertyId;i++)
732  {
733  HIKSetPropertyMode(lState, i, lStream.mMode.mField[i]);
734  HIKSetPropertyValue(lState, i, lStream.mValue.mField[i]);
735  }
736  }
737 
738  return lState;
739 }
740 
741 inline bool HIKSavePropertySetState(const char* pFileName, HIKPropertySetState* pState, float pUnitScale)
742 {
743  HIKPropertySetStream lStream;
744  lStream.Init();
745 
746  int i;
747  for(i=0;i<HIKLastPropertyId;i++)
748  {
749  lStream.mMode.mField[i] = HIKGetPropertyMode(pState, i);
750  lStream.mValue.mField[i] = HIKGetPropertyValue(pState, i);
751 
752  // Handle unitScale
753 
754  switch(i)
755  {
756  case HIKHipsTOffsetXId :
757  case HIKHipsTOffsetYId :
758  case HIKHipsTOffsetZId :
759  case HIKChestTOffsetXId :
760  case HIKChestTOffsetYId :
761  case HIKChestTOffsetZId :
762 
764  case HIKFootBackToAnkleId :
767  case HIKFootInToAnkleId :
768  case HIKFootOutToAnkleId :
769 
771  case HIKHandBackToWristId :
774  case HIKHandInToWristId :
775  case HIKHandOutToWristId :
776 
780 
781  lStream.mValue.mField[i] *= pUnitScale;
782  break;
783  }
784  }
785 
786  return Write(pFileName, lStream);
787 }
788 
790 {
791 public:
799 
800  inline void Init()
801  {
802  mTransformSpace.Init(0);
803  mTOffset.Init(0);
804  mQOffset.Init(0);
805  mSOffset.Init(0);
806  mStride.Init(0);
807  mHIKNodeId.Init(0);
808  HIKDataBlockHeader.Init(HIKCHARACTERDATABLOCK_HEADER);
809  }
810 
811  template<typename HIKFile>
812  inline bool Write(HIKFile pFile) const
813  {
814  bool lFlag = false;
815 
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);
823 
824  return lFlag;
825  }
826 
827  template<typename HIKFile>
828  inline bool Read(HIKFile pFile)
829  {
830  bool lFlag = false;
831 
832  if(HIKDataBlockHeader.Read(pFile))
833  {
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);
840  }
841 
842  return lFlag;
843  }
844 };
845 
846 inline void* HIKDefaultAlignedMalloc(size_t pSize, size_t pAlignment, HIKMalloc pMalloc)
847 {
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;
854  return lAligned;
855 }
856 
857 inline void HIKDefaultAlignedFree(void* pAligned, HIKFree pFree)
858 {
859  void* lRawPointer = *(void**)((char*)pAligned-sizeof(void*));
860  (*pFree)(lRawPointer);
861 }
862 
863 inline void* HIKLoadDataBlock(const char* pFileName, HIKDataDescription& pDataDesc, HIKMalloc pMalloc)
864 {
865  void *lDataBlock = NULL;
866  HIKDataDescriptionStream lStream;
867  lStream.Init();
868 
869  if(Read(pFileName, lStream))
870  {
871  pDataDesc.mTransformSpace = lStream.mTransformSpace.mField[0] == HIKDataDescription::HIKLocalSpace ? HIKDataDescription::HIKLocalSpace : HIKDataDescription::HIKGlobalSpace;;
872  pDataDesc.mTOffset = (size_t)lStream.mTOffset.mField[0];
873  pDataDesc.mQOffset = (size_t)lStream.mQOffset.mField[0];
874  pDataDesc.mSOffset = (size_t)lStream.mSOffset.mField[0];
875  pDataDesc.mStride = (size_t)lStream.mStride.mField[0];
876 
877  int i = 0;
878  do
879  {
880  pDataDesc.mHIKNodeId[i] = lStream.mHIKNodeId.mField[i];
881  }
882  while(lStream.mHIKNodeId.mField[i++] != HIKLastNode);
883 
884  // allocate the data bloc
885  const size_t align = 16;
886  lDataBlock = HIKDefaultAlignedMalloc(pDataDesc.mStride*i-1, align, pMalloc);
887  ReadBlock(pFileName, sizeof(HIKDataDescriptionStream), (size_t)pDataDesc.mStride, (size_t)(i-1), lDataBlock);
888  }
889  return lDataBlock;
890 }
891 
892 inline void HIKSaveDataBlock(const char* pFileName, const HIKDataDescription& pDataDesc, const void* pDataBlock)
893 {
894  HIKDataDescriptionStream lStream;
895  lStream.Init();
896 
897  lStream.mTransformSpace.mField[0] = pDataDesc.mTransformSpace;
898  lStream.mTOffset.mField[0] = (int)pDataDesc.mTOffset;
899  lStream.mQOffset.mField[0] = (int)pDataDesc.mQOffset;
900  lStream.mSOffset.mField[0] = (int)pDataDesc.mSOffset;
901  lStream.mStride.mField[0] = (int)pDataDesc.mStride;
902 
903  int i = 0;
904  do
905  {
906  lStream.mHIKNodeId.mField[i] = pDataDesc.mHIKNodeId[i];
907  }
908  while(pDataDesc.mHIKNodeId[i++] != HIKLastNode);
909 
910  // Save descriptor
911  if(Write(pFileName, lStream))
912  {
913  // Save all the collected data
914  WriteBlock(pFileName, (size_t)pDataDesc.mStride, (size_t)(i-1), pDataBlock);
915  }
916 }
917 
918 
919 #if !defined(__ghs__) && ( defined(_MSC_VER) || defined(__INTEL_COMPILER) || defined(__ICL) || defined(__GNUC__) || defined(__SNC__) )
920  #include "hikdump_std.inl"
921 #endif
922 
923 #endif
Defines the distance from the wrist to the inside edge of the model's hand (the side of the thumb)...
Definition: hikproperty.h:158
void HIKCharacterStateDestroy(HIKCharacterState *pCharacterState, HIKFree pFree)
Destroy HIKCharacterState pCharacterState.
float HIKGetRotationActive(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Reach Rotation constraint for Effector pEffectorIndex.
Header()
Definition: hikdump.h:208
bool Write(HIKFile pFile) const
Definition: hikdump.h:454
Defines the distance from the ankle to the inside edge of the model's foot (the instep).
Definition: hikproperty.h:151
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.
Definition: hikdump.h:611
Defines the distance from the ankle to the middle of the model's foot (its ball, or toe base)...
Definition: hikproperty.h:149
const char HIKCHARACTERPROPERTY_HEADER[]
Definition: hikdump.h:197
Field< int, LastNodeId > mNodeFlag
Definition: hikdump.h:277
If your source and target character have their ankles at different heights above the floor...
Definition: hikproperty.h:77
int
Definition: code.h:72
Field< int, 1 > mQOffset
Definition: hikdump.h:794
Defines the distance from the wrist to the outside edge of the model's hand (the side with the pinky)...
Definition: hikproperty.h:159
Node is characterized.
Definition: humanik.h:482
bool HIKSaveCharacter(const char *pFileName, HIKCharacter *pCharacter, HIKMalloc pMalloc, HIKFree pFree, float pUnitScale=1.0f)
Save HIKCharacter pCharacter to file pFileName.
Definition: hikdump.h:393
bool bSwap
Definition: hikdump.h:206
void HIKSetEffectorFloorStatefv(HIKEffectorSetState *pEffectorSetState, int pFloor, const float pXForm[16])
Set the transform matrix of the oriented plane that the floor contact engine applies to one of your c...
Definition: asdl.h:9
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
Definition: hikdump.h:557
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:36
Field2D< float, LastNodeId, 4 > mTOffset
Definition: hikdump.h:278
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.
Definition: humanik.h:332
Py_ssize_t i
Definition: abstract.h:1086
void(* HIKFree)(void *)
Memory de-allocator function.
Definition: humanik.h:393
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.
Definition: humanik.h:257
void HIKGetEffectorFloorStatefv(const HIKEffectorSetState *pEffectorSetState, int pFloor, float pXForm[16])
Retrieve the transform matrix of the oriented plane that the floor contact engine applies to one of y...
Field< int, 1 > mStride
Definition: hikdump.h:796
bool Read(HIKFile pFile)
Definition: hikdump.h:467
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
Definition: hikdump.h:555
void SwapBytes4(char *ToSwap)
Definition: hikdump.h:224
Defines the distance from the wrist to the bottom of the model's hand.
Definition: hikproperty.h:154
float HIKGetTranslationActive(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Reach Translation constraint for Effector pEffectorIndex.
Header HIKCharHeader
Definition: hikdump.h:284
#define NULL
Definition: kaydara.h:179
FieldType mField[eCount1][eCount2]
Definition: hikdump.h:263
Field< int, 1 > mTransformSpace
Definition: hikdump.h:792
bool Read(HIKFile pFile)
Definition: hikdump.h:317
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[]
Definition: hikdump.h:196
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.
Definition: hikdump.h:846
Defines the distance from the ankle to the outside edge of the model's foot.
Definition: hikproperty.h:152
void Init(FieldType pValue)
Definition: hikdump.h:245
Field2D< float, LastEffectorId, 12 > mTQS
Definition: hikdump.h:559
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...
type FieldType
Definition: hikdump.h:239
A description of a data set that contains separate translation, quaternion rotation, and scaling values for multiple different Nodes in an HIKCharacterState.
int type
Definition: node.h:20
int HIKGetNodeUse(const HIKCharacter *pCharacter, int pNodeId)
Retrieve the characterization flag set for Node pNodeId in HIKCharacter pCharacter.
Defines an HIKEffectorSetState.
Definition: humanik.h:418
Defines the distance from the wrist to the back of the model's hand.
Definition: hikproperty.h:155
Definition: hikdump.h:236
Field2D< float, LastNodeId, 4 > mSOffset
Definition: hikdump.h:280
Indicates the end of the list of Nodes.
Definition: humanik.h:1592
bool Write(HIKFile pFile) const
Definition: hikdump.h:576
Field< int, LastNodeId > mHIKNodeId
Definition: hikdump.h:797
bool WriteBlock(const char *pFileName, const size_t &pElementSize, const size_t &pElementCount, type &pStream)
Field< int, 1 > mTOffset
Definition: hikdump.h:793
float HIKGetPull(const HIKEffectorSetState *pEffectorSetState, int pEffectorIndex)
Retrieve the Pull constraint for Effector pEffectorIndex.
bool Write(HIKFile pFile) const
Definition: hikdump.h:692
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.
Definition: hikproperty.h:157
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...
bool Read(HIKFile pFile)
Definition: hikdump.h:828
void Init(FieldType pValue)
Definition: hikdump.h:265
bool HIKCharacterizeGeometry(HIKCharacter *pCharacter)
Set up and initialize character pCharacter for solving.
Field< float, LastEffectorId > mReachT
Definition: hikdump.h:553
bool Read(HIKFile pFile)
Definition: hikdump.h:704
bool Read(HIKFile pFile)
Definition: hikdump_std.inl:45
PyObject char size_t
Definition: import.h:39
The Hips and Chest Offset properties offset the translation of the character's hips and chest along e...
Definition: hikproperty.h:276
Adjusts the height of the target character's hips.
Definition: hikproperty.h:87
Field2D< float, HIKLastFloorId, 16 > mFloorTQS
Definition: hikdump.h:560
Field< int, 1 > mSOffset
Definition: hikdump.h:795
Defines the distance from the ankle to the bottom of the model's foot.
Definition: hikproperty.h:147
Defines a character's properties.
Definition: humanik.h:457
Adjusts the spacing between the left and right ankles of the target character relative to the source ...
Definition: hikproperty.h:82
Field< int, HIKLastPropertyId > mMode
Definition: hikdump.h:680
type FieldType
Definition: hikdump.h:257
Defines the distance from the ankle to the back of the model's foot.
Definition: hikproperty.h:148
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
Definition: hikdump.h:554
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.
Definition: hikdump.h:483
bool Write(HIKFile pFile) const
Definition: hikdump.h:300
Field< float, LastEffectorId > mPull
Definition: hikdump.h:556
Defines the distance from the wrist to the middle of the model's hand (its knuckles, or finger base).
Definition: hikproperty.h:156
void HIKGetParentOffsetfv(const HIKCharacter *pCharacter, int pNodeId, float pParentTOffset[4], float pParentQOffset[4], float pParentSOffset[4])
Retrieve the parent offset set for Node pNodeId.
#define HEADERLENGTH
Definition: hikdump.h:192
HIKCharacter * HIKLoadCharacter(const char *pFileName, const char *pValidationString, HIKMalloc pMalloc)
Load file pFileName, and create an HIKCharacter object from its contents.
Definition: hikdump.h:353
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...
Definition: hikdump.h:863
const char HIKCHARACTERSTATE_HEADER[]
Definition: hikdump.h:195
bool Read(const char *pFileName, type &pStream)
Field2D< float, LastNodeId, 4 > mParentSOffset
Definition: hikdump.h:283
FieldType mField[eCount]
Definition: hikdump.h:243
Defines a pose for a character.
Definition: humanik.h:441
const char HIKCHARACTER_HEADER[]
Definition: hikdump.h:194
HIKCharacterState * HIKCharacterStateCreate(const HIKCharacter *pCharacter, HIKMalloc pMalloc)
Create a new HIKCharacterState.
Field< int, 1 > mTransformMode
Definition: hikdump.h:440
Field2D< float, LastNodeId, 4 > mQOffset
Definition: hikdump.h:279
bool Read(HIKFile pFile)
Definition: hikdump.h:592
Defines the distance from the ankle to the front end of the model's toes.
Definition: hikproperty.h:150
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.
Definition: humanik.h:483
const int MagicNumber
Definition: hikdump.h:199
void *(* HIKMalloc)(size_t)
Memory allocator function.
Definition: humanik.h:388
Header HIKPropertySetHeader
Definition: hikdump.h:682
void HIKSetPull(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Pull constraint for Effector pEffectorIndex.
Field< int, LastNodeId > mNodeId
Definition: hikdump.h:441
bool HIKGetCharacterDefinitionFromDump(const char *pFileName, HIKCharacterDefinition &pDef)
Definition: hikdump.h:336
const char HIKCHARACTERDATABLOCK_HEADER[]
Definition: hikdump.h:198
Node is not characterized.
Definition: humanik.h:481
void HIKSaveDataBlock(const char *pFileName, const HIKDataDescription &pDataDesc, const void *pDataBlock)
Save the data set located in memory at pDataBlock to file pFileName.
Definition: hikdump.h:892
bool Read(HIKFile pFile, bool bSwap)
Definition: hikdump_std.inl:73
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().
Definition: hikdump.h:857
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.
Definition: humanik.h:315
const char void * pValue
Definition: fbcontrols.h:2116
Defines which Nodes are to be used by an HIKCharacter.
Field2D< float, LastNodeId, 4 > mParentQOffset
Definition: hikdump.h:282
Defines a character to be used with HumanIK.
void Init(const char *_Header)
Definition: hikdump.h:209
bool Write(HIKFile pFile) const
Definition: hikdump.h:812
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:66
void HIKSetRotationActive(HIKEffectorSetState *pEffectorSetState, int pEffectorIndex, float pValue)
Set the Reach Rotation constraint for Effector pEffectorIndex.
Field2D< float, LastNodeId, 4 > mParentTOffset
Definition: hikdump.h:281
bool HIKSaveCharacterState(const char *pFileName, HIKCharacter *pCharacter, HIKCharacterState *pState, int pTransformMode, float pUnitScale=1.0f)
Save HIKCharacterState pState to file pFileName.
Definition: hikdump.h:508
bool HIKSavePropertySetState(const char *pFileName, HIKPropertySetState *pState, float pUnitScale=1.0f)
Save HIKPropertySetState pState to file pFileName.
Definition: hikdump.h:741
Field< float, HIKLastPropertyId > mValue
Definition: hikdump.h:681
bool Write(HIKFile pFile) const
Definition: hikdump_std.inl:90
bool Read(HIKFile pFile, bool bSwap)
Definition: hikdump_std.inl:97
bool HIKSaveEffectorState(const char *pFileName, HIKEffectorSetState *pState, float pUnitScale=1.0f)
Save HIKEffectorSetState pState to file pFileName.
Definition: hikdump.h:644
Marks the end of the enumeration.
Definition: hikproperty.h:513
HIKCharacter * HIKCharacterCreate(const HIKCharacterDefinition *pCharacterDefinition, HIKMalloc pMalloc, const char *pValidationString)
Create a new HIKCharacter.
Py_ssize_t count
Definition: abstract.h:1077
HIKPropertySetState * HIKLoadPropertySetState(const char *pFileName, HIKMalloc pMalloc)
Load file pFileName, and create an HIKPropertySetState object from its contents.
Definition: hikdump.h:719