model.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef __MODEL_H__
  2. #define __MODEL_H__
  3. #include <vector>
  4. #include <string>
  5. #include "geometry.h"
  6. #include "tgaimage.h"
  7. class Model {
  8. private:
  9. std::vector<Vec3f> verts_;
  10. std::vector<std::vector<Vec3i> > faces_; // attention, this Vec3i means vertex/uv/normal
  11. std::vector<Vec3f> norms_;
  12. std::vector<Vec2f> uv_;
  13. TGAImage diffusemap_;
  14. TGAImage normalmap_;
  15. TGAImage specularmap_;
  16. Vec4f m_colorRGBA;
  17. void load_texture(std::string filename, const char *suffix, TGAImage &img);
  18. public:
  19. Model(const char *filename);
  20. Model();
  21. void setColorRGBA(const float rgba[4])
  22. {
  23. for (int i=0;i<4;i++)
  24. m_colorRGBA[i] = rgba[i];
  25. }
  26. const Vec4f& getColorRGBA() const
  27. {
  28. return m_colorRGBA;
  29. }
  30. void loadDiffuseTexture(const char* relativeFileName);
  31. void setDiffuseTextureFromData(unsigned char* textureImage,int textureWidth,int textureHeight);
  32. void reserveMemory(int numVertices, int numIndices);
  33. void addVertex(float x,float y,float z, float normalX, float normalY, float normalZ, float u, float v);
  34. void addTriangle(int vertexposIndex0, int normalIndex0, int uvIndex0,
  35. int vertexposIndex1, int normalIndex1, int uvIndex1,
  36. int vertexposIndex2, int normalIndex2, int uvIndex2);
  37. ~Model();
  38. int nverts();
  39. int nfaces();
  40. Vec3f normal(int iface, int nthvert);
  41. Vec3f normal(Vec2f uv);
  42. Vec3f vert(int i);
  43. Vec3f vert(int iface, int nthvert);
  44. Vec2f uv(int iface, int nthvert);
  45. TGAColor diffuse(Vec2f uv);
  46. float specular(Vec2f uv);
  47. std::vector<int> face(int idx);
  48. };
  49. #endif //__MODEL_H__