1 | /**************************************************************************************** |
2 | |
3 | Copyright (C) 2015 Autodesk, Inc. |
4 | All rights reserved. |
5 | |
6 | Use of this software is subject to the terms of the Autodesk license agreement |
7 | provided at the time of installation or download, or which otherwise accompanies |
8 | this software in either electronic or hard copy form. |
9 | |
10 | ****************************************************************************************/ |
11 | |
12 | //! \file fbxmaterialconverter.h |
13 | #ifndef _FBXSDK_UTILS_MATERIAL_CONVERTER_H_ |
14 | #define _FBXSDK_UTILS_MATERIAL_CONVERTER_H_ |
15 | |
16 | #include <fbxsdk/fbxsdk_def.h> |
17 | |
18 | #include <fbxsdk/scene/geometry/fbxlayer.h> |
19 | |
20 | #include <fbxsdk/fbxsdk_nsbegin.h> |
21 | |
22 | class LayerConfig; |
23 | class FbxMaterialConverter_Impl; |
24 | |
25 | /** |
26 | * \brief This class provides functions to restructure the material and textures |
27 | * applied to geometries from FBX v5 material system to v6-and-up or the other way around. |
28 | * \nosubgrouping |
29 | * \see FbxSurfaceMaterial, FbxTexture |
30 | */ |
31 | class FBXSDK_DLL FbxMaterialConverter |
32 | { |
33 | public: |
34 | FbxMaterialConverter( FbxManager& mManager, FbxSurfaceMaterial* pDefaultMaterial = NULL); |
35 | ~FbxMaterialConverter(); |
36 | |
37 | /** Moves textures in texture layer elements to connections |
38 | * on the corresponding material's color properties, for all geometries |
39 | * in the scene.(Convert scene from FBX v5 material system to v6-and-up) |
40 | * \param pScene The scene whose geometries should be converted. |
41 | * \return true on success, false otherwise |
42 | */ |
43 | bool ConnectTexturesToMaterials( FbxScene& pScene ); |
44 | |
45 | /** Moves textures in texture layer elements to connections |
46 | * on the corresponding material's color properties, for the given geometry |
47 | * in the scene.(Convert scene from FBX v5 material system to v6-and-up) |
48 | * \param pNode The geometry node to be converted. |
49 | * \return true on success, false otherwise |
50 | */ |
51 | bool ConnectTexturesToMaterials( FbxNode* pNode ); |
52 | |
53 | /** This is the reverse operation of ConnectTexturesToMaterials() |
54 | * Textures connected to Materials' color properties are stored |
55 | * in layer elements, and their connections to the color properties |
56 | * are broken.(Convert scene from FBX v6-and-up material system to v5) |
57 | * \param pScene The scene whose geometries should be converted. |
58 | * \return true if all geometries were converted, false otherwise |
59 | */ |
60 | bool AssignTexturesToLayerElements( FbxScene& pScene ); |
61 | |
62 | /***************************************************************************************************************************** |
63 | ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** |
64 | *****************************************************************************************************************************/ |
65 | #ifndef DOXYGEN_SHOULD_SKIP_THIS |
66 | private: |
67 | typedef FbxPair<FbxTexture*, FbxLayerElementTexture::EBlendMode> TexData; |
68 | |
69 | FbxMaterialConverter& operator=(const FbxMaterialConverter&); |
70 | |
71 | FbxManager& mManager; |
72 | FbxSurfaceMaterial* mDefaultMaterial; |
73 | FbxMaterialConverter_Impl* mImpl; |
74 | |
75 | |
76 | void GetTextures( int pComponent, FbxLayer* pLayer, LayerConfig& pLayerConfig ) const; |
77 | FbxSurfaceMaterial* GetMaterial( int pComponent, FbxLayer* pLayer, FbxNode* pNode, bool pLookOnNode ); |
78 | int GetMaterialOrder( int pComponent, FbxLayer* pLayer, FbxNode* pNode, bool pLookOnNode ); |
79 | |
80 | bool HasGoodMappingModes( FbxNode* pNode, FbxGeometry* pGeom ) const; |
81 | void ConnectTextures( FbxSurfaceMaterial* pMat, FbxObject* pTexture, int pTextureType ) const; |
82 | bool HasPerFaceMaterialMapping( FbxGeometry* pGeom ) const; |
83 | void SetTextureUVSets( FbxGeometry* pGeom ) const; |
84 | bool HasTextures( FbxGeometry* pGeom ) const; |
85 | |
86 | void GetTextureList( FbxArray<TexData>& pTextures, FbxLayeredTexture* pTex ) const; |
87 | |
88 | FbxLayer* FindLayerForTexture( FbxTexture* pTex, |
89 | FbxLayerElement::EType pTexType, |
90 | FbxLayerElementTexture::EBlendMode pTexBlendMode, |
91 | FbxGeometry* pGeom, |
92 | int lComponentIndex, |
93 | int lStartIndex = 0 ) const; |
94 | |
95 | void InitTextureElement( FbxLayerElementTexture* pTexElm, int pComponentCount, |
96 | FbxLayerElementTexture::EBlendMode pMode) const; |
97 | |
98 | bool AssignTexturesToLayerElements( FbxNode* pNode); |
99 | |
100 | bool HasTextureLayerElements( FbxGeometry& pGeom ) const; |
101 | |
102 | void ConvertToPerFaceMapping( FbxMesh* pGeom ) const; |
103 | #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ |
104 | }; |
105 | |
106 | #include <fbxsdk/fbxsdk_nsend.h> |
107 | |
108 | #endif /* _FBXSDK_UTILS_MATERIAL_CONVERTER_H_ */ |
109 | |