MessageProc.cpp 69 KB

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