00001 #ifndef FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
00002 #define FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
00003
00004
00005
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 #include <fbxfilesdk/components/kbaselib/kbaselib_h.h>
00040
00041 #include <string.h>
00042 #include <stdio.h>
00043 #include <stdlib.h>
00044 #include <errno.h>
00045
00046 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00047 #include <fbxfilesdk/components/kbaselib/klib/ktime.h>
00048 #include <fbxfilesdk/components/kbaselib/klib/kerror.h>
00049 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00050 #include <fbxfilesdk/components/kbaselib/klib/ksystemtime.h>
00051 #include <fbxfilesdk/components/kbaselib/klib/kcharptrset.h>
00052
00053 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00054
00055 class KFBX_DLL KFbxXRefManager;
00056 class KFile;
00057 class KFbxReader;
00058 class KFbxWriter;
00059
00060 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00061
00062 #include <fbxfilesdk/components/kbaselib/kbaselib_forward.h>
00063 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00064
00065
00066
00067
00068
00069 #define FBX_DEFAULT_VERSION_NUMBER 6100
00070
00071 #define FBX7_DEFAULT_VERSION_NUMBER 7000
00072
00073
00074
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 enum
00161 {
00162 FBX_NO_SECTION = -1,
00163 FBX_MAIN_SECTION,
00164 FBX_EXTENSION_SECTION_0,
00165
00166
00167
00168 };
00169
00170 class KFBX_DLL KDefaultRenderResolution
00171 {
00172 public:
00173 bool mIsOK;
00174 KString mCameraName;
00175 KString mResolutionMode;
00176 double mResolutionW;
00177 double mResolutionH;
00178
00179 KDefaultRenderResolution();
00180
00181 void Reset();
00182 };
00183
00184 class KFBX_DLL KFbxFileHeaderInfo
00185 {
00186 public:
00187 KFbxFileHeaderInfo();
00188 virtual ~KFbxFileHeaderInfo();
00189
00190 virtual void Reset();
00191
00192
00193
00194 virtual bool ReadExtendedHeaderInformation(KFbx*);
00195
00196 KDefaultRenderResolution mDefaultRenderResolution;
00197
00198
00199 int mFileVersion;
00200 bool mCreationTimeStampPresent;
00201 kLocalTime mCreationTimeStamp;
00202 KString mCreator;
00203 bool mPLE;
00204 bool mIOPlugin;
00205 };
00206
00207
00208
00209
00210
00211
00212 class KFBX_DLL KFbx
00213 {
00214
00215 public:
00216
00217 struct KFbxAutoResetXRefManager
00218 {
00219 KFbx* mFbx;
00220 const KFbxXRefManager* mXRefManager;
00221
00222 KFbxAutoResetXRefManager(KFbx* pFbx, KFbxXRefManager& pXRefManager)
00223 : mFbx(pFbx)
00224 , mXRefManager(NULL)
00225 {
00226 if( mFbx )
00227 {
00228 mXRefManager = mFbx->ProjectGetXRefManager();
00229 mFbx->ProjectSetXRefManager(&pXRefManager);
00230 }
00231 }
00232
00233 ~KFbxAutoResetXRefManager()
00234 {
00235 if( mFbx )
00236 {
00237 mFbx->ProjectSetXRefManager(mXRefManager);
00238 }
00239 }
00240 };
00241
00242
00243 static KFbx* KFbxObjectCreate(){ return new KFbx; }
00244
00245 KFbx();
00246 virtual ~KFbx();
00247
00252
00254 bool ProjectOpen(void* pAddress, kULong pMaxLength, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00255
00257 bool ProjectOpen(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00258
00260 bool ProjectOpen (KFile * pFile, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00261
00263 bool ProjectOpenDirect(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00264
00266 bool ProjectCreate(void* pAddress, kUInt pSize, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00267
00269 bool ProjectCreate(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00270
00272 bool ProjectCreateDirect(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00273
00275 bool ProjectCreateEmpty(const char* pName, KFbxWriter* pWriter, int pVersion, bool pBinary, bool pEncrypted);
00276
00277
00278 bool ProjectWrite_BeginFileHeader();
00279
00280
00281 bool ProjectWrite_BeginExtendedHeader();
00282
00283
00284 bool ProjectWrite_WriteExtendedHeader(const KFbxFileHeaderInfo* pExtendedHeader);
00285
00286
00287 bool ProjectWrite_EndExtendedHeader();
00288
00289
00290 bool ProjectWrite_EndFileHeader();
00291
00293 bool ProjectClose(void** pData=0,kULong *pSize=0);
00294
00301 void ProjectSetXRefManager(const KFbxXRefManager*);
00302
00306 const KFbxXRefManager* ProjectGetXRefManager() const;
00307
00319 bool ProjectCreateEmbeddedFolder(const KFbxXRefManager& pXRefManager, KString& pCreatedFolder);
00320
00322 void SetEmbedded(bool pValue);
00323
00325 bool IsEmbedded() const;
00326
00328 bool IsBinary() const;
00329
00331 bool IsEncrypted () const;
00332
00333 bool Fbx7Support() const;
00334 void Fbx7Support(bool pSupport);
00335
00336
00337
00338
00339
00340 bool CompressArrays() const;
00341 void CompressArrays(bool pCompress);
00342
00343 int CompressMinimumSize() const;
00344 void CompressMinimumSize(int pSize);
00345
00346 int CompressLevel() const;
00347 void CompressLevel(int pLevel);
00348
00352 bool CheckCRC();
00353
00355 kUInt32 GetFileVersionNumber() const;
00356
00358
00363
00365 bool ProjectOpenMainSection();
00366
00368 int ProjectGetExtensionSectionCount();
00369
00371 bool ProjectOpenExtensionSection(int pExtensionSectionIndex);
00372
00374 bool ProjectCreateExtensionSection(bool pOverwriteLastExtensionSection = false);
00375
00377 void ProjectCloseSection();
00378
00380 bool ProjectRemoveLastExtensionSection();
00381
00383 int ProjectGetCurrentSection();
00384
00386 int ProjectGetCurrentSectionMode();
00387
00389 int ProjectGetCurrentSectionVersion();
00390
00396 int ProjectGetSectionVersion(int pSection);
00397
00404 static void ProjectConvertVersionNumber(int pVersion, int& pMajor, int& pMinor, int& pRevision);
00405
00409 bool IsPasswordProtected() const;
00410
00415 bool CheckPassword(const char* pPassword);
00416
00422 bool WritePassword(const char* pPassword);
00423
00425
00430
00432 const char* GetFilename() const;
00433
00435 KString GetDataDirectory(bool pAutoCreate = true);
00436
00442 KString GetMediaDirectory(bool pCreate = false);
00443
00445 char* GetRelativePath(const char* pPath);
00446
00448 char* GetRelativeFilePath(const char* pFilePath);
00449
00451 char* GetFullPath(const char* pRelativePath);
00452
00454 char* GetFullFilePath(const char* pRelativeFilePath);
00455
00457 char* GetTmpProjectName(const char* pName);
00458
00460 bool SwapFromTmpProject(const char* pName, char* pError=NULL);
00461
00463
00468
00470 void FieldReadResetPosition();
00471
00473 int FieldGetCount();
00474
00476 const char* FieldGetName(int pFieldIndex);
00477
00479 int FieldGetInstanceCount(const char* pFieldName);
00480
00482 bool FieldReadBegin(int pFieldIndex, int pInstance);
00483
00485 bool FieldReadBegin(const char* pFieldName);
00486
00488 bool FieldReadBegin(const char* pFieldName, int pInstance);
00489
00491 void FieldReadEnd();
00492
00494 bool FieldReadIsBlock();
00495
00497 bool FieldReadBlockBegin();
00498
00500 void FieldReadBlockEnd();
00501
00503 int FieldReadGetCount();
00504
00506 int FieldReadGetRemain();
00507
00509 char FieldReadGetType();
00510
00512 char FieldReadCH();
00513
00515 char FieldReadCH(const char* pFieldName, char pDefault=0);
00516
00518 const char* FieldReadC();
00519
00521 const char* FieldReadC(const char* pFieldName, const char* pDefault="");
00522
00524 const char* FieldReadS();
00525
00527 const char* FieldReadS(const char* pFieldName, const char* pDefault="");
00528
00530 bool FieldReadB();
00531
00533 bool FieldReadB(const char* pFieldName, bool pDefault = false);
00534
00536 int FieldReadI();
00537
00539 int FieldReadI(const char* pFieldName, int pDefault=0);
00540
00542 kLongLong FieldReadLL();
00543
00545 kLongLong FieldReadLL(const char* pFieldName, kLongLong pDefault=0);
00546
00548 float FieldReadF();
00549
00551 float FieldReadF(const char* pFieldName, float pDefault=0);
00552
00554 double FieldReadD();
00555
00557 double FieldReadD(const char* pFieldName, double pDefault=0);
00558
00560 KTime FieldReadT(const char* pFieldName);
00561
00563 KTime FieldReadT();
00564
00566 KTimeSpan FieldReadTS(const char* pFieldName);
00567
00569 KTimeSpan FieldReadTS();
00570
00572 void FieldReadFn(float* pValue, kUInt pn);
00573
00575 void FieldRead3F(float* pValue);
00576
00578 void FieldRead4F(float* pValue);
00579
00581 void FieldReadFn(const char* pFieldName, float* pValue, const float *pDefault, kUInt pn);
00582
00584 void FieldRead3F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00585
00587 void FieldRead4F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00588
00590 void FieldReadDn(double* pValue, kUInt pn);
00591
00593 void FieldRead3D(double* pValue);
00594
00596 void FieldRead4D(double* pValue);
00597
00599 void FieldReadDn(const char* pFieldName, double* pValue, const double *pDefault, kUInt pn);
00600
00602 void FieldRead3D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00603
00605 void FieldRead4D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00606
00608 void* FieldReadR(int* pByteSize);
00609
00611 void* FieldReadR(const char* pFieldName,int* pByteSize);
00612
00617 virtual bool FieldReadEmbeddedFile (KString& pFileName, KString& pRelativeFileName, const char* pEmbeddedMediaDirectory = "", bool *pIsFileCreated=NULL);
00618
00619 const double* FieldReadArrayD( int &pCount );
00620 const float* FieldReadArrayF( int &pCount );
00621 const int* FieldReadArrayI( int &pCount );
00622 const kLongLong*FieldReadArrayLL(int &pCount );
00623 const bool* FieldReadArrayB( int &pCount );
00624 const kUByte* FieldReadArrayBytes( int &pCount );
00625
00626 const int* FieldReadArray(int& pCount, const int*);
00627 const float* FieldReadArray(int& pCount, const float*);
00628 const double* FieldReadArray(int& pCount, const double*);
00629 const kLongLong* FieldReadArray(int& pCount, const kLongLong*);
00630 const bool* FieldReadArray(int& pCount, const bool*);
00631 const kUByte* FieldReadArray(int& pCount, const kUByte*);
00632
00634
00639
00641 void FieldWriteBegin(const char* pFieldName);
00642
00644 void FieldWriteEnd();
00645
00647 void FieldWriteBlockBegin();
00648
00650 void FieldWriteObjectBegin(const char* pObjectType, const char* pName, const char* pSubType=NULL);
00651
00653 void FieldWriteObjectEnd();
00654
00658 void FieldWriteBlockBegin(const char* pFileName);
00659
00661 void FieldWriteBlockEnd ();
00662
00664 void FieldWriteCH(char pValue);
00665
00667 void FieldWriteCH(const char* pFieldName, char pValue);
00668
00670 void FieldWriteC(const char* pValue);
00671
00673 void FieldWriteC(const char* pFieldName, const char* pValue);
00674
00676 void FieldWriteS(const char* pValue);
00677 void FieldWriteS(const KString& pValue);
00678
00680 void FieldWriteS(const char* pFieldName, const char* pValue);
00681 void FieldWriteS(const char* pFieldName, const KString& pValue);
00682
00684 void FieldWriteB(bool pValue);
00685
00687 void FieldWriteB(const char* pFieldName, bool pValue);
00688
00690 void FieldWriteI(int pValue);
00691
00693 void FieldWriteI(const char* pFieldName, int pValue);
00694
00696 void FieldWriteLL(kLongLong pValue);
00697
00699 void FieldWriteLL(const char* pFieldName, kLongLong pValue);
00700
00704 void FieldWriteF(float pValue);
00705
00709 void FieldWriteF(const char* pFieldName, float pValue);
00710
00712 void FieldWriteD(double pValue);
00713
00715 void FieldWriteD(const char* pFieldName, double pValue);
00716
00718 void FieldWriteT(KTime pTime);
00719
00721 void FieldWriteT(const char* pFieldName,KTime pValue);
00722
00724 void FieldWriteTS(KTimeSpan pTimeSpan);
00725
00727 void FieldWriteTS(const char* pFieldName,KTimeSpan pValue);
00728
00730 void FieldWriteFn(const float* pValue, kUInt pn);
00731
00733 void FieldWriteFn(const char* pFieldName, const float* pValue, kUInt pn);
00734
00736 void FieldWrite3F(const float* pValue);
00737
00739 void FieldWrite3F(const char* pFieldName, const float* pValue);
00740
00742 void FieldWrite4F(const float* pValue);
00743
00745 void FieldWrite4F(const char* pFieldName, const float* pValue);
00746
00748 void FieldWriteDn(const double* pValue, kUInt pn);
00749
00751 void FieldWriteDn(const char* pFieldName, const double* pValue, kUInt pn);
00752
00754 void FieldWrite3D(const double* pValue);
00755
00757 void FieldWrite3D(const char* pFieldName, const double* pValue);
00758
00760 void FieldWrite4D(const double* pValue);
00761
00763 void FieldWrite4D(const char* pFieldName, const double* pValue);
00764
00765
00766
00767
00768
00769 void FieldWriteArrayD( int n, const double* pValue, int pSize = 1, int pStride = 0 );
00770 void FieldWriteArrayF( int n, const float* pValue, int pSize = 1, int pStride = 0 );
00771 void FieldWriteArrayI( int n, const int* pValue, int pSize = 1, int pStride = 0 );
00772 void FieldWriteArrayLL(int n, const kLongLong* pValue, int pSize = 1, int pStride = 0 );
00773 void FieldWriteArrayB( int n, const bool* pValue, int pSize = 1, int pStride = 0 );
00774 void FieldWriteArrayBytes( int n, const kUByte* pValue, int pSize = 1, int pStride = 0 );
00775
00778 void FieldWriteR(const void* pRawData, int pByteSize);
00779
00782 void FieldWriteR(const char* pFieldName, const void* pRawData, int pByteSize);
00783
00784
00785
00786 int GetFieldRMaxChunkSize() const;
00787
00789 void FieldWriteObjectReference(const char* pName);
00790
00792 void FieldWriteObjectReference(const char* pFieldName, const char* pName);
00793
00798 bool FieldWriteEmbeddedFile (KString pFileName, KString pRelativeFileName);
00799
00801 void WriteComments(const char* pFieldName);
00802
00804
00809
00811 enum EError
00812 {
00813 eFileCorrupted,
00814 eFileVersionNotSupportedYet,
00815 eFileVersionNotSupportedAnymore,
00816 eFileNotOpened,
00817 eFileNotCreated,
00818 eDirectoryNotCreated,
00819 eCrcCheckFailed,
00820 eNonExistingSection,
00821 eOperationCanceled,
00822 eCountError,
00823 eInvalidData,
00824 eWriteError,
00825 eReadError,
00826 eErrorCount
00827 };
00828
00832 KError& GetError();
00833
00837 EError GetLastErrorID() const;
00838
00842 const char* GetLastErrorString() const;
00843
00845
00846 #ifdef _DEBUG
00847
00848 void StdoutDump();
00849 #endif
00850
00851 bool GetHaveLoadedEmbededFile() const;
00852
00853 void* GetMemoryFileInfo(kULong& pSize);
00854
00855 public:
00856 bool IsBeforeVersion6() const;
00857 void SetIsBeforeVersion6(bool pIsBeforeVersion6);
00858
00859 private:
00860 struct KFbxImpl;
00861 KFbxImpl* mImpl;
00862
00864
00865 void ProjectClear();
00866 void ProjectReset();
00867
00868 bool ProjectReadHeader(bool pCheckASCIIHeader, bool pCheckCRC, bool pOpenMainSection, KFbxFileHeaderInfo* pFileHeaderInfo);
00869 bool ProjectReadExtendedHeader(int& pExtendedHeaderEnd, KFbxFileHeaderInfo* pFileHeaderInfo);
00870 bool BinaryReadHeader();
00871 bool BinaryReadSectionPosition();
00872 bool ASCIIReadHeader();
00873 bool ASCIIReadSectionPosition();
00874
00875 bool ProjectWriteHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
00876 bool ProjectWriteExtendedHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
00877 void BinaryWriteHeader();
00878 void ASCIIWriteHeader();
00879
00880 void ReadEncryptionKey(char* pEncryptionKey);
00881 void WriteEncryptionKey(char* pEncryptionKey);
00882
00884
00885 bool ProjectClearSection();
00886 bool ProjectOpenSection(int pSection);
00887 bool BinaryReadSectionHeader();
00888 int BinaryReadSectionFooter(char* pSourceCheck);
00889 bool BinaryReadExtensionCode(kUInt32 pFollowingSectionStart, kUInt32& pSectionStart, kUInt32& pSectionVersion);
00890 void BinaryReadSectionPassword();
00891
00892 bool ProjectWriteSectionHeader();
00893 void BinaryWriteSectionFooter();
00894 bool BinaryWriteExtensionCode(kUInt32 pSectionStart, kUInt32 pSectionVersion);
00895
00896 KString GetCreationTime();
00897 void SetCreationTime(KString pCreationTime);
00898 void CreateSourceCheck(char* lSourceCheck);
00899 bool TestSourceCheck(char* pSourceCheck, char* pSourceCompany);
00900 KString GetMangledCreationTime();
00901 void EncryptSourceCheck(char* pSourceCheck, char* pEncryptionData);
00902 void DecryptSourceCheck(char* pSourceCheck, const char* pEncryptionData);
00903
00904 void EncryptPasswordV1(KString pOriginalPassword, KString &pEncryptedPassword);
00905 void DecryptPasswordV1(KString pEncryptedPassword, KString &pDecryptedPassword);
00906
00908
00909 void CheckValidityOfFieldName(const char* pFieldName);
00910 void GetUnusedEmbeddedName(const KString& pDirectory, const KString& pName, KString& pResult, bool pCreateSubdirectory);
00911
00913 KString GetDirectory(bool pAutoCreate, const char* pExtension);
00914 };
00915
00916 #include <fbxfilesdk/fbxfilesdk_nsend.h>
00917
00918 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
00919