FBX SDK Reference Guide: kfbxlayer.h Source File
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 © 2001 - 2008 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 
00042 #include <fbxfilesdk/components/kbaselib/kaydaradef_h.h>
00043 #include <fbxfilesdk/components/kbaselib/kaydara.h>
00044 
00045 #include <fbxfilesdk/components/kbaselib/klib/kstring.h>
00046 #include <fbxfilesdk/components/kbaselib/klib/karrayul.h>
00047 #include <fbxfilesdk/components/kbaselib/klib/kdebug.h>
00048 
00049 #include <fbxfilesdk/kfbxmath/kfbxvector2.h>
00050 #include <fbxfilesdk/kfbxmath/kfbxvector4.h>
00051 #include <fbxfilesdk/kfbxplugins/kfbxcolor.h>
00052 #include <fbxfilesdk/kfbxplugins/kfbxdatatypes.h>
00053 #include <fbxfilesdk/kfbxplugins/kfbxstream.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 
00077 class KFBX_DLL KFbxLayerElement
00078 {
00079 
00080 public:
00081 
00109     typedef enum 
00110     {
00111         eUNDEFINED,
00112         eNORMAL,
00113         eMATERIAL,
00114         eDIFFUSE_TEXTURES,
00115         ePOLYGON_GROUP,
00116         eUV,
00117         eVERTEX_COLOR,
00118         eSMOOTHING,
00119         eUSER_DATA,
00120         eVISIBILITY,
00121         eEMISSIVE_TEXTURES,
00122         eEMISSIVE_FACTOR_TEXTURES,
00123         eAMBIENT_TEXTURES,
00124         eAMBIENT_FACTOR_TEXTURES,
00125         eDIFFUSE_FACTOR_TEXTURES,
00126         eSPECULAR_TEXTURES,
00127         eNORMALMAP_TEXTURES,
00128         eSPECULAR_FACTOR_TEXTURES,
00129         eSHININESS_TEXTURES,
00130         eBUMP_TEXTURES,
00131         eTRANSPARENT_TEXTURES,
00132         eTRANSPARENCY_FACTOR_TEXTURES,
00133         eREFLECTION_TEXTURES,
00134         eREFLECTION_FACTOR_TEXTURES,
00135         eLAST_ELEMENT_TYPE
00136     } ELayerElementType;
00137 
00148     typedef enum 
00149     {
00150         eNONE,
00151         eBY_CONTROL_POINT,
00152         eBY_POLYGON_VERTEX,
00153         eBY_POLYGON,
00154         eBY_EDGE,
00155         eALL_SAME
00156     } EMappingMode;
00157 
00171     typedef enum 
00172     {
00173         eDIRECT,
00174         eINDEX,
00175         eINDEX_TO_DIRECT
00176     } EReferenceMode;
00177 
00178     
00182     void SetMappingMode(EMappingMode pMappingMode) { mMappingMode = pMappingMode; }
00183 
00187     void SetReferenceMode(EReferenceMode pReferenceMode) { mReferenceMode = pReferenceMode; }
00188 
00192     EMappingMode GetMappingMode() const { return mMappingMode; }
00193 
00197     EReferenceMode GetReferenceMode() const { return mReferenceMode; }
00198 
00202     void SetName(const char* pName) { mName = KString(pName); }
00203 
00207     const char* GetName() const { return ((KFbxLayerElement*)this)->mName.Buffer(); }
00208 
00209     bool operator == (const KFbxLayerElement& pOther) const
00210     {
00211         return (mName == pOther.mName) && 
00212                (mMappingMode == pOther.mMappingMode) &&
00213                (mReferenceMode == pOther.mReferenceMode);
00214     }
00215 
00216     KFbxLayerElement& operator=( KFbxLayerElement const& pOther )
00217     {
00218         mMappingMode = pOther.mMappingMode;
00219         mReferenceMode = pOther.mReferenceMode;
00220         // name, type and owner should not be copied because they are
00221         // initialized when this object is created
00222         return *this;
00223     }
00224 
00227     void Destroy();
00228 
00230 //
00231 //  WARNING!
00232 //
00233 //  Anything beyond these lines may not be documented accurately and is 
00234 //  subject to change without notice.
00235 //
00237 
00238 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00239     void SetType(KFbxDataType* pType) { mType = pType; }
00240     const KFbxLayerContainer* GetOwner() const { return mOwner; }
00241 
00242 protected:
00243     KFbxLayerElement() 
00244         : mMappingMode(eNONE)
00245         , mReferenceMode(eDIRECT)
00246         , mName("")
00247         , mOwner(NULL)
00248     {
00249     }
00250     
00251     virtual ~KFbxLayerElement()
00252     {
00253     }
00254 
00255     EMappingMode mMappingMode;
00256     EReferenceMode mReferenceMode;
00257 
00258     KString mName;
00259     KFbxDataType* mType;
00260     KFbxLayerContainer* mOwner;
00261 
00262     void Destruct() { delete this; }
00263     virtual void SetOwner(KFbxLayerContainer* pOwner);
00264 
00265     friend class KFbxLayerContainer;
00266 
00267 public:
00272     virtual int MemorySize() const { return 0; }
00273 
00278     virtual bool ContentWriteTo(KFbxStream& pStream) const;
00279     virtual bool ContentReadFrom(const KFbxStream& pStream);
00281 
00282 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00283 };
00284 
00289 class KFBX_DLL LockAccessStatus
00290 {
00291 public:
00303     typedef enum {
00304         eSuccess,
00305         eUnsupportedDTConversion,
00306         eCorruptedCopyback,
00307         eBadValue,
00308         eLockMismatch,
00309         eNoWriteLock,
00310         eNoReadLock,
00311         eNotOwner,
00312         eDirectLockExist
00313     } ELockAccessStatus;
00314 };
00315 
00320 class KFBX_DLL KFbxLayerElementArray
00321 {
00322 public:
00330     KFbxLayerElementArray(EFbxType pDataType);
00332     virtual ~KFbxLayerElementArray();
00334 
00339 
00341     inline                                void ClearStatus()     { mStatus = LockAccessStatus::eSuccess; }
00342 
00344     inline LockAccessStatus::ELockAccessStatus GetStatus() const { return mStatus; }
00346 
00351 
00355     inline bool IsWriteLocked() const { return mWriteLock; };
00356 
00360     inline int  GetReadLockCount() const { return mReadLockCount; }
00362 
00365     bool    IsInUse() const;
00366 
00370     int     ReadLock() const;
00371 
00375     int     ReadUnlock() const;
00376 
00381     bool    WriteLock() const;
00382 
00385     void    WriteUnlock() const;
00386 
00391     bool    ReadWriteLock() const;
00392 
00395     void    ReadWriteUnlock() const;
00396 
00397 
00398     // Data access
00399     typedef enum {
00400         eREAD_LOCK = 1,
00401         eWRITE_LOCK = 2,
00402         eREADWRITE_LOCK = 3
00403     } ELockMode;
00404 
00417     virtual void*   GetLocked(ELockMode pLockMode, EFbxType pDataType);
00418     void*   GetLocked(ELockMode pLockMode=eREADWRITE_LOCK) { return GetLocked(pLockMode, mDataType); }
00419     template <class T> inline T* GetLocked(T* dummy=NULL, ELockMode pLockMode=eREADWRITE_LOCK) {T v; return (T*)GetLocked(pLockMode, _FbxTypeOf(v)); }
00420 
00431     virtual void   Release(void** pDataPtr, EFbxType pDataType);
00432     void   Release(void** pDataPtr) { Release(pDataPtr, mDataType); }
00433     template <class T> inline void Release(T** pDataPtr, T* dummy) { Release((void**)pDataPtr, _FbxTypeOf(*dummy)); }
00434 
00437     virtual size_t GetStride() const;
00438 
00443     int     GetCount() const;
00444     void    SetCount(int pCount);
00445     void    Clear();
00446     void    Resize(int pItemCount);
00447     void    AddMultiple(int pItemCount);
00448 
00449     int     Add(void const* pItem, EFbxType pValueType);
00450     int     InsertAt(int pIndex, void const* pItem, EFbxType pValueType);
00451     void    SetAt(int pIndex, void const* pItem, EFbxType pValueType);
00452     void    SetLast(void const* pItem, EFbxType pValueType);
00453 
00454     void    RemoveAt(int pIndex, void** pItem, EFbxType pValueType);
00455     void    RemoveLast(void** pItem, EFbxType pValueType);
00456     bool    RemoveIt(void** pItem, EFbxType pValueType);
00457 
00458     bool    GetAt(int pIndex, void** pItem, EFbxType pValueType) const;
00459     bool    GetFirst(void** pItem, EFbxType pValueType) const;
00460     bool    GetLast(void** pItem, EFbxType pValueType) const;
00461 
00462     int     Find(void const* pItem, EFbxType pValueType) const;
00463     int     FindAfter(int pAfterIndex, void const* pItem, EFbxType pValueType) const;
00464     int     FindBefore(int pBeforeIndex, void const* pItem, EFbxType pValueType) const;
00465 
00466     bool    IsEqual(const KFbxLayerElementArray& pArray);
00467 
00468     template <class T> inline int  Add(T const& pItem)                               { return Add((void const*)&pItem, _FbxTypeOf(pItem)); }
00469     template <class T> inline int  InsertAt(int pIndex, T const& pItem)              { return InsertAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00470     template <class T> inline void SetAt(int pIndex, T const& pItem)                 { SetAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00471     template <class T> inline void SetLast(T const& pItem)                           { SetLast((void const*)&pItem, _FbxTypeOf(pItem)); }
00472 
00473     template <class T> inline void RemoveAt(int pIndex, T* pItem)                    { RemoveAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00474     template <class T> inline void RemoveLast(T* pItem)                              { RemoveLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00475     template <class T> inline bool RemoveIt(T* pItem)                                { return RemoveIt((void**)&pItem, _FbxTypeOf(*pItem)); }
00476 
00477     template <class T> inline bool GetAt(int pIndex, T* pItem) const                 { return GetAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00478     template <class T> inline bool GetFirst(T* pItem) const                          { return GetFirst((void**)&pItem, _FbxTypeOf(*pItem)); }
00479     template <class T> inline bool GetLast(T* pItem) const                           { return GetLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00480 
00481     template <class T> inline int Find(T const& pItem) const                         { return Find((void const*)&pItem, _FbxTypeOf(pItem)); }
00482     template <class T> inline int FindAfter(int pAfterIndex, T const& pItem) const   { return FindAfter(pAfterIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00483     template <class T> inline int FindBefore(int pBeforeIndex, T const& pItem) const { return FindBefore(pBeforeIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00484 
00485 
00486     template<typename T> inline void CopyTo(KArrayTemplate<T>& pDst)
00487     {
00488         T src;
00489         T* srcPtr = &src;
00490 
00491         pDst.Clear();
00492         if (mDataType != _FbxTypeOf(src))
00493         {
00494             SetStatus(LockAccessStatus::eUnsupportedDTConversion);
00495             return;
00496         }
00497 
00498         pDst.SetCount(GetCount());
00499         for (int i = 0; i < GetCount(); i++)
00500         {
00501             if (GetAt(i, (void**)&srcPtr, mDataType))
00502             {
00503                 pDst.SetAt(i, src);
00504             }
00505         }
00506         SetStatus(LockAccessStatus::eSuccess);
00507     }
00509 
00510 protected:
00511     void*   GetDataPtr();
00512     void*   GetReference(int pIndex, EFbxType pValueType);
00513     void    GetReferenceTo(int pIndex, void** pRef, EFbxType pValueType);
00514 
00515     inline void SetStatus(LockAccessStatus::ELockAccessStatus pVal) const
00516     {
00517         const_cast<KFbxLayerElementArray*>(this)->mStatus = pVal;
00518     }
00519 
00520             void   SetImplementation(void* pImplementation);
00521     inline  void*  GetImplementation() { return mImplementation; }
00522     virtual void   ConvertDataType(EFbxType pDataType, void** pDataPtr, size_t* pStride);
00523 
00524     EFbxType mDataType;
00525 
00526 private:
00527     LockAccessStatus::ELockAccessStatus mStatus;
00528 
00529     int           mReadLockCount;
00530     bool          mWriteLock;
00531     void*         mImplementation;
00532     size_t        mStride;
00533     int           mDirectLockOn;
00534     bool          mDirectAccessOn;
00535 
00536     KArrayTemplate<void*>   mConvertedData;
00537 
00538 };
00539 
00540 template <typename T>
00541 struct KFbxLayerElementArrayReadLock
00542 {
00543    KFbxLayerElementArrayReadLock(KFbxLayerElementArray& pArray)
00544    : mArray(pArray)
00545    {
00546        mLockedData = mArray.GetLocked((T*)NULL, KFbxLayerElementArray::eREAD_LOCK);
00547    }
00548 
00549    ~KFbxLayerElementArrayReadLock()
00550    {
00551        if( mLockedData )
00552        {
00553            mArray.Release((void **) &mLockedData);
00554        }
00555    }
00556 
00557    const T* GetData() const
00558    {
00559        return mLockedData;
00560    }
00561 
00562 private:
00563     KFbxLayerElementArray&  mArray;
00564     T* mLockedData;
00565 };
00566 
00567 class KFbxLayerElementUserData;
00568 template <class T> class KFbxLayerElementArrayTemplate : public KFbxLayerElementArray
00569 {
00570 public:
00571     KFbxLayerElementArrayTemplate(EFbxType pDataType) :
00572         KFbxLayerElementArray(pDataType)
00573         {
00574         }
00575 
00576     inline int  Add( T const &pItem )                       { return KFbxLayerElementArray::Add(pItem); }
00577     inline int  InsertAt(int pIndex, T const &pItem)        { return KFbxLayerElementArray::InsertAt(pIndex, pItem); }
00578     inline void SetAt(int pIndex, T const &pItem)           { KFbxLayerElementArray::SetAt(pIndex, pItem); }
00579     inline void SetLast( T const &pItem)                    { KFbxLayerElementArray::SetLast(pItem); }
00580 
00581     inline T RemoveAt(int pIndex)                           { T lValue; KFbxLayerElementArray::RemoveAt(pIndex, &lValue); return lValue; }
00582     inline T RemoveLast()                                   { T lValue; KFbxLayerElementArray::RemoveLast(&lValue); return lValue; }
00583     inline bool RemoveIt(T const &pItem)                    { return KFbxLayerElementArray::RemoveIt(&pItem); }
00584 
00585     inline T  GetAt(int pIndex) const                       { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
00586     inline T  GetFirst() const                              { T lValue; KFbxLayerElementArray::GetFirst(&lValue); return lValue; }
00587     inline T  GetLast() const                               { T lValue; KFbxLayerElementArray::GetLast(&lValue); return lValue; }
00588 
00589     inline int Find(T const &pItem)                         { return KFbxLayerElementArray::Find(pItem); }
00590     inline int FindAfter(int pAfterIndex, T const &pItem)   { return KFbxLayerElementArray::FindAfter(pAfterIndex, pItem); }
00591     inline int FindBefore(int pBeforeIndex, T const &pItem) { return KFbxLayerElementArray::FindBefore(pBeforeIndex, pItem); }
00592 
00593     T  operator[](int pIndex) const                         { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; } 
00594 
00595     KFbxLayerElementArray& operator=(const KArrayTemplate<T>& pArrayTemplate)
00596     {
00597         SetStatus(LockAccessStatus::eNoWriteLock);
00598         if (WriteLock())
00599         {
00600             SetCount(pArrayTemplate.GetCount());
00601             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
00602                 SetAt(i, pArrayTemplate.GetAt(i));
00603             WriteUnlock();
00604             SetStatus(LockAccessStatus::eSuccess);
00605         }
00606         return *this;
00607     }
00608 
00609     KFbxLayerElementArrayTemplate<T>& operator=(const KFbxLayerElementArrayTemplate<T>& pArrayTemplate)
00610     {
00611         SetStatus(LockAccessStatus::eNoWriteLock);
00612         if (WriteLock())
00613         {
00614             SetCount(pArrayTemplate.GetCount());
00615             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
00616                 SetAt(i, pArrayTemplate.GetAt(i));
00617             WriteUnlock();
00618             SetStatus(LockAccessStatus::eSuccess);
00619         }
00620         return *this;
00621     }
00622 
00623     K_DEPRECATED       T*   GetArray()          { return (T*)GetDataPtr(); }
00624     K_DEPRECATED const T*   GetArray() const    { return (const T*)(const_cast<KFbxLayerElementArrayTemplate<T> *>(this)->GetDataPtr()); }
00625     K_DEPRECATED T& operator[](int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
00626 
00627 private:
00628     // This one is not the best thing to do, but at least I don't get deprecated calls inside this file.
00629     // Note that KFbxLayerElementUserData is kind of a weird class in the first place anyway. So either
00630     // we clean it up, or we live with this piece of code ;-)
00631     friend class KFbxLayerElementUserData;
00632     T& AsReference(int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
00633 
00634     T dummy;
00635 };
00636 
00637 
00638 extern int RemapIndexArrayTo(KFbxLayerElement* pLayerEl, 
00639                              KFbxLayerElement::EMappingMode pNewMapping, 
00640                              KFbxLayerElementArrayTemplate<int>* pIndexArray);
00641 
00642 
00646 template <class Type> class KFbxLayerElementTemplate : public KFbxLayerElement
00647 {
00648 public:
00653     KFbxLayerElementArrayTemplate<Type>& GetDirectArray() const
00654     { 
00655         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00656         return *mDirectArray; 
00657     }
00658     KFbxLayerElementArrayTemplate<Type>& GetDirectArray()
00659     { 
00660         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00661         return *mDirectArray; 
00662     }
00663 
00668     KFbxLayerElementArrayTemplate<int>& GetIndexArray() const
00669     { 
00670         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00671         return *mIndexArray; 
00672     }
00673     KFbxLayerElementArrayTemplate<int>& GetIndexArray()
00674     { 
00675         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00676         return *mIndexArray; 
00677     }
00678 
00683     bool Clear()
00684     {
00685         bool ret = true;
00686         mDirectArray->Clear();
00687         ret = (mDirectArray->GetStatus() == LockAccessStatus::eSuccess);
00688 
00689         mIndexArray->Clear();
00690         ret |= (mIndexArray->GetStatus() == LockAccessStatus::eSuccess);
00691 
00692         return ret;
00693     }
00694 
00695 public:
00696     bool operator==(const KFbxLayerElementTemplate& pOther) const
00697     {
00698         const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
00699         const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
00700 
00701         bool ret = true;
00702         if( directArray.GetCount() != mDirectArray->GetCount() || 
00703             indexArray.GetCount() != mIndexArray->GetCount() ||
00704             !directArray.ReadLock() || !indexArray.ReadLock() ||
00705             !mDirectArray->ReadLock() || !mIndexArray->ReadLock() )
00706         {
00707             ret = false;
00708         }
00709 
00710         if (ret == true)
00711         {
00712             if( !mIndexArray->IsEqual(indexArray) )
00713                 ret = false;
00714 
00715             if (ret == true)
00716             {
00717                 if( !mDirectArray->IsEqual(directArray) )
00718                     ret = false;
00719             }
00720         }
00721 
00722         directArray.ReadUnlock();
00723         indexArray.ReadUnlock();
00724         mDirectArray->ReadUnlock();
00725         mIndexArray->ReadUnlock();
00726 
00727         if (ret == false)
00728             return false;
00729 
00730         return KFbxLayerElement::operator ==( pOther );
00731     }
00732 
00733     KFbxLayerElementTemplate& operator=( KFbxLayerElementTemplate const& pOther )
00734     {
00735         K_ASSERT(mDirectArray != NULL);
00736         K_ASSERT(mIndexArray != NULL);
00737 
00738         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
00739             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
00740         {
00741             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
00742             *mDirectArray = directArray;
00743         }
00744 
00745         if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
00746             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
00747         {
00748             const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
00749             *mIndexArray = indexArray;
00750         }
00751         
00752         KFbxLayerElement* myself = (KFbxLayerElement*)this;
00753         KFbxLayerElement* myOther = (KFbxLayerElement*)&pOther;
00754         *myself = *myOther;
00755         return *this; 
00756     }
00757 
00766     int RemapIndexTo(KFbxLayerElement::EMappingMode pNewMapping)
00767     {
00768         return RemapIndexArrayTo(this, pNewMapping, mIndexArray);
00769     }
00770 
00772 //
00773 //  WARNING!
00774 //
00775 //  Anything beyond these lines may not be documented accurately and is 
00776 //  subject to change without notice.
00777 //
00779 
00780 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00781 protected:
00782     KFbxLayerElementTemplate() 
00783     {
00784         mDirectArray = NULL;
00785         mIndexArray = NULL;
00786     }
00787 
00788     ~KFbxLayerElementTemplate() 
00789     {
00790         delete mDirectArray;
00791         delete mIndexArray;
00792     }
00793 
00794     virtual void AllocateArrays()
00795     {
00796         mDirectArray = new KFbxLayerElementArrayTemplate<Type>(mType->GetType());
00797         mIndexArray = new KFbxLayerElementArrayTemplate<int>(DTInteger.GetType());
00798     }
00799 
00800 public:
00801     virtual int MemorySize() const
00802     {
00803         int size = KFbxLayerElement::MemorySize();
00804         size += (mDirectArray->GetCount()*sizeof(Type));
00805         size += (mIndexArray->GetCount()*sizeof(int));
00806         return size;
00807     }
00808 
00813     virtual bool ContentWriteTo(KFbxStream& pStream) const
00814     {
00815         void* a;
00816         int s,v;
00817         int count = 0;
00818 
00819         // direct array
00820         count = mDirectArray->GetCount();
00821         s = pStream.Write(&count, sizeof(int)); 
00822         if (s != sizeof(int)) return false;
00823         if (count > 0)
00824         {
00825             a = mDirectArray->GetLocked();
00826             K_ASSERT(a != NULL);
00827             v = count*sizeof(Type);
00828             s = pStream.Write(a, v); 
00829             mDirectArray->Release(&a);
00830             if (s != v) return false;
00831         }
00832 
00833         // index array
00834         count = mIndexArray->GetCount();
00835         s = pStream.Write(&count, sizeof(int)); 
00836         if (s != sizeof(int)) return false;
00837         if (count > 0)
00838         {
00839             a = mIndexArray->GetLocked();
00840             K_ASSERT(a != NULL);
00841             v = count*sizeof(int);
00842             s = pStream.Write(a, v);
00843             mIndexArray->Release(&a);
00844             if (s != v) return false;
00845         }
00846 
00847         return KFbxLayerElement::ContentWriteTo(pStream);
00848     }
00849 
00850     virtual bool ContentReadFrom(const KFbxStream& pStream)
00851     {
00852         void* a;
00853         int s,v;
00854         int count = 0;
00855 
00856         // direct array
00857         s = pStream.Read(&count, sizeof(int)); 
00858         if (s != sizeof(int)) return false;
00859         mDirectArray->Resize(count);
00860         if (count > 0)
00861         {
00862             a = mDirectArray->GetLocked();
00863             K_ASSERT(a != NULL);
00864             v = count*sizeof(Type);
00865             s = pStream.Read(a, v); 
00866             mDirectArray->Release(&a);
00867             if (s != v) return false;
00868         }
00869 
00870         // index array
00871         s = pStream.Read(&count, sizeof(int)); 
00872         if (s != sizeof(int)) return false;
00873         mIndexArray->Resize(count);     
00874         if (count > 0)
00875         {
00876             a = mIndexArray->GetLocked();
00877             K_ASSERT(a != NULL);
00878             v = count*sizeof(int);
00879             s = pStream.Read(a, v);
00880             mIndexArray->Release(&a);
00881             if (s != v) return false;
00882         }
00883         return KFbxLayerElement::ContentReadFrom(pStream);
00884     }
00886 
00887     KFbxLayerElementArrayTemplate<Type>* mDirectArray;
00888     KFbxLayerElementArrayTemplate<int>*  mIndexArray;
00889 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00890 };
00891 
00892 #define CREATE_DECLARE(classDesc) \
00893     static KFbx##classDesc* Create(KFbxLayerContainer* pOwner, char const *pName);
00894 
00898 class KFBX_DLL KFbxLayerElementNormal : public KFbxLayerElementTemplate<KFbxVector4>
00899 {
00900 public:
00901     CREATE_DECLARE(LayerElementNormal);
00902     
00903 protected:
00904     KFbxLayerElementNormal();
00905     ~KFbxLayerElementNormal();
00906 };
00907 
00908 
00912 class KFBX_DLL KFbxLayerElementMaterial : public KFbxLayerElementTemplate<KFbxSurfaceMaterial*>
00913 {
00914 public:
00915     typedef KFbxLayerElementTemplate<KFbxSurfaceMaterial*> ParentClass;
00916 
00917     CREATE_DECLARE(LayerElementMaterial);
00918     
00919     class LayerElementArrayProxy : public KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>
00920     {
00921     public:
00922         typedef KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*> ParentClass;
00923 
00924         LayerElementArrayProxy(EFbxType pType);
00925         void SetContainer( KFbxLayerContainer* pContainer, int pInstance = 0);
00926     };
00927 
00928 
00934     K_DEPRECATED KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray() const
00935     {
00936         return ParentClass::GetDirectArray();
00937     }
00938 
00939     K_DEPRECATED KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray()
00940     {
00941         return ParentClass::GetDirectArray();
00942     }
00943 
00945 //
00946 //  WARNING!
00947 //
00948 //  Anything beyond these lines may not be documented accurately and is 
00949 //  subject to change without notice.
00950 //
00952 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00953 
00954     virtual void AllocateArrays();
00955     virtual void SetOwner( KFbxLayerContainer* pOwner, int pInstance = 0);
00956     virtual void SetInstance( int pInstance ) { SetOwner( mOwner, pInstance ); }
00957 
00958 protected:
00959     KFbxLayerElementMaterial();
00960     ~KFbxLayerElementMaterial();
00961 
00962 #endif //DOXYGEN_SHOULD_SKIP_THIS
00963 }; 
00964 
00968 class KFBX_DLL KFbxLayerElementPolygonGroup : public KFbxLayerElementTemplate<int>
00969 {
00970 public:
00971     CREATE_DECLARE(LayerElementPolygonGroup);
00972     
00973 protected:
00974     KFbxLayerElementPolygonGroup();
00975     ~KFbxLayerElementPolygonGroup();
00976 };
00977 
00981 class KFBX_DLL KFbxLayerElementUV : public KFbxLayerElementTemplate<KFbxVector2>
00982 {
00983 public:
00984     CREATE_DECLARE(LayerElementUV);
00985     
00986 protected:
00987     KFbxLayerElementUV();
00988     ~KFbxLayerElementUV();
00989 };
00990 
00994 class KFBX_DLL KFbxLayerElementVertexColor : public KFbxLayerElementTemplate<KFbxColor>
00995 {
00996 public:
00997     CREATE_DECLARE(LayerElementVertexColor);
00998     
00999 protected:
01000     KFbxLayerElementVertexColor();
01001     ~KFbxLayerElementVertexColor();
01002 };
01003 
01006 const int kNoMapping = -1;
01007 
01015 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, int pIndex, bool* pStatus = NULL);
01016 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus = NULL);
01017 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, const char* pName, bool* pStatus = NULL );
01018 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus = NULL );
01019 
01023 class KFBX_DLL KFbxLayerElementUserData : public KFbxLayerElementTemplate<void*>
01024 {
01025 public:
01026 
01027     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, char const *pName, int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames);
01028     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, KFbxLayerElementUserData const& pOther );
01029 
01035     KFbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL)
01036     {       
01037         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01038         {
01039             if (pStatus) *pStatus = true;
01040             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01041         }
01042         else
01043         {
01044             if( pStatus ) *pStatus = false;
01045             K_ASSERT_MSG_NOW("Index out of bounds");
01046             return (KFbxLayerElementArrayTemplate<void*>*)NULL;
01047         }
01048     }
01049 
01055     KFbxLayerElementArrayTemplate<void*> const* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL) const
01056     {
01057         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01058         {
01059             if (pStatus) *pStatus = true;
01060             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01061         }
01062         else
01063         {
01064             if( pStatus ) *pStatus = false;
01065             K_ASSERT_MSG_NOW("Index out of bounds");
01066             return (KFbxLayerElementArrayTemplate<void*> const*)NULL;
01067         }
01068     }
01069 
01070 
01076     KFbxLayerElementArrayTemplate<void *>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL )
01077     {
01078         KString lName( pName );
01079         for( int i = 0; i < mDataNames.GetCount(); ++i )
01080         {
01081             if( *mDataNames[i] == lName )
01082                 return GetDirectArrayVoid(i, pStatus);
01083         }
01084 
01085         if (pStatus) *pStatus = false;
01086         return (KFbxLayerElementArrayTemplate<void *>*)NULL;
01087     }
01088  
01094     KFbxLayerElementArrayTemplate<void *> const* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL ) const
01095     {
01096         KString lName( pName );
01097         for( int i = 0; i < mDataNames.GetCount(); ++i )
01098         {
01099             if( *mDataNames[i] == lName )
01100                 return GetDirectArrayVoid(i, pStatus);
01101         }
01102 
01103         if (pStatus) *pStatus = false;
01104         return (KFbxLayerElementArrayTemplate<void *> const*)NULL;
01105     }
01106 
01111     KFbxDataType GetDataType( int pIndex ) const
01112     {
01113         if( pIndex < 0 || pIndex >= mDataTypes.GetCount() )
01114             return DTNone;
01115 
01116         return mDataTypes[pIndex];
01117     }
01118 
01123     KFbxDataType GetDataType( const char* pName ) const
01124     {
01125         KString lName( pName );
01126 
01127         for( int i = 0; i < mDataNames.GetCount(); ++i )
01128         {
01129             if( *mDataNames[i] == lName )
01130                 return mDataTypes[i];
01131         }
01132 
01133         return DTNone;
01134     }
01135 
01140     const char* GetDataName( int pIndex ) const
01141     {
01142         if( pIndex >= 0 && pIndex < mDataNames.GetCount() )
01143             return mDataNames[pIndex]->Buffer();
01144 
01145         return NULL;
01146     }
01147 
01151     void ResizeAllDirectArrays( int pSize )
01152     {
01153         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01154         {
01155             switch( mDataTypes[i].GetType() )
01156             {
01157                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).Resize( pSize )  ; break;
01158                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).Resize( pSize )   ; break;
01159                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).Resize( pSize ) ; break;
01160                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).Resize( pSize ); break;
01161                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).Resize( pSize );    break;
01162                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).Resize( pSize );    break;
01163                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).Resize( pSize );    break;  
01164                 default:
01165                     K_ASSERT_MSG_NOW("unknown type" ); break;
01166             }
01167         }
01168     }
01169 
01173     void RemoveFromAllDirectArrays( int pIndex )
01174     {
01175         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01176         {
01177             switch( mDataTypes[i].GetType() )
01178             {
01179                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).RemoveAt( pIndex )  ; break;
01180                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).RemoveAt( pIndex )   ; break;
01181                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).RemoveAt( pIndex ) ; break;
01182                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).RemoveAt( pIndex ); break;
01183                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).RemoveAt( pIndex ); break;
01184                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).RemoveAt( pIndex ); break;
01185                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).RemoveAt( pIndex ); break;  
01186                 default:
01187                     K_ASSERT_MSG_NOW("unknown type" ); break;
01188             }
01189         }
01190     }
01191 
01196     int GetArrayCount( int pIndex ) const 
01197     {
01198         if( pIndex >= 0 && pIndex < GetDirectArray().GetCount() )
01199         {
01200             switch( mDataTypes[pIndex].GetType() )
01201             {
01202                 case eBOOL1:    return KFbxGetDirectArray<bool>(this,pIndex).GetCount();
01203                 case eINTEGER1: return KFbxGetDirectArray<int>(this,pIndex).GetCount();
01204                 case eFLOAT1:   return KFbxGetDirectArray<float>(this,pIndex).GetCount();
01205                 case eDOUBLE1:  return KFbxGetDirectArray<double>(this,pIndex).GetCount();
01206                 //case eDOUBLE3:    return GetDirectArray< fbxDouble3 >(pIndex).GetCount();
01207                 //case eDOUBLE4:    return GetDirectArray< fbxDouble4 >(pIndex).GetCount();
01208                 //case eDOUBLE44:   return GetDirectArray< fbxDouble44>(pIndex).GetCount();
01209                 default:
01210                     K_ASSERT_MSG_NOW("Unknown type" ); break;
01211             }
01212         }
01213 
01214         return -1;
01215     }
01216 
01220     int GetId() const { return mId; }
01221 
01225     int GetDirectArrayCount() const { return GetDirectArray().GetCount(); }
01226 
01231     KFbxLayerElementUserData& operator=( KFbxLayerElementUserData const& pOther )
01232     {
01233         int i;
01234         Clear();
01235 
01236         // Build descriptives.
01237         //
01238         mDataNames.Resize(pOther.mDataNames.GetCount());
01239         for( i = 0; i < pOther.mDataNames.GetCount(); ++i )
01240             mDataNames.SetAt(i,  new KString( *pOther.mDataNames[i] ) );
01241 
01242         mDataTypes.Resize(pOther.mDataTypes.GetCount());
01243         for( i = 0; i < pOther.mDataTypes.GetCount(); ++i )
01244             mDataTypes.SetAt(i, pOther.mDataTypes[i] );
01245 
01246 
01247         Init();
01248         kReference** dummy = NULL;
01249         for( i = 0; i < pOther.GetDirectArrayCount(); ++i )
01250         {
01251             kReference** src = pOther.GetDirectArray().GetLocked(dummy, KFbxLayerElementArray::eREAD_LOCK);
01252             kReference** dst = GetDirectArray().GetLocked(dummy, KFbxLayerElementArray::eREADWRITE_LOCK);
01253 
01254             if (src && dst)
01255             {
01256                 *dst[i] = *src[i];
01257                 /*switch( mDataTypes[i].GetType() )
01258                 {
01259                     case eBOOL1:    ((KArrayTemplate<bool>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<bool>*)pOther.mDirectArray[i]) ); break;
01260                     case eINTEGER1: ((KArrayTemplate<int>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<int>*)pOther.mDirectArray[i]) ); break;
01261                     case eFLOAT1:   ((KArrayTemplate<float>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<float>*)pOther.mDirectArray[i]) ); break;
01262                     case eDOUBLE1:  ((KArrayTemplate<double>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<double>*)pOther.mDirectArray[i]) ); break;
01263                     //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01264                     //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01265                     //case eDOUBLE44:   GetDirectArray< fbxDouble44>(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01266                     default:
01267                         K_ASSERT_MSG_NOW("Unknown type" ); break;
01268                 }*/
01269 
01270                 GetDirectArray().Release((void**)&dst);
01271                 pOther.GetDirectArray().Release((void**)&src);
01272             }
01273             else
01274                 K_ASSERT_MSG_NOW("Unable to get lock");
01275         }
01276 
01277         mId = pOther.mId;
01278 
01279         GetIndexArray() = pOther.GetIndexArray();
01280 
01281         return *this;
01282     }
01283 
01286     void Clear()
01287     {
01288         int i;
01289         const int lCount = GetDirectArray().GetCount();
01290         KFbxLayerElementArray** directArray = NULL;
01291         directArray = GetDirectArray().GetLocked(directArray);
01292         for( i = 0; directArray != NULL && i < lCount; ++i )
01293         {
01294             if( directArray[i] )
01295                 delete directArray[i];
01296         }
01297         GetDirectArray().Release((void**)&directArray);
01298 
01299         for( i = 0; i < mDataNames.GetCount(); ++i )
01300         {
01301             if( mDataNames[i] )
01302             {
01303                 delete mDataNames[i];
01304                 mDataNames[i] = NULL;
01305             }
01306         }
01307         mDataNames.Clear();
01308         mDataTypes.Clear();
01309 
01310         KFbxLayerElementTemplate<void*>::Clear();
01311     }
01312 
01313     virtual int MemorySize() const
01314     {
01315         int size = KFbxLayerElementTemplate<void*>::MemorySize();
01316         size += sizeof(mId);
01317         return size;
01318     }
01319 
01320 protected:
01330     KFbxLayerElementUserData( int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames )
01331         :
01332         mId( pId ),
01333         mDataTypes( pDataTypes )
01334     {
01335         K_ASSERT( pDataTypes.GetCount() == pDataNames.GetCount() );
01336         for( int i = 0; i < pDataNames.GetCount(); ++i )
01337         {
01338             mDataNames.Add( new KString( pDataNames[i] ) );
01339         }
01340     }
01341 
01345     KFbxLayerElementUserData( KFbxLayerElementUserData const& pOther )
01346     {
01347         *this = pOther;
01348     }
01349 
01351     ~KFbxLayerElementUserData()
01352     {
01353         Clear();
01354     }
01355 
01357     virtual void AllocateArrays()
01358     {
01359         KFbxLayerElementTemplate<void*>::AllocateArrays();
01360         Init();
01361     }
01362 
01363 private:
01364     void Init()
01365     {
01366         int i;
01367         GetDirectArray().Resize( mDataTypes.GetCount() );
01368 
01369         // initialize arrays
01370         for( i = 0; i < mDataTypes.GetCount(); ++i )
01371         {
01372             kReference** dst = NULL;
01373             dst = GetDirectArray().GetLocked(dst);
01374             if (dst)
01375             {
01376                 switch( mDataTypes[i].GetType() )
01377                 {
01378                     case eBOOL1:    dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<bool>(mDataTypes[i].GetType()); break;
01379                     case eINTEGER1: dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<int>(mDataTypes[i].GetType());  break;
01380                     case eFLOAT1:   dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<float>(mDataTypes[i].GetType());    break;
01381                     case eDOUBLE1:  dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<double>(mDataTypes[i].GetType());   break;
01382                     //case eDOUBLE3:    mDirectArray[i] = new KArrayTemplate< fbxDouble3 >();   break;  
01383                     //case eDOUBLE4:    mDirectArray[i] = new KArrayTemplate< fbxDouble4 >();   break;
01384                     //case eDOUBLE44:   mDirectArray[i] = new KArrayTemplate< fbxDouble44 >();  break;  
01385                     default:
01386                         K_ASSERT_MSG_NOW("Trying to assign an unknown type" ); break;
01387                 }
01388                 GetDirectArray().Release((void**)&dst);
01389             }
01390         }
01391     }
01392 
01393     int mId;
01394     KArrayTemplate<KFbxDataType> mDataTypes;
01395     KArrayTemplate<KString*> mDataNames;
01396 };
01397 
01405 template <class T>
01406 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,int pIndex, bool* pStatus)
01407 {
01408     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
01409 }
01410 
01418 template <class T>
01419 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus)
01420 {
01421     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
01422 }
01423 
01424 
01432 template <class T>
01433 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,const char* pName, bool* pStatus )
01434 {
01435     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01436 }
01437 
01445 template <class T>
01446 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus )
01447 {
01448     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01449 }
01450 
01451 
01455 class KFBX_DLL KFbxLayerElementSmoothing : public KFbxLayerElementTemplate<int>
01456 {
01457 public:
01458     static KFbxLayerElementSmoothing* Create(KFbxLayerContainer* pOwner, char const *pName);
01459 
01460     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
01461     {
01462         if( pMode != KFbxLayerElement::eDIRECT )
01463         {
01464             K_ASSERT_MSG_NOW( "Smoothing layer elements must be direct mapped" );
01465             return;
01466         }
01467     }
01468 
01469 protected:
01470     KFbxLayerElementSmoothing()
01471     {
01472         mReferenceMode = KFbxLayerElement::eDIRECT;
01473     }
01474 
01475 };
01476 
01479 class KFBX_DLL KFbxLayerElementVisibility : public KFbxLayerElementTemplate<bool>
01480 {
01481 public:
01482     CREATE_DECLARE(LayerElementVisibility);
01483 
01484 protected:
01485     KFbxLayerElementVisibility();
01486     ~KFbxLayerElementVisibility();
01487 };
01488 
01489 typedef class KFBX_DLL KFbxLayerElementTemplate<KFbxTexture*>  KFbxLayerElementTextureBase;
01490 
01494 class KFBX_DLL KFbxLayerElementTexture : public KFbxLayerElementTextureBase
01495 {
01496 
01497 public:
01498     CREATE_DECLARE(LayerElementTexture);
01499 
01507     typedef enum 
01508     {
01509         eTRANSLUCENT,
01510         eADD,
01511         eMODULATE,
01512         eMODULATE2,
01513         eMAXBLEND
01514     } EBlendMode;
01515 
01519     void       SetBlendMode(EBlendMode pBlendMode) { mBlendMode = pBlendMode; }
01520 
01525     void       SetAlpha(double pAlpha)             
01526     { 
01527         mAlpha = pAlpha > 1.0 ? 1.0 : pAlpha;
01528         mAlpha = pAlpha < 0.0 ? 0.0 : pAlpha;
01529     }
01530 
01534     EBlendMode GetBlendMode()                      { return mBlendMode; } 
01535 
01539     double     GetAlpha()                          { return mAlpha; }
01540 
01542 //
01543 //  WARNING!
01544 //
01545 //  Anything beyond these lines may not be documented accurately and is 
01546 //  subject to change without notice.
01547 //
01549 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01550 
01551     virtual int MemorySize() const
01552     {
01553         int size = KFbxLayerElementTextureBase::MemorySize();
01554         size += sizeof(mBlendMode);
01555         size += sizeof(mAlpha);
01556         return size;
01557     }
01558 
01559 protected:
01564     KFbxLayerElementTexture() : mBlendMode(eTRANSLUCENT)
01565     {
01566         mReferenceMode = eINDEX_TO_DIRECT;
01567         mAlpha         = 1.0;
01568     }
01569 
01570 private:
01571     EBlendMode mBlendMode;
01572     double     mAlpha;
01573 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01574 };
01575 
01576 
01604 class KFBX_DLL KFbxLayer
01605 {
01606 
01607 public:
01608 
01613 
01618     KFbxLayerElementNormal* GetNormals();   
01619 
01624     KFbxLayerElementNormal const* GetNormals() const;   
01625 
01629     KFbxLayerElementMaterial* GetMaterials();
01630 
01634     KFbxLayerElementMaterial const* GetMaterials() const;
01635 
01639     KFbxLayerElementPolygonGroup* GetPolygonGroups();
01640 
01644     KFbxLayerElementPolygonGroup const* GetPolygonGroups() const;
01645 
01646 
01650     KFbxLayerElementUV* GetEmissiveUV();
01651 
01655     KFbxLayerElementUV const* GetEmissiveUV() const;
01656 
01660     KFbxLayerElementUV* GetEmissiveFactorUV();
01661 
01665     KFbxLayerElementUV const* GetEmissiveFactorUV() const;
01666 
01670     KFbxLayerElementUV* GetAmbientUV();
01671 
01675     KFbxLayerElementUV const* GetAmbientUV() const;
01676 
01680     KFbxLayerElementUV* GetAmbientFactorUV();
01681 
01685     KFbxLayerElementUV const* GetAmbientFactorUV() const;
01686     
01690     KFbxLayerElementUV* GetDiffuseUV();
01691 
01695     KFbxLayerElementUV const* GetDiffuseUV() const;
01696 
01700     KFbxLayerElementUV* GetDiffuseFactorUV();
01701 
01705     KFbxLayerElementUV const* GetDiffuseFactorUV() const;
01706 
01710     KFbxLayerElementUV* GetSpecularUV();
01711 
01715     KFbxLayerElementUV const* GetSpecularUV() const;
01716 
01720     KFbxLayerElementUV* GetSpecularFactorUV();
01721 
01725     KFbxLayerElementUV const* GetSpecularFactorUV() const;
01726 
01730     KFbxLayerElementUV* GetShininessUV();
01731 
01735     KFbxLayerElementUV const* GetShininessUV() const;
01736 
01740     KFbxLayerElementUV* GetNormalMapUV();
01741 
01745     KFbxLayerElementUV const* GetNormalMapUV() const;
01746 
01750     KFbxLayerElementUV* GetBumpUV();
01751 
01755     KFbxLayerElementUV const* GetBumpUV() const;
01756 
01760     KFbxLayerElementUV* GetTransparentUV();
01761 
01765     KFbxLayerElementUV const* GetTransparentUV() const;
01766 
01770     KFbxLayerElementUV* GetTransparencyFactorUV();
01771 
01775     KFbxLayerElementUV const* GetTransparencyFactorUV() const;
01776 
01780     KFbxLayerElementUV* GetReflectionUV();
01781 
01785     KFbxLayerElementUV const* GetReflectionUV() const;
01786 
01790     KFbxLayerElementUV* GetReflectionFactorUV();
01791 
01795     KFbxLayerElementUV const* GetReflectionFactorUV() const;
01796 
01803     KFbxLayerElementUV* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
01804 
01811     KFbxLayerElementUV const* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
01812 
01813 
01816     int GetUVSetCount() const;
01817     
01820     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetUVSetChannels() const;
01821 
01824     KArrayTemplate<KFbxLayerElementUV const*> GetUVSets() const;
01825 
01830     KFbxLayerElementVertexColor* GetVertexColors();
01831 
01836     KFbxLayerElementVertexColor const* GetVertexColors() const;
01837 
01842     KFbxLayerElementSmoothing* GetSmoothing();
01843 
01848     KFbxLayerElementSmoothing const* GetSmoothing() const;
01849 
01853     KFbxLayerElementUserData* GetUserData();
01854 
01858     KFbxLayerElementUserData const* GetUserData() const;
01859 
01863     KFbxLayerElementVisibility* GetVisibility();
01864 
01868     KFbxLayerElementVisibility const* GetVisibility() const;
01869 
01873     KFbxLayerElementTexture* GetEmissiveTextures();
01874 
01878     KFbxLayerElementTexture const* GetEmissiveTextures() const;
01879 
01883     KFbxLayerElementTexture* GetEmissiveFactorTextures();
01884 
01888     KFbxLayerElementTexture const* GetEmissiveFactorTextures() const;
01889 
01893     KFbxLayerElementTexture* GetAmbientTextures();
01894 
01898     KFbxLayerElementTexture const* GetAmbientTextures() const;
01899 
01903     KFbxLayerElementTexture* GetAmbientFactorTextures();
01904 
01908     KFbxLayerElementTexture const* GetAmbientFactorTextures() const;
01909     
01913     KFbxLayerElementTexture* GetDiffuseTextures();
01914 
01918     KFbxLayerElementTexture const* GetDiffuseTextures() const;
01919 
01923     KFbxLayerElementTexture* GetDiffuseFactorTextures();
01924 
01928     KFbxLayerElementTexture const* GetDiffuseFactorTextures() const;
01929 
01933     KFbxLayerElementTexture* GetSpecularTextures();
01934 
01938     KFbxLayerElementTexture const* GetSpecularTextures() const;
01939 
01943     KFbxLayerElementTexture* GetSpecularFactorTextures();
01944 
01948     KFbxLayerElementTexture const* GetSpecularFactorTextures() const;
01949 
01953     KFbxLayerElementTexture* GetShininessTextures();
01954 
01958     KFbxLayerElementTexture const* GetShininessTextures() const;
01959 
01963     KFbxLayerElementTexture* GetNormalMapTextures();
01964 
01968     KFbxLayerElementTexture const* GetNormalMapTextures() const;
01969 
01973     KFbxLayerElementTexture* GetBumpTextures();
01974 
01978     KFbxLayerElementTexture const* GetBumpTextures() const;
01979 
01983     KFbxLayerElementTexture* GetTransparentTextures();
01984 
01988     KFbxLayerElementTexture const* GetTransparentTextures() const;
01989 
01993     KFbxLayerElementTexture* GetTransparencyFactorTextures();
01994 
01998     KFbxLayerElementTexture const* GetTransparencyFactorTextures() const;
01999 
02003     KFbxLayerElementTexture* GetReflectionTextures();
02004 
02008     KFbxLayerElementTexture const* GetReflectionTextures() const;
02009 
02013     KFbxLayerElementTexture* GetReflectionFactorTextures();
02014 
02018     KFbxLayerElementTexture const* GetReflectionFactorTextures() const;
02019 
02024     KFbxLayerElementTexture* GetTextures(KFbxLayerElement::ELayerElementType pType);
02025 
02030     KFbxLayerElementTexture const* GetTextures(KFbxLayerElement::ELayerElementType pType) const;
02031 
02036     void SetTextures(KFbxLayerElement::ELayerElementType pType, KFbxLayerElementTexture* pTextures);
02037 
02066     KFbxLayerElement* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02067 
02096     KFbxLayerElement const* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false) const;
02097 
02102     void SetNormals(KFbxLayerElementNormal* pNormals);
02103 
02107     void SetMaterials(KFbxLayerElementMaterial* pMaterials);
02108 
02112     void SetPolygonGroups(KFbxLayerElementPolygonGroup* pPolygonGroups);
02113 
02120     void SetUVs(KFbxLayerElementUV* pUVs, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02121 
02126     void SetVertexColors (KFbxLayerElementVertexColor* pVertexColors);
02127 
02132     void SetSmoothing (KFbxLayerElementSmoothing* pSmoothing);
02133 
02137     void SetUserData (KFbxLayerElementUserData* pUserData);
02138 
02142     void SetVisibility( KFbxLayerElementVisibility* pVisibility );
02143 
02147     void SetEmissiveTextures(KFbxLayerElementTexture* pTextures);
02148 
02152     void SetEmissiveFactorTextures(KFbxLayerElementTexture* pTextures);
02153 
02157     void SetAmbientTextures(KFbxLayerElementTexture* pTextures);
02158 
02162     void SetAmbientFactorTextures(KFbxLayerElementTexture* pTextures);
02163 
02167     void SetDiffuseTextures(KFbxLayerElementTexture* pTextures);
02168 
02172     void SetDiffuseFactorTextures(KFbxLayerElementTexture* pTextures);
02173 
02177     void SetSpecularTextures(KFbxLayerElementTexture* pTextures);
02178 
02182     void SetSpecularFactorTextures(KFbxLayerElementTexture* pTextures);
02183 
02187     void SetShininessTextures(KFbxLayerElementTexture* pTextures);
02188 
02192     void SetNormalMapTextures(KFbxLayerElementTexture* pTextures);
02193 
02197     void SetBumpTextures(KFbxLayerElementTexture* pTextures);
02198 
02202     void SetTransparentTextures(KFbxLayerElementTexture* pTextures);
02203 
02207     void SetTransparencyFactorTextures(KFbxLayerElementTexture* pTextures);
02208 
02212     void SetReflectionTextures(KFbxLayerElementTexture* pTextures);
02213 
02217     void SetReflectionFactorTextures(KFbxLayerElementTexture* pTextures);
02218 
02219 
02227     KFbxLayerElement* CreateLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02228 
02233     void Clone(KFbxLayer const& pSrcLayer, KFbxSdkManager* pSdkManager);    
02234     
02236     //KFbxLayer& operator=(KFbxLayer const& pSrcLayer); 
02238     
02240 //
02241 //  WARNING!
02242 //
02243 //  Anything beyond these lines may not be documented accurately and is 
02244 //  subject to change without notice.
02245 //
02247 
02248 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02249 protected:
02251     KFbxLayer& operator=(KFbxLayer const& pSrcLayer);   
02253 private:
02254 
02255     KFbxLayer(KFbxLayerContainer& pOwner);
02256     virtual ~KFbxLayer();
02257 
02258     void Clear();
02259 
02260     KFbxLayerContainer& mOwner;
02261 
02262     KFbxLayerElementNormal*       mNormals;
02263     KFbxLayerElementMaterial*     mMaterials;
02264     KFbxLayerElementPolygonGroup* mPolygonGroups;
02265     KFbxLayerElementUV*           mUVs; 
02266     KFbxLayerElementVertexColor*  mVertexColors;
02267     KFbxLayerElementSmoothing*    mSmoothing;
02268     KFbxLayerElementUserData*     mUserData;
02269     KFbxLayerElementVisibility*   mVisibility;
02270 
02271     KFbxLayerElementUV*      mEmissiveUV;
02272     KFbxLayerElementUV*      mEmissiveFactorUV;
02273     KFbxLayerElementUV*      mAmbientUV;
02274     KFbxLayerElementUV*      mAmbientFactorUV;
02275     KFbxLayerElementUV*      mDiffuseFactorUV;
02276     KFbxLayerElementUV*      mSpecularUV;
02277     KFbxLayerElementUV*      mSpecularFactorUV;
02278     KFbxLayerElementUV*      mShininessUV;
02279     KFbxLayerElementUV*      mNormalMapUV;
02280     KFbxLayerElementUV*      mBumpUV;
02281     KFbxLayerElementUV*      mTransparentUV;
02282     KFbxLayerElementUV*      mTransparencyFactorUV;
02283     KFbxLayerElementUV*      mReflectionUV;
02284     KFbxLayerElementUV*      mReflectionFactorUV;
02285 
02286 
02287     KFbxLayerElementTexture*      mEmissiveTextures;
02288     KFbxLayerElementTexture*      mEmissiveFactorTextures;
02289     KFbxLayerElementTexture*      mAmbientTextures;
02290     KFbxLayerElementTexture*      mAmbientFactorTextures;
02291     KFbxLayerElementTexture*      mDiffuseTextures;
02292     KFbxLayerElementTexture*      mDiffuseFactorTextures;
02293     KFbxLayerElementTexture*      mSpecularTextures;
02294     KFbxLayerElementTexture*      mSpecularFactorTextures;
02295     KFbxLayerElementTexture*      mShininessTextures;
02296     KFbxLayerElementTexture*      mNormalMapTextures;
02297     KFbxLayerElementTexture*      mBumpTextures;
02298     KFbxLayerElementTexture*      mTransparentTextures;
02299     KFbxLayerElementTexture*      mTransparencyFactorTextures;
02300     KFbxLayerElementTexture*      mReflectionTextures;
02301     KFbxLayerElementTexture*      mReflectionFactorTextures;
02302 
02303     friend class KFbxLayerContainer;
02304 
02305 public:
02310         bool ContentWriteTo(KFbxStream& pStream) const;
02311         bool ContentReadFrom(const KFbxStream& pStream);
02313     virtual int MemoryUsage() const;
02314 
02315 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02316 };
02317 
02318 #undef CREATE_DECLARE
02319 #include <fbxfilesdk/fbxfilesdk_nsend.h>
02320 
02321 #endif // FBXFILESDK_KFBXPLUGINS_KFBXLAYER_H
02322