vrshoot

view libs/assimp/ObjFileParser.h @ 0:b2f14e535253

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 01 Feb 2014 19:58:19 +0200
parents
children
line source
1 /*
2 Open Asset Import Library (assimp)
3 ----------------------------------------------------------------------
5 Copyright (c) 2006-2012, assimp team
6 All rights reserved.
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:
12 * Redistributions of source code must retain the above
13 copyright notice, this list of conditions and the
14 following disclaimer.
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.
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.
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.
38 ----------------------------------------------------------------------
39 */
42 #ifndef OBJ_FILEPARSER_H_INC
43 #define OBJ_FILEPARSER_H_INC
45 #include <vector>
46 #include <string>
47 #include <map>
49 namespace Assimp
50 {
52 namespace ObjFile
53 {
54 struct Model;
55 struct Object;
56 struct Material;
57 struct Point3;
58 struct Point2;
59 }
60 class ObjFileImporter;
61 class IOSystem;
63 /// \class ObjFileParser
64 /// \brief Parser for a obj waveform file
65 class ObjFileParser
66 {
67 public:
68 static const size_t BUFFERSIZE = 4096;
69 typedef std::vector<char> DataArray;
70 typedef std::vector<char>::iterator DataArrayIt;
71 typedef std::vector<char>::const_iterator ConstDataArrayIt;
73 public:
74 /// \brief Constructor with data array.
75 ObjFileParser(std::vector<char> &Data,const std::string &strModelName, IOSystem* io);
76 /// \brief Destructor
77 ~ObjFileParser();
78 /// \brief Model getter.
79 ObjFile::Model *GetModel() const;
81 private:
82 /// Parse the loadedfile
83 void parseFile();
84 /// Method to copy the new delimited word in the current line.
85 void copyNextWord(char *pBuffer, size_t length);
86 /// Method to copy the new line.
87 void copyNextLine(char *pBuffer, size_t length);
88 /// Stores the following 3d vector.
89 void getVector3( std::vector<aiVector3D> &point3d_array );
90 /// Stores the following 3d vector.
91 void getVector2(std::vector<aiVector2D> &point2d_array);
92 /// Stores the following face.
93 void getFace(aiPrimitiveType type);
94 void getMaterialDesc();
95 /// Gets a comment.
96 void getComment();
97 /// Gets a a material library.
98 void getMaterialLib();
99 /// Creates a new material.
100 void getNewMaterial();
101 /// Gets the groupname from file.
102 void getGroupName();
103 /// Gets the group number from file.
104 void getGroupNumber();
105 /// Returns the index of the material. Is -1 if not material was found.
106 int getMaterialIndex( const std::string &strMaterialName );
107 /// Parse object name
108 void getObjectName();
109 /// Creates a new object.
110 void createObject(const std::string &strObjectName);
111 /// Creates a new mesh.
112 void createMesh();
113 /// Returns true, if a new mesh instance must be created.
114 bool needsNewMesh( const std::string &rMaterialName );
115 /// Error report in token
116 void reportErrorTokenInFace();
118 private:
119 /// Default material name
120 static const std::string DEFAULT_MATERIAL;
121 //! Iterator to current position in buffer
122 DataArrayIt m_DataIt;
123 //! Iterator to end position of buffer
124 DataArrayIt m_DataItEnd;
125 //! Pointer to model instance
126 ObjFile::Model *m_pModel;
127 //! Current line (for debugging)
128 unsigned int m_uiLine;
129 //! Helper buffer
130 char m_buffer[BUFFERSIZE];
131 /// Pointer to IO system instance.
132 IOSystem *m_pIO;
133 };
135 } // Namespace Assimp
137 #endif