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
00137 #define FBX_DEFAULT_VERSION_NUMBER 7200
00138
00139
00140 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00141
00143 enum
00144 {
00145 FBX_NO_SECTION = -1,
00146 FBX_MAIN_SECTION,
00147 FBX_EXTENSION_SECTION_0,
00148
00149
00150
00151 };
00152 #endif
00153
00157 class KFBX_DLL KDefaultRenderResolution
00158 {
00159 public:
00161 bool mIsOK;
00163 KString mCameraName;
00165 KString mResolutionMode;
00167 double mResolutionW;
00169 double mResolutionH;
00170
00175
00176 KDefaultRenderResolution();
00178
00183
00184 void Reset();
00186 };
00187
00192 class KFBX_DLL KFbxFileHeaderInfo
00193 {
00194 public:
00199
00200 KFbxFileHeaderInfo();
00201
00203 virtual ~KFbxFileHeaderInfo();
00205
00210
00212 virtual void Reset();
00213
00217 virtual bool ReadExtendedHeaderInformation(KFbx*);
00219
00221 KDefaultRenderResolution mDefaultRenderResolution;
00222
00224
00226
00230 int mFileVersion;
00231
00233 bool mCreationTimeStampPresent;
00234
00236 kLocalTime mCreationTimeStamp;
00237
00241 KString mCreator;
00242
00244 bool mIOPlugin;
00245
00247 bool mPLE;
00249 };
00250
00293 class KFBX_DLL KFbx
00294 {
00295 public:
00296
00299 struct KFbxAutoResetXRefManager
00300 {
00301 KFbx* mFbx;
00302 const KFbxXRefManager* mXRefManager;
00303
00305 KFbxAutoResetXRefManager(KFbx* pFbx, KFbxXRefManager& pXRefManager)
00306 : mFbx(pFbx)
00307 , mXRefManager(NULL)
00308 {
00309 if( mFbx )
00310 {
00311 mXRefManager = mFbx->ProjectGetXRefManager();
00312 mFbx->ProjectSetXRefManager(&pXRefManager);
00313 }
00314 }
00315
00317 ~KFbxAutoResetXRefManager()
00318 {
00319 if( mFbx )
00320 {
00321 mFbx->ProjectSetXRefManager(mXRefManager);
00322 }
00323 }
00324 };
00325
00329 static KFbx* KFbxObjectCreate(){ return FbxSdkNew< KFbx >(); }
00330
00332 KFbx();
00333
00335 virtual ~KFbx();
00336
00343
00353 bool ProjectOpen(void* pAddress, kULong pMaxLength, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00354
00363 bool ProjectOpen(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00364
00365 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00366
00374 bool ProjectOpen (KFile * pFile, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00375 #endif
00376
00385 bool ProjectOpenDirect(const char* pName, KFbxReader* pReader, bool pCheckCRC = false, bool pOpenMainSection = true, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00386
00396 bool ProjectCreate(void* pAddress, kUInt pSize, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00397
00406 bool ProjectCreate(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00407
00416 bool ProjectCreateDirect(const char* pName, KFbxWriter* pWriter, bool pBinary, bool pEncrypted, KFbxFileHeaderInfo* pFileHeaderInfo = NULL);
00417
00426 bool ProjectCreateEmpty(const char* pName, KFbxWriter* pWriter, int pVersion, bool pBinary, bool pEncrypted);
00427
00431 bool ProjectWrite_BeginFileHeader();
00432
00436 bool ProjectWrite_BeginExtendedHeader();
00437
00442 bool ProjectWrite_WriteExtendedHeader(const KFbxFileHeaderInfo* pExtendedHeader);
00443
00447 bool ProjectWrite_EndExtendedHeader();
00448
00452 bool ProjectWrite_EndFileHeader();
00453
00459 bool ProjectClose(void** pData=0,kULong *pSize=0);
00460
00464 void ProjectSetXRefManager(const KFbxXRefManager*);
00465
00469 const KFbxXRefManager* ProjectGetXRefManager() const;
00470
00485 bool ProjectCreateEmbeddedFolder(const KFbxXRefManager& pXRefManager, KString& pCreatedFolder, const char* pUserDefinedFolder = NULL);
00486
00490 void SetEmbedded(bool pValue);
00491
00495 void SetEmbeddingExtractionFolder(const char* pExtractionFolder);
00496
00499 const char* GetEmbeddingExtractionFolder();
00500
00504 bool IsEmbedded() const;
00505
00509 bool IsBinary() const;
00510
00514 bool IsEncrypted () const;
00515
00519 bool CheckCRC();
00520
00524 kUInt32 GetFileVersionNumber() const;
00525
00527
00538
00540 bool Fbx7Support() const;
00541
00545 void Fbx7Support(bool pSupport);
00546
00548 bool CompressArrays() const;
00549
00553 void CompressArrays(bool pCompress);
00554
00556 int CompressMinimumSize() const;
00557
00561 void CompressMinimumSize(int pSize);
00562
00564 int CompressLevel() const;
00565
00571 void CompressLevel(int pLevel);
00573
00579
00583 bool ProjectOpenMainSection();
00584
00588 int ProjectGetExtensionSectionCount() const;
00589
00594 bool ProjectOpenExtensionSection(int pExtensionSectionIndex);
00595
00600 bool ProjectCreateExtensionSection(bool pOverwriteLastExtensionSection = false);
00601
00604 void ProjectCloseSection();
00605
00609 int ProjectGetCurrentSection() const;
00610
00614 int ProjectGetCurrentSectionMode() const;
00615
00619 int ProjectGetCurrentSectionVersion() const;
00620
00628 int ProjectGetSectionVersion(int pSection) const;
00629
00636 static void ProjectConvertVersionNumber(int pVersion, int& pMajor, int& pMinor, int& pRevision);
00637
00641 bool IsPasswordProtected() const;
00642
00648 bool CheckPassword(const char* pPassword);
00649
00656 bool WritePassword(const char* pPassword);
00657
00659
00664
00668 const char* GetFilename() const;
00669
00674 KString GetDataDirectory(bool pAutoCreate = true);
00675
00684 KString GetMediaDirectory(bool pCreate = false, const char* pUserDefinedFolder = NULL);
00685
00691 KString GetContainerTemplateDirectory(const char* pTemplateName, bool pCreate);
00692
00697 char* GetRelativePath(const char* pPath);
00698
00703 char* GetRelativeFilePath(const char* pFilePath);
00704
00709 char* GetFullPath(const char* pRelativePath);
00710
00715 char* GetFullFilePath(const char* pRelativeFilePath);
00716
00721 char* GetTmpProjectName(const char* pName) const;
00722
00728 bool SwapFromTmpProject(const char* pName, char* pError=NULL);
00729
00731
00737
00740 void FieldReadResetPosition();
00741
00745 int FieldGetCount() const;
00746
00751 const char* FieldGetName(int pFieldIndex) const;
00752
00757 int FieldGetInstanceCount(const char* pFieldName) const;
00758
00764 bool FieldReadBegin(int pFieldIndex, int pInstance);
00765
00770 bool FieldReadBegin(const char* pFieldName);
00771
00777 bool FieldReadBegin(const char* pFieldName, int pInstance);
00778
00780 void FieldReadEnd();
00781
00783 bool FieldReadIsBlock();
00784
00786 bool FieldReadBlockBegin();
00787
00789 void FieldReadBlockEnd();
00790
00792 int FieldReadGetCount() const;
00793
00795 int FieldReadGetRemain() const;
00796
00798 char FieldReadGetType() const;
00799
00801 char FieldReadCH();
00802
00807 char FieldReadCH(const char* pFieldName, char pDefault=0);
00808
00810 const char* FieldReadC();
00811
00816 const char* FieldReadC(const char* pFieldName, const char* pDefault="");
00817
00819 const char* FieldReadS();
00820
00825 const char* FieldReadS(const char* pFieldName, const char* pDefault="");
00826
00828 bool FieldReadB();
00829
00834 bool FieldReadB(const char* pFieldName, bool pDefault = false);
00835
00837 int FieldReadI();
00838 int FieldReadI(const char* pFieldName, int pDefault=0);
00843
00845 kLongLong FieldReadLL();
00846
00851 kLongLong FieldReadLL(const char* pFieldName, kLongLong pDefault=0);
00852
00854 float FieldReadF();
00855
00860 float FieldReadF(const char* pFieldName, float pDefault=0);
00861
00863 double FieldReadD();
00864
00869 double FieldReadD(const char* pFieldName, double pDefault=0);
00870
00874 KTime FieldReadT(const char* pFieldName);
00875
00877 KTime FieldReadT();
00878
00882 KTimeSpan FieldReadTS(const char* pFieldName);
00883
00885 KTimeSpan FieldReadTS();
00886
00891 void FieldReadFn(float* pValue, kUInt pn);
00892
00896 void FieldRead3F(float* pValue);
00897
00901 void FieldRead4F(float* pValue);
00902
00909 void FieldReadFn(const char* pFieldName, float* pValue, const float *pDefault, kUInt pn);
00910
00916 void FieldRead3F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00917
00923 void FieldRead4F(const char* pFieldName, float* pValue, const float* pDefault=NULL);
00924
00929 void FieldReadDn(double* pValue, kUInt pn);
00930
00934 void FieldRead3D(double* pValue);
00935
00939 void FieldRead4D(double* pValue);
00940
00947 void FieldReadDn(const char* pFieldName, double* pValue, const double *pDefault, kUInt pn);
00948
00954 void FieldRead3D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00955
00961 void FieldRead4D(const char* pFieldName, double* pValue, const double* pDefault=NULL);
00962
00966 void* FieldReadR(int* pByteSize);
00967
00972 void* FieldReadR(const char* pFieldName,int* pByteSize);
00973
00978
00979 kByte FieldReadByte();
00980
00985 kByte FieldReadByte(const char* pFieldName, kByte pDefault=0);
00986
00988 kUByte FieldReadUByte();
00989
00994 kUByte FieldReadUByte(const char* pFieldName, kUByte pDefault=0);
00995
00997 kShort FieldReadShort();
00998
01003 kShort FieldReadShort(const char* pFieldName, kShort pDefault=0);
01004
01006 kUShort FieldReadUShort();
01007
01012 kUShort FieldReadUShort(const char* pFieldName, kUShort pDefault=0);
01013
01015 unsigned int FieldReadUI();
01016
01021 unsigned int FieldReadUI(const char* pFieldName, unsigned int pDefault=0);
01022
01024 kULongLong FieldReadULL();
01025
01030 kULongLong FieldReadULL(const char* pFieldName, kULongLong pDefault=0);
01031
01035 const kByte* FieldReadArraySBytes( int &pCount );
01039 const kShort* FieldReadArrayShort ( int &pCount );
01043 const kUShort* FieldReadArrayUShort( int &pCount );
01047 const unsigned int* FieldReadArrayUI ( int &pCount );
01051 const kULongLong* FieldReadArrayULL ( int &pCount );
01052
01056 const kByte* FieldReadArray(int &pCount, const kByte*);
01063 const kShort* FieldReadArray(int &pCount, const kShort*);
01067 const kUShort* FieldReadArray(int &pCount, const kUShort*);
01071 const unsigned int* FieldReadArray(int &pCount, const unsigned int*);
01075 const kULongLong* FieldReadArray(int &pCount, const kULongLong*);
01077
01086 virtual bool FieldReadEmbeddedFile (KString& pFileName, KString& pRelativeFileName, const char* pEmbeddedMediaDirectory = "", bool *pIsFileCreated=NULL);
01087
01091 const double* FieldReadArrayD( int &pCount );
01095 const float* FieldReadArrayF( int &pCount );
01099 const int* FieldReadArrayI( int &pCount );
01103 const kLongLong*FieldReadArrayLL(int &pCount );
01107 const bool* FieldReadArrayB( int &pCount );
01111 const kUByte* FieldReadArrayBytes( int &pCount );
01112
01116 const int* FieldReadArray(int& pCount, const int*);
01120 const float* FieldReadArray(int& pCount, const float*);
01124 const double* FieldReadArray(int& pCount, const double*);
01128 const kLongLong* FieldReadArray(int& pCount, const kLongLong*);
01132 const bool* FieldReadArray(int& pCount, const bool*);
01136 const kUByte* FieldReadArray(int& pCount, const kUByte*);
01137
01139
01145
01149 void FieldWriteBegin(const char* pFieldName);
01150
01152 void FieldWriteEnd();
01153
01155 void FieldWriteBlockBegin();
01156
01162 void FieldWriteObjectBegin(const char* pObjectType, const char* pName, const char* pSubType=NULL);
01163
01165 void FieldWriteObjectEnd();
01166
01171 void FieldWriteBlockBegin(const char* pFileName);
01172
01174 void FieldWriteBlockEnd ();
01175
01179 void FieldWriteCH(char pValue);
01180
01185 void FieldWriteCH(const char* pFieldName, char pValue);
01186
01190 void FieldWriteC(const char* pValue);
01191
01196 void FieldWriteC(const char* pFieldName, const char* pValue);
01197
01201 void FieldWriteS(const char* pValue);
01202
01206 void FieldWriteS(const KString& pValue);
01207
01212 void FieldWriteS(const char* pFieldName, const char* pValue);
01213
01218 void FieldWriteS(const char* pFieldName, const KString& pValue);
01219
01223 void FieldWriteB(bool pValue);
01224
01229 void FieldWriteB(const char* pFieldName, bool pValue);
01230
01234 void FieldWriteI(int pValue);
01235
01240 void FieldWriteI(const char* pFieldName, int pValue);
01241
01245 void FieldWriteLL(kLongLong pValue);
01246
01251 void FieldWriteLL(const char* pFieldName, kLongLong pValue);
01252
01257 void FieldWriteF(float pValue);
01258
01264 void FieldWriteF(const char* pFieldName, float pValue);
01265
01269 void FieldWriteD(double pValue);
01270
01275 void FieldWriteD(const char* pFieldName, double pValue);
01276
01280 void FieldWriteT(KTime pTime);
01281
01286 void FieldWriteT(const char* pFieldName,KTime pValue);
01287
01291 void FieldWriteTS(KTimeSpan pTimeSpan);
01292
01297 void FieldWriteTS(const char* pFieldName,KTimeSpan pValue);
01298
01303 void FieldWriteFn(const float* pValue, kUInt pn);
01304
01310 void FieldWriteFn(const char* pFieldName, const float* pValue, kUInt pn);
01311
01315 void FieldWrite3F(const float* pValue);
01316
01321 void FieldWrite3F(const char* pFieldName, const float* pValue);
01322
01326 void FieldWrite4F(const float* pValue);
01327
01332 void FieldWrite4F(const char* pFieldName, const float* pValue);
01333
01338 void FieldWriteDn(const double* pValue, kUInt pn);
01339
01345 void FieldWriteDn(const char* pFieldName, const double* pValue, kUInt pn);
01346
01350 void FieldWrite3D(const double* pValue);
01351
01356 void FieldWrite3D(const char* pFieldName, const double* pValue);
01357
01361 void FieldWrite4D(const double* pValue);
01362
01367 void FieldWrite4D(const char* pFieldName, const double* pValue);
01368
01369
01370
01371
01372
01373
01380 void FieldWriteArrayD( int n, const double* pValue, int pSize = 1, int pStride = 0 );
01387 void FieldWriteArrayF( int n, const float* pValue, int pSize = 1, int pStride = 0 );
01394 void FieldWriteArrayI( int n, const int* pValue, int pSize = 1, int pStride = 0 );
01401 void FieldWriteArrayLL(int n, const kLongLong* pValue, int pSize = 1, int pStride = 0 );
01408 void FieldWriteArrayB( int n, const bool* pValue, int pSize = 1, int pStride = 0 );
01415 void FieldWriteArrayBytes( int n, const kUByte* pValue, int pSize = 1, int pStride = 0 );
01416
01421 void FieldWriteR(const void* pRawData, int pByteSize);
01422
01428 void FieldWriteR(const char* pFieldName, const void* pRawData, int pByteSize);
01429
01434
01438 void FieldWriteByte(kByte pValue);
01439
01444 void FieldWriteByte(const char* pFieldName, kByte pValue);
01445
01449 void FieldWriteUByte(kUByte pValue);
01450
01455 void FieldWriteUByte(const char* pFieldName, kUByte pValue);
01456
01460 void FieldWriteShort(kShort pValue);
01461
01466 void FieldWriteShort(const char* pFieldName, kShort pValue);
01467
01471 void FieldWriteUShort(kUShort pValue);
01472
01477 void FieldWriteUShort(const char* pFieldName, kUShort pValue);
01478
01482 void FieldWriteUI(unsigned int pValue);
01483
01488 void FieldWriteUI(const char* pFieldName, unsigned int pValue);
01489
01493 void FieldWriteULL(kULongLong pValue);
01494
01500 void FieldWriteULL(const char* pFieldName, kULongLong pValue);
01501
01508 void FieldWriteArraySBytes( int n, const kByte* pValue, int pSize = 1, int pStride = 0 );
01515 void FieldWriteArrayShort( int n, const kShort* pValue, int pSize = 1, int pStride = 0 );
01522 void FieldWriteArrayUShort( int n, const kUShort* pValue, int pSize = 1, int pStride = 0 );
01529 void FieldWriteArrayUI( int n, const unsigned int* pValue, int pSize = 1, int pStride = 0 );
01536 void FieldWriteArrayULL(int n, const kULongLong* pValue, int pSize = 1, int pStride = 0 );
01538
01542 int GetFieldRMaxChunkSize() const;
01543
01547 void FieldWriteObjectReference(const char* pName);
01548
01553 void FieldWriteObjectReference(const char* pFieldName, const char* pName);
01554
01561 bool FieldWriteEmbeddedFile (KString pFileName, KString pRelativeFileName);
01562
01566 void WriteComments(const char* pFieldName);
01567
01569
01575
01577 enum EError
01578 {
01579 eFileCorrupted,
01580 eFileVersionNotSupportedYet,
01581 eFileVersionNotSupportedAnymore,
01582 eFileNotOpened,
01583 eFileNotCreated,
01584 eDirectoryNotCreated,
01585 eCrcCheckFailed,
01586 eNonExistingSection,
01587 eOperationCanceled,
01588 eCountError,
01589 eInvalidData,
01590 eWriteError,
01591 eReadError,
01592 eErrorCount
01593 };
01594
01598 KError& GetError();
01599
01603 EError GetLastErrorID() const;
01604
01608 const char* GetLastErrorString() const;
01609
01611
01612 #ifdef _DEBUG
01613
01614 void StdoutDump();
01615 #endif
01616
01624 bool GetHaveLoadedEmbededFile() const;
01625
01630 void* GetMemoryFileInfo(kULong& pSize) const;
01631
01632 public:
01633
01637 bool IsBeforeVersion6() const;
01638
01642 void SetIsBeforeVersion6(bool pIsBeforeVersion6);
01643
01644 private:
01645 struct KFbxImpl;
01646 KFbxImpl* mImpl;
01647
01649
01650 void ProjectClear();
01651 void ProjectReset();
01652
01653 bool ProjectReadHeader(bool pCheckASCIIHeader, bool pCheckCRC, bool pOpenMainSection, KFbxFileHeaderInfo* pFileHeaderInfo);
01654 bool ProjectReadExtendedHeader(int& pExtendedHeaderEnd, KFbxFileHeaderInfo* pFileHeaderInfo);
01655 bool BinaryReadHeader();
01656 bool BinaryReadSectionPosition();
01657 bool ASCIIReadHeader();
01658 bool ASCIIReadSectionPosition();
01659
01660 bool ProjectWriteHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01661 bool ProjectWriteExtendedHeader(KFbxFileHeaderInfo* pFileHeaderInfo);
01662 void BinaryWriteHeader();
01663 void ASCIIWriteHeader();
01664
01665 void ReadEncryptionKey(char* pEncryptionKey);
01666 void WriteEncryptionKey(char* pEncryptionKey);
01667
01669
01670 bool ProjectClearSection();
01671 bool ProjectOpenSection(int pSection);
01672 bool BinaryReadSectionHeader();
01673 int BinaryReadSectionFooter(char* pSourceCheck);
01674 bool BinaryReadExtensionCode(kUInt32 pFollowingSectionStart, kUInt32& pSectionStart, kUInt32& pSectionVersion);
01675 void BinaryReadSectionPassword();
01676
01677 bool ProjectWriteSectionHeader();
01678 void BinaryWriteSectionFooter();
01679 bool BinaryWriteExtensionCode(kUInt32 pSectionStart, kUInt32 pSectionVersion);
01680
01681 KString GetCreationTime() const;
01682 void SetCreationTime(KString pCreationTime);
01683 void CreateSourceCheck(char* lSourceCheck);
01684 bool TestSourceCheck(char* pSourceCheck, char* pSourceCompany);
01685 KString GetMangledCreationTime();
01686 void EncryptSourceCheck(char* pSourceCheck, char* pEncryptionData);
01687 void DecryptSourceCheck(char* pSourceCheck, const char* pEncryptionData);
01688
01689 void EncryptPasswordV1(KString pOriginalPassword, KString &pEncryptedPassword);
01690 void DecryptPasswordV1(KString pEncryptedPassword, KString &pDecryptedPassword);
01691
01693
01694 void CheckValidityOfFieldName(const char* pFieldName);
01695 void GetUnusedEmbeddedName(const KString& pDirectory, const KString& pName, KString& pResult, bool pCreateSubdirectory);
01696
01698 KString GetDirectory(bool pAutoCreate, const char* pExtension);
01699 };
01700
01701 #include <fbxfilesdk/fbxfilesdk_nsend.h>
01702
01703 #endif // FBXFILESDK_COMPONENTS_KBASELIB_KFBX_KFBX_H
01704