You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

238 lines
7.2 KiB

  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2012, assimp team
  6. All rights reserved.
  7. Redistribution and use of this software in source and binary forms,
  8. with or without modification, are permitted provided that the following
  9. conditions are met:
  10. * Redistributions of source code must retain the above
  11. copyright notice, this list of conditions and the
  12. following disclaimer.
  13. * Redistributions in binary form must reproduce the above
  14. copyright notice, this list of conditions and the
  15. following disclaimer in the documentation and/or other
  16. materials provided with the distribution.
  17. * Neither the name of the assimp team, nor the names of its
  18. contributors may be used to endorse or promote products
  19. derived from this software without specific prior
  20. written permission of the assimp team.
  21. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  24. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  25. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  26. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  27. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  28. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  29. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  30. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  31. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  32. ---------------------------------------------------------------------------
  33. */
  34. #if (!defined AV_ASSET_HELPER_H_INCLUDED)
  35. #define AV_ASSET_HELPER_H_INCLUDED
  36. class SceneAnimator;
  37. //-------------------------------------------------------------------------------
  38. /** \brief Class to wrap ASSIMP's asset output structures
  39. */
  40. //-------------------------------------------------------------------------------
  41. class AssetHelper
  42. {
  43. public:
  44. enum
  45. {
  46. // the original normal set will be used
  47. ORIGINAL = 0x0u,
  48. // a smoothed normal set will be used
  49. SMOOTH = 0x1u,
  50. // a hard normal set will be used
  51. HARD = 0x2u,
  52. };
  53. // default constructor
  54. AssetHelper()
  55. : iNormalSet(ORIGINAL)
  56. {
  57. mAnimator = NULL;
  58. apcMeshes = NULL;
  59. pcScene = NULL;
  60. }
  61. //---------------------------------------------------------------
  62. // default vertex data structure
  63. // (even if tangents, bitangents or normals aren't
  64. // required by the shader they will be committed to the GPU)
  65. //---------------------------------------------------------------
  66. struct Vertex
  67. {
  68. aiVector3D vPosition;
  69. aiVector3D vNormal;
  70. D3DCOLOR dColorDiffuse;
  71. aiVector3D vTangent;
  72. aiVector3D vBitangent;
  73. aiVector2D vTextureUV;
  74. aiVector2D vTextureUV2;
  75. unsigned char mBoneIndices[4];
  76. unsigned char mBoneWeights[4]; // last Weight not used, calculated inside the vertex shader
  77. /** Returns the vertex declaration elements to create a declaration from. */
  78. static D3DVERTEXELEMENT9* GetDeclarationElements()
  79. {
  80. static D3DVERTEXELEMENT9 decl[] =
  81. {
  82. { 0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
  83. { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },
  84. { 0, 24, D3DDECLTYPE_D3DCOLOR, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_COLOR, 0 },
  85. { 0, 28, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },
  86. { 0, 40, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },
  87. { 0, 52, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
  88. { 0, 60, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
  89. { 0, 68, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDINDICES, 0 },
  90. { 0, 72, D3DDECLTYPE_UBYTE4N, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BLENDWEIGHT, 0 },
  91. D3DDECL_END()
  92. };
  93. return decl;
  94. }
  95. };
  96. //---------------------------------------------------------------
  97. // FVF vertex structure used for normals
  98. //---------------------------------------------------------------
  99. struct LineVertex
  100. {
  101. aiVector3D vPosition;
  102. DWORD dColorDiffuse;
  103. // retrieves the FVF code of the vertex type
  104. static DWORD GetFVF()
  105. {
  106. return D3DFVF_DIFFUSE | D3DFVF_XYZ;
  107. }
  108. };
  109. //---------------------------------------------------------------
  110. // Helper class to store GPU related resources created for
  111. // a given aiMesh
  112. //---------------------------------------------------------------
  113. class MeshHelper
  114. {
  115. public:
  116. MeshHelper ()
  117. :
  118. piVB (NULL),
  119. piIB (NULL),
  120. piVBNormals (NULL),
  121. piEffect (NULL),
  122. bSharedFX (false),
  123. piDiffuseTexture (NULL),
  124. piSpecularTexture (NULL),
  125. piAmbientTexture (NULL),
  126. piEmissiveTexture (NULL),
  127. piNormalTexture (NULL),
  128. piOpacityTexture (NULL),
  129. piShininessTexture (NULL),
  130. piLightmapTexture (NULL),
  131. twosided (false),
  132. pvOriginalNormals (NULL)
  133. {}
  134. ~MeshHelper ()
  135. {
  136. // NOTE: This is done in DeleteAssetData()
  137. // TODO: Make this a proper d'tor
  138. }
  139. // shading mode to use. Either Lambert or otherwise phong
  140. // will be used in every case
  141. aiShadingMode eShadingMode;
  142. // vertex buffer
  143. IDirect3DVertexBuffer9* piVB;
  144. // index buffer. For partially transparent meshes
  145. // created with dynamic usage to be able to update
  146. // the buffer contents quickly
  147. IDirect3DIndexBuffer9* piIB;
  148. // vertex buffer to be used to draw vertex normals
  149. // (vertex normals are generated in every case)
  150. IDirect3DVertexBuffer9* piVBNormals;
  151. // shader to be used
  152. ID3DXEffect* piEffect;
  153. bool bSharedFX;
  154. // material textures
  155. IDirect3DTexture9* piDiffuseTexture;
  156. IDirect3DTexture9* piSpecularTexture;
  157. IDirect3DTexture9* piAmbientTexture;
  158. IDirect3DTexture9* piEmissiveTexture;
  159. IDirect3DTexture9* piNormalTexture;
  160. IDirect3DTexture9* piOpacityTexture;
  161. IDirect3DTexture9* piShininessTexture;
  162. IDirect3DTexture9* piLightmapTexture;
  163. // material colors
  164. D3DXVECTOR4 vDiffuseColor;
  165. D3DXVECTOR4 vSpecularColor;
  166. D3DXVECTOR4 vAmbientColor;
  167. D3DXVECTOR4 vEmissiveColor;
  168. // opacity for the material
  169. float fOpacity;
  170. // shininess for the material
  171. float fShininess;
  172. // strength of the specular highlight
  173. float fSpecularStrength;
  174. // two-sided?
  175. bool twosided;
  176. // Stores a pointer to the original normal set of the asset
  177. aiVector3D* pvOriginalNormals;
  178. };
  179. // One instance per aiMesh in the globally loaded asset
  180. MeshHelper** apcMeshes;
  181. // Scene wrapper instance
  182. aiScene* pcScene;
  183. // Animation player to animate the scene if necessary
  184. SceneAnimator* mAnimator;
  185. // Specifies the normal set to be used
  186. unsigned int iNormalSet;
  187. // ------------------------------------------------------------------
  188. // set the normal set to be used
  189. void SetNormalSet(unsigned int iSet);
  190. // ------------------------------------------------------------------
  191. // flip all normal vectors
  192. void FlipNormals();
  193. void FlipNormalsInt();
  194. };
  195. #endif // !! IG