MessageProc.cpp 79 KB

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