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