MessageProc.cpp 80 KB

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