| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287 |
- /*
- ---------------------------------------------------------------------------
- Open Asset Import Library (ASSIMP)
- ---------------------------------------------------------------------------
- Copyright (c) 2006-2008, ASSIMP Development Team
- All rights reserved.
- Redistribution and use of this software in source and binary forms,
- with or without modification, are permitted provided that the following
- conditions are met:
- * Redistributions of source code must retain the above
- copyright notice, this list of conditions and the
- following disclaimer.
- * Redistributions in binary form must reproduce the above
- copyright notice, this list of conditions and the
- following disclaimer in the documentation and/or other
- materials provided with the distribution.
- * Neither the name of the ASSIMP team, nor the names of its
- contributors may be used to endorse or promote products
- derived from this software without specific prior
- written permission of the ASSIMP Development Team.
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- ---------------------------------------------------------------------------
- */
- #include "stdafx.h"
- #include "assimp_view.h"
- namespace AssimpView {
- // Static array to keep custom color values
- COLORREF g_aclCustomColors[16] = {0};
- // Global registry key
- HKEY g_hRegistry = NULL;
- // list of previous files (always 5)
- std::vector<std::string> g_aPreviousFiles;
- // history menu item
- HMENU g_hHistoryMenu = NULL;
- #define AI_VIEW_NUM_RECENT_FILES 0x8
- #define AI_VIEW_RECENT_FILE_ID(_n_) (5678 + _n_)
- void UpdateHistory();
- void SaveHistory();
- //-------------------------------------------------------------------------------
- // Setup file associations for all formats supported by the library
- //
- // File associations are registered in HKCU\Software\Classes. They might
- // be overwritten by global file associations.
- //-------------------------------------------------------------------------------
- void MakeFileAssociations()
- {
- char szTemp2[MAX_PATH];
- char szTemp[MAX_PATH + 10];
- GetModuleFileName(NULL,szTemp2,MAX_PATH);
- sprintf(szTemp,"%s %%1",szTemp2);
- HKEY g_hRegistry;
- // -------------------------------------------------
- // .3ds
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.3ds",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .x
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.x",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .obj
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.obj",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .ms3d
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.ms3d",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .md3
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.md3",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .md2
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.md2",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .md4/mdr
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.md4",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.mdr",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .md5
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.md5",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .mdl
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.mdl",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .ply
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.ply",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- // -------------------------------------------------
- // .ase/.ask
- // -------------------------------------------------
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.ase",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\.ask",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)"ASSIMPVIEW_CLASS",(DWORD)strlen("ASSIMPVIEW_CLASS")+1);
- RegCloseKey(g_hRegistry);
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegCloseKey(g_hRegistry);
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS\\shell\\open\\command",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegSetValueEx(g_hRegistry,"",0,REG_SZ,(const BYTE*)szTemp,(DWORD)strlen(szTemp)+1);
- RegCloseKey(g_hRegistry);
- CLogDisplay::Instance().AddEntry("[OK] File assocations have been registered",
- D3DCOLOR_ARGB(0xFF,0,0xFF,0));
- aiString sz;
- aiGetExtensionList(&sz);
- CLogDisplay::Instance().AddEntry(sz.data,
- D3DCOLOR_ARGB(0xFF,0,0xFF,0));
- return;
- }
- //-------------------------------------------------------------------------------
- // Handle command line parameters
- //
- // The function loads an asset specified on the command line as first argument
- // Other command line parameters are not handled
- //-------------------------------------------------------------------------------
- void HandleCommandLine(char* p_szCommand)
- {
- char* sz = p_szCommand;
- //bool bQuak = false;
- if (strlen(sz) < 2)return;
- if (*sz == '\"')
- {
- char* sz2 = strrchr(sz,'\"');
- if (sz2)*sz2 = 0;
- }
- strcpy( g_szFileName, sz );
- LoadAsset();
- // update the history
- UpdateHistory();
- // Save the list of previous files to the registry
- SaveHistory();
- }
- //-------------------------------------------------------------------------------
- // Load the light colors from the registry
- //-------------------------------------------------------------------------------
- void LoadLightColors()
- {
- DWORD dwTemp = 4;
- RegQueryValueEx(g_hRegistry,"LightColor0",NULL,NULL,
- (BYTE*)&g_avLightColors[0],&dwTemp);
- RegQueryValueEx(g_hRegistry,"LightColor1",NULL,NULL,
- (BYTE*)&g_avLightColors[1],&dwTemp);
- RegQueryValueEx(g_hRegistry,"LightColor2",NULL,NULL,
- (BYTE*)&g_avLightColors[2],&dwTemp);
- return;
- }
- //-------------------------------------------------------------------------------
- // Save the light colors to the registry
- //-------------------------------------------------------------------------------
- void SaveLightColors()
- {
- RegSetValueExA(g_hRegistry,"LightColor0",0,REG_DWORD,(const BYTE*)&g_avLightColors[0],4);
- RegSetValueExA(g_hRegistry,"LightColor1",0,REG_DWORD,(const BYTE*)&g_avLightColors[1],4);
- RegSetValueExA(g_hRegistry,"LightColor2",0,REG_DWORD,(const BYTE*)&g_avLightColors[2],4);
- }
- //-------------------------------------------------------------------------------
- // Save the checker pattern colors to the registry
- //-------------------------------------------------------------------------------
- void SaveCheckerPatternColors()
- {
- // we have it as float4. save it as binary value --.
- RegSetValueExA(g_hRegistry,"CheckerPattern0",0,REG_BINARY,
- (const BYTE*)CDisplay::Instance().GetFirstCheckerColor(),
- sizeof(D3DXVECTOR3));
- RegSetValueExA(g_hRegistry,"CheckerPattern1",0,REG_BINARY,
- (const BYTE*)CDisplay::Instance().GetSecondCheckerColor(),
- sizeof(D3DXVECTOR3));
- }
- //-------------------------------------------------------------------------------
- // Load the checker pattern colors from the registry
- //-------------------------------------------------------------------------------
- void LoadCheckerPatternColors()
- {
- DWORD dwTemp = sizeof(D3DXVECTOR3);
- RegQueryValueEx(g_hRegistry,"CheckerPattern0",NULL,NULL,
- (BYTE*) /* jep, this is evil */ CDisplay::Instance().GetFirstCheckerColor(),&dwTemp);
- RegQueryValueEx(g_hRegistry,"CheckerPattern1",NULL,NULL,
- (BYTE*) /* jep, this is evil */ CDisplay::Instance().GetSecondCheckerColor(),&dwTemp);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "Display Normals" state
- //-------------------------------------------------------------------------------
- void ToggleNormals()
- {
- g_sOptions.bRenderNormals = !g_sOptions.bRenderNormals;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bRenderNormals)dwValue = 1;
- RegSetValueExA(g_hRegistry,"RenderNormals",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "AutoRotate" state
- //-------------------------------------------------------------------------------
- void ToggleAutoRotate()
- {
- g_sOptions.bRotate = !g_sOptions.bRotate;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bRotate)dwValue = 1;
- RegSetValueExA(g_hRegistry,"AutoRotate",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "FPS" state
- //-------------------------------------------------------------------------------
- void ToggleFPSView()
- {
- g_bFPSView = !g_bFPSView;
- SetupFPSView();
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_bFPSView)dwValue = 1;
- RegSetValueExA(g_hRegistry,"FPSView",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "2 Light sources" state
- //-------------------------------------------------------------------------------
- void ToggleMultipleLights()
- {
- g_sOptions.b3Lights = !g_sOptions.b3Lights;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.b3Lights)dwValue = 1;
- RegSetValueExA(g_hRegistry,"MultipleLights",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "LightRotate" state
- //-------------------------------------------------------------------------------
- void ToggleLightRotate()
- {
- g_sOptions.bLightRotate = !g_sOptions.bLightRotate;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bLightRotate)dwValue = 1;
- RegSetValueExA(g_hRegistry,"LightRotate",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "LowQuality" state
- //-------------------------------------------------------------------------------
- void ToggleLowQuality()
- {
- g_sOptions.bLowQuality = !g_sOptions.bLowQuality;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bLowQuality)dwValue = 1;
- RegSetValueExA(g_hRegistry,"LowQuality",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "Specular" state
- //-------------------------------------------------------------------------------
- void ToggleSpecular()
- {
- g_sOptions.bNoSpecular = !g_sOptions.bNoSpecular;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bNoSpecular)dwValue = 1;
- RegSetValueExA(g_hRegistry,"NoSpecular",0,REG_DWORD,(const BYTE*)&dwValue,4);
- // update all specular materials
- CMaterialManager::Instance().UpdateSpecularMaterials();
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "RenderMats" state
- //-------------------------------------------------------------------------------
- void ToggleMats()
- {
- g_sOptions.bRenderMats = !g_sOptions.bRenderMats;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bRenderMats)dwValue = 1;
- RegSetValueExA(g_hRegistry,"RenderMats",0,REG_DWORD,(const BYTE*)&dwValue,4);
- // update all specular materials
- CMaterialManager::Instance().UpdateSpecularMaterials();
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "WireFrame" state
- //-------------------------------------------------------------------------------
- void ToggleWireFrame()
- {
- if (g_sOptions.eDrawMode == RenderOptions::WIREFRAME)
- g_sOptions.eDrawMode = RenderOptions::NORMAL;
- else g_sOptions.eDrawMode = RenderOptions::WIREFRAME;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (RenderOptions::WIREFRAME == g_sOptions.eDrawMode)dwValue = 1;
- RegSetValueExA(g_hRegistry,"Wireframe",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "MultiSample" state
- //-------------------------------------------------------------------------------
- void ToggleMS()
- {
- g_sOptions.bMultiSample = !g_sOptions.bMultiSample;
- DeleteAssetData();
- ShutdownDevice();
- if (0 == CreateDevice())
- {
- CLogDisplay::Instance().AddEntry(
- "[ERROR] Failed to toggle MultiSampling mode");
- g_sOptions.bMultiSample = !g_sOptions.bMultiSample;
- CreateDevice();
- }
- CreateAssetData();
- if (g_sOptions.bMultiSample)
- {
- CLogDisplay::Instance().AddEntry(
- "[OK] Changed MultiSampling mode to the maximum value for this device");
- }
- else
- {
- CLogDisplay::Instance().AddEntry(
- "[OK] MultiSampling has been disabled");
- }
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bMultiSample)dwValue = 1;
- RegSetValueExA(g_hRegistry,"MultiSampling",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // Expand or collapse the UI
- //-------------------------------------------------------------------------------
- void ToggleUIState()
- {
- // adjust the size
- RECT sRect;
- GetWindowRect(g_hDlg,&sRect);
- sRect.right -= sRect.left;
- sRect.bottom -= sRect.top;
- RECT sRect2;
- GetWindowRect(GetDlgItem ( g_hDlg, IDC_BLUBB ),&sRect2);
- sRect2.left -= sRect.left;
- sRect2.top -= sRect.top;
- DWORD dwValue;
- if (BST_UNCHECKED == IsDlgButtonChecked(g_hDlg,IDC_BLUBB))
- {
- SetWindowPos(g_hDlg,NULL,0,0,sRect.right-188,sRect.bottom,
- SWP_NOMOVE | SWP_NOZORDER);
- dwValue = 0;
- SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>");
- RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4);
- }
- else
- {
- SetWindowPos(g_hDlg,NULL,0,0,sRect.right+188,sRect.bottom,
- SWP_NOMOVE | SWP_NOZORDER);
- dwValue = 1;
- SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),"<<");
- RegSetValueExA(g_hRegistry,"LastUIState",0,REG_DWORD,(const BYTE*)&dwValue,4);
- }
- UpdateWindow(g_hDlg);
- return;
- }
- //-------------------------------------------------------------------------------
- // Load the background texture for the cviewer
- //-------------------------------------------------------------------------------
- void LoadBGTexture()
- {
- char szFileName[MAX_PATH];
- DWORD dwTemp = MAX_PATH;
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"TextureSrc",NULL,NULL,
- (BYTE*)szFileName,&dwTemp))
- {
- // Key was not found. Use C:
- strcpy(szFileName,"");
- }
- else
- {
- // need to remove the file name
- char* sz = strrchr(szFileName,'\\');
- if (!sz)sz = strrchr(szFileName,'/');
- if (!sz)*sz = 0;
- }
- OPENFILENAME sFilename1 = {
- sizeof(OPENFILENAME),
- g_hDlg,GetModuleHandle(NULL),
- "Textures\0*.png;*.dds;*.tga;*.bmp;*.tif;*.ppm;*.ppx;*.jpg;*.jpeg;*.exr\0*.*\0",
- NULL, 0, 1,
- szFileName, MAX_PATH, NULL, 0, NULL,
- "Open texture as background",
- OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
- 0, 1, ".jpg", 0, NULL, NULL
- };
- if(GetOpenFileName(&sFilename1) == 0) return;
- // Now store the file in the registry
- RegSetValueExA(g_hRegistry,"TextureSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- CBackgroundPainter::Instance().SetTextureBG(szFileName);
- return;
- }
- //-------------------------------------------------------------------------------
- // Reset the background color to a smart and nice grey
- //-------------------------------------------------------------------------------
- void ClearBG()
- {
- D3DCOLOR clrColor = D3DCOLOR_ARGB(0xFF,100,100,100);
- CBackgroundPainter::Instance().SetColor(clrColor);
- RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4);
- return;
- }
- //-------------------------------------------------------------------------------
- // Let the user choose a color in a windows standard color dialog
- //-------------------------------------------------------------------------------
- void DisplayColorDialog(D3DCOLOR* pclrResult)
- {
- CHOOSECOLOR clr;
- clr.lStructSize = sizeof(CHOOSECOLOR);
- clr.hwndOwner = g_hDlg;
- clr.Flags = CC_RGBINIT | CC_FULLOPEN;
- clr.rgbResult = RGB((*pclrResult >> 16) & 0xff,(*pclrResult >> 8) & 0xff,*pclrResult & 0xff);
- clr.lpCustColors = g_aclCustomColors;
- clr.lpfnHook = NULL;
- clr.lpTemplateName = NULL;
- clr.lCustData = NULL;
- ChooseColor(&clr);
- *pclrResult = D3DCOLOR_ARGB(0xFF,
- GetRValue(clr.rgbResult),
- GetGValue(clr.rgbResult),
- GetBValue(clr.rgbResult));
- return;
- }
- //-------------------------------------------------------------------------------
- // Let the user choose a color in a windows standard color dialog
- //-------------------------------------------------------------------------------
- void DisplayColorDialog(D3DXVECTOR4* pclrResult)
- {
- CHOOSECOLOR clr;
- clr.lStructSize = sizeof(CHOOSECOLOR);
- clr.hwndOwner = g_hDlg;
- clr.Flags = CC_RGBINIT | CC_FULLOPEN;
- clr.rgbResult = RGB(clamp<unsigned char>(pclrResult->x * 255.0f),
- clamp<unsigned char>(pclrResult->y * 255.0f),
- clamp<unsigned char>(pclrResult->z * 255.0f));
- clr.lpCustColors = g_aclCustomColors;
- clr.lpfnHook = NULL;
- clr.lpTemplateName = NULL;
- clr.lCustData = NULL;
- ChooseColor(&clr);
- pclrResult->x = GetRValue(clr.rgbResult) / 255.0f;
- pclrResult->y = GetGValue(clr.rgbResult) / 255.0f;
- pclrResult->z = GetBValue(clr.rgbResult) / 255.0f;
- return;
- }
- //-------------------------------------------------------------------------------
- // Let the user choose the baclground color for the viewer
- //-------------------------------------------------------------------------------
- void ChooseBGColor()
- {
- RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- D3DCOLOR clrColor;
- DisplayColorDialog(&clrColor);
- CBackgroundPainter::Instance().SetColor(clrColor);
- RegSetValueExA(g_hRegistry,"Color",0,REG_DWORD,(const BYTE*)&clrColor,4);
- return;
- }
- //-------------------------------------------------------------------------------
- // Display the OpenFile dialog and let the user choose a new slybox as bg
- //-------------------------------------------------------------------------------
- void LoadSkybox()
- {
- char szFileName[MAX_PATH];
- DWORD dwTemp = MAX_PATH;
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"SkyBoxSrc",NULL,NULL,
- (BYTE*)szFileName,&dwTemp))
- {
- // Key was not found. Use C:
- strcpy(szFileName,"");
- }
- else
- {
- // need to remove the file name
- char* sz = strrchr(szFileName,'\\');
- if (!sz)sz = strrchr(szFileName,'/');
- if (!sz)*sz = 0;
- }
- OPENFILENAME sFilename1 = {
- sizeof(OPENFILENAME),
- g_hDlg,GetModuleHandle(NULL),
- "Skyboxes\0*.dds\0*.*\0", NULL, 0, 1,
- szFileName, MAX_PATH, NULL, 0, NULL,
- "Open skybox as background",
- OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
- 0, 1, ".dds", 0, NULL, NULL
- };
- if(GetOpenFileName(&sFilename1) == 0) return;
- // Now store the file in the registry
- RegSetValueExA(g_hRegistry,"SkyBoxSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastSkyBoxSrc",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- RegSetValueExA(g_hRegistry,"LastTextureSrc",0,REG_SZ,(const BYTE*)"",MAX_PATH);
- CBackgroundPainter::Instance().SetCubeMapBG(szFileName);
- return;
- }
- //-------------------------------------------------------------------------------
- // Sace a screenshot to an user-defined file
- //-------------------------------------------------------------------------------
- void SaveScreenshot()
- {
- char szFileName[MAX_PATH];
- DWORD dwTemp = MAX_PATH;
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"ScreenShot",NULL,NULL,
- (BYTE*)szFileName,&dwTemp))
- {
- // Key was not found. Use C:
- strcpy(szFileName,"");
- }
- else
- {
- // need to remove the file name
- char* sz = strrchr(szFileName,'\\');
- if (!sz)sz = strrchr(szFileName,'/');
- if (!sz)*sz = 0;
- }
- OPENFILENAME sFilename1 = {
- sizeof(OPENFILENAME),
- g_hDlg,GetModuleHandle(NULL),
- "PNG Images\0*.png", NULL, 0, 1,
- szFileName, MAX_PATH, NULL, 0, NULL,
- "Save Screenshot to file",
- OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
- 0, 1, ".png", 0, NULL, NULL
- };
- if(GetSaveFileName(&sFilename1) == 0) return;
- // Now store the file in the registry
- RegSetValueExA(g_hRegistry,"ScreenShot",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- IDirect3DSurface9* pi = NULL;
- g_piDevice->GetRenderTarget(0,&pi);
- if(!pi || FAILED(D3DXSaveSurfaceToFile(szFileName,D3DXIFF_PNG,pi,NULL,NULL)))
- {
- CLogDisplay::Instance().AddEntry("[ERROR] Unable to save screenshot",
- D3DCOLOR_ARGB(0xFF,0xFF,0,0));
- }
- else
- {
- CLogDisplay::Instance().AddEntry("[INFO] The screenshot has been saved",
- D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
- }
- if(pi)pi->Release();
- return;
- }
- //-------------------------------------------------------------------------------
- // Get the amount of memory required for textures
- //-------------------------------------------------------------------------------
- void AddTextureMem(IDirect3DTexture9* pcTex, unsigned int& out)
- {
- if (!pcTex)return;
- D3DSURFACE_DESC sDesc;
- pcTex->GetLevelDesc(0,&sDesc);
- out += (sDesc.Width * sDesc.Height) << 2;
- return;
- }
- //-------------------------------------------------------------------------------
- // Display memory statistics
- //-------------------------------------------------------------------------------
- void DisplayMemoryConsumption()
- {
- // first get the memory consumption for the aiScene
- if (! g_pcAsset ||!g_pcAsset->pcScene)
- {
- MessageBox(g_hDlg,"No asset is loaded. Can you guess how much memory I need to store nothing?",
- "Memory consumption",MB_OK);
- return;
- }
- unsigned int iScene = sizeof(aiScene);
- for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
- {
- iScene += sizeof(aiMesh);
- if (g_pcAsset->pcScene->mMeshes[i]->HasPositions())
- iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
- if (g_pcAsset->pcScene->mMeshes[i]->HasNormals())
- iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
- if (g_pcAsset->pcScene->mMeshes[i]->HasTangentsAndBitangents())
- iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices * 2;
- for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_COLOR_SETS;++a)
- {
- if (g_pcAsset->pcScene->mMeshes[i]->HasVertexColors(a))
- iScene += sizeof(aiColor4D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
- else break;
- }
- for (unsigned int a = 0; a < AI_MAX_NUMBER_OF_TEXTURECOORDS;++a)
- {
- if (g_pcAsset->pcScene->mMeshes[i]->HasTextureCoords(a))
- iScene += sizeof(aiVector3D) * g_pcAsset->pcScene->mMeshes[i]->mNumVertices;
- else break;
- }
- if (g_pcAsset->pcScene->mMeshes[i]->HasBones())
- {
- for (unsigned int p = 0; p < g_pcAsset->pcScene->mMeshes[i]->mNumBones;++p)
- {
- iScene += sizeof(aiBone);
- iScene += g_pcAsset->pcScene->mMeshes[i]->mBones[p]->mNumWeights * sizeof(aiVertexWeight);
- }
- }
- iScene += (sizeof(aiFace) + 3 * sizeof(unsigned int))*g_pcAsset->pcScene->mMeshes[i]->mNumFaces;
- }
- // add all embedded textures
- for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumTextures;++i)
- {
- const aiTexture* pc = g_pcAsset->pcScene->mTextures[i];
- if (0 != pc->mHeight)
- {
- iScene += 4 * pc->mHeight * pc->mWidth;
- }
- else iScene += pc->mWidth;
- }
- // add 30k for each material ... a string has 4k for example
- iScene += g_pcAsset->pcScene->mNumMaterials * 30 * 1024;
- // now get the memory consumption required by D3D, first all textures
- unsigned int iTexture = 0;
- for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
- {
- AssetHelper::MeshHelper* pc = g_pcAsset->apcMeshes[i];
- AddTextureMem(pc->piDiffuseTexture,iTexture);
- AddTextureMem(pc->piSpecularTexture,iTexture);
- AddTextureMem(pc->piAmbientTexture,iTexture);
- AddTextureMem(pc->piEmissiveTexture,iTexture);
- AddTextureMem(pc->piOpacityTexture,iTexture);
- AddTextureMem(pc->piNormalTexture,iTexture);
- AddTextureMem(pc->piShininessTexture,iTexture);
- }
- unsigned int iVRAM = iTexture;
- // now get the memory consumption of all vertex/index buffers
- unsigned int iVB = 0;
- unsigned int iIB = 0;
- for (unsigned int i = 0; i < g_pcAsset->pcScene->mNumMeshes;++i)
- {
- AssetHelper:: MeshHelper* pc = g_pcAsset->apcMeshes[i];
- union{
- D3DVERTEXBUFFER_DESC sDesc;
- D3DINDEXBUFFER_DESC sDesc2;
- };
- if (pc->piVB)
- {
- pc->piVB->GetDesc(&sDesc);
- iVB += sDesc.Size;
- }
- if (pc->piVBNormals)
- {
- pc->piVBNormals->GetDesc(&sDesc);
- iVB += sDesc.Size;
- }
- if (pc->piIB)
- {
- pc->piIB->GetDesc(&sDesc2);
- iIB += sDesc2.Size;
- }
- }
- iVRAM += iVB + iIB;
- // add the memory for the back buffer and depth stencil buffer
- RECT sRect;
- GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
- sRect.bottom -= sRect.top;
- sRect.right -= sRect.left;
- iVRAM += sRect.bottom * sRect.right * 8;
- char szOut[2048];
- sprintf(szOut,
- "(1 KB = 1024 Byte)\n\n"
- "ASSIMP Import Data: \t%i KB\n"
- "Texture data:\t\t%i KB\n"
- "Vertex buffers:\t\t%i KB\n"
- "Index buffers:\t\t%i KB\n"
- "Video Memory:\t\t%i KB\n\n"
- "Total: \t\t\t%i KB",
- iScene / 1024,iTexture / 1024,iVB / 1024,iIB / 1024,iVRAM / 1024,
- (iScene + iTexture + iVB + iIB + iVRAM) / 1024);
- MessageBox(g_hDlg,szOut,"Memory consumption",MB_OK);
- return;
- }
- //-------------------------------------------------------------------------------
- // Save the list of recent files to the registry
- //-------------------------------------------------------------------------------
- void SaveHistory()
- {
- for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
- {
- char szName[66];
- sprintf(szName,"Recent%i",i+1);
- RegSetValueEx(g_hRegistry,szName,0,REG_SZ,
- (const BYTE*)g_aPreviousFiles[i].c_str(),(DWORD)g_aPreviousFiles[i].length());
- }
- return;
- }
- //-------------------------------------------------------------------------------
- // Recover the file history
- //-------------------------------------------------------------------------------
- void LoadHistory()
- {
- g_aPreviousFiles.resize(AI_VIEW_NUM_RECENT_FILES);
- char szFileName[MAX_PATH];
- for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
- {
- char szName[66];
- sprintf(szName,"Recent%i",i+1);
- DWORD dwTemp = MAX_PATH;
- szFileName[0] ='\0';
- if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,szName,NULL,NULL,
- (BYTE*)szFileName,&dwTemp))
- {
- g_aPreviousFiles[i] = std::string(szFileName);
- }
- }
- // add sub items for all recent files
- g_hHistoryMenu = CreateMenu();
- for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
- {
- const char* szText = g_aPreviousFiles[i].c_str();
- UINT iFlags = 0;
- if ('\0' == *szText)
- {
- szText = "<empty>";
- iFlags = MF_GRAYED | MF_DISABLED;
- }
- AppendMenu(g_hHistoryMenu,MF_STRING | iFlags,AI_VIEW_RECENT_FILE_ID(i),szText);
- }
- ModifyMenu(GetMenu(g_hDlg),ID_VIEWER_RECENTFILES,MF_BYCOMMAND | MF_POPUP,
- (UINT_PTR)g_hHistoryMenu,"Recent files");
- return;
- }
- //-------------------------------------------------------------------------------
- // Clear the file history
- //-------------------------------------------------------------------------------
- void ClearHistory()
- {
- for(unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
- g_aPreviousFiles[i] = std::string("");
- for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
- {
- ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i),
- MF_STRING | MF_BYCOMMAND | MF_GRAYED | MF_DISABLED,AI_VIEW_RECENT_FILE_ID(i),"<empty>");
- }
- SaveHistory();
- }
- //-------------------------------------------------------------------------------
- // Update the file history
- //-------------------------------------------------------------------------------
- void UpdateHistory()
- {
- if(!g_hHistoryMenu)return;
- std::string sz = std::string(g_szFileName);
- if (g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] == sz)return;
- // add the new asset to the list of recent files
- for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES-1;++i)
- {
- g_aPreviousFiles[i] = g_aPreviousFiles[i+1];
- }
- g_aPreviousFiles[AI_VIEW_NUM_RECENT_FILES-1] = sz;
- for (int i = AI_VIEW_NUM_RECENT_FILES-1; i >= 0;--i)
- {
- const char* szText = g_aPreviousFiles[i].c_str();
- UINT iFlags = 0;
- if ('\0' == *szText)
- {
- szText = "<empty>";
- iFlags = MF_GRAYED | MF_DISABLED;
- }
- ModifyMenu(g_hHistoryMenu,AI_VIEW_RECENT_FILE_ID(i),
- MF_STRING | MF_BYCOMMAND | iFlags,AI_VIEW_RECENT_FILE_ID(i),szText);
- }
- return;
- }
- //-------------------------------------------------------------------------------
- // Open a new asset
- //-------------------------------------------------------------------------------
- void OpenAsset()
- {
- char szFileName[MAX_PATH];
- DWORD dwTemp = MAX_PATH;
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"CurrentApp",NULL,NULL,
- (BYTE*)szFileName,&dwTemp))
- {
- // Key was not found. Use C:
- strcpy(szFileName,"");
- }
- else
- {
- // need to remove the file name
- char* sz = strrchr(szFileName,'\\');
- if (!sz)sz = strrchr(szFileName,'/');
- if (!sz)*sz = 0;
- }
- // get a list of all file extensions supported by ASSIMP
- aiString sz;
- aiGetExtensionList(&sz);
- char szList[MAXLEN + 100];
- strcpy(szList,"ASSIMP assets");
- char* szCur = szList + 14;
- strcpy(szCur,sz.data);
- szCur += sz.length+1;
- strcpy(szCur,"All files");
- szCur += 10;
- strcpy(szCur,"*.*");
- szCur[4] = 0;
- OPENFILENAME sFilename1 = {
- sizeof(OPENFILENAME),
- g_hDlg,GetModuleHandle(NULL), szList, NULL, 0, 1,
- szFileName, MAX_PATH, NULL, 0, NULL,
- "Import Asset into ASSIMP",
- OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
- 0, 1, ".x", 0, NULL, NULL
- };
- if(GetOpenFileName(&sFilename1) == 0) return;
- // Now store the file in the registry
- RegSetValueExA(g_hRegistry,"CurrentApp",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- if (0 != strcmp(g_szFileName,szFileName))
- {
- strcpy(g_szFileName, szFileName);
- DeleteAssetData();
- DeleteAsset();
- LoadAsset();
- // update the history
- UpdateHistory();
- // Save the list of previous files to the registry
- SaveHistory();
- }
- return;
- }
- //-------------------------------------------------------------------------------
- // Initialize the user interface
- //-------------------------------------------------------------------------------
- void InitUI()
- {
- SetDlgItemText(g_hDlg,IDC_EVERT,"0");
- SetDlgItemText(g_hDlg,IDC_EFACE,"0");
- SetDlgItemText(g_hDlg,IDC_EMAT,"0");
- SetDlgItemText(g_hDlg,IDC_ESHADER,"0");
- SetDlgItemText(g_hDlg,IDC_ENODEWND,"0");
- SetDlgItemText(g_hDlg,IDC_ETEX,"0");
- SetDlgItemText(g_hDlg,IDC_EMESH,"0");
- // setup the default window title
- SetWindowText(g_hDlg,AI_VIEW_CAPTION_BASE);
- // read some UI properties from the registry and apply them
- DWORD dwValue;
- DWORD dwTemp = sizeof( DWORD );
- // store the key in a global variable for later use
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\ASSIMP\\Viewer",
- NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LastUIState",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))
- {
- dwValue = 1;
- }
- if (0 == dwValue)
- {
- // collapse the viewer
- // adjust the size
- RECT sRect;
- GetWindowRect(g_hDlg,&sRect);
- sRect.right -= sRect.left;
- sRect.bottom -= sRect.top;
- RECT sRect2;
- GetWindowRect(GetDlgItem ( g_hDlg, IDC_BLUBB ),&sRect2);
- sRect2.left -= sRect.left;
- sRect2.top -= sRect.top;
- SetWindowPos(g_hDlg,NULL,0,0,sRect.right-188,sRect.bottom,
- SWP_NOMOVE | SWP_NOZORDER);
- SetWindowText(GetDlgItem(g_hDlg,IDC_BLUBB),">>");
- }
- else
- {
- CheckDlgButton(g_hDlg,IDC_BLUBB,BST_CHECKED);
- }
- // AutoRotate
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"AutoRotate",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bRotate = false;
- CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bRotate = true;
- CheckDlgButton(g_hDlg,IDC_AUTOROTATE,BST_CHECKED);
- }
- // MultipleLights
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"MultipleLights",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.b3Lights = false;
- CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.b3Lights = true;
- CheckDlgButton(g_hDlg,IDC_3LIGHTS,BST_CHECKED);
- }
- // Light rotate
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LightRotate",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bLightRotate = false;
- CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bLightRotate = true;
- CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,BST_CHECKED);
- }
- // NoSpecular
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoSpecular",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bNoSpecular = false;
- CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bNoSpecular = true;
- CheckDlgButton(g_hDlg,IDC_NOSPECULAR,BST_CHECKED);
- }
- // LowQuality
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"LowQuality",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bLowQuality = false;
- CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bLowQuality = true;
- CheckDlgButton(g_hDlg,IDC_LOWQUALITY,BST_CHECKED);
- }
- // DisplayNormals
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderNormals",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bRenderNormals = false;
- CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bRenderNormals = true;
- CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,BST_CHECKED);
- }
- // NoMaterials
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"RenderMats",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 1;
- if (0 == dwValue)
- {
- g_sOptions.bRenderMats = false;
- CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_CHECKED);
- }
- else
- {
- g_sOptions.bRenderMats = true;
- CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,BST_UNCHECKED);
- }
- // MultiSampling
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"MultiSampling",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 1;
- if (0 == dwValue)
- {
- g_sOptions.bMultiSample = false;
- CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bMultiSample = true;
- CheckDlgButton(g_hDlg,IDC_TOGGLEMS,BST_CHECKED);
- }
- // FPS Mode
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"FPSView",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_bFPSView = false;
- CheckDlgButton(g_hDlg,IDC_ZOOM,BST_CHECKED);
- }
- else
- {
- g_bFPSView = true;
- CheckDlgButton(g_hDlg,IDC_ZOOM,BST_UNCHECKED);
- }
- // WireFrame
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"Wireframe",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.eDrawMode = RenderOptions::NORMAL;
- CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.eDrawMode = RenderOptions::WIREFRAME;
- CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,BST_CHECKED);
- }
- LoadCheckerPatternColors();
- return;
- }
- //-------------------------------------------------------------------------------
- // Main message procedure of the application
- //
- // The function handles all incoming messages for the main window.
- // However, if does not directly process input commands.
- // NOTE: Due to the impossibility to process WM_CHAR messages in dialogs
- // properly the code for all hotkeys has been moved to the WndMain
- //-------------------------------------------------------------------------------
- INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
- WPARAM wParam,LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- UNREFERENCED_PARAMETER(wParam);
- int xPos,yPos;
- int xPos2,yPos2;
- int fHalfX;
- int fHalfY;
- TRACKMOUSEEVENT sEvent;
- switch (uMsg)
- {
- case WM_INITDIALOG:
- g_hDlg = hwndDlg;
- // load the state of the usr interface
- InitUI();
- // load the file history
- LoadHistory();
- // load the current color of the lights
- LoadLightColors();
- return TRUE;
- case WM_MOUSEWHEEL:
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode())
- {
- CDisplay::Instance().SetTextureViewZoom ( GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f );
- }
- else
- {
- if (!g_bFPSView)
- {
- g_sCamera.vPos.z += GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f;
- }
- else
- {
- g_sCamera.vPos += (GET_WHEEL_DELTA_WPARAM(wParam) / 50.0f) *
- g_sCamera.vLookAt.Normalize();
- }
- }
- return TRUE;
- case WM_MOUSELEAVE:
- g_bMousePressed = false;
- g_bMousePressedR = false;
- g_bMousePressedM = false;
- g_bMousePressedBoth = false;
- return TRUE;
- case WM_LBUTTONDBLCLK:
- CheckDlgButton(hwndDlg,IDC_AUTOROTATE,
- IsDlgButtonChecked(hwndDlg,IDC_AUTOROTATE) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleAutoRotate();
- return TRUE;
- case WM_CLOSE:
- PostQuitMessage(0);
- DestroyWindow(hwndDlg);
- return TRUE;
- case WM_NOTIFY:
- if (IDC_TREE1 == wParam)
- {
- NMTREEVIEW* pnmtv = (LPNMTREEVIEW) lParam;
- if (TVN_SELCHANGED == pnmtv->hdr.code)
- CDisplay::Instance().OnSetup( pnmtv->itemNew.hItem );
- else if (NM_RCLICK == pnmtv->hdr.code)
- {
- // determine in which item the click was ...
- POINT sPoint;
- GetCursorPos(&sPoint);
- ScreenToClient(GetDlgItem(g_hDlg,IDC_TREE1),&sPoint);
- TVHITTESTINFO sHit;
- sHit.pt = sPoint;
- TreeView_HitTest(GetDlgItem(g_hDlg,IDC_TREE1),&sHit);
- CDisplay::Instance().ShowTreeViewContextMenu(sHit.hItem);
- }
- }
- return TRUE;
- case WM_DRAWITEM:
- {
- // draw the two light colors
- DRAWITEMSTRUCT* pcStruct = (DRAWITEMSTRUCT*)lParam;
- RECT sRect;
- GetWindowRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),&sRect);
- sRect.right -= sRect.left;
- sRect.bottom -= sRect.top;
- sRect.left = sRect.top = 0;
- bool bDraw = false;
- if(IDC_LCOLOR1 == pcStruct->CtlID)
- {
- unsigned char r,g,b;
- const char* szText;
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- r = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->x * 255.0f);
- g = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->y * 255.0f);
- b = (unsigned char)(CDisplay::Instance().GetFirstCheckerColor()->z * 255.0f);
- szText = "B0";
- }
- else if (!g_pcAsset)
- {
- r = g = b = 150;szText = "-";
- }
- else
- {
- r = (unsigned char)((g_avLightColors[0] >> 16) & 0xFF);
- g = (unsigned char)((g_avLightColors[0] >> 8) & 0xFF);
- b = (unsigned char)((g_avLightColors[0]) & 0xFF);
- szText = "L0";
- }
- HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
- FillRect(pcStruct->hDC,&sRect,hbr);
-
- SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
- SetBkMode(pcStruct->hDC,TRANSPARENT);
- TextOut(pcStruct->hDC,4,1,szText,2);
- bDraw = true;
- }
- else if(IDC_LCOLOR2 == pcStruct->CtlID)
- {
- unsigned char r,g,b;
- const char* szText;
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- r = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->x * 255.0f);
- g = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->y * 255.0f);
- b = (unsigned char)(CDisplay::Instance().GetSecondCheckerColor()->z * 255.0f);
- szText = "B1";
- }
- else if (!g_pcAsset)
- {
- r = g = b = 150;szText = "-";
- }
- else
- {
- r = (unsigned char)((g_avLightColors[1] >> 16) & 0xFF);
- g = (unsigned char)((g_avLightColors[1] >> 8) & 0xFF);
- b = (unsigned char)((g_avLightColors[1]) & 0xFF);
- szText = "L1";
- }
- HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
- FillRect(pcStruct->hDC,&sRect,hbr);
- SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
- SetBkMode(pcStruct->hDC,TRANSPARENT);
- TextOut(pcStruct->hDC,4,1,szText,2);
- bDraw = true;
- }
- else if(IDC_LCOLOR3 == pcStruct->CtlID)
- {
- unsigned char r,g,b;
- const char* szText;
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- r = g = b = 0;
- szText = "-";
- }
- else if (!g_pcAsset)
- {
- r = g = b = 150;szText = "-";
- }
- else
- {
- r = (unsigned char)((g_avLightColors[2] >> 16) & 0xFF);
- g = (unsigned char)((g_avLightColors[2] >> 8) & 0xFF);
- b = (unsigned char)((g_avLightColors[2]) & 0xFF);
- szText = "A0";
- }
- HBRUSH hbr = CreateSolidBrush(RGB(r,g,b));
- FillRect(pcStruct->hDC,&sRect,hbr);
-
- SetTextColor(pcStruct->hDC,RGB(0xFF-r,0xFF-g,0xFF-b));
- SetBkMode(pcStruct->hDC,TRANSPARENT);
- TextOut(pcStruct->hDC,4,1,szText,2);
- bDraw = true;
- }
- // draw the black border around the rects
- if (bDraw)
- {
- SetBkColor(pcStruct->hDC,RGB(0,0,0));
- MoveToEx(pcStruct->hDC,0,0,NULL);
- LineTo(pcStruct->hDC,sRect.right-1,0);
- LineTo(pcStruct->hDC,sRect.right-1,sRect.bottom-1);
- LineTo(pcStruct->hDC,0,sRect.bottom-1);
- LineTo(pcStruct->hDC,0,0);
- }
- }
- return TRUE;
- case WM_DESTROY:
- // close the open registry key
- RegCloseKey(g_hRegistry);
- return TRUE;
- case WM_LBUTTONDOWN:
- g_bMousePressed = true;
- // register a mouse track handler to be sure we'll know
- // when the mouse leaves the display view again
- sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
- sEvent.dwFlags = TME_LEAVE;
- sEvent.hwndTrack = g_hDlg;
- sEvent.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&sEvent);
- if (g_bMousePressedR)
- {
- g_bMousePressed = false;
- g_bMousePressedR = false;
- g_bMousePressedBoth = true;
- return TRUE;
- }
- // need to determine the position of the mouse and the
- // distance from the center
- //xPos = (int)(short)LOWORD(lParam);
- //yPos = (int)(short)HIWORD(lParam);
- POINT sPoint;
- GetCursorPos(&sPoint);
- ScreenToClient(GetDlgItem(g_hDlg,IDC_RT),&sPoint);
- xPos = xPos2 = sPoint.x;
- yPos = yPos2 = sPoint.y;
- /* xPos -= 10;
- yPos -= 10;
- xPos2 = xPos-3;
- yPos2 = yPos-5;*/
- RECT sRect;
- GetWindowRect(GetDlgItem(g_hDlg,IDC_RT),&sRect);
- sRect.right -= sRect.left;
- sRect.bottom -= sRect.top;
- // if the mouse klick was inside the viewer panel
- // give the focus to it
- if (xPos > 0 && xPos < sRect.right && yPos > 0 && yPos < sRect.bottom)
- {
- SetFocus(GetDlgItem(g_hDlg,IDC_RT));
- }
- // g_bInvert stores whether the mouse has started on the negative
- // x or on the positive x axis of the imaginary coordinate system
- // with origin p at the center of the HUD texture
- xPos -= sRect.right/2;
- yPos -= sRect.bottom/2;
- if (xPos > 0)g_bInvert = true;
- else g_bInvert = false;
- D3DSURFACE_DESC sDesc;
- g_pcTexture->GetLevelDesc(0,&sDesc);
-
- fHalfX = (int)(((float)sRect.right-(float)sDesc.Width) / 2.0f);
- fHalfY = (int)(((float)sRect.bottom-(float)sDesc.Height) / 2.0f);
- // Determine the input operation to perform for this position
- g_eClick = EClickPos_Outside;
- if (xPos2 >= fHalfX && xPos2 < fHalfX + (int)sDesc.Width &&
- yPos2 >= fHalfY && yPos2 < fHalfY + (int)sDesc.Height &&
- NULL != g_szImageMask)
- {
- // inside the texture. Lookup the grayscale value from it
- xPos2 -= fHalfX;
- yPos2 -= fHalfY;
- unsigned char chValue = g_szImageMask[xPos2 + yPos2 * sDesc.Width];
- if (chValue > 0xFF-20)
- {
- g_eClick = EClickPos_Circle;
- }
- else if (chValue < 0xFF-20 && chValue > 185)
- {
- g_eClick = EClickPos_CircleHor;
- }
- else if (chValue > 0x10 && chValue < 185)
- {
- g_eClick = EClickPos_CircleVert;
- }
- }
- return TRUE;
- case WM_RBUTTONDOWN:
- g_bMousePressedR = true;
- sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
- sEvent.dwFlags = TME_LEAVE;
- sEvent.hwndTrack = g_hDlg;
- sEvent.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&sEvent);
- if (g_bMousePressed)
- {
- g_bMousePressedR = false;
- g_bMousePressed = false;
- g_bMousePressedBoth = true;
- }
- return TRUE;
- case WM_MBUTTONDOWN:
-
- g_bMousePressedM = true;
- sEvent.cbSize = sizeof(TRACKMOUSEEVENT);
- sEvent.dwFlags = TME_LEAVE;
- sEvent.hwndTrack = g_hDlg;
- sEvent.dwHoverTime = HOVER_DEFAULT;
- TrackMouseEvent(&sEvent);
- return TRUE;
- case WM_LBUTTONUP:
- g_bMousePressed = false;
- g_bMousePressedBoth = false;
- return TRUE;
- case WM_RBUTTONUP:
- g_bMousePressedR = false;
- g_bMousePressedBoth = false;
- return TRUE;
- case WM_MBUTTONUP:
- g_bMousePressedM = false;
- return TRUE;
- case WM_DROPFILES:
- {
- HDROP hDrop = (HDROP)wParam;
- char szFile[MAX_PATH];
- DragQueryFile(hDrop,0,szFile,sizeof(szFile));
- const char* sz = strrchr(szFile,'.');
- if (sz && 0 != aiIsExtensionSupported(sz))
- {
- strcpy(g_szFileName,szFile);
- DeleteAsset();
- LoadAsset();
- UpdateHistory();
- SaveHistory();
- }
- else if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode())
- {
- // replace the selected texture with the new one ...
- CDisplay::Instance().ReplaceCurrentTexture(szFile);
- }
- else
- {
- if (!sz) goto __DRUNKEN_ALIEN_FROM_MARS;
- // check whether it is a typical texture file format ...
- ++sz;
- if (0 == Assimp::ASSIMP_stricmp(sz,"png") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"bmp") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"jpg") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"tga") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"tif") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"hdr") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"ppm") ||
- 0 == Assimp::ASSIMP_stricmp(sz,"pfm"))
- {
- CBackgroundPainter::Instance().SetTextureBG(szFile);
- }
- else if (0 == Assimp::ASSIMP_stricmp(sz,"dds"))
- {
- // DDS files could contain skyboxes, but they could also
- // contain normal 2D textures. The easiest way to find this
- // out is to open the file and check the header ...
- FILE* pFile = fopen(szFile,"rb");
- if (!pFile)goto __DRUNKEN_ALIEN_FROM_MARS;
- // header of a dds file (begin)
- /*
- DWORD dwMagic
- DWORD dwSize
- DWORD dwFlags
- DWORD dwHeight
- DWORD dwWidth
- DWORD dwPitchOrLinearSize
- DWORD dwDepth
- DWORD dwMipMapCount -> total with this: 32
- DWORD dwReserved1[11] -> total with this: 76
- DDPIXELFORMAT ddpfPixelFormat -> total with this: 108
- DWORD dwCaps1; -> total with this: 112
- DWORD dwCaps2; ---< here we are!
- */
- DWORD dwCaps = 0;
- fseek(pFile,112,SEEK_SET);
- fread(&dwCaps,4,1,pFile);
- if (dwCaps & 0x00000400L /* DDSCAPS2_CUBEMAP_POSITIVEX */)
- {
- CLogDisplay::Instance().AddEntry(
- "[INFO] Assuming this dds file is a skybox ...",
- D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
- CBackgroundPainter::Instance().SetCubeMapBG(szFile);
- }
- else CBackgroundPainter::Instance().SetTextureBG(szFile);
- fclose(pFile);
- }
- else
- {
- __DRUNKEN_ALIEN_FROM_MARS:
- CLogDisplay::Instance().AddEntry(
- "[ERROR] File extension is not supported. E.T. can read this.",
- D3DCOLOR_ARGB(0xFF,0xFF,0,0));
- }
- }
- DragFinish(hDrop);
- }
- return TRUE;
- case WM_COMMAND:
- if (ID_VIEWER_QUIT == LOWORD(wParam))
- {
- PostQuitMessage(0);
- DestroyWindow(hwndDlg);
- }
- else if (ID_VIEWER_RESETVIEW == LOWORD(wParam))
- {
- g_sCamera.vPos = aiVector3D(0.0f,0.0f,-10.0f);
- g_sCamera.vLookAt = aiVector3D(0.0f,0.0f,1.0f);
- g_sCamera.vUp = aiVector3D(0.0f,1.0f,0.0f);
- g_sCamera.vRight = aiVector3D(0.0f,1.0f,0.0f);
- g_mWorldRotate = aiMatrix4x4();
- g_mWorld = aiMatrix4x4();
- // don't forget to reset the st
- CBackgroundPainter::Instance().ResetSB();
- }
- else if (ID__HELP == LOWORD(wParam))
- {
- DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_AVHELP),
- hwndDlg,&HelpDialogProc);
- }
- else if (ID__ABOUT == LOWORD(wParam))
- {
- DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_ABOUTBOX),
- hwndDlg,&AboutMessageProc);
- }
- else if (ID_TOOLS_LOGWINDOW == LOWORD(wParam))
- {
- CLogWindow::Instance().Show();
- }
- else if (ID_TOOLS_CLEARLOG == LOWORD(wParam))
- {
- CLogWindow::Instance().Clear();
- }
- else if (ID_TOOLS_SAVELOGTOFILE == LOWORD(wParam))
- {
- CLogWindow::Instance().Save();
- }
- else if (ID_VIEWER_MEMORYCONSUMATION == LOWORD(wParam))
- {
- DisplayMemoryConsumption();
- }
- else if (ID_VIEWER_H == LOWORD(wParam))
- {
- MakeFileAssociations();
- }
- else if (ID_BACKGROUND_CLEAR == LOWORD(wParam))
- {
- ClearBG();
- }
- else if (ID_BACKGROUND_SETCOLOR == LOWORD(wParam))
- {
- ChooseBGColor();
- }
- else if (ID_BACKGROUND_LOADTEXTURE == LOWORD(wParam))
- {
- LoadBGTexture();
- }
- else if (ID_BACKGROUND_LOADSKYBOX == LOWORD(wParam))
- {
- LoadSkybox();
- }
- else if (ID_VIEWER_SAVESCREENSHOTTOFILE == LOWORD(wParam))
- {
- SaveScreenshot();
- }
- else if (ID_VIEWER_OPEN == LOWORD(wParam))
- {
- OpenAsset();
- }
- else if (ID_TOOLS_FLIPNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->FlipNormals();
- }
- }
- else if (ID_TOOLS_ORIGINALNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::ORIGINAL);
- HMENU hMenu = GetMenu(g_hDlg);
- ModifyMenu(hMenu,ID_TOOLS_ORIGINALNORMALS,
- MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_ORIGINALNORMALS,"Original normals");
- ModifyMenu(hMenu,ID_TOOLS_HARDNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_HARDNORMALS,"Hard normals");
- ModifyMenu(hMenu,ID_TOOLS_SMOOTHNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_SMOOTHNORMALS,"Smooth normals");
- }
- }
- else if (ID_TOOLS_SMOOTHNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::SMOOTH);
- HMENU hMenu = GetMenu(g_hDlg);
- ModifyMenu(hMenu,ID_TOOLS_SMOOTHNORMALS,
- MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_SMOOTHNORMALS,"Smooth normals");
- ModifyMenu(hMenu,ID_TOOLS_HARDNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_HARDNORMALS,"Hard normals");
- ModifyMenu(hMenu,ID_TOOLS_ORIGINALNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_ORIGINALNORMALS,"Original normals");
- }
- }
- else if (ID_TOOLS_HARDNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::HARD);
- HMENU hMenu = GetMenu(g_hDlg);
- ModifyMenu(hMenu,ID_TOOLS_HARDNORMALS,
- MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_HARDNORMALS,"Hard normals");
- ModifyMenu(hMenu,ID_TOOLS_ORIGINALNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_ORIGINALNORMALS,"Original normals");
- ModifyMenu(hMenu,ID_TOOLS_SMOOTHNORMALS,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_SMOOTHNORMALS,"Smooth normals");
- }
- }
- else if (ID_TOOLS_STEREOVIEW == LOWORD(wParam))
- {
- g_sOptions.bStereoView =! g_sOptions.bStereoView;
- HMENU hMenu = GetMenu(g_hDlg);
- if (g_sOptions.bStereoView)
- {
- ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW,
- MF_BYCOMMAND | MF_CHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view");
- CLogDisplay::Instance().AddEntry("[INFO] Switched to stereo mode",
- D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
- }
- else
- {
- ModifyMenu(hMenu,ID_TOOLS_STEREOVIEW,
- MF_BYCOMMAND | MF_UNCHECKED | MF_STRING,ID_TOOLS_STEREOVIEW,"Stereo view");
- CLogDisplay::Instance().AddEntry("[INFO] Switched to mono mode",
- D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0));
- }
- }
- else if (ID_VIEWER_CLEARHISTORY == LOWORD(wParam))
- {
- ClearHistory();
- }
- else if (ID_VIEWER_CLOSEASSET == LOWORD(wParam))
- {
- DeleteAssetData();
- DeleteAsset();
- }
- else if (BN_CLICKED == HIWORD(wParam))
- {
- if (IDC_TOGGLEMS == LOWORD(wParam))
- {
- ToggleMS();
- }
- else if (IDC_TOGGLEMAT == LOWORD(wParam))
- {
- ToggleMats();
- }
- else if (IDC_LCOLOR1 == LOWORD(wParam))
- {
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- // hey, I'm tired and yes, I KNOW IT IS EVIL!
- DisplayColorDialog(const_cast<D3DXVECTOR4*>(CDisplay::Instance().GetFirstCheckerColor()));
- SaveCheckerPatternColors();
- }
- else
- {
- DisplayColorDialog(&g_avLightColors[0]);
- SaveLightColors();
- }
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR1));
- }
- else if (IDC_LCOLOR2 == LOWORD(wParam))
- {
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- // hey, I'm tired and yes, I KNOW IT IS EVIL!
- DisplayColorDialog(const_cast<D3DXVECTOR4*>(CDisplay::Instance().GetSecondCheckerColor()));
- SaveCheckerPatternColors();
- }
- else
- {
- DisplayColorDialog(&g_avLightColors[1]);
- SaveLightColors();
- }
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR2),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR2));
- }
- else if (IDC_LCOLOR3 == LOWORD(wParam))
- {
- DisplayColorDialog(&g_avLightColors[2]);
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR3),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR3));
- SaveLightColors();
- }
- else if (IDC_LRESET == LOWORD(wParam))
- {
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode() ||
- CDisplay::VIEWMODE_MATERIAL == CDisplay::Instance().GetViewMode())
- {
- CDisplay::Instance().SetFirstCheckerColor(D3DXVECTOR4(0.4f,0.4f,0.4f,1.0f));
- CDisplay::Instance().SetSecondCheckerColor(D3DXVECTOR4(0.6f,0.6f,0.6f,1.0f));
- SaveCheckerPatternColors();
- }
- else
- {
- g_avLightColors[0] = D3DCOLOR_ARGB(0xFF,0xFF,0xFF,0xFF);
- g_avLightColors[1] = D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00);
- g_avLightColors[2] = D3DCOLOR_ARGB(0xFF,0x05,0x05,0x05);
- SaveLightColors();
- }
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR1),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR1));
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR2),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR2));
- InvalidateRect(GetDlgItem(g_hDlg,IDC_LCOLOR3),NULL,TRUE);
- UpdateWindow(GetDlgItem(g_hDlg,IDC_LCOLOR3));
- }
- else if (IDC_NOSPECULAR == LOWORD(wParam))
- {
- ToggleSpecular();
- }
- else if (IDC_ZOOM == LOWORD(wParam))
- {
- ToggleFPSView();
- }
- else if (IDC_BLUBB == LOWORD(wParam))
- {
- ToggleUIState();
- }
- else if (IDC_TOGGLENORMALS == LOWORD(wParam))
- {
- ToggleNormals();
- }
- else if (IDC_LOWQUALITY == LOWORD(wParam))
- {
- ToggleLowQuality();
- }
- else if (IDC_3LIGHTS == LOWORD(wParam))
- {
- ToggleMultipleLights();
- }
- else if (IDC_LIGHTROTATE == LOWORD(wParam))
- {
- ToggleLightRotate();
- }
- else if (IDC_AUTOROTATE == LOWORD(wParam))
- {
- ToggleAutoRotate();
- }
- else if (IDC_TOGGLEWIRE == LOWORD(wParam))
- {
- ToggleWireFrame();
- }
- }
- // check the file history
- for (unsigned int i = 0; i < AI_VIEW_NUM_RECENT_FILES;++i)
- {
- if (AI_VIEW_RECENT_FILE_ID(i) == LOWORD(wParam))
- {
- strcpy(g_szFileName,g_aPreviousFiles[i].c_str());
- DeleteAssetData();
- DeleteAsset();
- LoadAsset();
- // update and safe the history
- UpdateHistory();
- SaveHistory();
- }
- }
- // handle popup menus for the tree window
- CDisplay::Instance().HandleTreeViewPopup(wParam,lParam);
- return TRUE;
- };
- return FALSE;
- }
- //-------------------------------------------------------------------------------
- // Message prcoedure for the progress dialog
- //-------------------------------------------------------------------------------
- INT_PTR CALLBACK ProgressMessageProc(HWND hwndDlg,UINT uMsg,
- WPARAM wParam,LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (uMsg)
- {
- case WM_INITDIALOG:
- SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_SETRANGE,0,
- MAKELPARAM(0,500));
- SetTimer(hwndDlg,0,40,NULL);
- return TRUE;
- case WM_CLOSE:
- EndDialog(hwndDlg,0);
- return TRUE;
- case WM_COMMAND:
- if (IDOK == LOWORD(wParam))
- {
- #if 0
- g_bLoadingCanceled = true;
- TerminateThread(g_hThreadHandle,5);
- g_pcAsset = NULL;
- EndDialog(hwndDlg,0);
- #endif
- // PROBLEM: If we terminate the loader thread, ASSIMP's state
- // is undefined. Any further attempts to load assets will
- // fail.
- exit(5);
- // return TRUE;
- }
- case WM_TIMER:
- UINT iPos = (UINT)SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_GETPOS,0,0);
- iPos += 10;
- if (iPos > 490)iPos = 0;
- SendDlgItemMessage(hwndDlg,IDC_PROGRESS,PBM_SETPOS,iPos,0);
- if (g_bLoadingFinished)
- {
- EndDialog(hwndDlg,0);
- return TRUE;
- }
- return TRUE;
- }
- return FALSE;
- }
- //-------------------------------------------------------------------------------
- // Message procedure for the about dialog
- //-------------------------------------------------------------------------------
- INT_PTR CALLBACK AboutMessageProc(HWND hwndDlg,UINT uMsg,
- WPARAM wParam,LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (uMsg)
- {
- case WM_CLOSE:
- EndDialog(hwndDlg,0);
- return TRUE;
- case WM_COMMAND:
- if (IDOK == LOWORD(wParam))
- {
- EndDialog(hwndDlg,0);
- return TRUE;
- }
- }
- return FALSE;
- }
- };
- using namespace AssimpView;
- //-------------------------------------------------------------------------------
- // Entry point to the application
- //-------------------------------------------------------------------------------
- int APIENTRY _tWinMain(HINSTANCE hInstance,
- HINSTANCE hPrevInstance,
- LPTSTR lpCmdLine,
- int nCmdShow)
- {
- UNREFERENCED_PARAMETER(hPrevInstance);
- UNREFERENCED_PARAMETER(lpCmdLine);
- // needed for the RichEdit control in the about/help dialog
- LoadLibrary( "riched20.dll" );
- // load windows common controls library to get XP style
- InitCommonControls();
- // intiailize the IDirect3D9 interface
- g_hInstance = hInstance;
- if (0 == InitD3D())
- {
- MessageBox(NULL,"Failed to initialize Direct3D 9",
- "ASSIMP ModelViewer",MB_OK);
- return -6;
- }
- // create the main dialog
- HWND hDlg = CreateDialog(hInstance,MAKEINTRESOURCE(IDD_DIALOGMAIN),
- NULL,&MessageProc);
- // initialise the default logger if neccessary
- Assimp::DefaultLogger::create("",Assimp::Logger::VERBOSE);
- Assimp::DefaultLogger::get()->attachStream((Assimp::LogStream*)&CLogWindow::Instance().pcStream,
- Assimp::DefaultLogger::DEBUGGING | Assimp::DefaultLogger::INFO |
- Assimp::DefaultLogger::ERR | Assimp::DefaultLogger::WARN);
- if (NULL == hDlg)
- {
- MessageBox(NULL,"Failed to create dialog from resource",
- "ASSIMP ModelViewer",MB_OK);
- return -5;
- }
- // display the window
- g_hDlg = hDlg;
- MSG uMsg;
- memset(&uMsg,0,sizeof( MSG));
- ShowWindow( hDlg, nCmdShow );
- UpdateWindow( hDlg );
- // create the D3D device object
- if (0 == CreateDevice(g_sOptions.bMultiSample,false,true))
- {
- MessageBox(NULL,"Failed to initialize Direct3D 9 (2)",
- "ASSIMP ModelViewer",MB_OK);
- return -4;
- }
- // setup ASSIMP standard limits for the SplitLargeMeshes-process
- aiSetTriangleSplitLimit(g_sCaps.MaxPrimitiveCount-1);
- aiSetVertexSplitLimit(0xFFFFFFFF);
- CLogDisplay::Instance().AddEntry("[OK] The viewer has been initialized successfully");
- // create the log window
- CLogWindow::Instance().Init();
- // set the focus to the main window
- SetFocus(g_hDlg);
- // recover background skyboxes/textures from the last session
- HKEY g_hRegistry;
- union
- {
- char szFileName[MAX_PATH];
- D3DCOLOR clrColor;
- };
- DWORD dwTemp = MAX_PATH;
- RegCreateKeyEx(HKEY_CURRENT_USER,
- "Software\\ASSIMP\\Viewer",NULL,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastSkyBoxSrc",NULL,NULL,
- (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0])
- {
- CBackgroundPainter::Instance().SetCubeMapBG(szFileName);
- }
- else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"LastTextureSrc",NULL,NULL,
- (BYTE*)szFileName,&dwTemp) && '\0' != szFileName[0])
- {
- CBackgroundPainter::Instance().SetTextureBG(szFileName);
- }
- else if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"Color",NULL,NULL,
- (BYTE*)&clrColor,&dwTemp))
- {
- CBackgroundPainter::Instance().SetColor(clrColor);
- }
- RegCloseKey(g_hRegistry);
- // now handle command line arguments
- HandleCommandLine(lpCmdLine);
- double adLast[30];
- for (int i = 0; i < 30;++i)adLast[i] = 0.0f;
- int iCurrent = 0;
- double g_dCurTime = 0;
- double g_dLastTime = 0;
- while( uMsg.message != WM_QUIT )
- {
- if( PeekMessage( &uMsg, NULL, 0, 0, PM_REMOVE ) )
- {
- TranslateMessage( &uMsg );
- DispatchMessage( &uMsg );
- if (WM_CHAR == uMsg.message)
- {
- switch ((char)uMsg.wParam)
- {
- case 'M':
- case 'm':
- CheckDlgButton(g_hDlg,IDC_TOGGLEMS,
- IsDlgButtonChecked(g_hDlg,IDC_TOGGLEMS) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleMS();
- break;
- case 'L':
- case 'l':
- CheckDlgButton(g_hDlg,IDC_3LIGHTS,
- IsDlgButtonChecked(g_hDlg,IDC_3LIGHTS) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleMultipleLights();
- break;
- case 'P':
- case 'p':
- CheckDlgButton(g_hDlg,IDC_LOWQUALITY,
- IsDlgButtonChecked(g_hDlg,IDC_LOWQUALITY) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleLowQuality();
- break;
- case 'D':
- case 'd':
- CheckDlgButton(g_hDlg,IDC_TOGGLEMAT,
- IsDlgButtonChecked(g_hDlg,IDC_TOGGLEMAT) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleMats();
- break;
- case 'N':
- case 'n':
- CheckDlgButton(g_hDlg,IDC_TOGGLENORMALS,
- IsDlgButtonChecked(g_hDlg,IDC_TOGGLENORMALS) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleNormals();
- break;
- case 'S':
- case 's':
- CheckDlgButton(g_hDlg,IDC_NOSPECULAR,
- IsDlgButtonChecked(g_hDlg,IDC_NOSPECULAR) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleSpecular();
- break;
- case 'A':
- case 'a':
- CheckDlgButton(g_hDlg,IDC_AUTOROTATE,
- IsDlgButtonChecked(g_hDlg,IDC_AUTOROTATE) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleAutoRotate();
- break;
- case 'R':
- case 'r':
- CheckDlgButton(g_hDlg,IDC_LIGHTROTATE,
- IsDlgButtonChecked(g_hDlg,IDC_LIGHTROTATE) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleLightRotate();
- break;
- case 'Z':
- case 'z':
- CheckDlgButton(g_hDlg,IDC_ZOOM,
- IsDlgButtonChecked(g_hDlg,IDC_ZOOM) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleFPSView();
- break;
- case 'W':
- case 'w':
- CheckDlgButton(g_hDlg,IDC_TOGGLEWIRE,
- IsDlgButtonChecked(g_hDlg,IDC_TOGGLEWIRE) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleWireFrame();
- break;
- }
- }
- }
- // render the scene
- CDisplay::Instance().OnRender();
- g_dCurTime = timeGetTime();
- g_fElpasedTime = (float)((g_dCurTime - g_dLastTime) * 0.001);
- g_dLastTime = g_dCurTime;
- adLast[iCurrent++] = 1.0f / g_fElpasedTime;
- double dFPS = 0.0;
- for (int i = 0;i < 30;++i)
- dFPS += adLast[i];
- dFPS /= 30.0;
- if (30 == iCurrent)
- {
- iCurrent = 0;
- if (dFPS != g_fFPS)
- {
- g_fFPS = dFPS;
- char szOut[256];
- sprintf(szOut,"%i",(int)floorf((float)dFPS+0.5f));
- SetDlgItemText(g_hDlg,IDC_EFPS,szOut);
- }
- }
- }
- DeleteAsset();
- Assimp::DefaultLogger::kill();
- ShutdownDevice();
- ShutdownD3D();
- return 0;
- }
|