fbxlayer.h 121 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801
  1. /****************************************************************************************
  2. Copyright (C) 2015 Autodesk, Inc.
  3. All rights reserved.
  4. Use of this software is subject to the terms of the Autodesk license agreement
  5. provided at the time of installation or download, or which otherwise accompanies
  6. this software in either electronic or hard copy form.
  7. ****************************************************************************************/
  8. //! \file fbxlayer.h
  9. #ifndef _FBXSDK_SCENE_GEOMETRY_LAYER_H_
  10. #define _FBXSDK_SCENE_GEOMETRY_LAYER_H_
  11. #include <fbxsdk/fbxsdk_def.h>
  12. #include <fbxsdk/core/fbxdatatypes.h>
  13. #include <fbxsdk/core/fbxstream.h>
  14. #include <fbxsdk/scene/shading/fbxsurfacematerial.h>
  15. #include <fbxsdk/scene/shading/fbxtexture.h>
  16. #include <fbxsdk/fbxsdk_nsbegin.h>
  17. class FbxLayerElementArray;
  18. class FbxLayerContainer;
  19. /** Base class for elements of layers (FbxLayer).
  20. * A layer element type is identified by EType.
  21. * A FbxLayerElement describes how the layer element is mapped to a geometry surface
  22. * and how the mapping information is arranged in memory.
  23. * A FbxLayerElement contains Normals, UVs or other kind of information.
  24. *
  25. * \see FbxLayer
  26. * \see FbxLayerElement::EMappingMode
  27. * \see FbxLayerElement::EReferenceMode
  28. */
  29. class FBXSDK_DLL FbxLayerElement
  30. {
  31. public:
  32. /** \enum EType Layer Element type identifier.
  33. * - \e eUnknown Undefined Layer Element class.
  34. * - \e eNormal Layer Element of type FbxLayerElementNormal.
  35. * - \e eBiNormal Layer Element of type FbxLayerElementBinormal.
  36. * - \e eTangent Layer Element of type FbxLayerElementTangent.
  37. * - \e eMaterial Layer Element of type FbxLayerElementMaterial.
  38. * - \e eTextureDiffuse Layer Element of type FbxLayerElementTexture.
  39. * - \e ePolygonGroup Layer Element of type FbxLayerElementPolygonGroup.
  40. * - \e eUV Layer Element of type FbxLayerElementUV.
  41. * - \e eVertexColor Layer Element of type FbxLayerElementVertexColor.
  42. * - \e eSmoothing Layer Element of type FbxLayerElementSmoothing.
  43. * - \e eVertexCrease Layer Element of type FbxLayerElementCrease.
  44. * - \e eEdgeCrease Layer Element of type FbxLayerElementCrease.
  45. * - \e eHole Layer Element of type FbxLayerElementHole.
  46. * - \e eUserData Layer Element of type FbxLayerElementUserData.
  47. * - \e eVisibility Layer Element of type FbxLayerElementVisibility.
  48. * - \e eTextureEmissive Layer Element of type FbxLayerElementTexture.
  49. * - \e eTextureEmissiveFactor Layer Element of type FbxLayerElementTexture.
  50. * - \e eTextureAmbient Layer Element of type FbxLayerElementTexture.
  51. * - \e eTextureAmbientFactor Layer Element of type FbxLayerElementTexture.
  52. * - \e eTextureDiffuseFactor Layer Element of type FbxLayerElementTexture.
  53. * - \e eTextureSpecular Layer Element of type FbxLayerElementTexture.
  54. * - \e eTextureNormalMap Layer Element of type FbxLayerElementTexture.
  55. * - \e eTextureSpecularFactor Layer Element of type FbxLayerElementTexture.
  56. * - \e eTextureShininess Layer Element of type FbxLayerElementTexture.
  57. * - \e eTextureBump Layer Element of type FbxLayerElementTexture.
  58. * - \e eTextureTransparency Layer Element of type FbxLayerElementTexture.
  59. * - \e eTextureTransparencyFactor Layer Element of type FbxLayerElementTexture.
  60. * - \e eTextureReflection Layer Element of type FbxLayerElementTexture.
  61. * - \e eTextureReflectionFactor Layer Element of type FbxLayerElementTexture.
  62. * - \e eTextureDisplacement Layer Element of type FbxLayerElementTexture.
  63. * - \e eTextureDisplacementVector Layer Element of type FbxLayerElementTexture.
  64. * - \e eTypeCount
  65. */
  66. enum EType
  67. {
  68. eUnknown,
  69. //Non-Texture layer element types
  70. //Note: Make sure to update static index below if you change this enum!
  71. eNormal,
  72. eBiNormal,
  73. eTangent,
  74. eMaterial,
  75. ePolygonGroup,
  76. eUV,
  77. eVertexColor,
  78. eSmoothing,
  79. eVertexCrease,
  80. eEdgeCrease,
  81. eHole,
  82. eUserData,
  83. eVisibility,
  84. //Texture layer element types
  85. //Note: Make sure to update static index below if you change this enum!
  86. eTextureDiffuse,
  87. eTextureDiffuseFactor,
  88. eTextureEmissive,
  89. eTextureEmissiveFactor,
  90. eTextureAmbient,
  91. eTextureAmbientFactor,
  92. eTextureSpecular,
  93. eTextureSpecularFactor,
  94. eTextureShininess,
  95. eTextureNormalMap,
  96. eTextureBump,
  97. eTextureTransparency,
  98. eTextureTransparencyFactor,
  99. eTextureReflection,
  100. eTextureReflectionFactor,
  101. eTextureDisplacement,
  102. eTextureDisplacementVector,
  103. eTypeCount
  104. };
  105. const static int sTypeTextureStartIndex = int(eTextureDiffuse); //!< The start index of texture type layer elements.
  106. const static int sTypeTextureEndIndex = int(eTypeCount) - 1; //!< The end index of texture type layer elements.
  107. const static int sTypeTextureCount = sTypeTextureEndIndex - sTypeTextureStartIndex + 1; //!< The count of texture type layer elements.
  108. const static int sTypeNonTextureStartIndex = int(eNormal); //!< The start index of non-texture type layer elements.
  109. const static int sTypeNonTextureEndIndex = int(eVisibility); //!< The end index of non-texture type layer elements.
  110. const static int sTypeNonTextureCount = sTypeNonTextureEndIndex - sTypeNonTextureStartIndex + 1; //!< The count of non-texture type layer elements.
  111. static const char* const sTextureNames[]; //!< Array of names of texture type layer elements.
  112. static const char* const sTextureUVNames[]; //!< Array of names of UV layer elements.
  113. static const char* const sNonTextureNames[]; //!< Array of names of non-texture type layer elements.
  114. static const FbxDataType sTextureDataTypes[]; //!< Array of texture types.
  115. static const char* const sTextureChannelNames[]; //!< Array of texture channels.
  116. /** \enum EMappingMode Determines how the element is mapped to a surface.
  117. * - \e eNone The mapping is undetermined.
  118. * - \e eByControlPoint There will be one mapping coordinate for each surface control point/vertex.
  119. * - \e eByPolygonVertex There will be one mapping coordinate for each vertex, for every polygon of which it is a part.
  120. This means that a vertex will have as many mapping coordinates as polygons of which it is a part.
  121. * - \e eByPolygon There can be only one mapping coordinate for the whole polygon.
  122. * - \e eByEdge There will be one mapping coordinate for each unique edge in the mesh.
  123. This is meant to be used with smoothing layer elements.
  124. * - \e eAllSame There can be only one mapping coordinate for the whole surface.
  125. */
  126. enum EMappingMode
  127. {
  128. eNone,
  129. eByControlPoint,
  130. eByPolygonVertex,
  131. eByPolygon,
  132. eByEdge,
  133. eAllSame
  134. };
  135. /** \enum EReferenceMode Determines how the mapping information is stored in the array of coordinates.
  136. * - \e eDirect This indicates that the mapping information for the n'th element is found in the n'th place of
  137. FbxLayerElementTemplate::mDirectArray.
  138. * - \e eIndex, This symbol is kept for backward compatibility with FBX v5.0 files. In FBX v6.0 and higher,
  139. this symbol is replaced with eIndexToDirect.
  140. * - \e eIndexToDirect This indicates that the FbxLayerElementTemplate::mIndexArray
  141. contains, for the n'th element, an index in the FbxLayerElementTemplate::mDirectArray
  142. array of mapping elements. eIndexToDirect is usually useful for storing eByPolygonVertex mapping
  143. mode elements coordinates. Since the same coordinates are usually
  144. repeated many times, this saves spaces by storing the coordinate only one time
  145. and then referring to them with an index. Materials and Textures are also referenced with this
  146. mode and the actual Material/Texture can be accessed via the FbxLayerElementTemplate::mDirectArray
  147. */
  148. enum EReferenceMode
  149. {
  150. eDirect,
  151. eIndex,
  152. eIndexToDirect
  153. };
  154. /** Sets the Mapping Mode.
  155. * \param pMappingMode Specifies the way that layer element is mapped to a surface.
  156. */
  157. void SetMappingMode(EMappingMode pMappingMode) { mMappingMode = pMappingMode; }
  158. /** Sets the Reference Mode.
  159. * \param pReferenceMode Specifies the reference mode.
  160. */
  161. void SetReferenceMode(EReferenceMode pReferenceMode) { mReferenceMode = pReferenceMode; }
  162. /** Returns the Mapping Mode.
  163. * \return The current Mapping Mode.
  164. */
  165. EMappingMode GetMappingMode() const { return mMappingMode; }
  166. /** Returns the Reference Mode.
  167. * \return The current Reference Mode.
  168. */
  169. EReferenceMode GetReferenceMode() const { return mReferenceMode; }
  170. /** Sets the name of this object.
  171. * \param pName Specifies the name of this LayerElement object.
  172. */
  173. void SetName(const char* pName) { mName = FbxString(pName); }
  174. /** Returns the name of this object.
  175. * \return The current name of this LayerElement object.
  176. */
  177. const char* GetName() const { return ((FbxLayerElement*)this)->mName.Buffer(); }
  178. /** Equivalence operator
  179. * \param pOther Layer element to be compared.
  180. * \return \c True if equal, \c false otherwise.
  181. */
  182. bool operator==(const FbxLayerElement& pOther) const
  183. {
  184. return (mName == pOther.mName) &&
  185. (mMappingMode == pOther.mMappingMode) &&
  186. (mReferenceMode == pOther.mReferenceMode);
  187. }
  188. /** Assignment operator
  189. * \param pOther Layer element assigned to this one.
  190. * \return This layer element after assignment.
  191. */
  192. FbxLayerElement& operator=( FbxLayerElement const& pOther )
  193. {
  194. mMappingMode = pOther.mMappingMode;
  195. mReferenceMode = pOther.mReferenceMode;
  196. // name, type and owner should not be copied because they are
  197. // initialized when this object is created
  198. return *this;
  199. }
  200. //! Removes this layer element from its owner and delete it.
  201. void Destroy();
  202. //! Clears all the data from this layer element.
  203. virtual bool Clear()
  204. {
  205. return true;
  206. }
  207. /*****************************************************************************************************************************
  208. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  209. *****************************************************************************************************************************/
  210. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  211. void SetType(const FbxDataType* pType) { mType = pType; }
  212. const FbxLayerContainer* GetOwner() const { return mOwner; }
  213. protected:
  214. FbxLayerElement()
  215. : mMappingMode(eNone)
  216. , mReferenceMode(eDirect)
  217. , mName("")
  218. , mOwner(NULL)
  219. {
  220. }
  221. virtual ~FbxLayerElement()
  222. {
  223. }
  224. EMappingMode mMappingMode;
  225. EReferenceMode mReferenceMode;
  226. FbxString mName;
  227. const FbxDataType* mType;
  228. FbxLayerContainer* mOwner;
  229. void Destruct() { FbxDelete(this); }
  230. virtual void SetOwner(FbxLayerContainer* pOwner, int pInstance = 0);
  231. FBXSDK_FRIEND_NEW();
  232. public:
  233. virtual int MemorySize() const { return 0; }
  234. virtual bool ContentWriteTo(FbxStream& pStream) const;
  235. virtual bool ContentReadFrom(const FbxStream& pStream);
  236. friend class FbxLayerContainer;
  237. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  238. };
  239. /** \internal
  240. * Identifies what error occurs when the data arrays are manipulated.
  241. * \nosubgrouping
  242. */
  243. class FBXSDK_DLL LockAccessStatus
  244. {
  245. public:
  246. /** \internal
  247. * \enum ELockAccessStatus Identifies what error occurs when the data arrays are manipulated.
  248. * - \e eSuccess Operation Successful.
  249. * - \e eUnsupportedDTConversion Attempts to convert to an unsupported DataType.
  250. * - \e eCorruptedCopyback The Release of a converted buffer fails and corrupts the main data.
  251. * - \e eBadValue Invalid value.
  252. * - \e eLockMismatch Attempts to change to an incompatible lock.
  253. * - \e eNoWriteLock A write operation is attempted but no WriteLock is available.
  254. * - \e eNoReadLock A read operation is attempted but the WriteLock is active.
  255. * - \e eNotOwner Attempts to release a lock on an invalid data buffer pointer.
  256. * - \e eDirectLockExist A direct access lock is still active.
  257. */
  258. enum ELockAccessStatus
  259. {
  260. eSuccess,
  261. eUnsupportedDTConversion,
  262. eCorruptedCopyback,
  263. eBadValue,
  264. eLockMismatch,
  265. eNoWriteLock,
  266. eNoReadLock,
  267. eNotOwner,
  268. eDirectLockExist
  269. };
  270. };
  271. //Special conversion types, we do not want them to resolve to undefined.
  272. typedef FbxHandle* FbxRefPtr;
  273. typedef FbxLayerElementArray* FbxLayerElementArrayPtr;
  274. typedef FbxSurfaceMaterial* FbxSurfaceMaterialPtr;
  275. typedef FbxTexture* FbxTexturePtr;
  276. inline EFbxType FbxTypeOf(const FbxRefPtr&){ return eFbxReference; }
  277. inline EFbxType FbxTypeOf(const FbxLayerElementArrayPtr&){ return eFbxReference; }
  278. inline EFbxType FbxTypeOf(const FbxSurfaceMaterialPtr&){ return eFbxReference; }
  279. inline EFbxType FbxTypeOf(const FbxTexturePtr&){ return eFbxReference; }
  280. /** FbxLayerElementArray is the base class for FbxLayerElementArrayTemplate,
  281. * it provides lock handling and data array manipulation of the data buffer for FbxLayerElement.
  282. * \nosubgrouping
  283. */
  284. class FBXSDK_DLL FbxLayerElementArray
  285. {
  286. public:
  287. /**
  288. * \name Constructor and Destructor
  289. */
  290. //@{
  291. /** Constructor.
  292. * \param pDataType The data type of the items in the data array.
  293. */
  294. FbxLayerElementArray(EFbxType pDataType);
  295. //!Destructor.
  296. virtual ~FbxLayerElementArray();
  297. //@}
  298. /**
  299. * \name Status handling
  300. */
  301. //@{
  302. //!Clears the access state and sets it to eSuccess.
  303. inline void ClearStatus() { mStatus = LockAccessStatus::eSuccess; }
  304. //!Retrieves the access state.
  305. inline LockAccessStatus::ELockAccessStatus GetStatus() const { return mStatus; }
  306. //@}
  307. /**
  308. * \name Locks handling
  309. */
  310. //@{
  311. /** Returns whether write is locked.
  312. * \return \c True if write is locked, \c false otherwise.
  313. */
  314. inline bool IsWriteLocked() const { return mWriteLock; };
  315. /** Retrieves the read lock count.
  316. * \return The read lock count.
  317. */
  318. inline int GetReadLockCount() const { return mReadLockCount; }
  319. //@}
  320. /** Returns whether this Array is accessed in any way.
  321. * \return \c True if it is in use, \c false otherwise.
  322. */
  323. bool IsInUse() const;
  324. /** Increments the number of read locks on this array.
  325. * \return The current number of read locks (including the one just grabbed) or 0 if a write lock is active.
  326. */
  327. int ReadLock() const;
  328. /** Releases a read lock on this array.
  329. * \return The remaining read locks or -1 if a write lock is active.
  330. */
  331. int ReadUnlock() const;
  332. /** Locks this array for writing. The data in the array is wiped out.
  333. * \return \c True if a write lock has been successfully granted, \c false if one or more read locks
  334. * are active.
  335. */
  336. bool WriteLock() const;
  337. /** Releases the write lock on this array.
  338. */
  339. void WriteUnlock() const;
  340. /** Locks this array for writing. The data that already exists in the array is kept and is valid.
  341. * \return \c True if a write lock has been successfully granted, \c false if one or more read locks
  342. * are active.
  343. */
  344. bool ReadWriteLock() const;
  345. /** Releases the write lock on this array.
  346. */
  347. void ReadWriteUnlock() const;
  348. /** \enum ELockMode Identifies the access mode to the data buffer.
  349. * - \e eReadLock Read mode.
  350. * - \e eWriteLock Write mode.
  351. * - \e eReadWriteLock Read-write mode.
  352. */
  353. enum ELockMode
  354. {
  355. eReadLock = 1,
  356. eWriteLock = 2,
  357. eReadWriteLock = 3
  358. };
  359. /** Grants a locked access to the data buffer.
  360. * \param pLockMode Access mode to the data buffer.
  361. * \param pDataType If defined, tries to return the data as this type.
  362. * \return A pointer to the data buffer or NULL if a failure occurs.
  363. * \remarks In the case of a failure, the Status is updated with the
  364. * reason for the failure. Also, when a type conversion occurs, a second buffer
  365. * of the new type is allocated. In this case, the LockMode does not apply to the
  366. * returned buffer since it is a copy but it does apply to the internal data of this
  367. * object. The returned buffer still remains a property of this object and is
  368. * deleted when the pointer is released or the object is destroyed. At the moment of
  369. * release or destruction, the values in this buffer are copied back into this object.
  370. */
  371. virtual void* GetLocked(ELockMode pLockMode, EFbxType pDataType);
  372. /** Grants a locked access to the data buffer.
  373. * \param pLockMode Access mode to the data buffer.
  374. * \return A pointer to the data buffer or NULL if a failure occurs.
  375. * \remarks In the case of a failure, the Status is updated with the
  376. * reason for the failure. Also, when a type conversion occurs, a second buffer
  377. * of the new type is allocated. In this case, the LockMode does not apply to the
  378. * returned buffer since it is a copy but it does apply to the internal data of this
  379. * object. The returned buffer still remains a property of this object and is
  380. * deleted when the pointer is released or the object is destroyed. At the moment of
  381. * release or destruction, the values in this buffer are copied back into this object.
  382. */
  383. void* GetLocked(ELockMode pLockMode=eReadWriteLock) { return GetLocked(pLockMode, mDataType); }
  384. /** Grants a locked access to the data buffer.
  385. * \param pLockMode Access mode to the data buffer.
  386. * \return A pointer to the data buffer or NULL if a failure occurs.
  387. * \remarks In the case of a failure, the Status is updated with the
  388. * reason for the failure. Also, when a type conversion occurs, a second buffer
  389. * of the new type is allocated. In this case, the LockMode does not apply to the
  390. * returned buffer since it is a copy but it does apply to the internal data of this
  391. * object. The returned buffer still remains a property of this object and is
  392. * deleted when the pointer is released or the object is destroyed. At the moment of
  393. * release or destruction, the values in this buffer are copied back into this object.
  394. */
  395. template <class T> inline T* GetLocked(T*, ELockMode pLockMode=eReadWriteLock) {T v; return (T*)GetLocked(pLockMode, FbxTypeOf(v)); }
  396. /** Unlock the data buffer.
  397. * \param pDataPtr The buffer to be released.
  398. * \param pDataType The data type of the data buffer.
  399. * \remarks The passed pointer must be the one obtained by the call to GetLocked().
  400. * Any other pointer causes this method to fail and the Status is updated with
  401. * the reason for the failure. If the passed pointer refers a converted data
  402. * buffer (see comment of GetLocked), this method copies the GetCount() items
  403. * of the received buffer back into this object. Any other items that may have been added
  404. * using a realloc call are ignored.
  405. */
  406. virtual void Release(void** pDataPtr, EFbxType pDataType);
  407. /** Unlock the data buffer.
  408. * \param pDataPtr The buffer to be released.
  409. * \remarks The passed pointer must be the one obtained by the call to GetLocked().
  410. * Any other pointer causes this method to fail and the Status is updated with
  411. * the reason for the failure. If the passed pointer refers a converted data
  412. * buffer (see comment of GetLocked), this method copies the GetCount() items
  413. * of the received buffer back into this object. Any other items that may have been added
  414. * using a realloc call are ignored.
  415. */
  416. void Release(void** pDataPtr) { Release(pDataPtr, mDataType); }
  417. /** Unlock the data buffer.
  418. * \param pDataPtr The buffer to be released.
  419. * \param dummy The data type of dummy is used to specialize this function.
  420. * \remarks The passed pointer must be the one obtained by the call to GetLocked().
  421. * Any other pointer causes this method to fail and the Status is updated with
  422. * the reason for the failure. If the passed pointer refers a converted data
  423. * buffer (see comment of GetLocked), this method copies the GetCount() items
  424. * of the received buffer back into this object. Any other items that may have been added
  425. * using a realloc call are ignored.
  426. */
  427. template <class T> inline void Release(T** pDataPtr, T* dummy)
  428. {
  429. T*** voidPtr = &pDataPtr;
  430. Release((void**)*voidPtr, FbxTypeOf(*dummy));
  431. }
  432. /** Returns the Stride size which equals the size of the data type of the data buffer.
  433. */
  434. virtual size_t GetStride() const;
  435. /**
  436. * \name Data array manipulation
  437. */
  438. //@{
  439. //! Returns the count of items in the data buffer.
  440. int GetCount() const;
  441. /** Sets the count of items in the data buffer.
  442. * \param pCount The count of items to be set.
  443. */
  444. void SetCount(int pCount);
  445. //! Clears the data buffer.
  446. void Clear();
  447. /** Resizes the data buffer.
  448. * \param pItemCount The new size of the data buffer.
  449. */
  450. void Resize(int pItemCount);
  451. /** Appends space to the data buffer.
  452. * \param pItemCount The appended space size
  453. */
  454. void AddMultiple(int pItemCount);
  455. /** Appends a new item to the end of the data buffer.
  456. * \param pItem Pointer of the new item to be added
  457. * \param pValueType Data type of the new item
  458. * \return The index of the new item
  459. */
  460. int Add(const void* pItem, EFbxType pValueType);
  461. /** Inserts a new item at the specified position of the data buffer.
  462. * \param pIndex The specified position
  463. * \param pItem Pointer of the new item to be inserted
  464. * \param pValueType Data type of the new item
  465. * \return The index of the inserted item
  466. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  467. */
  468. int InsertAt(int pIndex, const void* pItem, EFbxType pValueType);
  469. /** Sets the value for the specified item.
  470. * \param pIndex The index of the item to be updated.
  471. * \param pItem Pointer of the item whose value is copied to pIndex'th item
  472. * \param pValueType Data type of the item
  473. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  474. */
  475. void SetAt(int pIndex, const void* pItem, EFbxType pValueType);
  476. /** Sets the value of the last item.
  477. * \param pItem Pointer of the item whose value is copied to the last item
  478. * \param pValueType Data type of the item
  479. * \remarks The array should contain at least one item and no error will be thrown if it is empty.
  480. */
  481. void SetLast(const void* pItem, EFbxType pValueType);
  482. /** Removes the specified item from the data buffer.
  483. * \param pIndex The index of the item to be removed
  484. * \param pItem Place to hold the value of the removed item.
  485. * \param pValueType Data type of the item
  486. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  487. */
  488. void RemoveAt(int pIndex, void** pItem, EFbxType pValueType);
  489. /** Removes the last item from the data buffer.
  490. * \param pItem Place to hold the value of the removed item.
  491. * \param pValueType Data type of the item
  492. * \remarks The array should contain at least one item and no error will be thrown if it is empty.
  493. */
  494. void RemoveLast(void** pItem, EFbxType pValueType);
  495. /** Removes one item from the data buffer.
  496. * \param pItem The first item who equals pItem is to be removed
  497. * \param pValueType Data type of the item
  498. * \return \c True if the item is removed successfully, \c false otherwise
  499. */
  500. bool RemoveIt(void** pItem, EFbxType pValueType);
  501. /** Returns the specified item's value.
  502. * \param pIndex Index of the item
  503. * \param pItem Place to hold the item's value
  504. * \param pValueType Data type of the item
  505. * \return \c True if the item's value is returned successfully, \c false otherwise
  506. * \remarks If the index is invalid, pItem is set to zero.
  507. */
  508. bool GetAt(int pIndex, void** pItem, EFbxType pValueType) const;
  509. /** Returns the first item's value.
  510. * \param pItem Place to hold the item's value
  511. * \param pValueType Data type of the item
  512. * \return \c True if the item's value is returned successfully, \c false otherwise
  513. */
  514. bool GetFirst(void** pItem, EFbxType pValueType) const;
  515. /** Returns the last item's value.
  516. * \param pItem Place to hold the item's value
  517. * \param pValueType Data type of the item
  518. * \return \c True if the item's value is returned successfully, \c false otherwise
  519. */
  520. bool GetLast(void** pItem, EFbxType pValueType) const;
  521. /** Searches for an item in the data buffer.
  522. * \param pItem The value of the item for which to search.
  523. * \param pValueType Data type of the item
  524. * \return The index of the item found, -1 if not found.
  525. * \remarks The index of the first item whose value equals pItem is returned.
  526. */
  527. int Find(const void* pItem, EFbxType pValueType) const;
  528. /** Searches for an item after the specified index in the data buffer.
  529. * \param pAfterIndex The specified index after which the searching begins
  530. * \param pItem The value of the item for which to search, the searching begins after pAfterIndex.
  531. * \param pValueType Data type of the item
  532. * \return The index of the item found, -1 if not found.
  533. * \remarks The index of the first item whose value equals pItem is returned.
  534. */
  535. int FindAfter(int pAfterIndex, const void* pItem, EFbxType pValueType) const;
  536. /** Searches for an item before the specified index in the data buffer.
  537. * \param pBeforeIndex The specified index before which the searching begins
  538. * \param pItem The value of the item for which to search, the searching begins before pBeforeIndex.
  539. * \param pValueType The item's data type.
  540. * \return The index of the item found, -1 if not found.
  541. * \remarks The index of the first item whose value equals pItem is returned.
  542. */
  543. int FindBefore(int pBeforeIndex, const void* pItem, EFbxType pValueType) const;
  544. /** Equivalence operator
  545. * \param pArray Array compared to this one
  546. * \return \c True if equal. \c false otherwise.
  547. */
  548. bool IsEqual(const FbxLayerElementArray& pArray) const;
  549. /** Appends a new item to the end of the data buffer.
  550. * \param pItem The new item to be added
  551. * \return The index of the new item
  552. */
  553. template <class T> inline int Add(T const& pItem) { return Add((const void*)&pItem, FbxTypeOf(pItem)); }
  554. /** Inserts a new item at the specified position of the data buffer.
  555. * \param pIndex The specified position
  556. * \param pItem The new item to be inserted
  557. * \return The index of the inserted item
  558. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  559. */
  560. template <class T> inline int InsertAt(int pIndex, T const& pItem) { return InsertAt(pIndex, (const void*)&pItem, FbxTypeOf(pItem)); }
  561. /** Sets the value of the specified item.
  562. * \param pIndex The index of the item to be updated.
  563. * \param pItem The item whose value is copied to pIndex'th item
  564. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  565. */
  566. template <class T> inline void SetAt(int pIndex, T const& pItem) { SetAt(pIndex, (const void*)&pItem, FbxTypeOf(pItem)); }
  567. /** Sets the value of the last item.
  568. * \param pItem The item whose value is copied to the last item
  569. * \remarks The array should contain at least one item and no error will be thrown if it is empty.
  570. */
  571. template <class T> inline void SetLast(T const& pItem) { SetLast((const void*)&pItem, FbxTypeOf(pItem)); }
  572. /** Removes the specified item from the data buffer.
  573. * \param pIndex The index of the item to be removed
  574. * \param pItem Place to hold the value of the removed item.
  575. * \remarks The input index must be within valid range and no error will be thrown if it is invalid.
  576. */
  577. template <class T> inline void RemoveAt(int pIndex, T* pItem)
  578. {
  579. T** voidPtr = &pItem;
  580. RemoveAt(pIndex, (void**)voidPtr, FbxTypeOf(*pItem));
  581. }
  582. /** Removes the last item from the data buffer.
  583. * \param pItem Place to hold the value of the removed item.
  584. * \remarks The array should contain at least one item and no error will be thrown if it is empty.
  585. */
  586. template <class T> inline void RemoveLast(T* pItem)
  587. {
  588. T** voidPtr = &pItem;
  589. RemoveLast((void**)voidPtr, FbxTypeOf(*pItem));
  590. }
  591. /** Removes one item from the data buffer.
  592. * \param pItem The first item who equals pItem is to be removed
  593. * \return \c True if the item is removed successfully, \c false otherwise
  594. */
  595. template <class T> inline bool RemoveIt(T* pItem)
  596. {
  597. T** voidPtr = &pItem;
  598. return RemoveIt((void**)voidPtr, FbxTypeOf(*pItem));
  599. }
  600. /** Returns the specified item's value.
  601. * \param pIndex Index of the item
  602. * \param pItem Place to hold the item's value
  603. * \return \c True if the item's value is returned successfully, \c false otherwise
  604. * \remarks If the index is invalid, pItem is set to zero.
  605. */
  606. template <class T> inline bool GetAt(int pIndex, T* pItem) const
  607. {
  608. T** voidPtr = &pItem;
  609. return GetAt(pIndex, (void**)voidPtr, FbxTypeOf(*pItem));
  610. }
  611. /** Returns the first item's value.
  612. * \param pItem Place to hold the item's value
  613. * \return \c True if the item's value is returned successfully, \c false otherwise
  614. */
  615. template <class T> inline bool GetFirst(T* pItem) const
  616. {
  617. T** voidPtr = &pItem;
  618. return GetFirst((void**)voidPtr, FbxTypeOf(*pItem));
  619. }
  620. /** Returns the last item's value.
  621. * \param pItem Place to hold the item's value
  622. * \return \c True if the item's value is returned successfully, \c false otherwise
  623. */
  624. template <class T> inline bool GetLast(T* pItem) const
  625. {
  626. T** voidPtr = &pItem;
  627. return GetLast((void**)voidPtr, FbxTypeOf(*pItem));
  628. }
  629. /** Searches for an item in the data buffer.
  630. * \param pItem The value of the item for which to search.
  631. * \return The index of the item found, -1 if not found.
  632. * \remarks The index of the first item whose value equals pItem is returned.
  633. */
  634. template <class T> inline int Find(T const& pItem) const { return Find((const void*)&pItem, FbxTypeOf(pItem)); }
  635. /** Searches for an item after the specified index in the data buffer.
  636. * \param pAfterIndex The specified index after which the searching begins
  637. * \param pItem The value of the item for which to search, the searching begins after pAfterIndex.
  638. * \return The index of the item found, -1 if not found.
  639. * \remarks The index of the first item whose value equals pItem is returned.
  640. */
  641. template <class T> inline int FindAfter(int pAfterIndex, T const& pItem) const { return FindAfter(pAfterIndex, (const void*)&pItem, FbxTypeOf(pItem)); }
  642. /** Searches for one item before the specified index in the data buffer.
  643. * \param pBeforeIndex The specified index before which the searching begins
  644. * \param pItem The value of the item for which to search, the searching begins before pBeforeIndex.
  645. * \return The index of the item found, -1 if not found.
  646. * \remarks The index of the first item whose value equals pItem is returned.
  647. */
  648. template <class T> inline int FindBefore(int pBeforeIndex, T const& pItem) const { return FindBefore(pBeforeIndex, (const void*)&pItem, FbxTypeOf(pItem)); }
  649. /** Copies the items in the data buffer to an array.
  650. * \param pDst The destination array where the items are to be copied.
  651. */
  652. template<typename T> inline void CopyTo(FbxArray<T>& pDst)
  653. {
  654. T src;
  655. T* srcPtr = &src;
  656. pDst.Clear();
  657. if (mDataType != FbxTypeOf(src))
  658. {
  659. SetStatus(LockAccessStatus::eUnsupportedDTConversion);
  660. return;
  661. }
  662. pDst.Resize(GetCount());
  663. for (int i = 0; i < GetCount(); i++)
  664. {
  665. if (GetAt(i, (void**)&srcPtr, mDataType))
  666. {
  667. pDst.SetAt(i, src);
  668. }
  669. }
  670. SetStatus(LockAccessStatus::eSuccess);
  671. }
  672. //@}
  673. protected:
  674. void* GetDataPtr();
  675. void* GetReference(int pIndex, EFbxType pValueType);
  676. void GetReferenceTo(int pIndex, void** pRef, EFbxType pValueType);
  677. inline void SetStatus(LockAccessStatus::ELockAccessStatus pVal) const
  678. {
  679. const_cast<FbxLayerElementArray*>(this)->mStatus = pVal;
  680. }
  681. void SetImplementation(void* pImplementation);
  682. inline void* GetImplementation() { return mImplementation; }
  683. virtual void ConvertDataType(EFbxType pDataType, void** pDataPtr, size_t* pStride);
  684. EFbxType mDataType;
  685. private:
  686. LockAccessStatus::ELockAccessStatus mStatus;
  687. int mReadLockCount;
  688. bool mWriteLock;
  689. void* mImplementation;
  690. size_t mStride;
  691. int mDirectLockOn;
  692. bool mDirectAccessOn;
  693. FbxArray<void*> mConvertedData;
  694. };
  695. /** \internal
  696. * This class provides simple RAII-style read locking of a FbxLayerElementArray object.
  697. */
  698. template <typename T>
  699. struct FbxLayerElementArrayReadLock
  700. {
  701. /** \internal
  702. * On construction, this class requires the read lock.
  703. */
  704. FbxLayerElementArrayReadLock(FbxLayerElementArray& pArray) : mArray(pArray)
  705. {
  706. mLockedData = mArray.GetLocked((T*)NULL, FbxLayerElementArray::eReadLock);
  707. }
  708. /** \internal
  709. * On destruction, this class releases the read lock.
  710. */
  711. ~FbxLayerElementArrayReadLock()
  712. {
  713. if( mLockedData )
  714. {
  715. mArray.Release((void **) &mLockedData);
  716. }
  717. }
  718. /** \internal
  719. * Retrieve the locked array data.
  720. */
  721. const T* GetData() const
  722. {
  723. return mLockedData;
  724. }
  725. private:
  726. FbxLayerElementArray& mArray;
  727. T* mLockedData;
  728. };
  729. class FbxLayerElementUserData;
  730. /** FbxLayerElementArrayTemplate provides data array manipulation of the data buffer for FbxLayerElement.
  731. * It is the subclass of FbxLayerElementArray.
  732. * \nosubgrouping
  733. */
  734. template <class T> class FbxLayerElementArrayTemplate : public FbxLayerElementArray
  735. {
  736. public:
  737. /** Constructor
  738. * \param pDataType The data type of the array items.
  739. */
  740. FbxLayerElementArrayTemplate(EFbxType pDataType) :
  741. FbxLayerElementArray(pDataType)
  742. {
  743. }
  744. /** Appends a new item to the end of the data buffer.
  745. * \param pItem The new item to be added
  746. * \return The index of the new item
  747. */
  748. inline int Add( T const &pItem ) { return FbxLayerElementArray::Add(pItem); }
  749. /** Inserts a new item at the specified position of the data buffer.
  750. * \param pIndex The specified position
  751. * \param pItem The new item to be inserted
  752. * \return The index of the inserted item
  753. */
  754. inline int InsertAt(int pIndex, T const &pItem) { return FbxLayerElementArray::InsertAt(pIndex, pItem); }
  755. /** Sets the value of the specified item.
  756. * \param pIndex The index of the item to be updated.
  757. * \param pItem The item whose value is copied to pIndex'th item
  758. */
  759. inline void SetAt(int pIndex, T const &pItem) { FbxLayerElementArray::SetAt(pIndex, pItem); }
  760. /** Sets the value of the last item.
  761. * \param pItem The item whose value is copied to the last item
  762. */
  763. inline void SetLast( T const &pItem) { FbxLayerElementArray::SetLast(pItem); }
  764. /** Removes the specified item from the data buffer.
  765. * \param pIndex The index of the item to be removed
  766. * \return The value of the item removed
  767. */
  768. inline T RemoveAt(int pIndex) { T lValue; FbxLayerElementArray::RemoveAt(pIndex, &lValue); return lValue; }
  769. /** Removes the last item from the data buffer.
  770. * \return The value of the last item removed
  771. */
  772. inline T RemoveLast() { T lValue; FbxLayerElementArray::RemoveLast(&lValue); return lValue; }
  773. /** Removes one item from the data buffer.
  774. * \param pItem The first item who equals pItem is to be removed
  775. * \return \c True if the item is removed successfully, \c false otherwise
  776. */
  777. inline bool RemoveIt(T const &pItem) { return FbxLayerElementArray::RemoveIt(&pItem); }
  778. /** Returns the specified item's value.
  779. * \param pIndex Index of the item
  780. * \return The value of the specified item
  781. * \remarks If the index is invalid, pItem is set to zero.
  782. */
  783. inline T GetAt(int pIndex) const { T lValue; FbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
  784. /** Returns the first item's value.
  785. * \return The first item's value.
  786. */
  787. inline T GetFirst() const { T lValue; FbxLayerElementArray::GetFirst(&lValue); return lValue; }
  788. /** Returns the last item's value.
  789. * \return The last item's value.
  790. */
  791. inline T GetLast() const { T lValue; FbxLayerElementArray::GetLast(&lValue); return lValue; }
  792. /** Searches for an item in the data buffer.
  793. * \param pItem The value of the item for which to search
  794. * \return The index of the item found, -1 if not found.
  795. * \remarks The index of the first item whose value equals pItem is returned.
  796. */
  797. inline int Find(T const &pItem) { return FbxLayerElementArray::Find(pItem); }
  798. /** Searches for an item after the specified index in the data buffer.
  799. * \param pAfterIndex The specified index after which the searching begins
  800. * \param pItem The value of the item for which to search, the searching begins after pAfterIndex.
  801. * \return The index of the item found, -1 if not found.
  802. * \remarks The index of the first item whose value equals pItem is returned.
  803. */
  804. inline int FindAfter(int pAfterIndex, T const &pItem) { return FbxLayerElementArray::FindAfter(pAfterIndex, pItem); }
  805. /** Searches for one item before the specified index in the data buffer.
  806. * \param pBeforeIndex The specified index before which the searching begins
  807. * \param pItem The value of the item for which to search, the searching begins before pBeforeIndex.
  808. * \return The index of the item found, -1 if not found.
  809. * \remarks The index of the first item whose value equals pItem is returned.
  810. */
  811. inline int FindBefore(int pBeforeIndex, T const &pItem) { return FbxLayerElementArray::FindBefore(pBeforeIndex, pItem); }
  812. /** Returns the specified item's value.
  813. * \param pIndex Index of the item
  814. * \return The value of the item
  815. * \remarks If the index is invalid, pItem is set to zero.
  816. */
  817. T operator[](int pIndex) const { T lValue; FbxLayerElementArray::GetAt(pIndex, &lValue); return lValue; }
  818. /** Assignment operator.
  819. * \param pArrayTemplate The source array whose items are copied to this array.
  820. */
  821. FbxLayerElementArray& operator=(const FbxArray<T>& pArrayTemplate)
  822. {
  823. SetStatus(LockAccessStatus::eNoWriteLock);
  824. if (WriteLock())
  825. {
  826. SetCount(pArrayTemplate.GetCount());
  827. for (int i = 0; i < pArrayTemplate.GetCount(); i++)
  828. SetAt(i, pArrayTemplate.GetAt(i));
  829. WriteUnlock();
  830. SetStatus(LockAccessStatus::eSuccess);
  831. }
  832. return *this;
  833. }
  834. /** Assignment operator.
  835. * \param pArrayTemplate The source array whose items are copied to this array.
  836. */
  837. FbxLayerElementArrayTemplate<T>& operator=(const FbxLayerElementArrayTemplate<T>& pArrayTemplate)
  838. {
  839. if ( this != &pArrayTemplate )
  840. {
  841. SetStatus(LockAccessStatus::eNoWriteLock);
  842. if (WriteLock())
  843. {
  844. SetCount(pArrayTemplate.GetCount());
  845. for (int i = 0; i < pArrayTemplate.GetCount(); i++)
  846. SetAt(i, pArrayTemplate.GetAt(i));
  847. WriteUnlock();
  848. SetStatus(LockAccessStatus::eSuccess);
  849. }
  850. }
  851. return *this;
  852. }
  853. private:
  854. // This one is not the best thing to do, but at least I don't get deprecated calls inside this file.
  855. // Note that FbxLayerElementUserData is kind of a weird class in the first place anyway. So either
  856. // we clean it up, or we live with this piece of code ;-)
  857. friend class FbxLayerElementUserData;
  858. T& AsReference(int pIndex) { T* v = (T*)FbxLayerElementArray::GetReference(pIndex, mDataType); return (v)?*v:dummy;}
  859. T dummy;
  860. };
  861. /** Remap the index array to a new EMappingMode
  862. * \param pLayerEl The layer element to remap
  863. * \param pNewMapping The new mapping mode
  864. * \param pIndexArray The index array to modify
  865. * \return return -1 if the layer element is FbxLayerElement::eDirect
  866. * 0 if layer element or index array is \c NULL and 1 if the remap is successful
  867. */
  868. extern FBXSDK_DLL int RemapIndexArrayTo(FbxLayerElement* pLayerEl,
  869. FbxLayerElement::EMappingMode pNewMapping,
  870. FbxLayerElementArrayTemplate<int>* pIndexArray);
  871. /** This class complements the FbxLayerElement class.
  872. * It provides interfaces to access the direct array and index array of different layer elements.
  873. * \nosubgrouping
  874. */
  875. template <class Type> class FbxLayerElementTemplate : public FbxLayerElement
  876. {
  877. public:
  878. /** Returns the direct array of Layer Elements.
  879. * \return A reference to the Layer Elements direct array.
  880. * \remarks You cannot put elements in the direct array when the reference mode is set to eIndex.
  881. */
  882. FbxLayerElementArrayTemplate<Type>& GetDirectArray() const
  883. {
  884. FBX_ASSERT(mReferenceMode == FbxLayerElement::eDirect || mReferenceMode == FbxLayerElement::eIndexToDirect);
  885. return *mDirectArray;
  886. }
  887. /** Returns the direct array of Layer Elements.
  888. * \return A reference to the Layer Elements direct array.
  889. * \remarks You cannot put elements in the direct array when the reference mode is set to eIndex.
  890. */
  891. FbxLayerElementArrayTemplate<Type>& GetDirectArray()
  892. {
  893. FBX_ASSERT(mReferenceMode == FbxLayerElement::eDirect || mReferenceMode == FbxLayerElement::eIndexToDirect);
  894. return *mDirectArray;
  895. }
  896. /** Returns the index array of Layer Elements.
  897. * \return A reference to the index array.
  898. * \remarks You cannot put elements in the index array when the mapping mode is set to eDirect.
  899. */
  900. FbxLayerElementArrayTemplate<int>& GetIndexArray() const
  901. {
  902. FBX_ASSERT(mReferenceMode == FbxLayerElement::eIndex || mReferenceMode == FbxLayerElement::eIndexToDirect);
  903. return *mIndexArray;
  904. }
  905. /** Returns the index array of Layer Elements.
  906. * \return A reference to the index array.
  907. * \remarks You cannot put elements in the index array when the mapping mode is set to eDirect.
  908. */
  909. FbxLayerElementArrayTemplate<int>& GetIndexArray()
  910. {
  911. FBX_ASSERT(mReferenceMode == FbxLayerElement::eIndex || mReferenceMode == FbxLayerElement::eIndexToDirect);
  912. return *mIndexArray;
  913. }
  914. /** Removes all elements from the direct and the index arrays.
  915. * \remarks This function fails if there is a lock on the arrays.
  916. * \return \c True if successful, \c false if a lock is present.
  917. */
  918. bool Clear()
  919. {
  920. bool ret = true;
  921. mDirectArray->Clear();
  922. ret = (mDirectArray->GetStatus() == LockAccessStatus::eSuccess);
  923. mIndexArray->Clear();
  924. ret |= (mIndexArray->GetStatus() == LockAccessStatus::eSuccess);
  925. return ret;
  926. }
  927. public:
  928. /** Equivalence operator.
  929. * \param pOther Another element compared to this object
  930. * \return \c True if equal, \c false if unequal.
  931. */
  932. bool operator==(const FbxLayerElementTemplate& pOther) const
  933. {
  934. bool ret = true;
  935. if (pOther.GetReferenceMode() == FbxLayerElement::eDirect ||
  936. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect)
  937. {
  938. const FbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
  939. if( directArray.GetCount() != mDirectArray->GetCount() ||
  940. !directArray.ReadLock() || !mDirectArray->ReadLock() )
  941. {
  942. ret = false;
  943. }
  944. if( ret && !mDirectArray->IsEqual(directArray) )
  945. ret = false;
  946. directArray.ReadUnlock();
  947. mDirectArray->ReadUnlock();
  948. }
  949. if (ret)
  950. {
  951. if (pOther.GetReferenceMode() == FbxLayerElement::eIndex ||
  952. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect)
  953. {
  954. const FbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
  955. if( indexArray.GetCount() != mIndexArray->GetCount() ||
  956. !indexArray.ReadLock() || !mIndexArray->ReadLock() )
  957. {
  958. ret = false;
  959. }
  960. if( ret && !mIndexArray->IsEqual(indexArray) )
  961. ret = false;
  962. indexArray.ReadUnlock();
  963. mIndexArray->ReadUnlock();
  964. }
  965. }
  966. if (ret == false)
  967. return false;
  968. return FbxLayerElement::operator==(pOther);
  969. }
  970. /** Assignment operator.
  971. * \param pOther Another element assigned to this one
  972. */
  973. FbxLayerElementTemplate& operator=( FbxLayerElementTemplate const& pOther )
  974. {
  975. FBX_ASSERT(mDirectArray != NULL);
  976. FBX_ASSERT(mIndexArray != NULL);
  977. if (pOther.GetReferenceMode() == FbxLayerElement::eDirect ||
  978. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect)
  979. {
  980. const FbxLayerElementArrayTemplate<Type>& directArray = pOther.GetDirectArray();
  981. *mDirectArray = directArray;
  982. }
  983. if (pOther.GetReferenceMode() == FbxLayerElement::eIndex ||
  984. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect)
  985. {
  986. const FbxLayerElementArrayTemplate<int>& indexArray = pOther.GetIndexArray();
  987. *mIndexArray = indexArray;
  988. }
  989. FbxLayerElement* myself = (FbxLayerElement*)this;
  990. FbxLayerElement* myOther = (FbxLayerElement*)&pOther;
  991. *myself = *myOther;
  992. return *this;
  993. }
  994. /** Changes the Mapping mode to the new one and re-computes the index array.
  995. * \param pNewMapping New mapping mode.
  996. * \return If the remapping is successful, returns 1.
  997. * If an error occurs, returns 0. In case the function cannot
  998. * remap to the desired mode because of incompatible modes or
  999. * unsupported modes, returns -1.
  1000. */
  1001. int RemapIndexTo(FbxLayerElement::EMappingMode pNewMapping)
  1002. {
  1003. return RemapIndexArrayTo(this, pNewMapping, mIndexArray);
  1004. }
  1005. /*****************************************************************************************************************************
  1006. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1007. *****************************************************************************************************************************/
  1008. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1009. protected:
  1010. FbxLayerElementTemplate()
  1011. {
  1012. mDirectArray = NULL;
  1013. mIndexArray = NULL;
  1014. }
  1015. ~FbxLayerElementTemplate()
  1016. {
  1017. FbxDelete(mDirectArray);
  1018. FbxDelete(mIndexArray);
  1019. }
  1020. virtual void AllocateArrays()
  1021. {
  1022. mDirectArray = FbxNew< FbxLayerElementArrayTemplate<Type> >(mType->GetType());
  1023. mIndexArray = FbxNew< FbxLayerElementArrayTemplate<int> >(FbxIntDT.GetType());
  1024. }
  1025. public:
  1026. virtual int MemorySize() const
  1027. {
  1028. int size = FbxLayerElement::MemorySize();
  1029. size += (mDirectArray->GetCount()*sizeof(Type));
  1030. size += (mIndexArray->GetCount()*sizeof(int));
  1031. return size;
  1032. }
  1033. /**
  1034. * \name Serialization section
  1035. */
  1036. //@{
  1037. virtual bool ContentWriteTo(FbxStream& pStream) const
  1038. {
  1039. void* a;
  1040. int s,v;
  1041. int count = 0;
  1042. // direct array
  1043. count = mDirectArray->GetCount();
  1044. s = pStream.Write(&count, sizeof(int));
  1045. if (s != sizeof(int)) return false;
  1046. if (count > 0)
  1047. {
  1048. a = mDirectArray->GetLocked();
  1049. FBX_ASSERT(a != NULL);
  1050. v = count*sizeof(Type);
  1051. s = pStream.Write(a, v);
  1052. mDirectArray->Release(&a);
  1053. if (s != v) return false;
  1054. }
  1055. // index array
  1056. count = mIndexArray->GetCount();
  1057. s = pStream.Write(&count, sizeof(int));
  1058. if (s != sizeof(int)) return false;
  1059. if (count > 0)
  1060. {
  1061. a = mIndexArray->GetLocked();
  1062. FBX_ASSERT(a != NULL);
  1063. v = count*sizeof(int);
  1064. s = pStream.Write(a, v);
  1065. mIndexArray->Release(&a);
  1066. if (s != v) return false;
  1067. }
  1068. return FbxLayerElement::ContentWriteTo(pStream);
  1069. }
  1070. virtual bool ContentReadFrom(const FbxStream& pStream)
  1071. {
  1072. void* a;
  1073. int s,v;
  1074. int count = 0;
  1075. // direct array
  1076. s = pStream.Read(&count, sizeof(int));
  1077. if (s != sizeof(int)) return false;
  1078. mDirectArray->Resize(count);
  1079. if (count > 0)
  1080. {
  1081. a = mDirectArray->GetLocked();
  1082. FBX_ASSERT(a != NULL);
  1083. v = count*sizeof(Type);
  1084. s = pStream.Read(a, v);
  1085. mDirectArray->Release(&a);
  1086. if (s != v) return false;
  1087. }
  1088. // index array
  1089. s = pStream.Read(&count, sizeof(int));
  1090. if (s != sizeof(int)) return false;
  1091. mIndexArray->Resize(count);
  1092. if (count > 0)
  1093. {
  1094. a = mIndexArray->GetLocked();
  1095. FBX_ASSERT(a != NULL);
  1096. v = count*sizeof(int);
  1097. s = pStream.Read(a, v);
  1098. mIndexArray->Release(&a);
  1099. if (s != v) return false;
  1100. }
  1101. return FbxLayerElement::ContentReadFrom(pStream);
  1102. }
  1103. //@}
  1104. typedef Type ArrayElementType;
  1105. typedef FbxLayerElementArrayTemplate<Type> DirectArrayType;
  1106. typedef FbxLayerElementArrayTemplate<int> IndexArrayType;
  1107. FbxLayerElementArrayTemplate<Type>* mDirectArray;
  1108. FbxLayerElementArrayTemplate<int>* mIndexArray;
  1109. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1110. };
  1111. #define FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(classDesc) \
  1112. FBXSDK_FRIEND_NEW(); \
  1113. static Fbx##classDesc* Create(FbxLayerContainer* pOwner, const char* pName);
  1114. /** \brief Layer element for mapping Normals to a geometry.
  1115. * \remarks To be correctly saved in FBX file, this type of Layer element should have its reference
  1116. * mode set to \e eIndexToDirect.
  1117. * \nosubgrouping
  1118. */
  1119. class FBXSDK_DLL FbxLayerElementNormal : public FbxLayerElementTemplate<FbxVector4>
  1120. {
  1121. public:
  1122. /** Allocation method.
  1123. * \return A pointer to the layer element or \c NULL if creation fails.
  1124. */
  1125. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementNormal);
  1126. protected:
  1127. FbxLayerElementNormal();
  1128. ~FbxLayerElementNormal();
  1129. };
  1130. /** \brief Layer element for mapping Binormals to a geometry.
  1131. * \nosubgrouping
  1132. */
  1133. class FBXSDK_DLL FbxLayerElementBinormal : public FbxLayerElementTemplate<FbxVector4>
  1134. {
  1135. public:
  1136. /** Allocation method.
  1137. * \return A pointer to the layer element or \c NULL if creation fails.
  1138. */
  1139. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementBinormal);
  1140. protected:
  1141. FbxLayerElementBinormal();
  1142. ~FbxLayerElementBinormal();
  1143. };
  1144. /** \brief Layer element for mapping Tangents to a geometry.
  1145. * \nosubgrouping
  1146. */
  1147. class FBXSDK_DLL FbxLayerElementTangent : public FbxLayerElementTemplate<FbxVector4>
  1148. {
  1149. public:
  1150. /** Allocation method.
  1151. * \return A pointer to the layer element or \c NULL if creation fails.
  1152. */
  1153. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementTangent);
  1154. protected:
  1155. FbxLayerElementTangent();
  1156. ~FbxLayerElementTangent();
  1157. };
  1158. /** Layer element for mapping materials (FbxSurfaceMaterial) to a geometry.
  1159. *
  1160. * FBX SDK 2011 and later connects materials (FbxSurfaceMaterial) to nodes (FbxNode).
  1161. * The direct array of this class is no longer used.
  1162. * The integer "n" in the index array of this class represents the n-th material (zero-based) connected to the node.
  1163. *
  1164. * For example:
  1165. *
  1166. * Mapping mode eAllSame and index array {0} means the whole geometry is assigned with the 0-th material
  1167. * connected to the node.
  1168. *
  1169. * Mapping mode eByPolygon and index array {0, 1} means the first polygon is assigned with the 0-th material and
  1170. * the second polygon is assigned with the 1-th material.
  1171. *
  1172. *
  1173. * You can access the materials from a node by using FbxNode::GetMaterialCount() and FbxNode::GetMaterial(int pIndex)
  1174. * or the more generic calls to GetSrcObjectCount<FbxSurfaceMaterial>() and
  1175. * GetSrcObject<FbxSurfaceMaterial>(index)
  1176. *
  1177. * For example:
  1178. *
  1179. * \code
  1180. * FbxNode* node;
  1181. * int nbMat = node->GetMaterialCount();
  1182. * int nbMat1= node->GetSrcObjectCount<FbxSurfaceMaterial>();
  1183. *
  1184. * FbxSurfaceMaterial* material;
  1185. * FbxLayerElementMaterial* layerElement;
  1186. * if (layerElement->GetMappingMode() == FbxLayerElement::eAllSame)
  1187. * {
  1188. * int index = layerElement->GetIndexArray()[0];
  1189. * material = node->GetMaterial(index);
  1190. * }
  1191. * \endcode
  1192. *
  1193. * \remarks
  1194. * The DirectArray() methods still exist for legacy reasons but has been made private and should not be used.
  1195. * Therefore, to be correctly saved in FBX file, this type of Layer element should have its reference
  1196. * mode set to \e eIndexToDirect.
  1197. *
  1198. * \see FbxSurfaceMaterial
  1199. * \see FbxNode
  1200. */
  1201. class FBXSDK_DLL FbxLayerElementMaterial : public FbxLayerElementTemplate<FbxSurfaceMaterial*>
  1202. {
  1203. public:
  1204. typedef FbxLayerElementTemplate<FbxSurfaceMaterial*> ParentClass;
  1205. /** Allocation method.
  1206. * \return A pointer to the layer element or \c NULL if creation fails.
  1207. */
  1208. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementMaterial);
  1209. /** \internal
  1210. * Internal class to maintain backward compatibility with old FBX code (prior to FBX SDK 2011).
  1211. * This class synchronizes the direct array with FbxNode connections.
  1212. * Thus, changes on the direct array will reflect on FbxNode.
  1213. */
  1214. class LayerElementArrayProxy : public FbxLayerElementArrayTemplate<FbxSurfaceMaterial*>
  1215. {
  1216. public:
  1217. typedef FbxLayerElementArrayTemplate<FbxSurfaceMaterial*> ParentClass;
  1218. LayerElementArrayProxy(EFbxType pType);
  1219. void SetContainer( FbxLayerContainer* pContainer, int pInstance = 0);
  1220. };
  1221. /*****************************************************************************************************************************
  1222. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1223. *****************************************************************************************************************************/
  1224. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1225. virtual void AllocateArrays();
  1226. virtual void SetOwner( FbxLayerContainer* pOwner, int pInstance = 0);
  1227. virtual void SetInstance( int pInstance ) { SetOwner( mOwner, pInstance ); }
  1228. protected:
  1229. FbxLayerElementMaterial();
  1230. ~FbxLayerElementMaterial();
  1231. private:
  1232. FbxLayerElementArrayTemplate<FbxSurfaceMaterial*>& GetDirectArray() const
  1233. {
  1234. return ParentClass::GetDirectArray();
  1235. }
  1236. FbxLayerElementArrayTemplate<FbxSurfaceMaterial*>& GetDirectArray()
  1237. {
  1238. return ParentClass::GetDirectArray();
  1239. }
  1240. friend class FbxLayerContainer;
  1241. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1242. };
  1243. /** \brief Layer element for grouping related polygons together.
  1244. * \remarks To be correctly saved in FBX file, this type of Layer element should have its reference
  1245. * mode set to \e eIndexToDirect.
  1246. * \nosubgrouping
  1247. */
  1248. class FBXSDK_DLL FbxLayerElementPolygonGroup : public FbxLayerElementTemplate<int>
  1249. {
  1250. public:
  1251. /** Allocation method.
  1252. * \return A pointer to the layer element or \c NULL if creation fails.
  1253. */
  1254. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementPolygonGroup);
  1255. protected:
  1256. FbxLayerElementPolygonGroup();
  1257. ~FbxLayerElementPolygonGroup();
  1258. };
  1259. /** \brief Layer element for mapping UVs to a geometry.
  1260. *
  1261. * This class represents a UV set belongs to a geometry. Each UV set in a geometry
  1262. * has a name to identify itself. The string property FbxTexture.UVSet indicates
  1263. * the UV set to use.
  1264. *
  1265. * \remarks if the Mapping mode of this LayerElement is \e eNone, the stored data
  1266. * should be treated as irrelevant. In some circumstances, you can still send this data
  1267. * to systems that cannot function without UV coordinates, but ensure
  1268. * that you have enough coordinates to do so.
  1269. *
  1270. * \see FbxTexture
  1271. * \nosubgrouping
  1272. */
  1273. class FBXSDK_DLL FbxLayerElementUV : public FbxLayerElementTemplate<FbxVector2>
  1274. {
  1275. public:
  1276. /** Allocation method.
  1277. * \return A pointer to the layer element or \c NULL if creation fails.
  1278. */
  1279. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementUV);
  1280. protected:
  1281. FbxLayerElementUV();
  1282. ~FbxLayerElementUV();
  1283. };
  1284. /** \brief Layer element for mapping Vertex Colors to a geometry.
  1285. * \nosubgrouping
  1286. */
  1287. class FBXSDK_DLL FbxLayerElementVertexColor : public FbxLayerElementTemplate<FbxColor>
  1288. {
  1289. public:
  1290. /** Allocation method.
  1291. * \return A pointer to the layer element or \c NULL if creation fails.
  1292. */
  1293. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementVertexColor);
  1294. protected:
  1295. FbxLayerElementVertexColor();
  1296. ~FbxLayerElementVertexColor();
  1297. };
  1298. template <class T> inline FbxLayerElementArrayTemplate<T>& FbxGetDirectArray(FbxLayerElementUserData *pLayerElement, int pIndex, bool* pStatus = NULL);
  1299. template <class T> inline FbxLayerElementArrayTemplate<T> const& FbxGetDirectArray(FbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus = NULL);
  1300. template <class T> inline FbxLayerElementArrayTemplate<T>& FbxGetDirectArray(FbxLayerElementUserData *pLayerElement, const char* pName, bool* pStatus = NULL );
  1301. template <class T> inline FbxLayerElementArrayTemplate<T> const& FbxGetDirectArray(FbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus = NULL );
  1302. /** \brief Layer element for mapping custom user data to a geometry.
  1303. * This layer element is different from the other types of layer elements in that it has multiple direct arrays. There is one array for each user data attribute.
  1304. * Each array is indexed by the index array.
  1305. * \nosubgrouping
  1306. */
  1307. class FBXSDK_DLL FbxLayerElementUserData : public FbxLayerElementTemplate<void*>
  1308. {
  1309. public:
  1310. FBXSDK_FRIEND_NEW();
  1311. /** Allocation method.
  1312. * \param pOwner The owner of this layer element.
  1313. * \param pName The layer element name.
  1314. * \param pId The layer element ID.
  1315. * \param pDataTypes Attribute data types of this layer element, one direct array is allocated for each Attribute data type.
  1316. * \param pDataNames Attribute names of this layer element.
  1317. * \return A pointer to the layer element or \c NULL if creation fails.
  1318. * \remarks Only "bool", "int", "float" and "double" are supported.
  1319. */
  1320. static FbxLayerElementUserData* Create(FbxLayerContainer* pOwner, const char* pName, int pId, FbxArray<FbxDataType>& pDataTypes, FbxArray<const char*>& pDataNames);
  1321. /** Allocation method.
  1322. * \param pOwner The owner of this layer element.
  1323. * \param pOther Other layer element from which to copy.
  1324. * \return A pointer to the layer element or \c NULL if creation fails.
  1325. */
  1326. static FbxLayerElementUserData* Create(FbxLayerContainer* pOwner, FbxLayerElementUserData const& pOther );
  1327. /** Returns the direct array with the specified attribute index.
  1328. * \param pIndex Specified attribute index.
  1329. * \param pStatus A flag to indicate whether the direct array is returned successfully or not.
  1330. * \return The specified attribute's direct array.
  1331. */
  1332. FbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL)
  1333. {
  1334. if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
  1335. {
  1336. if (pStatus) *pStatus = true;
  1337. return (FbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
  1338. }
  1339. else
  1340. {
  1341. if( pStatus ) *pStatus = false;
  1342. FBX_ASSERT_NOW("Index out of bounds");
  1343. return (FbxLayerElementArrayTemplate<void*>*)NULL;
  1344. }
  1345. }
  1346. /** Returns the direct array with the specified attribute index.
  1347. * \param pIndex Specified attribute index.
  1348. * \param pStatus A flag to indicate whether the direct array is returned successfully or not.
  1349. * \return The specified attribute's direct array.
  1350. */
  1351. const FbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid( int pIndex, bool* pStatus = NULL) const
  1352. {
  1353. if( pIndex >= 0 || pIndex < GetDirectArray().GetCount() )
  1354. {
  1355. if (pStatus) *pStatus = true;
  1356. return (FbxLayerElementArrayTemplate<void*>*)GetDirectArray().AsReference(pIndex);
  1357. }
  1358. else
  1359. {
  1360. if( pStatus ) *pStatus = false;
  1361. FBX_ASSERT_NOW("Index out of bounds");
  1362. return (const FbxLayerElementArrayTemplate<void*>*)NULL;
  1363. }
  1364. }
  1365. /** Returns the direct array with the specified attribute name.
  1366. * \param pName Specified attribute name.
  1367. * \param pStatus A flag to indicate whether the direct array is returned successfully or not.
  1368. * \return The specified attribute's direct array.
  1369. */
  1370. FbxLayerElementArrayTemplate<void *>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL )
  1371. {
  1372. FbxString lName( pName );
  1373. for( int i = 0; i < mDataNames.GetCount(); ++i )
  1374. {
  1375. if( *mDataNames[i] == lName )
  1376. return GetDirectArrayVoid(i, pStatus);
  1377. }
  1378. if (pStatus) *pStatus = false;
  1379. return (FbxLayerElementArrayTemplate<void *>*)NULL;
  1380. }
  1381. /** Returns the direct array with the specified attribute name.
  1382. * \param pName Specified attribute name.
  1383. * \param pStatus A flag to indicate whether the direct array is returned successfully or not.
  1384. * \return The specified attribute's direct array.
  1385. */
  1386. const FbxLayerElementArrayTemplate<void*>* GetDirectArrayVoid ( const char* pName, bool* pStatus = NULL ) const
  1387. {
  1388. FbxString lName( pName );
  1389. for( int i = 0; i < mDataNames.GetCount(); ++i )
  1390. {
  1391. if( *mDataNames[i] == lName )
  1392. return GetDirectArrayVoid(i, pStatus);
  1393. }
  1394. if (pStatus) *pStatus = false;
  1395. return (const FbxLayerElementArrayTemplate<void*>*)NULL;
  1396. }
  1397. /** Returns the data type for the specified index
  1398. * \param pIndex The index of the attribute being queried
  1399. * \return The data type, or FbxUndefinedDT if pIndex is out of range
  1400. */
  1401. FbxDataType GetDataType( int pIndex ) const
  1402. {
  1403. if( pIndex < 0 || pIndex >= mDataTypes.GetCount() )
  1404. return FbxUndefinedDT;
  1405. return mDataTypes[pIndex];
  1406. }
  1407. /** Returns the specified attribute data type.
  1408. * \param pName The name of the attribute being queried
  1409. * \return The data type, or FbxUndefinedDT if no attribute has the given name
  1410. */
  1411. FbxDataType GetDataType( const char* pName ) const
  1412. {
  1413. FbxString lName( pName );
  1414. for( int i = 0; i < mDataNames.GetCount(); ++i )
  1415. {
  1416. if( *mDataNames[i] == lName )
  1417. return mDataTypes[i];
  1418. }
  1419. return FbxUndefinedDT;
  1420. }
  1421. /** Returns the attribute name at the specified index
  1422. * \param pIndex Attribute index
  1423. * \return The name, or \c NULL if pIndex is out of range.
  1424. */
  1425. const char* GetDataName( int pIndex ) const
  1426. {
  1427. if( pIndex >= 0 && pIndex < mDataNames.GetCount() )
  1428. return mDataNames[pIndex]->Buffer();
  1429. return NULL;
  1430. }
  1431. /** Resizes all direct arrays to the specified size.
  1432. * \param pSize The new size of the direct arrays.
  1433. */
  1434. void ResizeAllDirectArrays( int pSize )
  1435. {
  1436. for( int i = 0; i < GetDirectArray().GetCount(); ++i )
  1437. {
  1438. switch( mDataTypes[i].GetType() )
  1439. {
  1440. case eFbxBool: FbxGetDirectArray<bool>(this,i).Resize( pSize ) ; break;
  1441. case eFbxInt: FbxGetDirectArray<int>(this,i).Resize( pSize ) ; break;
  1442. case eFbxFloat: FbxGetDirectArray<float>(this,i).Resize( pSize ) ; break;
  1443. case eFbxDouble: FbxGetDirectArray<double>(this,i).Resize( pSize ); break;
  1444. //case eFbxDouble3: GetDirectArray< FbxDouble3 >(i).Resize( pSize ); break;
  1445. //case eFbxDouble4: GetDirectArray< FbxDouble4 >(i).Resize( pSize ); break;
  1446. //case eFbxDouble4x4: GetDirectArray< FbxDouble4x4>(i).Resize( pSize ); break;
  1447. default:
  1448. FBX_ASSERT_NOW("unknown type" ); break;
  1449. }
  1450. }
  1451. }
  1452. /** Removes a single element at pIndex from every direct array.
  1453. * \param pIndex The index of the element to be removed.
  1454. */
  1455. void RemoveFromAllDirectArrays( int pIndex )
  1456. {
  1457. for( int i = 0; i < GetDirectArray().GetCount(); ++i )
  1458. {
  1459. switch( mDataTypes[i].GetType() )
  1460. {
  1461. case eFbxBool: FbxGetDirectArray<bool>(this,i).RemoveAt( pIndex ) ; break;
  1462. case eFbxInt: FbxGetDirectArray<int>(this,i).RemoveAt( pIndex ) ; break;
  1463. case eFbxFloat: FbxGetDirectArray<float>(this,i).RemoveAt( pIndex ) ; break;
  1464. case eFbxDouble: FbxGetDirectArray<double>(this,i).RemoveAt( pIndex ); break;
  1465. //case eFbxDouble3: GetDirectArray< FbxDouble3 >(i).RemoveAt( pIndex ); break;
  1466. //case eFbxDouble4: GetDirectArray< FbxDouble4 >(i).RemoveAt( pIndex ); break;
  1467. //case eFbxDouble4x4: GetDirectArray< FbxDouble4x4>(i).RemoveAt( pIndex ); break;
  1468. default:
  1469. FBX_ASSERT_NOW("unknown type" ); break;
  1470. }
  1471. }
  1472. }
  1473. /** Returns the direct array count for the attribute at pIndex
  1474. * \param pIndex The attribute index
  1475. * \return The specified attribute's direct array count.
  1476. */
  1477. int GetArrayCount( int pIndex ) const
  1478. {
  1479. if( pIndex >= 0 && pIndex < GetDirectArray().GetCount() )
  1480. {
  1481. switch( mDataTypes[pIndex].GetType() )
  1482. {
  1483. case eFbxBool: return FbxGetDirectArray<bool>(this,pIndex).GetCount();
  1484. case eFbxInt: return FbxGetDirectArray<int>(this,pIndex).GetCount();
  1485. case eFbxFloat: return FbxGetDirectArray<float>(this,pIndex).GetCount();
  1486. case eFbxDouble: return FbxGetDirectArray<double>(this,pIndex).GetCount();
  1487. //case eFbxDouble3: return GetDirectArray< FbxDouble3 >(pIndex).GetCount();
  1488. //case eFbxDouble4: return GetDirectArray< FbxDouble4 >(pIndex).GetCount();
  1489. //case eFbxDouble4x4: return GetDirectArray< FbxDouble4x4>(pIndex).GetCount();
  1490. default:
  1491. FBX_ASSERT_NOW("Unknown type" ); break;
  1492. }
  1493. }
  1494. return -1;
  1495. }
  1496. /** Queries the this layer element's ID.
  1497. * \return The ID expressed as an int
  1498. */
  1499. int GetId() const { return mId; }
  1500. /** Returns this layer element's direct array count.
  1501. * \return The direct array count expressed as an int.
  1502. * \remarks This count should be equal to the count of user data attributes.
  1503. */
  1504. int GetDirectArrayCount() const { return GetDirectArray().GetCount(); }
  1505. /** Assignment operator which performs a deep copy.
  1506. * \param pOther Other FbxLayerElementUserData from which to perform a deep copy.
  1507. * \return This FbxLayerElementUserData.
  1508. */
  1509. FbxLayerElementUserData& operator=( FbxLayerElementUserData const& pOther )
  1510. {
  1511. if (this == &pOther)
  1512. return *this;
  1513. Clear();
  1514. mId = pOther.mId;
  1515. mDataTypes = pOther.mDataTypes;
  1516. mDataNames.Resize(pOther.mDataNames.GetCount());
  1517. for(int i = 0; i < pOther.mDataNames.GetCount(); ++i)
  1518. mDataNames.SetAt(i, FbxNew< FbxString >( *pOther.mDataNames[i] ) );
  1519. Init();
  1520. for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
  1521. {
  1522. switch (mDataTypes[i].GetType())
  1523. {
  1524. case eFbxBool:
  1525. FbxGetDirectArray<bool>(this, i) = FbxGetDirectArray<bool>(&pOther, i);
  1526. break;
  1527. case eFbxInt:
  1528. FbxGetDirectArray<int>(this, i) = FbxGetDirectArray<int>(&pOther, i);
  1529. break;
  1530. case eFbxFloat:
  1531. FbxGetDirectArray<float>(this, i) = FbxGetDirectArray<float>(&pOther, i);
  1532. break;
  1533. case eFbxDouble:
  1534. FbxGetDirectArray<double>(this, i) = FbxGetDirectArray<double>(&pOther, i);
  1535. break;
  1536. default:
  1537. FBX_ASSERT_NOW("Unknown type" );
  1538. break;
  1539. }
  1540. }
  1541. if ( ( mReferenceMode == FbxLayerElement::eIndex ||
  1542. mReferenceMode == FbxLayerElement::eIndexToDirect) &&
  1543. ( pOther.GetReferenceMode() == FbxLayerElement::eIndex ||
  1544. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect))
  1545. {
  1546. GetIndexArray() = pOther.GetIndexArray();
  1547. }
  1548. return *this;
  1549. }
  1550. /** Removes all data from this layer element.
  1551. * \return \c True always
  1552. */
  1553. bool Clear()
  1554. {
  1555. int i;
  1556. const int lCount = GetDirectArray().GetCount();
  1557. FbxLayerElementArray** directArray = NULL;
  1558. directArray = GetDirectArray().GetLocked(directArray);
  1559. for( i = 0; directArray != NULL && i < lCount; ++i )
  1560. {
  1561. if( directArray[i] )
  1562. FbxDelete(directArray[i]);
  1563. }
  1564. FbxLayerElementArray*** ptr = &directArray;
  1565. GetDirectArray().Release((void**)ptr);
  1566. for( i = 0; i < mDataNames.GetCount(); ++i )
  1567. {
  1568. FBX_SAFE_DELETE(mDataNames[i]);
  1569. }
  1570. mDataNames.Clear();
  1571. mDataTypes.Clear();
  1572. FbxLayerElementTemplate<void*>::Clear();
  1573. return true;
  1574. }
  1575. /** Queries the amount of memory used by this
  1576. * object as well as its content. It does not consider the content pointed.
  1577. * \return The amount of memory used.
  1578. */
  1579. virtual int MemorySize() const
  1580. {
  1581. int size = FbxLayerElementTemplate<void*>::MemorySize();
  1582. size += sizeof(mId);
  1583. for(int i = 0; i < mDataTypes.GetCount(); i++)
  1584. {
  1585. size += sizeof(mDataTypes[i]);
  1586. }
  1587. size += (mDataNames.GetCount() * sizeof(FbxString*));
  1588. return size;
  1589. }
  1590. /*****************************************************************************************************************************
  1591. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1592. *****************************************************************************************************************************/
  1593. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1594. protected:
  1595. /**
  1596. * \name Constructor and Destructor.
  1597. */
  1598. //@{
  1599. /** Constructs a user data layer element.
  1600. * \param pId An identifier for this UserData layer element
  1601. * \param pDataTypes Attribute data types for this layer element
  1602. * \param pDataNames Attribute names for this layer element
  1603. */
  1604. FbxLayerElementUserData( int pId, FbxArray<FbxDataType>& pDataTypes, FbxArray<const char*>& pDataNames )
  1605. :
  1606. mId( pId ),
  1607. mDataTypes( pDataTypes )
  1608. {
  1609. FBX_ASSERT( pDataTypes.GetCount() == pDataNames.GetCount() );
  1610. for( int i = 0; i < pDataNames.GetCount(); ++i )
  1611. {
  1612. mDataNames.Add( FbxNew< FbxString >( pDataNames[i] ) );
  1613. }
  1614. }
  1615. /** Copy constructor. A deep copy is made.
  1616. * \param pOther Another FbxLayerElementUserData object to be copied.
  1617. */
  1618. FbxLayerElementUserData( FbxLayerElementUserData const& pOther ) : mId(pOther.mId), mDataTypes(pOther.mDataTypes)
  1619. {
  1620. for (int lIndex = 0; lIndex < pOther.mDataNames.GetCount(); ++lIndex)
  1621. {
  1622. mDataNames.Add(FbxNew<FbxString>(*(pOther.mDataNames[lIndex])));
  1623. }
  1624. SetType(&FbxLayerElementUserDataDT);
  1625. AllocateArrays();
  1626. for(int i = 0; i < pOther.GetDirectArrayCount(); ++i)
  1627. {
  1628. switch (mDataTypes[i].GetType())
  1629. {
  1630. case eFbxBool:
  1631. FbxGetDirectArray<bool>(this, i) = FbxGetDirectArray<bool>(&pOther, i);
  1632. break;
  1633. case eFbxInt:
  1634. FbxGetDirectArray<int>(this, i) = FbxGetDirectArray<int>(&pOther, i);
  1635. break;
  1636. case eFbxFloat:
  1637. FbxGetDirectArray<float>(this, i) = FbxGetDirectArray<float>(&pOther, i);
  1638. break;
  1639. case eFbxDouble:
  1640. FbxGetDirectArray<double>(this, i) = FbxGetDirectArray<double>(&pOther, i);
  1641. break;
  1642. default:
  1643. FBX_ASSERT_NOW("Unknown type" );
  1644. break;
  1645. }
  1646. }
  1647. if ( ( mReferenceMode == FbxLayerElement::eIndex ||
  1648. mReferenceMode == FbxLayerElement::eIndexToDirect) &&
  1649. ( pOther.GetReferenceMode() == FbxLayerElement::eIndex ||
  1650. pOther.GetReferenceMode() == FbxLayerElement::eIndexToDirect))
  1651. {
  1652. GetIndexArray() = pOther.GetIndexArray();
  1653. }
  1654. }
  1655. //!Destructor.
  1656. ~FbxLayerElementUserData()
  1657. {
  1658. Clear();
  1659. }
  1660. //@}
  1661. virtual void AllocateArrays()
  1662. {
  1663. FbxLayerElementTemplate<void*>::AllocateArrays();
  1664. Init();
  1665. }
  1666. private:
  1667. void Init()
  1668. {
  1669. int i;
  1670. GetDirectArray().Resize( mDataTypes.GetCount() );
  1671. // initialize arrays
  1672. for( i = 0; i < mDataTypes.GetCount(); ++i )
  1673. {
  1674. FbxHandle** dst = NULL;
  1675. dst = GetDirectArray().GetLocked(dst);
  1676. if (dst)
  1677. {
  1678. switch( mDataTypes[i].GetType() )
  1679. {
  1680. case eFbxBool: dst[i] = (FbxHandle*)FbxNew< FbxLayerElementArrayTemplate<bool> >(mDataTypes[i].GetType()); break;
  1681. case eFbxInt: dst[i] = (FbxHandle*)FbxNew< FbxLayerElementArrayTemplate<int> >(mDataTypes[i].GetType()); break;
  1682. case eFbxFloat: dst[i] = (FbxHandle*)FbxNew< FbxLayerElementArrayTemplate<float> >(mDataTypes[i].GetType()); break;
  1683. case eFbxDouble: dst[i] = (FbxHandle*)FbxNew< FbxLayerElementArrayTemplate<double> >(mDataTypes[i].GetType()); break;
  1684. default:
  1685. FBX_ASSERT_NOW("Trying to assign an unknown type" ); break;
  1686. }
  1687. FbxHandle*** ptr = &dst;
  1688. GetDirectArray().Release((void**)ptr);
  1689. }
  1690. }
  1691. }
  1692. int mId;
  1693. FbxArray<FbxDataType> mDataTypes;
  1694. FbxArray<FbxString*> mDataNames;
  1695. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1696. };
  1697. /** Returns the direct array with the given attribute index. The template type must match the attribute type at pIndex.
  1698. * \param pLayerElement The layer element whose direct array to return.
  1699. * \param pIndex The direct array index
  1700. * \param pStatus Will be set to \c false if accessing the direct array encounters an error.
  1701. * \return If pStatus receives \c true, the direct array at the given index is
  1702. * returned. Otherwise the return value is \c undefined.
  1703. */
  1704. template <class T>
  1705. inline FbxLayerElementArrayTemplate<T>& FbxGetDirectArray( FbxLayerElementUserData *pLayerElement,int pIndex, bool* pStatus)
  1706. {
  1707. return *(FbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
  1708. }
  1709. /** Returns the direct array with the given attribute index. The template type must match the attribute type at pIndex.
  1710. * \param pLayerElement The layer element whose direct array to return.
  1711. * \param pIndex The direct array index
  1712. * \param pStatus Will be set to \c false if accessing the direct array encounters an error.
  1713. * \return If pStatus receives \c true, the direct array at the given index is
  1714. * returned. Otherwise the return value is \c undefined.
  1715. */
  1716. template <class T>
  1717. inline FbxLayerElementArrayTemplate<T> const& FbxGetDirectArray(FbxLayerElementUserData const *pLayerElement, int pIndex, bool* pStatus)
  1718. {
  1719. return *(const FbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pIndex,pStatus);
  1720. }
  1721. /** Returns the direct array with the given attribute name.The template type must match the attribute type with pName.
  1722. * \param pLayerElement The layer element whose direct array to return.
  1723. * \param pName The given attribute name.
  1724. * \param pStatus Will be set to false if accessing the direct array encounters an error.
  1725. * \return If pStatus receives \c true, the direct array at the given index is
  1726. * returned. Otherwise the return value is \c undefined.
  1727. */
  1728. template <class T>
  1729. inline FbxLayerElementArrayTemplate<T>& FbxGetDirectArray( FbxLayerElementUserData *pLayerElement,const char* pName, bool* pStatus )
  1730. {
  1731. return *(FbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
  1732. }
  1733. /** Returns the direct array with the given attribute name.The template type must match the attribute type with pName.
  1734. * \param pLayerElement The layer element whose direct array to return.
  1735. * \param pName The given attribute name.
  1736. * \param pStatus Will be set to false if accessing the direct array encounters an error.
  1737. * \return If pStatus receives \c true, the direct array at the given index is
  1738. * returned. Otherwise the return value is \c undefined.
  1739. */
  1740. template <class T>
  1741. inline FbxLayerElementArrayTemplate<T> const& FbxGetDirectArray(FbxLayerElementUserData const *pLayerElement, const char* pName, bool* pStatus )
  1742. {
  1743. return *(const FbxLayerElementArrayTemplate<T>*)pLayerElement->GetDirectArrayVoid(pName,pStatus);
  1744. }
  1745. /** Layer element for indicating smoothness of components of a geometry.
  1746. * \remarks To be correctly saved in FBX file, this type of Layer element should have its reference
  1747. * mode set to \e eDirect.
  1748. *
  1749. * \nosubgrouping
  1750. */
  1751. class FBXSDK_DLL FbxLayerElementSmoothing : public FbxLayerElementTemplate<int>
  1752. {
  1753. public:
  1754. FBXSDK_FRIEND_NEW();
  1755. /** Allocation method.
  1756. * \param pOwner The owner of this layer element.
  1757. * \param pName The name of this layer element.
  1758. * \return A pointer to the layer element or \c NULL if creation fails.
  1759. */
  1760. static FbxLayerElementSmoothing* Create(FbxLayerContainer* pOwner, const char* pName);
  1761. /** Sets the Reference Mode.
  1762. * \param pMode Specifies the reference mode.
  1763. * \remarks Only support eDirect.
  1764. */
  1765. void SetReferenceMode( FbxLayerElement::EReferenceMode pMode )
  1766. {
  1767. if( pMode != FbxLayerElement::eDirect )
  1768. {
  1769. FBX_ASSERT_NOW( "Smoothing layer elements must be direct mapped" );
  1770. return;
  1771. }
  1772. }
  1773. /*****************************************************************************************************************************
  1774. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1775. *****************************************************************************************************************************/
  1776. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1777. protected:
  1778. FbxLayerElementSmoothing()
  1779. {
  1780. mReferenceMode = FbxLayerElement::eDirect;
  1781. }
  1782. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1783. };
  1784. /** Layer element for indicating crease of components of a geometry.
  1785. * \nosubgrouping
  1786. */
  1787. class FBXSDK_DLL FbxLayerElementCrease : public FbxLayerElementTemplate<double>
  1788. {
  1789. public:
  1790. FBXSDK_FRIEND_NEW();
  1791. /** Allocation method.
  1792. * \param pOwner The owner of this layer element.
  1793. * \param pName The name of this layer element.
  1794. * \return A pointer to the layer element or \c NULL if creation fails.
  1795. */
  1796. static FbxLayerElementCrease* Create(FbxLayerContainer* pOwner, const char* pName);
  1797. /** Sets the Reference Mode.
  1798. * \param pMode Specifies the reference mode.
  1799. * \remarks Only support eDirect.
  1800. */
  1801. void SetReferenceMode( FbxLayerElement::EReferenceMode pMode )
  1802. {
  1803. if( pMode != FbxLayerElement::eDirect )
  1804. {
  1805. FBX_ASSERT_NOW( "Crease layer elements must be direct mapped" );
  1806. return;
  1807. }
  1808. }
  1809. /*****************************************************************************************************************************
  1810. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1811. *****************************************************************************************************************************/
  1812. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1813. protected:
  1814. FbxLayerElementCrease()
  1815. {
  1816. mReferenceMode = FbxLayerElement::eDirect;
  1817. }
  1818. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1819. };
  1820. /** Layer element for indicating hole of polygon of a geometry.
  1821. * \nosubgrouping
  1822. */
  1823. class FBXSDK_DLL FbxLayerElementHole : public FbxLayerElementTemplate<bool>
  1824. {
  1825. public:
  1826. FBXSDK_FRIEND_NEW();
  1827. /** Allocation method.
  1828. * \param pOwner The owner of this layer element.
  1829. * \param pName The name of this layer element.
  1830. * \return A pointer to the layer element or \c NULL if creation fails.
  1831. */
  1832. static FbxLayerElementHole* Create(FbxLayerContainer* pOwner, const char* pName);
  1833. /** Sets the Reference Mode.
  1834. * \param pMode Specifies the reference mode.
  1835. * \remarks Only support eDirect.
  1836. */
  1837. void SetReferenceMode( FbxLayerElement::EReferenceMode pMode )
  1838. {
  1839. if( pMode != FbxLayerElement::eDirect )
  1840. {
  1841. FBX_ASSERT_NOW( "hole layer elements must be direct mapped" );
  1842. return;
  1843. }
  1844. }
  1845. /*****************************************************************************************************************************
  1846. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1847. *****************************************************************************************************************************/
  1848. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1849. protected:
  1850. FbxLayerElementHole()
  1851. {
  1852. mReferenceMode = FbxLayerElement::eDirect;
  1853. }
  1854. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1855. };
  1856. /** Layer element for indicating if specified components are shown/hidden
  1857. */
  1858. class FBXSDK_DLL FbxLayerElementVisibility : public FbxLayerElementTemplate<bool>
  1859. {
  1860. public:
  1861. /** Allocation method.
  1862. * \return A pointer to the layer element or \c NULL if creation fails.
  1863. */
  1864. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementVisibility);
  1865. /*****************************************************************************************************************************
  1866. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1867. *****************************************************************************************************************************/
  1868. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1869. protected:
  1870. FbxLayerElementVisibility();
  1871. ~FbxLayerElementVisibility();
  1872. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  1873. };
  1874. /** \brief Layer element for mapping Textures to a geometry. This class is deprecated.
  1875. *
  1876. * Deprecated since FBX SDK 2011. Textures (FbxTexture derived classes) should be connected
  1877. * to material properties.
  1878. *
  1879. * For example:
  1880. *
  1881. * \code
  1882. * FbxFileTexture* file;
  1883. * FbxSurfacePhong* phong;
  1884. * phong->Diffuse.ConnectSrcObject(file);
  1885. * \endcode
  1886. * \see FbxSurfaceMaterial
  1887. *
  1888. * \remarks To be correctly saved in FBX file, this type of Layer element should have its reference
  1889. * mode set to \e eIndexToDirect.
  1890. * \nosubgrouping
  1891. */
  1892. class FBXSDK_DLL FbxLayerElementTexture : public FbxLayerElementTemplate<FbxTexture*>
  1893. {
  1894. public:
  1895. /** Allocation method.
  1896. * \return A pointer to the layer element or \c NULL if creation fails.
  1897. */
  1898. FBXSDK_LAYER_ELEMENT_CREATE_DECLARE(LayerElementTexture);
  1899. /** \enum EBlendMode Lets you control how textures are combined when you apply multiple layers of texture to a surface.
  1900. * - \e eTranslucent The new texture layer is transparent (depending on the Alpha value).
  1901. * - \e eAdd Add the color of the new texture to the previous texture.
  1902. * - \e eModulate Multiples the color value of the new texture by the color values of all previous layers of texture.
  1903. * - \e eModulate2 Multiples the color value of the new texture by two and then by the color values of all previous layers of texture.
  1904. * - \e eOver Equivalent to eTranslucent. Blends the new texture over top of the old texture, according to the new texture's alpha channel.
  1905. * - \e eNormal, The colors of the two layers will not interact in any way, and it will display the full value of the colors in layer 1.
  1906. * - \e eDissolve, Dissolve makes the lower layer take on the colors of the top layer, and how much depends on the opacity of the upper layer.
  1907. * - \e eDarken, Darken compares each pixel value of the upper layer to its counterpart's pixel value of the lower layer and chooses the darker of the two to display.
  1908. * - \e eColorBurn, Color Burn burns in the color of the upper layer with the lower layer. No part of the image will get lighter.
  1909. * - \e eLinearBurn, Linear Burn works like multiply but the results are more intense.
  1910. * - \e eDarkerColor, This blend mode simply divides pixel values of one layer with the other.
  1911. * - \e eLighten, Lighten compares the two layers pixel for pixel and uses the lightest pixel value. No part of the image gets darker.
  1912. * - \e eScreen, Screen brightens by lightning the lower layer based on the lightness of the upper layer
  1913. * - \e eColorDodge, Color Dodge dodges the lower layer with the upper layer, resulting in a lighter image. No part of the image will be darkened.
  1914. * - \e eLinearDodge, Linear Dodge works like screen but with more intense results.
  1915. * - \e eLighterColor, This blend mode has the opposite effect of the Darker Color mode. It compares all the values in both layers, then displays the lightest values.
  1916. * - \e eSoftLight, Soft Light will multiply the dark tones and screen the light tones.
  1917. * - \e eHardLight, Hard Light multiplies the dark colors and screens the light colors.
  1918. * - \e eVividLight, Vivid Light will dodges or burn the lower layer pixels depending on whether the upper layer pixels are brighter or darker than neutral gray. It works on the contrast of the lower layer.
  1919. * - \e eLinearLight, Linear Light is the same as Vivid light but it works on the brightness of the lower layer.
  1920. * - \e ePinLight, Pin Light changes the lower layer pixels depending on how bright the pixels are in the upper layer.
  1921. * - \e eHardMix, Produces either white or black, depending on similarities between A and B.
  1922. * - \e eDifference, Difference reacts to the differences between the upper and lower layer pixels.
  1923. * - \e eExclusion, Exclusion uses the darkness of the lower layer to mask the difference between upper and lower layers.
  1924. * - \e eSubtract, The result color is the foreground color subtracted from the background color. The result color is then applied over the background color using the foreground alpha to define the opacity of the result.
  1925. * - \e eDivide, This blend mode simply divides pixel values of one layer with the other.
  1926. * - \e eHue, Hue changes the hue of the lower layer to the hue of the upper layer but leaves brightness and saturation alone.
  1927. * - \e eSaturation, Saturation changes the saturation of the lower layer to the hue of the upper layer but leaves brightness and hue alone.
  1928. * - \e eColor, Color changes the hue and saturation of the lower layer to the hue and saturation of the upper layer but leaves luminosity alone.
  1929. * - \e eLuminosity, Luminosity changes the luminosity of the lower layer to the luminosity of the upper layer while leaving hue and saturation the same.
  1930. * - \e eOverlay, Multiplies (darkens) when the layer on which the mode is set is dark and screens (brightens) when the layer on which the mode is applied is lighter.
  1931. * - \e eBlendModeCount Marks the end of the blend mode enum.
  1932. */
  1933. enum EBlendMode
  1934. {
  1935. eTranslucent,
  1936. eAdd,
  1937. eModulate,
  1938. eModulate2,
  1939. eOver,
  1940. eNormal,
  1941. eDissolve,
  1942. eDarken,
  1943. eColorBurn,
  1944. eLinearBurn,
  1945. eDarkerColor,
  1946. eLighten,
  1947. eScreen,
  1948. eColorDodge,
  1949. eLinearDodge,
  1950. eLighterColor,
  1951. eSoftLight,
  1952. eHardLight,
  1953. eVividLight,
  1954. eLinearLight,
  1955. ePinLight,
  1956. eHardMix,
  1957. eDifference,
  1958. eExclusion,
  1959. eSubtract,
  1960. eDivide,
  1961. eHue,
  1962. eSaturation,
  1963. eColor,
  1964. eLuminosity,
  1965. eOverlay,
  1966. eBlendModeCount
  1967. };
  1968. /** Sets the way Textures blend between layers.
  1969. * \param pBlendMode A valid blend mode.
  1970. */
  1971. void SetBlendMode(EBlendMode pBlendMode) { mBlendMode = pBlendMode; }
  1972. /** Sets the transparency level between multiple texture levels.
  1973. * \param pAlpha Set to a value between 0.0 and 1.0, where 0.0 is totally transparent and 1.0 is totally opaque.
  1974. * \remarks Values smaller than 0.0 are clipped to 0.0, while values greater than 1.0 are clipped to 1.0.
  1975. */
  1976. void SetAlpha(double pAlpha)
  1977. {
  1978. if (pAlpha > 1.0)
  1979. mAlpha = 1.0;
  1980. else if (pAlpha < 0.0)
  1981. mAlpha = 0.0;
  1982. else
  1983. mAlpha = pAlpha;
  1984. }
  1985. /** Returns the way Textures blend between layers.
  1986. * \return The current Blend Mode.
  1987. */
  1988. EBlendMode GetBlendMode() const { return mBlendMode; }
  1989. /** Returns the transparency level between multiple levels of textures.
  1990. * \return An alpha value between 0.0 and 1.0, where 0.0 is totally transparent and 1.0 is totally opaque.
  1991. */
  1992. double GetAlpha() const { return mAlpha; }
  1993. /*****************************************************************************************************************************
  1994. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  1995. *****************************************************************************************************************************/
  1996. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  1997. virtual int MemorySize() const
  1998. {
  1999. int size = FbxLayerElementTemplate<FbxTexture*>::MemorySize();
  2000. size += sizeof(mBlendMode);
  2001. size += sizeof(mAlpha);
  2002. return size;
  2003. }
  2004. protected:
  2005. /** Constructor
  2006. * By default, textures have a Blend Mode of eTranslucent,
  2007. * a Reference Mode of eIndexToDirect, and an Alpha value of 1.0.
  2008. */
  2009. FbxLayerElementTexture() : mBlendMode(eTranslucent)
  2010. {
  2011. mReferenceMode = eIndexToDirect;
  2012. mAlpha = 1.0;
  2013. }
  2014. private:
  2015. EBlendMode mBlendMode;
  2016. double mAlpha;
  2017. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  2018. };
  2019. /** FbxLayer class provides a base for the layering mechanism.
  2020. *
  2021. * A layer can contain one or more of the following layer elements:
  2022. * \li Normals
  2023. * \li Binormals
  2024. * \li Tangents
  2025. * \li Materials
  2026. * \li Polygon Groups
  2027. * \li UVs
  2028. * \li Vertex Colors
  2029. * \li Smoothing informations
  2030. * \li Vertex Creases
  2031. * \li Edge Creases
  2032. * \li Custom User Data
  2033. * \li Visibilities
  2034. * \li Textures (diffuse, ambient, specular, etc.) (deprecated)
  2035. *
  2036. * A typical layer for a Mesh contains Normals, UVs and Materials. A typical layer for NURBS contains only Materials.
  2037. * In the case of the NURBS, the NURBS' parameterization is used for the UVs; no UVs should be specified.
  2038. *
  2039. * In most cases, you only need a single layer to describe a geometry. Many applications only support what is defined on the first layer.
  2040. * Take this into account when you fill the layer. For example, it is legal to define the Layer 0 with the UVs and then
  2041. * define the model's Normals on layer 1. However if you construct a file this way, it may not be imported correctly in other applications.
  2042. * Store the Normals in Layer 0 to avoid problems.
  2043. *
  2044. * Since FBX SDK 2011, Textures are connected to the properties of FbxSurfaceMaterial derived classes.
  2045. * FbxLayerElementTexture is no longer used. See the code example in FbxLayerElementTexture for how to connect a texture.
  2046. *
  2047. * Since FBX SDK 2011, texture layering is achieved by FbxLayeredTexture. See the code example in FbxLayeredTexture for how to blend textures.
  2048. *
  2049. * Normally, you can access layer from FbxLayerContainer like FbxGeometry.
  2050. * For example,
  2051. * \code
  2052. * FbxMesh* mesh;
  2053. * FbxLayer* layer0 = mesh->GetLayer(0);
  2054. * FbxLayerElementNormal* normals = layer0->GetNormals();
  2055. * \endcode
  2056. *
  2057. * \nosubgrouping
  2058. * \see FbxLayerElement
  2059. * \see FbxLayerElementNormal
  2060. * \see FbxLayerElementBinormal
  2061. * \see FbxLayerElementTangent
  2062. * \see FbxLayerElementMaterial
  2063. * \see FbxLayerElementPolygonGroup
  2064. * \see FbxLayerElementUV
  2065. * \see FbxLayerElementVertexColor
  2066. * \see FbxLayerElementSmoothing
  2067. * \see FbxLayerElementCrease
  2068. * \see FbxLayerElementUserData
  2069. * \see FbxLayerElementHole
  2070. * \see FbxLayerElementVisibility
  2071. */
  2072. class FBXSDK_DLL FbxLayer
  2073. {
  2074. public:
  2075. FBXSDK_FRIEND_NEW();
  2076. /**
  2077. * \name Layer Element Management
  2078. */
  2079. //@{
  2080. /** Returns this layer's Normals description .
  2081. * \return A pointer to the Normals layer element, or \c NULL if no Normals layer element is defined in this layer.
  2082. * \remarks FbxNurbs or FbxPatch geometry should not have Normals defined.
  2083. */
  2084. FbxLayerElementNormal* GetNormals();
  2085. /** Returns this layer's Normals description .
  2086. * \return A pointer to the Normals layer element, or \c NULL if no Normals layer element is defined in this layer.
  2087. * \remarks FbxNurbs or FbxPatch geometry should not have Normals defined.
  2088. */
  2089. const FbxLayerElementNormal* GetNormals() const;
  2090. /** Returns this layer's Tangents description.
  2091. * \return A pointer to the Tangents layer element, or \c NULL if no Tangents layer element is defined in this layer.
  2092. * \remarks FbxNurbs or FbxPatch geometry should not have Tangents defined.
  2093. */
  2094. FbxLayerElementTangent* GetTangents();
  2095. /** Returns this layer's Tangents description.
  2096. * \return A pointer to the Tangents layer element, or \c NULL if no Tangents layer element is defined in this layer.
  2097. * \remarks FbxNurbs or FbxPatch geometry should not have Tangents defined.
  2098. */
  2099. const FbxLayerElementTangent* GetTangents() const;
  2100. /** Returns this layer's Binormals description.
  2101. * \return A pointer to the Binormals layer element, or \c NULL if no Binormals layer element is defined in this layer.
  2102. * \remarks FbxNurbs or FbxPatch geometry should not have Binormals defined.
  2103. */
  2104. FbxLayerElementBinormal* GetBinormals();
  2105. /** Returns this layer's Binormals description.
  2106. * \return A pointer to the Binormals layer element, or \c NULL if no Binormals layer element is defined in this layer.
  2107. * \remarks FbxNurbs or FbxPatch geometry should not have Binormals defined.
  2108. */
  2109. const FbxLayerElementBinormal* GetBinormals() const;
  2110. /** Returns this layer's Materials description.
  2111. * \return A pointer to the Materials layer element, or \c NULL if no Materials layer element is defined in this layer.
  2112. */
  2113. FbxLayerElementMaterial* GetMaterials();
  2114. /** Returns this layer's Materials description.
  2115. * \return A pointer to the Materials layer element, or \c NULL if no Materials layer element is defined in this layer.
  2116. */
  2117. const FbxLayerElementMaterial* GetMaterials() const;
  2118. /** Returns this layer's Polygon Groups description.
  2119. * \return A pointer to the Polygon Groups layer element, or \c NULL if no Polygon Groups layer element is defined in this layer.
  2120. */
  2121. FbxLayerElementPolygonGroup* GetPolygonGroups();
  2122. /** Returns this layer's Polygon Groups description.
  2123. * \return A pointer to the Polygon Groups layer element, or \c NULL if no Polygon Groups layer element is defined in this layer.
  2124. */
  2125. const FbxLayerElementPolygonGroup* GetPolygonGroups() const;
  2126. /** Returns this layer's UV description.
  2127. * \param pTypeIdentifier Layer element type identifier, should be a texture type identifier.
  2128. * \return A pointer to the UVs layer element, or \c NULL if no UV is defined in this layer.
  2129. * \remarks FbxNurbs or FbxPatch geometry should not have UVs defined.
  2130. * The NURBS/Patch parameterization is used as UV parameters to map a texture.
  2131. */
  2132. FbxLayerElementUV* GetUVs(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
  2133. /** Returns this layer's UV description.
  2134. * \param pTypeIdentifier Layer element type identifier, should be a texture type identifier.
  2135. * \return A pointer to the UVs layer element, or \c NULL if no UV is defined in this layer.
  2136. * \remarks FbxNurbs or FbxPatch geometry should not have UVs defined.
  2137. * The NURBS/Patch parameterization is used as UV parameters to map a texture.
  2138. */
  2139. const FbxLayerElementUV* GetUVs(FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse) const;
  2140. /** Returns the number of different UV sets in this layer.
  2141. */
  2142. int GetUVSetCount() const;
  2143. /** Returns an array that describes which UV sets are in this layer.
  2144. */
  2145. FbxArray<FbxLayerElement::EType> GetUVSetChannels() const;
  2146. /** Returns an array of UV sets in this layer.
  2147. */
  2148. FbxArray<const FbxLayerElementUV*> GetUVSets() const;
  2149. /** Returns this layer's Vertex Colors description.
  2150. * \return A pointer to the Vertex Colors layer element, or \c NULL if no Vertex Color layer element is defined in this layer.
  2151. * \remarks FbxNurbs or FbxPatch geometry should not have Vertex Colors defined, since no vertex exists.
  2152. */
  2153. FbxLayerElementVertexColor* GetVertexColors();
  2154. /** Returns this layer's Vertex Colors description.
  2155. * \return A pointer to the Vertex Colors layer element, or \c NULL if no Vertex Color layer element is defined in this layer.
  2156. * \remarks FbxNurbs or FbxPatch geometry should not have Vertex Colors defined, since no vertex exists.
  2157. */
  2158. const FbxLayerElementVertexColor* GetVertexColors() const;
  2159. /** Returns this layer's Smoothing description.
  2160. * \return A pointer to the Smoothing layer element, or \c NULL if no Smoothing layer element is defined in this layer.
  2161. * \remarks FbxNurbs or FbxPatch geometry should not have Smoothing defined.
  2162. */
  2163. FbxLayerElementSmoothing* GetSmoothing();
  2164. /** Returns this layer's Smoothing description.
  2165. * \return A pointer to the Smoothing layer element, or \c NULL if no Smoothing layer element is defined in this layer.
  2166. * \remarks FbxNurbs or FbxPatch geometry should not have Smoothing defined.
  2167. */
  2168. const FbxLayerElementSmoothing* GetSmoothing() const;
  2169. /** Returns this layer's vertex crease description.
  2170. * \return A pointer to the Crease layer element, or \c NULL if no Crease layer element is defined in this layer.
  2171. * \remarks Crease info should only be defined when the geometry is FbxSubDiv.
  2172. */
  2173. FbxLayerElementCrease* GetVertexCrease();
  2174. /** Returns this layer's vertex crease description.
  2175. * \return A pointer to the Crease layer element, or \c NULL if no Crease layer element is defined in this layer.
  2176. * \remarks Crease info should only be defined when the geometry is FbxSubDiv.
  2177. */
  2178. const FbxLayerElementCrease* GetVertexCrease() const;
  2179. /** Returns this layer's edge crease description.
  2180. * \return A pointer to the Crease layer element, or \c NULL if no Crease layer element is defined in this layer.
  2181. * \remarks Crease info should only be defined when the geometry is FbxSubDiv.
  2182. */
  2183. FbxLayerElementCrease* GetEdgeCrease();
  2184. /** Returns this layer's edge crease description.
  2185. * \return A pointer to the Crease layer element, or \c NULL if no Crease layer element is defined in this layer.
  2186. * \remarks Crease info should only be defined when the geometry is FbxSubDiv.
  2187. */
  2188. const FbxLayerElementCrease* GetEdgeCrease() const;
  2189. /** Returns this layer's Hole description.
  2190. * \return A pointer to the Hole layer element, or \c NULL if no Hole layer element is defined in this layer.
  2191. * \remarks Hole info should only be defined when the geometry is FbxMesh.
  2192. */
  2193. FbxLayerElementHole* GetHole();
  2194. /** Returns this layer's Hole description.
  2195. * \return A pointer to the Hole layer element, or \c NULL if no Hole layer element is defined in this layer.
  2196. * \remarks Hole info should only be defined when the geometry is FbxMesh.
  2197. */
  2198. const FbxLayerElementHole* GetHole() const;
  2199. /** Returns this layer's User Data.
  2200. * \return A pointer to the User Data layer element, or \c NULL if no User Data layer element is defined in this layer.
  2201. */
  2202. FbxLayerElementUserData* GetUserData();
  2203. /** Returns this layer's User Data.
  2204. * \return A pointer to the User Data layer element, or \c NULL if no User Data layer element is defined in this layer.
  2205. */
  2206. const FbxLayerElementUserData* GetUserData() const;
  2207. /** Returns this layer's visibility.
  2208. * \return A pointer to the visibility layer element, or \c NULL if no visibility layer element is defined in this layer.
  2209. */
  2210. FbxLayerElementVisibility* GetVisibility();
  2211. /** Returns this layer's visibility.
  2212. * \return A pointer to the visibility layer element, or \c NULL if no visibility layer element is defined in this layer.
  2213. */
  2214. const FbxLayerElementVisibility* GetVisibility() const;
  2215. /** Returns this layer's Textures description.
  2216. * \param pType Layer element type, should be a texture type identifier.
  2217. * \return A pointer to the Textures layer element, or \c NULL if no Textures layer element is defined in this layer.
  2218. */
  2219. FbxLayerElementTexture* GetTextures(FbxLayerElement::EType pType);
  2220. /** Returns this layer's Textures description.
  2221. * \param pType Layer element type, should be a texture type identifier.
  2222. * \return A pointer to the Textures layer element, or \c NULL if no Textures layer element is defined in this layer.
  2223. */
  2224. const FbxLayerElementTexture* GetTextures(FbxLayerElement::EType pType) const;
  2225. /** Sets this layer's Textures description.
  2226. * \param pType Texture type identifier.
  2227. * \param pTextures A pointer to the Textures layer element, or \c NULL to remove the Textures definition.
  2228. */
  2229. void SetTextures(FbxLayerElement::EType pType, FbxLayerElementTexture* pTextures);
  2230. /** Returns the specified type of layer element description for this layer.
  2231. * \param pType The required Layer element type.
  2232. * - Calling with eNormal is the equivalent of calling GetNormals().
  2233. * - Calling with eBiNormal is the equivalent of calling GetBinormals().
  2234. * - Calling with eTangent is the equivalent of calling GetTangents().
  2235. * - Calling with eMaterial is the equivalent of calling GetMaterials().
  2236. * - Calling with ePolygonGroup is the equivalent of calling GetPolygonGroups().
  2237. * - Calling with eUV is the equivalent of calling GetUVs().
  2238. * - Calling with eVertexColor is the equivalent of calling GetVertexColors().
  2239. * - Calling with eSmoothing is the equivalent of calling GetSmoothing().
  2240. * - Calling with eVertexCrease is the equivalent of calling GetVertexCrease().
  2241. * - Calling with eEdgeCrease is the equivalent of calling GetEdgeCrease().
  2242. * - Calling with eUserData is the equivalent of calling GetUserData().
  2243. * - Calling with eVisibility is the equivalent of calling GetVisibility().
  2244. * - Calling with texture type is the equivalent of calling GetTextures(FbxLayerElement::EType pType).
  2245. * \param pIsUV If \c true, requests the UV layer element that corresponds with the specified texture type.
  2246. * \return A pointer to the requested layer element, or \e NULL if the layer element is not defined in this layer.
  2247. */
  2248. FbxLayerElement* GetLayerElementOfType(FbxLayerElement::EType pType, bool pIsUV=false);
  2249. /** Returns the specified type of layer element description for this layer.
  2250. * \param pType The required Layer element type.
  2251. * - Calling with eNormal is the equivalent of calling GetNormals().
  2252. * - Calling with eBiNormal is the equivalent of calling GetBinormals().
  2253. * - Calling with eTangent is the equivalent of calling GetTangents().
  2254. * - Calling with eMaterial is the equivalent of calling GetMaterials().
  2255. * - Calling with ePolygonGroup is the equivalent of calling GetPolygonGroups().
  2256. * - Calling with eUV is the equivalent of calling GetUVs().
  2257. * - Calling with eVertexColor is the equivalent of calling GetVertexColors().
  2258. * - Calling with eSmoothing is the equivalent of calling GetSmoothing().
  2259. * - Calling with eVertexCrease is the equivalent of calling GetVertexCrease().
  2260. * - Calling with eEdgeCrease is the equivalent of calling GetEdgeCrease().
  2261. * - Calling with eUserData is the equivalent of calling GetUserData().
  2262. * - Calling with eVisibility is the equivalent of calling GetVisibility().
  2263. * - Calling with texture type is the equivalent of calling GetTextures(FbxLayerElement::EType pType).
  2264. * \param pIsUV If \c true, requests the UV layer element that corresponds with the specified texture type.
  2265. * \return A pointer to the requested layer element, or \e NULL if the layer element is not defined in this layer.
  2266. */
  2267. const FbxLayerElement* GetLayerElementOfType(FbxLayerElement::EType pType, bool pIsUV=false) const;
  2268. /** Sets this layer's Normals description.
  2269. * \param pNormals A pointer to the Normals layer element, or \c NULL to remove the Normals definition.
  2270. * \remarks FbxNurbs or FbxPatch geometry should not have Normals defined.
  2271. */
  2272. void SetNormals(FbxLayerElementNormal* pNormals);
  2273. /** Sets this layer's Binormals description.
  2274. * \param pBinormals A pointer to the Binormals layer element, or \c NULL to remove the Binormals definition.
  2275. * \remarks FbxNurbs or FbxPatch geometry should not have Binormals defined.
  2276. */
  2277. void SetBinormals(FbxLayerElementBinormal* pBinormals);
  2278. /** Sets this layer's Tangents description.
  2279. * \param pTangents A pointer to the Tangents layer element, or \c NULL to remove the Tangents definition.
  2280. * \remarks FbxNurbs or FbxPatch geometry should not have Tangents defined.
  2281. */
  2282. void SetTangents(FbxLayerElementTangent* pTangents);
  2283. /** Sets this layer's Materials description.
  2284. * \param pMaterials A pointer to the Materials layer element, or \c NULL to remove the Material definition.
  2285. */
  2286. void SetMaterials(FbxLayerElementMaterial* pMaterials);
  2287. /** Sets this layer's Polygon Groups description.
  2288. * \param pPolygonGroups A pointer to the Polygon Groups layer element, or \c NULL to remove the Polygon Group definition.
  2289. */
  2290. void SetPolygonGroups(FbxLayerElementPolygonGroup* pPolygonGroups);
  2291. /** Sets this layer's UVs description.
  2292. * \param pUVs A pointer to the UVs layer element, or \c NULL to remove the UV definition.
  2293. * \param pTypeIdentifier Layer element type, should be texture type.
  2294. * \remarks FbxNurbs or FbxPatch geometry should not have UVs defined.
  2295. * The NURBS/Patch parameterization is used as UV parameters to map a texture.
  2296. */
  2297. void SetUVs(FbxLayerElementUV* pUVs, FbxLayerElement::EType pTypeIdentifier=FbxLayerElement::eTextureDiffuse);
  2298. /** Sets this layer's Vertex Colors description.
  2299. * \param pVertexColors A pointer to the Vertex Colors layer element, or \c NULL to remove the Vertex Color definition.
  2300. * \remarks FbxNurbs or FbxPatch geometry should not have Vertex Colors defined, since no vertex exists.
  2301. */
  2302. void SetVertexColors (FbxLayerElementVertexColor* pVertexColors);
  2303. /** Sets this layer's Smoothing description.
  2304. * \param pSmoothing A pointer to the Smoothing layer element, or \c NULL to remove the Smoothing definition.
  2305. * \remarks FbxNurbs or FbxPatch geometry should not have Smoothing defined.
  2306. */
  2307. void SetSmoothing (FbxLayerElementSmoothing* pSmoothing);
  2308. /** Sets this layer's Vertex Crease description.
  2309. * \param pCrease A pointer to the Vertex Crease layer element, or \c NULL to remove the Crease definition.
  2310. * \remarks Crease should only be defined when the geometry is FbxSubDiv.
  2311. */
  2312. void SetVertexCrease (FbxLayerElementCrease* pCrease);
  2313. /** Sets this layer's Edge Crease description.
  2314. * \param pCrease A pointer to the Edge Crease layer element, or \c NULL to remove the Crease definition.
  2315. * \remarks Crease should only be defined when the geometry is FbxSubDiv.
  2316. */
  2317. void SetEdgeCrease (FbxLayerElementCrease* pCrease);
  2318. /** Sets this layer's Hole description.
  2319. * \param pHole A pointer to the Hole layer element, or \c NULL to remove the Hole definition.
  2320. * \remarks Hole should only be defined when the geometry is FbxMesh.
  2321. */
  2322. void SetHole (FbxLayerElementHole* pHole);
  2323. /** Sets this layer's User Data.
  2324. * \param pUserData A pointer to the User Data layer element, or \c NULL to remove the User Data.
  2325. */
  2326. void SetUserData (FbxLayerElementUserData* pUserData);
  2327. /** Sets this layer's the visibility.
  2328. * \param pVisibility A pointer to the visibility layer element, or \c NULL to remove the visibility.
  2329. */
  2330. void SetVisibility( FbxLayerElementVisibility* pVisibility );
  2331. /** Sets the specified type of layer element description for this layer.
  2332. * \param pLayerElement A pointer to the layer element, or \c NULL to remove the layer element.
  2333. * \param pType The required Layer element type.
  2334. * - Calling with eNormal is the equivalent of calling GetNormals().
  2335. * - Calling with eBiNormal is the equivalent of calling GetBinormals().
  2336. * - Calling with eTangent is the equivalent of calling GetTangents().
  2337. * - Calling with eMaterial is the equivalent of calling GetMaterials().
  2338. * - Calling with ePolygonGroup is the equivalent of calling GetPolygonGroups().
  2339. * - Calling with eUV is the equivalent of calling GetUVs().
  2340. * - Calling with eVertexColor is the equivalent of calling GetVertexColors().
  2341. * - Calling with eSmoothing is the equivalent of calling GetSmoothing().
  2342. * - Calling with eVertexCrease is the equivalent of calling GetVertexCrease().
  2343. * - Calling with eEdgeCrease is the equivalent of calling GetEdgeCrease().
  2344. * - Calling with eUserData is the equivalent of calling GetUserData().
  2345. * - Calling with eVisibility is the equivalent of calling GetVisibility().
  2346. * - Calling with texture type is the equivalent of calling GetTextures(FbxLayerElement::EType pType).
  2347. * \param pIsUV If \c true, requests the UV layer element that corresponds with the specified texture type.
  2348. */
  2349. void SetLayerElementOfType(FbxLayerElement* pLayerElement, FbxLayerElement::EType pType, bool pIsUV=false);
  2350. /** Creates the specified type of layer element description for this layer.
  2351. * \param pType The required Layer element type.
  2352. * \param pIsUV When \c true, requests the UV LayerElement that corresponds with the specified Layer Element type (only applies to
  2353. * TEXTURE type layer elements).
  2354. * \return A pointer to the newly created layer element, or \e NULL if the layer element has not been created for this layer.
  2355. */
  2356. FbxLayerElement* CreateLayerElementOfType(FbxLayerElement::EType pType, bool pIsUV=false);
  2357. /** Clone function.
  2358. * \param pSrcLayer The source layer to be cloned.
  2359. */
  2360. void Clone(FbxLayer const& pSrcLayer);
  2361. /*****************************************************************************************************************************
  2362. ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! **
  2363. *****************************************************************************************************************************/
  2364. #ifndef DOXYGEN_SHOULD_SKIP_THIS
  2365. protected:
  2366. //! Assignment operator.
  2367. FbxLayer& operator=(FbxLayer const& pSrcLayer);
  2368. //@}
  2369. private:
  2370. FbxLayer(FbxLayerContainer& pOwner);
  2371. virtual ~FbxLayer();
  2372. void Clear();
  2373. FbxLayerContainer& mOwner;
  2374. FbxLayerElement* mNonTexturesArray[FbxLayerElement::sTypeNonTextureCount];
  2375. FbxLayerElementUV* mUVsArray[FbxLayerElement::sTypeTextureCount];
  2376. FbxLayerElementTexture* mTexturesArray[FbxLayerElement::sTypeTextureCount];
  2377. friend class FbxLayerContainer;
  2378. public:
  2379. /**
  2380. * \name Serialization section
  2381. */
  2382. //@{
  2383. bool ContentWriteTo(FbxStream& pStream) const;
  2384. bool ContentReadFrom(const FbxStream& pStream);
  2385. //@}
  2386. virtual int MemoryUsage() const;
  2387. #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/
  2388. };
  2389. /**
  2390. * Utility macro for iterating over texture layer elements
  2391. */
  2392. #define FBXSDK_FOR_EACH_TEXTURE(lLayerIndex) for((lLayerIndex)=0;(lLayerIndex)<FbxLayerElement::sTypeTextureCount;(lLayerIndex)++)
  2393. /**
  2394. * Utility macro for iterating over non-texture layer elements
  2395. */
  2396. #define FBXSDK_FOR_EACH_NON_TEXTURE(lLayerIndex) for((lLayerIndex)=0;(lLayerIndex)<FbxLayerElement::sTypeNonTextureCount;(lLayerIndex)++)
  2397. /**
  2398. * Utility macro for getting texture layer element index by type
  2399. */
  2400. #define FBXSDK_TEXTURE_INDEX(ElementType) (int(ElementType)-FbxLayerElement::sTypeTextureStartIndex)
  2401. /**
  2402. * Utility macro for getting texture layer element type by index
  2403. */
  2404. #define FBXSDK_TEXTURE_TYPE(TextureIndex) (FbxLayerElement::EType((TextureIndex)+FbxLayerElement::sTypeTextureStartIndex))
  2405. /**
  2406. * Utility macro for getting non-texture layer element index by type
  2407. */
  2408. #define FBXSDK_NON_TEXTURE_INDEX(ElementType) (int(ElementType)-FbxLayerElement::sTypeNonTextureStartIndex)
  2409. /**
  2410. * Utility macro for getting non-texture layer element type by index
  2411. */
  2412. #define FBXSDK_NON_TEXTURE_TYPE(Index) (FbxLayerElement::EType((Index)+FbxLayerElement::sTypeNonTextureStartIndex))
  2413. /** Defines geometry element classes.
  2414. * A geometry element describes how the geometry element is mapped to a geometry surface
  2415. * and how the mapping information is arranged in memory.
  2416. * \remarks Geometry elements are independent of layer elements and hide the complexity of layers.
  2417. * \code
  2418. * FbxGeometryElementUV* lUVs = lMesh->GetElementUV("map1");
  2419. * FbxGeometryElementUV::DirectArrayType lDirectArray = lUVs->GetDirectArray();
  2420. * int lDirectUVCount = lDirectArray.GetCount();
  2421. * FbxVector2 lFirstUV = lDirectArray[0];
  2422. * \endcode
  2423. * \see FbxGeometryBase
  2424. */
  2425. typedef FbxLayerElement FbxGeometryElement;
  2426. typedef FbxLayerElementNormal FbxGeometryElementNormal;
  2427. typedef FbxLayerElementBinormal FbxGeometryElementBinormal;
  2428. typedef FbxLayerElementTangent FbxGeometryElementTangent;
  2429. typedef FbxLayerElementMaterial FbxGeometryElementMaterial;
  2430. typedef FbxLayerElementPolygonGroup FbxGeometryElementPolygonGroup;
  2431. typedef FbxLayerElementUV FbxGeometryElementUV;
  2432. typedef FbxLayerElementVertexColor FbxGeometryElementVertexColor;
  2433. typedef FbxLayerElementUserData FbxGeometryElementUserData;
  2434. typedef FbxLayerElementSmoothing FbxGeometryElementSmoothing;
  2435. typedef FbxLayerElementCrease FbxGeometryElementCrease;
  2436. typedef FbxLayerElementHole FbxGeometryElementHole;
  2437. typedef FbxLayerElementVisibility FbxGeometryElementVisibility;
  2438. #undef FBXSDK_LAYER_ELEMENT_CREATE_DECLARE
  2439. #include <fbxsdk/fbxsdk_nsend.h>
  2440. #endif /* _FBXSDK_SCENE_GEOMETRY_LAYER_H_ */