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
00042 #include <fbxfilesdk/components/kbaselib/kbaselib_h.h>
00043
00044 #include <string.h>
00045 #include <stdio.h>
00046 #include <stdlib.h>
00047 #include <errno.h>
00048
00049 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00050 #include <fbxfilesdk/components/kbaselib/klib/ktime.h>
00051 #include <fbxfilesdk/components/kbaselib/klib/kerror.h>
00052 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00053 #include <fbxfilesdk/components/kbaselib/klib/ksystemtime.h>
00054 #include <fbxfilesdk/components/kbaselib/klib/kcharptrset.h>
00055
00056 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00057
00058 class KFBX_DLL KFbxXRefManager;
00059 class KFile;
00060 class KFbxReader;
00061 class KFbxWriter;
00062
00063 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00064
00065 #include <fbxfilesdk/components/kbaselib/kbaselib_forward.h>
00066 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00067
00068
00069
00070
00071
00072 #define FBX_DEFAULT_VERSION_NUMBER 6100
00073
00074 #define FBX7_DEFAULT_VERSION_NUMBER 7000
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163 enum
00164 {
00165 FBX_NO_SECTION = -1,
00166 FBX_MAIN_SECTION,
00167 FBX_EXTENSION_SECTION_0,
00168
00169
00170
00171 };
00172
00176 class KFBX_DLL KDefaultRenderResolution
00177 {
00178 public:
00180 bool mIsOK;
00182 KString mCameraName;
00183 KString mResolutionMode;
00185 double mResolutionW;
00187 double mResolutionH;
00188
00193
00194 KDefaultRenderResolution();
00196
00201
00202 void Reset();
00204 };
00205
00208 class KFBX_DLL KFbxFileHeaderInfo
00209 {
00210 public:
00215
00216 KFbxFileHeaderInfo();
00217
00219 virtual ~KFbxFileHeaderInfo();
00221
00226 virtual void Reset();
00227
00228
00229
00230 virtual bool ReadExtendedHeaderInformation(KFbx*);
00232
00233 KDefaultRenderResolution mDefaultRenderResolution;
00234
00235
00236
00238 int mFileVersion;
00239
00241 bool mCreationTimeStampPresent;
00242
00244 kLocalTime mCreationTimeStamp;
00245
00247 KString mCreator;
00248
00250 bool mIOPlugin;
00251
00252
00253 bool mPLE;
00254 };
00255
00258 class KFBX_DLL KFbx
00259 {
00260 public:
00261
00262 struct KFbxAutoResetXRefManager
00263 {
00264 KFbx* mFbx;
00265 const KFbxXRefManager* mXRefManager;
00266
00267 KFbxAutoResetXRefManager(KFbx* pFbx, KFbxXRefManager& pXRefManager)
00268 : mFbx(pFbx)
00269 , mXRefManager(NULL)
00270 {
00271 if( mFbx )
00272 {
00273 mXRefManager = mFbx->ProjectGetXRefManager();
00274 mFbx->ProjectSetXRefManager(&pXRefManager);
00275 }
00276 }
00277
00278 ~KFbxAutoResetXRefManager()
00279 {
00280 if( mFbx )
00281 {
00282 mFbx->ProjectSetXRefManager(mXRefManager);
00283 }
00284 }
00285 };
00286
00287
00288 static KFbx* KFbxObjectCreate(){ return new KFbx; }
00289
00290 KFbx();
00291 virtual ~KFbx();
00292
00297
00307 bool ProjectOpen(void* pAddress, kULong pMaxLength, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00308
00317 bool ProjectOpen(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00318
00327 bool ProjectOpen (KFile * pFile, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00328
00337 bool ProjectOpenDirect(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00338
00348 bool ProjectCreate(void* pAddress, kUInt pSize, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00349
00358 bool ProjectCreate(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00359
00368 bool ProjectCreateDirect(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00369
00378 bool ProjectCreateEmpty(const char* pName, KFbxWriter* pWriter, int pVersion, bool pBinary, bool pEncrypted);
00379
00383 bool ProjectWrite_BeginFileHeader();
00384
00388 bool ProjectWrite_BeginExtendedHeader();
00389
00394 bool ProjectWrite_WriteExtendedHeader(const KFbxFileHeaderInfo* pExtendedHeader);
00395
00399 bool ProjectWrite_EndExtendedHeader();
00400
00404 bool ProjectWrite_EndFileHeader();
00405
00411 bool ProjectClose(void** pData=0,kULong *pSize=0);
00412
00416 void ProjectSetXRefManager(const KFbxXRefManager*);
00417
00421 const KFbxXRefManager* ProjectGetXRefManager() const;
00422
00436 bool ProjectCreateEmbeddedFolder(const KFbxXRefManager& pXRefManager, KString& pCreatedFolder);
00437
00441 void SetEmbedded(bool pValue);
00442
00446 bool IsEmbedded() const;
00447
00451 bool IsBinary() const;
00452
00456 bool IsEncrypted () const;
00457
00461 bool CheckCRC();
00462
00466 kUInt32 GetFileVersionNumber() const;
00467
00469
00479
00481 bool Fbx7Support() const;
00482
00486 void Fbx7Support(bool pSupport);
00487
00489 bool CompressArrays() const;
00490
00494 void CompressArrays(bool pCompress);
00495
00497 int CompressMinimumSize() const;
00498
00502 void CompressMinimumSize(int pSize);
00503
00505 int CompressLevel() const;
00506
00512 void CompressLevel(int pLevel);
00514
00519
00523 bool ProjectOpenMainSection();
00524
00528 int ProjectGetExtensionSectionCount();
00529
00534 bool ProjectOpenExtensionSection(int pExtensionSectionIndex);
00535
00540 bool ProjectCreateExtensionSection(bool pOverwriteLastExtensionSection = false);
00541
00544 void ProjectCloseSection();
00545
00549 bool ProjectRemoveLastExtensionSection();
00550
00554 int ProjectGetCurrentSection();
00555
00559 int ProjectGetCurrentSectionMode();
00560
00564 int ProjectGetCurrentSectionVersion();
00565
00573 int ProjectGetSectionVersion(int pSection);
00574
00581 static void ProjectConvertVersionNumber(int pVersion, int& pMajor, int& pMinor, int& pRevision);
00582
00586 bool IsPasswordProtected() const;
00587
00593 bool CheckPassword(const char* pPassword);
00594
00601 bool WritePassword(const char* pPassword);
00602
00604
00609
00613 const char* GetFilename() const;
00614
00619 KString GetDataDirectory(bool pAutoCreate = true);
00620
00628 KString GetMediaDirectory(bool pCreate = false);
00629
00635 KString GetContainerTemplateDirectory(const char* pTemplateName, bool pCreate);
00636
00641 char* GetRelativePath(const char* pPath);
00642
00647 char* GetRelativeFilePath(const char* pFilePath);
00648
00653 char* GetFullPath(const char* pRelativePath);
00654
00659 char* GetFullFilePath(const char* pRelativeFilePath);
00660
00665 char* GetTmpProjectName(const char* pName);
00666
00672 bool SwapFromTmpProject(const char* pName, char* pError=NULL);
00673
00675
00680
00683 void FieldReadResetPosition();
00684
00688 int FieldGetCount();
00689
00694 const char* FieldGetName(int pFieldIndex);
00695
00700 int FieldGetInstanceCount(const char* pFieldName);
00701
00707 bool FieldReadBegin(int pFieldIndex, int pInstance);
00708
00713 bool FieldReadBegin(const char* pFieldName);
00714
00720 bool FieldReadBegin(const char* pFieldName, int pInstance);
00721
00723 void FieldReadEnd();
00724
00726 bool FieldReadIsBlock();
00727
00729 bool FieldReadBlockBegin();
00730
00732 void FieldReadBlockEnd();
00733
00735 int FieldReadGetCount();
00736
00738 int FieldReadGetRemain();
00739
00741 char FieldReadGetType();
00742
00744 char FieldReadCH();
00745
00750 char FieldReadCH(const char* pFieldName, char pDefault=0);
00751
00753 const char* FieldReadC();
00754
00759 const char* FieldReadC(const char* pFieldName, const char* pDefault="");
00760
00762 const char* FieldReadS();
00763
00768 const char* FieldReadS(const char* pFieldName, const char* pDefault="");
00769
00771 bool FieldReadB();
00772
00777 bool FieldReadB(const char* pFieldName, bool pDefault = false);
00778
00780 int FieldReadI();
00781 int FieldReadI(const char* pFieldName, int pDefault=0);
00786
00788 kLongLong FieldReadLL();
00789
00794 kLongLong FieldReadLL(const char* pFieldName, kLongLong pDefault=0);
00795
00797 float FieldReadF();
00798
00803 float FieldReadF(const char* pFieldName, float pDefault=0);
00804
00806 double FieldReadD();
00807
00812 double FieldReadD(const char* pFieldName, double pDefault=0);
00813
00817 KTime FieldReadT(const char* pFieldName);
00818
00820 KTime FieldReadT();
00821
00825 KTimeSpan FieldReadTS(const char* pFieldName);
00826
00828 KTimeSpan FieldReadTS();
00829
00834 void FieldReadFn(float* pValue, kUInt pn);
00835
00839 void FieldRead3F(float* pValue);
00840
00844 void FieldRead4F(float* pValue);
00845
00852 void FieldReadFn(const char* pFieldName, float* pValue, const float *pDefault, kUInt pn);
00853
00859 void FieldRead3F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00860
00866 void FieldRead4F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00867
00872 void FieldReadDn(double* pValue, kUInt pn);
00873
00877 void FieldRead3D(double* pValue);
00878
00882 void FieldRead4D(double* pValue);
00883
00890 void FieldReadDn(const char* pFieldName, double* pValue, const double *pDefault, kUInt pn);
00891
00897 void FieldRead3D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00898
00904 void FieldRead4D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00905
00909 void* FieldReadR(int* pByteSize);
00910
00915 void* FieldReadR(const char* pFieldName,int* pByteSize);
00916
00921
00922 kByte FieldReadByte();
00923
00928 kByte FieldReadByte(const char* pFieldName, kByte pDefault=0);
00929
00931 kUByte FieldReadUByte();
00932
00937 kUByte FieldReadUByte(const char* pFieldName, kUByte pDefault=0);
00938
00940 kShort FieldReadShort();
00941
00946 kShort FieldReadShort(const char* pFieldName, kShort pDefault=0);
00947
00949 kUShort FieldReadUShort();
00950
00955 kUShort FieldReadUShort(const char* pFieldName, kUShort pDefault=0);
00956
00958 unsigned int FieldReadUI();
00959
00964 unsigned int FieldReadUI(const char* pFieldName, unsigned int pDefault=0);
00965
00967 kULongLong FieldReadULL();
00968
00973 kULongLong FieldReadULL(const char* pFieldName, kULongLong pDefault=0);
00974
00978 const kByte* FieldReadArraySBytes( int &pCount );
00982 const kShort* FieldReadArrayShort ( int &pCount );
00986 const kUShort* FieldReadArrayUShort( int &pCount );
00990 const unsigned int* FieldReadArrayUI ( int &pCount );
00994 const kULongLong* FieldReadArrayULL ( int &pCount );
00995
00999 const kByte* FieldReadArray(int &pCount, const kByte*);
01006 const kShort* FieldReadArray(int &pCount, const kShort*);
01010 const kUShort* FieldReadArray(int &pCount, const kUShort*);
01014 const unsigned int* FieldReadArray(int &pCount, const unsigned int*);
01018 const kULongLong* FieldReadArray(int &pCount, const kULongLong*);
01020
01029 virtual bool FieldReadEmbeddedFile (KString& pFileName, KString& pRelativeFileName, const char* pEmbeddedMediaDirectory = "", bool *pIsFileCreated=NULL);
01030
01034 const double* FieldReadArrayD( int &pCount );
01038 const float* FieldReadArrayF( int &pCount );
01042 const int* FieldReadArrayI( int &pCount );
01046 const kLongLong*FieldReadArrayLL(int &pCount );
01050 const bool* FieldReadArrayB( int &pCount );
01054 const kUByte* FieldReadArrayBytes( int &pCount );
01055
01059 const int* FieldReadArray(int& pCount, const int*);
01063 const float* FieldReadArray(int& pCount, const float*);
01067 const double* FieldReadArray(int& pCount, const double*);
01071 const kLongLong* FieldReadArray(int& pCount, const kLongLong*);
01075 const bool* FieldReadArray(int& pCount, const bool*);
01079 const kUByte* FieldReadArray(int& pCount, const kUByte*);
01080
01082
01087
01091 void FieldWriteBegin(const char* pFieldName);
01092
01094 void FieldWriteEnd();
01095
01097 void FieldWriteBlockBegin();
01098
01104 void FieldWriteObjectBegin(const char* pObjectType, const char* pName, const char* pSubType=NULL);
01105
01107 void FieldWriteObjectEnd();
01108
01113 void FieldWriteBlockBegin(const char* pFileName);
01114
01116 void FieldWriteBlockEnd ();
01117
01121 void FieldWriteCH(char pValue);
01122
01127 void FieldWriteCH(const char* pFieldName, char pValue);
01128
01132 void FieldWriteC(const char* pValue);
01133
01138 void FieldWriteC(const char* pFieldName, const char* pValue);
01139
01143 void FieldWriteS(const char* pValue);
01144
01148 void FieldWriteS(const KString& pValue);
01149
01154 void FieldWriteS(const char* pFieldName, const char* pValue);
01155
01160 void FieldWriteS(const char* pFieldName, const KString& pValue);
01161
01165 void FieldWriteB(bool pValue);
01166
01171 void FieldWriteB(const char* pFieldName, bool pValue);
01172
01176 void FieldWriteI(int pValue);
01177
01182 void FieldWriteI(const char* pFieldName, int pValue);
01183
01187 void FieldWriteLL(kLongLong pValue);
01188
01193 void FieldWriteLL(const char* pFieldName, kLongLong pValue);
01194
01199 void FieldWriteF(float pValue);
01200
01206 void FieldWriteF(const char* pFieldName, float pValue);
01207
01211 void FieldWriteD(double pValue);
01212
01217 void FieldWriteD(const char* pFieldName, double pValue);
01218
01222 void FieldWriteT(KTime pTime);
01223
01228 void FieldWriteT(const char* pFieldName,KTime pValue);
01229
01233 void FieldWriteTS(KTimeSpan pTimeSpan);
01234
01239 void FieldWriteTS(const char* pFieldName,KTimeSpan pValue);
01240
01245 void FieldWriteFn(const float* pValue, kUInt pn);
01246
01252 void FieldWriteFn(const char* pFieldName, const float* pValue, kUInt pn);
01253
01257 void FieldWrite3F(const float* pValue);
01258
01263 void FieldWrite3F(const char* pFieldName, const float* pValue);
01264
01268 void FieldWrite4F(const float* pValue);
01269
01274 void FieldWrite4F(const char* pFieldName, const float* pValue);
01275
01280 void FieldWriteDn(const double* pValue, kUInt pn);
01281
01287 void FieldWriteDn(const char* pFieldName, const double* pValue, kUInt pn);
01288
01292 void FieldWrite3D(const double* pValue);
01293
01298 void FieldWrite3D(const char* pFieldName, const double* pValue);
01299
01303 void FieldWrite4D(const double* pValue);
01304
01309 void FieldWrite4D(const char* pFieldName, const double* pValue);
01310
01311
01312
01313
01314
01315
01322 void FieldWriteArrayD( int n, const double* pValue, int pSize = 1, int pStride = 0 );
01329 void FieldWriteArrayF( int n, const float* pValue, int pSize = 1, int pStride = 0 );
01336 void FieldWriteArrayI( int n, const int* pValue, int pSize = 1, int pStride = 0 );
01343 void FieldWriteArrayLL(int n, const kLongLong* pValue, int pSize = 1, int pStride = 0 );
01350 void FieldWriteArrayB( int n, const bool* pValue, int pSize = 1, int pStride = 0 );
01357 void FieldWriteArrayBytes( int n, const kUByte* pValue, int pSize = 1, int pStride = 0 );
01358
01363 void FieldWriteR(const void* pRawData, int pByteSize);
01364
01370 void FieldWriteR(const char* pFieldName, const void* pRawData, int pByteSize);
01371
01376
01380 void FieldWriteByte(kByte pValue);
01381
01386 void FieldWriteByte(const char* pFieldName, kByte pValue);
01387
01391 void FieldWriteUByte(kUByte pValue);
01392
01397 void FieldWriteUByte(const char* pFieldName, kUByte pValue);
01398
01402 void FieldWriteShort(kShort pValue);
01403
01408 void FieldWriteShort(const char* pFieldName, kShort pValue);
01409
01413 void FieldWriteUShort(kUShort pValue);
01414
01419 void FieldWriteUShort(const char* pFieldName, kUShort pValue);
01420
01424 void FieldWriteUI(unsigned int pValue);
01425
01430 void FieldWriteUI(const char* pFieldName, unsigned int pValue);
01431
01435 void FieldWriteULL(kULongLong pValue);
01436
01442 void FieldWriteULL(const char* pFieldName, kULongLong pValue);
01443
01450 void FieldWriteArraySBytes( int n, const kByte* pValue, int pSize = 1, int pStride = 0 );
01457 void FieldWriteArrayShort( int n, const kShort* pValue, int pSize = 1, int pStride = 0 );
01464 void FieldWriteArrayUShort( int n, const kUShort* pValue, int pSize = 1, int pStride = 0 );
01471 void FieldWriteArrayUI( int n, const unsigned int* pValue, int pSize = 1, int pStride = 0 );
01478 void FieldWriteArrayULL(int n, const kULongLong* pValue, int pSize = 1, int pStride = 0 );
01480
01484 int GetFieldRMaxChunkSize() const;
01485
01489 void FieldWriteObjectReference(const char* pName);
01490
01495 void FieldWriteObjectReference(const char* pFieldName, const char* pName);
01496
01503 bool FieldWriteEmbeddedFile (KString pFileName, KString pRelativeFileName);
01504
01508 void WriteComments(const char* pFieldName);
01509
01511
01516
01518 enum EError
01519 {
01520 eFileCorrupted,
01521 eFileVersionNotSupportedYet,
01522 eFileVersionNotSupportedAnymore,
01523 eFileNotOpened,
01524 eFileNotCreated,
01525 eDirectoryNotCreated,
01526 eCrcCheckFailed,
01527 eNonExistingSection,
01528 eOperationCanceled,
01529 eCountError,
01530 eInvalidData,
01531 eWriteError,
01532 eReadError,
01533 eErrorCount
01534 };
01535
01539 KError& GetError();
01540
01544 EError GetLastErrorID() const;
01545
01549 const char* GetLastErrorString() const;
01550
01552
01553 #ifdef _DEBUG
01554
01555 void StdoutDump();
01556 #endif
01557
01558 bool GetHaveLoadedEmbededFile() const;
01559
01560 void* GetMemoryFileInfo(kULong& pSize);
01561
01562 public:
01563 bool IsBeforeVersion6() const;
01564 void SetIsBeforeVersion6(bool pIsBeforeVersion6);
01565
01566 private:
01567 struct KFbxImpl;
01568 KFbxImpl* mImpl;
01569
01571
01572 void ProjectClear();
01573 void ProjectReset();
01574
01575 bool ProjectReadHeader(bool pCheckASCIIHeader, bool pCheckCRC, bool pOpenMainSection, KFbxFileHeaderInfo* pFileHeaderInfo);
01576 bool ProjectReadExtendedHeader(int& pExtendedHeaderEnd, KFbxFileHeaderInfo* pFileHeaderInfo);
01577 bool BinaryReadHeader();
01578 bool BinaryReadSectionPosition();
01579 bool ASCIIReadHeader();
01580 bool ASCIIReadSectionPosition();
01581
01582 bool ProjectWriteHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01583 bool ProjectWriteExtendedHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01584 void BinaryWriteHeader();
01585 void ASCIIWriteHeader();
01586
01587 void ReadEncryptionKey(char* pEncryptionKey);
01588 void WriteEncryptionKey(char* pEncryptionKey);
01589
01591
01592 bool ProjectClearSection();
01593 bool ProjectOpenSection(int pSection);
01594 bool BinaryReadSectionHeader();
01595 int BinaryReadSectionFooter(char* pSourceCheck);
01596 bool BinaryReadExtensionCode(kUInt32 pFollowingSectionStart, kUInt32& pSectionStart, kUInt32& pSectionVersion);
01597 void BinaryReadSectionPassword();
01598
01599 bool ProjectWriteSectionHeader();
01600 void BinaryWriteSectionFooter();
01601 bool BinaryWriteExtensionCode(kUInt32 pSectionStart, kUInt32 pSectionVersion);
01602
01603 KString GetCreationTime();
01604 void SetCreationTime(KString pCreationTime);
01605 void CreateSourceCheck(char* lSourceCheck);
01606 bool TestSourceCheck(char* pSourceCheck, char* pSourceCompany);
01607 KString GetMangledCreationTime();
01608 void EncryptSourceCheck(char* pSourceCheck, char* pEncryptionData);
01609 void DecryptSourceCheck(char* pSourceCheck, const char* pEncryptionData);
01610
01611 void EncryptPasswordV1(KString pOriginalPassword, KString &pEncryptedPassword);
01612 void DecryptPasswordV1(KString pEncryptedPassword, KString &pDecryptedPassword);
01613
01615
01616 void CheckValidityOfFieldName(const char* pFieldName);
01617 void GetUnusedEmbeddedName(const KString& pDirectory, const KString& pName, KString& pResult, bool pCreateSubdirectory);
01618
01620 KString GetDirectory(bool pAutoCreate, const char* pExtension);
01621 };
01622
01623 #include <fbxfilesdk/fbxfilesdk_nsend.h>
01624
01625 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
01626