MessageProc.cpp 78 KB

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