Mesh.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // ----------------------------------------------------------------
  2. // From Game Programming in C++ by Sanjay Madhav
  3. // Copyright (C) 2017 Sanjay Madhav. All rights reserved.
  4. //
  5. // Released under the BSD License
  6. // See LICENSE in root directory for full details.
  7. // ----------------------------------------------------------------
  8. #pragma once
  9. #include <vector>
  10. #include <string>
  11. #include "Collision.h"
  12. #include "VertexArray.h"
  13. class Mesh
  14. {
  15. public:
  16. Mesh();
  17. ~Mesh();
  18. // Load/unload mesh
  19. bool Load(const std::string& fileName, class Renderer* renderer);
  20. void Unload();
  21. // Get the vertex array associated with this mesh
  22. VertexArray* GetVertexArray() { return mVertexArray; }
  23. // Get a texture from specified index
  24. class Texture* GetTexture(size_t index);
  25. // Get name of shader
  26. const std::string& GetShaderName() const { return mShaderName; }
  27. // Get file name
  28. const std::string& GetFileName() const { return mFileName; }
  29. // Get object space bounding sphere radius
  30. float GetRadius() const { return mRadius; }
  31. // Get object space bounding box
  32. const AABB& GetBox() const { return mBox; }
  33. // Get specular power of mesh
  34. float GetSpecPower() const { return mSpecPower; }
  35. // Save the mesh in binary format
  36. void SaveBinary(const std::string& fileName, const void* verts,
  37. uint32_t numVerts, VertexArray::Layout layout,
  38. const uint32_t* indices, uint32_t numIndices,
  39. const std::vector<std::string>& textureNames,
  40. const AABB& box, float radius,
  41. float specPower);
  42. // Load in the mesh from binary format
  43. bool LoadBinary(const std::string& fileName, class Renderer* renderer);
  44. private:
  45. // AABB collision
  46. AABB mBox;
  47. // Textures associated with this mesh
  48. std::vector<class Texture*> mTextures;
  49. // Vertex array associated with this mesh
  50. VertexArray* mVertexArray;
  51. // Name of shader specified by mesh
  52. std::string mShaderName;
  53. // Name of mesh file
  54. std::string mFileName;
  55. // Stores object space bounding sphere radius
  56. float mRadius;
  57. // Specular power of surface
  58. float mSpecPower;
  59. };