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