| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654 |
- /*
- ---------------------------------------------------------------------------
- Open Asset Import Library (assimp)
- ---------------------------------------------------------------------------
- Copyright (c) 2006-2015, assimp 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 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 "assimp_view.h"
- #include <assimp/Exporter.hpp>
- #include <algorithm>
- #include <windowsx.h>
- #include <commdlg.h>
- #include <timeapi.h>
- namespace AssimpView {
- using namespace Assimp;
- // 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;
- float g_fACMR = 3.0f;
- #define AI_VIEW_NUM_RECENT_FILES 0x8
- #define AI_VIEW_RECENT_FILE_ID(_n_) (5678 + _n_)
- #define AI_VIEW_EXPORT_FMT_BASE 7912
- #define AI_VIEW_EXPORT_FMT_ID(_n_) (AI_VIEW_EXPORT_FMT_BASE + _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;
- aiString list, tmp;
- aiGetExtensionList(&list);
- tmp = list;
- const char* sz = strtok(list.data,";");
- do
- {
- char buf[256];
- ai_assert(sz[0] == '*');
- sprintf(buf,"Software\\Classes\\%s",sz+1);
- RegCreateKeyEx(HKEY_CURRENT_USER,buf,0,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);
- }
- while ((sz = strtok(NULL,";")));
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS",0,NULL,0,KEY_ALL_ACCESS, NULL, &g_hRegistry,NULL);
- RegCloseKey(g_hRegistry);
- RegCreateKeyEx(HKEY_CURRENT_USER,"Software\\Classes\\ASSIMPVIEW_CLASS\\shell\\open\\command",0,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));
- CLogDisplay::Instance().AddEntry(tmp.data,D3DCOLOR_ARGB(0xFF,0,0xFF,0));
- }
- //-------------------------------------------------------------------------------
- // 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;
- sz++; // skip the starting quote
- }
- 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);
- }
- //-------------------------------------------------------------------------------
- // Changed pp setup
- //-------------------------------------------------------------------------------
- void UpdatePPSettings()
- {
- DWORD dwValue = ppsteps;
- RegSetValueExA(g_hRegistry,"PostProcessing",0,REG_DWORD,(const BYTE*)&dwValue,4);
- UpdateWindow(g_hDlg);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "NoTransparency" state
- //-------------------------------------------------------------------------------
- void ToggleTransparency()
- {
- g_sOptions.bNoAlphaBlending = !g_sOptions.bNoAlphaBlending;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bNoAlphaBlending)dwValue = 1;
- RegSetValueExA(g_hRegistry,"NoTransparency",0,REG_DWORD,(const BYTE*)&dwValue,4);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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();
- }
- //-------------------------------------------------------------------------------
- // 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();
- }
- //-------------------------------------------------------------------------------
- // Toggle the "Culling" state
- //-------------------------------------------------------------------------------
- void ToggleCulling()
- {
- g_sOptions.bCulling = !g_sOptions.bCulling;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bCulling)dwValue = 1;
- RegSetValueExA(g_hRegistry,"Culling",0,REG_DWORD,(const BYTE*)&dwValue,4);
- }
- //-------------------------------------------------------------------------------
- // Toggle the "Skeleton" state
- //-------------------------------------------------------------------------------
- void ToggleSkeleton()
- {
- g_sOptions.bSkeleton = !g_sOptions.bSkeleton;
- // store this in the registry, too
- DWORD dwValue = 0;
- if (g_sOptions.bCulling)dwValue = 1;
- RegSetValueExA(g_hRegistry,"Skeleton",0,REG_DWORD,(const BYTE*)&dwValue,4);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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);
- }
- //-------------------------------------------------------------------------------
- // 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-214,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+214,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 = 0;
- 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 = 0;
- 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 KiB = 1024 bytes)\n\n"
- "ASSIMP Import Data: \t%i KiB\n"
- "Texture data:\t\t%i KiB\n"
- "Vertex buffers:\t\t%i KiB\n"
- "Index buffers:\t\t%i KiB\n"
- "Video Memory:\t\t%i KiB\n\n"
- "Total: \t\t\t%i KiB",
- 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;
- }
- //-------------------------------------------------------------------------------
- void SetupPPUIState()
- {
- // that's ugly. anyone willing to rewrite me from scratch?
- HMENU hMenu = GetMenu(g_hDlg);
- CheckMenuItem(hMenu,ID_VIEWER_PP_JIV,ppsteps & aiProcess_JoinIdenticalVertices ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_CTS,ppsteps & aiProcess_CalcTangentSpace ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_FD,ppsteps & aiProcess_FindDegenerates ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_FID,ppsteps & aiProcess_FindInvalidData ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_FIM,ppsteps & aiProcess_FindInstances ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_FIN,ppsteps & aiProcess_FixInfacingNormals ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_GUV,ppsteps & aiProcess_GenUVCoords ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_ICL,ppsteps & aiProcess_ImproveCacheLocality ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_OG,ppsteps & aiProcess_OptimizeGraph ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_OM,ppsteps & aiProcess_OptimizeMeshes ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_PTV,ppsteps & aiProcess_PreTransformVertices ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_RRM2,ppsteps & aiProcess_RemoveRedundantMaterials ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_TUV,ppsteps & aiProcess_TransformUVCoords ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_VDS,ppsteps & aiProcess_ValidateDataStructure ? MF_CHECKED : MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_VIEWER_PP_DB,ppsteps & aiProcess_Debone ? MF_CHECKED : MF_UNCHECKED);
- }
- #ifndef ASSIMP_BUILD_NO_EXPORT
- //-------------------------------------------------------------------------------
- // Fill the 'export' top level menu with a list of all supported export formats
- //-------------------------------------------------------------------------------
- void PopulateExportMenu()
- {
- // add sub items for all recent files
- Exporter exp;
- HMENU hm = ::CreateMenu();
- for(size_t i = 0; i < exp.GetExportFormatCount(); ++i)
- {
- const aiExportFormatDesc* const e = exp.GetExportFormatDescription(i);
- char tmp[256];
- sprintf(tmp,"%s (%s)",e->description,e->id);
- AppendMenu(hm,MF_STRING,AI_VIEW_EXPORT_FMT_ID(i),tmp);
- }
- ModifyMenu(GetMenu(g_hDlg),ID_EXPORT,MF_BYCOMMAND | MF_POPUP,
- (UINT_PTR)hm,"Export");
- }
- //-------------------------------------------------------------------------------
- //-------------------------------------------------------------------------------
- void DoExport(size_t formatId)
- {
- if (!g_szFileName[0]) {
- MessageBox(g_hDlg, "No model loaded", "Export", MB_ICONERROR);
- return;
- }
- Exporter exp;
- const aiExportFormatDesc* const e = exp.GetExportFormatDescription(formatId);
- ai_assert(e);
- char szFileName[MAX_PATH*2];
- DWORD dwTemp = sizeof(szFileName);
- if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"ModelExportDest",NULL,NULL,(BYTE*)szFileName, &dwTemp)) {
- ai_assert(strlen(szFileName) <= MAX_PATH);
- // invent a nice default file name
- char* sz = max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
- if (sz) {
- strncpy(sz,max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')),MAX_PATH);
- }
- }
- else {
- // Key was not found. Use the folder where the asset comes from
- strncpy(szFileName,g_szFileName,MAX_PATH);
- }
- // fix file extension
- { char * const sz = strrchr(szFileName,'.');
- if(sz) {
- ai_assert((sz - &szFileName[0]) + strlen(e->fileExtension) + 1 <= MAX_PATH);
- strcpy(sz+1,e->fileExtension);
- }
- }
- // build the stupid info string for GetSaveFileName() - can't use sprintf() because the string must contain binary zeros.
- char desc[256] = {0};
- char* c = strcpy(desc,e->description) + strlen(e->description)+1;
- c += sprintf(c,"*.%s",e->fileExtension)+1;
- strcpy(c, "*.*\0"); c += 4;
- ai_assert(c - &desc[0] <= 256);
- const std::string ext = "."+std::string(e->fileExtension);
- OPENFILENAME sFilename1 = {
- sizeof(OPENFILENAME),
- g_hDlg,GetModuleHandle(NULL),
- desc, NULL, 0, 1,
- szFileName, MAX_PATH, NULL, 0, NULL,
- "Export asset",
- OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY | OFN_NOCHANGEDIR,
- 0, 1, ext.c_str(), 0, NULL, NULL
- };
- if(::GetSaveFileName(&sFilename1) == 0) {
- return;
- }
- // Now store the file in the registry unless the user decided to stay in the model directory
- const std::string sFinal = szFileName, sub = sFinal.substr(0,sFinal.find_last_of("\\/"));
- if (strncmp(sub.c_str(),g_szFileName,sub.length())) {
- RegSetValueExA(g_hRegistry,"ModelExportDest",0,REG_SZ,(const BYTE*)szFileName,MAX_PATH);
- }
- // export the file
- const aiReturn res = exp.Export(g_pcAsset->pcScene,e->id,sFinal.c_str(),
- ppsteps | /* configurable pp steps */
- aiProcess_GenSmoothNormals | // generate smooth normal vectors if not existing
- aiProcess_SplitLargeMeshes | // split large, unrenderable meshes into submeshes
- aiProcess_Triangulate | // triangulate polygons with more than 3 edges
- aiProcess_ConvertToLeftHanded | // convert everything to D3D left handed space
- aiProcess_SortByPType | // make 'clean' meshes which consist of a single typ of primitives
- 0
- );
- if (res == aiReturn_SUCCESS) {
- CLogDisplay::Instance().AddEntry("[INFO] Exported file " + sFinal,D3DCOLOR_ARGB(0xFF,0x00,0xFF,0x00));
- return;
- }
- CLogDisplay::Instance().AddEntry("[INFO] Failure exporting file " +
- sFinal,D3DCOLOR_ARGB(0xFF,0xFF,0x00,0x00));
- }
- #endif
- //-------------------------------------------------------------------------------
- // 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");
- #ifndef ASSIMP_BUILD_NO_EXPORT
- PopulateExportMenu();
- #endif
- // 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",
- 0,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-214,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);
- }
- // LowQuality
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"NoTransparency",NULL,NULL,
- (BYTE*)&dwValue,&dwTemp))dwValue = 0;
- if (0 == dwValue)
- {
- g_sOptions.bNoAlphaBlending = false;
- CheckDlgButton(g_hDlg,IDC_NOAB,BST_UNCHECKED);
- }
- else
- {
- g_sOptions.bNoAlphaBlending = true;
- CheckDlgButton(g_hDlg,IDC_NOAB,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);
- }
- if(ERROR_SUCCESS != RegQueryValueEx(g_hRegistry,"PostProcessing",NULL,NULL,(BYTE*)&dwValue,&dwTemp))
- ppsteps = ppstepsdefault;
- else ppsteps = dwValue;
- SetupPPUIState();
- LoadCheckerPatternColors();
- SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMIN,TRUE,0);
- SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_SETRANGEMAX,TRUE,10000);
- return;
- }
- //-------------------------------------------------------------------------------
- // Message prcoedure for the smooth normals dialog
- //-------------------------------------------------------------------------------
- INT_PTR CALLBACK SMMessageProc(HWND hwndDlg,UINT uMsg,
- WPARAM wParam,LPARAM lParam)
- {
- UNREFERENCED_PARAMETER(lParam);
- switch (uMsg)
- {
- case WM_INITDIALOG:
- char s[30];
- ::sprintf(s,"%.2f",g_smoothAngle);
- SetDlgItemText(hwndDlg,IDC_EDITSM,s);
- return TRUE;
- case WM_CLOSE:
- EndDialog(hwndDlg,0);
- return TRUE;
- case WM_COMMAND:
- if (IDOK == LOWORD(wParam)) {
- char s[30];
- GetDlgItemText(hwndDlg,IDC_EDITSM,s,30);
- g_smoothAngle = (float)atof(s);
- EndDialog(hwndDlg,0);
- }
- else if (IDCANCEL == LOWORD(wParam)) {
- EndDialog(hwndDlg,1);
- }
- return TRUE;
- }
- return FALSE;
- }
- //-------------------------------------------------------------------------------
- // 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_HSCROLL:
- // XXX quick and dirty fix for #3029892
- if (GetDlgItem(g_hDlg, IDC_SLIDERANIM) == (HWND)lParam && g_pcAsset && g_pcAsset->pcScene->mAnimations)
- {
- double num = (double)SendDlgItemMessage(g_hDlg,IDC_SLIDERANIM,TBM_GETPOS,0,0);
- const aiAnimation* anim = g_pcAsset->pcScene->mAnimations[ g_pcAsset->mAnimator->CurrentAnimIndex() ];
- g_dCurrent = (anim->mDuration/anim->mTicksPerSecond) * num/10000;
- g_pcAsset->mAnimator->Calculate(g_dCurrent);
- }
- break;
- 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 = "Background #0";
- }
- 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 = "Light #0";
- }
- 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, static_cast<int>(strlen(szText)));
- 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 = "Background #1";
- }
- 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 = "Light #1";
- }
- 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, static_cast<int>(strlen(szText)));
- 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 = "Ambient";
- }
- 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,static_cast<int>(strlen(szText)));
- 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)
- sz = szFile;
- if (CDisplay::VIEWMODE_TEXTURE == CDisplay::Instance().GetViewMode())
- {
- // replace the selected texture with the new one ...
- CDisplay::Instance().ReplaceCurrentTexture(szFile);
- }
- else
- {
- // check whether it is a typical texture file format ...
- ++sz;
- if (0 == ASSIMP_stricmp(sz,"png") ||
- 0 == ASSIMP_stricmp(sz,"bmp") ||
- 0 == ASSIMP_stricmp(sz,"jpg") ||
- 0 == ASSIMP_stricmp(sz,"tga") ||
- 0 == ASSIMP_stricmp(sz,"tif") ||
- 0 == ASSIMP_stricmp(sz,"hdr") ||
- 0 == ASSIMP_stricmp(sz,"ppm") ||
- 0 == 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)
- return TRUE;
- // 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
- {
- strcpy(g_szFileName,szFile);
- DeleteAsset();
- LoadAsset();
- UpdateHistory();
- SaveHistory();
- }
- }
- DragFinish(hDrop);
- }
- return TRUE;
- case WM_COMMAND:
- HMENU hMenu = GetMenu(g_hDlg);
- if (ID_VIEWER_QUIT == LOWORD(wParam))
- {
- PostQuitMessage(0);
- DestroyWindow(hwndDlg);
- }
- else if (IDC_COMBO1 == LOWORD(wParam))
- {
- if(HIWORD(wParam) == CBN_SELCHANGE) {
- const size_t sel = static_cast<size_t>(ComboBox_GetCurSel(GetDlgItem(hwndDlg,IDC_COMBO1)));
- if(g_pcAsset) {
- g_pcAsset->mAnimator->SetAnimIndex(sel);
- SendDlgItemMessage(hwndDlg,IDC_SLIDERANIM,TBM_SETPOS,TRUE,0);
- }
- }
- }
- 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__WEBSITE == LOWORD(wParam))
- {
- ShellExecute(NULL,"open","http://assimp.sourceforge.net","","",SW_SHOW);
- }
- else if (ID__WEBSITESF == LOWORD(wParam))
- {
- ShellExecute(NULL,"open","https://sourceforge.net/projects/assimp","","",SW_SHOW);
- }
- else if (ID_REPORTBUG == LOWORD(wParam))
- {
- ShellExecute(NULL,"open","https://sourceforge.net/tracker/?func=add&group_id=226462&atid=1067632","","",SW_SHOW);
- }
- else if (ID_FR == LOWORD(wParam))
- {
- ShellExecute(NULL,"open","https://sourceforge.net/forum/forum.php?forum_id=817653","","",SW_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();
- }
- }
- // this is ugly. anyone willing to rewrite it from scratch using wxwidgets or similar?
- else if (ID_VIEWER_PP_JIV == LOWORD(wParam)) {
- ppsteps ^= aiProcess_JoinIdenticalVertices;
- CheckMenuItem(hMenu,ID_VIEWER_PP_JIV,ppsteps & aiProcess_JoinIdenticalVertices ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_CTS == LOWORD(wParam)) {
- ppsteps ^= aiProcess_CalcTangentSpace;
- CheckMenuItem(hMenu,ID_VIEWER_PP_CTS,ppsteps & aiProcess_CalcTangentSpace ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_FD == LOWORD(wParam)) {
- ppsteps ^= aiProcess_FindDegenerates;
- CheckMenuItem(hMenu,ID_VIEWER_PP_FD,ppsteps & aiProcess_FindDegenerates ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_FID == LOWORD(wParam)) {
- ppsteps ^= aiProcess_FindInvalidData;
- CheckMenuItem(hMenu,ID_VIEWER_PP_FID,ppsteps & aiProcess_FindInvalidData ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_FIM == LOWORD(wParam)) {
- ppsteps ^= aiProcess_FindInstances;
- CheckMenuItem(hMenu,ID_VIEWER_PP_FIM,ppsteps & aiProcess_FindInstances ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_FIN == LOWORD(wParam)) {
- ppsteps ^= aiProcess_FixInfacingNormals;
- CheckMenuItem(hMenu,ID_VIEWER_PP_FIN,ppsteps & aiProcess_FixInfacingNormals ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_GUV == LOWORD(wParam)) {
- ppsteps ^= aiProcess_GenUVCoords;
- CheckMenuItem(hMenu,ID_VIEWER_PP_GUV,ppsteps & aiProcess_GenUVCoords ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_ICL == LOWORD(wParam)) {
- ppsteps ^= aiProcess_ImproveCacheLocality;
- CheckMenuItem(hMenu,ID_VIEWER_PP_ICL,ppsteps & aiProcess_ImproveCacheLocality ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_OG == LOWORD(wParam)) {
- if (ppsteps & aiProcess_PreTransformVertices) {
- CLogDisplay::Instance().AddEntry("[ERROR] This setting is incompatible with \'Pretransform Vertices\'");
- }
- else {
- ppsteps ^= aiProcess_OptimizeGraph;
- CheckMenuItem(hMenu,ID_VIEWER_PP_OG,ppsteps & aiProcess_OptimizeGraph ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- }
- else if (ID_VIEWER_PP_OM == LOWORD(wParam)) {
- ppsteps ^= aiProcess_OptimizeMeshes;
- CheckMenuItem(hMenu,ID_VIEWER_PP_OM,ppsteps & aiProcess_OptimizeMeshes ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_PTV == LOWORD(wParam)) {
- if (ppsteps & aiProcess_OptimizeGraph) {
- CLogDisplay::Instance().AddEntry("[ERROR] This setting is incompatible with \'Optimize Scenegraph\'");
- }
- else {
- ppsteps ^= aiProcess_PreTransformVertices;
- CheckMenuItem(hMenu,ID_VIEWER_PP_PTV,ppsteps & aiProcess_PreTransformVertices ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- }
- else if (ID_VIEWER_PP_RRM2 == LOWORD(wParam)) {
- ppsteps ^= aiProcess_RemoveRedundantMaterials;
- CheckMenuItem(hMenu,ID_VIEWER_PP_RRM2,ppsteps & aiProcess_RemoveRedundantMaterials ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_TUV == LOWORD(wParam)) {
- ppsteps ^= aiProcess_TransformUVCoords;
- CheckMenuItem(hMenu,ID_VIEWER_PP_TUV,ppsteps & aiProcess_TransformUVCoords ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_DB == LOWORD(wParam)) {
- ppsteps ^= aiProcess_Debone;
- CheckMenuItem(hMenu,ID_VIEWER_PP_DB,ppsteps & aiProcess_Debone ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_PP_VDS == LOWORD(wParam)) {
- ppsteps ^= aiProcess_ValidateDataStructure;
- CheckMenuItem(hMenu,ID_VIEWER_PP_VDS,ppsteps & aiProcess_ValidateDataStructure ? MF_CHECKED : MF_UNCHECKED);
- UpdatePPSettings();
- }
- else if (ID_VIEWER_RELOAD == LOWORD(wParam))
- {
- DeleteAsset();
- LoadAsset();
- }
- else if (ID_IMPORTSETTINGS_RESETTODEFAULT == LOWORD(wParam))
- {
- ppsteps = ppstepsdefault;
- UpdatePPSettings();
- SetupPPUIState();
- }
- else if (ID_IMPORTSETTINGS_OPENPOST == LOWORD(wParam))
- {
- ShellExecute(NULL,"open","http://assimp.sourceforge.net/lib_html/ai_post_process_8h.html","","",SW_SHOW);
- }
- else if (ID_TOOLS_ORIGINALNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::ORIGINAL);
- CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_CHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- }
- }
- else if (ID_TOOLS_SMOOTHNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::SMOOTH);
- CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_CHECKED);
- }
- }
- else if (ID_TOOLS_HARDNORMALS == LOWORD(wParam))
- {
- if (g_pcAsset && g_pcAsset->pcScene)
- {
- g_pcAsset->SetNormalSet(AssimpView::AssetHelper::HARD);
- CheckMenuItem(hMenu,ID_TOOLS_ORIGINALNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_HARDNORMALS,MF_BYCOMMAND | MF_CHECKED);
- CheckMenuItem(hMenu,ID_TOOLS_SMOOTHNORMALS,MF_BYCOMMAND | MF_UNCHECKED);
- }
- }
- 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_TOOLS_SETANGLELIMIT == LOWORD(wParam))
- {
- DialogBox(g_hInstance,MAKEINTRESOURCE(IDD_DIALOGSMOOTH),g_hDlg,&SMMessageProc);
- }
- 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_NOAB == LOWORD(wParam))
- {
- ToggleTransparency();
- }
- 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();
- }
- else if (IDC_SHOWSKELETON == LOWORD(wParam))
- {
- ToggleSkeleton();
- }
- else if (IDC_BFCULL == LOWORD(wParam))
- {
- ToggleCulling();
- }
- else if (IDC_PLAY == LOWORD(wParam))
- {
- g_bPlay = !g_bPlay;
- SetDlgItemText(g_hDlg,IDC_PLAY,(g_bPlay ? "Stop" : "Play"));
- if (g_bPlay)
- EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),FALSE);
- else EnableWindow(GetDlgItem(g_hDlg,IDC_SLIDERANIM),TRUE);
- }
- }
- // 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();
- }
- }
- #ifndef ASSIMP_BUILD_NO_EXPORT
- if (LOWORD(wParam) >= AI_VIEW_EXPORT_FMT_BASE && LOWORD(wParam) < AI_VIEW_EXPORT_FMT_BASE+Assimp::Exporter().GetExportFormatCount()) {
- DoExport(LOWORD(wParam) - AI_VIEW_EXPORT_FMT_BASE);
- }
- #endif
- // 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);
- // ensure we get high priority
- ::SetPriorityClass(GetCurrentProcess(),HIGH_PRIORITY_CLASS);
- // initialize the default logger if necessary
- Assimp::DefaultLogger::create("",Assimp::Logger::VERBOSE);
- CLogWindow::Instance().pcStream = new CMyLogStream();
- Assimp::DefaultLogger::get()->attachStream(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;
- }
- CLogDisplay::Instance().AddEntry("[OK] Here we go!");
- // 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",0,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;
- case 'K':
- case 'k':
- CheckDlgButton(g_hDlg,IDC_SHOWSKELETON,
- IsDlgButtonChecked(g_hDlg,IDC_SHOWSKELETON) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleSkeleton();
- break;
- case 'C':
- case 'c':
- CheckDlgButton(g_hDlg,IDC_BFCULL,
- IsDlgButtonChecked(g_hDlg,IDC_BFCULL) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleCulling();
- break;
- case 'T':
- case 't':
- CheckDlgButton(g_hDlg,IDC_NOAB,
- IsDlgButtonChecked(g_hDlg,IDC_NOAB) == BST_CHECKED
- ? BST_UNCHECKED : BST_CHECKED);
- ToggleTransparency();
- break;
- }
- }
- }
- // render the scene
- CDisplay::Instance().OnRender();
- // measure FPS, average it out
- 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;
- }
|