Advertisement
Guest User

md5animation.h

a guest
Mar 5th, 2013
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.75 KB | None | 0 0
  1. /*-----------------------------------------*\
  2. |               md5animation.h              |
  3. |                                           |
  4. |                                           |
  5. \*-----------------------------------------*/
  6.  
  7. #ifndef _MD5ANIMATION_H_
  8. #define _MD5ANIMATION_H_
  9.  
  10. #include <D3D11.h>
  11. #include <D3DX11.h>
  12. #include <D3DX10math.h>
  13. #include <xnamath.h>
  14. #include <vector>
  15. #include <fstream>
  16. #include <iostream>
  17. #include <string>
  18. #include <cstring>
  19. #include <Windows.h>
  20. using namespace std;
  21.  
  22. #pragma comment(lib, "d3d11.lib")
  23. #pragma comment(lib, "d3dx11.lib")
  24.  
  25. #include "Texture.h"
  26.  
  27. class md5animation
  28. {
  29.  
  30.     private:
  31.        
  32.         //Overloaded VertexType Structure
  33.         //Stores information sent to shader
  34.         //Stores Vertices start weight index value - Will not be sent to shader
  35.         //Stores number of weights per vertex bound - Will not be sent to shader
  36.         struct VertexType
  37.         {
  38.             VertexType(){}
  39.             VertexType(float x, float y, float z,
  40.                     float u, float v,
  41.                     float nx, float ny, float nz,
  42.                     float tx, float ty, float tz)
  43.                     : pos(x, y, z), texCoord(u, v),
  44.                     normal(nx, ny, nz),tangent(tx, ty, tz){}
  45.  
  46.             XMFLOAT3 pos;
  47.             XMFLOAT2 texCoord;
  48.             XMFLOAT3 normal;
  49.             XMFLOAT3 tangent;
  50.             XMFLOAT3 biTangent;
  51.  
  52.             //Will not be sent to shader
  53.             int StartWeight;
  54.             int WeightCount;
  55.         };
  56.  
  57.         //Joint
  58.         //Stores Joint information for the md5mesh file
  59.         struct Joint
  60.         {
  61.             std::wstring name;
  62.             int parentID;
  63.             XMFLOAT3 pos;
  64.             XMFLOAT4 orientation;
  65.         };
  66.  
  67.         //Weight
  68.         //Stores Weight information for the md5mesh file
  69.         struct Weight
  70.         {
  71.             int jointID;
  72.             float bias;
  73.             XMFLOAT3 pos;
  74.         };
  75.  
  76.         //Model Subset
  77.         //Stores various information for md5mesh file, most of them vectors
  78.         //Includes a brand new vertex and index buffer
  79.         struct ModelSubset
  80.         {
  81.             int texArrayIndex;
  82.             int numTriangles;
  83.             std::vector<VertexType> vertices;
  84.             std::vector<DWORD> indices;
  85.             std::vector<Weight> weights;
  86.             std::vector<XMFLOAT3> positions;
  87.             ID3D11Buffer* vertBuff;
  88.             ID3D11Buffer* indexBuff;
  89.         };
  90.  
  91.         //Model 3D
  92.         //Stores information that applies to the model as a whole
  93.         struct Model3D
  94.         {
  95.             int numSubsets;
  96.             int numJoints;
  97.             std::vector<Joint> joints;
  98.             std::vector<ModelSubset> subsets;
  99.         };
  100.  
  101.         //cbPerObject
  102.         //Create effects constant buffer's structure
  103.         struct cbPerObject
  104.         {
  105.             XMMATRIX  WVP;
  106.             XMMATRIX World;
  107.  
  108.             //These will be used for the pixel shader
  109.             XMFLOAT4 difColor;
  110.             BOOL hasTexture;
  111.             //Because of HLSL structure packing, we will use windows BOOL
  112.             //instead of bool because HLSL packs things into 4 bytes, and
  113.             //bool is only one byte, where BOOL is 4 bytes
  114.             BOOL hasNormMap;
  115.         };
  116.  
  117.  
  118.     public:
  119.  
  120.         //Public
  121.         md5animation();
  122.         ~md5animation();
  123.  
  124.         bool Init(ID3D11Device*, WCHAR*, WCHAR*);
  125.         void Render(ID3D11DeviceContext*);
  126.         void Shutdown();
  127.  
  128.         int GetIndexCount();
  129.         ID3D11ShaderResourceView* GetTexture();
  130.  
  131.     private:
  132.  
  133.         bool InitBuffers(ID3D11Device*);
  134.         void ShutdownBuffers();
  135.         void RenderBuffers(ID3D11DeviceContext*);
  136.  
  137.         bool LoadTexture(ID3D11Device*, WCHAR*);
  138.         void ReleaseTexture();
  139.  
  140.         bool LoadMD5Model(ID3D11Device*,
  141.                         std::wstring filename,
  142.                         Model3D& MD5Model,
  143.                         std::vector<ID3D11ShaderResourceView*>& shaderResourceViewArray,
  144.                         std::vector<std::wstring> texFileNameArray);
  145.         void ReleaseModel();
  146.  
  147.     private:
  148.  
  149.         ID3D11Buffer *m_vertexBuffer;
  150.         ID3D11Buffer* m_indexBuffer;
  151.         ID3D11Buffer* cbPerObjectBuffer;
  152.         int m_vertexCount;
  153.         int m_indexCount;
  154.  
  155.         XMMATRIX m_smilesWorld;     //World Matrix
  156.         Model3D m_NewMD5Model;      //Model Data
  157.         Texture* m_texture;         //Texture Data
  158.         cbPerObject m_cbPerObj;     //Constant Buffer
  159.  
  160.         //Textures and Material variables, used for all mesh's loaded
  161.         std::vector<ID3D11ShaderResourceView*> m_meshSRV;
  162.         std::vector<std::wstring> m_textureNameArray;
  163. };
  164.  
  165. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement