MessageProc.cpp 74 KB

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