FBX SDK Reference Guide: kfbxlayer.h Source File
Go to the documentation of this file.
00001 
00004 #ifndef _FBXSDK_LAYER_H_
00005 #define _FBXSDK_LAYER_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 <kaydaradef.h>
00043 #ifndef KFBX_DLL 
00044     #define KFBX_DLL K_DLLIMPORT
00045 #endif
00046 
00047 #include <kaydara.h>
00048 
00049 #include <klib/kstring.h>
00050 #include <klib/karrayul.h>
00051 #include <klib/kdebug.h>
00052 
00053 #ifndef MB_FBXSDK
00054 #include <kbaselib_nsuse.h>
00055 #endif
00056 
00057 #include <kfbxmath/kfbxvector2.h>
00058 #include <kfbxmath/kfbxvector4.h>
00059 #include <kfbxplugins/kfbxcolor.h>
00060 #include <kfbxplugins/kfbxdatatypes.h>
00061 #include <kfbxplugins/kfbxstream.h>
00062 
00063 #include <fbxfilesdk_nsbegin.h>
00064 
00065 class KFbxTexture;
00066 class KFbxSurfaceMaterial;
00067 class KFbxSdkManager;
00068 
00069 class KFbxGeometryBase;
00070 class KFbxLayer;
00071 class KFbxLayerContainer;
00072 class KFbxMesh;
00073 class KFbxNode;
00074 class KFbxReader3DS;
00075 class KFbxReaderFbx;
00076 class KFbxReaderFbx6;
00077 class KFbxReaderObj;
00078 
00079 //class KFbxReaderCollada;
00080 
00081 
00087 class KFBX_DLL KFbxLayerElement
00088 {
00089 
00090 public:
00091 
00119     typedef enum 
00120     {
00121         eUNDEFINED,
00122         eNORMAL,
00123         eMATERIAL,
00124         eDIFFUSE_TEXTURES,
00125         ePOLYGON_GROUP,
00126         eUV,
00127         eVERTEX_COLOR,
00128         eSMOOTHING,
00129         eUSER_DATA,
00130         eVISIBILITY,
00131         eEMISSIVE_TEXTURES,
00132         eEMISSIVE_FACTOR_TEXTURES,
00133         eAMBIENT_TEXTURES,
00134         eAMBIENT_FACTOR_TEXTURES,
00135         eDIFFUSE_FACTOR_TEXTURES,
00136         eSPECULAR_TEXTURES,
00137         eNORMALMAP_TEXTURES,
00138         eSPECULAR_FACTOR_TEXTURES,
00139         eSHININESS_TEXTURES,
00140         eBUMP_TEXTURES,
00141         eTRANSPARENT_TEXTURES,
00142         eTRANSPARENCY_FACTOR_TEXTURES,
00143         eREFLECTION_TEXTURES,
00144         eREFLECTION_FACTOR_TEXTURES,
00145         eLAST_ELEMENT_TYPE
00146     } ELayerElementType;
00147 
00158     typedef enum 
00159     {
00160         eNONE,
00161         eBY_CONTROL_POINT,
00162         eBY_POLYGON_VERTEX,
00163         eBY_POLYGON,
00164         eBY_EDGE,
00165         eALL_SAME
00166     } EMappingMode;
00167 
00181     typedef enum 
00182     {
00183         eDIRECT,
00184         eINDEX,
00185         eINDEX_TO_DIRECT
00186     } EReferenceMode;
00187 
00188     
00192     void SetMappingMode(EMappingMode pMappingMode) { mMappingMode = pMappingMode; }
00193 
00197     void SetReferenceMode(EReferenceMode pReferenceMode) { mReferenceMode = pReferenceMode; }
00198 
00202     EMappingMode GetMappingMode() const { return mMappingMode; }
00203 
00207     EReferenceMode GetReferenceMode() const { return mReferenceMode; }
00208 
00212     void SetName(const char* pName) { mName = KString(pName); }
00213 
00217     const char* GetName() const { return ((KFbxLayerElement*)this)->mName.Buffer(); }
00218 
00219     bool operator == (const KFbxLayerElement& pOther) const
00220     {
00221         return (mName == pOther.mName) && 
00222                (mMappingMode == pOther.mMappingMode) &&
00223                (mReferenceMode == pOther.mReferenceMode);
00224     }
00225 
00226     KFbxLayerElement& operator=( KFbxLayerElement const& pOther )
00227     {
00228         mMappingMode = pOther.mMappingMode;
00229         mReferenceMode = pOther.mReferenceMode;
00230         // name, type and owner should not be copied because they are
00231         // initialized when this object is created
00232         return *this;
00233     }
00234 
00237     void Destroy();
00238 
00240 //
00241 //  WARNING!
00242 //
00243 //  Anything beyond these lines may not be documented accurately and is 
00244 //  subject to change without notice.
00245 //
00247 
00248 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00249     void SetType(KFbxDataType* pType) { mType = pType; }
00250     const KFbxLayerContainer* GetOwner() const { return mOwner; }
00251 
00252 protected:
00253     KFbxLayerElement() 
00254         : mMappingMode(eNONE)
00255         , mReferenceMode(eDIRECT)
00256         , mName("")
00257         , mOwner(NULL)
00258     {
00259     }
00260     
00261     virtual ~KFbxLayerElement()
00262     {
00263     }
00264 
00265     EMappingMode mMappingMode;
00266     EReferenceMode mReferenceMode;
00267 
00268     KString mName;
00269     KFbxDataType* mType;
00270     KFbxLayerContainer* mOwner;
00271 
00272     void Destruct() { delete this; }
00273     virtual void SetOwner(KFbxLayerContainer* pOwner);
00274 
00275     friend class KFbxLayerContainer;
00276 
00277 public:
00282     virtual int MemorySize() const { return 0; }
00283 
00288     virtual bool ContentWriteTo(KFbxStream& pStream) const;
00289     virtual bool ContentReadFrom(const KFbxStream& pStream);
00291 
00292 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00293 };
00294 
00299 class KFBX_DLL LockAccessStatus
00300 {
00301 public:
00313     typedef enum {
00314         eSuccess,
00315         eUnsupportedDTConversion,
00316         eCorruptedCopyback,
00317         eBadValue,
00318         eLockMismatch,
00319         eNoWriteLock,
00320         eNoReadLock,
00321         eNotOwner,
00322         eDirectLockExist
00323     } ELockAccessStatus;
00324 };
00325 
00330 class KFBX_DLL KFbxLayerElementArray
00331 {
00332 public:
00337 
00338     KFbxLayerElementArray(EFbxType pDataType);
00340     virtual ~KFbxLayerElementArray();
00342 
00347 
00349     inline                                void ClearStatus()     { mStatus = LockAccessStatus::eSuccess; }
00350 
00352     inline LockAccessStatus::ELockAccessStatus GetStatus() const { return mStatus; }
00354 
00359 
00363     inline bool IsWriteLocked() const { return mWriteLock; };
00364 
00368     inline int  GetReadLockCount() const { return mReadLockCount; }
00370 
00373     bool    IsInUse() const;
00374 
00378     int     ReadLock() const;
00379 
00383     int     ReadUnlock() const;
00384 
00389     bool    WriteLock() const;
00390 
00393     void    WriteUnlock() const;
00394 
00399     bool    ReadWriteLock() const;
00400 
00403     void    ReadWriteUnlock() const;
00404 
00405 
00406     // Data access
00407     typedef enum {
00408         eREAD_LOCK = 1,
00409         eWRITE_LOCK = 2,
00410         eREADWRITE_LOCK = 3
00411     } ELockMode;
00412 
00425     virtual void*   GetLocked(ELockMode pLockMode, EFbxType pDataType);
00426     void*   GetLocked(ELockMode pLockMode=eREADWRITE_LOCK) { return GetLocked(pLockMode, mDataType); }
00427     template <class T> inline T* GetLocked(T* dummy=NULL, ELockMode pLockMode=eREADWRITE_LOCK) {T v; return (T*)GetLocked(pLockMode, _FbxTypeOf(v)); }
00428 
00439     virtual void   Release(void** pDataPtr, EFbxType pDataType);
00440     void   Release(void** pDataPtr) { Release(pDataPtr, mDataType); }
00441     template <class T> inline void Release(T** pDataPtr, T* dummy) { Release((void**)pDataPtr, _FbxTypeOf(*dummy)); }
00442 
00445     virtual size_t GetStride() const;
00446 
00451     int     GetCount() const;
00452     void    SetCount(int pCount);
00453     void    Clear();
00454     void    Resize(int pItemCount);
00455     void    AddMultiple(int pItemCount);
00456 
00457     int     Add(void const* pItem, EFbxType pValueType);
00458     int     InsertAt(int pIndex, void const* pItem, EFbxType pValueType);
00459     void    SetAt(int pIndex, void const* pItem, EFbxType pValueType);
00460     void    SetLast(void const* pItem, EFbxType pValueType);
00461 
00462     void    RemoveAt(int pIndex, void** pItem, EFbxType pValueType);
00463     void    RemoveLast(void** pItem, EFbxType pValueType);
00464     bool    RemoveIt(void** pItem, EFbxType pValueType);
00465 
00466     bool    GetAt(int pIndex, void** pItem, EFbxType pValueType) const;
00467     bool    GetFirst(void** pItem, EFbxType pValueType) const;
00468     bool    GetLast(void** pItem, EFbxType pValueType) const;
00469 
00470     int     Find(void const* pItem, EFbxType pValueType) const;
00471     int     FindAfter(int pAfterIndex, void const* pItem, EFbxType pValueType) const;
00472     int     FindBefore(int pBeforeIndex, void const* pItem, EFbxType pValueType) const;
00473 
00474     bool    IsEqual(const KFbxLayerElementArray& pArray);
00475 
00476     template <class T> inline int  Add(T const& pItem)                               { return Add((void const*)&pItem, _FbxTypeOf(pItem)); }
00477     template <class T> inline int  InsertAt(int pIndex, T const& pItem)              { return InsertAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00478     template <class T> inline void SetAt(int pIndex, T const& pItem)                 { SetAt(pIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00479     template <class T> inline void SetLast(T const& pItem)                           { SetLast((void const*)&pItem, _FbxTypeOf(pItem)); }
00480 
00481     template <class T> inline void RemoveAt(int pIndex, T* pItem)                    { RemoveAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00482     template <class T> inline void RemoveLast(T* pItem)                              { RemoveLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00483     template <class T> inline bool RemoveIt(T* pItem)                                { return RemoveIt((void**)&pItem, _FbxTypeOf(*pItem)); }
00484 
00485     template <class T> inline bool GetAt(int pIndex, T* pItem) const                 { return GetAt(pIndex, (void**)&pItem, _FbxTypeOf(*pItem)); }
00486     template <class T> inline bool GetFirst(T* pItem) const                          { return GetFirst((void**)&pItem, _FbxTypeOf(*pItem)); }
00487     template <class T> inline bool GetLast(T* pItem) const                           { return GetLast((void**)&pItem, _FbxTypeOf(*pItem)); }
00488 
00489     template <class T> inline int Find(T const& pItem) const                         { return Find((void const*)&pItem, _FbxTypeOf(pItem)); }
00490     template <class T> inline int FindAfter(int pAfterIndex, T const& pItem) const   { return FindAfter(pAfterIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00491     template <class T> inline int FindBefore(int pBeforeIndex, T const& pItem) const { return FindBefore(pBeforeIndex, (void const*)&pItem, _FbxTypeOf(pItem)); }
00492 
00493 
00494     template<typename T> inline void CopyTo(KArrayTemplate<T>& pDst)
00495     {
00496         T src;
00497         T* srcPtr = &src;
00498 
00499         pDst.Clear();
00500         if (mDataType != _FbxTypeOf(src))
00501         {
00502             SetStatus(LockAccessStatus::eUnsupportedDTConversion);
00503             return;
00504         }
00505 
00506         pDst.SetCount(GetCount());
00507         for (int i = 0; i < GetCount(); i++)
00508         {
00509             if (GetAt(i, (void**)&srcPtr, mDataType))
00510             {
00511                 pDst.SetAt(i, src);
00512             }
00513         }
00514         SetStatus(LockAccessStatus::eSuccess);
00515     }
00517 
00518 protected:
00519     void*   GetDataPtr();
00520     void*   GetReference(int pIndex, EFbxType pValueType);
00521     void    GetReferenceTo(int pIndex, void** pRef, EFbxType pValueType);
00522 
00523     inline void SetStatus(LockAccessStatus::ELockAccessStatus pVal) const
00524     {
00525         const_cast<KFbxLayerElementArray*>(this)->mStatus = pVal;
00526     }
00527 
00528             void   SetImplementation(void* pImplementation);
00529     inline  void*  GetImplementation() { return mImplementation; }
00530     virtual void   ConvertDataType(EFbxType pDataType, void** pDataPtr, size_t* pStride);
00531 
00532     EFbxType mDataType;
00533 
00534 private:
00535     LockAccessStatus::ELockAccessStatus mStatus;
00536 
00537     int           mReadLockCount;
00538     bool          mWriteLock;
00539     void*         mImplementation;
00540     size_t        mStride;
00541     int           mDirectLockOn;
00542     bool          mDirectAccessOn;
00543 
00544     KArrayTemplate<void*>   mConvertedData;
00545 
00546 };
00547 
00548 template <typename T>
00549 struct KFbxLayerElementArrayReadLock
00550 {
00551    KFbxLayerElementArrayReadLock(KFbxLayerElementArray& pArray)
00552    : mArray(pArray)
00553    {
00554        mLockedData = mArray.GetLocked((T*)NULL, KFbxLayerElementArray::eREAD_LOCK);
00555    }
00556 
00557    ~KFbxLayerElementArrayReadLock()
00558    {
00559        if( mLockedData )
00560        {
00561            mArray.Release((void **) &mLockedData);
00562        }
00563    }
00564 
00565    const T* GetData() const
00566    {
00567        return mLockedData;
00568    }
00569 
00570 private:
00571     KFbxLayerElementArray&  mArray;
00572     T* mLockedData;
00573 };
00574 
00575 class KFbxLayerElementUserData;
00576 template <class T> class KFbxLayerElementArrayTemplate : public KFbxLayerElementArray
00577 {
00578 public:
00579     KFbxLayerElementArrayTemplate(EFbxType pDataType) :
00580         KFbxLayerElementArray(pDataType)
00581         {
00582         }
00583 
00584     inline int  Add( T const &pItem )                       { return KFbxLayerElementArray::Add(pItem); }
00585     inline int  InsertAt(int pIndex, T const &pItem)        { return KFbxLayerElementArray::InsertAt(pIndex, pItem); }
00586     inline void SetAt(int pIndex, T const &pItem)           { KFbxLayerElementArray::SetAt(pIndex, pItem); }
00587     inline void SetLast( T const &pItem)                    { KFbxLayerElementArray::SetLast(pItem); }
00588 
00589     inline T RemoveAt(int pIndex)                           { T lValue; KFbxLayerElementArray::RemoveAt(pIndex, &lValue); return lValue; }
00590     inline T RemoveLast()                                   { T lValue; KFbxLayerElementArray::RemoveLast(&lValue); return lValue; }
00591     inline bool RemoveIt(T const &pItem)                    { return KFbxLayerElementArray::RemoveIt(&pItem); }
00592 
00593     inline T  GetAt(int pIndex) const                       { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
00594     inline T  GetFirst() const                              { T lValue; KFbxLayerElementArray::GetFirst(&lValue); return lValue; }
00595     inline T  GetLast() const                               { T lValue; KFbxLayerElementArray::GetLast(&lValue); return lValue; }
00596 
00597     inline int Find(T const &pItem)                         { return KFbxLayerElementArray::Find(pItem); }
00598     inline int FindAfter(int pAfterIndex, T const &pItem)   { return KFbxLayerElementArray::FindAfter(pAfterIndex, pItem); }
00599     inline int FindBefore(int pBeforeIndex, T const &pItem) { return KFbxLayerElementArray::FindBefore(pBeforeIndex, pItem); }
00600 
00601     T  operator[](int pIndex) const                         { T lValue; KFbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; } 
00602 
00603     KFbxLayerElementArray& operator=(const KArrayTemplate<T>& pArrayTemplate)
00604     {
00605         SetStatus(LockAccessStatus::eNoWriteLock);
00606         if (WriteLock())
00607         {
00608             SetCount(pArrayTemplate.GetCount());
00609             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
00610                 SetAt(i, pArrayTemplate.GetAt(i));
00611             WriteUnlock();
00612             SetStatus(LockAccessStatus::eSuccess);
00613         }
00614         return *this;
00615     }
00616 
00617     KFbxLayerElementArrayTemplate<T>& operator=(const KFbxLayerElementArrayTemplate<T>& pArrayTemplate)
00618     {
00619         SetStatus(LockAccessStatus::eNoWriteLock);
00620         if (WriteLock())
00621         {
00622             SetCount(pArrayTemplate.GetCount());
00623             for (int i = 0; i < pArrayTemplate.GetCount(); i++)
00624                 SetAt(i, pArrayTemplate.GetAt(i));
00625             WriteUnlock();
00626             SetStatus(LockAccessStatus::eSuccess);
00627         }
00628         return *this;
00629     }
00630 
00631     K_DEPRECATED       T*   GetArray()          { return (T*)GetDataPtr(); }
00632     K_DEPRECATED const T*   GetArray() const    { return (const T*)(const_cast<KFbxLayerElementArrayTemplate<T> *>(this)->GetDataPtr()); }
00633     K_DEPRECATED T& operator[](int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
00634 
00635 private:
00636     // This one is not the best thing to do, but at least I don't get deprecated calls inside this file.
00637     // Note that KFbxLayerElementUserData is kind of a weird class in the first place anyway. So either
00638     // we clean it up, or we live with this piece of code ;-)
00639     friend class KFbxLayerElementUserData;
00640     T& AsReference(int pIndex)      { T* v = (T*)KFbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
00641 
00642     T dummy;
00643 };
00644 
00645 
00646 extern int RemapIndexArrayTo(KFbxLayerElement* pLayerEl, 
00647                              KFbxLayerElement::EMappingMode pNewMapping, 
00648                              KFbxLayerElementArrayTemplate<int>* pIndexArray);
00649 
00650 
00654 template <class Type> class KFbxLayerElementTemplate : public KFbxLayerElement
00655 {
00656 public:
00661     KFbxLayerElementArrayTemplate<Type>& GetDirectArray() const
00662     { 
00663         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00664         return *mDirectArray; 
00665     }
00666     KFbxLayerElementArrayTemplate<Type>& GetDirectArray()
00667     { 
00668         K_ASSERT(mReferenceMode == KFbxLayerElement::eDIRECT || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00669         return *mDirectArray; 
00670     }
00671 
00676     KFbxLayerElementArrayTemplate<int>& GetIndexArray() const
00677     { 
00678         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00679         return *mIndexArray; 
00680     }
00681     KFbxLayerElementArrayTemplate<int>& GetIndexArray()
00682     { 
00683         K_ASSERT(mReferenceMode == KFbxLayerElement::eINDEX || mReferenceMode == KFbxLayerElement::eINDEX_TO_DIRECT);
00684         return *mIndexArray; 
00685     }
00686 
00691     bool Clear()
00692     {
00693         bool ret = true;
00694         mDirectArray->Clear();
00695         ret = (mDirectArray->GetStatus() == LockAccessStatus::eSuccess);
00696 
00697         mIndexArray->Clear();
00698         ret |= (mIndexArray->GetStatus() == LockAccessStatus::eSuccess);
00699 
00700         return ret;
00701     }
00702 
00703 public:
00704     bool operator==(const KFbxLayerElementTemplate& pOther) const
00705     {
00706         const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
00707         const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
00708 
00709         bool ret = true;
00710         if( directArray.GetCount() != mDirectArray->GetCount() || 
00711             indexArray.GetCount() != mIndexArray->GetCount() ||
00712             !directArray.ReadLock() || !indexArray.ReadLock() ||
00713             !mDirectArray->ReadLock() || !mIndexArray->ReadLock() )
00714         {
00715             ret = false;
00716         }
00717 
00718         if (ret == true)
00719         {
00720             if( !mIndexArray->IsEqual(indexArray) )
00721                 ret = false;
00722 
00723             if (ret == true)
00724             {
00725                 if( !mDirectArray->IsEqual(directArray) )
00726                     ret = false;
00727             }
00728         }
00729 
00730         directArray.ReadUnlock();
00731         indexArray.ReadUnlock();
00732         mDirectArray->ReadUnlock();
00733         mIndexArray->ReadUnlock();
00734 
00735         if (ret == false)
00736             return false;
00737 
00738         return KFbxLayerElement::operator ==( pOther );
00739     }
00740 
00741     KFbxLayerElementTemplate& operator=( KFbxLayerElementTemplate const& pOther )
00742     {
00743         K_ASSERT(mDirectArray != NULL);
00744         K_ASSERT(mIndexArray != NULL);
00745 
00746         if (pOther.GetReferenceMode() == KFbxLayerElement::eDIRECT || 
00747             pOther.GetReferenceMode() == KFbxLayerElement::eINDEX_TO_DIRECT)
00748         {
00749             const KFbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
00750             *mDirectArray = directArray;
00751         }
00752 
00753         if (pOther.GetReferenceMode() == KFbxLayerElement::eINDEX || 
00754             pOther.GetReferenceMode()  == KFbxLayerElement::eINDEX_TO_DIRECT)
00755         {
00756             const KFbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
00757             *mIndexArray = indexArray;
00758         }
00759         
00760         KFbxLayerElement* myself = (KFbxLayerElement*)this;
00761         KFbxLayerElement* myOther = (KFbxLayerElement*)&pOther;
00762         *myself = *myOther;
00763         return *this; 
00764     }
00765 
00774     int RemapIndexTo(KFbxLayerElement::EMappingMode pNewMapping)
00775     {
00776         return RemapIndexArrayTo(this, pNewMapping, mIndexArray);
00777     }
00778 
00780 //
00781 //  WARNING!
00782 //
00783 //  Anything beyond these lines may not be documented accurately and is 
00784 //  subject to change without notice.
00785 //
00787 
00788 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00789 protected:
00790     KFbxLayerElementTemplate() 
00791     {
00792         mDirectArray = NULL;
00793         mIndexArray = NULL;
00794     }
00795 
00796     ~KFbxLayerElementTemplate() 
00797     {
00798         delete mDirectArray;
00799         delete mIndexArray;
00800     }
00801 
00802     virtual void AllocateArrays()
00803     {
00804         mDirectArray = new KFbxLayerElementArrayTemplate<Type>(mType->GetType());
00805         mIndexArray = new KFbxLayerElementArrayTemplate<int>(DTInteger.GetType());
00806     }
00807 
00808 public:
00809     virtual int MemorySize() const
00810     {
00811         int size = KFbxLayerElement::MemorySize();
00812         size += (mDirectArray->GetCount()*sizeof(Type));
00813         size += (mIndexArray->GetCount()*sizeof(int));
00814         return size;
00815     }
00816 
00821     virtual bool ContentWriteTo(KFbxStream& pStream) const
00822     {
00823         void* a;
00824         int s,v;
00825         int count = 0;
00826 
00827         // direct array
00828         count = mDirectArray->GetCount();
00829         s = pStream.Write(&count, sizeof(int)); 
00830         if (s != sizeof(int)) return false;
00831         if (count > 0)
00832         {
00833             a = mDirectArray->GetLocked();
00834             K_ASSERT(a != NULL);
00835             v = count*sizeof(Type);
00836             s = pStream.Write(a, v); 
00837             mDirectArray->Release(&a);
00838             if (s != v) return false;
00839         }
00840 
00841         // index array
00842         count = mIndexArray->GetCount();
00843         s = pStream.Write(&count, sizeof(int)); 
00844         if (s != sizeof(int)) return false;
00845         if (count > 0)
00846         {
00847             a = mIndexArray->GetLocked();
00848             K_ASSERT(a != NULL);
00849             v = count*sizeof(int);
00850             s = pStream.Write(a, v);
00851             mIndexArray->Release(&a);
00852             if (s != v) return false;
00853         }
00854 
00855         return KFbxLayerElement::ContentWriteTo(pStream);
00856     }
00857 
00858     virtual bool ContentReadFrom(const KFbxStream& pStream)
00859     {
00860         void* a;
00861         int s,v;
00862         int count = 0;
00863 
00864         // direct array
00865         s = pStream.Read(&count, sizeof(int)); 
00866         if (s != sizeof(int)) return false;
00867         mDirectArray->Resize(count);
00868         if (count > 0)
00869         {
00870             a = mDirectArray->GetLocked();
00871             K_ASSERT(a != NULL);
00872             v = count*sizeof(Type);
00873             s = pStream.Read(a, v); 
00874             mDirectArray->Release(&a);
00875             if (s != v) return false;
00876         }
00877 
00878         // index array
00879         s = pStream.Read(&count, sizeof(int)); 
00880         if (s != sizeof(int)) return false;
00881         mIndexArray->Resize(count);     
00882         if (count > 0)
00883         {
00884             a = mIndexArray->GetLocked();
00885             K_ASSERT(a != NULL);
00886             v = count*sizeof(int);
00887             s = pStream.Read(a, v);
00888             mIndexArray->Release(&a);
00889             if (s != v) return false;
00890         }
00891         return KFbxLayerElement::ContentReadFrom(pStream);
00892     }
00894 
00895     KFbxLayerElementArrayTemplate<Type>* mDirectArray;
00896     KFbxLayerElementArrayTemplate<int>*  mIndexArray;
00897 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00898 };
00899 
00900 #define CREATE_DECLARE(classDesc) \
00901     static KFbx##classDesc* Create(KFbxLayerContainer* pOwner, char const *pName);
00902 
00906 class KFBX_DLL KFbxLayerElementNormal : public KFbxLayerElementTemplate<KFbxVector4>
00907 {
00908 public:
00909     CREATE_DECLARE(LayerElementNormal);
00910     
00911 protected:
00912     KFbxLayerElementNormal();
00913     ~KFbxLayerElementNormal();
00914 };
00915 
00916 
00920 class KFBX_DLL KFbxLayerElementMaterial : public KFbxLayerElementTemplate<KFbxSurfaceMaterial*>
00921 {
00922 public:
00923     typedef KFbxLayerElementTemplate<KFbxSurfaceMaterial*> ParentClass;
00924 
00925     CREATE_DECLARE(LayerElementMaterial);
00926     
00927     class LayerElementArrayProxy : public KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>
00928     {
00929     public:
00930         typedef KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*> ParentClass;
00931 
00932         LayerElementArrayProxy(EFbxType pType);
00933         void SetContainer( KFbxLayerContainer* pContainer, int pInstance = 0);
00934     };
00935 
00936 
00942     K_DEPRECATED KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray() const
00943     {
00944         return ParentClass::GetDirectArray();
00945     }
00946 
00947     K_DEPRECATED KFbxLayerElementArrayTemplate<KFbxSurfaceMaterial*>& GetDirectArray()
00948     {
00949         return ParentClass::GetDirectArray();
00950     }
00951 
00953 //
00954 //  WARNING!
00955 //
00956 //  Anything beyond these lines may not be documented accurately and is 
00957 //  subject to change without notice.
00958 //
00960 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00961 
00962     virtual void AllocateArrays();
00963     virtual void SetOwner( KFbxLayerContainer* pOwner, int pInstance = 0);
00964     virtual void SetInstance( int pInstance ) { SetOwner( mOwner, pInstance ); }
00965 
00966 protected:
00967     KFbxLayerElementMaterial();
00968     ~KFbxLayerElementMaterial();
00969 
00970 #endif //DOXYGEN_SHOULD_SKIP_THIS
00971 }; 
00972 
00976 class KFBX_DLL KFbxLayerElementPolygonGroup : public KFbxLayerElementTemplate<int>
00977 {
00978 public:
00979     CREATE_DECLARE(LayerElementPolygonGroup);
00980     
00981 protected:
00982     KFbxLayerElementPolygonGroup();
00983     ~KFbxLayerElementPolygonGroup();
00984 };
00985 
00989 class KFBX_DLL KFbxLayerElementUV : public KFbxLayerElementTemplate<KFbxVector2>
00990 {
00991 public:
00992     CREATE_DECLARE(LayerElementUV);
00993     
00994 protected:
00995     KFbxLayerElementUV();
00996     ~KFbxLayerElementUV();
00997 };
00998 
01002 class KFBX_DLL KFbxLayerElementVertexColor : public KFbxLayerElementTemplate<KFbxColor>
01003 {
01004 public:
01005     CREATE_DECLARE(LayerElementVertexColor);
01006     
01007 protected:
01008     KFbxLayerElementVertexColor();
01009     ~KFbxLayerElementVertexColor();
01010 };
01011 
01014 const int kNoMapping = -1;
01015 
01023 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, int pIndex, bool* pStatus = NULL);
01024 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus = NULL);
01025 template <class T> inline KFbxLayerElementArrayTemplate<T>&       KFbxGetDirectArray(KFbxLayerElementUserData       *pLayerElement, const char* pName, bool* pStatus = NULL );
01026 template <class T> inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus = NULL );
01027 
01031 class KFBX_DLL KFbxLayerElementUserData : public KFbxLayerElementTemplate<void*>
01032 {
01033 public:
01034 
01035     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, char const *pName, int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames);
01036     static KFbxLayerElementUserData* Create(KFbxLayerContainer* pOwner, KFbxLayerElementUserData const& pOther );
01037 
01043     KFbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL)
01044     {       
01045         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01046         {
01047             if (pStatus) *pStatus = true;
01048             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01049         }
01050         else
01051         {
01052             if( pStatus ) *pStatus = false;
01053             K_ASSERT_MSG_NOW("Index out of bounds");
01054             return (KFbxLayerElementArrayTemplate<void*>*)NULL;
01055         }
01056     }
01057 
01063     KFbxLayerElementArrayTemplate<void*> const* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL) const
01064     {
01065         if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
01066         {
01067             if (pStatus) *pStatus = true;
01068             return (KFbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
01069         }
01070         else
01071         {
01072             if( pStatus ) *pStatus = false;
01073             K_ASSERT_MSG_NOW("Index out of bounds");
01074             return (KFbxLayerElementArrayTemplate<void*> const*)NULL;
01075         }
01076     }
01077 
01078 
01084     KFbxLayerElementArrayTemplate<void *>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL )
01085     {
01086         KString lName( pName );
01087         for( int i = 0; i < mDataNames.GetCount(); ++i )
01088         {
01089             if( *mDataNames[i] == lName )
01090                 return GetDirectArrayVoid(i, pStatus);
01091         }
01092 
01093         if (pStatus) *pStatus = false;
01094         return (KFbxLayerElementArrayTemplate<void *>*)NULL;
01095     }
01096  
01102     KFbxLayerElementArrayTemplate<void *> const* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL ) const
01103     {
01104         KString lName( pName );
01105         for( int i = 0; i < mDataNames.GetCount(); ++i )
01106         {
01107             if( *mDataNames[i] == lName )
01108                 return GetDirectArrayVoid(i, pStatus);
01109         }
01110 
01111         if (pStatus) *pStatus = false;
01112         return (KFbxLayerElementArrayTemplate<void *> const*)NULL;
01113     }
01114 
01119     KFbxDataType GetDataType( int pIndex ) const
01120     {
01121         if( pIndex < 0 || pIndex >= mDataTypes.GetCount() )
01122             return DTNone;
01123 
01124         return mDataTypes[pIndex];
01125     }
01126 
01131     KFbxDataType GetDataType( const char* pName ) const
01132     {
01133         KString lName( pName );
01134 
01135         for( int i = 0; i < mDataNames.GetCount(); ++i )
01136         {
01137             if( *mDataNames[i] == lName )
01138                 return mDataTypes[i];
01139         }
01140 
01141         return DTNone;
01142     }
01143 
01148     const char* GetDataName( int pIndex ) const
01149     {
01150         if( pIndex >= 0 && pIndex < mDataNames.GetCount() )
01151             return mDataNames[pIndex]->Buffer();
01152 
01153         return NULL;
01154     }
01155 
01159     void ResizeAllDirectArrays( int pSize )
01160     {
01161         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01162         {
01163             switch( mDataTypes[i].GetType() )
01164             {
01165                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).Resize( pSize )  ; break;
01166                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).Resize( pSize )   ; break;
01167                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).Resize( pSize ) ; break;
01168                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).Resize( pSize ); break;
01169                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).Resize( pSize );    break;
01170                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).Resize( pSize );    break;
01171                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).Resize( pSize );    break;  
01172                 default:
01173                     K_ASSERT_MSG_NOW("unknown type" ); break;
01174             }
01175         }
01176     }
01177 
01181     void RemoveFromAllDirectArrays( int pIndex )
01182     {
01183         for( int i = 0; i < GetDirectArray().GetCount(); ++i )
01184         {
01185             switch( mDataTypes[i].GetType() )
01186             {
01187                 case eBOOL1:    KFbxGetDirectArray<bool>(this,i).RemoveAt( pIndex )  ; break;
01188                 case eINTEGER1: KFbxGetDirectArray<int>(this,i).RemoveAt( pIndex )   ; break;
01189                 case eFLOAT1:   KFbxGetDirectArray<float>(this,i).RemoveAt( pIndex ) ; break;
01190                 case eDOUBLE1:  KFbxGetDirectArray<double>(this,i).RemoveAt( pIndex ); break;
01191                 //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(i).RemoveAt( pIndex ); break;
01192                 //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(i).RemoveAt( pIndex ); break;
01193                 //case eDOUBLE44:   GetDirectArray< fbxDouble44>(i).RemoveAt( pIndex ); break;  
01194                 default:
01195                     K_ASSERT_MSG_NOW("unknown type" ); break;
01196             }
01197         }
01198     }
01199 
01204     int GetArrayCount( int pIndex ) const 
01205     {
01206         if( pIndex >= 0 && pIndex < GetDirectArray().GetCount() )
01207         {
01208             switch( mDataTypes[pIndex].GetType() )
01209             {
01210                 case eBOOL1:    return KFbxGetDirectArray<bool>(this,pIndex).GetCount();
01211                 case eINTEGER1: return KFbxGetDirectArray<int>(this,pIndex).GetCount();
01212                 case eFLOAT1:   return KFbxGetDirectArray<float>(this,pIndex).GetCount();
01213                 case eDOUBLE1:  return KFbxGetDirectArray<double>(this,pIndex).GetCount();
01214                 //case eDOUBLE3:    return GetDirectArray< fbxDouble3 >(pIndex).GetCount();
01215                 //case eDOUBLE4:    return GetDirectArray< fbxDouble4 >(pIndex).GetCount();
01216                 //case eDOUBLE44:   return GetDirectArray< fbxDouble44>(pIndex).GetCount();
01217                 default:
01218                     K_ASSERT_MSG_NOW("Unknown type" ); break;
01219             }
01220         }
01221 
01222         return -1;
01223     }
01224 
01228     int GetId() const { return mId; }
01229 
01233     int GetDirectArrayCount() const { return GetDirectArray().GetCount(); }
01234 
01239     KFbxLayerElementUserData& operator=( KFbxLayerElementUserData const& pOther )
01240     {
01241         int i;
01242         Clear();
01243 
01244         // Build descriptives.
01245         //
01246         mDataNames.Resize(pOther.mDataNames.GetCount());
01247         for( i = 0; i < pOther.mDataNames.GetCount(); ++i )
01248             mDataNames.SetAt(i,  new KString( *pOther.mDataNames[i] ) );
01249 
01250         mDataTypes.Resize(pOther.mDataTypes.GetCount());
01251         for( i = 0; i < pOther.mDataTypes.GetCount(); ++i )
01252             mDataTypes.SetAt(i, pOther.mDataTypes[i] );
01253 
01254 
01255         Init();
01256         kReference** dummy = NULL;
01257         for( i = 0; i < pOther.GetDirectArrayCount(); ++i )
01258         {
01259             kReference** src = pOther.GetDirectArray().GetLocked(dummy, KFbxLayerElementArray::eREAD_LOCK);
01260             kReference** dst = GetDirectArray().GetLocked(dummy, KFbxLayerElementArray::eREADWRITE_LOCK);
01261 
01262             if (src && dst)
01263             {
01264                 *dst[i] = *src[i];
01265                 /*switch( mDataTypes[i].GetType() )
01266                 {
01267                     case eBOOL1:    ((KArrayTemplate<bool>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<bool>*)pOther.mDirectArray[i]) ); break;
01268                     case eINTEGER1: ((KArrayTemplate<int>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<int>*)pOther.mDirectArray[i]) ); break;
01269                     case eFLOAT1:   ((KArrayTemplate<float>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<float>*)pOther.mDirectArray[i]) ); break;
01270                     case eDOUBLE1:  ((KArrayTemplate<double>*)mDirectArray[i])->operator=( (*(const KArrayTemplate<double>*)pOther.mDirectArray[i]) ); break;
01271                     //case eDOUBLE3:    GetDirectArray< fbxDouble3 >(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01272                     //case eDOUBLE4:    GetDirectArray< fbxDouble4 >(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01273                     //case eDOUBLE44:   GetDirectArray< fbxDouble44>(pIndex).SetAt(j, pOther.GetDirectArray<bool>(i)[j] );
01274                     default:
01275                         K_ASSERT_MSG_NOW("Unknown type" ); break;
01276                 }*/
01277 
01278                 GetDirectArray().Release((void**)&dst);
01279                 pOther.GetDirectArray().Release((void**)&src);
01280             }
01281             else
01282                 K_ASSERT_MSG_NOW("Unable to get lock");
01283         }
01284 
01285         mId = pOther.mId;
01286 
01287         GetIndexArray() = pOther.GetIndexArray();
01288 
01289         return *this;
01290     }
01291 
01294     void Clear()
01295     {
01296         int i;
01297         const int lCount = GetDirectArray().GetCount();
01298         KFbxLayerElementArray** directArray = NULL;
01299         directArray = GetDirectArray().GetLocked(directArray);
01300         for( i = 0; directArray != NULL && i < lCount; ++i )
01301         {
01302             if( directArray[i] )
01303                 delete directArray[i];
01304         }
01305         GetDirectArray().Release((void**)&directArray);
01306 
01307         for( i = 0; i < mDataNames.GetCount(); ++i )
01308         {
01309             if( mDataNames[i] )
01310             {
01311                 delete mDataNames[i];
01312                 mDataNames[i] = NULL;
01313             }
01314         }
01315         mDataNames.Clear();
01316         mDataTypes.Clear();
01317 
01318         KFbxLayerElementTemplate<void*>::Clear();
01319     }
01320 
01321     virtual int MemorySize() const
01322     {
01323         int size = KFbxLayerElementTemplate<void*>::MemorySize();
01324         size += sizeof(mId);
01325         return size;
01326     }
01327 
01328 protected:
01338     KFbxLayerElementUserData( int pId, KArrayTemplate<KFbxDataType>& pDataTypes, KArrayTemplate<const char*>& pDataNames )
01339         :
01340         mId( pId ),
01341         mDataTypes( pDataTypes )
01342     {
01343         K_ASSERT( pDataTypes.GetCount() == pDataNames.GetCount() );
01344         for( int i = 0; i < pDataNames.GetCount(); ++i )
01345         {
01346             mDataNames.Add( new KString( pDataNames[i] ) );
01347         }
01348     }
01349 
01352     KFbxLayerElementUserData( KFbxLayerElementUserData const& pOther )
01353     {
01354         *this = pOther;
01355     }
01356 
01358     ~KFbxLayerElementUserData()
01359     {
01360         Clear();
01361     }
01362 
01364     virtual void AllocateArrays()
01365     {
01366         KFbxLayerElementTemplate<void*>::AllocateArrays();
01367         Init();
01368     }
01369 
01370 private:
01371     void Init()
01372     {
01373         int i;
01374         GetDirectArray().Resize( mDataTypes.GetCount() );
01375 
01376         // initialize arrays
01377         for( i = 0; i < mDataTypes.GetCount(); ++i )
01378         {
01379             kReference** dst = NULL;
01380             dst = GetDirectArray().GetLocked(dst);
01381             if (dst)
01382             {
01383                 switch( mDataTypes[i].GetType() )
01384                 {
01385                     case eBOOL1:    dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<bool>(mDataTypes[i].GetType()); break;
01386                     case eINTEGER1: dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<int>(mDataTypes[i].GetType());  break;
01387                     case eFLOAT1:   dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<float>(mDataTypes[i].GetType());    break;
01388                     case eDOUBLE1:  dst[i] = (kReference*)new KFbxLayerElementArrayTemplate<double>(mDataTypes[i].GetType());   break;
01389                     //case eDOUBLE3:    mDirectArray[i] = new KArrayTemplate< fbxDouble3 >();   break;  
01390                     //case eDOUBLE4:    mDirectArray[i] = new KArrayTemplate< fbxDouble4 >();   break;
01391                     //case eDOUBLE44:   mDirectArray[i] = new KArrayTemplate< fbxDouble44 >();  break;  
01392                     default:
01393                         K_ASSERT_MSG_NOW("Trying to assign an unknown type" ); break;
01394                 }
01395                 GetDirectArray().Release((void**)&dst);
01396             }
01397         }
01398     }
01399 
01400     int mId;
01401     KArrayTemplate<KFbxDataType> mDataTypes;
01402     KArrayTemplate<KString*> mDataNames;
01403 };
01404 
01412 template <class T>
01413 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,int pIndex, bool* pStatus)
01414 {
01415     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
01416 }
01417 
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 
01427 template <class T>
01428 inline KFbxLayerElementArrayTemplate<T>& KFbxGetDirectArray( KFbxLayerElementUserData *pLayerElement,const char* pName, bool* pStatus )
01429 {
01430     return *(KFbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01431 }
01432 
01433 template <class T>
01434 inline KFbxLayerElementArrayTemplate<T> const& KFbxGetDirectArray(KFbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus )
01435 {
01436     return *(KFbxLayerElementArrayTemplate<T> const*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
01437 }
01438 
01439 
01443 class KFBX_DLL KFbxLayerElementSmoothing : public KFbxLayerElementTemplate<int>
01444 {
01445 public:
01446     static KFbxLayerElementSmoothing* Create(KFbxLayerContainer* pOwner, char const *pName);
01447 
01448     void SetReferenceMode( KFbxLayerElement::EReferenceMode pMode )
01449     {
01450         if( pMode != KFbxLayerElement::eDIRECT )
01451         {
01452             K_ASSERT_MSG_NOW( "Smoothing layer elements must be direct mapped" );
01453             return;
01454         }
01455     }
01456 
01457 protected:
01458     KFbxLayerElementSmoothing()
01459     {
01460         mReferenceMode = KFbxLayerElement::eDIRECT;
01461     }
01462 
01463 };
01464 
01467 class KFBX_DLL KFbxLayerElementVisibility : public KFbxLayerElementTemplate<bool>
01468 {
01469 public:
01470     CREATE_DECLARE(LayerElementVisibility);
01471 
01472 protected:
01473     KFbxLayerElementVisibility();
01474     ~KFbxLayerElementVisibility();
01475 };
01476 
01477 typedef class KFBX_DLL KFbxLayerElementTemplate<KFbxTexture*>  KFbxLayerElementTextureBase;
01478 
01482 class KFBX_DLL KFbxLayerElementTexture : public KFbxLayerElementTextureBase
01483 {
01484 
01485 public:
01486     CREATE_DECLARE(LayerElementTexture);
01487 
01495     typedef enum 
01496     {
01497         eTRANSLUCENT,
01498         eADD,
01499         eMODULATE,
01500         eMODULATE2,
01501         eMAXBLEND
01502     } EBlendMode;
01503 
01507     void       SetBlendMode(EBlendMode pBlendMode) { mBlendMode = pBlendMode; }
01508 
01513     void       SetAlpha(double pAlpha)             
01514     { 
01515         mAlpha = pAlpha > 1.0 ? 1.0 : pAlpha;
01516         mAlpha = pAlpha < 0.0 ? 0.0 : pAlpha;
01517     }
01518 
01522     EBlendMode GetBlendMode()                      { return mBlendMode; } 
01523 
01527     double     GetAlpha()                          { return mAlpha; }
01528 
01530 //
01531 //  WARNING!
01532 //
01533 //  Anything beyond these lines may not be documented accurately and is 
01534 //  subject to change without notice.
01535 //
01537 #ifndef DOXYGEN_SHOULD_SKIP_THIS
01538 
01539     virtual int MemorySize() const
01540     {
01541         int size = KFbxLayerElementTextureBase::MemorySize();
01542         size += sizeof(mBlendMode);
01543         size += sizeof(mAlpha);
01544         return size;
01545     }
01546 
01547 protected:
01552     KFbxLayerElementTexture() : mBlendMode(eTRANSLUCENT)
01553     {
01554         mReferenceMode = eINDEX_TO_DIRECT;
01555         mAlpha         = 1.0;
01556     }
01557 
01558 private:
01559     EBlendMode mBlendMode;
01560     double     mAlpha;
01561 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
01562 };
01563 
01564 
01592 class KFBX_DLL KFbxLayer
01593 {
01594 
01595 public:
01596 
01601 
01606     KFbxLayerElementNormal* GetNormals();   
01607 
01612     KFbxLayerElementNormal const* GetNormals() const;   
01613 
01617     KFbxLayerElementMaterial* GetMaterials();
01618 
01622     KFbxLayerElementMaterial const* GetMaterials() const;
01623 
01627     KFbxLayerElementPolygonGroup* GetPolygonGroups();
01628 
01632     KFbxLayerElementPolygonGroup const* GetPolygonGroups() const;
01633 
01634 
01638     KFbxLayerElementUV* GetEmissiveUV();
01639 
01643     KFbxLayerElementUV const* GetEmissiveUV() const;
01644 
01648     KFbxLayerElementUV* GetEmissiveFactorUV();
01649 
01653     KFbxLayerElementUV const* GetEmissiveFactorUV() const;
01654 
01658     KFbxLayerElementUV* GetAmbientUV();
01659 
01663     KFbxLayerElementUV const* GetAmbientUV() const;
01664 
01668     KFbxLayerElementUV* GetAmbientFactorUV();
01669 
01673     KFbxLayerElementUV const* GetAmbientFactorUV() const;
01674     
01678     KFbxLayerElementUV* GetDiffuseUV();
01679 
01683     KFbxLayerElementUV const* GetDiffuseUV() const;
01684 
01688     KFbxLayerElementUV* GetDiffuseFactorUV();
01689 
01693     KFbxLayerElementUV const* GetDiffuseFactorUV() const;
01694 
01698     KFbxLayerElementUV* GetSpecularUV();
01699 
01703     KFbxLayerElementUV const* GetSpecularUV() const;
01704 
01708     KFbxLayerElementUV* GetSpecularFactorUV();
01709 
01713     KFbxLayerElementUV const* GetSpecularFactorUV() const;
01714 
01718     KFbxLayerElementUV* GetShininessUV();
01719 
01723     KFbxLayerElementUV const* GetShininessUV() const;
01724 
01728     KFbxLayerElementUV* GetNormalMapUV();
01729 
01733     KFbxLayerElementUV const* GetNormalMapUV() const;
01734 
01738     KFbxLayerElementUV* GetBumpUV();
01739 
01743     KFbxLayerElementUV const* GetBumpUV() const;
01744 
01748     KFbxLayerElementUV* GetTransparentUV();
01749 
01753     KFbxLayerElementUV const* GetTransparentUV() const;
01754 
01758     KFbxLayerElementUV* GetTransparencyFactorUV();
01759 
01763     KFbxLayerElementUV const* GetTransparencyFactorUV() const;
01764 
01768     KFbxLayerElementUV* GetReflectionUV();
01769 
01773     KFbxLayerElementUV const* GetReflectionUV() const;
01774 
01778     KFbxLayerElementUV* GetReflectionFactorUV();
01779 
01783     KFbxLayerElementUV const* GetReflectionFactorUV() const;
01784 
01790     KFbxLayerElementUV* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
01791 
01797     KFbxLayerElementUV const* GetUVs(KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES) const;
01798 
01799 
01802     int GetUVSetCount() const;
01803     
01806     KArrayTemplate<KFbxLayerElement::ELayerElementType> GetUVSetChannels() const;
01807 
01810     KArrayTemplate<KFbxLayerElementUV const*> GetUVSets() const;
01811 
01816     KFbxLayerElementVertexColor* GetVertexColors();
01817 
01822     KFbxLayerElementVertexColor const* GetVertexColors() const;
01823 
01828     KFbxLayerElementSmoothing* GetSmoothing();
01829 
01834     KFbxLayerElementSmoothing const* GetSmoothing() const;
01835 
01839     KFbxLayerElementUserData* GetUserData();
01840 
01844     KFbxLayerElementUserData const* GetUserData() const;
01845 
01849     KFbxLayerElementVisibility* GetVisibility();
01850 
01854     KFbxLayerElementVisibility const* GetVisibility() const;
01855 
01859     KFbxLayerElementTexture* GetEmissiveTextures();
01860 
01864     KFbxLayerElementTexture const* GetEmissiveTextures() const;
01865 
01869     KFbxLayerElementTexture* GetEmissiveFactorTextures();
01870 
01874     KFbxLayerElementTexture const* GetEmissiveFactorTextures() const;
01875 
01879     KFbxLayerElementTexture* GetAmbientTextures();
01880 
01884     KFbxLayerElementTexture const* GetAmbientTextures() const;
01885 
01889     KFbxLayerElementTexture* GetAmbientFactorTextures();
01890 
01894     KFbxLayerElementTexture const* GetAmbientFactorTextures() const;
01895     
01899     KFbxLayerElementTexture* GetDiffuseTextures();
01900 
01904     KFbxLayerElementTexture const* GetDiffuseTextures() const;
01905 
01909     KFbxLayerElementTexture* GetDiffuseFactorTextures();
01910 
01914     KFbxLayerElementTexture const* GetDiffuseFactorTextures() const;
01915 
01919     KFbxLayerElementTexture* GetSpecularTextures();
01920 
01924     KFbxLayerElementTexture const* GetSpecularTextures() const;
01925 
01929     KFbxLayerElementTexture* GetSpecularFactorTextures();
01930 
01934     KFbxLayerElementTexture const* GetSpecularFactorTextures() const;
01935 
01939     KFbxLayerElementTexture* GetShininessTextures();
01940 
01944     KFbxLayerElementTexture const* GetShininessTextures() const;
01945 
01949     KFbxLayerElementTexture* GetNormalMapTextures();
01950 
01954     KFbxLayerElementTexture const* GetNormalMapTextures() const;
01955 
01959     KFbxLayerElementTexture* GetBumpTextures();
01960 
01964     KFbxLayerElementTexture const* GetBumpTextures() const;
01965 
01969     KFbxLayerElementTexture* GetTransparentTextures();
01970 
01974     KFbxLayerElementTexture const* GetTransparentTextures() const;
01975 
01979     KFbxLayerElementTexture* GetTransparencyFactorTextures();
01980 
01984     KFbxLayerElementTexture const* GetTransparencyFactorTextures() const;
01985 
01989     KFbxLayerElementTexture* GetReflectionTextures();
01990 
01994     KFbxLayerElementTexture const* GetReflectionTextures() const;
01995 
01999     KFbxLayerElementTexture* GetReflectionFactorTextures();
02000 
02004     KFbxLayerElementTexture const* GetReflectionFactorTextures() const;
02005 
02009     KFbxLayerElementTexture* GetTextures(KFbxLayerElement::ELayerElementType pType);
02010 
02014     KFbxLayerElementTexture const* GetTextures(KFbxLayerElement::ELayerElementType pType) const;
02015 
02020     void SetTextures(KFbxLayerElement::ELayerElementType pType, KFbxLayerElementTexture* pTextures);
02021 
02050     KFbxLayerElement* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02051 
02080     KFbxLayerElement const* GetLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false) const;
02081 
02086     void SetNormals(KFbxLayerElementNormal* pNormals);
02087 
02091     void SetMaterials(KFbxLayerElementMaterial* pMaterials);
02092 
02096     void SetPolygonGroups(KFbxLayerElementPolygonGroup* pPolygonGroups);
02097 
02104     void SetUVs(KFbxLayerElementUV* pUVs, KFbxLayerElement::ELayerElementType pTypeIdentifier=KFbxLayerElement::eDIFFUSE_TEXTURES);
02105 
02110     void SetVertexColors (KFbxLayerElementVertexColor* pVertexColors);
02111 
02116     void SetSmoothing (KFbxLayerElementSmoothing* pSmoothing);
02117 
02121     void SetUserData (KFbxLayerElementUserData* pUserData);
02122 
02126     void SetVisibility( KFbxLayerElementVisibility* pVisibility );
02127 
02131     void SetEmissiveTextures(KFbxLayerElementTexture* pTextures);
02132 
02136     void SetEmissiveFactorTextures(KFbxLayerElementTexture* pTextures);
02137 
02141     void SetAmbientTextures(KFbxLayerElementTexture* pTextures);
02142 
02146     void SetAmbientFactorTextures(KFbxLayerElementTexture* pTextures);
02147 
02151     void SetDiffuseTextures(KFbxLayerElementTexture* pTextures);
02152 
02156     void SetDiffuseFactorTextures(KFbxLayerElementTexture* pTextures);
02157 
02161     void SetSpecularTextures(KFbxLayerElementTexture* pTextures);
02162 
02166     void SetSpecularFactorTextures(KFbxLayerElementTexture* pTextures);
02167 
02171     void SetShininessTextures(KFbxLayerElementTexture* pTextures);
02172 
02176     void SetNormalMapTextures(KFbxLayerElementTexture* pTextures);
02177 
02181     void SetBumpTextures(KFbxLayerElementTexture* pTextures);
02182 
02186     void SetTransparentTextures(KFbxLayerElementTexture* pTextures);
02187 
02191     void SetTransparencyFactorTextures(KFbxLayerElementTexture* pTextures);
02192 
02196     void SetReflectionTextures(KFbxLayerElementTexture* pTextures);
02197 
02201     void SetReflectionFactorTextures(KFbxLayerElementTexture* pTextures);
02202 
02203 
02211     KFbxLayerElement* CreateLayerElementOfType(KFbxLayerElement::ELayerElementType pType, bool pIsUV=false);
02212 
02213 
02214     void Clone(KFbxLayer const& pSrcLayer, KFbxSdkManager* pSdkManager);    
02215     
02217     //KFbxLayer& operator=(KFbxLayer const& pSrcLayer); 
02219     
02221 //
02222 //  WARNING!
02223 //
02224 //  Anything beyond these lines may not be documented accurately and is 
02225 //  subject to change without notice.
02226 //
02228 
02229 #ifndef DOXYGEN_SHOULD_SKIP_THIS
02230 protected:
02232     KFbxLayer& operator=(KFbxLayer const& pSrcLayer);   
02234 private:
02235 
02236     KFbxLayer(KFbxLayerContainer& pOwner);
02237     virtual ~KFbxLayer();
02238 
02239     void Clear();
02240 
02241     KFbxLayerContainer& mOwner;
02242 
02243     KFbxLayerElementNormal*       mNormals;
02244     KFbxLayerElementMaterial*     mMaterials;
02245     KFbxLayerElementPolygonGroup* mPolygonGroups;
02246     KFbxLayerElementUV*           mUVs; 
02247     KFbxLayerElementVertexColor*  mVertexColors;
02248     KFbxLayerElementSmoothing*    mSmoothing;
02249     KFbxLayerElementUserData*     mUserData;
02250     KFbxLayerElementVisibility*   mVisibility;
02251 
02252     KFbxLayerElementUV*      mEmissiveUV;
02253     KFbxLayerElementUV*      mEmissiveFactorUV;
02254     KFbxLayerElementUV*      mAmbientUV;
02255     KFbxLayerElementUV*      mAmbientFactorUV;
02256     KFbxLayerElementUV*      mDiffuseFactorUV;
02257     KFbxLayerElementUV*      mSpecularUV;
02258     KFbxLayerElementUV*      mSpecularFactorUV;
02259     KFbxLayerElementUV*      mShininessUV;
02260     KFbxLayerElementUV*      mNormalMapUV;
02261     KFbxLayerElementUV*      mBumpUV;
02262     KFbxLayerElementUV*      mTransparentUV;
02263     KFbxLayerElementUV*      mTransparencyFactorUV;
02264     KFbxLayerElementUV*      mReflectionUV;
02265     KFbxLayerElementUV*      mReflectionFactorUV;
02266 
02267 
02268     KFbxLayerElementTexture*      mEmissiveTextures;
02269     KFbxLayerElementTexture*      mEmissiveFactorTextures;
02270     KFbxLayerElementTexture*      mAmbientTextures;
02271     KFbxLayerElementTexture*      mAmbientFactorTextures;
02272     KFbxLayerElementTexture*      mDiffuseTextures;
02273     KFbxLayerElementTexture*      mDiffuseFactorTextures;
02274     KFbxLayerElementTexture*      mSpecularTextures;
02275     KFbxLayerElementTexture*      mSpecularFactorTextures;
02276     KFbxLayerElementTexture*      mShininessTextures;
02277     KFbxLayerElementTexture*      mNormalMapTextures;
02278     KFbxLayerElementTexture*      mBumpTextures;
02279     KFbxLayerElementTexture*      mTransparentTextures;
02280     KFbxLayerElementTexture*      mTransparencyFactorTextures;
02281     KFbxLayerElementTexture*      mReflectionTextures;
02282     KFbxLayerElementTexture*      mReflectionFactorTextures;
02283 
02284     friend class KFbxLayerContainer;
02285 
02286 public:
02291         bool ContentWriteTo(KFbxStream& pStream) const;
02292         bool ContentReadFrom(const KFbxStream& pStream);
02294     virtual int MemoryUsage() const;
02295 
02296 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
02297 };
02298 
02299 #undef CREATE_DECLARE
02300 #include <fbxfilesdk_nsend.h>
02301 
02302 #endif // #ifndef _FBXSDK_LAYER_H_
02303 
02304 
02305 
02306