1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
4 
5 Copyright (c) 2006-2015, assimp team
6 All rights reserved.
7 
8 Redistribution and use of this software in source and binary forms,
9 with or without modification, are permitted provided that the
10 following conditions are met:
11 
12 * Redistributions of source code must retain the above
13   copyright notice, this list of conditions and the
14   following disclaimer.
15 
16 * Redistributions in binary form must reproduce the above
17   copyright notice, this list of conditions and the
18   following disclaimer in the documentation and/or other
19   materials provided with the distribution.
20 
21 * Neither the name of the assimp team, nor the names of its
22   contributors may be used to endorse or promote products
23   derived from this software without specific prior
24   written permission of the assimp team.
25 
26 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 
38 ----------------------------------------------------------------------
39 */
40 
41 
42 #ifndef OBJ_FILE_IMPORTER_H_INC
43 #define OBJ_FILE_IMPORTER_H_INC
44 
45 #include "BaseImporter.h"
46 #include "../include/assimp/material.h"
47 #include <vector>
48 
49 struct aiMesh;
50 struct aiNode;
51 
52 namespace Assimp
53 {
54 
55 namespace ObjFile
56 {
57 struct Object;
58 struct Model;
59 }
60 
61 // ------------------------------------------------------------------------------------------------
62 /// \class  ObjFileImporter
63 /// \brief  Imports a waveform obj file
64 // ------------------------------------------------------------------------------------------------
65 class ObjFileImporter : public BaseImporter
66 {
67 public:
68     /// \brief  Default constructor
69     ObjFileImporter();
70 
71     /// \brief  Destructor
72     ~ObjFileImporter();
73 
74 public:
75     /// \brief  Returns whether the class can handle the format of the given file.
76     /// \remark See BaseImporter::CanRead() for details.
77     bool CanRead( const std::string& pFile, IOSystem* pIOHandler, bool checkSig) const;
78 
79 private:
80 
81     //! \brief  Appends the supported extension.
82     const aiImporterDesc* GetInfo () const;
83 
84     //! \brief  File import implementation.
85     void InternReadFile(const std::string& pFile, aiScene* pScene, IOSystem* pIOHandler);
86 
87     //! \brief  Create the data from imported content.
88     void CreateDataFromImport(const ObjFile::Model* pModel, aiScene* pScene);
89 
90     //! \brief  Creates all nodes stored in imported content.
91     aiNode *createNodes(const ObjFile::Model* pModel, const ObjFile::Object* pData,
92         aiNode *pParent, aiScene* pScene, std::vector<aiMesh*> &MeshArray);
93 
94     //! \brief  Creates topology data like faces and meshes for the geometry.
95     aiMesh *createTopology( const ObjFile::Model* pModel, const ObjFile::Object* pData,
96         unsigned int uiMeshIndex );
97 
98     //! \brief  Creates vertices from model.
99     void createVertexArray(const ObjFile::Model* pModel, const ObjFile::Object* pCurrentObject,
100         unsigned int uiMeshIndex, aiMesh* pMesh, unsigned int numIndices );
101 
102     //! \brief  Object counter helper method.
103     void countObjects(const std::vector<ObjFile::Object*> &rObjects, int &iNumMeshes);
104 
105     //! \brief  Material creation.
106     void createMaterials(const ObjFile::Model* pModel, aiScene* pScene);
107 
108     /// @brief  Adds special property for the used texture mapping mode of the model.
109     void addTextureMappingModeProperty(aiMaterial* mat, aiTextureType type, int clampMode = 1);
110 
111     //! \brief  Appends a child node to a parent node and updates the data structures.
112     void appendChildToParentNode(aiNode *pParent, aiNode *pChild);
113 
114 private:
115     //! Data buffer
116     std::vector<char> m_Buffer;
117     //! Pointer to root object instance
118     ObjFile::Object *m_pRootObject;
119     //! Absolute pathname of model in file system
120     std::string m_strAbsPath;
121 };
122 
123 // ------------------------------------------------------------------------------------------------
124 
125 } // Namespace Assimp
126 
127 #endif
128