/src/assimp/code/AssetLib/Obj/ObjFileMtlImporter.h
Line | Count | Source |
1 | | /* |
2 | | Open Asset Import Library (assimp) |
3 | | ---------------------------------------------------------------------- |
4 | | |
5 | | Copyright (c) 2006-2026, 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 <assimp/defs.h> |
44 | | #include <string> |
45 | | #include <vector> |
46 | | #include "Common/Maybe.h" |
47 | | |
48 | | struct aiColor3D; |
49 | | struct aiString; |
50 | | |
51 | | namespace Assimp { |
52 | | |
53 | | namespace ObjFile { |
54 | | struct Model; |
55 | | struct Material; |
56 | | } // namespace ObjFile |
57 | | |
58 | | /** |
59 | | * @class ObjFileMtlImporter |
60 | | * @brief Loads the material description from a mtl file. |
61 | | */ |
62 | | class ObjFileMtlImporter { |
63 | | public: |
64 | | static const size_t BUFFERSIZE = 2048; |
65 | | using DataArray = std::vector<char>; |
66 | | using DataArrayIt = std::vector<char>::iterator; |
67 | | using ConstDataArrayIt = std::vector<char>::const_iterator; |
68 | | |
69 | | //! \brief The class default constructor |
70 | | ObjFileMtlImporter(std::vector<char> &buffer, const std::string &strAbsPath, |
71 | | ObjFile::Model *pModel); |
72 | | |
73 | | //! \brief The class destructor |
74 | 65.8k | ~ObjFileMtlImporter() = default; |
75 | | |
76 | | ObjFileMtlImporter(const ObjFileMtlImporter &rOther) = delete; |
77 | | ObjFileMtlImporter &operator=(const ObjFileMtlImporter &rOther) = delete; |
78 | | |
79 | | private: |
80 | | /// Load the whole material description |
81 | | void load(); |
82 | | /// Get color data. |
83 | | void getColorRGBA(aiColor3D *pColor); |
84 | | void getColorRGBA(Maybe<aiColor3D> &value); |
85 | | /// Get illumination model from loaded data |
86 | | void getIlluminationModel(int &illum_model); |
87 | | /// Gets a float value from data. |
88 | | void getFloatValue(ai_real &value); |
89 | | void getFloatValue(Maybe<ai_real> &value); |
90 | | void getFloatIfMaterialValid(ai_real ObjFile::Material::*member); |
91 | | void getFloatIfMaterialValid(Maybe<ai_real> ObjFile::Material::*member); |
92 | | /// Creates a new material from loaded data. |
93 | | void createMaterial(); |
94 | | /// Get texture name from loaded data. |
95 | | void getTexture(); |
96 | | void getTextureOption(bool &clamp, int &clampIndex, aiString *&out); |
97 | | |
98 | | private: |
99 | | //! Absolute pathname |
100 | | std::string m_strAbsPath; |
101 | | //! Data iterator showing to the current position in data buffer |
102 | | DataArrayIt m_DataIt; |
103 | | //! Data iterator to end of buffer |
104 | | DataArrayIt m_DataItEnd; |
105 | | //! USed model instance |
106 | | ObjFile::Model *m_pModel; |
107 | | //! Current line in file |
108 | | unsigned int m_uiLine; |
109 | | //! Helper buffer |
110 | | std::vector<char> m_buffer; |
111 | | }; |
112 | | |
113 | | } // Namespace Assimp |
114 | | |
115 | | #endif // OBJFILEMTLIMPORTER_H_INC |