17 #include "boost/bind.hpp" 19 #include "boost/spirit.hpp" 32 namespace spt=boost::spirit;
35 typedef spt::rule<spt::phrase_scanner_t>
srule;
44 srule vertex =
"v" >> spt::real_p[spt::append(values)] >>
45 spt::real_p[spt::append(values)] >>
46 spt::real_p[spt::append(values)];
48 spt::parse_info<>
result = spt::parse(_begin, vertex, spt::space_p);
52 m_verts.push_back(
Vec3(values[0],values[1],values[2]));
63 srule texcord =
"vt" >> spt::real_p[spt::append(values)] >>
64 spt::real_p[spt::append(values)] >>
65 *(spt::real_p[spt::append(values)]);
66 spt::parse_info<>
result = spt::parse(_begin, texcord, spt::space_p);
72 Real vt3 = values.size() == 3 ? values[2] : 0.0f;
73 m_tex.push_back(
Vec3(values[0],values[1],vt3));
82 srule norm =
"vn" >> spt::real_p[spt::append(values)] >>
83 spt::real_p[spt::append(values)] >>
84 spt::real_p[spt::append(values)];
86 spt::parse_info<>
result = spt::parse(_begin, norm, spt::space_p);
89 m_norm.push_back(
Vec3(values[0],values[1],values[2]));
98 std::vector<unsigned int> vec;
100 std::vector<unsigned int> tvec;
102 std::vector<unsigned int> nvec;
107 srule entry = spt::int_p[spt::append(vec)] >>
109 (
"/" >> (spt::int_p[spt::append(tvec)] | spt::epsilon_p) >>
110 "/" >> (spt::int_p[spt::append(nvec)] | spt::epsilon_p)
115 srule
face =
"f" >> entry >> entry >> entry >> *(entry);
117 spt::parse(_begin, face, spt::space_p);
119 unsigned int numVerts=
static_cast<unsigned int>(vec.size());
139 if(nvec.size() != vec.size())
141 std::cerr <<
"Something wrong with the face data will continue but may not be correct\n";
158 if(tvec.size() != vec.size())
160 std::cerr <<
"Something wrong with the face data will continue but may not be correct\n";
166 f.
m_tex.push_back(i-1);
181 srule comment = spt::comment_p(
"#");
194 srule vertex_type = vertex | tex | norm;
199 std::ifstream
in(_fname.c_str());
200 if (
in.is_open() !=
true)
202 std::cout<<
"FILE NOT FOUND !!!! "<<_fname.c_str()<<
"\n";
208 while(std::getline(
in, str))
210 spt::parse(str.c_str(), vertex_type | face | comment, spt::space_p);
216 m_nVerts=
static_cast<unsigned int>(m_verts.size());
217 m_nNorm=
static_cast<unsigned int>(m_norm.size());
218 m_nTex=
static_cast<unsigned int>(m_tex.size());
219 m_nFaces=
static_cast<unsigned int>(m_face.size());
225 this->calcDimensions();
237 m_nVerts=m_nNorm=m_nTex=m_nFaces=0;
239 m_maxX=0.0f; m_maxY=0.0f; m_maxZ=0.0f;
240 m_minX=0.0f; m_minY=0.0f; m_minZ=0.0f;
244 m_loaded=load(_fname,_calcBB);
256 m_nVerts=m_nNorm=m_nTex=m_nFaces=0;
258 m_maxX=0.0f; m_maxY=0.0f; m_maxZ=0.0f;
259 m_minX=0.0f; m_minY=0.0f; m_minZ=0.0f;
262 m_loaded=load(_fname,_calcBB);
265 loadTexture(_texName);
276 m_nVerts=m_nNorm=m_nTex=m_nFaces=0;
278 m_maxX=0.0f; m_maxY=0.0f; m_maxZ=0.0f;
279 m_minX=0.0f; m_minY=0.0f; m_minZ=0.0f;
282 m_loaded=load(_fname,_calcBB);
285 loadTexture(_texName);
293 std::fstream fileOut;
294 fileOut.open(_fname.c_str(),std::ios::out);
295 if (!fileOut.is_open())
297 std::cout <<
"File : "<<_fname<<
" Not founds "<<std::endl;
301 fileOut<<
"# This file was created by ngl Obj exporter "<<_fname.c_str()<<std::endl;
304 for(
Vec3 v : m_verts)
306 fileOut<<
"v "<<
v.m_x<<
" "<<
v.m_y<<
" "<<
v.m_z<<std::endl;
312 fileOut<<
"vt "<<
v.m_x<<
" "<<
v.m_y<<std::endl;
318 fileOut<<
"vn "<<
v.m_x<<
" "<<
v.m_y<<
" "<<
v.m_z<<std::endl;
326 for(
unsigned int i=0; i<=
f.m_numVerts; ++i)
329 fileOut<<
f.m_vert[i]+1;
331 fileOut<<
f.m_tex[i]+1;
334 fileOut<<
f.m_norm[i]+1;
std::vector< uint32_t > m_tex
The texture co-ord index.
#define NGL_UNUSED(arg)
define unused to quiet Warnings
std::vector< uint32_t > m_norm
the normal index
void save(const std::string &_fname) const noexcept
method to save the obj
std::vector< uint32_t > m_vert
The vertices index.
virtual void parseVertex(const char *_begin) noexcept
parser function to parse the vertex used by boost::spirit parser
simple Vec3 encapsulates a 3 float object like glsl vec3 but not maths use the Vec3 class for maths a...
implementation files for RibExport class
GLint GLsizei const GLuint64 * values
PRECISION Real
create a variable called Real which is the main data type we use (GLfloat for most cases) ...
virtual void parseFace(const char *_begin) noexcept
parser function to parse the Face data used by boost::spirit parser
an abstract base mesh used to build specific meshes such as Obj
simple class used to encapsulate a single face of an abstract mesh file
spt::rule< spt::phrase_scanner_t > srule
basic obj loader inherits from AbstractMesh
virtual void parseTextureCoordinate(const char *_begin) noexcept
parser function to parse the text cord used by boost::spirit parser
virtual void parseNormal(const char *_begin) noexcept
parser function to parse the Norma used by boost::spirit parser
bool load(const std::string &_fname, bool _calcBB=true) noexcept
Method to load the file in.
bool m_textureCoord
debug flag to turn face on and off
unsigned int m_numVerts
the number of vertices in the face
GLsizei const GLchar *const * string
Obj() noexcept
default constructor
GLenum GLuint GLint GLenum face