MessageProc.cpp 78 KB

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