00001
00004 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
00005 #define FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042
00043 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00044 #include <fbxfilesdk/components/kbaselib/klib/ktime.h>
00045 #include <fbxfilesdk/components/kbaselib/klib/kerror.h>
00046 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00047 #include <fbxfilesdk/components/kbaselib/klib/ksystemtime.h>
00048 #include <fbxfilesdk/components/kbaselib/klib/kcharptrset.h>
00049
00050 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00051
00052 class KFBX_DLL KFbxXRefManager;
00053 class KFile;
00054 class KFbxReader;
00055 class KFbxWriter;
00056 class KFbx;
00057
00126 #define FBX_DEFAULT_VERSION_NUMBER 7100
00127
00128
00129 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00130
00132 enum
00133 {
00134 FBX_NO_SECTION = -1,
00135 FBX_MAIN_SECTION,
00136 FBX_EXTENSION_SECTION_0,
00137
00138
00139
00140 };
00141 #endif
00142
00146 class KFBX_DLL KDefaultRenderResolution
00147 {
00148 public:
00150 bool mIsOK;
00152 KString mCameraName;
00154 KString mResolutionMode;
00156 double mResolutionW;
00158 double mResolutionH;
00159
00164
00165 KDefaultRenderResolution();
00167
00172
00173 void Reset();
00175 };
00176
00181 class KFBX_DLL KFbxFileHeaderInfo
00182 {
00183 public:
00188
00189 KFbxFileHeaderInfo();
00190
00192 virtual ~KFbxFileHeaderInfo();
00194
00199
00201 virtual void Reset();
00202
00206 virtual bool ReadExtendedHeaderInformation(KFbx*);
00208
00210 KDefaultRenderResolution mDefaultRenderResolution;
00211
00213
00215
00219 int mFileVersion;
00220
00222 bool mCreationTimeStampPresent;
00223
00225 kLocalTime mCreationTimeStamp;
00226
00230 KString mCreator;
00231
00233 bool mIOPlugin;
00234
00236 bool mPLE;
00238 };
00239
00282 class KFBX_DLL KFbx
00283 {
00284 public:
00285
00288 struct KFbxAutoResetXRefManager
00289 {
00290 KFbx* mFbx;
00291 const KFbxXRefManager* mXRefManager;
00292
00294 KFbxAutoResetXRefManager(KFbx* pFbx, KFbxXRefManager& pXRefManager)
00295 : mFbx(pFbx)
00296 , mXRefManager(NULL)
00297 {
00298 if( mFbx )
00299 {
00300 mXRefManager = mFbx->ProjectGetXRefManager();
00301 mFbx->ProjectSetXRefManager(&pXRefManager);
00302 }
00303 }
00304
00306 ~KFbxAutoResetXRefManager()
00307 {
00308 if( mFbx )
00309 {
00310 mFbx->ProjectSetXRefManager(mXRefManager);
00311 }
00312 }
00313 };
00314
00318 static KFbx* KFbxObjectCreate(){ return FbxSdkNew< KFbx >(); }
00319
00321 KFbx();
00322
00324 virtual ~KFbx();
00325
00332
00342 bool ProjectOpen(void* pAddress, kULong pMaxLength, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00343
00352 bool ProjectOpen(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00353
00362 bool ProjectOpen (KFile * pFile, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00363
00372 bool ProjectOpenDirect(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00373
00383 bool ProjectCreate(void* pAddress, kUInt pSize, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00384
00393 bool ProjectCreate(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00394
00403 bool ProjectCreateDirect(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00404
00413 bool ProjectCreateEmpty(const char* pName, KFbxWriter* pWriter, int pVersion, bool pBinary, bool pEncrypted);
00414
00418 bool ProjectWrite_BeginFileHeader();
00419
00423 bool ProjectWrite_BeginExtendedHeader();
00424
00429 bool ProjectWrite_WriteExtendedHeader(const KFbxFileHeaderInfo* pExtendedHeader);
00430
00434 bool ProjectWrite_EndExtendedHeader();
00435
00439 bool ProjectWrite_EndFileHeader();
00440
00446 bool ProjectClose(void** pData=0,kULong *pSize=0);
00447
00451 void ProjectSetXRefManager(const KFbxXRefManager*);
00452
00456 const KFbxXRefManager* ProjectGetXRefManager() const;
00457
00472 bool ProjectCreateEmbeddedFolder(const KFbxXRefManager& pXRefManager, KString& pCreatedFolder, const char* pUserDefinedFolder = NULL);
00473
00477 void SetEmbedded(bool pValue);
00478
00482 bool IsEmbedded() const;
00483
00487 bool IsBinary() const;
00488
00492 bool IsEncrypted () const;
00493
00497 bool CheckCRC();
00498
00502 kUInt32 GetFileVersionNumber() const;
00503
00505
00516
00518 bool Fbx7Support() const;
00519
00523 void Fbx7Support(bool pSupport);
00524
00526 bool CompressArrays() const;
00527
00531 void CompressArrays(bool pCompress);
00532
00534 int CompressMinimumSize() const;
00535
00539 void CompressMinimumSize(int pSize);
00540
00542 int CompressLevel() const;
00543
00549 void CompressLevel(int pLevel);
00551
00557
00561 bool ProjectOpenMainSection();
00562
00566 int ProjectGetExtensionSectionCount() const;
00567
00572 bool ProjectOpenExtensionSection(int pExtensionSectionIndex);
00573
00578 bool ProjectCreateExtensionSection(bool pOverwriteLastExtensionSection = false);
00579
00582 void ProjectCloseSection();
00583
00587 int ProjectGetCurrentSection() const;
00588
00592 int ProjectGetCurrentSectionMode() const;
00593
00597 int ProjectGetCurrentSectionVersion() const;
00598
00606 int ProjectGetSectionVersion(int pSection) const;
00607
00614 static void ProjectConvertVersionNumber(int pVersion, int& pMajor, int& pMinor, int& pRevision);
00615
00619 bool IsPasswordProtected() const;
00620
00626 bool CheckPassword(const char* pPassword);
00627
00634 bool WritePassword(const char* pPassword);
00635
00637
00642
00646 const char* GetFilename() const;
00647
00652 KString GetDataDirectory(bool pAutoCreate = true);
00653
00662 KString GetMediaDirectory(bool pCreate = false, const char* pUserDefinedFolder = NULL);
00663
00669 KString GetContainerTemplateDirectory(const char* pTemplateName, bool pCreate);
00670
00675 char* GetRelativePath(const char* pPath);
00676
00681 char* GetRelativeFilePath(const char* pFilePath);
00682
00687 char* GetFullPath(const char* pRelativePath);
00688
00693 char* GetFullFilePath(const char* pRelativeFilePath);
00694
00699 char* GetTmpProjectName(const char* pName) const;
00700
00706 bool SwapFromTmpProject(const char* pName, char* pError=NULL);
00707
00709
00715
00718 void FieldReadResetPosition();
00719
00723 int FieldGetCount() const;
00724
00729 const char* FieldGetName(int pFieldIndex) const;
00730
00735 int FieldGetInstanceCount(const char* pFieldName) const;
00736
00742 bool FieldReadBegin(int pFieldIndex, int pInstance);
00743
00748 bool FieldReadBegin(const char* pFieldName);
00749
00755 bool FieldReadBegin(const char* pFieldName, int pInstance);
00756
00758 void FieldReadEnd();
00759
00761 bool FieldReadIsBlock();
00762
00764 bool FieldReadBlockBegin();
00765
00767 void FieldReadBlockEnd();
00768
00770 int FieldReadGetCount() const;
00771
00773 int FieldReadGetRemain() const;
00774
00776 char FieldReadGetType() const;
00777
00779 char FieldReadCH();
00780
00785 char FieldReadCH(const char* pFieldName, char pDefault=0);
00786
00788 const char* FieldReadC();
00789
00794 const char* FieldReadC(const char* pFieldName, const char* pDefault="");
00795
00797 const char* FieldReadS();
00798
00803 const char* FieldReadS(const char* pFieldName, const char* pDefault="");
00804
00806 bool FieldReadB();
00807
00812 bool FieldReadB(const char* pFieldName, bool pDefault = false);
00813
00815 int FieldReadI();
00816 int FieldReadI(const char* pFieldName, int pDefault=0);
00821
00823 kLongLong FieldReadLL();
00824
00829 kLongLong FieldReadLL(const char* pFieldName, kLongLong pDefault=0);
00830
00832 float FieldReadF();
00833
00838 float FieldReadF(const char* pFieldName, float pDefault=0);
00839
00841 double FieldReadD();
00842
00847 double FieldReadD(const char* pFieldName, double pDefault=0);
00848
00852 KTime FieldReadT(const char* pFieldName);
00853
00855 KTime FieldReadT();
00856
00860 KTimeSpan FieldReadTS(const char* pFieldName);
00861
00863 KTimeSpan FieldReadTS();
00864
00869 void FieldReadFn(float* pValue, kUInt pn);
00870
00874 void FieldRead3F(float* pValue);
00875
00879 void FieldRead4F(float* pValue);
00880
00887 void FieldReadFn(const char* pFieldName, float* pValue, const float *pDefault, kUInt pn);
00888
00894 void FieldRead3F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00895
00901 void FieldRead4F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00902
00907 void FieldReadDn(double* pValue, kUInt pn);
00908
00912 void FieldRead3D(double* pValue);
00913
00917 void FieldRead4D(double* pValue);
00918
00925 void FieldReadDn(const char* pFieldName, double* pValue, const double *pDefault, kUInt pn);
00926
00932 void FieldRead3D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00933
00939 void FieldRead4D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00940
00944 void* FieldReadR(int* pByteSize);
00945
00950 void* FieldReadR(const char* pFieldName,int* pByteSize);
00951
00956
00957 kByte FieldReadByte();
00958
00963 kByte FieldReadByte(const char* pFieldName, kByte pDefault=0);
00964
00966 kUByte FieldReadUByte();
00967
00972 kUByte FieldReadUByte(const char* pFieldName, kUByte pDefault=0);
00973
00975 kShort FieldReadShort();
00976
00981 kShort FieldReadShort(const char* pFieldName, kShort pDefault=0);
00982
00984 kUShort FieldReadUShort();
00985
00990 kUShort FieldReadUShort(const char* pFieldName, kUShort pDefault=0);
00991
00993 unsigned int FieldReadUI();
00994
00999 unsigned int FieldReadUI(const char* pFieldName, unsigned int pDefault=0);
01000
01002 kULongLong FieldReadULL();
01003
01008 kULongLong FieldReadULL(const char* pFieldName, kULongLong pDefault=0);
01009
01013 const kByte* FieldReadArraySBytes( int &pCount );
01017 const kShort* FieldReadArrayShort ( int &pCount );
01021 const kUShort* FieldReadArrayUShort( int &pCount );
01025 const unsigned int* FieldReadArrayUI ( int &pCount );
01029 const kULongLong* FieldReadArrayULL ( int &pCount );
01030
01034 const kByte* FieldReadArray(int &pCount, const kByte*);
01041 const kShort* FieldReadArray(int &pCount, const kShort*);
01045 const kUShort* FieldReadArray(int &pCount, const kUShort*);
01049 const unsigned int* FieldReadArray(int &pCount, const unsigned int*);
01053 const kULongLong* FieldReadArray(int &pCount, const kULongLong*);
01055
01064 virtual bool FieldReadEmbeddedFile (KString& pFileName, KString& pRelativeFileName, const char* pEmbeddedMediaDirectory = "", bool *pIsFileCreated=NULL);
01065
01069 const double* FieldReadArrayD( int &pCount );
01073 const float* FieldReadArrayF( int &pCount );
01077 const int* FieldReadArrayI( int &pCount );
01081 const kLongLong*FieldReadArrayLL(int &pCount );
01085 const bool* FieldReadArrayB( int &pCount );
01089 const kUByte* FieldReadArrayBytes( int &pCount );
01090
01094 const int* FieldReadArray(int& pCount, const int*);
01098 const float* FieldReadArray(int& pCount, const float*);
01102 const double* FieldReadArray(int& pCount, const double*);
01106 const kLongLong* FieldReadArray(int& pCount, const kLongLong*);
01110 const bool* FieldReadArray(int& pCount, const bool*);
01114 const kUByte* FieldReadArray(int& pCount, const kUByte*);
01115
01117
01123
01127 void FieldWriteBegin(const char* pFieldName);
01128
01130 void FieldWriteEnd();
01131
01133 void FieldWriteBlockBegin();
01134
01140 void FieldWriteObjectBegin(const char* pObjectType, const char* pName, const char* pSubType=NULL);
01141
01143 void FieldWriteObjectEnd();
01144
01149 void FieldWriteBlockBegin(const char* pFileName);
01150
01152 void FieldWriteBlockEnd ();
01153
01157 void FieldWriteCH(char pValue);
01158
01163 void FieldWriteCH(const char* pFieldName, char pValue);
01164
01168 void FieldWriteC(const char* pValue);
01169
01174 void FieldWriteC(const char* pFieldName, const char* pValue);
01175
01179 void FieldWriteS(const char* pValue);
01180
01184 void FieldWriteS(const KString& pValue);
01185
01190 void FieldWriteS(const char* pFieldName, const char* pValue);
01191
01196 void FieldWriteS(const char* pFieldName, const KString& pValue);
01197
01201 void FieldWriteB(bool pValue);
01202
01207 void FieldWriteB(const char* pFieldName, bool pValue);
01208
01212 void FieldWriteI(int pValue);
01213
01218 void FieldWriteI(const char* pFieldName, int pValue);
01219
01223 void FieldWriteLL(kLongLong pValue);
01224
01229 void FieldWriteLL(const char* pFieldName, kLongLong pValue);
01230
01235 void FieldWriteF(float pValue);
01236
01242 void FieldWriteF(const char* pFieldName, float pValue);
01243
01247 void FieldWriteD(double pValue);
01248
01253 void FieldWriteD(const char* pFieldName, double pValue);
01254
01258 void FieldWriteT(KTime pTime);
01259
01264 void FieldWriteT(const char* pFieldName,KTime pValue);
01265
01269 void FieldWriteTS(KTimeSpan pTimeSpan);
01270
01275 void FieldWriteTS(const char* pFieldName,KTimeSpan pValue);
01276
01281 void FieldWriteFn(const float* pValue, kUInt pn);
01282
01288 void FieldWriteFn(const char* pFieldName, const float* pValue, kUInt pn);
01289
01293 void FieldWrite3F(const float* pValue);
01294
01299 void FieldWrite3F(const char* pFieldName, const float* pValue);
01300
01304 void FieldWrite4F(const float* pValue);
01305
01310 void FieldWrite4F(const char* pFieldName, const float* pValue);
01311
01316 void FieldWriteDn(const double* pValue, kUInt pn);
01317
01323 void FieldWriteDn(const char* pFieldName, const double* pValue, kUInt pn);
01324
01328 void FieldWrite3D(const double* pValue);
01329
01334 void FieldWrite3D(const char* pFieldName, const double* pValue);
01335
01339 void FieldWrite4D(const double* pValue);
01340
01345 void FieldWrite4D(const char* pFieldName, const double* pValue);
01346
01347
01348
01349
01350
01351
01358 void FieldWriteArrayD( int n, const double* pValue, int pSize = 1, int pStride = 0 );
01365 void FieldWriteArrayF( int n, const float* pValue, int pSize = 1, int pStride = 0 );
01372 void FieldWriteArrayI( int n, const int* pValue, int pSize = 1, int pStride = 0 );
01379 void FieldWriteArrayLL(int n, const kLongLong* pValue, int pSize = 1, int pStride = 0 );
01386 void FieldWriteArrayB( int n, const bool* pValue, int pSize = 1, int pStride = 0 );
01393 void FieldWriteArrayBytes( int n, const kUByte* pValue, int pSize = 1, int pStride = 0 );
01394
01399 void FieldWriteR(const void* pRawData, int pByteSize);
01400
01406 void FieldWriteR(const char* pFieldName, const void* pRawData, int pByteSize);
01407
01412
01416 void FieldWriteByte(kByte pValue);
01417
01422 void FieldWriteByte(const char* pFieldName, kByte pValue);
01423
01427 void FieldWriteUByte(kUByte pValue);
01428
01433 void FieldWriteUByte(const char* pFieldName, kUByte pValue);
01434
01438 void FieldWriteShort(kShort pValue);
01439
01444 void FieldWriteShort(const char* pFieldName, kShort pValue);
01445
01449 void FieldWriteUShort(kUShort pValue);
01450
01455 void FieldWriteUShort(const char* pFieldName, kUShort pValue);
01456
01460 void FieldWriteUI(unsigned int pValue);
01461
01466 void FieldWriteUI(const char* pFieldName, unsigned int pValue);
01467
01471 void FieldWriteULL(kULongLong pValue);
01472
01478 void FieldWriteULL(const char* pFieldName, kULongLong pValue);
01479
01486 void FieldWriteArraySBytes( int n, const kByte* pValue, int pSize = 1, int pStride = 0 );
01493 void FieldWriteArrayShort( int n, const kShort* pValue, int pSize = 1, int pStride = 0 );
01500 void FieldWriteArrayUShort( int n, const kUShort* pValue, int pSize = 1, int pStride = 0 );
01507 void FieldWriteArrayUI( int n, const unsigned int* pValue, int pSize = 1, int pStride = 0 );
01514 void FieldWriteArrayULL(int n, const kULongLong* pValue, int pSize = 1, int pStride = 0 );
01516
01520 int GetFieldRMaxChunkSize() const;
01521
01525 void FieldWriteObjectReference(const char* pName);
01526
01531 void FieldWriteObjectReference(const char* pFieldName, const char* pName);
01532
01539 bool FieldWriteEmbeddedFile (KString pFileName, KString pRelativeFileName);
01540
01544 void WriteComments(const char* pFieldName);
01545
01547
01553
01555 enum EError
01556 {
01557 eFileCorrupted,
01558 eFileVersionNotSupportedYet,
01559 eFileVersionNotSupportedAnymore,
01560 eFileNotOpened,
01561 eFileNotCreated,
01562 eDirectoryNotCreated,
01563 eCrcCheckFailed,
01564 eNonExistingSection,
01565 eOperationCanceled,
01566 eCountError,
01567 eInvalidData,
01568 eWriteError,
01569 eReadError,
01570 eErrorCount
01571 };
01572
01576 KError& GetError();
01577
01581 EError GetLastErrorID() const;
01582
01586 const char* GetLastErrorString() const;
01587
01589
01590 #ifdef _DEBUG
01591
01592 void StdoutDump();
01593 #endif
01594
01602 bool GetHaveLoadedEmbededFile() const;
01603
01608 void* GetMemoryFileInfo(kULong& pSize) const;
01609
01610 public:
01611
01615 bool IsBeforeVersion6() const;
01616
01620 void SetIsBeforeVersion6(bool pIsBeforeVersion6);
01621
01622 private:
01623 struct KFbxImpl;
01624 KFbxImpl* mImpl;
01625
01627
01628 void ProjectClear();
01629 void ProjectReset();
01630
01631 bool ProjectReadHeader(bool pCheckASCIIHeader, bool pCheckCRC, bool pOpenMainSection, KFbxFileHeaderInfo* pFileHeaderInfo);
01632 bool ProjectReadExtendedHeader(int& pExtendedHeaderEnd, KFbxFileHeaderInfo* pFileHeaderInfo);
01633 bool BinaryReadHeader();
01634 bool BinaryReadSectionPosition();
01635 bool ASCIIReadHeader();
01636 bool ASCIIReadSectionPosition();
01637
01638 bool ProjectWriteHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01639 bool ProjectWriteExtendedHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01640 void BinaryWriteHeader();
01641 void ASCIIWriteHeader();
01642
01643 void ReadEncryptionKey(char* pEncryptionKey);
01644 void WriteEncryptionKey(char* pEncryptionKey);
01645
01647
01648 bool ProjectClearSection();
01649 bool ProjectOpenSection(int pSection);
01650 bool BinaryReadSectionHeader();
01651 int BinaryReadSectionFooter(char* pSourceCheck);
01652 bool BinaryReadExtensionCode(kUInt32 pFollowingSectionStart, kUInt32& pSectionStart, kUInt32& pSectionVersion);
01653 void BinaryReadSectionPassword();
01654
01655 bool ProjectWriteSectionHeader();
01656 void BinaryWriteSectionFooter();
01657 bool BinaryWriteExtensionCode(kUInt32 pSectionStart, kUInt32 pSectionVersion);
01658
01659 KString GetCreationTime() const;
01660 void SetCreationTime(KString pCreationTime);
01661 void CreateSourceCheck(char* lSourceCheck);
01662 bool TestSourceCheck(char* pSourceCheck, char* pSourceCompany);
01663 KString GetMangledCreationTime();
01664 void EncryptSourceCheck(char* pSourceCheck, char* pEncryptionData);
01665 void DecryptSourceCheck(char* pSourceCheck, const char* pEncryptionData);
01666
01667 void EncryptPasswordV1(KString pOriginalPassword, KString &pEncryptedPassword);
01668 void DecryptPasswordV1(KString pEncryptedPassword, KString &pDecryptedPassword);
01669
01671
01672 void CheckValidityOfFieldName(const char* pFieldName);
01673 void GetUnusedEmbeddedName(const KString& pDirectory, const KString& pName, KString& pResult, bool pCreateSubdirectory);
01674
01676 KString GetDirectory(bool pAutoCreate, const char* pExtension);
01677 };
01678
01679 #include <fbxfilesdk/fbxfilesdk_nsend.h>
01680
01681 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
01682