MessageProc.cpp 94 KB

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