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.
 
 
 
 
 
 

2641 lines
77 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. #include "stdafx.h"
  35. #include "assimp_view.h"
  36. #include <windowsx.h>
  37. namespace AssimpView {
  38. // Static array to keep custom color values
  39. COLORREF g_aclCustomColors[16] = {0};
  40. // Global registry key
  41. HKEY g_hRegistry = NULL;
  42. // list of previous files (always 5)
  43. std::vector<std::string> g_aPreviousFiles;
  44. // history menu item
  45. HMENU g_hHistoryMenu = NULL;
  46. float g_fACMR = 3.0f;
  47. #define AI_VIEW_NUM_RECENT_FILES 0x8
  48. #define AI_VIEW_RECENT_FILE_ID(_n_) (5678 + _n_)
  49. #define AI_VIEW_EXPORT_FMT_BASE 7912
  50. #define AI_VIEW_EXPORT_FMT_ID(_n_) (AI_VIEW_EXPORT_FMT_BASE + _n_)
  51. void UpdateHistory();
  52. void SaveHistory();
  53. //-------------------------------------------------------------------------------
  54. // Setup file associations for all formats supported by the library
  55. //
  56. // File associations are registered in HKCU\Software\Classes. They might
  57. // be overwritten by global file associations.
  58. //-------------------------------------------------------------------------------
  59. void MakeFileAssociations()
  60. {
  61. char szTemp2[MAX_PATH];
  62. char szTemp[MAX_PATH + 10];
  63. GetModuleFileName(NULL,szTemp2,MAX_PATH);
  64. sprintf(szTemp,"%s %%1",szTemp2);
  65. HKEY g_hRegistry;
  66. aiString list, tmp;
  67. aiGetExtensionList(&list);
  68. tmp = list;
  69. const char* sz = strtok(list.data,";");
  70. do
  71. {
  72. char buf[256];
  73. ai_assert(sz[0] == '*');
  74. sprintf(buf,"Software\\Classes\\%s",sz+1);
  75. RegCreateKeyEx(HKEY_CURRENT_USER,buf,0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
  76. RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
  77. RegCloseKey(g_hRegistry);
  78. }
  79. while ((sz = strtok(NULL,";")));
  80. RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
  81. RegCloseKey(g_hRegistry);
  82. RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS\\shell\\open\\command",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
  83. RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)szTemp,(DWORD)strlen(szTemp)+1);
  84. RegCloseKey(g_hRegistry);
  85. CLogDisplay::Instance().AddEntry("[OK] File assocations have been registered",
  86. D3DCOLOR_ARGB(0xFF,0,0xFF,0));
  87. CLogDisplay::Instance().AddEntry(tmp.data,D3DCOLOR_ARGB(0xFF,0,0xFF,0));
  88. }
  89. //-------------------------------------------------------------------------------
  90. // Handle command line parameters
  91. //
  92. // The function loads an asset specified on the command line as first argument
  93. // Other command line parameters are not handled
  94. //-------------------------------------------------------------------------------
  95. void HandleCommandLine(char* p_szCommand)
  96. {
  97. char* sz = p_szCommand;
  98. //bool bQuak = false;
  99. if (strlen(sz) < 2)return;
  100. if (*sz == '\"')
  101. {
  102. char* sz2 = strrchr(sz,'\"');
  103. if (sz2)*sz2 = 0;
  104. sz++; // skip the starting quote
  105. }
  106. strcpy( g_szFileName, sz );
  107. LoadAsset();
  108. // update the history
  109. UpdateHistory();
  110. // Save the list of previous files to the registry
  111. SaveHistory();
  112. }
  113. //-------------------------------------------------------------------------------
  114. // Load the light colors from the registry
  115. //-------------------------------------------------------------------------------
  116. void LoadLightColors()
  117. {
  118. DWORD dwTemp = 4;
  119. RegQueryValueEx(g_hRegistry,"LightColor0",NULL,NULL,
  120. (BYTE*)&g_avLightColors[0],&dwTemp);
  121. RegQueryValueEx(g_hRegistry,"LightColor1",NULL,NULL,
  122. (BYTE*)&g_avLightColors[1],&dwTemp);
  123. RegQueryValueEx(g_hRegistry,"LightColor2",NULL,NULL,
  124. (BYTE*)&g_avLightColors[2],&dwTemp);
  125. return;
  126. }
  127. //-------------------------------------------------------------------------------
  128. // Save the light colors to the registry
  129. //-------------------------------------------------------------------------------
  130. void SaveLightColors()
  131. {
  132. RegSetValueExA(g_hRegistry,"LightColor0",0,REG_DWORD,(const BYTE*)&g_avLightColors[0],4);
  133. RegSetValueExA(g_hRegistry,"LightColor1",0,REG_DWORD,(const BYTE*)&g_avLightColors[1],4);
  134. RegSetValueExA(g_hRegistry,"LightColor2",0,REG_DWORD,(const BYTE*)&g_avLightColors[2],4);
  135. }
  136. //-------------------------------------------------------------------------------
  137. // Save the checker pattern colors to the registry
  138. //-------------------------------------------------------------------------------
  139. void SaveCheckerPatternColors()
  140. {
  141. // we have it as float4. save it as binary value --.
  142. RegSetValueExA(g_hRegistry,"CheckerPattern0",0,REG_BINARY,
  143. (const BYTE*)CDisplay::Instance().GetFirstCheckerColor(),
  144. sizeof(D3DXVECTOR3));
  145. RegSetValueExA(g_hRegistry,"CheckerPattern1",0,REG_BINARY,
  146. (const BYTE*)CDisplay::Instance().GetSecondCheckerColor(),
  147. sizeof(D3DXVECTOR3));
  148. }
  149. //-------------------------------------------------------------------------------
  150. // Load the checker pattern colors from the registry
  151. //-------------------------------------------------------------------------------
  152. void LoadCheckerPatternColors()
  153. {
  154. DWORD dwTemp = sizeof(D3DXVECTOR3);
  155. RegQueryValueEx(g_hRegistry,"CheckerPattern0",NULL,NULL,
  156. (BYTE*) /* jep, this is evil */ CDisplay::Instance().GetFirstCheckerColor(),&dwTemp);
  157. RegQueryValueEx(g_hRegistry,"CheckerPattern1",NULL,NULL,
  158. (BYTE*) /* jep, this is evil */ CDisplay::Instance().GetSecondCheckerColor(),&dwTemp);
  159. }
  160. //-------------------------------------------------------------------------------
  161. // Changed pp setup
  162. //-------------------------------------------------------------------------------
  163. void UpdatePPSettings()
  164. {
  165. DWORD dwValue = ppsteps;
  166. RegSetValueExA(g_hRegistry,"PostProcessing",0,REG_DWORD,(const BYTE*)&dwValue,4);
  167. UpdateWindow(g_hDlg);
  168. }
  169. //-------------------------------------------------------------------------------
  170. // Toggle the "Display Normals" state
  171. //-------------------------------------------------------------------------------
  172. void ToggleNormals()
  173. {
  174. g_sOptions.bRenderNormals = !g_sOptions.bRenderNormals;
  175. // store this in the registry, too
  176. DWORD dwValue = 0;
  177. if (g_sOptions.bRenderNormals)dwValue = 1;
  178. RegSetValueExA(g_hRegistry,"RenderNormals",0,REG_DWORD,(const BYTE*)&dwValue,4);
  179. }
  180. //-------------------------------------------------------------------------------
  181. // Toggle the "AutoRotate" state
  182. //-------------------------------------------------------------------------------
  183. void ToggleAutoRotate()
  184. {
  185. g_sOptions.bRotate = !g_sOptions.bRotate;
  186. // store this in the registry, too
  187. DWORD dwValue = 0;
  188. if (g_sOptions.bRotate)dwValue = 1;
  189. RegSetValueExA(g_hRegistry,"AutoRotate",0,REG_DWORD,(const BYTE*)&dwValue,4);
  190. UpdateWindow(g_hDlg);
  191. }
  192. //-------------------------------------------------------------------------------
  193. // Toggle the "FPS" state
  194. //-------------------------------------------------------------------------------
  195. void ToggleFPSView()
  196. {
  197. g_bFPSView = !g_bFPSView;
  198. SetupFPSView();
  199. // store this in the registry, too
  200. DWORD dwValue = 0;
  201. if (g_bFPSView)dwValue = 1;
  202. RegSetValueExA(g_hRegistry,"FPSView",0,REG_DWORD,(const BYTE*)&dwValue,4);
  203. }
  204. //-------------------------------------------------------------------------------
  205. // Toggle the "2 Light sources" state
  206. //-------------------------------------------------------------------------------
  207. void ToggleMultipleLights()
  208. {
  209. g_sOptions.b3Lights = !g_sOptions.b3Lights;
  210. // store this in the registry, too
  211. DWORD dwValue = 0;
  212. if (g_sOptions.b3Lights)dwValue = 1;
  213. RegSetValueExA(g_hRegistry,"MultipleLights",0,REG_DWORD,(const BYTE*)&dwValue,4);
  214. }
  215. //-------------------------------------------------------------------------------
  216. // Toggle the "LightRotate" state
  217. //-------------------------------------------------------------------------------
  218. void ToggleLightRotate()
  219. {
  220. g_sOptions.bLightRotate = !g_sOptions.bLightRotate;
  221. // store this in the registry, too
  222. DWORD dwValue = 0;
  223. if (g_sOptions.bLightRotate)dwValue = 1;
  224. RegSetValueExA(g_hRegistry,"LightRotate",0,REG_DWORD,(const BYTE*)&dwValue,4);
  225. }
  226. //-------------------------------------------------------------------------------
  227. // Toggle the "NoTransparency" state
  228. //-------------------------------------------------------------------------------
  229. void ToggleTransparency()
  230. {
  231. g_sOptions.bNoAlphaBlending = !g_sOptions.bNoAlphaBlending;
  232. // store this in the registry, too
  233. DWORD dwValue = 0;
  234. if (g_sOptions.bNoAlphaBlending)dwValue = 1;
  235. RegSetValueExA(g_hRegistry,"NoTransparency",0,REG_DWORD,(const BYTE*)&dwValue,4);
  236. }
  237. //-------------------------------------------------------------------------------
  238. // Toggle the "LowQuality" state
  239. //-------------------------------------------------------------------------------
  240. void ToggleLowQuality()
  241. {
  242. g_sOptions.bLowQuality = !g_sOptions.bLowQuality;
  243. // store this in the registry, too
  244. DWORD dwValue = 0;
  245. if (g_sOptions.bLowQuality)dwValue = 1;
  246. RegSetValueExA(g_hRegistry,"LowQuality",0,REG_DWORD,(const BYTE*)&dwValue,4);
  247. }
  248. //-------------------------------------------------------------------------------
  249. // Toggle the "Specular" state
  250. //-------------------------------------------------------------------------------
  251. void ToggleSpecular()
  252. {
  253. g_sOptions.bNoSpecular = !g_sOptions.bNoSpecular;
  254. // store this in the registry, too
  255. DWORD dwValue = 0;
  256. if (g_sOptions.bNoSpecular)dwValue = 1;
  257. RegSetValueExA(g_hRegistry,"NoSpecular",0,REG_DWORD,(const BYTE*)&dwValue,4);
  258. // update all specular materials
  259. CMaterialManager::Instance().UpdateSpecularMaterials();
  260. }
  261. //-------------------------------------------------------------------------------
  262. // Toggle the "RenderMats" state
  263. //-------------------------------------------------------------------------------
  264. void ToggleMats()
  265. {
  266. g_sOptions.bRenderMats = !g_sOptions.bRenderMats;
  267. // store this in the registry, too
  268. DWORD dwValue = 0;
  269. if (g_sOptions.bRenderMats)dwValue = 1;
  270. RegSetValueExA(g_hRegistry,"RenderMats",0,REG_DWORD,(const BYTE*)&dwValue,4);
  271. // update all specular materials
  272. CMaterialManager::Instance().UpdateSpecularMaterials();
  273. }
  274. //-------------------------------------------------------------------------------
  275. // Toggle the "Culling" state
  276. //-------------------------------------------------------------------------------
  277. void ToggleCulling()
  278. {
  279. g_sOptions.bCulling = !g_sOptions.bCulling;
  280. // store this in the registry, too
  281. DWORD dwValue = 0;
  282. if (g_sOptions.bCulling)dwValue = 1;
  283. RegSetValueExA(g_hRegistry,"Culling",0,REG_DWORD,(const BYTE*)&dwValue,4);
  284. }
  285. //-------------------------------------------------------------------------------
  286. // Toggle the "Skeleton" state
  287. //-------------------------------------------------------------------------------
  288. void ToggleSkeleton()
  289. {
  290. g_sOptions.bSkeleton = !g_sOptions.bSkeleton;
  291. // store this in the registry, too
  292. DWORD dwValue = 0;
  293. if (g_sOptions.bCulling)dwValue = 1;
  294. RegSetValueExA(g_hRegistry,"Skeleton",0,REG_DWORD,(const BYTE*)&dwValue,4);
  295. }
  296. //-------------------------------------------------------------------------------
  297. // Toggle the "WireFrame" state
  298. //-------------------------------------------------------------------------------
  299. void ToggleWireFrame()
  300. {
  301. if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME)
  302. g_sOptions.eDrawMode = RenderOptions::NORMAL;
  303. else g_sOptions.eDrawMode = RenderOptions::WIREFRAME;
  304. // store this in the registry, too
  305. DWORD dwValue = 0;
  306. if (RenderOptions::WIREFRAME == g_sOptions.eDrawMode)dwValue = 1;
  307. RegSetValueExA(g_hRegistry,"Wireframe",0,REG_DWORD,(const BYTE*)&dwValue,4);
  308. }
  309. //-------------------------------------------------------------------------------
  310. // Toggle the "MultiSample" state
  311. //-------------------------------------------------------------------------------
  312. void ToggleMS()
  313. {
  314. g_sOptions.bMultiSample = !g_sOptions.bMultiSample;
  315. DeleteAssetData();
  316. ShutdownDevice();
  317. if (0 == CreateDevice())
  318. {
  319. CLogDisplay::Instance().AddEntry(
  320. "[ERROR] Failed to toggle MultiSampling mode");
  321. g_sOptions.bMultiSample = !g_sOptions.bMultiSample;
  322. CreateDevice();
  323. }
  324. CreateAssetData();
  325. if (g_sOptions.bMultiSample)
  326. {
  327. CLogDisplay::Instance().AddEntry(
  328. "[OK] Changed MultiSampling mode to the maximum value for this device");
  329. }
  330. else
  331. {
  332. CLogDisplay::Instance().AddEntry(
  333. "[OK] MultiSampling has been disabled");
  334. }
  335. // store this in the registry, too
  336. DWORD dwValue = 0;
  337. if (g_sOptions.bMultiSample)dwValue = 1;
  338. RegSetValueExA(g_hRegistry,"MultiSampling",0,REG_DWORD,(const BYTE*)&dwValue,4);
  339. }
  340. //-------------------------------------------------------------------------------
  341. // Expand or collapse the UI
  342. //-------------------------------------------------------------------------------
  343. void ToggleUIState()
  344. {
  345. // adjust the size
  346. RECT sRect;
  347. GetWindowRect(g_hDlg,&sRect);
  348. sRect.right -= sRect.left;
  349. sRect.bottom -= sRect.top;
  350. RECT sRect2;
  351. GetWindowRect(GetDlgItem ( g_hDlg, IDC_BLUBB ),&sRect2);
  352. sRect2.left -= sRect.left;
  353. sRect2.top -= sRect.top;
  354. DWORD dwValue;
  355. if (BST_UNCHECKED == IsDlgButtonChecked(g_hDlg,IDC_BLUBB))
  356. {
  357. SetWindowPos(g_hDlg,NULL,0,0,sRect.right-214,sRect.bottom,
  358. SWP_NOMOVE | SWP_NOZORDER);
  359. dwValue = 0;
  360. SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>");
  361. RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4);
  362. }
  363. else
  364. {
  365. SetWindowPos(g_hDlg,NULL,0,0,sRect.right+214,sRect.bottom,
  366. SWP_NOMOVE | SWP_NOZORDER);
  367. dwValue = 1;
  368. SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),"<<");
  369. RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4);
  370. }
  371. UpdateWindow(g_hDlg);
  372. return;
  373. }
  374. //-------------------------------------------------------------------------------
  375. // Load the background texture for the cviewer
  376. //-------------------------------------------------------------------------------
  377. void LoadBGTexture()
  378. {
  379. char szFileName[MAX_PATH];
  380. DWORD dwTemp = MAX_PATH;
  381. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"TextureSrc",NULL,NULL,
  382. (BYTE*)szFileName,&dwTemp))
  383. {
  384. // Key was not found. Use C:
  385. strcpy(szFileName,"");
  386. }
  387. else
  388. {
  389. // need to remove the file name
  390. char* sz = strrchr(szFileName,'\\');
  391. if (!sz)sz = strrchr(szFileName,'/');
  392. if (!sz)*sz = 0;
  393. }
  394. OPENFILENAME sFilename1 = {
  395. sizeof(OPENFILENAME),
  396. g_hDlg,GetModuleHandle(NULL),
  397. "Textures\0*.png;*.dds;*.tga;*.bmp;*.tif;*.ppm;*.ppx;*.jpg;*.jpeg;*.exr\0*.*\0",
  398. NULL, 0, 1,
  399. szFileName, MAX_PATH, NULL, 0, NULL,
  400. "Open texture as background",
  401. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  402. 0, 1, ".jpg", 0, NULL, NULL
  403. };
  404. if(GetOpenFileName(&sFilename1) == 0) return;
  405. // Now store the file in the registry
  406. RegSetValueExA(g_hRegistry,"TextureSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  407. RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  408. RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  409. CBackgroundPainter::Instance().SetTextureBG(szFileName);
  410. return;
  411. }
  412. //-------------------------------------------------------------------------------
  413. // Reset the background color to a smart and nice grey
  414. //-------------------------------------------------------------------------------
  415. void ClearBG()
  416. {
  417. D3DCOLOR clrColor = D3DCOLOR_ARGB(0xFF,100,100,100);
  418. CBackgroundPainter::Instance().SetColor(clrColor);
  419. RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  420. RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  421. RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4);
  422. return;
  423. }
  424. //-------------------------------------------------------------------------------
  425. // Let the user choose a color in a windows standard color dialog
  426. //-------------------------------------------------------------------------------
  427. void DisplayColorDialog(D3DCOLOR* pclrResult)
  428. {
  429. CHOOSECOLOR clr;
  430. clr.lStructSize = sizeof(CHOOSECOLOR);
  431. clr.hwndOwner = g_hDlg;
  432. clr.Flags = CC_RGBINIT | CC_FULLOPEN;
  433. clr.rgbResult = RGB((*pclrResult >> 16) & 0xff,(*pclrResult >> 8) & 0xff,*pclrResult & 0xff);
  434. clr.lpCustColors = g_aclCustomColors;
  435. clr.lpfnHook = NULL;
  436. clr.lpTemplateName = NULL;
  437. clr.lCustData = 0;
  438. ChooseColor(&clr);
  439. *pclrResult = D3DCOLOR_ARGB(0xFF,
  440. GetRValue(clr.rgbResult),
  441. GetGValue(clr.rgbResult),
  442. GetBValue(clr.rgbResult));
  443. return;
  444. }
  445. //-------------------------------------------------------------------------------
  446. // Let the user choose a color in a windows standard color dialog
  447. //-------------------------------------------------------------------------------
  448. void DisplayColorDialog(D3DXVECTOR4* pclrResult)
  449. {
  450. CHOOSECOLOR clr;
  451. clr.lStructSize = sizeof(CHOOSECOLOR);
  452. clr.hwndOwner = g_hDlg;
  453. clr.Flags = CC_RGBINIT | CC_FULLOPEN;
  454. clr.rgbResult = RGB(clamp<unsigned char>(pclrResult->x * 255.0f),
  455. clamp<unsigned char>(pclrResult->y * 255.0f),
  456. clamp<unsigned char>(pclrResult->z * 255.0f));
  457. clr.lpCustColors = g_aclCustomColors;
  458. clr.lpfnHook = NULL;
  459. clr.lpTemplateName = NULL;
  460. clr.lCustData = 0;
  461. ChooseColor(&clr);
  462. pclrResult->x = GetRValue(clr.rgbResult) / 255.0f;
  463. pclrResult->y = GetGValue(clr.rgbResult) / 255.0f;
  464. pclrResult->z = GetBValue(clr.rgbResult) / 255.0f;
  465. return;
  466. }
  467. //-------------------------------------------------------------------------------
  468. // Let the user choose the baclground color for the viewer
  469. //-------------------------------------------------------------------------------
  470. void ChooseBGColor()
  471. {
  472. RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  473. RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  474. D3DCOLOR clrColor;
  475. DisplayColorDialog(&clrColor);
  476. CBackgroundPainter::Instance().SetColor(clrColor);
  477. RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4);
  478. return;
  479. }
  480. //-------------------------------------------------------------------------------
  481. // Display the OpenFile dialog and let the user choose a new slybox as bg
  482. //-------------------------------------------------------------------------------
  483. void LoadSkybox()
  484. {
  485. char szFileName[MAX_PATH];
  486. DWORD dwTemp = MAX_PATH;
  487. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"SkyBoxSrc",NULL,NULL,
  488. (BYTE*)szFileName,&dwTemp))
  489. {
  490. // Key was not found. Use C:
  491. strcpy(szFileName,"");
  492. }
  493. else
  494. {
  495. // need to remove the file name
  496. char* sz = strrchr(szFileName,'\\');
  497. if (!sz)sz = strrchr(szFileName,'/');
  498. if (!sz)*sz = 0;
  499. }
  500. OPENFILENAME sFilename1 = {
  501. sizeof(OPENFILENAME),
  502. g_hDlg,GetModuleHandle(NULL),
  503. "Skyboxes\0*.dds\0*.*\0", NULL, 0, 1,
  504. szFileName, MAX_PATH, NULL, 0, NULL,
  505. "Open skybox as background",
  506. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  507. 0, 1, ".dds", 0, NULL, NULL
  508. };
  509. if(GetOpenFileName(&sFilename1) == 0) return;
  510. // Now store the file in the registry
  511. RegSetValueExA(g_hRegistry,"SkyBoxSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  512. RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  513. RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
  514. CBackgroundPainter::Instance().SetCubeMapBG(szFileName);
  515. return;
  516. }
  517. //-------------------------------------------------------------------------------
  518. // Sace a screenshot to an user-defined file
  519. //-------------------------------------------------------------------------------
  520. void SaveScreenshot()
  521. {
  522. char szFileName[MAX_PATH];
  523. DWORD dwTemp = MAX_PATH;
  524. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"ScreenShot",NULL,NULL,
  525. (BYTE*)szFileName,&dwTemp))
  526. {
  527. // Key was not found. Use C:
  528. strcpy(szFileName,"");
  529. }
  530. else
  531. {
  532. // need to remove the file name
  533. char* sz = strrchr(szFileName,'\\');
  534. if (!sz)sz = strrchr(szFileName,'/');
  535. if (!sz)*sz = 0;
  536. }
  537. OPENFILENAME sFilename1 = {
  538. sizeof(OPENFILENAME),
  539. g_hDlg,GetModuleHandle(NULL),
  540. "PNG Images\0*.png", NULL, 0, 1,
  541. szFileName, MAX_PATH, NULL, 0, NULL,
  542. "Save Screenshot to file",
  543. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  544. 0, 1, ".png", 0, NULL, NULL
  545. };
  546. if(GetSaveFileName(&sFilename1) == 0) return;
  547. // Now store the file in the registry
  548. RegSetValueExA(g_hRegistry,"ScreenShot",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  549. IDirect3DSurface9* pi = NULL;
  550. g_piDevice->GetRenderTarget(0,&pi);
  551. if(!pi || FAILED(D3DXSaveSurfaceToFile(szFileName,D3DXIFF_PNG,pi,NULL,NULL)))
  552. {
  553. CLogDisplay::Instance().AddEntry("[ERROR] Unable to save screenshot",
  554. D3DCOLOR_ARGB(0xFF,0xFF,0,0));
  555. }
  556. else
  557. {
  558. CLogDisplay::Instance().AddEntry("[INFO] The screenshot has been saved",
  559. D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
  560. }
  561. if(pi)pi->Release();
  562. return;
  563. }
  564. //-------------------------------------------------------------------------------
  565. // Get the amount of memory required for textures
  566. //-------------------------------------------------------------------------------
  567. void AddTextureMem(IDirect3DTexture9* pcTex, unsigned int& out)
  568. {
  569. if (!pcTex)return;
  570. D3DSURFACE_DESC sDesc;
  571. pcTex->GetLevelDesc(0,&sDesc);
  572. out += (sDesc.Width * sDesc.Height) << 2;
  573. return;
  574. }
  575. //-------------------------------------------------------------------------------
  576. // Display memory statistics
  577. //-------------------------------------------------------------------------------
  578. void DisplayMemoryConsumption()
  579. {
  580. // first get the memory consumption for the aiScene
  581. if (! g_pcAsset ||!g_pcAsset->pcScene)
  582. {
  583. MessageBox(g_hDlg,"No asset is loaded. Can you guess how much memory I need to store nothing?",
  584. "Memory consumption",MB_OK);
  585. return;
  586. }
  587. unsigned int iScene = sizeof(aiScene);
  588. for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
  589. {
  590. iScene += sizeof(aiMesh);
  591. if (g_pcAsset->pcScene->mMeshes[i]->HasPositions())
  592. iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
  593. if (g_pcAsset->pcScene->mMeshes[i]->HasNormals())
  594. iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
  595. if (g_pcAsset->pcScene->mMeshes[i]->HasTangentsAndBitangents())
  596. iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices * 2;
  597. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a)
  598. {
  599. if (g_pcAsset->pcScene->mMeshes[i]->HasVertexColors(a))
  600. iScene += sizeof(aiColor4D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
  601. else break;
  602. }
  603. for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
  604. {
  605. if (g_pcAsset->pcScene->mMeshes[i]->HasTextureCoords(a))
  606. iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
  607. else break;
  608. }
  609. if (g_pcAsset->pcScene->mMeshes[i]->HasBones())
  610. {
  611. for (unsigned int p = 0; p < g_pcAsset->pcScene->mMeshes[i]->mNumBones;++p)
  612. {
  613. iScene += sizeof(aiBone);
  614. iScene += g_pcAsset->pcScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
  615. }
  616. }
  617. iScene += (sizeof(aiFace) + 3 * sizeof(unsigned int))*g_pcAsset->pcScene->mMeshes[i]->mNumFaces;
  618. }
  619. // add all embedded textures
  620. for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumTextures;++i)
  621. {
  622. const aiTexture* pc = g_pcAsset->pcScene->mTextures[i];
  623. if (0 != pc->mHeight)
  624. {
  625. iScene += 4 * pc->mHeight * pc->mWidth;
  626. }
  627. else iScene += pc->mWidth;
  628. }
  629. // add 30k for each material ... a string has 4k for example
  630. iScene += g_pcAsset->pcScene->mNumMaterials * 30 * 1024;
  631. // now get the memory consumption required by D3D, first all textures
  632. unsigned int iTexture = 0;
  633. for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
  634. {
  635. AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i];
  636. AddTextureMem(pc->piDiffuseTexture,iTexture);
  637. AddTextureMem(pc->piSpecularTexture,iTexture);
  638. AddTextureMem(pc->piAmbientTexture,iTexture);
  639. AddTextureMem(pc->piEmissiveTexture,iTexture);
  640. AddTextureMem(pc->piOpacityTexture,iTexture);
  641. AddTextureMem(pc->piNormalTexture,iTexture);
  642. AddTextureMem(pc->piShininessTexture,iTexture);
  643. }
  644. unsigned int iVRAM = iTexture;
  645. // now get the memory consumption of all vertex/index buffers
  646. unsigned int iVB = 0;
  647. unsigned int iIB = 0;
  648. for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
  649. {
  650. AssetHelper:: MeshHelper* pc = g_pcAsset->apcMeshes[i];
  651. union{
  652. D3DVERTEXBUFFER_DESC sDesc;
  653. D3DINDEXBUFFER_DESC sDesc2;
  654. };
  655. if (pc->piVB)
  656. {
  657. pc->piVB->GetDesc(&sDesc);
  658. iVB += sDesc.Size;
  659. }
  660. if (pc->piVBNormals)
  661. {
  662. pc->piVBNormals->GetDesc(&sDesc);
  663. iVB += sDesc.Size;
  664. }
  665. if (pc->piIB)
  666. {
  667. pc->piIB->GetDesc(&sDesc2);
  668. iIB += sDesc2.Size;
  669. }
  670. }
  671. iVRAM += iVB + iIB;
  672. // add the memory for the back buffer and depth stencil buffer
  673. RECT sRect;
  674. GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
  675. sRect.bottom -= sRect.top;
  676. sRect.right -= sRect.left;
  677. iVRAM += sRect.bottom * sRect.right * 8;
  678. char szOut[2048];
  679. sprintf(szOut,
  680. "(1 KiB = 1024 bytes)\n\n"
  681. "ASSIMP Import Data: \t%i KiB\n"
  682. "Texture data:\t\t%i KiB\n"
  683. "Vertex buffers:\t\t%i KiB\n"
  684. "Index buffers:\t\t%i KiB\n"
  685. "Video Memory:\t\t%i KiB\n\n"
  686. "Total: \t\t\t%i KiB",
  687. iScene / 1024,iTexture / 1024,iVB / 1024,iIB / 1024,iVRAM / 1024,
  688. (iScene + iTexture + iVB + iIB + iVRAM) / 1024);
  689. MessageBox(g_hDlg,szOut,"Memory consumption",MB_OK);
  690. return;
  691. }
  692. //-------------------------------------------------------------------------------
  693. // Save the list of recent files to the registry
  694. //-------------------------------------------------------------------------------
  695. void SaveHistory()
  696. {
  697. for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
  698. {
  699. char szName[66];
  700. sprintf(szName,"Recent%i",i+1);
  701. RegSetValueEx(g_hRegistry,szName,0,REG_SZ,
  702. (const BYTE*)g_aPreviousFiles[i].c_str(),(DWORD)g_aPreviousFiles[i].length());
  703. }
  704. return;
  705. }
  706. //-------------------------------------------------------------------------------
  707. // Recover the file history
  708. //-------------------------------------------------------------------------------
  709. void LoadHistory()
  710. {
  711. g_aPreviousFiles.resize(AI_VIEW_NUM_RECENT_FILES);
  712. char szFileName[MAX_PATH];
  713. for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
  714. {
  715. char szName[66];
  716. sprintf(szName,"Recent%i",i+1);
  717. DWORD dwTemp = MAX_PATH;
  718. szFileName[0] ='\0';
  719. if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,szName,NULL,NULL,
  720. (BYTE*)szFileName,&dwTemp))
  721. {
  722. g_aPreviousFiles[i] = std::string(szFileName);
  723. }
  724. }
  725. // add sub items for all recent files
  726. g_hHistoryMenu = CreateMenu();
  727. for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
  728. {
  729. const char* szText = g_aPreviousFiles[i].c_str();
  730. UINT iFlags = 0;
  731. if ('\0' == *szText)
  732. {
  733. szText = "<empty>";
  734. iFlags = MF_GRAYED | MF_DISABLED;
  735. }
  736. AppendMenu(g_hHistoryMenu,MF_STRING | iFlags,AI_VIEW_RECENT_FILE_ID(i),szText);
  737. }
  738. ModifyMenu(GetMenu(g_hDlg),ID_VIEWER_RECENTFILES,MF_BYCOMMAND | MF_POPUP,
  739. (UINT_PTR)g_hHistoryMenu,"Recent files");
  740. return;
  741. }
  742. //-------------------------------------------------------------------------------
  743. // Clear the file history
  744. //-------------------------------------------------------------------------------
  745. void ClearHistory()
  746. {
  747. for(unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
  748. g_aPreviousFiles[i] = std::string("");
  749. for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
  750. {
  751. ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i),
  752. MF_STRING | MF_BYCOMMAND | MF_GRAYED | MF_DISABLED,AI_VIEW_RECENT_FILE_ID(i),"<empty>");
  753. }
  754. SaveHistory();
  755. }
  756. //-------------------------------------------------------------------------------
  757. // Update the file history
  758. //-------------------------------------------------------------------------------
  759. void UpdateHistory()
  760. {
  761. if(!g_hHistoryMenu)return;
  762. std::string sz = std::string(g_szFileName);
  763. if (g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] == sz)return;
  764. // add the new asset to the list of recent files
  765. for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES-1;++i)
  766. {
  767. g_aPreviousFiles[i] = g_aPreviousFiles[i+1];
  768. }
  769. g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] = sz;
  770. for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
  771. {
  772. const char* szText = g_aPreviousFiles[i].c_str();
  773. UINT iFlags = 0;
  774. if ('\0' == *szText)
  775. {
  776. szText = "<empty>";
  777. iFlags = MF_GRAYED | MF_DISABLED;
  778. }
  779. ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i),
  780. MF_STRING | MF_BYCOMMAND | iFlags,AI_VIEW_RECENT_FILE_ID(i),szText);
  781. }
  782. return;
  783. }
  784. //-------------------------------------------------------------------------------
  785. // Open a new asset
  786. //-------------------------------------------------------------------------------
  787. void OpenAsset()
  788. {
  789. char szFileName[MAX_PATH];
  790. DWORD dwTemp = MAX_PATH;
  791. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"CurrentApp",NULL,NULL,
  792. (BYTE*)szFileName,&dwTemp))
  793. {
  794. // Key was not found. Use C:
  795. strcpy(szFileName,"");
  796. }
  797. else
  798. {
  799. // need to remove the file name
  800. char* sz = strrchr(szFileName,'\\');
  801. if (!sz)sz = strrchr(szFileName,'/');
  802. if (!sz)*sz = 0;
  803. }
  804. // get a list of all file extensions supported by ASSIMP
  805. aiString sz;
  806. aiGetExtensionList(&sz);
  807. char szList[MAXLEN + 100];
  808. strcpy(szList,"ASSIMP assets");
  809. char* szCur = szList + 14;
  810. strcpy(szCur,sz.data);
  811. szCur += sz.length+1;
  812. strcpy(szCur,"All files");
  813. szCur += 10;
  814. strcpy(szCur,"*.*");
  815. szCur[4] = 0;
  816. OPENFILENAME sFilename1 = {
  817. sizeof(OPENFILENAME),
  818. g_hDlg,GetModuleHandle(NULL), szList, NULL, 0, 1,
  819. szFileName, MAX_PATH, NULL, 0, NULL,
  820. "Import Asset into ASSIMP",
  821. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  822. 0, 1, ".x", 0, NULL, NULL
  823. };
  824. if(GetOpenFileName(&sFilename1) == 0) return;
  825. // Now store the file in the registry
  826. RegSetValueExA(g_hRegistry,"CurrentApp",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  827. if (0 != strcmp(g_szFileName,szFileName))
  828. {
  829. strcpy(g_szFileName, szFileName);
  830. DeleteAssetData();
  831. DeleteAsset();
  832. LoadAsset();
  833. // update the history
  834. UpdateHistory();
  835. // Save the list of previous files to the registry
  836. SaveHistory();
  837. }
  838. return;
  839. }
  840. //-------------------------------------------------------------------------------
  841. void SetupPPUIState()
  842. {
  843. // that's ugly. anyone willing to rewrite me from scratch?
  844. HMENU hMenu = GetMenu(g_hDlg);
  845. CheckMenuItem(hMenu,ID_VIEWER_PP_JIV,ppsteps & aiProcess_JoinIdenticalVertices ? MF_CHECKED : MF_UNCHECKED);
  846. CheckMenuItem(hMenu,ID_VIEWER_PP_CTS,ppsteps & aiProcess_CalcTangentSpace ? MF_CHECKED : MF_UNCHECKED);
  847. CheckMenuItem(hMenu,ID_VIEWER_PP_FD,ppsteps & aiProcess_FindDegenerates ? MF_CHECKED : MF_UNCHECKED);
  848. CheckMenuItem(hMenu,ID_VIEWER_PP_FID,ppsteps & aiProcess_FindInvalidData ? MF_CHECKED : MF_UNCHECKED);
  849. CheckMenuItem(hMenu,ID_VIEWER_PP_FIM,ppsteps & aiProcess_FindInstances ? MF_CHECKED : MF_UNCHECKED);
  850. CheckMenuItem(hMenu,ID_VIEWER_PP_FIN,ppsteps & aiProcess_FixInfacingNormals ? MF_CHECKED : MF_UNCHECKED);
  851. CheckMenuItem(hMenu,ID_VIEWER_PP_GUV,ppsteps & aiProcess_GenUVCoords ? MF_CHECKED : MF_UNCHECKED);
  852. CheckMenuItem(hMenu,ID_VIEWER_PP_ICL,ppsteps & aiProcess_ImproveCacheLocality ? MF_CHECKED : MF_UNCHECKED);
  853. CheckMenuItem(hMenu,ID_VIEWER_PP_OG,ppsteps & aiProcess_OptimizeGraph ? MF_CHECKED : MF_UNCHECKED);
  854. CheckMenuItem(hMenu,ID_VIEWER_PP_OM,ppsteps & aiProcess_OptimizeMeshes ? MF_CHECKED : MF_UNCHECKED);
  855. CheckMenuItem(hMenu,ID_VIEWER_PP_PTV,ppsteps & aiProcess_PreTransformVertices ? MF_CHECKED : MF_UNCHECKED);
  856. CheckMenuItem(hMenu,ID_VIEWER_PP_RRM2,ppsteps & aiProcess_RemoveRedundantMaterials ? MF_CHECKED : MF_UNCHECKED);
  857. CheckMenuItem(hMenu,ID_VIEWER_PP_TUV,ppsteps & aiProcess_TransformUVCoords ? MF_CHECKED : MF_UNCHECKED);
  858. CheckMenuItem(hMenu,ID_VIEWER_PP_VDS,ppsteps & aiProcess_ValidateDataStructure ? MF_CHECKED : MF_UNCHECKED);
  859. CheckMenuItem(hMenu,ID_VIEWER_PP_DB,ppsteps & aiProcess_Debone ? MF_CHECKED : MF_UNCHECKED);
  860. }
  861. #ifndef ASSIMP_BUILD_NO_EXPORT
  862. //-------------------------------------------------------------------------------
  863. // Fill the 'export' top level menu with a list of all supported export formats
  864. //-------------------------------------------------------------------------------
  865. void PopulateExportMenu()
  866. {
  867. // add sub items for all recent files
  868. Exporter exp;
  869. HMENU hm = ::CreateMenu();
  870. for(size_t i = 0; i < exp.GetExportFormatCount(); ++i)
  871. {
  872. const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i);
  873. char tmp[256];
  874. sprintf(tmp,"%s (%s)",e->description,e->id);
  875. AppendMenu(hm,MF_STRING,AI_VIEW_EXPORT_FMT_ID(i),tmp);
  876. }
  877. ModifyMenu(GetMenu(g_hDlg),ID_EXPORT,MF_BYCOMMAND | MF_POPUP,
  878. (UINT_PTR)hm,"Export");
  879. }
  880. //-------------------------------------------------------------------------------
  881. //-------------------------------------------------------------------------------
  882. void DoExport(size_t formatId)
  883. {
  884. if (!g_szFileName) {
  885. return;
  886. }
  887. Exporter exp;
  888. const aiExportFormatDesc* const e = exp.GetExportFormatDescription(formatId);
  889. ai_assert(e);
  890. char szFileName[MAX_PATH*2];
  891. DWORD dwTemp;
  892. if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"ModelExportDest",NULL,NULL,(BYTE*)szFileName,&dwTemp)) {
  893. ai_assert(dwTemp == MAX_PATH + 1);
  894. ai_assert(strlen(szFileName) <= MAX_PATH);
  895. // invent a nice default file name
  896. char* sz = std::max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
  897. if (sz) {
  898. strncpy(sz,std::max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')),MAX_PATH);
  899. }
  900. }
  901. else {
  902. // Key was not found. Use the folder where the asset comes from
  903. strncpy(szFileName,g_szFileName,MAX_PATH);
  904. }
  905. // fix file extension
  906. { char * const sz = strrchr(szFileName,'.');
  907. if(sz) {
  908. ai_assert((sz - &szFileName[0]) + strlen(e->fileExtension) + 1 <= MAX_PATH);
  909. strcpy(sz+1,e->fileExtension);
  910. }
  911. }
  912. // build the stupid info string for GetSaveFileName() - can't use sprintf() because the string must contain binary zeros.
  913. char desc[256] = {0};
  914. char* c = strcpy(desc,e->description) + strlen(e->description)+1;
  915. c += sprintf(c,"*.%s",e->fileExtension)+1;
  916. strcpy(c, "*.*\0"); c += 4;
  917. ai_assert(c - &desc[0] <= 256);
  918. const std::string ext = "."+std::string(e->fileExtension);
  919. OPENFILENAME sFilename1 = {
  920. sizeof(OPENFILENAME),
  921. g_hDlg,GetModuleHandle(NULL),
  922. desc, NULL, 0, 1,
  923. szFileName, MAX_PATH, NULL, 0, NULL,
  924. "Export asset",
  925. OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
  926. 0, 1, ext.c_str(), 0, NULL, NULL
  927. };
  928. if(::GetSaveFileName(&sFilename1) == 0) {
  929. return;
  930. }
  931. // Now store the file in the registry unless the user decided to stay in the model directory
  932. const std::string sFinal = szFileName, sub = sFinal.substr(0,sFinal.find_last_of("\\/"));
  933. if (strncmp(sub.c_str(),g_szFileName,sub.length())) {
  934. RegSetValueExA(g_hRegistry,"ModelExportDest",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
  935. }
  936. // export the file
  937. const aiReturn res = exp.Export(g_pcAsset->pcScene,e->id,sFinal.c_str(),
  938. ppsteps | /* configurable pp steps */
  939. aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing
  940. aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes
  941. aiProcess_Triangulate | // triangulate polygons with more than 3 edges
  942. aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
  943. aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives
  944. 0
  945. );
  946. if (res == aiReturn_SUCCESS) {
  947. CLogDisplay::Instance().AddEntry("[INFO] Exported file " + sFinal,D3DCOLOR_ARGB(0xFF,0x00,0xFF,0x00));
  948. return;
  949. }
  950. CLogDisplay::Instance().AddEntry("[INFO] Failure exporting file " +
  951. sFinal,D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00));
  952. }
  953. #endif
  954. //-------------------------------------------------------------------------------
  955. // Initialize the user interface
  956. //-------------------------------------------------------------------------------
  957. void InitUI()
  958. {
  959. SetDlgItemText(g_hDlg,IDC_EVERT,"0");
  960. SetDlgItemText(g_hDlg,IDC_EFACE,"0");
  961. SetDlgItemText(g_hDlg,IDC_EMAT,"0");
  962. SetDlgItemText(g_hDlg,IDC_ESHADER,"0");
  963. SetDlgItemText(g_hDlg,IDC_ENODEWND,"0");
  964. SetDlgItemText(g_hDlg,IDC_ETEX,"0");
  965. SetDlgItemText(g_hDlg,IDC_EMESH,"0");
  966. #ifndef ASSIMP_BUILD_NO_EXPORT
  967. PopulateExportMenu();
  968. #endif
  969. // setup the default window title
  970. SetWindowText(g_hDlg,AI_VIEW_CAPTION_BASE);
  971. // read some UI properties from the registry and apply them
  972. DWORD dwValue;
  973. DWORD dwTemp = sizeof( DWORD );
  974. // store the key in a global variable for later use
  975. RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\ASSIMP\\Viewer",
  976. 0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
  977. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LastUIState",NULL,NULL,
  978. (BYTE*)&dwValue,&dwTemp))
  979. {
  980. dwValue = 1;
  981. }
  982. if (0 == dwValue)
  983. {
  984. // collapse the viewer
  985. // adjust the size
  986. RECT sRect;
  987. GetWindowRect(g_hDlg,&sRect);
  988. sRect.right -= sRect.left;
  989. sRect.bottom -= sRect.top;
  990. RECT sRect2;
  991. GetWindowRect(GetDlgItem ( g_hDlg, IDC_BLUBB ),&sRect2);
  992. sRect2.left -= sRect.left;
  993. sRect2.top -= sRect.top;
  994. SetWindowPos(g_hDlg,NULL,0,0,sRect.right-214,sRect.bottom,
  995. SWP_NOMOVE | SWP_NOZORDER);
  996. SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>");
  997. }
  998. else
  999. {
  1000. CheckDlgButton(g_hDlg,IDC_BLUBB,BST_CHECKED);
  1001. }
  1002. // AutoRotate
  1003. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"AutoRotate",NULL,NULL,
  1004. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1005. if (0 == dwValue)
  1006. {
  1007. g_sOptions.bRotate = false;
  1008. CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_UNCHECKED);
  1009. }
  1010. else
  1011. {
  1012. g_sOptions.bRotate = true;
  1013. CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_CHECKED);
  1014. }
  1015. // MultipleLights
  1016. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"MultipleLights",NULL,NULL,
  1017. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1018. if (0 == dwValue)
  1019. {
  1020. g_sOptions.b3Lights = false;
  1021. CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_UNCHECKED);
  1022. }
  1023. else
  1024. {
  1025. g_sOptions.b3Lights = true;
  1026. CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_CHECKED);
  1027. }
  1028. // Light rotate
  1029. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LightRotate",NULL,NULL,
  1030. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1031. if (0 == dwValue)
  1032. {
  1033. g_sOptions.bLightRotate = false;
  1034. CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_UNCHECKED);
  1035. }
  1036. else
  1037. {
  1038. g_sOptions.bLightRotate = true;
  1039. CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_CHECKED);
  1040. }
  1041. // NoSpecular
  1042. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoSpecular",NULL,NULL,
  1043. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1044. if (0 == dwValue)
  1045. {
  1046. g_sOptions.bNoSpecular = false;
  1047. CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_UNCHECKED);
  1048. }
  1049. else
  1050. {
  1051. g_sOptions.bNoSpecular = true;
  1052. CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_CHECKED);
  1053. }
  1054. // LowQuality
  1055. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LowQuality",NULL,NULL,
  1056. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1057. if (0 == dwValue)
  1058. {
  1059. g_sOptions.bLowQuality = false;
  1060. CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_UNCHECKED);
  1061. }
  1062. else
  1063. {
  1064. g_sOptions.bLowQuality = true;
  1065. CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_CHECKED);
  1066. }
  1067. // LowQuality
  1068. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoTransparency",NULL,NULL,
  1069. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1070. if (0 == dwValue)
  1071. {
  1072. g_sOptions.bNoAlphaBlending = false;
  1073. CheckDlgButton(g_hDlg,IDC_NOAB,BST_UNCHECKED);
  1074. }
  1075. else
  1076. {
  1077. g_sOptions.bNoAlphaBlending = true;
  1078. CheckDlgButton(g_hDlg,IDC_NOAB,BST_CHECKED);
  1079. }
  1080. // DisplayNormals
  1081. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderNormals",NULL,NULL,
  1082. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1083. if (0 == dwValue)
  1084. {
  1085. g_sOptions.bRenderNormals = false;
  1086. CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_UNCHECKED);
  1087. }
  1088. else
  1089. {
  1090. g_sOptions.bRenderNormals = true;
  1091. CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_CHECKED);
  1092. }
  1093. // NoMaterials
  1094. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderMats",NULL,NULL,
  1095. (BYTE*)&dwValue,&dwTemp))dwValue = 1;
  1096. if (0 == dwValue)
  1097. {
  1098. g_sOptions.bRenderMats = false;
  1099. CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_CHECKED);
  1100. }
  1101. else
  1102. {
  1103. g_sOptions.bRenderMats = true;
  1104. CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_UNCHECKED);
  1105. }
  1106. // MultiSampling
  1107. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"MultiSampling",NULL,NULL,
  1108. (BYTE*)&dwValue,&dwTemp))dwValue = 1;
  1109. if (0 == dwValue)
  1110. {
  1111. g_sOptions.bMultiSample = false;
  1112. CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_UNCHECKED);
  1113. }
  1114. else
  1115. {
  1116. g_sOptions.bMultiSample = true;
  1117. CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_CHECKED);
  1118. }
  1119. // FPS Mode
  1120. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"FPSView",NULL,NULL,
  1121. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1122. if (0 == dwValue)
  1123. {
  1124. g_bFPSView = false;
  1125. CheckDlgButton(g_hDlg,IDC_ZOOM,BST_CHECKED);
  1126. }
  1127. else
  1128. {
  1129. g_bFPSView = true;
  1130. CheckDlgButton(g_hDlg,IDC_ZOOM,BST_UNCHECKED);
  1131. }
  1132. // WireFrame
  1133. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"Wireframe",NULL,NULL,
  1134. (BYTE*)&dwValue,&dwTemp))dwValue = 0;
  1135. if (0 == dwValue)
  1136. {
  1137. g_sOptions.eDrawMode = RenderOptions::NORMAL;
  1138. CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,BST_UNCHECKED);
  1139. }
  1140. else
  1141. {
  1142. g_sOptions.eDrawMode = RenderOptions::WIREFRAME;
  1143. CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,BST_CHECKED);
  1144. }
  1145. if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"PostProcessing",NULL,NULL,(BYTE*)&dwValue,&dwTemp))
  1146. ppsteps = ppstepsdefault;
  1147. else ppsteps = dwValue;
  1148. SetupPPUIState();
  1149. LoadCheckerPatternColors();
  1150. SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMIN,TRUE,0);
  1151. SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMAX,TRUE,10000);
  1152. return;
  1153. }
  1154. //-------------------------------------------------------------------------------
  1155. // Message prcoedure for the smooth normals dialog
  1156. //-------------------------------------------------------------------------------
  1157. INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg,
  1158. WPARAM wParam,LPARAM lParam)
  1159. {
  1160. UNREFERENCED_PARAMETER(lParam);
  1161. switch (uMsg)
  1162. {
  1163. case WM_INITDIALOG:
  1164. char s[30];
  1165. ::sprintf(s,"%.2f",g_smoothAngle);
  1166. SetDlgItemText(hwndDlg,IDC_EDITSM,s);
  1167. return TRUE;
  1168. case WM_CLOSE:
  1169. EndDialog(hwndDlg,0);
  1170. return TRUE;
  1171. case WM_COMMAND:
  1172. if (IDOK == LOWORD(wParam)) {
  1173. char s[30];
  1174. GetDlgItemText(hwndDlg,IDC_EDITSM,s,30);
  1175. g_smoothAngle = (float)atof(s);
  1176. EndDialog(hwndDlg,0);
  1177. }
  1178. else if (IDCANCEL == LOWORD(wParam)) {
  1179. EndDialog(hwndDlg,1);
  1180. }
  1181. return TRUE;
  1182. }
  1183. return FALSE;
  1184. }
  1185. //-------------------------------------------------------------------------------
  1186. // Main message procedure of the application
  1187. //
  1188. // The function handles all incoming messages for the main window.
  1189. // However, if does not directly process input commands.
  1190. // NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
  1191. // properly the code for all hotkeys has been moved to the WndMain
  1192. //-------------------------------------------------------------------------------
  1193. INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
  1194. WPARAM wParam,LPARAM lParam)
  1195. {
  1196. UNREFERENCED_PARAMETER(lParam);
  1197. UNREFERENCED_PARAMETER(wParam);
  1198. int xPos,yPos;
  1199. int xPos2,yPos2;
  1200. int fHalfX;
  1201. int fHalfY;
  1202. TRACKMOUSEEVENT sEvent;
  1203. switch (uMsg)
  1204. {
  1205. case WM_INITDIALOG:
  1206. g_hDlg = hwndDlg;
  1207. // load the state of the usr interface
  1208. InitUI();
  1209. // load the file history
  1210. LoadHistory();
  1211. // load the current color of the lights
  1212. LoadLightColors();
  1213. return TRUE;
  1214. case WM_HSCROLL:
  1215. // XXX quick and dirty fix for #3029892
  1216. if (GetDlgItem(g_hDlg, IDC_SLIDERANIM) == (HWND)lParam && g_pcAsset && g_pcAsset->pcScene->mAnimations)
  1217. {
  1218. double num = (double)SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_GETPOS,0,0);
  1219. const aiAnimation* anim = g_pcAsset->pcScene->mAnimations[ g_pcAsset->mAnimator->CurrentAnimIndex() ];
  1220. g_dCurrent = (anim->mDuration/anim->mTicksPerSecond) * num/10000;
  1221. g_pcAsset->mAnimator->Calculate(g_dCurrent);
  1222. }
  1223. break;
  1224. case WM_MOUSEWHEEL:
  1225. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode())
  1226. {
  1227. CDisplay::Instance().SetTextureViewZoom ( GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f );
  1228. }
  1229. else
  1230. {
  1231. if (!g_bFPSView)
  1232. {
  1233. g_sCamera.vPos.z += GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f;
  1234. }
  1235. else
  1236. {
  1237. g_sCamera.vPos += (GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f) *
  1238. g_sCamera.vLookAt.Normalize();
  1239. }
  1240. }
  1241. return TRUE;
  1242. case WM_MOUSELEAVE:
  1243. g_bMousePressed = false;
  1244. g_bMousePressedR = false;
  1245. g_bMousePressedM = false;
  1246. g_bMousePressedBoth = false;
  1247. return TRUE;
  1248. case WM_LBUTTONDBLCLK:
  1249. CheckDlgButton(hwndDlg,IDC_AUTOROTATE,
  1250. IsDlgButtonChecked(hwndDlg,IDC_AUTOROTATE) == BST_CHECKED
  1251. ? BST_UNCHECKED : BST_CHECKED);
  1252. ToggleAutoRotate();
  1253. return TRUE;
  1254. case WM_CLOSE:
  1255. PostQuitMessage(0);
  1256. DestroyWindow(hwndDlg);
  1257. return TRUE;
  1258. case WM_NOTIFY:
  1259. if (IDC_TREE1 == wParam)
  1260. {
  1261. NMTREEVIEW* pnmtv = (LPNMTREEVIEW) lParam;
  1262. if (TVN_SELCHANGED == pnmtv->hdr.code)
  1263. CDisplay::Instance().OnSetup( pnmtv->itemNew.hItem );
  1264. else if (NM_RCLICK == pnmtv->hdr.code)
  1265. {
  1266. // determine in which item the click was ...
  1267. POINT sPoint;
  1268. GetCursorPos(&sPoint);
  1269. ScreenToClient(GetDlgItem(g_hDlg,IDC_TREE1),&sPoint);
  1270. TVHITTESTINFO sHit;
  1271. sHit.pt = sPoint;
  1272. TreeView_HitTest(GetDlgItem(g_hDlg,IDC_TREE1),&sHit);
  1273. CDisplay::Instance().ShowTreeViewContextMenu(sHit.hItem);
  1274. }
  1275. }
  1276. return TRUE;
  1277. case WM_DRAWITEM:
  1278. {
  1279. // draw the two light colors
  1280. DRAWITEMSTRUCT* pcStruct = (DRAWITEMSTRUCT*)lParam;
  1281. RECT sRect;
  1282. GetWindowRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),&sRect);
  1283. sRect.right -= sRect.left;
  1284. sRect.bottom -= sRect.top;
  1285. sRect.left = sRect.top = 0;
  1286. bool bDraw = false;
  1287. if(IDC_LCOLOR1 == pcStruct->CtlID)
  1288. {
  1289. unsigned char r,g,b;
  1290. const char* szText;
  1291. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1292. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1293. {
  1294. r = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->x * 255.0f);
  1295. g = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->y * 255.0f);
  1296. b = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->z * 255.0f);
  1297. szText = "Background #0";
  1298. }
  1299. else if (!g_pcAsset)
  1300. {
  1301. r = g = b = 150;szText = "";
  1302. }
  1303. else
  1304. {
  1305. r = (unsigned char)((g_avLightColors[0] >> 16) & 0xFF);
  1306. g = (unsigned char)((g_avLightColors[0] >> 8) & 0xFF);
  1307. b = (unsigned char)((g_avLightColors[0]) & 0xFF);
  1308. szText = "Light #0";
  1309. }
  1310. HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
  1311. FillRect(pcStruct->hDC,&sRect,hbr);
  1312. SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
  1313. SetBkMode(pcStruct->hDC,TRANSPARENT);
  1314. TextOut(pcStruct->hDC,4,1,szText,strlen(szText));
  1315. bDraw = true;
  1316. }
  1317. else if(IDC_LCOLOR2 == pcStruct->CtlID)
  1318. {
  1319. unsigned char r,g,b;
  1320. const char* szText;
  1321. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1322. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1323. {
  1324. r = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->x * 255.0f);
  1325. g = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->y * 255.0f);
  1326. b = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->z * 255.0f);
  1327. szText = "Background #1";
  1328. }
  1329. else if (!g_pcAsset)
  1330. {
  1331. r = g = b = 150;szText = "";
  1332. }
  1333. else
  1334. {
  1335. r = (unsigned char)((g_avLightColors[1] >> 16) & 0xFF);
  1336. g = (unsigned char)((g_avLightColors[1] >> 8) & 0xFF);
  1337. b = (unsigned char)((g_avLightColors[1]) & 0xFF);
  1338. szText = "Light #1";
  1339. }
  1340. HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
  1341. FillRect(pcStruct->hDC,&sRect,hbr);
  1342. SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
  1343. SetBkMode(pcStruct->hDC,TRANSPARENT);
  1344. TextOut(pcStruct->hDC,4,1,szText,strlen(szText));
  1345. bDraw = true;
  1346. }
  1347. else if(IDC_LCOLOR3 == pcStruct->CtlID)
  1348. {
  1349. unsigned char r,g,b;
  1350. const char* szText;
  1351. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1352. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1353. {
  1354. r = g = b = 0;
  1355. szText = "";
  1356. }
  1357. else if (!g_pcAsset)
  1358. {
  1359. r = g = b = 150;szText = "";
  1360. }
  1361. else
  1362. {
  1363. r = (unsigned char)((g_avLightColors[2] >> 16) & 0xFF);
  1364. g = (unsigned char)((g_avLightColors[2] >> 8) & 0xFF);
  1365. b = (unsigned char)((g_avLightColors[2]) & 0xFF);
  1366. szText = "Ambient";
  1367. }
  1368. HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
  1369. FillRect(pcStruct->hDC,&sRect,hbr);
  1370. SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
  1371. SetBkMode(pcStruct->hDC,TRANSPARENT);
  1372. TextOut(pcStruct->hDC,4,1,szText,strlen(szText));
  1373. bDraw = true;
  1374. }
  1375. // draw the black border around the rects
  1376. if (bDraw)
  1377. {
  1378. SetBkColor(pcStruct->hDC,RGB(0,0,0));
  1379. MoveToEx(pcStruct->hDC,0,0,NULL);
  1380. LineTo(pcStruct->hDC,sRect.right-1,0);
  1381. LineTo(pcStruct->hDC,sRect.right-1,sRect.bottom-1);
  1382. LineTo(pcStruct->hDC,0,sRect.bottom-1);
  1383. LineTo(pcStruct->hDC,0,0);
  1384. }
  1385. }
  1386. return TRUE;
  1387. case WM_DESTROY:
  1388. // close the open registry key
  1389. RegCloseKey(g_hRegistry);
  1390. return TRUE;
  1391. case WM_LBUTTONDOWN:
  1392. g_bMousePressed = true;
  1393. // register a mouse track handler to be sure we'll know
  1394. // when the mouse leaves the display view again
  1395. sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
  1396. sEvent.dwFlags = TME_LEAVE;
  1397. sEvent.hwndTrack = g_hDlg;
  1398. sEvent.dwHoverTime = HOVER_DEFAULT;
  1399. TrackMouseEvent(&sEvent);
  1400. if (g_bMousePressedR)
  1401. {
  1402. g_bMousePressed = false;
  1403. g_bMousePressedR = false;
  1404. g_bMousePressedBoth = true;
  1405. return TRUE;
  1406. }
  1407. // need to determine the position of the mouse and the
  1408. // distance from the center
  1409. //xPos = (int)(short)LOWORD(lParam);
  1410. //yPos = (int)(short)HIWORD(lParam);
  1411. POINT sPoint;
  1412. GetCursorPos(&sPoint);
  1413. ScreenToClient(GetDlgItem(g_hDlg,IDC_RT),&sPoint);
  1414. xPos = xPos2 = sPoint.x;
  1415. yPos = yPos2 = sPoint.y;
  1416. /* xPos -= 10;
  1417. yPos -= 10;
  1418. xPos2 = xPos-3;
  1419. yPos2 = yPos-5;*/
  1420. RECT sRect;
  1421. GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
  1422. sRect.right -= sRect.left;
  1423. sRect.bottom -= sRect.top;
  1424. // if the mouse klick was inside the viewer panel
  1425. // give the focus to it
  1426. if (xPos > 0 && xPos < sRect.right && yPos > 0 && yPos < sRect.bottom)
  1427. {
  1428. SetFocus(GetDlgItem(g_hDlg,IDC_RT));
  1429. }
  1430. // g_bInvert stores whether the mouse has started on the negative
  1431. // x or on the positive x axis of the imaginary coordinate system
  1432. // with origin p at the center of the HUD texture
  1433. xPos -= sRect.right/2;
  1434. yPos -= sRect.bottom/2;
  1435. if (xPos > 0)g_bInvert = true;
  1436. else g_bInvert = false;
  1437. D3DSURFACE_DESC sDesc;
  1438. g_pcTexture->GetLevelDesc(0,&sDesc);
  1439. fHalfX = (int)(((float)sRect.right-(float)sDesc.Width) / 2.0f);
  1440. fHalfY = (int)(((float)sRect.bottom-(float)sDesc.Height) / 2.0f);
  1441. // Determine the input operation to perform for this position
  1442. g_eClick = EClickPos_Outside;
  1443. if (xPos2 >= fHalfX && xPos2 < fHalfX + (int)sDesc.Width &&
  1444. yPos2 >= fHalfY && yPos2 < fHalfY + (int)sDesc.Height &&
  1445. NULL != g_szImageMask)
  1446. {
  1447. // inside the texture. Lookup the grayscale value from it
  1448. xPos2 -= fHalfX;
  1449. yPos2 -= fHalfY;
  1450. unsigned char chValue = g_szImageMask[xPos2 + yPos2 * sDesc.Width];
  1451. if (chValue > 0xFF-20)
  1452. {
  1453. g_eClick = EClickPos_Circle;
  1454. }
  1455. else if (chValue < 0xFF-20 && chValue > 185)
  1456. {
  1457. g_eClick = EClickPos_CircleHor;
  1458. }
  1459. else if (chValue > 0x10 && chValue < 185)
  1460. {
  1461. g_eClick = EClickPos_CircleVert;
  1462. }
  1463. }
  1464. return TRUE;
  1465. case WM_RBUTTONDOWN:
  1466. g_bMousePressedR = true;
  1467. sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
  1468. sEvent.dwFlags = TME_LEAVE;
  1469. sEvent.hwndTrack = g_hDlg;
  1470. sEvent.dwHoverTime = HOVER_DEFAULT;
  1471. TrackMouseEvent(&sEvent);
  1472. if (g_bMousePressed)
  1473. {
  1474. g_bMousePressedR = false;
  1475. g_bMousePressed = false;
  1476. g_bMousePressedBoth = true;
  1477. }
  1478. return TRUE;
  1479. case WM_MBUTTONDOWN:
  1480. g_bMousePressedM = true;
  1481. sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
  1482. sEvent.dwFlags = TME_LEAVE;
  1483. sEvent.hwndTrack = g_hDlg;
  1484. sEvent.dwHoverTime = HOVER_DEFAULT;
  1485. TrackMouseEvent(&sEvent);
  1486. return TRUE;
  1487. case WM_LBUTTONUP:
  1488. g_bMousePressed = false;
  1489. g_bMousePressedBoth = false;
  1490. return TRUE;
  1491. case WM_RBUTTONUP:
  1492. g_bMousePressedR = false;
  1493. g_bMousePressedBoth = false;
  1494. return TRUE;
  1495. case WM_MBUTTONUP:
  1496. g_bMousePressedM = false;
  1497. return TRUE;
  1498. case WM_DROPFILES:
  1499. {
  1500. HDROP hDrop = (HDROP)wParam;
  1501. char szFile[MAX_PATH];
  1502. DragQueryFile(hDrop,0,szFile,sizeof(szFile));
  1503. const char* sz = strrchr(szFile,'.');
  1504. if (!sz)
  1505. sz = szFile;
  1506. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode())
  1507. {
  1508. // replace the selected texture with the new one ...
  1509. CDisplay::Instance().ReplaceCurrentTexture(szFile);
  1510. }
  1511. else
  1512. {
  1513. // check whether it is a typical texture file format ...
  1514. ++sz;
  1515. if (0 == ASSIMP_stricmp(sz,"png") ||
  1516. 0 == ASSIMP_stricmp(sz,"bmp") ||
  1517. 0 == ASSIMP_stricmp(sz,"jpg") ||
  1518. 0 == ASSIMP_stricmp(sz,"tga") ||
  1519. 0 == ASSIMP_stricmp(sz,"tif") ||
  1520. 0 == ASSIMP_stricmp(sz,"hdr") ||
  1521. 0 == ASSIMP_stricmp(sz,"ppm") ||
  1522. 0 == ASSIMP_stricmp(sz,"pfm"))
  1523. {
  1524. CBackgroundPainter::Instance().SetTextureBG(szFile);
  1525. }
  1526. else if (0 == Assimp::ASSIMP_stricmp(sz,"dds"))
  1527. {
  1528. // DDS files could contain skyboxes, but they could also
  1529. // contain normal 2D textures. The easiest way to find this
  1530. // out is to open the file and check the header ...
  1531. FILE* pFile = fopen(szFile,"rb");
  1532. if (!pFile)
  1533. return TRUE;
  1534. // header of a dds file (begin)
  1535. /*
  1536. DWORD dwMagic
  1537. DWORD dwSize
  1538. DWORD dwFlags
  1539. DWORD dwHeight
  1540. DWORD dwWidth
  1541. DWORD dwPitchOrLinearSize
  1542. DWORD dwDepth
  1543. DWORD dwMipMapCount -> total with this: 32
  1544. DWORD dwReserved1[11] -> total with this: 76
  1545. DDPIXELFORMAT ddpfPixelFormat -> total with this: 108
  1546. DWORD dwCaps1; -> total with this: 112
  1547. DWORD dwCaps2; ---< here we are!
  1548. */
  1549. DWORD dwCaps = 0;
  1550. fseek(pFile,112,SEEK_SET);
  1551. fread(&dwCaps,4,1,pFile);
  1552. if (dwCaps & 0x00000400L /* DDSCAPS2_CUBEMAP_POSITIVEX */)
  1553. {
  1554. CLogDisplay::Instance().AddEntry(
  1555. "[INFO] Assuming this dds file is a skybox ...",
  1556. D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
  1557. CBackgroundPainter::Instance().SetCubeMapBG(szFile);
  1558. }
  1559. else CBackgroundPainter::Instance().SetTextureBG(szFile);
  1560. fclose(pFile);
  1561. }
  1562. else
  1563. {
  1564. strcpy(g_szFileName,szFile);
  1565. DeleteAsset();
  1566. LoadAsset();
  1567. UpdateHistory();
  1568. SaveHistory();
  1569. }
  1570. }
  1571. DragFinish(hDrop);
  1572. }
  1573. return TRUE;
  1574. case WM_COMMAND:
  1575. HMENU hMenu = GetMenu(g_hDlg);
  1576. if (ID_VIEWER_QUIT == LOWORD(wParam))
  1577. {
  1578. PostQuitMessage(0);
  1579. DestroyWindow(hwndDlg);
  1580. }
  1581. else if (IDC_COMBO1 == LOWORD(wParam))
  1582. {
  1583. if(HIWORD(wParam) == CBN_SELCHANGE) {
  1584. const size_t sel = static_cast<size_t>(ComboBox_GetCurSel(GetDlgItem(hwndDlg,IDC_COMBO1)));
  1585. if(g_pcAsset) {
  1586. g_pcAsset->mAnimator->SetAnimIndex(sel);
  1587. SendDlgItemMessage(hwndDlg,IDC_SLIDERANIM,TBM_SETPOS,TRUE,0);
  1588. }
  1589. }
  1590. }
  1591. else if (ID_VIEWER_RESETVIEW == LOWORD(wParam))
  1592. {
  1593. g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f);
  1594. g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f);
  1595. g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f);
  1596. g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f);
  1597. g_mWorldRotate = aiMatrix4x4();
  1598. g_mWorld = aiMatrix4x4();
  1599. // don't forget to reset the st
  1600. CBackgroundPainter::Instance().ResetSB();
  1601. }
  1602. else if (ID__HELP == LOWORD(wParam))
  1603. {
  1604. DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_AVHELP),
  1605. hwndDlg,&HelpDialogProc);
  1606. }
  1607. else if (ID__ABOUT == LOWORD(wParam))
  1608. {
  1609. DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_ABOUTBOX),
  1610. hwndDlg,&AboutMessageProc);
  1611. }
  1612. else if (ID_TOOLS_LOGWINDOW == LOWORD(wParam))
  1613. {
  1614. CLogWindow::Instance().Show();
  1615. }
  1616. else if (ID__WEBSITE == LOWORD(wParam))
  1617. {
  1618. ShellExecute(NULL,"open","http://assimp.sourceforge.net","","",SW_SHOW);
  1619. }
  1620. else if (ID__WEBSITESF == LOWORD(wParam))
  1621. {
  1622. ShellExecute(NULL,"open","https://sourceforge.net/projects/assimp","","",SW_SHOW);
  1623. }
  1624. else if (ID_REPORTBUG == LOWORD(wParam))
  1625. {
  1626. ShellExecute(NULL,"open","https://sourceforge.net/tracker/?func=add&group_id=226462&atid=1067632","","",SW_SHOW);
  1627. }
  1628. else if (ID_FR == LOWORD(wParam))
  1629. {
  1630. ShellExecute(NULL,"open","https://sourceforge.net/forum/forum.php?forum_id=817653","","",SW_SHOW);
  1631. }
  1632. else if (ID_TOOLS_CLEARLOG == LOWORD(wParam))
  1633. {
  1634. CLogWindow::Instance().Clear();
  1635. }
  1636. else if (ID_TOOLS_SAVELOGTOFILE == LOWORD(wParam))
  1637. {
  1638. CLogWindow::Instance().Save();
  1639. }
  1640. else if (ID_VIEWER_MEMORYCONSUMATION == LOWORD(wParam))
  1641. {
  1642. DisplayMemoryConsumption();
  1643. }
  1644. else if (ID_VIEWER_H == LOWORD(wParam))
  1645. {
  1646. MakeFileAssociations();
  1647. }
  1648. else if (ID_BACKGROUND_CLEAR == LOWORD(wParam))
  1649. {
  1650. ClearBG();
  1651. }
  1652. else if (ID_BACKGROUND_SETCOLOR == LOWORD(wParam))
  1653. {
  1654. ChooseBGColor();
  1655. }
  1656. else if (ID_BACKGROUND_LOADTEXTURE == LOWORD(wParam))
  1657. {
  1658. LoadBGTexture();
  1659. }
  1660. else if (ID_BACKGROUND_LOADSKYBOX == LOWORD(wParam))
  1661. {
  1662. LoadSkybox();
  1663. }
  1664. else if (ID_VIEWER_SAVESCREENSHOTTOFILE == LOWORD(wParam))
  1665. {
  1666. SaveScreenshot();
  1667. }
  1668. else if (ID_VIEWER_OPEN == LOWORD(wParam))
  1669. {
  1670. OpenAsset();
  1671. }
  1672. else if (ID_TOOLS_FLIPNORMALS == LOWORD(wParam))
  1673. {
  1674. if (g_pcAsset && g_pcAsset->pcScene)
  1675. {
  1676. g_pcAsset->FlipNormals();
  1677. }
  1678. }
  1679. // this is ugly. anyone willing to rewrite it from scratch using wxwidgets or similar?
  1680. else if (ID_VIEWER_PP_JIV == LOWORD(wParam)) {
  1681. ppsteps ^= aiProcess_JoinIdenticalVertices;
  1682. CheckMenuItem(hMenu,ID_VIEWER_PP_JIV,ppsteps & aiProcess_JoinIdenticalVertices ? MF_CHECKED : MF_UNCHECKED);
  1683. UpdatePPSettings();
  1684. }
  1685. else if (ID_VIEWER_PP_CTS == LOWORD(wParam)) {
  1686. ppsteps ^= aiProcess_CalcTangentSpace;
  1687. CheckMenuItem(hMenu,ID_VIEWER_PP_CTS,ppsteps & aiProcess_CalcTangentSpace ? MF_CHECKED : MF_UNCHECKED);
  1688. UpdatePPSettings();
  1689. }
  1690. else if (ID_VIEWER_PP_FD == LOWORD(wParam)) {
  1691. ppsteps ^= aiProcess_FindDegenerates;
  1692. CheckMenuItem(hMenu,ID_VIEWER_PP_FD,ppsteps & aiProcess_FindDegenerates ? MF_CHECKED : MF_UNCHECKED);
  1693. UpdatePPSettings();
  1694. }
  1695. else if (ID_VIEWER_PP_FID == LOWORD(wParam)) {
  1696. ppsteps ^= aiProcess_FindInvalidData;
  1697. CheckMenuItem(hMenu,ID_VIEWER_PP_FID,ppsteps & aiProcess_FindInvalidData ? MF_CHECKED : MF_UNCHECKED);
  1698. UpdatePPSettings();
  1699. }
  1700. else if (ID_VIEWER_PP_FIM == LOWORD(wParam)) {
  1701. ppsteps ^= aiProcess_FindInstances;
  1702. CheckMenuItem(hMenu,ID_VIEWER_PP_FIM,ppsteps & aiProcess_FindInstances ? MF_CHECKED : MF_UNCHECKED);
  1703. UpdatePPSettings();
  1704. }
  1705. else if (ID_VIEWER_PP_FIN == LOWORD(wParam)) {
  1706. ppsteps ^= aiProcess_FixInfacingNormals;
  1707. CheckMenuItem(hMenu,ID_VIEWER_PP_FIN,ppsteps & aiProcess_FixInfacingNormals ? MF_CHECKED : MF_UNCHECKED);
  1708. UpdatePPSettings();
  1709. }
  1710. else if (ID_VIEWER_PP_GUV == LOWORD(wParam)) {
  1711. ppsteps ^= aiProcess_GenUVCoords;
  1712. CheckMenuItem(hMenu,ID_VIEWER_PP_GUV,ppsteps & aiProcess_GenUVCoords ? MF_CHECKED : MF_UNCHECKED);
  1713. UpdatePPSettings();
  1714. }
  1715. else if (ID_VIEWER_PP_ICL == LOWORD(wParam)) {
  1716. ppsteps ^= aiProcess_ImproveCacheLocality;
  1717. CheckMenuItem(hMenu,ID_VIEWER_PP_ICL,ppsteps & aiProcess_ImproveCacheLocality ? MF_CHECKED : MF_UNCHECKED);
  1718. UpdatePPSettings();
  1719. }
  1720. else if (ID_VIEWER_PP_OG == LOWORD(wParam)) {
  1721. if (ppsteps & aiProcess_PreTransformVertices) {
  1722. CLogDisplay::Instance().AddEntry("[ERROR] This setting is incompatible with \'Pretransform Vertices\'");
  1723. }
  1724. else {
  1725. ppsteps ^= aiProcess_OptimizeGraph;
  1726. CheckMenuItem(hMenu,ID_VIEWER_PP_OG,ppsteps & aiProcess_OptimizeGraph ? MF_CHECKED : MF_UNCHECKED);
  1727. UpdatePPSettings();
  1728. }
  1729. }
  1730. else if (ID_VIEWER_PP_OM == LOWORD(wParam)) {
  1731. ppsteps ^= aiProcess_OptimizeMeshes;
  1732. CheckMenuItem(hMenu,ID_VIEWER_PP_OM,ppsteps & aiProcess_OptimizeMeshes ? MF_CHECKED : MF_UNCHECKED);
  1733. UpdatePPSettings();
  1734. }
  1735. else if (ID_VIEWER_PP_PTV == LOWORD(wParam)) {
  1736. if (ppsteps & aiProcess_OptimizeGraph) {
  1737. CLogDisplay::Instance().AddEntry("[ERROR] This setting is incompatible with \'Optimize Scenegraph\'");
  1738. }
  1739. else {
  1740. ppsteps ^= aiProcess_PreTransformVertices;
  1741. CheckMenuItem(hMenu,ID_VIEWER_PP_PTV,ppsteps & aiProcess_PreTransformVertices ? MF_CHECKED : MF_UNCHECKED);
  1742. UpdatePPSettings();
  1743. }
  1744. }
  1745. else if (ID_VIEWER_PP_RRM2 == LOWORD(wParam)) {
  1746. ppsteps ^= aiProcess_RemoveRedundantMaterials;
  1747. CheckMenuItem(hMenu,ID_VIEWER_PP_RRM2,ppsteps & aiProcess_RemoveRedundantMaterials ? MF_CHECKED : MF_UNCHECKED);
  1748. UpdatePPSettings();
  1749. }
  1750. else if (ID_VIEWER_PP_TUV == LOWORD(wParam)) {
  1751. ppsteps ^= aiProcess_TransformUVCoords;
  1752. CheckMenuItem(hMenu,ID_VIEWER_PP_TUV,ppsteps & aiProcess_TransformUVCoords ? MF_CHECKED : MF_UNCHECKED);
  1753. UpdatePPSettings();
  1754. }
  1755. else if (ID_VIEWER_PP_DB == LOWORD(wParam)) {
  1756. ppsteps ^= aiProcess_Debone;
  1757. CheckMenuItem(hMenu,ID_VIEWER_PP_DB,ppsteps & aiProcess_Debone ? MF_CHECKED : MF_UNCHECKED);
  1758. UpdatePPSettings();
  1759. }
  1760. else if (ID_VIEWER_PP_VDS == LOWORD(wParam)) {
  1761. ppsteps ^= aiProcess_ValidateDataStructure;
  1762. CheckMenuItem(hMenu,ID_VIEWER_PP_VDS,ppsteps & aiProcess_ValidateDataStructure ? MF_CHECKED : MF_UNCHECKED);
  1763. UpdatePPSettings();
  1764. }
  1765. else if (ID_VIEWER_RELOAD == LOWORD(wParam))
  1766. {
  1767. DeleteAsset();
  1768. LoadAsset();
  1769. }
  1770. else if (ID_IMPORTSETTINGS_RESETTODEFAULT == LOWORD(wParam))
  1771. {
  1772. ppsteps = ppstepsdefault;
  1773. UpdatePPSettings();
  1774. SetupPPUIState();
  1775. }
  1776. else if (ID_IMPORTSETTINGS_OPENPOST == LOWORD(wParam))
  1777. {
  1778. ShellExecute(NULL,"open","http://assimp.sourceforge.net/lib_html/ai_post_process_8h.html","","",SW_SHOW);
  1779. }
  1780. else if (ID_TOOLS_ORIGINALNORMALS == LOWORD(wParam))
  1781. {
  1782. if (g_pcAsset && g_pcAsset->pcScene)
  1783. {
  1784. g_pcAsset->SetNormalSet(AssimpView::AssetHelper::ORIGINAL);
  1785. CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_CHECKED);
  1786. CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1787. CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1788. }
  1789. }
  1790. else if (ID_TOOLS_SMOOTHNORMALS == LOWORD(wParam))
  1791. {
  1792. if (g_pcAsset && g_pcAsset->pcScene)
  1793. {
  1794. g_pcAsset->SetNormalSet(AssimpView::AssetHelper::SMOOTH);
  1795. CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1796. CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1797. CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_CHECKED);
  1798. }
  1799. }
  1800. else if (ID_TOOLS_HARDNORMALS == LOWORD(wParam))
  1801. {
  1802. if (g_pcAsset && g_pcAsset->pcScene)
  1803. {
  1804. g_pcAsset->SetNormalSet(AssimpView::AssetHelper::HARD);
  1805. CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1806. CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_CHECKED);
  1807. CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
  1808. }
  1809. }
  1810. else if (ID_TOOLS_STEREOVIEW == LOWORD(wParam))
  1811. {
  1812. g_sOptions.bStereoView =! g_sOptions.bStereoView;
  1813. HMENU hMenu = GetMenu(g_hDlg);
  1814. if (g_sOptions.bStereoView)
  1815. {
  1816. ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW,
  1817. MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view");
  1818. CLogDisplay::Instance().AddEntry("[INFO] Switched to stereo mode",
  1819. D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
  1820. }
  1821. else
  1822. {
  1823. ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW,
  1824. MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view");
  1825. CLogDisplay::Instance().AddEntry("[INFO] Switched to mono mode",
  1826. D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
  1827. }
  1828. }
  1829. else if (ID_TOOLS_SETANGLELIMIT == LOWORD(wParam))
  1830. {
  1831. DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_DIALOGSMOOTH),g_hDlg,&SMMessageProc);
  1832. }
  1833. else if (ID_VIEWER_CLEARHISTORY == LOWORD(wParam))
  1834. {
  1835. ClearHistory();
  1836. }
  1837. else if (ID_VIEWER_CLOSEASSET == LOWORD(wParam))
  1838. {
  1839. DeleteAssetData();
  1840. DeleteAsset();
  1841. }
  1842. else if (BN_CLICKED == HIWORD(wParam))
  1843. {
  1844. if (IDC_TOGGLEMS == LOWORD(wParam))
  1845. {
  1846. ToggleMS();
  1847. }
  1848. else if (IDC_TOGGLEMAT == LOWORD(wParam))
  1849. {
  1850. ToggleMats();
  1851. }
  1852. else if (IDC_LCOLOR1 == LOWORD(wParam))
  1853. {
  1854. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1855. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1856. {
  1857. // hey, I'm tired and yes, I KNOW IT IS EVIL!
  1858. DisplayColorDialog(const_cast<D3DXVECTOR4*>(CDisplay::Instance().GetFirstCheckerColor()));
  1859. SaveCheckerPatternColors();
  1860. }
  1861. else
  1862. {
  1863. DisplayColorDialog(&g_avLightColors[0]);
  1864. SaveLightColors();
  1865. }
  1866. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),NULL,TRUE);
  1867. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR1));
  1868. }
  1869. else if (IDC_LCOLOR2 == LOWORD(wParam))
  1870. {
  1871. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1872. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1873. {
  1874. // hey, I'm tired and yes, I KNOW IT IS EVIL!
  1875. DisplayColorDialog(const_cast<D3DXVECTOR4*>(CDisplay::Instance().GetSecondCheckerColor()));
  1876. SaveCheckerPatternColors();
  1877. }
  1878. else
  1879. {
  1880. DisplayColorDialog(&g_avLightColors[1]);
  1881. SaveLightColors();
  1882. }
  1883. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR2),NULL,TRUE);
  1884. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR2));
  1885. }
  1886. else if (IDC_LCOLOR3 == LOWORD(wParam))
  1887. {
  1888. DisplayColorDialog(&g_avLightColors[2]);
  1889. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR3),NULL,TRUE);
  1890. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR3));
  1891. SaveLightColors();
  1892. }
  1893. else if (IDC_LRESET == LOWORD(wParam))
  1894. {
  1895. if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
  1896. CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
  1897. {
  1898. CDisplay::Instance().SetFirstCheckerColor(D3DXVECTOR4(0.4f,0.4f,0.4f,1.0f));
  1899. CDisplay::Instance().SetSecondCheckerColor(D3DXVECTOR4(0.6f,0.6f,0.6f,1.0f));
  1900. SaveCheckerPatternColors();
  1901. }
  1902. else
  1903. {
  1904. g_avLightColors[0] = D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF);
  1905. g_avLightColors[1] = D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00);
  1906. g_avLightColors[2] = D3DCOLOR_ARGB(0xFF,0x05,0x05,0x05);
  1907. SaveLightColors();
  1908. }
  1909. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),NULL,TRUE);
  1910. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR1));
  1911. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR2),NULL,TRUE);
  1912. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR2));
  1913. InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR3),NULL,TRUE);
  1914. UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR3));
  1915. }
  1916. else if (IDC_NOSPECULAR == LOWORD(wParam))
  1917. {
  1918. ToggleSpecular();
  1919. }
  1920. else if (IDC_NOAB == LOWORD(wParam))
  1921. {
  1922. ToggleTransparency();
  1923. }
  1924. else if (IDC_ZOOM == LOWORD(wParam))
  1925. {
  1926. ToggleFPSView();
  1927. }
  1928. else if (IDC_BLUBB == LOWORD(wParam))
  1929. {
  1930. ToggleUIState();
  1931. }
  1932. else if (IDC_TOGGLENORMALS == LOWORD(wParam))
  1933. {
  1934. ToggleNormals();
  1935. }
  1936. else if (IDC_LOWQUALITY == LOWORD(wParam))
  1937. {
  1938. ToggleLowQuality();
  1939. }
  1940. else if (IDC_3LIGHTS == LOWORD(wParam))
  1941. {
  1942. ToggleMultipleLights();
  1943. }
  1944. else if (IDC_LIGHTROTATE == LOWORD(wParam))
  1945. {
  1946. ToggleLightRotate();
  1947. }
  1948. else if (IDC_AUTOROTATE == LOWORD(wParam))
  1949. {
  1950. ToggleAutoRotate();
  1951. }
  1952. else if (IDC_TOGGLEWIRE == LOWORD(wParam))
  1953. {
  1954. ToggleWireFrame();
  1955. }
  1956. else if (IDC_SHOWSKELETON == LOWORD(wParam))
  1957. {
  1958. ToggleSkeleton();
  1959. }
  1960. else if (IDC_BFCULL == LOWORD(wParam))
  1961. {
  1962. ToggleCulling();
  1963. }
  1964. else if (IDC_PLAY == LOWORD(wParam))
  1965. {
  1966. g_bPlay = !g_bPlay;
  1967. SetDlgItemText(g_hDlg,IDC_PLAY,(g_bPlay ? "Stop" : "Play"));
  1968. if (g_bPlay)
  1969. EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),FALSE);
  1970. else EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),TRUE);
  1971. }
  1972. }
  1973. // check the file history
  1974. for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
  1975. {
  1976. if (AI_VIEW_RECENT_FILE_ID(i) == LOWORD(wParam))
  1977. {
  1978. strcpy(g_szFileName,g_aPreviousFiles[i].c_str());
  1979. DeleteAssetData();
  1980. DeleteAsset();
  1981. LoadAsset();
  1982. // update and safe the history
  1983. UpdateHistory();
  1984. SaveHistory();
  1985. }
  1986. }
  1987. #ifndef ASSIMP_BUILD_NO_EXPORT
  1988. if (LOWORD(wParam) >= AI_VIEW_EXPORT_FMT_BASE && LOWORD(wParam) < AI_VIEW_EXPORT_FMT_BASE+Assimp::Exporter().GetExportFormatCount()) {
  1989. DoExport(LOWORD(wParam) - AI_VIEW_EXPORT_FMT_BASE);
  1990. }
  1991. #endif
  1992. // handle popup menus for the tree window
  1993. CDisplay::Instance().HandleTreeViewPopup(wParam,lParam);
  1994. return TRUE;
  1995. };
  1996. return FALSE;
  1997. }
  1998. //-------------------------------------------------------------------------------
  1999. // Message prcoedure for the progress dialog
  2000. //-------------------------------------------------------------------------------
  2001. INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg,UINT uMsg,
  2002. WPARAM wParam,LPARAM lParam)
  2003. {
  2004. UNREFERENCED_PARAMETER(lParam);
  2005. switch (uMsg)
  2006. {
  2007. case WM_INITDIALOG:
  2008. SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_SETRANGE,0,
  2009. MAKELPARAM(0,500));
  2010. SetTimer(hwndDlg,0,40,NULL);
  2011. return TRUE;
  2012. case WM_CLOSE:
  2013. EndDialog(hwndDlg,0);
  2014. return TRUE;
  2015. case WM_COMMAND:
  2016. if (IDOK == LOWORD(wParam))
  2017. {
  2018. #if 0
  2019. g_bLoadingCanceled = true;
  2020. TerminateThread(g_hThreadHandle,5);
  2021. g_pcAsset = NULL;
  2022. EndDialog(hwndDlg,0);
  2023. #endif
  2024. // PROBLEM: If we terminate the loader thread, ASSIMP's state
  2025. // is undefined. Any further attempts to load assets will
  2026. // fail.
  2027. exit(5);
  2028. // return TRUE;
  2029. }
  2030. case WM_TIMER:
  2031. UINT iPos = (UINT)SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_GETPOS,0,0);
  2032. iPos += 10;
  2033. if (iPos > 490)iPos = 0;
  2034. SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_SETPOS,iPos,0);
  2035. if (g_bLoadingFinished)
  2036. {
  2037. EndDialog(hwndDlg,0);
  2038. return TRUE;
  2039. }
  2040. return TRUE;
  2041. }
  2042. return FALSE;
  2043. }
  2044. //-------------------------------------------------------------------------------
  2045. // Message procedure for the about dialog
  2046. //-------------------------------------------------------------------------------
  2047. INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
  2048. WPARAM wParam,LPARAM lParam)
  2049. {
  2050. UNREFERENCED_PARAMETER(lParam);
  2051. switch (uMsg)
  2052. {
  2053. case WM_CLOSE:
  2054. EndDialog(hwndDlg,0);
  2055. return TRUE;
  2056. case WM_COMMAND:
  2057. if (IDOK == LOWORD(wParam))
  2058. {
  2059. EndDialog(hwndDlg,0);
  2060. return TRUE;
  2061. }
  2062. }
  2063. return FALSE;
  2064. }
  2065. };
  2066. using namespace AssimpView;
  2067. //-------------------------------------------------------------------------------
  2068. // Entry point to the application
  2069. //-------------------------------------------------------------------------------
  2070. int APIENTRY _tWinMain(HINSTANCE hInstance,
  2071. HINSTANCE hPrevInstance,
  2072. LPTSTR lpCmdLine,
  2073. int nCmdShow)
  2074. {
  2075. UNREFERENCED_PARAMETER(hPrevInstance);
  2076. UNREFERENCED_PARAMETER(lpCmdLine);
  2077. // needed for the RichEdit control in the about/help dialog
  2078. LoadLibrary( "riched20.dll" );
  2079. // load windows common controls library to get XP style
  2080. InitCommonControls();
  2081. // intiailize the IDirect3D9 interface
  2082. g_hInstance = hInstance;
  2083. if (0 == InitD3D())
  2084. {
  2085. MessageBox(NULL,"Failed to initialize Direct3D 9",
  2086. "ASSIMP ModelViewer",MB_OK);
  2087. return -6;
  2088. }
  2089. // create the main dialog
  2090. HWND hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOGMAIN),
  2091. NULL,&MessageProc);
  2092. // ensure we get high priority
  2093. ::SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);
  2094. // initialize the default logger if necessary
  2095. Assimp::DefaultLogger::create("",Assimp::Logger::VERBOSE);
  2096. CLogWindow::Instance().pcStream = new CMyLogStream();
  2097. Assimp::DefaultLogger::get()->attachStream(CLogWindow::Instance().pcStream,
  2098. Assimp::DefaultLogger::Debugging | Assimp::DefaultLogger::Info |
  2099. Assimp::DefaultLogger::Err | Assimp::DefaultLogger::Warn);
  2100. if (NULL == hDlg)
  2101. {
  2102. MessageBox(NULL,"Failed to create dialog from resource",
  2103. "ASSIMP ModelViewer",MB_OK);
  2104. return -5;
  2105. }
  2106. // display the window
  2107. g_hDlg = hDlg;
  2108. MSG uMsg;
  2109. memset(&uMsg,0,sizeof( MSG));
  2110. ShowWindow( hDlg, nCmdShow );
  2111. UpdateWindow( hDlg );
  2112. // create the D3D device object
  2113. if (0 == CreateDevice(g_sOptions.bMultiSample,false,true))
  2114. {
  2115. MessageBox(NULL,"Failed to initialize Direct3D 9 (2)",
  2116. "ASSIMP ModelViewer",MB_OK);
  2117. return -4;
  2118. }
  2119. CLogDisplay::Instance().AddEntry("[OK] Here we go!");
  2120. // create the log window
  2121. CLogWindow::Instance().Init();
  2122. // set the focus to the main window
  2123. SetFocus(g_hDlg);
  2124. // recover background skyboxes/textures from the last session
  2125. HKEY g_hRegistry;
  2126. union
  2127. {
  2128. char szFileName[MAX_PATH];
  2129. D3DCOLOR clrColor;
  2130. };
  2131. DWORD dwTemp = MAX_PATH;
  2132. RegCreateKeyEx(HKEY_CURRENT_USER,
  2133. "Software\\ASSIMP\\Viewer",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
  2134. if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastSkyBoxSrc",NULL,NULL,
  2135. (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0])
  2136. {
  2137. CBackgroundPainter::Instance().SetCubeMapBG(szFileName);
  2138. }
  2139. else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastTextureSrc",NULL,NULL,
  2140. (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0])
  2141. {
  2142. CBackgroundPainter::Instance().SetTextureBG(szFileName);
  2143. }
  2144. else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"Color",NULL,NULL,
  2145. (BYTE*)&clrColor,&dwTemp))
  2146. {
  2147. CBackgroundPainter::Instance().SetColor(clrColor);
  2148. }
  2149. RegCloseKey(g_hRegistry);
  2150. // now handle command line arguments
  2151. HandleCommandLine(lpCmdLine);
  2152. double adLast[30];
  2153. for (int i = 0; i < 30;++i)adLast[i] = 0.0f;
  2154. int iCurrent = 0;
  2155. double g_dCurTime = 0;
  2156. double g_dLastTime = 0;
  2157. while( uMsg.message != WM_QUIT )
  2158. {
  2159. if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
  2160. {
  2161. TranslateMessage( &uMsg );
  2162. DispatchMessage( &uMsg );
  2163. if (WM_CHAR == uMsg.message)
  2164. {
  2165. switch ((char)uMsg.wParam)
  2166. {
  2167. case 'M':
  2168. case 'm':
  2169. CheckDlgButton(g_hDlg,IDC_TOGGLEMS,
  2170. IsDlgButtonChecked(g_hDlg,IDC_TOGGLEMS) == BST_CHECKED
  2171. ? BST_UNCHECKED : BST_CHECKED);
  2172. ToggleMS();
  2173. break;
  2174. case 'L':
  2175. case 'l':
  2176. CheckDlgButton(g_hDlg,IDC_3LIGHTS,
  2177. IsDlgButtonChecked(g_hDlg,IDC_3LIGHTS) == BST_CHECKED
  2178. ? BST_UNCHECKED : BST_CHECKED);
  2179. ToggleMultipleLights();
  2180. break;
  2181. case 'P':
  2182. case 'p':
  2183. CheckDlgButton(g_hDlg,IDC_LOWQUALITY,
  2184. IsDlgButtonChecked(g_hDlg,IDC_LOWQUALITY) == BST_CHECKED
  2185. ? BST_UNCHECKED : BST_CHECKED);
  2186. ToggleLowQuality();
  2187. break;
  2188. case 'D':
  2189. case 'd':
  2190. CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,
  2191. IsDlgButtonChecked(g_hDlg,IDC_TOGGLEMAT) == BST_CHECKED
  2192. ? BST_UNCHECKED : BST_CHECKED);
  2193. ToggleMats();
  2194. break;
  2195. case 'N':
  2196. case 'n':
  2197. CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,
  2198. IsDlgButtonChecked(g_hDlg,IDC_TOGGLENORMALS) == BST_CHECKED
  2199. ? BST_UNCHECKED : BST_CHECKED);
  2200. ToggleNormals();
  2201. break;
  2202. case 'S':
  2203. case 's':
  2204. CheckDlgButton(g_hDlg,IDC_NOSPECULAR,
  2205. IsDlgButtonChecked(g_hDlg,IDC_NOSPECULAR) == BST_CHECKED
  2206. ? BST_UNCHECKED : BST_CHECKED);
  2207. ToggleSpecular();
  2208. break;
  2209. case 'A':
  2210. case 'a':
  2211. CheckDlgButton(g_hDlg,IDC_AUTOROTATE,
  2212. IsDlgButtonChecked(g_hDlg,IDC_AUTOROTATE) == BST_CHECKED
  2213. ? BST_UNCHECKED : BST_CHECKED);
  2214. ToggleAutoRotate();
  2215. break;
  2216. case 'R':
  2217. case 'r':
  2218. CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,
  2219. IsDlgButtonChecked(g_hDlg,IDC_LIGHTROTATE) == BST_CHECKED
  2220. ? BST_UNCHECKED : BST_CHECKED);
  2221. ToggleLightRotate();
  2222. break;
  2223. case 'Z':
  2224. case 'z':
  2225. CheckDlgButton(g_hDlg,IDC_ZOOM,
  2226. IsDlgButtonChecked(g_hDlg,IDC_ZOOM) == BST_CHECKED
  2227. ? BST_UNCHECKED : BST_CHECKED);
  2228. ToggleFPSView();
  2229. break;
  2230. case 'W':
  2231. case 'w':
  2232. CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,
  2233. IsDlgButtonChecked(g_hDlg,IDC_TOGGLEWIRE) == BST_CHECKED
  2234. ? BST_UNCHECKED : BST_CHECKED);
  2235. ToggleWireFrame();
  2236. break;
  2237. case 'K':
  2238. case 'k':
  2239. CheckDlgButton(g_hDlg,IDC_SHOWSKELETON,
  2240. IsDlgButtonChecked(g_hDlg,IDC_SHOWSKELETON) == BST_CHECKED
  2241. ? BST_UNCHECKED : BST_CHECKED);
  2242. ToggleSkeleton();
  2243. break;
  2244. case 'C':
  2245. case 'c':
  2246. CheckDlgButton(g_hDlg,IDC_BFCULL,
  2247. IsDlgButtonChecked(g_hDlg,IDC_BFCULL) == BST_CHECKED
  2248. ? BST_UNCHECKED : BST_CHECKED);
  2249. ToggleCulling();
  2250. break;
  2251. case 'T':
  2252. case 't':
  2253. CheckDlgButton(g_hDlg,IDC_NOAB,
  2254. IsDlgButtonChecked(g_hDlg,IDC_NOAB) == BST_CHECKED
  2255. ? BST_UNCHECKED : BST_CHECKED);
  2256. ToggleTransparency();
  2257. break;
  2258. }
  2259. }
  2260. }
  2261. // render the scene
  2262. CDisplay::Instance().OnRender();
  2263. // measure FPS, average it out
  2264. g_dCurTime = timeGetTime();
  2265. g_fElpasedTime = (float)((g_dCurTime - g_dLastTime) * 0.001);
  2266. g_dLastTime = g_dCurTime;
  2267. adLast[iCurrent++] = 1.0f / g_fElpasedTime;
  2268. double dFPS = 0.0;
  2269. for (int i = 0;i < 30;++i)
  2270. dFPS += adLast[i];
  2271. dFPS /= 30.0;
  2272. if (30 == iCurrent)
  2273. {
  2274. iCurrent = 0;
  2275. if (dFPS != g_fFPS)
  2276. {
  2277. g_fFPS = dFPS;
  2278. char szOut[256];
  2279. sprintf(szOut,"%i",(int)floorf((float)dFPS+0.5f));
  2280. SetDlgItemText(g_hDlg,IDC_EFPS,szOut);
  2281. }
  2282. }
  2283. }
  2284. DeleteAsset();
  2285. Assimp::DefaultLogger::kill();
  2286. ShutdownDevice();
  2287. ShutdownD3D();
  2288. return 0;
  2289. }