assimp_view.h 10 KB

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