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.
 
 
 
 
 
 

285 line
9.6 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_MAIN_H_INCLUDED)
  35. #define AV_MAIN_H_INCLUDED
  36. #define AI_SHADER_COMPILE_FLAGS D3DXSHADER_USE_LEGACY_D3DX9_31_DLL
  37. // include resource definitions
  38. #include "resource.h"
  39. // Include ASSIMP headers (XXX: do we really need all of them?)
  40. #include <assimp/cimport.h>
  41. #include <assimp/Importer.hpp>
  42. #include <assimp/ai_assert.h>
  43. #include <assimp/cfileio.h>
  44. #include <assimp/postprocess.h>
  45. #include <assimp/scene.h>
  46. #include <assimp/IOSystem.hpp>
  47. #include <assimp/IOStream.hpp>
  48. #include <assimp/LogStream.hpp>
  49. #include <assimp/DefaultLogger.hpp>
  50. #include "../../code/AssimpPCH.h" /* HACK */
  51. #include "../../code/MaterialSystem.h" // aiMaterial class
  52. #include "../../code/StringComparison.h" // ASSIMP_stricmp and ASSIMP_strincmp
  53. // in order for std::min and std::max to behave properly
  54. #ifdef min
  55. #undef min
  56. #endif // min
  57. #ifdef max
  58. #undef max
  59. #endif // min
  60. #include <time.h>
  61. // default movement speed
  62. #define MOVE_SPEED 3.f
  63. using namespace Assimp;
  64. namespace AssimpView
  65. {
  66. #include "AssetHelper.h"
  67. #include "Camera.h"
  68. #include "RenderOptions.h"
  69. #include "Shaders.h"
  70. #include "Background.h"
  71. #include "LogDisplay.h"
  72. #include "LogWindow.h"
  73. #include "Display.h"
  74. #include "MeshRenderer.h"
  75. #include "MaterialManager.h"
  76. } // end of namespace AssimpView - for a while
  77. // outside of namespace, to help Intellisense and solve boost::metatype_stuff_miracle
  78. #include "AnimEvaluator.h"
  79. #include "SceneAnimator.h"
  80. namespace AssimpView
  81. {
  82. //-------------------------------------------------------------------------------
  83. // Function prototypes
  84. //-------------------------------------------------------------------------------
  85. int InitD3D(void);
  86. int ShutdownD3D(void);
  87. int CreateDevice (bool p_bMultiSample,bool p_bSuperSample, bool bHW = true);
  88. int CreateDevice (void);
  89. int ShutdownDevice(void);
  90. int GetProjectionMatrix (aiMatrix4x4& p_mOut);
  91. int LoadAsset(void);
  92. int CreateAssetData(void);
  93. int DeleteAssetData(bool bNoMaterials = false);
  94. int ScaleAsset(void);
  95. int DeleteAsset(void);
  96. int SetupFPSView();
  97. aiVector3D GetCameraMatrix (aiMatrix4x4& p_mOut);
  98. int CreateMaterial(AssetHelper::MeshHelper* pcMesh,const aiMesh* pcSource);
  99. void HandleMouseInputFPS( void );
  100. void HandleMouseInputLightRotate( void );
  101. void HandleMouseInputLocal( void );
  102. void HandleKeyboardInputFPS( void );
  103. void HandleMouseInputLightIntensityAndColor( void );
  104. void HandleMouseInputSkyBox( void );
  105. void HandleKeyboardInputTextureView( void );
  106. void HandleMouseInputTextureView( void );
  107. //-------------------------------------------------------------------------------
  108. //
  109. // Dialog procedure for the progress bar window
  110. //
  111. //-------------------------------------------------------------------------------
  112. INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg,UINT uMsg,
  113. WPARAM wParam,LPARAM lParam);
  114. //-------------------------------------------------------------------------------
  115. // Main message procedure of the application
  116. //
  117. // The function handles all incoming messages for the main window.
  118. // However, if does not directly process input commands.
  119. // NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
  120. // properly the code for all hotkeys has been moved to the WndMain
  121. //-------------------------------------------------------------------------------
  122. INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
  123. WPARAM wParam,LPARAM lParam);
  124. //-------------------------------------------------------------------------------
  125. //
  126. // Dialog procedure for the about dialog
  127. //
  128. //-------------------------------------------------------------------------------
  129. INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
  130. WPARAM wParam,LPARAM lParam);
  131. //-------------------------------------------------------------------------------
  132. //
  133. // Dialog prcoedure for the help dialog
  134. //
  135. //-------------------------------------------------------------------------------
  136. INT_PTR CALLBACK HelpDialogProc(HWND hwndDlg,UINT uMsg,
  137. WPARAM wParam,LPARAM lParam);
  138. //-------------------------------------------------------------------------------
  139. // Handle command line parameters
  140. //
  141. // The function loads an asset specified on the command line as first argument
  142. // Other command line parameters are not handled
  143. //-------------------------------------------------------------------------------
  144. void HandleCommandLine(char* p_szCommand);
  145. //-------------------------------------------------------------------------------
  146. template <class type, class intype>
  147. type clamp(intype in)
  148. {
  149. // for unsigned types only ...
  150. intype mask = (0x1u << (sizeof(type)*8))-1;
  151. return (type)std::max((intype)0,std::min(in,mask));
  152. }
  153. //-------------------------------------------------------------------------------
  154. // Position of the cursor relative to the 3ds max' like control circle
  155. //-------------------------------------------------------------------------------
  156. enum EClickPos
  157. {
  158. // The click was inside the inner circle (x,y axis)
  159. EClickPos_Circle,
  160. // The click was inside one of tghe vertical snap-ins
  161. EClickPos_CircleVert,
  162. // The click was inside onf of the horizontal snap-ins
  163. EClickPos_CircleHor,
  164. // the cklick was outside the circle (z-axis)
  165. EClickPos_Outside
  166. };
  167. #if (!defined AI_VIEW_CAPTION_BASE)
  168. # define AI_VIEW_CAPTION_BASE "Open Asset Import Library : Viewer "
  169. #endif // !! AI_VIEW_CAPTION_BASE
  170. //-------------------------------------------------------------------------------
  171. // Evil globals
  172. //-------------------------------------------------------------------------------
  173. extern HINSTANCE g_hInstance /*= NULL*/;
  174. extern HWND g_hDlg /*= NULL*/;
  175. extern IDirect3D9* g_piD3D /*= NULL*/;
  176. extern IDirect3DDevice9* g_piDevice /*= NULL*/;
  177. extern IDirect3DVertexDeclaration9* gDefaultVertexDecl /*= NULL*/;
  178. extern double g_fFPS /*= 0.0f*/;
  179. extern char g_szFileName[MAX_PATH];
  180. extern ID3DXEffect* g_piDefaultEffect /*= NULL*/;
  181. extern ID3DXEffect* g_piNormalsEffect /*= NULL*/;
  182. extern ID3DXEffect* g_piPassThroughEffect /*= NULL*/;
  183. extern ID3DXEffect* g_piPatternEffect /*= NULL*/;
  184. extern bool g_bMousePressed /*= false*/;
  185. extern bool g_bMousePressedR /*= false*/;
  186. extern bool g_bMousePressedM /*= false*/;
  187. extern bool g_bMousePressedBoth /*= false*/;
  188. extern float g_fElpasedTime /*= 0.0f*/;
  189. extern D3DCAPS9 g_sCaps;
  190. extern bool g_bLoadingFinished /*= false*/;
  191. extern HANDLE g_hThreadHandle /*= NULL*/;
  192. extern float g_fWheelPos /*= -10.0f*/;
  193. extern bool g_bLoadingCanceled /*= false*/;
  194. extern IDirect3DTexture9* g_pcTexture /*= NULL*/;
  195. extern aiMatrix4x4 g_mWorld;
  196. extern aiMatrix4x4 g_mWorldRotate;
  197. extern aiVector3D g_vRotateSpeed /*= aiVector3D(0.5f,0.5f,0.5f)*/;
  198. extern aiVector3D g_avLightDirs[1] /* =
  199. { aiVector3D(-0.5f,0.6f,0.2f) ,
  200. aiVector3D(-0.5f,0.5f,0.5f)} */;
  201. extern POINT g_mousePos /*= {0,0};*/;
  202. extern POINT g_LastmousePos /*= {0,0}*/;
  203. extern bool g_bFPSView /*= false*/;
  204. extern bool g_bInvert /*= false*/;
  205. extern EClickPos g_eClick;
  206. extern unsigned int g_iCurrentColor /*= 0*/;
  207. // NOTE: The light intensity is separated from the color, it can
  208. // directly be manipulated using the middle mouse button.
  209. // When the user chooses a color from the palette the intensity
  210. // is reset to 1.0
  211. // index[2] is the ambient color
  212. extern float g_fLightIntensity /*=0.0f*/;
  213. extern D3DCOLOR g_avLightColors[3];
  214. extern RenderOptions g_sOptions;
  215. extern Camera g_sCamera;
  216. extern AssetHelper *g_pcAsset /*= NULL*/;
  217. //
  218. // Contains the mask image for the HUD
  219. // (used to determine the position of a click)
  220. //
  221. // The size of the image is identical to the size of the main
  222. // HUD texture
  223. //
  224. extern unsigned char* g_szImageMask /*= NULL*/;
  225. extern float g_fACMR /*= 3.0f*/;
  226. extern IDirect3DQuery9* g_piQuery;
  227. extern bool g_bPlay /*= false*/;
  228. extern double g_dCurrent;
  229. extern float g_smoothAngle /*= 80.f*/;
  230. extern unsigned int ppsteps,ppstepsdefault;
  231. extern bool nopointslines;
  232. }
  233. #endif // !! AV_MAIN_H_INCLUDED