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.
 
 
 
 
 
 

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