2016-04-27 03:47:10 +00:00
|
|
|
#ifndef __MODEL_H__
|
|
|
|
#define __MODEL_H__
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
|
|
|
#include "geometry.h"
|
|
|
|
#include "tgaimage.h"
|
|
|
|
|
|
|
|
class Model {
|
|
|
|
private:
|
|
|
|
std::vector<Vec3f> verts_;
|
|
|
|
std::vector<std::vector<Vec3i> > faces_; // attention, this Vec3i means vertex/uv/normal
|
|
|
|
std::vector<Vec3f> norms_;
|
|
|
|
std::vector<Vec2f> uv_;
|
|
|
|
TGAImage diffusemap_;
|
|
|
|
TGAImage normalmap_;
|
|
|
|
TGAImage specularmap_;
|
2016-06-02 00:47:41 +00:00
|
|
|
Vec4f m_colorRGBA;
|
|
|
|
|
2016-04-27 03:47:10 +00:00
|
|
|
void load_texture(std::string filename, const char *suffix, TGAImage &img);
|
|
|
|
public:
|
|
|
|
Model(const char *filename);
|
2016-04-28 19:28:04 +00:00
|
|
|
Model();
|
2016-06-02 00:47:41 +00:00
|
|
|
void setColorRGBA(const float rgba[4])
|
|
|
|
{
|
|
|
|
for (int i=0;i<4;i++)
|
|
|
|
m_colorRGBA[i] = rgba[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
const Vec4f& getColorRGBA() const
|
|
|
|
{
|
|
|
|
return m_colorRGBA;
|
|
|
|
}
|
2016-04-28 19:28:04 +00:00
|
|
|
void loadDiffuseTexture(const char* relativeFileName);
|
2016-05-18 06:57:19 +00:00
|
|
|
void setDiffuseTextureFromData(unsigned char* textureImage,int textureWidth,int textureHeight);
|
2016-07-14 07:05:57 +00:00
|
|
|
void reserveMemory(int numVertices, int numIndices);
|
2016-04-28 19:28:04 +00:00
|
|
|
void addVertex(float x,float y,float z, float normalX, float normalY, float normalZ, float u, float v);
|
|
|
|
void addTriangle(int vertexposIndex0, int normalIndex0, int uvIndex0,
|
|
|
|
int vertexposIndex1, int normalIndex1, int uvIndex1,
|
|
|
|
int vertexposIndex2, int normalIndex2, int uvIndex2);
|
|
|
|
|
2016-04-27 03:47:10 +00:00
|
|
|
~Model();
|
|
|
|
int nverts();
|
|
|
|
int nfaces();
|
|
|
|
Vec3f normal(int iface, int nthvert);
|
|
|
|
Vec3f normal(Vec2f uv);
|
|
|
|
Vec3f vert(int i);
|
|
|
|
Vec3f vert(int iface, int nthvert);
|
|
|
|
Vec2f uv(int iface, int nthvert);
|
|
|
|
TGAColor diffuse(Vec2f uv);
|
|
|
|
float specular(Vec2f uv);
|
|
|
|
std::vector<int> face(int idx);
|
|
|
|
};
|
|
|
|
#endif //__MODEL_H__
|
|
|
|
|