kfbxlayer.h

Go to the documentation of this file.
00001 /****************************************************************************************
00002 
00003    Copyright (C) 2010 Autodesk, Inc.
00004    All rights reserved.
00005 
00006    Use of this software is subject to the terms of the Autodesk license agreement
00007    provided at the time of installation or download, or which otherwise accompanies
00008    this software in either electronic or hard copy form.
00009 
00010 ****************************************************************************************/
00011 
00015 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
00016 #define FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
00017 
00018 
00019 #include <fbxfilesdk/fbxfilesdk_def.h>
00020 
00021 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00022 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00023 #include <fbxfilesdk/components/kbaselib/klib/kdebug.h>
00024 
00025 #include <fbxfilesdk/kfbxmath/kfbxvector2.h>
00026 #include <fbxfilesdk/kfbxmath/kfbxvector4.h>
00027 #include <fbxfilesdk/kfbxplugins/kfbxcolor.h>
00028 #include <fbxfilesdk/kfbxplugins/kfbxdatatypes.h>
00029 #include <fbxfilesdk/kfbxplugins/kfbxstream.h>
00030 #include <fbxfilesdk/kfbxplugins/kfbxsurfacematerial.h>
00031 #include <fbxfilesdk/kfbxplugins/kfbxtexture.h>
00032 
00033 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00034 
00035 class KFbxTexture;
00036 class KFbxSurfaceMaterial;
00037 class KFbxSdkManager;
00038 
00039 class KFbxGeometryBase;
00040 class KFbxLayer;
00041 class KFbxLayerContainer;
00042 class KFbxMesh;
00043 class KFbxNode;
00044 
00045 
00056 class KFBX_DLL KFbxLayerElement
00057 {
00058 
00059 public:
00060 
00095     typedef enum 
00096     {
00097         eUNDEFINED,
00098 
00099         //NON-TEXTURE LAYER ELEMENT BEGIN
00100         eNORMAL,
00101         eBINORMAL,
00102         eTANGENT,
00103         eMATERIAL,
00104         ePOLYGON_GROUP,
00105         eUV,
00106         eVERTEX_COLOR,
00107         eSMOOTHING,
00108         eVERTEX_CREASE,
00109         eEDGE_CREASE,
00110         eHOLE,
00111         eUSER_DATA,
00112         eVISIBILITY,
00113         //NEW NON-TEXTURE LAYER ELEMENT ADD HERE...
00114 
00115         //NON-TEXTURE LAYER ELEMENT END
00116 
00117         //TEXTURE LAYER ELEMENT BEGIN
00118         eDIFFUSE_TEXTURES,
00119         eDIFFUSE_FACTOR_TEXTURES,
00120         eEMISSIVE_TEXTURES,
00121         eEMISSIVE_FACTOR_TEXTURES,
00122         eAMBIENT_TEXTURES,
00123         eAMBIENT_FACTOR_TEXTURES,
00124         eSPECULAR_TEXTURES,
00125         eSPECULAR_FACTOR_TEXTURES,
00126         eSHININESS_TEXTURES,
00127         eNORMALMAP_TEXTURES,
00128         eBUMP_TEXTURES,
00129         eTRANSPARENT_TEXTURES,
00130         eTRANSPARENCY_FACTOR_TEXTURES,
00131         eREFLECTION_TEXTURES,
00132         eREFLECTION_FACTOR_TEXTURES,
00133         eDISPLACEMENT_TEXTURES,
00134         //NEW TEXTURE LAYER ELEMENT ADD HERE...
00135         eVECTOR_DISPLACEMENT_TEXTURES,
00136 
00137         //TEXTURE LAYER ELEMENT END
00138 
00139         eLAST_ELEMENT_TYPE
00140     } ELayerElementType;
00141 
00142     //common used constant for looping through and access layer element
00143 
00145     const static int LAYERELEMENT_TYPE_TEXTURE_START_INDEX = int(eDIFFUSE_TEXTURES);
00146 
00148     const static int LAYERELEMENT_TYPE_TEXTURE_END_INDEX = int(eLAST_ELEMENT_TYPE) - 1;
00149 
00151     const static int LAYERELEMENT_TYPE_TEXTURE_COUNT = LAYERELEMENT_TYPE_TEXTURE_END_INDEX - LAYERELEMENT_TYPE_TEXTURE_START_INDEX + 1;
00152 
00154     const static int LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX = int(eNORMAL);
00155 
00157     const static int LAYERELEMENT_TYPE_NON_TEXTURE_END_INDEX = int(eVISIBILITY);
00158 
00160     const static int LAYERELEMENT_TYPE_NON_TEXTURE_COUNT = LAYERELEMENT_TYPE_NON_TEXTURE_END_INDEX - LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX + 1;
00161 
00162     //names for different textures and non-textures channels
00163 
00165     static const char* const TEXTURE_NAMES[];
00166 
00168     static const char* const TEXTURE_UV_NAMES[];
00169 
00171     static const char* const NON_TEXTURE_NAMES[];
00172 
00174     static const KFbxDataType TEXTURE_TYPES[];
00175 
00177     static const char* const TEXTURE_CHANNEL_NAMES[];
00178 
00189     typedef enum 
00190     {
00191         eNONE,
00192         eBY_CONTROL_POINT,
00193         eBY_POLYGON_VERTEX,
00194         eBY_POLYGON,
00195         eBY_EDGE,
00196         eALL_SAME
00197     } EMappingMode;
00198 
00212     typedef enum 
00213     {
00214         eDIRECT,
00215         eINDEX,
00216         eINDEX_TO_DIRECT
00217     } EReferenceMode;
00218 
00219     
00223     void SetMappingMode(EMappingMode pMappingMode) { mMappingMode = pMappingMode; }
00224 
00228     void SetReferenceMode(EReferenceMode pReferenceMode) { mReferenceMode = pReferenceMode; }
00229 
00233     EMappingMode GetMappingMode() const { return mMappingMode; }
00234 
00238     EReferenceMode GetReferenceMode() const { return mReferenceMode; }
00239 
00243     void SetName(const char* pName) { mName = KString(pName); }
00244 
00248     const char* GetName() const { return ((KFbxLayerElement*)this)->mName.Buffer(); }
00249 
00254     bool operator==(const KFbxLayerElement& pOther) const
00255     {
00256         return (mName == pOther.mName) && 
00257                (mMappingMode == pOther.mMappingMode) &&
00258                (mReferenceMode == pOther.mReferenceMode);
00259     }
00260 
00265     KFbxLayerElement& operator=( KFbxLayerElement const& pOther )
00266     {
00267         mMappingMode = pOther.mMappingMode;
00268         mReferenceMode = pOther.mReferenceMode;
00269         // name, type and owner should not be copied because they are
00270         // initialized when this object is created
00271         return *this;
00272     }
00273 
00275     void Destroy();
00276 
00278     virtual bool Clear() 
00279     { 
00280         return true;
00281     }
00282 
00284 //
00285 //  WARNING!
00286 //
00287 //  Anything beyond these lines may not be documented accurately and is 
00288 //  subject to change without notice.
00289 //
00291 
00292 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00293     void SetType(const KFbxDataType* pType) { mType = pType; }
00294     const KFbxLayerContainer* GetOwner() const { return mOwner; }
00295 
00296 protected:
00297     KFbxLayerElement() 
00298         : mMappingMode(eNONE)
00299         , mReferenceMode(eDIRECT)
00300         , mName("")
00301         , mOwner(NULL)
00302     {
00303     }
00304     
00305     virtual ~KFbxLayerElement()
00306     {
00307     }
00308 
00309     EMappingMode mMappingMode;
00310     EReferenceMode mReferenceMode;
00311 
00312     KString mName;
00313     const KFbxDataType* mType;
00314     KFbxLayerContainer* mOwner;
00315 
00316     void Destruct() { FbxSdkDelete(this); }
00317     virtual void SetOwner(KFbxLayerContainer* pOwner);
00318 
00319     KFBXNEW_DECLARE_FRIEND
00320     friend class KFbxLayerContainer;
00321 
00322 public:
00327     virtual int MemorySize() const { return 0; }
00328 
00333 
00339     virtual bool ContentWriteTo(KFbxStream& pStream) const;
00340 
00346     virtual bool ContentReadFrom(const KFbxStream& pStream);
00348 
00349 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00350 };
00351 
00357 class KFBX_DLL LockAccessStatus
00358 {
00359 public:
00372     typedef enum {
00373         eSuccess,
00374         eUnsupportedDTConversion,
00375         eCorruptedCopyback,
00376         eBadValue,
00377         eLockMismatch,
00378         eNoWriteLock,
00379         eNoReadLock,
00380         eNotOwner,
00381         eDirectLockExist
00382     } ELockAccessStatus;
00383 };
00384 
00390 class KFBX_DLL KFbxLayerElementArray
00391 {
00392 public:
00397 
00401     KFbxLayerElementArray(EFbxType pDataType);
00402 
00404     virtual ~KFbxLayerElementArray();
00405 
00407 
00412 
00414     inline                                void ClearStatus()     { mStatus = LockAccessStatus::eSuccess; }
00415 
00417     inline LockAccessStatus::ELockAccessStatus GetStatus() const { return mStatus; }
00419 
00424 
00428     inline bool IsWriteLocked() const { return mWriteLock; };
00429 
00433     inline int  GetReadLockCount() const { return mReadLockCount; }
00435 
00439     bool    IsInUse() const;
00440 
00444     int     ReadLock() const;
00445 
00449     int     ReadUnlock() const;
00450 
00455     bool    WriteLock() const;
00456 
00459     void    WriteUnlock() const;
00460 
00465     bool    ReadWriteLock() const;
00466 
00469     void    ReadWriteUnlock() const;
00470 
00471 
00477     typedef enum {
00478         eREAD_LOCK = 1,
00479         eWRITE_LOCK = 2,
00480         eREADWRITE_LOCK = 3
00481     } ELockMode;
00482 
00495     virtual void*   GetLocked(ELockMode pLockMode, EFbxType pDataType);
00496 
00508     void*   GetLocked(ELockMode pLockMode=eREADWRITE_LOCK) { return GetLocked(pLockMode, mDataType); }
00509 
00522     template <class T> inline T* GetLocked(T* dummy=NULL, ELockMode pLockMode=eREADWRITE_LOCK) {T v; return (T*)GetLocked(pLockMode, _FbxTypeOf(v)); }
00523 
00534     virtual void   Release(void** pDataPtr, EFbxType pDataType);
00535 
00545     void   Release(void** pDataPtr) { Release(pDataPtr, mDataType); }
00546 
00557     template <class T> inline void Release(T** pDataPtr, T* dummy) { Release((void**)pDataPtr, _FbxTypeOf(*dummy)); }
00558 
00561     virtual size_t GetStride() const;
00562 
00567 
00569     int     GetCount() const;
00570 
00574     void    SetCount(int pCount);
00575 
00577     void    Clear();
00578 
00582     void    Resize(int pItemCount);
00583 
00587     void    AddMultiple(int pItemCount);
00588 
00594     int     Add(void const* pItem, EFbxType pValueType);
00595 
00603     int     InsertAt(int pIndex, void const* pItem, EFbxType pValueType);
00604 
00611     void    SetAt(int pIndex, void const* pItem, EFbxType pValueType);
00612 
00618     void    SetLast(void const* pItem, EFbxType pValueType);
00619 
00626     void    RemoveAt(int pIndex, void** pItem, EFbxType pValueType);
00627 
00633     void    RemoveLast(void** pItem, EFbxType pValueType);
00634 
00640     bool    RemoveIt(void** pItem, EFbxType pValueType);
00641 
00649     bool    GetAt(int pIndex, void** pItem, EFbxType pValueType) const;
00650 
00656     bool    GetFirst(void** pItem, EFbxType pValueType) const;
00657 
00663     bool    GetLast(void** pItem, EFbxType pValueType) const;
00664 
00671     int     Find(void const* pItem, EFbxType pValueType) const;
00672 
00680     int     FindAfter(int pAfterIndex, void const* pItem, EFbxType pValueType) const;
00681 
00689     int     FindBefore(int pBeforeIndex, void const* pItem, EFbxType pValueType) const;
00690 
00695     bool    IsEqual(const KFbxLayerElementArray& pArray) const;
00696 
00701     template <class T> inline int  Add(T const& pItem)                               { return Add((void const*)&pItem, _FbxTypeOf(pItem)); }
00702 
00709     template <class T> inline int  InsertAt(int pIndex, T const& pItem)              { return InsertAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00710 
00716     template <class T> inline void SetAt(int pIndex, T const& pItem)                 { SetAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00717 
00722     template <class T> inline void SetLast(T const& pItem)                           { SetLast((void const*)&pItem, _FbxTypeOf(pItem)); }
00723 
00729     template <class T> inline void RemoveAt(int pIndex, T* pItem)                    { RemoveAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00730 
00735     template <class T> inline void RemoveLast(T* pItem)                              { RemoveLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00736 
00741     template <class T> inline bool RemoveIt(T* pItem)                                { return RemoveIt((void**)&pItem, _FbxTypeOf(*pItem)); }
00742 
00749     template <class T> inline bool GetAt(int pIndex, T* pItem) const                 { return GetAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00750 
00755     template <class T> inline bool GetFirst(T* pItem) const                          { return GetFirst((void**)&pItem, _FbxTypeOf(*pItem)); }
00756 
00761     template <class T> inline bool GetLast(T* pItem) const                           { return GetLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00762 
00768     template <class T> inline int Find(T const& pItem) const                         { return Find((void const*)&pItem, _FbxTypeOf(pItem)); }
00769 
00776     template <class T> inline int FindAfter(int pAfterIndex, T const& pItem) const   { return FindAfter(pAfterIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00777 
00784     template <class T> inline int FindBefore(int pBeforeIndex, T const& pItem) const { return FindBefore(pBeforeIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00785 
00786 
00790     template<typename T> inline void CopyTo(KArrayTemplate<T>& pDst)
00791     {
00792         T src;
00793         T* srcPtr = &src;
00794 
00795         pDst.Clear();
00796         if (mDataType != _FbxTypeOf(src))
00797         {
00798             SetStatus(LockAccessStatus::eUnsupportedDTConversion);
00799             return;
00800         }
00801 
00802         pDst.SetCount(GetCount());
00803         for (int i = 0; i < GetCount(); i++)
00804         {
00805             if (GetAt(i, (void**)&srcPtr, mDataType))
00806             {
00807                 pDst.SetAt(i, src);
00808             }
00809         }
00810         SetStatus(LockAccessStatus::eSuccess);
00811     }
00813 
00814 protected:
00815     void*   GetDataPtr();
00816     void*   GetReference(int pIndex, EFbxType pValueType);
00817     void    GetReferenceTo(int pIndex, void** pRef, EFbxType pValueType);
00818 
00819     inline void SetStatus(LockAccessStatus::ELockAccessStatus pVal) const
00820     {
00821         const_cast<KFbxLayerElementArray*>(this)->mStatus = pVal;
00822     }
00823 
00824             void   SetImplementation(void* pImplementation);
00825     inline  void*  GetImplementation() { return mImplementation; }
00826     virtual void   ConvertDataType(EFbxType pDataType, void** pDataPtr, size_t* pStride);
00827 
00828     EFbxType mDataType;
00829 
00830 private:
00831     LockAccessStatus::ELockAccessStatus mStatus;
00832 
00833     int           mReadLockCount;
00834     bool          mWriteLock;
00835     void*         mImplementation;
00836     size_t        mStride;
00837     int           mDirectLockOn;
00838     bool          mDirectAccessOn;
00839 
00840     KArrayTemplate<void*>   mConvertedData;
00841 
00842 };
00843 
00847 template <typename T>
00848 struct KFbxLayerElementArrayReadLock
00849 {
00853     KFbxLayerElementArrayReadLock(KFbxLayerElementArray& pArray) : mArray(pArray)
00854     {
00855         mLockedData = mArray.GetLocked((T*)NULL, KFbxLayerElementArray::eREAD_LOCK);
00856     }
00857 
00861     ~KFbxLayerElementArrayReadLock()
00862     {
00863         if( mLockedData )
00864         {
00865             mArray.Release((void **) &mLockedData);
00866         }
00867     }
00868 
00872     const T* GetData() const
00873     {
00874         return mLockedData;
00875     }
00876 
00877 private:
00878     KFbxLayerElementArray&  mArray;
00879     T* mLockedData;
00880 };
00881 
00882 class KFbxLayerElementUserData;
00883 
00888 template <class T> class KFbxLayerElementArrayTemplate : public KFbxLayerElementArray
00889 {
00890 public:
00891 
00895     KFbxLayerElementArrayTemplate(EFbxType pDataType) :
00896         KFbxLayerElementArray(pDataType)
00897         {
00898         }
00899 
00904     inline int  Add( T const &pItem )                       { return KFbxLayerElementArray::Add(pItem); }
00905 
00911     inline int  InsertAt(int pIndex, T const &pItem)        { return KFbxLayerElementArray::InsertAt(pIndex, pItem); }
00912 
00917     inline void SetAt(int pIndex, T const &pItem)           { KFbxLayerElementArray::SetAt(pIndex, pItem); }
00918 
00922     inline void SetLast( T const &pItem)                    { KFbxLayerElementArray::SetLast(pItem); }
00923 
00928     inline T RemoveAt(int pIndex)                           { T lValue; KFbxLayerElementArray::RemoveAt(pIndex, &lValue); return lValue; }
00929 
00933     inline T RemoveLast()                                   { T lValue; KFbxLayerElementArray::RemoveLast(&lValue); return lValue; }
00934 
00939     inline bool RemoveIt(T const &pItem)                    { return KFbxLayerElementArray::RemoveIt(&pItem); }
00940 
00946     inline T  GetAt(int pIndex) const                       { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
00947 
00951     inline T  GetFirst() const                              { T lValue; KFbxLayerElementArray::GetFirst(&lValue); return lValue; }
00952 
00956     inline T  GetLast() const                               { T lValue; KFbxLayerElementArray::GetLast(&lValue); return lValue; }
00957 
00963     inline int Find(T const &pItem)                         { return KFbxLayerElementArray::Find(pItem); }
00964 
00971     inline int FindAfter(int pAfterIndex, T const &pItem)   { return KFbxLayerElementArray::FindAfter(pAfterIndex, pItem); }
00972 
00979     inline int FindBefore(int pBeforeIndex, T const &pItem) { return KFbxLayerElementArray::FindBefore(pBeforeIndex, pItem); }
00980 
00986     T  operator[](int pIndex) const                         { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; } 
00987 
00991     KFbxLayerElementArray& operator=(const KArrayTemplate<T>& pArrayTemplate)
00992     {
00993         SetStatus(LockAccessStatus::eNoWriteLock);
00994         if (WriteLock())
00995         {
00996             SetCount(pArrayTemplate.GetCount());
00997             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
00998                 SetAt(i, pArrayTemplate.GetAt(i));
00999             WriteUnlock();
01000             SetStatus(LockAccessStatus::eSuccess);
01001         }
01002         return *this;
01003     }
01004 
01008     KFbxLayerElementArrayTemplate<T>& operator=(const KFbxLayerElementArrayTemplate<T>& pArrayTemplate)
01009     {
01010         if ( this != &pArrayTemplate )
01011         {
01012             SetStatus(LockAccessStatus::eNoWriteLock);
01013             if (WriteLock())
01014             {
01015                 SetCount(pArrayTemplate.GetCount());
01016                 for (int i = 0; i < pArrayTemplate.GetCount(); i++)
01017                     SetAt(i, pArrayTemplate.GetAt(i));
01018                 WriteUnlock();
01019                 SetStatus(LockAccessStatus::eSuccess);
01020             }
01021         }
01022         return *this;
01023     }
01024 
01025 private:
01026     // This one is not the best thing to do, but at least I don't get deprecated calls inside this file.
01027     // Note that KFbxLayerElementUserData is kind of a weird class in the first place anyway. So either
01028     // we clean it up, or we live with this piece of code ;-)
01029     friend class KFbxLayerElementUserData;
01030     T& AsReference(int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
01031 
01032     T dummy;
01033 };
01034 
01035 
01043 extern int RemapIndexArrayTo(KFbxLayerElement* pLayerEl, 
01044                              KFbxLayerElement::EMappingMode pNewMapping, 
01045                              KFbxLayerElementArrayTemplate<int>* pIndexArray);
01046 
01047 
01052 template <class Type> class KFbxLayerElementTemplate : public KFbxLayerElement
01053 {
01054 public:
01055 
01060     KFbxLayerElementArrayTemplate<Type>& GetDirectArray() const
01061     { 
01062         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01063         return *mDirectArray; 
01064     }
01065 
01070     KFbxLayerElementArrayTemplate<Type>& GetDirectArray()
01071     { 
01072         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01073         return *mDirectArray; 
01074     }
01075 
01080     KFbxLayerElementArrayTemplate<int>& GetIndexArray() const
01081     { 
01082         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01083         return *mIndexArray; 
01084     }
01085 
01090     KFbxLayerElementArrayTemplate<int>& GetIndexArray()
01091     { 
01092         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01093         return *mIndexArray; 
01094     }
01095 
01100     bool Clear()
01101     {
01102         bool ret = true;
01103         mDirectArray->Clear();
01104         ret = (mDirectArray->GetStatus() == LockAccessStatus::eSuccess);
01105 
01106         mIndexArray->Clear();
01107         ret |= (mIndexArray->GetStatus() == LockAccessStatus::eSuccess);
01108 
01109         return ret;
01110     }
01111 
01112 public:
01113 
01118     bool operator==(const KFbxLayerElementTemplate& pOther) const
01119     {
01120         bool ret = true;
01121 
01122         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
01123             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
01124         {
01125             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
01126             if( directArray.GetCount() != mDirectArray->GetCount() || 
01127                 !directArray.ReadLock() || !mDirectArray->ReadLock() )
01128             {
01129                 ret = false;
01130             }
01131 
01132             if( ret && !mDirectArray->IsEqual(directArray) )
01133                 ret = false;
01134 
01135             directArray.ReadUnlock();
01136             mDirectArray->ReadUnlock();
01137         }
01138 
01139         if (ret)
01140         {
01141             if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01142                 pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
01143             {
01144                 const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
01145                 if( indexArray.GetCount() != mIndexArray->GetCount() ||
01146                     !indexArray.ReadLock() || !mIndexArray->ReadLock() )
01147                 {
01148                     ret = false;
01149                 }
01150 
01151                 if( ret && !mIndexArray->IsEqual(indexArray) )
01152                     ret = false;
01153 
01154                 indexArray.ReadUnlock();
01155                 mIndexArray->ReadUnlock();
01156             }
01157         }
01158 
01159         if (ret == false)
01160             return false;
01161 
01162         return KFbxLayerElement::operator==(pOther);
01163     }
01164 
01168     KFbxLayerElementTemplate& operator=( KFbxLayerElementTemplate const& pOther )
01169     {
01170         K_ASSERT(mDirectArray != NULL);
01171         K_ASSERT(mIndexArray != NULL);
01172 
01173         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
01174             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
01175         {
01176             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
01177             *mDirectArray = directArray;
01178         }
01179 
01180         if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01181             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
01182         {
01183             const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
01184             *mIndexArray = indexArray;
01185         }
01186         
01187         KFbxLayerElement* myself = (KFbxLayerElement*)this;
01188         KFbxLayerElement* myOther = (KFbxLayerElement*)&pOther;
01189         *myself = *myOther;
01190         return *this; 
01191     }
01192 
01200     int RemapIndexTo(KFbxLayerElement::EMappingMode pNewMapping)
01201     {
01202         return RemapIndexArrayTo(this, pNewMapping, mIndexArray);
01203     }
01204 
01206 //
01207 //  WARNING!
01208 //
01209 //  Anything beyond these lines may not be documented accurately and is 
01210 //  subject to change without notice.
01211 //
01213 
01214 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01215 protected:
01216     KFbxLayerElementTemplate() 
01217     {
01218         mDirectArray = NULL;
01219         mIndexArray = NULL;
01220     }
01221 
01222     ~KFbxLayerElementTemplate() 
01223     {
01224         FbxSdkDelete(mDirectArray);
01225         FbxSdkDelete(mIndexArray);
01226     }
01227 
01228     virtual void AllocateArrays()
01229     {
01230         mDirectArray = FbxSdkNew< KFbxLayerElementArrayTemplate<Type> >(mType->GetType());
01231         mIndexArray = FbxSdkNew< KFbxLayerElementArrayTemplate<int> >(DTInteger.GetType());
01232     }
01233 
01234 public:
01235     virtual int MemorySize() const
01236     {
01237         int size = KFbxLayerElement::MemorySize();
01238         size += (mDirectArray->GetCount()*sizeof(Type));
01239         size += (mIndexArray->GetCount()*sizeof(int));
01240         return size;
01241     }
01242 
01247     virtual bool ContentWriteTo(KFbxStream& pStream) const
01248     {
01249         void* a;
01250         int s,v;
01251         int count = 0;
01252 
01253         // direct array
01254         count = mDirectArray->GetCount();
01255         s = pStream.Write(&count, sizeof(int)); 
01256         if (s != sizeof(int)) return false;
01257         if (count > 0)
01258         {
01259             a = mDirectArray->GetLocked();
01260             K_ASSERT(a != NULL);
01261             v = count*sizeof(Type);
01262             s = pStream.Write(a, v); 
01263             mDirectArray->Release(&a);
01264             if (s != v) return false;
01265         }
01266 
01267         // index array
01268         count = mIndexArray->GetCount();
01269         s = pStream.Write(&count, sizeof(int)); 
01270         if (s != sizeof(int)) return false;
01271         if (count > 0)
01272         {
01273             a = mIndexArray->GetLocked();
01274             K_ASSERT(a != NULL);
01275             v = count*sizeof(int);
01276             s = pStream.Write(a, v);
01277             mIndexArray->Release(&a);
01278             if (s != v) return false;
01279         }
01280 
01281         return KFbxLayerElement::ContentWriteTo(pStream);
01282     }
01283 
01284     virtual bool ContentReadFrom(const KFbxStream& pStream)
01285     {
01286         void* a;
01287         int s,v;
01288         int count = 0;
01289 
01290         // direct array
01291         s = pStream.Read(&count, sizeof(int)); 
01292         if (s != sizeof(int)) return false;
01293         mDirectArray->Resize(count);
01294         if (count > 0)
01295         {
01296             a = mDirectArray->GetLocked();
01297             K_ASSERT(a != NULL);
01298             v = count*sizeof(Type);
01299             s = pStream.Read(a, v); 
01300             mDirectArray->Release(&a);
01301             if (s != v) return false;
01302         }
01303 
01304         // index array
01305         s = pStream.Read(&count, sizeof(int)); 
01306         if (s != sizeof(int)) return false;
01307         mIndexArray->Resize(count);     
01308         if (count > 0)
01309         {
01310             a = mIndexArray->GetLocked();
01311             K_ASSERT(a != NULL);
01312             v = count*sizeof(int);
01313             s = pStream.Read(a, v);
01314             mIndexArray->Release(&a);
01315             if (s != v) return false;
01316         }
01317         return KFbxLayerElement::ContentReadFrom(pStream);
01318     }
01320 
01321     typedef Type ArrayElementType;
01322     typedef KFbxLayerElementArrayTemplate<Type> DirectArrayType;
01323     typedef KFbxLayerElementArrayTemplate<int> IndexArrayType;
01324 
01325     KFbxLayerElementArrayTemplate<Type>* mDirectArray;
01326     KFbxLayerElementArrayTemplate<int>*  mIndexArray;
01327 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01328 };
01329 
01330 #define CREATE_DECLARE(classDesc) \
01331     KFBXNEW_DECLARE_FRIEND        \
01332     static KFbx##classDesc* Create(KFbxLayerContainer* pOwner, char const *pName);
01333 
01337 class KFBX_DLL KFbxLayerElementNormal : public KFbxLayerElementTemplate<KFbxVector4>
01338 {
01339 public:
01340 
01344     CREATE_DECLARE(LayerElementNormal);
01345     
01346 protected:
01347     KFbxLayerElementNormal();
01348     ~KFbxLayerElementNormal();
01349 };
01350 
01354 class KFBX_DLL KFbxLayerElementBinormal : public KFbxLayerElementTemplate<KFbxVector4>
01355 {
01356 public:
01357 
01361     CREATE_DECLARE(LayerElementBinormal);
01362     
01363 protected:
01364     KFbxLayerElementBinormal();
01365     ~KFbxLayerElementBinormal();
01366 };
01367 
01371 class KFBX_DLL KFbxLayerElementTangent : public KFbxLayerElementTemplate<KFbxVector4>
01372 {
01373 public:
01374 
01378     CREATE_DECLARE(LayerElementTangent);
01379     
01380 protected:
01381     KFbxLayerElementTangent();
01382     ~KFbxLayerElementTangent();
01383 };
01384 
01425 class KFBX_DLL KFbxLayerElementMaterial : public KFbxLayerElementTemplate<KFbxSurfaceMaterial*>
01426 {
01427 public:
01428     typedef KFbxLayerElementTemplate<KFbxSurfaceMaterial*> ParentClass;
01429 
01433     CREATE_DECLARE(LayerElementMaterial);
01434     
01440     class LayerElementArrayProxy : public KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>
01441     {
01442     public:
01443         typedef KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*> ParentClass;
01444 
01445         LayerElementArrayProxy(EFbxType pType);
01446         void SetContainer( KFbxLayerContainer* pContainer, int pInstance = 0);
01447     };
01448 
01450 //
01451 //  WARNING!
01452 //
01453 //  Anything beyond these lines may not be documented accurately and is 
01454 //  subject to change without notice.
01455 //
01457 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01458 
01459     virtual void AllocateArrays();
01460     virtual void SetOwner( KFbxLayerContainer* pOwner, int pInstance = 0);
01461     virtual void SetInstance( int pInstance ) { SetOwner( mOwner, pInstance ); }
01462 
01463 protected:
01464     KFbxLayerElementMaterial();
01465     ~KFbxLayerElementMaterial();
01466 
01467 private:
01468     KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray() const
01469     { 
01470         return ParentClass::GetDirectArray();
01471     }
01472 
01473     KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray()
01474     { 
01475         return ParentClass::GetDirectArray();
01476     }
01477     
01478     friend class KFbxLayerContainer;
01479 
01480 #endif //DOXYGEN_SHOULD_SKIP_THIS
01481 }; 
01482 
01486 class KFBX_DLL KFbxLayerElementPolygonGroup : public KFbxLayerElementTemplate<int>
01487 {
01488 public:
01489 
01493     CREATE_DECLARE(LayerElementPolygonGroup);
01494     
01495 protected:
01496     KFbxLayerElementPolygonGroup();
01497     ~KFbxLayerElementPolygonGroup();
01498 };
01499 
01509 class KFBX_DLL KFbxLayerElementUV : public KFbxLayerElementTemplate<KFbxVector2>
01510 {
01511 public:
01515     CREATE_DECLARE(LayerElementUV);
01516     
01517 protected:
01518     KFbxLayerElementUV();
01519     ~KFbxLayerElementUV();
01520 };
01521 
01525 class KFBX_DLL KFbxLayerElementVertexColor : public KFbxLayerElementTemplate<KFbxColor>
01526 {
01527 public:
01528 
01532     CREATE_DECLARE(LayerElementVertexColor);
01533     
01534 protected:
01535     KFbxLayerElementVertexColor();
01536     ~KFbxLayerElementVertexColor();
01537 };
01538 
01541 const int kNoMapping = -1;
01542 
01543 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, int pIndex, bool* pStatus = NULL);
01544 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus = NULL);
01545 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, const char* pName, bool* pStatus = NULL );
01546 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus = NULL );
01547 
01553 class KFBX_DLL KFbxLayerElementUserData : public KFbxLayerElementTemplate<void*>
01554 {
01555 public:
01556     KFBXNEW_DECLARE_FRIEND
01557 
01567     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, char const *pName, int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames);
01568 
01574     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, KFbxLayerElementUserData const& pOther );
01575 
01581     KFbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL)
01582     {       
01583         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01584         {
01585             if (pStatus) *pStatus = true;
01586             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01587         }
01588         else
01589         {
01590             if( pStatus ) *pStatus = false;
01591             K_ASSERT_MSG_NOW("Index out of bounds");
01592             return (KFbxLayerElementArrayTemplate<void*>*)NULL;
01593         }
01594     }
01595 
01601     KFbxLayerElementArrayTemplate<void*> const* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL) const
01602     {
01603         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01604         {
01605             if (pStatus) *pStatus = true;
01606             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01607         }
01608         else
01609         {
01610             if( pStatus ) *pStatus = false;
01611             K_ASSERT_MSG_NOW("Index out of bounds");
01612             return (KFbxLayerElementArrayTemplate<void*> const*)NULL;
01613         }
01614     }
01615 
01616 
01622     KFbxLayerElementArrayTemplate<void *>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL )
01623     {
01624         KString lName( pName );
01625         for( int i = 0; i < mDataNames.GetCount(); ++i )
01626         {
01627             if( *mDataNames[i] == lName )
01628                 return GetDirectArrayVoid(i, pStatus);
01629         }
01630 
01631         if (pStatus) *pStatus = false;
01632         return (KFbxLayerElementArrayTemplate<void *>*)NULL;
01633     }
01634  
01640     KFbxLayerElementArrayTemplate<void *> const* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL ) const
01641     {
01642         KString lName( pName );
01643         for( int i = 0; i < mDataNames.GetCount(); ++i )
01644         {
01645             if( *mDataNames[i] == lName )
01646                 return GetDirectArrayVoid(i, pStatus);
01647         }
01648 
01649         if (pStatus) *pStatus = false;
01650         return (KFbxLayerElementArrayTemplate<void *> const*)NULL;
01651     }
01652 
01657     KFbxDataType GetDataType( int pIndex ) const
01658     {
01659         if( pIndex < 0 || pIndex >= mDataTypes.GetCount() )
01660             return DTNone;
01661 
01662         return mDataTypes[pIndex];
01663     }
01664 
01669     KFbxDataType GetDataType( const char* pName ) const
01670     {
01671         KString lName( pName );
01672 
01673         for( int i = 0; i < mDataNames.GetCount(); ++i )
01674         {
01675             if( *mDataNames[i] == lName )
01676                 return mDataTypes[i];
01677         }
01678 
01679         return DTNone;
01680     }
01681 
01686     const char* GetDataName( int pIndex ) const
01687     {
01688         if( pIndex >= 0 && pIndex < mDataNames.GetCount() )
01689             return mDataNames[pIndex]->Buffer();
01690 
01691         return NULL;
01692     }
01693 
01697     void ResizeAllDirectArrays( int pSize )
01698     {
01699         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01700         {
01701             switch( mDataTypes[i].GetType() )
01702             {
01703                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).Resize( pSize )  ; break;
01704                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).Resize( pSize )   ; break;
01705                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).Resize( pSize ) ; break;
01706                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).Resize( pSize ); break;
01707                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).Resize( pSize );    break;
01708                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).Resize( pSize );    break;
01709                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).Resize( pSize );    break;  
01710                 default:
01711                     K_ASSERT_MSG_NOW("unknown type" ); break;
01712             }
01713         }
01714     }
01715 
01719     void RemoveFromAllDirectArrays( int pIndex )
01720     {
01721         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01722         {
01723             switch( mDataTypes[i].GetType() )
01724             {
01725                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).RemoveAt( pIndex )  ; break;
01726                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).RemoveAt( pIndex )   ; break;
01727                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).RemoveAt( pIndex ) ; break;
01728                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).RemoveAt( pIndex ); break;
01729                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).RemoveAt( pIndex ); break;
01730                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).RemoveAt( pIndex ); break;
01731                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).RemoveAt( pIndex ); break;  
01732                 default:
01733                     K_ASSERT_MSG_NOW("unknown type" ); break;
01734             }
01735         }
01736     }
01737 
01742     int GetArrayCount( int pIndex ) const 
01743     {
01744         if( pIndex >= 0 && pIndex < GetDirectArray().GetCount() )
01745         {
01746             switch( mDataTypes[pIndex].GetType() )
01747             {
01748                 case eBOOL1:    return KFbxGetDirectArray<bool>(this,pIndex).GetCount();
01749                 case eINTEGER1: return KFbxGetDirectArray<int>(this,pIndex).GetCount();
01750                 case eFLOAT1:   return KFbxGetDirectArray<float>(this,pIndex).GetCount();
01751                 case eDOUBLE1:  return KFbxGetDirectArray<double>(this,pIndex).GetCount();
01752                 //case eDOUBLE3:    return GetDirectArray< fbxDouble3 >(pIndex).GetCount();
01753                 //case eDOUBLE4:    return GetDirectArray< fbxDouble4 >(pIndex).GetCount();
01754                 //case eDOUBLE44:   return GetDirectArray< fbxDouble44>(pIndex).GetCount();
01755                 default:
01756                     K_ASSERT_MSG_NOW("Unknown type" ); break;
01757             }
01758         }
01759 
01760         return -1;
01761     }
01762 
01766     int GetId() const { return mId; }
01767 
01772     int GetDirectArrayCount() const { return GetDirectArray().GetCount(); }
01773 
01778     KFbxLayerElementUserData& operator=( KFbxLayerElementUserData const& pOther )
01779     {
01780         if (this == &pOther)
01781             return *this;
01782 
01783         Clear();
01784 
01785         mId = pOther.mId;
01786         mDataTypes = pOther.mDataTypes;
01787         mDataNames.Resize(pOther.mDataNames.GetCount());
01788         for(int i = 0; i < pOther.mDataNames.GetCount(); ++i)
01789             mDataNames.SetAt(i,  FbxSdkNew< KString >( *pOther.mDataNames[i] ) );
01790 
01791         Init();
01792         for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
01793         {
01794             switch (mDataTypes[i].GetType())
01795             {
01796             case eBOOL1:
01797                 KFbxGetDirectArray<bool>(this, i) = KFbxGetDirectArray<bool>(&pOther, i);
01798                 break;
01799 
01800             case eINTEGER1:
01801                 KFbxGetDirectArray<int>(this, i) = KFbxGetDirectArray<int>(&pOther, i);
01802                 break;
01803 
01804             case eFLOAT1:
01805                 KFbxGetDirectArray<float>(this, i) = KFbxGetDirectArray<float>(&pOther, i);
01806                 break;
01807 
01808             case eDOUBLE1:
01809                 KFbxGetDirectArray<double>(this, i) = KFbxGetDirectArray<double>(&pOther, i);
01810                 break;
01811 
01812             default:
01813                 K_ASSERT_MSG_NOW("Unknown type" );
01814                 break;
01815             }
01816         }
01817 
01818         if ( ( mReferenceMode == KFbxLayerElement::eINDEX || 
01819                mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT) &&
01820              ( pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01821                pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT))
01822         {
01823             GetIndexArray() = pOther.GetIndexArray();
01824         }
01825 
01826         return *this;
01827     }
01828 
01832     bool Clear()
01833     {
01834         int i;
01835         const int lCount = GetDirectArray().GetCount();
01836         KFbxLayerElementArray** directArray = NULL;
01837         directArray = GetDirectArray().GetLocked(directArray);
01838         for( i = 0; directArray != NULL && i < lCount; ++i )
01839         {
01840             if( directArray[i] )
01841                 FbxSdkDelete(directArray[i]);
01842         }
01843         GetDirectArray().Release((void**)&directArray);
01844 
01845         for( i = 0; i < mDataNames.GetCount(); ++i )
01846         {
01847             KFBX_SAFE_DELETE_PTR(mDataNames[i]);
01848         }
01849         mDataNames.Clear();
01850         mDataTypes.Clear();
01851 
01852         KFbxLayerElementTemplate<void*>::Clear();
01853 
01854         return true;
01855     }
01856 
01861     virtual int MemorySize() const
01862     {
01863         int size = KFbxLayerElementTemplate<void*>::MemorySize();
01864         size += sizeof(mId);
01865 
01866         for(int i = 0; i < mDataTypes.GetCount(); i++)
01867         {
01868             size += sizeof(mDataTypes[i]);
01869         }
01870         size += (mDataNames.GetCount() * sizeof(KString*));
01871 
01872         return size;
01873     }
01874 
01876 //
01877 //  WARNING!
01878 //
01879 //  Anything beyond these lines may not be documented accurately and is 
01880 //  subject to change without notice.
01881 //
01883 
01884 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01885 protected:
01895     KFbxLayerElementUserData( int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames )
01896         :
01897         mId( pId ),
01898         mDataTypes( pDataTypes )
01899     {
01900         K_ASSERT( pDataTypes.GetCount() == pDataNames.GetCount() );
01901         for( int i = 0; i < pDataNames.GetCount(); ++i )
01902         {
01903             mDataNames.Add( FbxSdkNew< KString >( pDataNames[i] ) );
01904         }
01905     }
01906 
01910     KFbxLayerElementUserData( KFbxLayerElementUserData const& pOther ) : mId(pOther.mId), mDataTypes(pOther.mDataTypes)
01911     {
01912         for (int lIndex = 0; lIndex < pOther.mDataNames.GetCount(); ++lIndex)
01913         {
01914             mDataNames.Add(FbxSdkNew<KString>(*(pOther.mDataNames[lIndex])));
01915         }
01916 
01917         SetType(&DTLayerElementUserData);
01918         AllocateArrays();
01919 
01920         for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
01921         {
01922             switch (mDataTypes[i].GetType())
01923             {
01924             case eBOOL1:
01925                 KFbxGetDirectArray<bool>(this, i) = KFbxGetDirectArray<bool>(&pOther, i);
01926                 break;
01927 
01928             case eINTEGER1:
01929                 KFbxGetDirectArray<int>(this, i) = KFbxGetDirectArray<int>(&pOther, i);
01930                 break;
01931 
01932             case eFLOAT1:
01933                 KFbxGetDirectArray<float>(this, i) = KFbxGetDirectArray<float>(&pOther, i);
01934                 break;
01935 
01936             case eDOUBLE1:
01937                 KFbxGetDirectArray<double>(this, i) = KFbxGetDirectArray<double>(&pOther, i);
01938                 break;
01939 
01940             default:
01941                 K_ASSERT_MSG_NOW("Unknown type" );
01942                 break;
01943             }
01944         }
01945 
01946         if ( ( mReferenceMode == KFbxLayerElement::eINDEX || 
01947             mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT) &&
01948             ( pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01949             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT))
01950         {
01951             GetIndexArray() = pOther.GetIndexArray();
01952         }
01953     }
01954 
01956     ~KFbxLayerElementUserData()
01957     {
01958         Clear();
01959     }
01960 
01962     virtual void AllocateArrays()
01963     {
01964         KFbxLayerElementTemplate<void*>::AllocateArrays();
01965         Init();
01966     }
01967 
01968 
01969 private:
01970 
01971     void Init()
01972     {
01973         int i;
01974         GetDirectArray().Resize( mDataTypes.GetCount() );
01975 
01976         // initialize arrays
01977         for( i = 0; i < mDataTypes.GetCount(); ++i )
01978         {
01979             kReference** dst = NULL;
01980             dst = GetDirectArray().GetLocked(dst);
01981             if (dst)
01982             {
01983                 switch( mDataTypes[i].GetType() )
01984                 {
01985                     case eBOOL1:    dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<bool> >(mDataTypes[i].GetType());    break;
01986                     case eINTEGER1: dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<int> >(mDataTypes[i].GetType()); break;
01987                     case eFLOAT1:   dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<float> >(mDataTypes[i].GetType());   break;
01988                     case eDOUBLE1:  dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<double> >(mDataTypes[i].GetType());  break;
01989                     //case eDOUBLE3:    mDirectArray[i] = new KArrayTemplate< fbxDouble3 >();   break;  
01990                     //case eDOUBLE4:    mDirectArray[i] = new KArrayTemplate< fbxDouble4 >();   break;
01991                     //case eDOUBLE44:   mDirectArray[i] = new KArrayTemplate< fbxDouble44 >();  break;  
01992                     default:
01993                         K_ASSERT_MSG_NOW("Trying to assign an unknown type" ); break;
01994                 }
01995                 GetDirectArray().Release((void**)&dst);
01996             }
01997         }
01998     }
01999 
02000     int mId;
02001     KArrayTemplate<KFbxDataType> mDataTypes;
02002     KArrayTemplate<KString*> mDataNames;
02003   #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02004 };
02005 
02013 template <class T>
02014 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,int pIndex, bool* pStatus)
02015 {
02016     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
02017 }
02018 
02026 template <class T>
02027 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus)
02028 {
02029     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
02030 }
02031 
02032 
02040 template <class T>
02041 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,const char* pName, bool* pStatus )
02042 {
02043     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
02044 }
02045 
02053 template <class T>
02054 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus )
02055 {
02056     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
02057 }
02058 
02059 
02063 class KFBX_DLL KFbxLayerElementSmoothing : public KFbxLayerElementTemplate<int>
02064 {
02065 public:
02066     KFBXNEW_DECLARE_FRIEND
02067 
02073     static KFbxLayerElementSmoothing* Create(KFbxLayerContainer* pOwner, char const *pName);
02074 
02079     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02080     {
02081         if( pMode != KFbxLayerElement::eDIRECT )
02082         {
02083             K_ASSERT_MSG_NOW( "Smoothing layer elements must be direct mapped" );
02084             return;
02085         }
02086     }
02087 
02089 //
02090 //  WARNING!
02091 //
02092 //  Anything beyond these lines may not be documented accurately and is 
02093 //  subject to change without notice.
02094 //
02096 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02097 
02098 protected:
02099     KFbxLayerElementSmoothing()
02100     {
02101         mReferenceMode = KFbxLayerElement::eDIRECT;
02102     }
02103 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02104 };
02105 
02109 class KFBX_DLL KFbxLayerElementCrease : public KFbxLayerElementTemplate<double>
02110 {
02111 public:
02112     KFBXNEW_DECLARE_FRIEND
02113 
02119     static KFbxLayerElementCrease* Create(KFbxLayerContainer* pOwner, char const *pName);
02120 
02125     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02126     {
02127         if( pMode != KFbxLayerElement::eDIRECT )
02128         {
02129             K_ASSERT_MSG_NOW( "Crease layer elements must be direct mapped" );
02130             return;
02131         }
02132     }
02133 
02135 //
02136 //  WARNING!
02137 //
02138 //  Anything beyond these lines may not be documented accurately and is 
02139 //  subject to change without notice.
02140 //
02142 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02143 
02144 protected:
02145     KFbxLayerElementCrease()
02146     {
02147         mReferenceMode = KFbxLayerElement::eDIRECT;
02148     }
02149 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02150 
02151 };
02152 
02156 class KFBX_DLL KFbxLayerElementHole : public KFbxLayerElementTemplate<bool>
02157 {
02158 public:
02159     KFBXNEW_DECLARE_FRIEND
02160 
02166         static KFbxLayerElementHole* Create(KFbxLayerContainer* pOwner, char const *pName);
02167 
02172     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02173     {
02174         if( pMode != KFbxLayerElement::eDIRECT )
02175         {
02176             K_ASSERT_MSG_NOW( "hole layer elements must be direct mapped" );
02177             return;
02178         }
02179     }
02180 
02182     //
02183     //  WARNING!
02184     //
02185     //  Anything beyond these lines may not be documented accurately and is 
02186     //  subject to change without notice.
02187     //
02189 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02190 
02191 protected:
02192     KFbxLayerElementHole()
02193     {
02194         mReferenceMode = KFbxLayerElement::eDIRECT;
02195     }
02196 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02197 
02198 };
02199 
02202 class KFBX_DLL KFbxLayerElementVisibility : public KFbxLayerElementTemplate<bool>
02203 {
02204 public:
02205 
02209     CREATE_DECLARE(LayerElementVisibility);
02210 
02212 //
02213 //  WARNING!
02214 //
02215 //  Anything beyond these lines may not be documented accurately and is 
02216 //  subject to change without notice.
02217 //
02219 
02220 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02221 protected:
02222     KFbxLayerElementVisibility();
02223     ~KFbxLayerElementVisibility();
02224 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02225 };
02226 
02230 typedef class KFBX_DLL KFbxLayerElementTemplate<KFbxTexture*>  KFbxLayerElementTextureBase;
02231 
02247 class KFBX_DLL KFbxLayerElementTexture : public KFbxLayerElementTextureBase
02248 {
02249 
02250 public:
02251 
02255     CREATE_DECLARE(LayerElementTexture);
02256 
02290     typedef enum 
02291     {
02292         eTRANSLUCENT,
02293         eADD,
02294         eMODULATE,
02295         eMODULATE2,
02296         eOVER,
02297         eNORMAL,        
02298         eDISSOLVE,
02299         eDARKEN,            
02300         eCOLORBURN,
02301         eLINEARBURN,    
02302         eDARKERCOLOR,
02303         eLIGHTEN,           
02304         eSCREEN,        
02305         eCOLORDODGE,
02306         eLINEARDODGE,
02307         eLIGHTERCOLOR,
02308         eSOFTLIGHT,     
02309         eHARDLIGHT,     
02310         eVIVIDLIGHT,
02311         eLINEARLIGHT,
02312         ePINLIGHT,      
02313         eHARDMIX,       
02314         eDIFFERENCE,        
02315         eEXCLUSION,         
02316         eSUBTRACT,
02317         eDIVIDE,
02318         eHUE,           
02319         eSATURATION,        
02320         eCOLOR,     
02321         eLUMINOSITY,
02322         eMAXBLEND
02323     } EBlendMode;
02324 
02328     void       SetBlendMode(EBlendMode pBlendMode) { mBlendMode = pBlendMode; }
02329 
02334     void       SetAlpha(double pAlpha)
02335     {
02336         if (pAlpha > 1.0)
02337             mAlpha = 1.0;
02338         else if (pAlpha < 0.0)
02339             mAlpha = 0.0;
02340         else
02341             mAlpha = pAlpha;
02342     }
02343 
02347     EBlendMode GetBlendMode() const                      { return mBlendMode; } 
02348 
02352     double     GetAlpha() const                          { return mAlpha; }
02353 
02355 //
02356 //  WARNING!
02357 //
02358 //  Anything beyond these lines may not be documented accurately and is 
02359 //  subject to change without notice.
02360 //
02362 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02363 
02364     virtual int MemorySize() const
02365     {
02366         int size = KFbxLayerElementTextureBase::MemorySize();
02367         size += sizeof(mBlendMode);
02368         size += sizeof(mAlpha);
02369         return size;
02370     }
02371 
02372 protected:
02377     KFbxLayerElementTexture() : mBlendMode(eTRANSLUCENT)
02378     {
02379         mReferenceMode = eINDEX_TO_DIRECT;
02380         mAlpha         = 1.0;
02381     }
02382 
02383 private:
02384     EBlendMode mBlendMode;
02385     double     mAlpha;
02386 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02387 };
02388 
02389 
02443 class KFBX_DLL KFbxLayer
02444 {
02445 
02446 public:
02447     KFBXNEW_DECLARE_FRIEND
02448 
02453 
02458     KFbxLayerElementNormal* GetNormals();   
02459 
02464     KFbxLayerElementNormal const* GetNormals() const;
02465 
02470     KFbxLayerElementTangent* GetTangents(); 
02471 
02476     KFbxLayerElementTangent const* GetTangents() const;
02477 
02482     KFbxLayerElementBinormal* GetBinormals();   
02483 
02488     KFbxLayerElementBinormal const* GetBinormals() const;
02489 
02493     KFbxLayerElementMaterial* GetMaterials();
02494 
02498     KFbxLayerElementMaterial const* GetMaterials() const;
02499 
02503     KFbxLayerElementPolygonGroup* GetPolygonGroups();
02504 
02508     KFbxLayerElementPolygonGroup const* GetPolygonGroups() const;
02509 
02516     KFbxLayerElementUV* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02517 
02524     KFbxLayerElementUV const* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
02525 
02526 
02529     int GetUVSetCount() const;
02530     
02533     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetUVSetChannels() const;
02534 
02537     KArrayTemplate<KFbxLayerElementUV const*> GetUVSets() const;
02538 
02543     KFbxLayerElementVertexColor* GetVertexColors();
02544 
02549     KFbxLayerElementVertexColor const* GetVertexColors() const;
02550 
02555     KFbxLayerElementSmoothing* GetSmoothing();
02556 
02561     KFbxLayerElementSmoothing const* GetSmoothing() const;
02562 
02567     KFbxLayerElementCrease* GetVertexCrease();
02568 
02573     KFbxLayerElementCrease const* GetVertexCrease() const;
02574 
02579     KFbxLayerElementCrease* GetEdgeCrease();
02580 
02585     KFbxLayerElementCrease const* GetEdgeCrease() const;
02586 
02591     KFbxLayerElementHole* GetHole();
02592 
02597     KFbxLayerElementHole const* GetHole() const;
02598 
02602     KFbxLayerElementUserData* GetUserData();
02603 
02607     KFbxLayerElementUserData const* GetUserData() const;
02608 
02612     KFbxLayerElementVisibility* GetVisibility();
02613 
02617     KFbxLayerElementVisibility const* GetVisibility() const;
02618 
02623     KFbxLayerElementTexture* GetTextures(KFbxLayerElement::ELayerElementType pType);
02624 
02629     KFbxLayerElementTexture const* GetTextures(KFbxLayerElement::ELayerElementType pType) const;
02630 
02635     void SetTextures(KFbxLayerElement::ELayerElementType pType, KFbxLayerElementTexture* pTextures);
02636 
02655     KFbxLayerElement* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02656 
02675     KFbxLayerElement const* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false) const;
02676 
02681     void SetNormals(KFbxLayerElementNormal* pNormals);
02682 
02687     void SetBinormals(KFbxLayerElementBinormal* pBinormals);
02688 
02693     void SetTangents(KFbxLayerElementTangent* pTangents);
02694 
02698     void SetMaterials(KFbxLayerElementMaterial* pMaterials);
02699 
02703     void SetPolygonGroups(KFbxLayerElementPolygonGroup* pPolygonGroups);
02704 
02711     void SetUVs(KFbxLayerElementUV* pUVs, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02712 
02717     void SetVertexColors (KFbxLayerElementVertexColor* pVertexColors);
02718 
02723     void SetSmoothing (KFbxLayerElementSmoothing* pSmoothing);
02724 
02729     void SetVertexCrease (KFbxLayerElementCrease* pCrease);
02730 
02735     void SetEdgeCrease (KFbxLayerElementCrease* pCrease);
02736 
02741     void SetHole (KFbxLayerElementHole* pHole);
02742 
02746     void SetUserData (KFbxLayerElementUserData* pUserData);
02747 
02751     void SetVisibility( KFbxLayerElementVisibility* pVisibility );
02752 
02771     void SetLayerElementOfType(KFbxLayerElement* pLayerElement, KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02772 
02779     KFbxLayerElement* CreateLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02780 
02785     void Clone(KFbxLayer const& pSrcLayer, KFbxSdkManager* pSdkManager);    
02786     
02787     
02789 //
02790 //  WARNING!
02791 //
02792 //  Anything beyond these lines may not be documented accurately and is 
02793 //  subject to change without notice.
02794 //
02796 
02797 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02798 protected:
02800     KFbxLayer& operator=(KFbxLayer const& pSrcLayer);
02802 private:
02803 
02804     KFbxLayer(KFbxLayerContainer& pOwner);
02805     virtual ~KFbxLayer();
02806 
02807     void Clear();
02808 
02809     KFbxLayerContainer& mOwner;
02810 
02811     KFbxLayerElement*             mNonTexturesArray[KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_COUNT];
02812     KFbxLayerElementUV*           mUVsArray[KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT];
02813     KFbxLayerElementTexture*      mTexturesArray[KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT];
02814 
02815 
02816     friend class KFbxLayerContainer;
02817 
02818 public:
02823         bool ContentWriteTo(KFbxStream& pStream) const;
02824         bool ContentReadFrom(const KFbxStream& pStream);
02826     virtual int MemoryUsage() const;
02827 
02828 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02829 };
02830 
02834 #define FOR_EACH_TEXTURE(lLayerIndex) for((lLayerIndex) = 0; (lLayerIndex) < KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT; (lLayerIndex)++)
02835 
02839 #define FOR_EACH_NON_TEXTURE(lLayerIndex) for((lLayerIndex) = 0; (lLayerIndex) < KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_COUNT; (lLayerIndex)++)
02840 
02844 #define TEXTURE_INDEX(ElementType) (int(ElementType) - KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_START_INDEX)
02845 
02849 #define TEXTURE_TYPE(TextureIndex) (KFbxLayerElement::ELayerElementType((TextureIndex) + KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_START_INDEX))
02850 
02854 #define NON_TEXTURE_INDEX(ElementType) (int(ElementType) - KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX)
02855 
02859 #define NON_TEXTURE_TYPE(Index) (KFbxLayerElement::ELayerElementType((Index) + KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX))
02860 
02861 
02874 typedef KFbxLayerElement KFbxGeometryElement;
02875 typedef KFbxLayerElementNormal KFbxGeometryElementNormal;
02876 typedef KFbxLayerElementBinormal KFbxGeometryElementBinormal;
02877 typedef KFbxLayerElementTangent KFbxGeometryElementTangent;
02878 typedef KFbxLayerElementMaterial KFbxGeometryElementMaterial;
02879 typedef KFbxLayerElementPolygonGroup KFbxGeometryElementPolygonGroup;
02880 typedef KFbxLayerElementUV KFbxGeometryElementUV;
02881 typedef KFbxLayerElementVertexColor KFbxGeometryElementVertexColor;
02882 typedef KFbxLayerElementUserData KFbxGeometryElementUserData;
02883 typedef KFbxLayerElementSmoothing KFbxGeometryElementSmoothing;
02884 typedef KFbxLayerElementCrease KFbxGeometryElementCrease;
02885 typedef KFbxLayerElementHole KFbxGeometryElementHole;
02886 typedef KFbxLayerElementVisibility KFbxGeometryElementVisibility;
02887 
02888 
02889 #undef CREATE_DECLARE
02890 #include <fbxfilesdk/fbxfilesdk_nsend.h>
02891 
02892 #endif // FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
02893