Advertisement
Guest User

Untitled

a guest
Aug 1st, 2012
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.05 KB | None | 0 0
  1. //---------------------------------------------------------------
  2. // Helper class to store GPU related resources created for
  3. // a given aiMesh
  4. //---------------------------------------------------------------
  5. class MeshHelper
  6. {
  7.     public:
  8.  
  9.         MeshHelper ()
  10.             :
  11.             piVB                (NULL),
  12.             piIB                (NULL),
  13.             piEffect            (NULL),
  14.             piVBNormals         (NULL),
  15.             piDiffuseTexture    (NULL),
  16.             piSpecularTexture   (NULL),
  17.             piAmbientTexture    (NULL),
  18.             piNormalTexture     (NULL),
  19.             piEmissiveTexture   (NULL),
  20.             piOpacityTexture    (NULL),
  21.             piShininessTexture  (NULL),
  22.             piLightmapTexture   (NULL),
  23.             //pvOriginalNormals (NULL),
  24.             bSharedFX(false),
  25.             twosided (false){}
  26.  
  27.         ~MeshHelper ()
  28.         {
  29.             // NOTE: This is done in DeleteAssetData()
  30.             // TODO: Make this a proper d'tor
  31.         }
  32.  
  33.         // shading mode to use. Either Lambert or otherwise phong
  34.         // will be used in every case
  35.         //aiShadingMode eShadingMode;
  36.  
  37.         // vertex buffer
  38.         IDirect3DVertexBuffer9* piVB;
  39.  
  40.         // index buffer. For partially transparent meshes
  41.         // created with dynamic usage to be able to update
  42.         // the buffer contents quickly
  43.         IDirect3DIndexBuffer9* piIB;
  44.  
  45.         // vertex buffer to be used to draw vertex normals
  46.         // (vertex normals are generated in every case)
  47.         IDirect3DVertexBuffer9* piVBNormals;
  48.  
  49.         // shader to be used
  50.         ID3DXEffect* piEffect;
  51.         bool bSharedFX;
  52.  
  53.         // material textures
  54.         IDirect3DTexture9* piDiffuseTexture;
  55.         IDirect3DTexture9* piSpecularTexture;
  56.         IDirect3DTexture9* piAmbientTexture;
  57.         IDirect3DTexture9* piEmissiveTexture;
  58.         IDirect3DTexture9* piNormalTexture;
  59.         IDirect3DTexture9* piOpacityTexture;
  60.         IDirect3DTexture9* piShininessTexture;
  61.         IDirect3DTexture9* piLightmapTexture;
  62.  
  63.         // material colors
  64.         D3DXVECTOR4 vDiffuseColor;
  65.         D3DXVECTOR4 vSpecularColor;
  66.         D3DXVECTOR4 vAmbientColor;
  67.         D3DXVECTOR4 vEmissiveColor;
  68.  
  69.         // opacity for the material
  70.         float fOpacity;
  71.  
  72.         // shininess for the material
  73.         float fShininess;
  74.  
  75.         // strength of the specular highlight
  76.         float fSpecularStrength;
  77.  
  78.         // two-sided?
  79.         bool twosided;
  80.  
  81.         // Stores a pointer to the original normal set of the asset
  82.         //aiVector3D* pvOriginalNormals;
  83. };
  84.  
  85. ////////////////////////////////////////////////////////////
  86. // default vertex data structure
  87. // (even if tangents, bitangents or normals aren't
  88. // required by the shader they will be committed to the GPU)
  89. ////////////////////////////////////////////////////////////
  90. struct Vertex
  91. {
  92.     aiVector3D vPosition;
  93.     aiVector3D vNormal;
  94.  
  95.     D3DCOLOR dColorDiffuse;
  96.     aiVector3D vTangent;
  97.     aiVector3D vBitangent;
  98.     aiVector2D vTextureUV;
  99.     aiVector2D vTextureUV2;
  100.     unsigned char mBoneIndices[4];
  101.     unsigned char mBoneWeights[4]; // last Weight not used, calculated inside the vertex shader
  102.  
  103.     /** Returns the vertex declaration elements to create a declaration from. */
  104.     static D3DVERTEXELEMENT9* GetDeclarationElements()
  105.     {
  106.         static D3DVERTEXELEMENT9 decl[] =
  107.         {
  108.             { 0,  0, D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION,     0 },
  109.             { 0, 12, D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,       0 },
  110.             { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR,        0 },
  111.             { 0, 28, D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT,      0 },
  112.             { 0, 40, D3DDECLTYPE_FLOAT3,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL,     0 },
  113.             { 0, 52, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,     0 },
  114.             { 0, 60, D3DDECLTYPE_FLOAT2,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD,     1 },
  115.             { 0, 68, D3DDECLTYPE_UBYTE4,   D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
  116.             { 0, 72, D3DDECLTYPE_UBYTE4N,  D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT,  0 },
  117.             D3DDECL_END()
  118.         };
  119.  
  120.         return decl;
  121.     }
  122. };
  123.  
  124. ////////////////////////////////////////////////////////////
  125. // FVF vertex structure used for normals
  126. ////////////////////////////////////////////////////////////
  127. struct LineVertex
  128. {
  129.     aiVector3D vPosition;
  130.     DWORD dColorDiffuse;
  131.  
  132.     // retrieves the FVF code of the vertex type
  133.     static DWORD GetFVF()
  134.     {
  135.         return D3DFVF_DIFFUSE | D3DFVF_XYZ;
  136.     }
  137. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement