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