1 | /* |
2 | Open Asset Import Library (assimp) |
3 | ---------------------------------------------------------------------- |
4 | |
5 | Copyright (c) 2006-2017, assimp team |
6 | |
7 | All rights reserved. |
8 | |
9 | Redistribution and use of this software in source and binary forms, |
10 | with or without modification, are permitted provided that the |
11 | following conditions are met: |
12 | |
13 | * Redistributions of source code must retain the above |
14 | copyright notice, this list of conditions and the |
15 | following disclaimer. |
16 | |
17 | * Redistributions in binary form must reproduce the above |
18 | copyright notice, this list of conditions and the |
19 | following disclaimer in the documentation and/or other |
20 | materials provided with the distribution. |
21 | |
22 | * Neither the name of the assimp team, nor the names of its |
23 | contributors may be used to endorse or promote products |
24 | derived from this software without specific prior |
25 | written permission of the assimp team. |
26 | |
27 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
28 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
29 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
30 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
31 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
32 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
33 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
34 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
35 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
36 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
37 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
38 | |
39 | ----------------------------------------------------------------------*/ |
40 | #ifndef OBJFILEMTLIMPORTER_H_INC |
41 | #define OBJFILEMTLIMPORTER_H_INC |
42 | |
43 | #include <vector> |
44 | #include <string> |
45 | #include <assimp/defs.h> |
46 | |
47 | struct aiColor3D; |
48 | struct aiString; |
49 | |
50 | namespace Assimp { |
51 | |
52 | namespace ObjFile { |
53 | struct Model; |
54 | struct Material; |
55 | } |
56 | |
57 | |
58 | /** |
59 | * @class ObjFileMtlImporter |
60 | * @brief Loads the material description from a mtl file. |
61 | */ |
62 | class ObjFileMtlImporter |
63 | { |
64 | public: |
65 | static const size_t BUFFERSIZE = 2048; |
66 | typedef std::vector<char> DataArray; |
67 | typedef std::vector<char>::iterator DataArrayIt; |
68 | typedef std::vector<char>::const_iterator ConstDataArrayIt; |
69 | |
70 | public: |
71 | //! \brief Default constructor |
72 | ObjFileMtlImporter( std::vector<char> &buffer, const std::string &strAbsPath, |
73 | ObjFile::Model *pModel ); |
74 | |
75 | //! \brief DEstructor |
76 | ~ObjFileMtlImporter(); |
77 | |
78 | private: |
79 | /// Copy constructor, empty. |
80 | ObjFileMtlImporter(const ObjFileMtlImporter &rOther); |
81 | /// \brief Assignment operator, returns only a reference of this instance. |
82 | ObjFileMtlImporter &operator = (const ObjFileMtlImporter &rOther); |
83 | /// Load the whole material description |
84 | void load(); |
85 | /// Get color data. |
86 | void getColorRGBA( aiColor3D *pColor); |
87 | /// Get illumination model from loaded data |
88 | void getIlluminationModel( int &illum_model ); |
89 | /// Gets a float value from data. |
90 | void getFloatValue( ai_real &value ); |
91 | /// Creates a new material from loaded data. |
92 | void createMaterial(); |
93 | /// Get texture name from loaded data. |
94 | void getTexture(); |
95 | void getTextureOption(bool &clamp, int &clampIndex, aiString *&out); |
96 | |
97 | private: |
98 | //! Absolute pathname |
99 | std::string m_strAbsPath; |
100 | //! Data iterator showing to the current position in data buffer |
101 | DataArrayIt m_DataIt; |
102 | //! Data iterator to end of buffer |
103 | DataArrayIt m_DataItEnd; |
104 | //! USed model instance |
105 | ObjFile::Model *m_pModel; |
106 | //! Current line in file |
107 | unsigned int m_uiLine; |
108 | //! Helper buffer |
109 | char m_buffer[BUFFERSIZE]; |
110 | }; |
111 | |
112 | // ------------------------------------------------------------------------------------------------ |
113 | |
114 | } // Namespace Assimp |
115 | |
116 | #endif // OBJFILEMTLIMPORTER_H_INC |
117 | |