MessageProc.cpp 92 KB

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