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 */
41 
42 #ifndef AI_OGREIMPORTER_H_INC
43 #define AI_OGREIMPORTER_H_INC
44 
45 #ifndef ASSIMP_BUILD_NO_OGRE_IMPORTER
46 
47 #include "BaseImporter.h"
48 
49 #include "OgreStructs.h"
50 #include "OgreParsingUtils.h"
51 
52 #include <assimp/material.h>
53 
54 namespace Assimp
55 {
56 namespace Ogre
57 {
58 
59 /** Importer for Ogre mesh, skeleton and material formats.
60     @todo Support vertex colors.
61     @todo Support poses/animations from the mesh file.
62     Currently only skeleton file animations are supported. */
63 class OgreImporter : public BaseImporter
64 {
65 public:
66     /// BaseImporter override.
67     virtual bool CanRead(const std::string &pFile, IOSystem *pIOHandler, bool checkSig) const;
68 
69     /// BaseImporter override.
70     virtual void InternReadFile(const std::string &pFile, aiScene *pScene, IOSystem *pIOHandler);
71 
72     /// BaseImporter override.
73     virtual const aiImporterDesc *GetInfo() const;
74 
75     /// BaseImporter override.
76     virtual void SetupProperties(const Importer *pImp);
77 
78 private:
79     /// Read materials referenced by the @c mesh to @c pScene.
80     void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, Mesh *mesh);
81     void ReadMaterials(const std::string &pFile, Assimp::IOSystem *pIOHandler, aiScene *pScene, MeshXml *mesh);
82     void AssignMaterials(aiScene *pScene, std::vector<aiMaterial*> &materials);
83 
84     /// Reads material
85     aiMaterial* ReadMaterial(const std::string &pFile, Assimp::IOSystem *pIOHandler, const std::string &MaterialName);
86 
87     // These functions parse blocks from a material file from @c ss. Starting parsing from "{" and ending it to "}".
88     bool ReadTechnique(const std::string &techniqueName, std::stringstream &ss, aiMaterial *material);
89     bool ReadPass(const std::string &passName, std::stringstream &ss, aiMaterial *material);
90     bool ReadTextureUnit(const std::string &textureUnitName, std::stringstream &ss, aiMaterial *material);
91 
92     std::string m_userDefinedMaterialLibFile;
93     bool m_detectTextureTypeFromFilename;
94 
95     std::map<aiTextureType, unsigned int> m_textures;
96 };
97 } // Ogre
98 } // Assimp
99 
100 #endif // ASSIMP_BUILD_NO_OGRE_IMPORTER
101 #endif // AI_OGREIMPORTER_H_INC
102