kfbxlayer.h

Go to the documentation of this file.
00001 
00004 #ifndef FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
00005 #define FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
00006 
00007 /**************************************************************************************
00008 
00009  Copyright (C) 2001 - 2010 Autodesk, Inc. and/or its licensors.
00010  All Rights Reserved.
00011 
00012  The coded instructions, statements, computer programs, and/or related material 
00013  (collectively the "Data") in these files contain unpublished information 
00014  proprietary to Autodesk, Inc. and/or its licensors, which is protected by 
00015  Canada and United States of America federal copyright law and by international 
00016  treaties. 
00017  
00018  The Data may not be disclosed or distributed to third parties, in whole or in
00019  part, without the prior written consent of Autodesk, Inc. ("Autodesk").
00020 
00021  THE DATA IS PROVIDED "AS IS" AND WITHOUT WARRANTY.
00022  ALL WARRANTIES ARE EXPRESSLY EXCLUDED AND DISCLAIMED. AUTODESK MAKES NO
00023  WARRANTY OF ANY KIND WITH RESPECT TO THE DATA, EXPRESS, IMPLIED OR ARISING
00024  BY CUSTOM OR TRADE USAGE, AND DISCLAIMS ANY IMPLIED WARRANTIES OF TITLE, 
00025  NON-INFRINGEMENT, MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE OR USE. 
00026  WITHOUT LIMITING THE FOREGOING, AUTODESK DOES NOT WARRANT THAT THE OPERATION
00027  OF THE DATA WILL BE UNINTERRUPTED OR ERROR FREE. 
00028  
00029  IN NO EVENT SHALL AUTODESK, ITS AFFILIATES, PARENT COMPANIES, LICENSORS
00030  OR SUPPLIERS ("AUTODESK GROUP") BE LIABLE FOR ANY LOSSES, DAMAGES OR EXPENSES
00031  OF ANY KIND (INCLUDING WITHOUT LIMITATION PUNITIVE OR MULTIPLE DAMAGES OR OTHER
00032  SPECIAL, DIRECT, INDIRECT, EXEMPLARY, INCIDENTAL, LOSS OF PROFITS, REVENUE
00033  OR DATA, COST OF COVER OR CONSEQUENTIAL LOSSES OR DAMAGES OF ANY KIND),
00034  HOWEVER CAUSED, AND REGARDLESS OF THE THEORY OF LIABILITY, WHETHER DERIVED
00035  FROM CONTRACT, TORT (INCLUDING, BUT NOT LIMITED TO, NEGLIGENCE), OR OTHERWISE,
00036  ARISING OUT OF OR RELATING TO THE DATA OR ITS USE OR ANY OTHER PERFORMANCE,
00037  WHETHER OR NOT AUTODESK HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH LOSS
00038  OR DAMAGE. 
00039 
00040 **************************************************************************************/
00041 #include <fbxfilesdk/fbxfilesdk_def.h>
00042 
00043 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00044 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00045 #include <fbxfilesdk/components/kbaselib/klib/kdebug.h>
00046 
00047 #include <fbxfilesdk/kfbxmath/kfbxvector2.h>
00048 #include <fbxfilesdk/kfbxmath/kfbxvector4.h>
00049 #include <fbxfilesdk/kfbxplugins/kfbxcolor.h>
00050 #include <fbxfilesdk/kfbxplugins/kfbxdatatypes.h>
00051 #include <fbxfilesdk/kfbxplugins/kfbxstream.h>
00052 #include <fbxfilesdk/kfbxplugins/kfbxsurfacematerial.h>
00053 #include <fbxfilesdk/kfbxplugins/kfbxtexture.h>
00054 
00055 #include <fbxfilesdk/fbxfilesdk_nsbegin.h>
00056 
00057 class KFbxTexture;
00058 class KFbxSurfaceMaterial;
00059 class KFbxSdkManager;
00060 
00061 class KFbxGeometryBase;
00062 class KFbxLayer;
00063 class KFbxLayerContainer;
00064 class KFbxMesh;
00065 class KFbxNode;
00066 class KFbxReader3DS;
00067 class KFbxReaderObj;
00068 
00069 //class KFbxReaderCollada;
00070 
00071 
00078 class KFBX_DLL KFbxLayerElement
00079 {
00080 
00081 public:
00082 
00116     typedef enum 
00117     {
00118         eUNDEFINED,
00119 
00120         //NON-TEXTURE LAYER ELEMENT BEGIN
00121         eNORMAL,
00122         eBINORMAL,
00123         eTANGENT,
00124         eMATERIAL,
00125         ePOLYGON_GROUP,
00126         eUV,
00127         eVERTEX_COLOR,
00128         eSMOOTHING,
00129         eVERTEX_CREASE,
00130         eEDGE_CREASE,
00131         eHOLE,
00132         eUSER_DATA,
00133         eVISIBILITY,
00134         //NEW NON-TEXTURE LAYER ELEMENT ADD HERE...
00135 
00136         //NON-TEXTURE LAYER ELEMENT END
00137 
00138         //TEXTURE LAYER ELEMENT BEGIN
00139         eDIFFUSE_TEXTURES,
00140         eDIFFUSE_FACTOR_TEXTURES,
00141         eEMISSIVE_TEXTURES,
00142         eEMISSIVE_FACTOR_TEXTURES,
00143         eAMBIENT_TEXTURES,
00144         eAMBIENT_FACTOR_TEXTURES,
00145         eSPECULAR_TEXTURES,
00146         eSPECULAR_FACTOR_TEXTURES,
00147         eSHININESS_TEXTURES,
00148         eNORMALMAP_TEXTURES,
00149         eBUMP_TEXTURES,
00150         eTRANSPARENT_TEXTURES,
00151         eTRANSPARENCY_FACTOR_TEXTURES,
00152         eREFLECTION_TEXTURES,
00153         eREFLECTION_FACTOR_TEXTURES,
00154         eDISPLACEMENT_TEXTURES,
00155         //NEW TEXTURE LAYER ELEMENT ADD HERE...
00156 
00157 
00158         //TEXTURE LAYER ELEMENT END
00159 
00160         eLAST_ELEMENT_TYPE
00161     } ELayerElementType;
00162 
00163     //common used constant for looping through and access layer element
00164 
00166     const static int LAYERELEMENT_TYPE_TEXTURE_START_INDEX = int(eDIFFUSE_TEXTURES);
00167 
00169     const static int LAYERELEMENT_TYPE_TEXTURE_END_INDEX = int(eDISPLACEMENT_TEXTURES);
00170 
00172     const static int LAYERELEMENT_TYPE_TEXTURE_COUNT = int(eLAST_ELEMENT_TYPE - eDIFFUSE_TEXTURES);
00173 
00175     const static int LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX = int(eNORMAL);
00176 
00178     const static int LAYERELEMENT_TYPE_NON_TEXTURE_END_INDEX = int(eVISIBILITY);
00179 
00181     const static int LAYERELEMENT_TYPE_NON_TEXTURE_COUNT = int(eDIFFUSE_TEXTURES - eUNDEFINED - 1);
00182 
00183     //names for different textures and non-textures channels
00184 
00186     static const char* TEXTURE_NAMES[];
00187 
00189     static const char* TEXTURE_UV_NAMES[];
00190 
00192     static const char* NON_TEXTURE_NAMES[];
00193 
00195     static KFbxDataType TEXTURE_TYPES[];
00196 
00198     static const char* TEXTURE_CHANNEL_NAMES[];
00199 
00210     typedef enum 
00211     {
00212         eNONE,
00213         eBY_CONTROL_POINT,
00214         eBY_POLYGON_VERTEX,
00215         eBY_POLYGON,
00216         eBY_EDGE,
00217         eALL_SAME
00218     } EMappingMode;
00219 
00233     typedef enum 
00234     {
00235         eDIRECT,
00236         eINDEX,
00237         eINDEX_TO_DIRECT
00238     } EReferenceMode;
00239 
00240     
00244     void SetMappingMode(EMappingMode pMappingMode) { mMappingMode = pMappingMode; }
00245 
00249     void SetReferenceMode(EReferenceMode pReferenceMode) { mReferenceMode = pReferenceMode; }
00250 
00254     EMappingMode GetMappingMode() const { return mMappingMode; }
00255 
00259     EReferenceMode GetReferenceMode() const { return mReferenceMode; }
00260 
00264     void SetName(const char* pName) { mName = KString(pName); }
00265 
00269     const char* GetName() const { return ((KFbxLayerElement*)this)->mName.Buffer(); }
00270 
00275     bool operator==(const KFbxLayerElement& pOther) const
00276     {
00277         return (mName == pOther.mName) && 
00278                (mMappingMode == pOther.mMappingMode) &&
00279                (mReferenceMode == pOther.mReferenceMode);
00280     }
00281 
00286     KFbxLayerElement& operator=( KFbxLayerElement const& pOther )
00287     {
00288         mMappingMode = pOther.mMappingMode;
00289         mReferenceMode = pOther.mReferenceMode;
00290         // name, type and owner should not be copied because they are
00291         // initialized when this object is created
00292         return *this;
00293     }
00294 
00296     void Destroy();
00297 
00299     virtual bool Clear() 
00300     { 
00301         return true;
00302     }
00303 
00305 //
00306 //  WARNING!
00307 //
00308 //  Anything beyond these lines may not be documented accurately and is 
00309 //  subject to change without notice.
00310 //
00312 
00313 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00314     void SetType(KFbxDataType* pType) { mType = pType; }
00315     const KFbxLayerContainer* GetOwner() const { return mOwner; }
00316 
00317 protected:
00318     KFbxLayerElement() 
00319         : mMappingMode(eNONE)
00320         , mReferenceMode(eDIRECT)
00321         , mName("")
00322         , mOwner(NULL)
00323     {
00324     }
00325     
00326     virtual ~KFbxLayerElement()
00327     {
00328     }
00329 
00330     EMappingMode mMappingMode;
00331     EReferenceMode mReferenceMode;
00332 
00333     KString mName;
00334     KFbxDataType* mType;
00335     KFbxLayerContainer* mOwner;
00336 
00337     void Destruct() { FbxSdkDelete(this); }
00338     virtual void SetOwner(KFbxLayerContainer* pOwner);
00339 
00340     KFBXNEW_DECLARE_FRIEND
00341     friend class KFbxLayerContainer;
00342 
00343 public:
00348     virtual int MemorySize() const { return 0; }
00349 
00354 
00360     virtual bool ContentWriteTo(KFbxStream& pStream) const;
00361 
00367     virtual bool ContentReadFrom(const KFbxStream& pStream);
00369 
00370 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00371 };
00372 
00378 class KFBX_DLL LockAccessStatus
00379 {
00380 public:
00393     typedef enum {
00394         eSuccess,
00395         eUnsupportedDTConversion,
00396         eCorruptedCopyback,
00397         eBadValue,
00398         eLockMismatch,
00399         eNoWriteLock,
00400         eNoReadLock,
00401         eNotOwner,
00402         eDirectLockExist
00403     } ELockAccessStatus;
00404 };
00405 
00411 class KFBX_DLL KFbxLayerElementArray
00412 {
00413 public:
00418 
00422     KFbxLayerElementArray(EFbxType pDataType);
00423 
00425     virtual ~KFbxLayerElementArray();
00426 
00428 
00433 
00435     inline                                void ClearStatus()     { mStatus = LockAccessStatus::eSuccess; }
00436 
00438     inline LockAccessStatus::ELockAccessStatus GetStatus() const { return mStatus; }
00440 
00445 
00449     inline bool IsWriteLocked() const { return mWriteLock; };
00450 
00454     inline int  GetReadLockCount() const { return mReadLockCount; }
00456 
00460     bool    IsInUse() const;
00461 
00465     int     ReadLock() const;
00466 
00470     int     ReadUnlock() const;
00471 
00476     bool    WriteLock() const;
00477 
00480     void    WriteUnlock() const;
00481 
00486     bool    ReadWriteLock() const;
00487 
00490     void    ReadWriteUnlock() const;
00491 
00492 
00498     typedef enum {
00499         eREAD_LOCK = 1,
00500         eWRITE_LOCK = 2,
00501         eREADWRITE_LOCK = 3
00502     } ELockMode;
00503 
00516     virtual void*   GetLocked(ELockMode pLockMode, EFbxType pDataType);
00517 
00529     void*   GetLocked(ELockMode pLockMode=eREADWRITE_LOCK) { return GetLocked(pLockMode, mDataType); }
00530 
00543     template <class T> inline T* GetLocked(T* dummy=NULL, ELockMode pLockMode=eREADWRITE_LOCK) {T v; return (T*)GetLocked(pLockMode, _FbxTypeOf(v)); }
00544 
00555     virtual void   Release(void** pDataPtr, EFbxType pDataType);
00556 
00566     void   Release(void** pDataPtr) { Release(pDataPtr, mDataType); }
00567 
00578     template <class T> inline void Release(T** pDataPtr, T* dummy) { Release((void**)pDataPtr, _FbxTypeOf(*dummy)); }
00579 
00582     virtual size_t GetStride() const;
00583 
00588 
00590     int     GetCount() const;
00591 
00595     void    SetCount(int pCount);
00596 
00598     void    Clear();
00599 
00603     void    Resize(int pItemCount);
00604 
00608     void    AddMultiple(int pItemCount);
00609 
00615     int     Add(void const* pItem, EFbxType pValueType);
00616 
00623     int     InsertAt(int pIndex, void const* pItem, EFbxType pValueType);
00624 
00630     void    SetAt(int pIndex, void const* pItem, EFbxType pValueType);
00631 
00632 
00637     void    SetLast(void const* pItem, EFbxType pValueType);
00638 
00644     void    RemoveAt(int pIndex, void** pItem, EFbxType pValueType);
00645 
00650     void    RemoveLast(void** pItem, EFbxType pValueType);
00651 
00657     bool    RemoveIt(void** pItem, EFbxType pValueType);
00658 
00666     bool    GetAt(int pIndex, void** pItem, EFbxType pValueType) const;
00667 
00673     bool    GetFirst(void** pItem, EFbxType pValueType) const;
00674 
00680     bool    GetLast(void** pItem, EFbxType pValueType) const;
00681 
00688     int     Find(void const* pItem, EFbxType pValueType) const;
00689 
00697     int     FindAfter(int pAfterIndex, void const* pItem, EFbxType pValueType) const;
00698 
00706     int     FindBefore(int pBeforeIndex, void const* pItem, EFbxType pValueType) const;
00707 
00712     bool    IsEqual(const KFbxLayerElementArray& pArray);
00713 
00718     template <class T> inline int  Add(T const& pItem)                               { return Add((void const*)&pItem, _FbxTypeOf(pItem)); }
00719 
00725     template <class T> inline int  InsertAt(int pIndex, T const& pItem)              { return InsertAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00726 
00731     template <class T> inline void SetAt(int pIndex, T const& pItem)                 { SetAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00732 
00736     template <class T> inline void SetLast(T const& pItem)                           { SetLast((void const*)&pItem, _FbxTypeOf(pItem)); }
00737 
00742     template <class T> inline void RemoveAt(int pIndex, T* pItem)                    { RemoveAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00743 
00747     template <class T> inline void RemoveLast(T* pItem)                              { RemoveLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00748 
00753     template <class T> inline bool RemoveIt(T* pItem)                                { return RemoveIt((void**)&pItem, _FbxTypeOf(*pItem)); }
00754 
00761     template <class T> inline bool GetAt(int pIndex, T* pItem) const                 { return GetAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00762 
00767     template <class T> inline bool GetFirst(T* pItem) const                          { return GetFirst((void**)&pItem, _FbxTypeOf(*pItem)); }
00768 
00773     template <class T> inline bool GetLast(T* pItem) const                           { return GetLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00774 
00780     template <class T> inline int Find(T const& pItem) const                         { return Find((void const*)&pItem, _FbxTypeOf(pItem)); }
00781 
00788     template <class T> inline int FindAfter(int pAfterIndex, T const& pItem) const   { return FindAfter(pAfterIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00789 
00796     template <class T> inline int FindBefore(int pBeforeIndex, T const& pItem) const { return FindBefore(pBeforeIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00797 
00798 
00802     template<typename T> inline void CopyTo(KArrayTemplate<T>& pDst)
00803     {
00804         T src;
00805         T* srcPtr = &src;
00806 
00807         pDst.Clear();
00808         if (mDataType != _FbxTypeOf(src))
00809         {
00810             SetStatus(LockAccessStatus::eUnsupportedDTConversion);
00811             return;
00812         }
00813 
00814         pDst.SetCount(GetCount());
00815         for (int i = 0; i < GetCount(); i++)
00816         {
00817             if (GetAt(i, (void**)&srcPtr, mDataType))
00818             {
00819                 pDst.SetAt(i, src);
00820             }
00821         }
00822         SetStatus(LockAccessStatus::eSuccess);
00823     }
00825 
00826 protected:
00827     void*   GetDataPtr();
00828     void*   GetReference(int pIndex, EFbxType pValueType);
00829     void    GetReferenceTo(int pIndex, void** pRef, EFbxType pValueType);
00830 
00831     inline void SetStatus(LockAccessStatus::ELockAccessStatus pVal) const
00832     {
00833         const_cast<KFbxLayerElementArray*>(this)->mStatus = pVal;
00834     }
00835 
00836             void   SetImplementation(void* pImplementation);
00837     inline  void*  GetImplementation() { return mImplementation; }
00838     virtual void   ConvertDataType(EFbxType pDataType, void** pDataPtr, size_t* pStride);
00839 
00840     EFbxType mDataType;
00841 
00842 private:
00843     LockAccessStatus::ELockAccessStatus mStatus;
00844 
00845     int           mReadLockCount;
00846     bool          mWriteLock;
00847     void*         mImplementation;
00848     size_t        mStride;
00849     int           mDirectLockOn;
00850     bool          mDirectAccessOn;
00851 
00852     KArrayTemplate<void*>   mConvertedData;
00853 
00854 };
00855 
00859 template <typename T>
00860 struct KFbxLayerElementArrayReadLock
00861 {
00862    KFbxLayerElementArrayReadLock(KFbxLayerElementArray& pArray)
00863    : mArray(pArray)
00864    {
00865        mLockedData = mArray.GetLocked((T*)NULL, KFbxLayerElementArray::eREAD_LOCK);
00866    }
00867 
00868    ~KFbxLayerElementArrayReadLock()
00869    {
00870        if( mLockedData )
00871        {
00872            mArray.Release((void **) &mLockedData);
00873        }
00874    }
00875 
00876    const T* GetData() const
00877    {
00878        return mLockedData;
00879    }
00880 
00881 private:
00882     KFbxLayerElementArray&  mArray;
00883     T* mLockedData;
00884 };
00885 
00886 class KFbxLayerElementUserData;
00887 
00892 template <class T> class KFbxLayerElementArrayTemplate : public KFbxLayerElementArray
00893 {
00894 public:
00895 
00899     KFbxLayerElementArrayTemplate(EFbxType pDataType) :
00900         KFbxLayerElementArray(pDataType)
00901         {
00902         }
00903 
00908     inline int  Add( T const &pItem )                       { return KFbxLayerElementArray::Add(pItem); }
00909 
00915     inline int  InsertAt(int pIndex, T const &pItem)        { return KFbxLayerElementArray::InsertAt(pIndex, pItem); }
00916 
00921     inline void SetAt(int pIndex, T const &pItem)           { KFbxLayerElementArray::SetAt(pIndex, pItem); }
00922 
00926     inline void SetLast( T const &pItem)                    { KFbxLayerElementArray::SetLast(pItem); }
00927 
00932     inline T RemoveAt(int pIndex)                           { T lValue; KFbxLayerElementArray::RemoveAt(pIndex, &lValue); return lValue; }
00933 
00937     inline T RemoveLast()                                   { T lValue; KFbxLayerElementArray::RemoveLast(&lValue); return lValue; }
00938 
00943     inline bool RemoveIt(T const &pItem)                    { return KFbxLayerElementArray::RemoveIt(&pItem); }
00944 
00950     inline T  GetAt(int pIndex) const                       { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
00951 
00955     inline T  GetFirst() const                              { T lValue; KFbxLayerElementArray::GetFirst(&lValue); return lValue; }
00956 
00960     inline T  GetLast() const                               { T lValue; KFbxLayerElementArray::GetLast(&lValue); return lValue; }
00961 
00967     inline int Find(T const &pItem)                         { return KFbxLayerElementArray::Find(pItem); }
00968 
00975     inline int FindAfter(int pAfterIndex, T const &pItem)   { return KFbxLayerElementArray::FindAfter(pAfterIndex, pItem); }
00976 
00983     inline int FindBefore(int pBeforeIndex, T const &pItem) { return KFbxLayerElementArray::FindBefore(pBeforeIndex, pItem); }
00984 
00990     T  operator[](int pIndex) const                         { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; } 
00991 
00995     KFbxLayerElementArray& operator=(const KArrayTemplate<T>& pArrayTemplate)
00996     {
00997         SetStatus(LockAccessStatus::eNoWriteLock);
00998         if (WriteLock())
00999         {
01000             SetCount(pArrayTemplate.GetCount());
01001             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
01002                 SetAt(i, pArrayTemplate.GetAt(i));
01003             WriteUnlock();
01004             SetStatus(LockAccessStatus::eSuccess);
01005         }
01006         return *this;
01007     }
01008 
01012     KFbxLayerElementArrayTemplate<T>& operator=(const KFbxLayerElementArrayTemplate<T>& pArrayTemplate)
01013     {
01014         if ( this != &pArrayTemplate )
01015         {
01016             SetStatus(LockAccessStatus::eNoWriteLock);
01017             if (WriteLock())
01018             {
01019                 SetCount(pArrayTemplate.GetCount());
01020                 for (int i = 0; i < pArrayTemplate.GetCount(); i++)
01021                     SetAt(i, pArrayTemplate.GetAt(i));
01022                 WriteUnlock();
01023                 SetStatus(LockAccessStatus::eSuccess);
01024             }
01025         }
01026         return *this;
01027     }
01028 
01029 private:
01030     // This one is not the best thing to do, but at least I don't get deprecated calls inside this file.
01031     // Note that KFbxLayerElementUserData is kind of a weird class in the first place anyway. So either
01032     // we clean it up, or we live with this piece of code ;-)
01033     friend class KFbxLayerElementUserData;
01034     T& AsReference(int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
01035 
01036     T dummy;
01037 };
01038 
01039 
01047 extern int RemapIndexArrayTo(KFbxLayerElement* pLayerEl, 
01048                              KFbxLayerElement::EMappingMode pNewMapping, 
01049                              KFbxLayerElementArrayTemplate<int>* pIndexArray);
01050 
01051 
01056 template <class Type> class KFbxLayerElementTemplate : public KFbxLayerElement
01057 {
01058 public:
01059 
01064     KFbxLayerElementArrayTemplate<Type>& GetDirectArray() const
01065     { 
01066         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01067         return *mDirectArray; 
01068     }
01069 
01074     KFbxLayerElementArrayTemplate<Type>& GetDirectArray()
01075     { 
01076         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01077         return *mDirectArray; 
01078     }
01079 
01084     KFbxLayerElementArrayTemplate<int>& GetIndexArray() const
01085     { 
01086         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01087         return *mIndexArray; 
01088     }
01089 
01094     KFbxLayerElementArrayTemplate<int>& GetIndexArray()
01095     { 
01096         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
01097         return *mIndexArray; 
01098     }
01099 
01104     bool Clear()
01105     {
01106         bool ret = true;
01107         mDirectArray->Clear();
01108         ret = (mDirectArray->GetStatus() == LockAccessStatus::eSuccess);
01109 
01110         mIndexArray->Clear();
01111         ret |= (mIndexArray->GetStatus() == LockAccessStatus::eSuccess);
01112 
01113         return ret;
01114     }
01115 
01116 public:
01117 
01122     bool operator==(const KFbxLayerElementTemplate& pOther) const
01123     {
01124         bool ret = true;
01125 
01126         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
01127             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
01128         {
01129             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
01130             if( directArray.GetCount() != mDirectArray->GetCount() || 
01131                 !directArray.ReadLock() || !mDirectArray->ReadLock() )
01132             {
01133                 ret = false;
01134             }
01135 
01136             if( ret && !mDirectArray->IsEqual(directArray) )
01137                 ret = false;
01138 
01139             directArray.ReadUnlock();
01140             mDirectArray->ReadUnlock();
01141         }
01142 
01143         if (ret)
01144         {
01145             if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01146                 pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
01147             {
01148                 const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
01149                 if( indexArray.GetCount() != mIndexArray->GetCount() ||
01150                     !indexArray.ReadLock() || !mIndexArray->ReadLock() )
01151                 {
01152                     ret = false;
01153                 }
01154 
01155                 if( ret && !mIndexArray->IsEqual(indexArray) )
01156                     ret = false;
01157 
01158                 indexArray.ReadUnlock();
01159                 mIndexArray->ReadUnlock();
01160             }
01161         }
01162 
01163         if (ret == false)
01164             return false;
01165 
01166         return KFbxLayerElement::operator==(pOther);
01167     }
01168 
01172     KFbxLayerElementTemplate& operator=( KFbxLayerElementTemplate const& pOther )
01173     {
01174         K_ASSERT(mDirectArray != NULL);
01175         K_ASSERT(mIndexArray != NULL);
01176 
01177         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
01178             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
01179         {
01180             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
01181             *mDirectArray = directArray;
01182         }
01183 
01184         if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01185             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
01186         {
01187             const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
01188             *mIndexArray = indexArray;
01189         }
01190         
01191         KFbxLayerElement* myself = (KFbxLayerElement*)this;
01192         KFbxLayerElement* myOther = (KFbxLayerElement*)&pOther;
01193         *myself = *myOther;
01194         return *this; 
01195     }
01196 
01204     int RemapIndexTo(KFbxLayerElement::EMappingMode pNewMapping)
01205     {
01206         return RemapIndexArrayTo(this, pNewMapping, mIndexArray);
01207     }
01208 
01210 //
01211 //  WARNING!
01212 //
01213 //  Anything beyond these lines may not be documented accurately and is 
01214 //  subject to change without notice.
01215 //
01217 
01218 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01219 protected:
01220     KFbxLayerElementTemplate() 
01221     {
01222         mDirectArray = NULL;
01223         mIndexArray = NULL;
01224     }
01225 
01226     ~KFbxLayerElementTemplate() 
01227     {
01228         FbxSdkDelete(mDirectArray);
01229         FbxSdkDelete(mIndexArray);
01230     }
01231 
01232     virtual void AllocateArrays()
01233     {
01234         mDirectArray = FbxSdkNew< KFbxLayerElementArrayTemplate<Type> >(mType->GetType());
01235         mIndexArray = FbxSdkNew< KFbxLayerElementArrayTemplate<int> >(DTInteger.GetType());
01236     }
01237 
01238 public:
01239     virtual int MemorySize() const
01240     {
01241         int size = KFbxLayerElement::MemorySize();
01242         size += (mDirectArray->GetCount()*sizeof(Type));
01243         size += (mIndexArray->GetCount()*sizeof(int));
01244         return size;
01245     }
01246 
01251     virtual bool ContentWriteTo(KFbxStream& pStream) const
01252     {
01253         void* a;
01254         int s,v;
01255         int count = 0;
01256 
01257         // direct array
01258         count = mDirectArray->GetCount();
01259         s = pStream.Write(&count, sizeof(int)); 
01260         if (s != sizeof(int)) return false;
01261         if (count > 0)
01262         {
01263             a = mDirectArray->GetLocked();
01264             K_ASSERT(a != NULL);
01265             v = count*sizeof(Type);
01266             s = pStream.Write(a, v); 
01267             mDirectArray->Release(&a);
01268             if (s != v) return false;
01269         }
01270 
01271         // index array
01272         count = mIndexArray->GetCount();
01273         s = pStream.Write(&count, sizeof(int)); 
01274         if (s != sizeof(int)) return false;
01275         if (count > 0)
01276         {
01277             a = mIndexArray->GetLocked();
01278             K_ASSERT(a != NULL);
01279             v = count*sizeof(int);
01280             s = pStream.Write(a, v);
01281             mIndexArray->Release(&a);
01282             if (s != v) return false;
01283         }
01284 
01285         return KFbxLayerElement::ContentWriteTo(pStream);
01286     }
01287 
01288     virtual bool ContentReadFrom(const KFbxStream& pStream)
01289     {
01290         void* a;
01291         int s,v;
01292         int count = 0;
01293 
01294         // direct array
01295         s = pStream.Read(&count, sizeof(int)); 
01296         if (s != sizeof(int)) return false;
01297         mDirectArray->Resize(count);
01298         if (count > 0)
01299         {
01300             a = mDirectArray->GetLocked();
01301             K_ASSERT(a != NULL);
01302             v = count*sizeof(Type);
01303             s = pStream.Read(a, v); 
01304             mDirectArray->Release(&a);
01305             if (s != v) return false;
01306         }
01307 
01308         // index array
01309         s = pStream.Read(&count, sizeof(int)); 
01310         if (s != sizeof(int)) return false;
01311         mIndexArray->Resize(count);     
01312         if (count > 0)
01313         {
01314             a = mIndexArray->GetLocked();
01315             K_ASSERT(a != NULL);
01316             v = count*sizeof(int);
01317             s = pStream.Read(a, v);
01318             mIndexArray->Release(&a);
01319             if (s != v) return false;
01320         }
01321         return KFbxLayerElement::ContentReadFrom(pStream);
01322     }
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 
01388 class KFBX_DLL KFbxLayerElementMaterial : public KFbxLayerElementTemplate<KFbxSurfaceMaterial*>
01389 {
01390 public:
01391     typedef KFbxLayerElementTemplate<KFbxSurfaceMaterial*> ParentClass;
01392 
01396     CREATE_DECLARE(LayerElementMaterial);
01397     
01398     class LayerElementArrayProxy : public KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>
01399     {
01400     public:
01401         typedef KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*> ParentClass;
01402 
01403         LayerElementArrayProxy(EFbxType pType);
01404         void SetContainer( KFbxLayerContainer* pContainer, int pInstance = 0);
01405     };
01406 
01407 
01409 //
01410 //  WARNING!
01411 //
01412 //  Anything beyond these lines may not be documented accurately and is 
01413 //  subject to change without notice.
01414 //
01416 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01417 
01418     virtual void AllocateArrays();
01419     virtual void SetOwner( KFbxLayerContainer* pOwner, int pInstance = 0);
01420     virtual void SetInstance( int pInstance ) { SetOwner( mOwner, pInstance ); }
01421 
01422 protected:
01423     KFbxLayerElementMaterial();
01424     ~KFbxLayerElementMaterial();
01425 
01426 #endif //DOXYGEN_SHOULD_SKIP_THIS
01427 }; 
01428 
01432 class KFBX_DLL KFbxLayerElementPolygonGroup : public KFbxLayerElementTemplate<int>
01433 {
01434 public:
01435 
01439     CREATE_DECLARE(LayerElementPolygonGroup);
01440     
01441 protected:
01442     KFbxLayerElementPolygonGroup();
01443     ~KFbxLayerElementPolygonGroup();
01444 };
01445 
01449 class KFBX_DLL KFbxLayerElementUV : public KFbxLayerElementTemplate<KFbxVector2>
01450 {
01451 public:
01455     CREATE_DECLARE(LayerElementUV);
01456     
01457 protected:
01458     KFbxLayerElementUV();
01459     ~KFbxLayerElementUV();
01460 };
01461 
01465 class KFBX_DLL KFbxLayerElementVertexColor : public KFbxLayerElementTemplate<KFbxColor>
01466 {
01467 public:
01468 
01472     CREATE_DECLARE(LayerElementVertexColor);
01473     
01474 protected:
01475     KFbxLayerElementVertexColor();
01476     ~KFbxLayerElementVertexColor();
01477 };
01478 
01481 const int kNoMapping = -1;
01482 
01483 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, int pIndex, bool* pStatus = NULL);
01484 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus = NULL);
01485 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, const char* pName, bool* pStatus = NULL );
01486 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus = NULL );
01487 
01493 class KFBX_DLL KFbxLayerElementUserData : public KFbxLayerElementTemplate<void*>
01494 {
01495 public:
01496     KFBXNEW_DECLARE_FRIEND
01497 
01507     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, char const *pName, int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames);
01508 
01514     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, KFbxLayerElementUserData const& pOther );
01515 
01521     KFbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL)
01522     {       
01523         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01524         {
01525             if (pStatus) *pStatus = true;
01526             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01527         }
01528         else
01529         {
01530             if( pStatus ) *pStatus = false;
01531             K_ASSERT_MSG_NOW("Index out of bounds");
01532             return (KFbxLayerElementArrayTemplate<void*>*)NULL;
01533         }
01534     }
01535 
01541     KFbxLayerElementArrayTemplate<void*> const* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL) const
01542     {
01543         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01544         {
01545             if (pStatus) *pStatus = true;
01546             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01547         }
01548         else
01549         {
01550             if( pStatus ) *pStatus = false;
01551             K_ASSERT_MSG_NOW("Index out of bounds");
01552             return (KFbxLayerElementArrayTemplate<void*> const*)NULL;
01553         }
01554     }
01555 
01556 
01562     KFbxLayerElementArrayTemplate<void *>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL )
01563     {
01564         KString lName( pName );
01565         for( int i = 0; i < mDataNames.GetCount(); ++i )
01566         {
01567             if( *mDataNames[i] == lName )
01568                 return GetDirectArrayVoid(i, pStatus);
01569         }
01570 
01571         if (pStatus) *pStatus = false;
01572         return (KFbxLayerElementArrayTemplate<void *>*)NULL;
01573     }
01574  
01580     KFbxLayerElementArrayTemplate<void *> const* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL ) const
01581     {
01582         KString lName( pName );
01583         for( int i = 0; i < mDataNames.GetCount(); ++i )
01584         {
01585             if( *mDataNames[i] == lName )
01586                 return GetDirectArrayVoid(i, pStatus);
01587         }
01588 
01589         if (pStatus) *pStatus = false;
01590         return (KFbxLayerElementArrayTemplate<void *> const*)NULL;
01591     }
01592 
01597     KFbxDataType GetDataType( int pIndex ) const
01598     {
01599         if( pIndex < 0 || pIndex >= mDataTypes.GetCount() )
01600             return DTNone;
01601 
01602         return mDataTypes[pIndex];
01603     }
01604 
01609     KFbxDataType GetDataType( const char* pName ) const
01610     {
01611         KString lName( pName );
01612 
01613         for( int i = 0; i < mDataNames.GetCount(); ++i )
01614         {
01615             if( *mDataNames[i] == lName )
01616                 return mDataTypes[i];
01617         }
01618 
01619         return DTNone;
01620     }
01621 
01626     const char* GetDataName( int pIndex ) const
01627     {
01628         if( pIndex >= 0 && pIndex < mDataNames.GetCount() )
01629             return mDataNames[pIndex]->Buffer();
01630 
01631         return NULL;
01632     }
01633 
01637     void ResizeAllDirectArrays( int pSize )
01638     {
01639         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01640         {
01641             switch( mDataTypes[i].GetType() )
01642             {
01643                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).Resize( pSize )  ; break;
01644                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).Resize( pSize )   ; break;
01645                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).Resize( pSize ) ; break;
01646                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).Resize( pSize ); break;
01647                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).Resize( pSize );    break;
01648                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).Resize( pSize );    break;
01649                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).Resize( pSize );    break;  
01650                 default:
01651                     K_ASSERT_MSG_NOW("unknown type" ); break;
01652             }
01653         }
01654     }
01655 
01659     void RemoveFromAllDirectArrays( int pIndex )
01660     {
01661         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01662         {
01663             switch( mDataTypes[i].GetType() )
01664             {
01665                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).RemoveAt( pIndex )  ; break;
01666                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).RemoveAt( pIndex )   ; break;
01667                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).RemoveAt( pIndex ) ; break;
01668                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).RemoveAt( pIndex ); break;
01669                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).RemoveAt( pIndex ); break;
01670                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).RemoveAt( pIndex ); break;
01671                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).RemoveAt( pIndex ); break;  
01672                 default:
01673                     K_ASSERT_MSG_NOW("unknown type" ); break;
01674             }
01675         }
01676     }
01677 
01682     int GetArrayCount( int pIndex ) const 
01683     {
01684         if( pIndex >= 0 && pIndex < GetDirectArray().GetCount() )
01685         {
01686             switch( mDataTypes[pIndex].GetType() )
01687             {
01688                 case eBOOL1:    return KFbxGetDirectArray<bool>(this,pIndex).GetCount();
01689                 case eINTEGER1: return KFbxGetDirectArray<int>(this,pIndex).GetCount();
01690                 case eFLOAT1:   return KFbxGetDirectArray<float>(this,pIndex).GetCount();
01691                 case eDOUBLE1:  return KFbxGetDirectArray<double>(this,pIndex).GetCount();
01692                 //case eDOUBLE3:    return GetDirectArray< fbxDouble3 >(pIndex).GetCount();
01693                 //case eDOUBLE4:    return GetDirectArray< fbxDouble4 >(pIndex).GetCount();
01694                 //case eDOUBLE44:   return GetDirectArray< fbxDouble44>(pIndex).GetCount();
01695                 default:
01696                     K_ASSERT_MSG_NOW("Unknown type" ); break;
01697             }
01698         }
01699 
01700         return -1;
01701     }
01702 
01706     int GetId() const { return mId; }
01707 
01712     int GetDirectArrayCount() const { return GetDirectArray().GetCount(); }
01713 
01718     KFbxLayerElementUserData& operator=( KFbxLayerElementUserData const& pOther )
01719     {
01720         if (this == &pOther)
01721             return *this;
01722 
01723         Clear();
01724 
01725         mId = pOther.mId;
01726         mDataTypes = pOther.mDataTypes;
01727         mDataNames.Resize(pOther.mDataNames.GetCount());
01728         for(int i = 0; i < pOther.mDataNames.GetCount(); ++i)
01729             mDataNames.SetAt(i,  FbxSdkNew< KString >( *pOther.mDataNames[i] ) );
01730 
01731         Init();
01732         for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
01733         {
01734             switch (mDataTypes[i].GetType())
01735             {
01736             case eBOOL1:
01737                 KFbxGetDirectArray<bool>(this, i) = KFbxGetDirectArray<bool>(&pOther, i);
01738                 break;
01739 
01740             case eINTEGER1:
01741                 KFbxGetDirectArray<int>(this, i) = KFbxGetDirectArray<int>(&pOther, i);
01742                 break;
01743 
01744             case eFLOAT1:
01745                 KFbxGetDirectArray<float>(this, i) = KFbxGetDirectArray<float>(&pOther, i);
01746                 break;
01747 
01748             case eDOUBLE1:
01749                 KFbxGetDirectArray<double>(this, i) = KFbxGetDirectArray<double>(&pOther, i);
01750                 break;
01751 
01752             default:
01753                 K_ASSERT_MSG_NOW("Unknown type" );
01754                 break;
01755             }
01756         }
01757 
01758         if ( ( mReferenceMode == KFbxLayerElement::eINDEX || 
01759                mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT) &&
01760              ( pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01761                pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT))
01762         {
01763             GetIndexArray() = pOther.GetIndexArray();
01764         }
01765 
01766         return *this;
01767     }
01768 
01772     bool Clear()
01773     {
01774         int i;
01775         const int lCount = GetDirectArray().GetCount();
01776         KFbxLayerElementArray** directArray = NULL;
01777         directArray = GetDirectArray().GetLocked(directArray);
01778         for( i = 0; directArray != NULL && i < lCount; ++i )
01779         {
01780             if( directArray[i] )
01781                 FbxSdkDelete(directArray[i]);
01782         }
01783         GetDirectArray().Release((void**)&directArray);
01784 
01785         for( i = 0; i < mDataNames.GetCount(); ++i )
01786         {
01787             KFBX_SAFE_DELETE_PTR(mDataNames[i]);
01788         }
01789         mDataNames.Clear();
01790         mDataTypes.Clear();
01791 
01792         KFbxLayerElementTemplate<void*>::Clear();
01793 
01794         return true;
01795     }
01796 
01801     virtual int MemorySize() const
01802     {
01803         int size = KFbxLayerElementTemplate<void*>::MemorySize();
01804         size += sizeof(mId);
01805 
01806         for(int i = 0; i < mDataTypes.GetCount(); i++)
01807         {
01808             size += sizeof(mDataTypes[i]);
01809         }
01810         size += (mDataNames.GetCount() * sizeof(KString*));
01811 
01812         return size;
01813     }
01814 
01816 //
01817 //  WARNING!
01818 //
01819 //  Anything beyond these lines may not be documented accurately and is 
01820 //  subject to change without notice.
01821 //
01823 
01824 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01825 protected:
01835     KFbxLayerElementUserData( int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames )
01836         :
01837         mId( pId ),
01838         mDataTypes( pDataTypes )
01839     {
01840         K_ASSERT( pDataTypes.GetCount() == pDataNames.GetCount() );
01841         for( int i = 0; i < pDataNames.GetCount(); ++i )
01842         {
01843             mDataNames.Add( FbxSdkNew< KString >( pDataNames[i] ) );
01844         }
01845     }
01846 
01850     KFbxLayerElementUserData( KFbxLayerElementUserData const& pOther ) : mId(pOther.mId), mDataTypes(pOther.mDataTypes)
01851     {
01852         for (int lIndex = 0; lIndex < pOther.mDataNames.GetCount(); ++lIndex)
01853         {
01854             mDataNames.Add(FbxSdkNew<KString>(*(pOther.mDataNames[lIndex])));
01855         }
01856 
01857         SetType(&DTLayerElementUserData);
01858         AllocateArrays();
01859 
01860         for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
01861         {
01862             switch (mDataTypes[i].GetType())
01863             {
01864             case eBOOL1:
01865                 KFbxGetDirectArray<bool>(this, i) = KFbxGetDirectArray<bool>(&pOther, i);
01866                 break;
01867 
01868             case eINTEGER1:
01869                 KFbxGetDirectArray<int>(this, i) = KFbxGetDirectArray<int>(&pOther, i);
01870                 break;
01871 
01872             case eFLOAT1:
01873                 KFbxGetDirectArray<float>(this, i) = KFbxGetDirectArray<float>(&pOther, i);
01874                 break;
01875 
01876             case eDOUBLE1:
01877                 KFbxGetDirectArray<double>(this, i) = KFbxGetDirectArray<double>(&pOther, i);
01878                 break;
01879 
01880             default:
01881                 K_ASSERT_MSG_NOW("Unknown type" );
01882                 break;
01883             }
01884         }
01885 
01886         if ( ( mReferenceMode == KFbxLayerElement::eINDEX || 
01887             mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT) &&
01888             ( pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
01889             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT))
01890         {
01891             GetIndexArray() = pOther.GetIndexArray();
01892         }
01893     }
01894 
01896     ~KFbxLayerElementUserData()
01897     {
01898         Clear();
01899     }
01900 
01902     virtual void AllocateArrays()
01903     {
01904         KFbxLayerElementTemplate<void*>::AllocateArrays();
01905         Init();
01906     }
01907 
01908 
01909 private:
01910 
01911     void Init()
01912     {
01913         int i;
01914         GetDirectArray().Resize( mDataTypes.GetCount() );
01915 
01916         // initialize arrays
01917         for( i = 0; i < mDataTypes.GetCount(); ++i )
01918         {
01919             kReference** dst = NULL;
01920             dst = GetDirectArray().GetLocked(dst);
01921             if (dst)
01922             {
01923                 switch( mDataTypes[i].GetType() )
01924                 {
01925                     case eBOOL1:    dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<bool> >(mDataTypes[i].GetType());    break;
01926                     case eINTEGER1: dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<int> >(mDataTypes[i].GetType()); break;
01927                     case eFLOAT1:   dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<float> >(mDataTypes[i].GetType());   break;
01928                     case eDOUBLE1:  dst[i] = (kReference*)FbxSdkNew< KFbxLayerElementArrayTemplate<double> >(mDataTypes[i].GetType());  break;
01929                     //case eDOUBLE3:    mDirectArray[i] = new KArrayTemplate< fbxDouble3 >();   break;  
01930                     //case eDOUBLE4:    mDirectArray[i] = new KArrayTemplate< fbxDouble4 >();   break;
01931                     //case eDOUBLE44:   mDirectArray[i] = new KArrayTemplate< fbxDouble44 >();  break;  
01932                     default:
01933                         K_ASSERT_MSG_NOW("Trying to assign an unknown type" ); break;
01934                 }
01935                 GetDirectArray().Release((void**)&dst);
01936             }
01937         }
01938     }
01939 
01940     int mId;
01941     KArrayTemplate<KFbxDataType> mDataTypes;
01942     KArrayTemplate<KString*> mDataNames;
01943   #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01944 };
01945 
01953 template <class T>
01954 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,int pIndex, bool* pStatus)
01955 {
01956     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
01957 }
01958 
01966 template <class T>
01967 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus)
01968 {
01969     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
01970 }
01971 
01972 
01980 template <class T>
01981 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,const char* pName, bool* pStatus )
01982 {
01983     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01984 }
01985 
01993 template <class T>
01994 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus )
01995 {
01996     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01997 }
01998 
01999 
02003 class KFBX_DLL KFbxLayerElementSmoothing : public KFbxLayerElementTemplate<int>
02004 {
02005 public:
02006     KFBXNEW_DECLARE_FRIEND
02007 
02013     static KFbxLayerElementSmoothing* Create(KFbxLayerContainer* pOwner, char const *pName);
02014 
02019     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02020     {
02021         if( pMode != KFbxLayerElement::eDIRECT )
02022         {
02023             K_ASSERT_MSG_NOW( "Smoothing layer elements must be direct mapped" );
02024             return;
02025         }
02026     }
02027 
02029 //
02030 //  WARNING!
02031 //
02032 //  Anything beyond these lines may not be documented accurately and is 
02033 //  subject to change without notice.
02034 //
02036 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02037 
02038 protected:
02039     KFbxLayerElementSmoothing()
02040     {
02041         mReferenceMode = KFbxLayerElement::eDIRECT;
02042     }
02043 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02044 };
02045 
02049 class KFBX_DLL KFbxLayerElementCrease : public KFbxLayerElementTemplate<double>
02050 {
02051 public:
02052     KFBXNEW_DECLARE_FRIEND
02053 
02059     static KFbxLayerElementCrease* Create(KFbxLayerContainer* pOwner, char const *pName);
02060 
02065     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02066     {
02067         if( pMode != KFbxLayerElement::eDIRECT )
02068         {
02069             K_ASSERT_MSG_NOW( "Crease layer elements must be direct mapped" );
02070             return;
02071         }
02072     }
02073 
02075 //
02076 //  WARNING!
02077 //
02078 //  Anything beyond these lines may not be documented accurately and is 
02079 //  subject to change without notice.
02080 //
02082 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02083 
02084 protected:
02085     KFbxLayerElementCrease()
02086     {
02087         mReferenceMode = KFbxLayerElement::eDIRECT;
02088     }
02089 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02090 
02091 };
02092 
02096 class KFBX_DLL KFbxLayerElementHole : public KFbxLayerElementTemplate<bool>
02097 {
02098 public:
02099     KFBXNEW_DECLARE_FRIEND
02100 
02106         static KFbxLayerElementHole* Create(KFbxLayerContainer* pOwner, char const *pName);
02107 
02112     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
02113     {
02114         if( pMode != KFbxLayerElement::eDIRECT )
02115         {
02116             K_ASSERT_MSG_NOW( "hole layer elements must be direct mapped" );
02117             return;
02118         }
02119     }
02120 
02122     //
02123     //  WARNING!
02124     //
02125     //  Anything beyond these lines may not be documented accurately and is 
02126     //  subject to change without notice.
02127     //
02129 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02130 
02131 protected:
02132     KFbxLayerElementHole()
02133     {
02134         mReferenceMode = KFbxLayerElement::eDIRECT;
02135     }
02136 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02137 
02138 };
02139 
02142 class KFBX_DLL KFbxLayerElementVisibility : public KFbxLayerElementTemplate<bool>
02143 {
02144 public:
02145 
02149     CREATE_DECLARE(LayerElementVisibility);
02150 
02152 //
02153 //  WARNING!
02154 //
02155 //  Anything beyond these lines may not be documented accurately and is 
02156 //  subject to change without notice.
02157 //
02159 
02160 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02161 protected:
02162     KFbxLayerElementVisibility();
02163     ~KFbxLayerElementVisibility();
02164 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02165 };
02166 
02167 typedef class KFBX_DLL KFbxLayerElementTemplate<KFbxTexture*>  KFbxLayerElementTextureBase;
02168 
02172 class KFBX_DLL KFbxLayerElementTexture : public KFbxLayerElementTextureBase
02173 {
02174 
02175 public:
02176 
02180     CREATE_DECLARE(LayerElementTexture);
02181 
02190     typedef enum 
02191     {
02192         eTRANSLUCENT,
02193         eADD,
02194         eMODULATE,
02195         eMODULATE2,
02196         eOVER,
02197         eMAXBLEND
02198     } EBlendMode;
02199 
02203     void       SetBlendMode(EBlendMode pBlendMode) { mBlendMode = pBlendMode; }
02204 
02209     void       SetAlpha(double pAlpha)
02210     {
02211         if (pAlpha > 1.0)
02212             mAlpha = 1.0;
02213         else if (pAlpha < 0.0)
02214             mAlpha = 0.0;
02215         else
02216             mAlpha = pAlpha;
02217     }
02218 
02222     EBlendMode GetBlendMode()                      { return mBlendMode; } 
02223 
02227     double     GetAlpha()                          { return mAlpha; }
02228 
02230 //
02231 //  WARNING!
02232 //
02233 //  Anything beyond these lines may not be documented accurately and is 
02234 //  subject to change without notice.
02235 //
02237 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02238 
02239     virtual int MemorySize() const
02240     {
02241         int size = KFbxLayerElementTextureBase::MemorySize();
02242         size += sizeof(mBlendMode);
02243         size += sizeof(mAlpha);
02244         return size;
02245     }
02246 
02247 protected:
02252     KFbxLayerElementTexture() : mBlendMode(eTRANSLUCENT)
02253     {
02254         mReferenceMode = eINDEX_TO_DIRECT;
02255         mAlpha         = 1.0;
02256     }
02257 
02258 private:
02259     EBlendMode mBlendMode;
02260     double     mAlpha;
02261 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02262 };
02263 
02264 
02301 class KFBX_DLL KFbxLayer
02302 {
02303 
02304 public:
02305     KFBXNEW_DECLARE_FRIEND
02306 
02311 
02316     KFbxLayerElementNormal* GetNormals();   
02317 
02322     KFbxLayerElementNormal const* GetNormals() const;
02323 
02328     KFbxLayerElementTangent* GetTangents(); 
02329 
02334     KFbxLayerElementTangent const* GetTangents() const;
02335 
02340     KFbxLayerElementBinormal* GetBinormals();   
02341 
02346     KFbxLayerElementBinormal const* GetBinormals() const;
02347 
02351     KFbxLayerElementMaterial* GetMaterials();
02352 
02356     KFbxLayerElementMaterial const* GetMaterials() const;
02357 
02361     KFbxLayerElementPolygonGroup* GetPolygonGroups();
02362 
02366     KFbxLayerElementPolygonGroup const* GetPolygonGroups() const;
02367 
02374     KFbxLayerElementUV* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02375 
02382     KFbxLayerElementUV const* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
02383 
02384 
02387     int GetUVSetCount() const;
02388     
02391     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetUVSetChannels() const;
02392 
02395     KArrayTemplate<KFbxLayerElementUV const*> GetUVSets() const;
02396 
02401     KFbxLayerElementVertexColor* GetVertexColors();
02402 
02407     KFbxLayerElementVertexColor const* GetVertexColors() const;
02408 
02413     KFbxLayerElementSmoothing* GetSmoothing();
02414 
02419     KFbxLayerElementSmoothing const* GetSmoothing() const;
02420 
02425     KFbxLayerElementCrease* GetVertexCrease();
02426 
02431     KFbxLayerElementCrease const* GetVertexCrease() const;
02432 
02437     KFbxLayerElementCrease* GetEdgeCrease();
02438 
02443     KFbxLayerElementCrease const* GetEdgeCrease() const;
02444 
02449     KFbxLayerElementHole* GetHole();
02450 
02455     KFbxLayerElementHole const* GetHole() const;
02456 
02460     KFbxLayerElementUserData* GetUserData();
02461 
02465     KFbxLayerElementUserData const* GetUserData() const;
02466 
02470     KFbxLayerElementVisibility* GetVisibility();
02471 
02475     KFbxLayerElementVisibility const* GetVisibility() const;
02476 
02481     KFbxLayerElementTexture* GetTextures(KFbxLayerElement::ELayerElementType pType);
02482 
02487     KFbxLayerElementTexture const* GetTextures(KFbxLayerElement::ELayerElementType pType) const;
02488 
02493     void SetTextures(KFbxLayerElement::ELayerElementType pType, KFbxLayerElementTexture* pTextures);
02494 
02513     KFbxLayerElement* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02514 
02533     KFbxLayerElement const* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false) const;
02534 
02539     void SetNormals(KFbxLayerElementNormal* pNormals);
02540 
02545     void SetBinormals(KFbxLayerElementBinormal* pBinormals);
02546 
02551     void SetTangents(KFbxLayerElementTangent* pTangents);
02552 
02556     void SetMaterials(KFbxLayerElementMaterial* pMaterials);
02557 
02561     void SetPolygonGroups(KFbxLayerElementPolygonGroup* pPolygonGroups);
02562 
02569     void SetUVs(KFbxLayerElementUV* pUVs, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02570 
02575     void SetVertexColors (KFbxLayerElementVertexColor* pVertexColors);
02576 
02581     void SetSmoothing (KFbxLayerElementSmoothing* pSmoothing);
02582 
02587     void SetVertexCrease (KFbxLayerElementCrease* pCrease);
02588 
02593     void SetEdgeCrease (KFbxLayerElementCrease* pCrease);
02594 
02599     void SetHole (KFbxLayerElementHole* pHole);
02600 
02604     void SetUserData (KFbxLayerElementUserData* pUserData);
02605 
02609     void SetVisibility( KFbxLayerElementVisibility* pVisibility );
02610 
02617     KFbxLayerElement* CreateLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02618 
02623     void Clone(KFbxLayer const& pSrcLayer, KFbxSdkManager* pSdkManager);    
02624     
02625     
02627 //
02628 //  WARNING!
02629 //
02630 //  Anything beyond these lines may not be documented accurately and is 
02631 //  subject to change without notice.
02632 //
02634 
02635 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02636 protected:
02638     KFbxLayer& operator=(KFbxLayer const& pSrcLayer);
02640 private:
02641 
02642     KFbxLayer(KFbxLayerContainer& pOwner);
02643     virtual ~KFbxLayer();
02644 
02645     void Clear();
02646 
02647     KFbxLayerContainer& mOwner;
02648 
02649     KFbxLayerElement*             mNonTexturesArray[KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_COUNT];
02650     KFbxLayerElementUV*           mUVsArray[KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT];
02651     KFbxLayerElementTexture*      mTexturesArray[KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT];
02652 
02653 
02654     friend class KFbxLayerContainer;
02655 
02656 public:
02661         bool ContentWriteTo(KFbxStream& pStream) const;
02662         bool ContentReadFrom(const KFbxStream& pStream);
02664     virtual int MemoryUsage() const;
02665 
02666 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02667 };
02668 
02672 #define FOR_EACH_TEXTURE(lLayerIndex) for((lLayerIndex) = 0; (lLayerIndex) < KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_COUNT; (lLayerIndex)++)
02673 
02677 #define FOR_EACH_NON_TEXTURE(lLayerIndex) for((lLayerIndex) = 0; (lLayerIndex) < KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_COUNT; (lLayerIndex)++)
02678 
02682 #define TEXTURE_INDEX(ElementType) (int(ElementType) - KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_START_INDEX)
02683 
02687 #define TEXTURE_TYPE(TextureIndex) (KFbxLayerElement::ELayerElementType((TextureIndex) + KFbxLayerElement::LAYERELEMENT_TYPE_TEXTURE_START_INDEX))
02688 
02692 #define NON_TEXTURE_INDEX(ElementType) (int(ElementType) - KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX)
02693 
02697 #define NON_TEXTURE_TYPE(Index) (KFbxLayerElement::ELayerElementType((Index) + KFbxLayerElement::LAYERELEMENT_TYPE_NON_TEXTURE_START_INDEX))
02698 
02699 #undef CREATE_DECLARE
02700 #include <fbxfilesdk/fbxfilesdk_nsend.h>
02701 
02702 #endif // FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
02703