break compile; begin to modify for v2.0
This commit is contained in:
parent
ebb39c8750
commit
d59eb2ffe5
58
WFObj.cc
58
WFObj.cc
@ -11,7 +11,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
|
||||||
#include "WFObj.h"
|
#include "WFObj.h"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -89,46 +88,18 @@ static void checkGLErrorLine(const char * function, int line)
|
|||||||
|
|
||||||
/****** WFObj functions ******/
|
/****** WFObj functions ******/
|
||||||
|
|
||||||
WFObj::WFObj()
|
WFObj::WFObj(loadfile_t lf, loadtexture_t lt)
|
||||||
{
|
{
|
||||||
init();
|
m_loadfile = lf;
|
||||||
}
|
m_loadtexture = lt;
|
||||||
|
if (m_loadfile == NULL)
|
||||||
WFObj::WFObj(FileLoader & fileLoader)
|
|
||||||
{
|
|
||||||
init(&fileLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
WFObj::WFObj(TextureLoader & textureLoader)
|
|
||||||
{
|
|
||||||
init(NULL, &textureLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
WFObj::WFObj(FileLoader & fileLoader, TextureLoader & textureLoader)
|
|
||||||
{
|
|
||||||
init(&fileLoader, &textureLoader);
|
|
||||||
}
|
|
||||||
|
|
||||||
void WFObj::init (FileLoader * fileLoader,
|
|
||||||
TextureLoader * textureLoader)
|
|
||||||
{
|
|
||||||
m_fileLoader = fileLoader;
|
|
||||||
if (m_fileLoader == NULL)
|
|
||||||
{
|
{
|
||||||
m_fileLoader = new WFFileLoader();
|
m_loadfile = loadfile;
|
||||||
m_iCreatedFileLoader = true;
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
m_iCreatedFileLoader = false;
|
|
||||||
}
|
|
||||||
m_textureLoader = textureLoader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WFObj::~WFObj()
|
WFObj::~WFObj()
|
||||||
{
|
{
|
||||||
if (m_iCreatedFileLoader)
|
|
||||||
delete m_fileLoader;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WFObj::clear()
|
void WFObj::clear()
|
||||||
@ -137,26 +108,21 @@ void WFObj::clear()
|
|||||||
m_loadedVertex = false;
|
m_loadedVertex = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WFObj::load(const FileLoader::Path & path)
|
bool WFObj::load(const char *fname)
|
||||||
{
|
{
|
||||||
clear();
|
clear();
|
||||||
|
|
||||||
FileLoader::Buffer buff = m_fileLoader->load(path);
|
m_path = fname;
|
||||||
if (buff.size <= 0)
|
|
||||||
|
Buffer buff;
|
||||||
|
if (!m_loadfile(fname, &buff))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
m_path = path;
|
return load(buff);
|
||||||
string str(buff.data, buff.size);
|
|
||||||
stringstream istr(str, ios_base::in);
|
|
||||||
load(istr, buff.size);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool WFObj::load(std::istream & istr, unsigned int size)
|
bool WFObj::load(const WFObj::Buffer &buff)
|
||||||
{
|
{
|
||||||
char buf[size+1];
|
|
||||||
|
|
||||||
string buildup;
|
string buildup;
|
||||||
while (istr.good())
|
while (istr.good())
|
||||||
{
|
{
|
||||||
|
42
WFObj.h
42
WFObj.h
@ -2,8 +2,6 @@
|
|||||||
#ifndef WFOBJ_H
|
#ifndef WFOBJ_H
|
||||||
#define WFOBJ_H
|
#define WFOBJ_H
|
||||||
|
|
||||||
#include "FileLoader/FileLoader.h"
|
|
||||||
#include "TextureLoader/TextureLoader.h"
|
|
||||||
#include <GL/gl.h>
|
#include <GL/gl.h>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
@ -12,11 +10,16 @@
|
|||||||
class WFObj
|
class WFObj
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
WFObj();
|
/* types */
|
||||||
WFObj(FileLoader & fileLoader);
|
typedef bool (*loadfile_t)(const char *fname, Buffer *buff);
|
||||||
WFObj(TextureLoader & textureLoader);
|
typedef GLuint (*loadtexture_t)(const char *fname);
|
||||||
WFObj(FileLoader & fileLoader, TextureLoader & textureLoader);
|
|
||||||
~WFObj();
|
class Buffer
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
uint8_t *data;
|
||||||
|
size_t length;
|
||||||
|
};
|
||||||
|
|
||||||
class WFMtl
|
class WFMtl
|
||||||
{
|
{
|
||||||
@ -45,16 +48,14 @@ public:
|
|||||||
WFObj * m_obj;
|
WFObj * m_obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WFFileLoader : public FileLoader
|
/* constructors */
|
||||||
{
|
WFObj(loadfile_t lf = NULL, loadtexture_t lt = NULL);
|
||||||
public:
|
~WFObj();
|
||||||
virtual int getSize(const Path & path);
|
|
||||||
virtual Buffer load(const Path & path);
|
|
||||||
};
|
|
||||||
|
|
||||||
bool load(const FileLoader::Path & path);
|
/* methods */
|
||||||
GLuint render(bool doTextureInfo = true,
|
bool load(const char *fname);
|
||||||
bool enableBlending = false);
|
bool load(const Buffer &buff);
|
||||||
|
GLuint render(int flags);
|
||||||
const float * const getAABB() { return m_aabb; }
|
const float * const getAABB() { return m_aabb; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
@ -70,23 +71,20 @@ protected:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/* methods */
|
/* methods */
|
||||||
void init(FileLoader * fileLoader = NULL,
|
|
||||||
TextureLoader * textureLoader = NULL);
|
|
||||||
void clear();
|
void clear();
|
||||||
void processInputLine(const std::string & input);
|
void processInputLine(const std::string & input);
|
||||||
Vertex readVertex(const std::vector<std::string> & parts);
|
Vertex readVertex(const std::vector<std::string> & parts);
|
||||||
void parseVertexIndices(const std::string & vtxref, int * ret);
|
void parseVertexIndices(const std::string & vtxref, int * ret);
|
||||||
void updateAABB(const float * const vertex);
|
void updateAABB(const float * const vertex);
|
||||||
bool load(std::istream & istr, unsigned int size);
|
static Buffer loadfile(const char *path);
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
std::vector< std::vector<std::string> > m_data;
|
std::vector< std::vector<std::string> > m_data;
|
||||||
FileLoader::Path m_path;
|
FileLoader::Path m_path;
|
||||||
float m_aabb[6];
|
float m_aabb[6];
|
||||||
bool m_loadedVertex;
|
bool m_loadedVertex;
|
||||||
FileLoader * m_fileLoader;
|
loadfile_t m_loadfile;
|
||||||
TextureLoader * m_textureLoader;
|
loadtexture_t m_loadtexture;
|
||||||
bool m_iCreatedFileLoader;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user