Display.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. ---------------------------------------------------------------------------
  3. Open Asset Import Library (assimp)
  4. ---------------------------------------------------------------------------
  5. Copyright (c) 2006-2020, 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_DISPLAY_H_INCLUDED)
  35. #define AV_DISPLAY_H_INCLUDE
  36. #include <windows.h>
  37. #include <shellapi.h>
  38. #include <commctrl.h>
  39. // see CDisplay::m_aiImageList
  40. #define AI_VIEW_IMGLIST_NODE 0x0
  41. #define AI_VIEW_IMGLIST_MATERIAL 0x1
  42. #define AI_VIEW_IMGLIST_TEXTURE 0x2
  43. #define AI_VIEW_IMGLIST_TEXTURE_INVALID 0x3
  44. #define AI_VIEW_IMGLIST_MODEL 0x4
  45. namespace AssimpView
  46. {
  47. //-------------------------------------------------------------------------------
  48. /* Corresponds to the "Display" combobox in the UI
  49. */
  50. //-------------------------------------------------------------------------------
  51. class CDisplay
  52. {
  53. private:
  54. // helper class
  55. struct Info
  56. {
  57. Info( D3DXVECTOR4* p1,
  58. AssetHelper::MeshHelper* p2,
  59. const char* p3 )
  60. : pclrColor( p1 ), pMesh( p2 ), szShaderParam( p3 ) {}
  61. D3DXVECTOR4* pclrColor;
  62. AssetHelper::MeshHelper* pMesh;
  63. const char* szShaderParam;
  64. };
  65. // default constructor
  66. CDisplay()
  67. : m_iViewMode( VIEWMODE_FULL ),
  68. m_pcCurrentTexture( NULL ),
  69. m_pcCurrentNode( NULL ),
  70. m_pcCurrentMaterial( NULL ),
  71. m_hImageList( NULL ),
  72. m_hRoot( NULL ),
  73. m_fTextureZoom( 1000.0f )
  74. {
  75. this->m_aiImageList[ 0 ] = 0;
  76. this->m_aiImageList[ 1 ] = 1;
  77. this->m_aiImageList[ 2 ] = 2;
  78. this->m_aiImageList[ 3 ] = 3;
  79. this->m_aiImageList[ 4 ] = 4;
  80. this->m_avCheckerColors[ 0 ].x = this->m_avCheckerColors[ 0 ].y = this->m_avCheckerColors[ 0 ].z = 0.4f;
  81. this->m_avCheckerColors[ 1 ].x = this->m_avCheckerColors[ 1 ].y = this->m_avCheckerColors[ 1 ].z = 0.6f;
  82. }
  83. public:
  84. //------------------------------------------------------------------
  85. enum
  86. {
  87. // the full model is displayed
  88. VIEWMODE_FULL,
  89. // a material is displayed on a simple spjere as model
  90. VIEWMODE_MATERIAL,
  91. // a texture with an UV set mapped on it is displayed
  92. VIEWMODE_TEXTURE,
  93. // a single node in the scenegraph is displayed
  94. VIEWMODE_NODE,
  95. };
  96. //------------------------------------------------------------------
  97. // represents a texture in the tree view
  98. struct TextureInfo
  99. {
  100. // texture info
  101. IDirect3DTexture9** piTexture;
  102. // Blend factor of the texture
  103. float fBlend;
  104. // blend operation for the texture
  105. aiTextureOp eOp;
  106. // UV index for the texture
  107. unsigned int iUV;
  108. // Associated tree item
  109. HTREEITEM hTreeItem;
  110. // Original path to the texture
  111. std::string szPath;
  112. // index of the corresponding material
  113. unsigned int iMatIndex;
  114. // type of the texture
  115. unsigned int iType;
  116. };
  117. //------------------------------------------------------------------
  118. // represents a node in the tree view
  119. struct NodeInfo
  120. {
  121. // node object
  122. aiNode* psNode;
  123. // corresponding tree view item
  124. HTREEITEM hTreeItem;
  125. };
  126. //------------------------------------------------------------------
  127. // represents a mesh in the tree view
  128. struct MeshInfo
  129. {
  130. // the mesh object
  131. aiMesh* psMesh;
  132. // corresponding tree view item
  133. HTREEITEM hTreeItem;
  134. };
  135. //------------------------------------------------------------------
  136. // represents a material in the tree view
  137. struct MaterialInfo
  138. {
  139. // material index
  140. unsigned int iIndex;
  141. // material object
  142. aiMaterial* psMaterial;
  143. // ID3DXEffect interface
  144. ID3DXEffect* piEffect;
  145. // corresponding tree view item
  146. HTREEITEM hTreeItem;
  147. };
  148. //------------------------------------------------------------------
  149. // Singleton accessors
  150. static CDisplay s_cInstance;
  151. inline static CDisplay& Instance()
  152. {
  153. return s_cInstance;
  154. }
  155. //------------------------------------------------------------------
  156. // Called during the render loop. Renders the scene (including the
  157. // HUD etc) in the current view mode
  158. int OnRender();
  159. //------------------------------------------------------------------
  160. // called when the user selects another item in the "Display" tree
  161. // view the method determines the new view mode and performs all
  162. // required operations
  163. // \param p_hTreeItem Selected tree view item
  164. int OnSetup( HTREEITEM p_hTreeItem );
  165. //------------------------------------------------------------------
  166. // Variant 1: Render the full scene with the asset
  167. int RenderFullScene();
  168. #if 0
  169. //------------------------------------------------------------------
  170. // Variant 2: Render only a part of the scene. One node to
  171. // be exact
  172. int RenderScenePart();
  173. #endif
  174. //------------------------------------------------------------------
  175. // Variant 3: Render a large sphere and map a given material on it
  176. int RenderMaterialView();
  177. //------------------------------------------------------------------
  178. // Variant 4: Render a flat plane, map a texture on it and
  179. // display the UV wire on it
  180. int RenderTextureView();
  181. //------------------------------------------------------------------
  182. // Fill the UI combobox with a list of all supported view modi
  183. //
  184. // The display modes are added in order
  185. int FillDisplayList( void );
  186. //------------------------------------------------------------------
  187. // Add a material and all sub textures to the display mode list
  188. // hRoot - Handle to the root of the tree view
  189. // iIndex - Material index
  190. int AddMaterialToDisplayList( HTREEITEM hRoot,
  191. unsigned int iIndex );
  192. //------------------------------------------------------------------
  193. // Add a texture to the display list
  194. // pcMat - material containing the texture
  195. // hTexture - Handle to the material tree item
  196. // szPath - Path to the texture
  197. // iUVIndex - UV index to be used for the texture
  198. // fBlendFactor - Blend factor to be used for the texture
  199. // eTextureOp - texture operation to be used for the texture
  200. int AddTextureToDisplayList( unsigned int iType,
  201. unsigned int iIndex,
  202. const aiString* szPath,
  203. HTREEITEM hFX,
  204. unsigned int iUVIndex = 0,
  205. const float fBlendFactor = 0.0f,
  206. aiTextureOp eTextureOp = aiTextureOp_Multiply,
  207. unsigned int iMesh = 0 );
  208. //------------------------------------------------------------------
  209. // Add a node to the display list
  210. // Recusrivly adds all subnodes as well
  211. // iIndex - Index of the node in the parent's child list
  212. // iDepth - Current depth of the node
  213. // pcNode - Node object
  214. // hRoot - Parent tree view node
  215. int AddNodeToDisplayList(
  216. unsigned int iIndex,
  217. unsigned int iDepth,
  218. aiNode* pcNode,
  219. HTREEITEM hRoot );
  220. //------------------------------------------------------------------
  221. // Add a mesh to the display list
  222. // iIndex - Index of the mesh in the scene's mesh list
  223. // hRoot - Parent tree view node
  224. int AddMeshToDisplayList(
  225. unsigned int iIndex,
  226. HTREEITEM hRoot );
  227. //------------------------------------------------------------------
  228. // Load the image list for the tree view item
  229. int LoadImageList( void );
  230. //------------------------------------------------------------------
  231. // Expand all nodes in the tree
  232. int ExpandTree();
  233. //------------------------------------------------------------------
  234. // Fill the UI combobox with a list of all supported animations
  235. // The animations are added in order
  236. int FillAnimList( void );
  237. //------------------------------------------------------------------
  238. // Clear the combox box containing the list of animations
  239. int ClearAnimList( void );
  240. //------------------------------------------------------------------
  241. // Clear the combox box containing the list of scenegraph items
  242. int ClearDisplayList( void );
  243. //------------------------------------------------------------------
  244. // Fill in the default statistics
  245. int FillDefaultStatistics( void );
  246. //------------------------------------------------------------------
  247. // Called by LoadAsset()
  248. // reset the class instance to the default values
  249. int Reset( void );
  250. //------------------------------------------------------------------
  251. // Replace the texture that is current selected with
  252. // a new texture
  253. int ReplaceCurrentTexture( const char* szPath );
  254. //------------------------------------------------------------------
  255. // Display the context menu (if there) for the specified tree item
  256. // hItem Valid tree view item handle
  257. int ShowTreeViewContextMenu( HTREEITEM hItem );
  258. //------------------------------------------------------------------
  259. // Event handling for pop-up menus displayed by th tree view
  260. int HandleTreeViewPopup( WPARAM wParam, LPARAM lParam );
  261. //------------------------------------------------------------------
  262. // Enable animation-related parts of the UI
  263. int EnableAnimTools( BOOL hm );
  264. //------------------------------------------------------------------
  265. // setter for m_iViewMode
  266. inline void SetViewMode( unsigned int p_iNew )
  267. {
  268. this->m_iViewMode = p_iNew;
  269. }
  270. //------------------------------------------------------------------
  271. // getter for m_iViewMode
  272. inline unsigned int GetViewMode()
  273. {
  274. return m_iViewMode;
  275. }
  276. //------------------------------------------------------------------
  277. // change the texture view's zoom factor
  278. inline void SetTextureViewZoom( float f )
  279. {
  280. // FIX: Removed log(), seems to make more problems than it fixes
  281. this->m_fTextureZoom += f * 15;
  282. if( this->m_fTextureZoom < 0.05f )this->m_fTextureZoom = 0.05f;
  283. }
  284. //------------------------------------------------------------------
  285. // change the texture view's offset on the x axis
  286. inline void SetTextureViewOffsetX( float f )
  287. {
  288. this->m_vTextureOffset.x += f;
  289. }
  290. //------------------------------------------------------------------
  291. // change the texture view's offset on the y axis
  292. inline void SetTextureViewOffsetY( float f )
  293. {
  294. this->m_vTextureOffset.y += f;
  295. }
  296. //------------------------------------------------------------------
  297. // add a new texture to the list
  298. inline void AddTexture( const TextureInfo& info )
  299. {
  300. this->m_asTextures.push_back( info );
  301. }
  302. //------------------------------------------------------------------
  303. // add a new node to the list
  304. inline void AddNode( const NodeInfo& info )
  305. {
  306. this->m_asNodes.push_back( info );
  307. }
  308. //------------------------------------------------------------------
  309. // add a new mesh to the list
  310. inline void AddMesh( const MeshInfo& info )
  311. {
  312. this->m_asMeshes.push_back( info );
  313. }
  314. //------------------------------------------------------------------
  315. // add a new material to the list
  316. inline void AddMaterial( const MaterialInfo& info )
  317. {
  318. this->m_asMaterials.push_back( info );
  319. }
  320. //------------------------------------------------------------------
  321. // set the primary color of the checker pattern background
  322. inline void SetFirstCheckerColor( D3DXVECTOR4 c )
  323. {
  324. this->m_avCheckerColors[ 0 ] = c;
  325. }
  326. //------------------------------------------------------------------
  327. // set the secondary color of the checker pattern background
  328. inline void SetSecondCheckerColor( D3DXVECTOR4 c )
  329. {
  330. this->m_avCheckerColors[ 1 ] = c;
  331. }
  332. //------------------------------------------------------------------
  333. // get the primary color of the checker pattern background
  334. inline const D3DXVECTOR4* GetFirstCheckerColor() const
  335. {
  336. return &this->m_avCheckerColors[ 0 ];
  337. }
  338. //------------------------------------------------------------------
  339. // get the secondary color of the checker pattern background
  340. inline const D3DXVECTOR4* GetSecondCheckerColor() const
  341. {
  342. return &this->m_avCheckerColors[ 1 ];
  343. }
  344. private:
  345. //------------------------------------------------------------------
  346. // Render a screen-filling square using the checker pattern shader
  347. int RenderPatternBG();
  348. //------------------------------------------------------------------
  349. // Render a given node in the scenegraph
  350. // piNode Node to be rendered
  351. // piMatrix Current transformation matrix
  352. // bAlpha Render alpha or opaque objects only?
  353. int RenderNode( aiNode* piNode, const aiMatrix4x4& piMatrix,
  354. bool bAlpha = false );
  355. //------------------------------------------------------------------
  356. // Setup the camera for the stereo view rendering mode
  357. int SetupStereoView();
  358. //------------------------------------------------------------------
  359. // Render the second view (for the right eye) in stereo mod
  360. // m - World matrix
  361. int RenderStereoView( const aiMatrix4x4& m );
  362. //------------------------------------------------------------------
  363. // Handle user input
  364. int HandleInput();
  365. //------------------------------------------------------------------
  366. // Handle user input for the texture viewer
  367. int HandleInputTextureView();
  368. //------------------------------------------------------------------
  369. // Handle user input if no asset is loaded
  370. int HandleInputEmptyScene();
  371. //------------------------------------------------------------------
  372. // Draw the HUD (call only if FPS mode isn't active)
  373. int DrawHUD();
  374. //------------------------------------------------------------------
  375. // Used by OnSetup().
  376. // Do everything necessary to switch to texture view mode
  377. int OnSetupTextureView( TextureInfo* pcNew );
  378. //------------------------------------------------------------------
  379. // Used by OnSetup().
  380. // Do everything necessary to switch to material view mode
  381. int OnSetupMaterialView( MaterialInfo* pcNew );
  382. //------------------------------------------------------------------
  383. // Used by OnSetup().
  384. // Do everything necessary to switch to node view mode
  385. int OnSetupNodeView( NodeInfo* pcNew );
  386. //------------------------------------------------------------------
  387. // Used by OnSetup().
  388. // Do everything necessary to switch back to normal view mode
  389. int OnSetupNormalView();
  390. //------------------------------------------------------------------
  391. // Used by HandleTreeViewPopup().
  392. int HandleTreeViewPopup2( WPARAM wParam, LPARAM lParam );
  393. //------------------------------------------------------------------
  394. // Render skeleton
  395. int RenderSkeleton( aiNode* piNode, const aiMatrix4x4& piMatrix,
  396. const aiMatrix4x4& parent );
  397. private:
  398. // view mode
  399. unsigned int m_iViewMode;
  400. // List of all textures in the display CB
  401. std::vector<TextureInfo> m_asTextures;
  402. // current texture or NULL if no texture is active
  403. TextureInfo* m_pcCurrentTexture;
  404. // List of all node in the display CB
  405. std::vector<NodeInfo> m_asNodes;
  406. // List of all node in the display CB
  407. std::vector<MeshInfo> m_asMeshes;
  408. // current Node or NULL if no Node is active
  409. NodeInfo* m_pcCurrentNode;
  410. // List of all materials in the display CB
  411. std::vector<MaterialInfo> m_asMaterials;
  412. // current material or NULL if no material is active
  413. MaterialInfo* m_pcCurrentMaterial;
  414. // indices into the image list of the "display" tree view control
  415. unsigned int m_aiImageList[ 5 ]; /* = {0,1,2,3,4};*/
  416. // Image list
  417. HIMAGELIST m_hImageList;
  418. // Root node of the tree, "Model"
  419. HTREEITEM m_hRoot;
  420. // Current zoom factor of the texture viewer
  421. float m_fTextureZoom;
  422. // Current offset (in pixels) of the texture viewer
  423. aiVector2D m_vTextureOffset;
  424. // Colors used to draw the checker pattern (for the
  425. // texture viewer as background )
  426. D3DXVECTOR4 m_avCheckerColors[ 2 ];
  427. // View projection matrix
  428. aiMatrix4x4 mViewProjection;
  429. aiVector3D vPos;
  430. };
  431. }
  432. #endif // AV_DISPLAY_H_INCLUDE