Browse Source

+ implement export support into AssimpView

git-svn-id: https://assimp.svn.sourceforge.net/svnroot/assimp/trunk@937 67173fc5-114c-0410-ac8e-9d2fd5bffc1f
aramis_acg 14 years ago
parent
commit
45d6647ffe

+ 99 - 0
tools/assimp_view/MessageProc.cpp

@@ -61,6 +61,9 @@ 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();
 
@@ -997,6 +1000,92 @@ void SetupPPUIState()
 	CheckMenuItem(hMenu,ID_VIEWER_PP_VDS,ppsteps & aiProcess_ValidateDataStructure ? 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)
+{
+	Exporter exp;
+	const aiExportFormatDesc* const e = exp.GetExportFormatDescription(formatId);
+	assert(e);
+
+	char szFileName[MAX_PATH*2];
+	DWORD dwTemp;
+	if(ERROR_SUCCESS == RegQueryValueEx(g_hRegistry,"ModelExportDest",NULL,NULL,(BYTE*)szFileName,&dwTemp)) {
+		// invent a nice default file name 
+		char* sz = std::max(strrchr(szFileName,'\\'),strrchr(szFileName,'/'));
+		if (sz) {
+			strcpy(sz,std::max(strrchr(g_szFileName,'\\'),strrchr(g_szFileName,'/')));
+		}
+	}
+	else {
+		// Key was not found. Use the folder where the asset comes from
+		strcpy(szFileName,g_szFileName);
+	}
+
+	// fix file extension
+	{	char * const sz = strrchr(szFileName,'.');
+		if(sz) 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");
+
+	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());
+	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
 //-------------------------------------------------------------------------------
@@ -1010,6 +1099,10 @@ void InitUI()
 	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);
 
@@ -2117,6 +2210,12 @@ INT_PTR CALLBACK MessageProc(HWND hwndDlg,UINT uMsg,
 				}
 			}
 
+#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);
 

+ 0 - 13
tools/assimp_view/assimp_view.cpp

@@ -184,19 +184,6 @@ DWORD WINAPI LoadThreadProc(LPVOID lpParameter)
 		return 1;
 	}
 
-#ifdef ASSIMP_BUILD_NO_EXPORT
-	// testweise wieder rausschreiben
-	const aiExportDataBlob* blob = aiExportSceneToBlob( g_pcAsset->pcScene, "collada");
-	if( blob )
-	{
-		FILE* file = fopen( "test.dae", "wb");
-		fwrite( blob->data, 1, blob->size, file);
-		fclose( file);
-
-		aiReleaseExportData( blob);
-	}
-#endif // ASSIMP_BUILD_NO_EXPORT
-
 	return 0;
 }
 

+ 1 - 0
tools/assimp_view/assimp_view.rc

@@ -376,6 +376,7 @@ BEGIN
         MENUITEM SEPARATOR
         MENUITEM "Clear",                       ID_BACKGROUND_CLEAR
     END
+    MENUITEM "Export",                      32878
     POPUP "?"
     BEGIN
         POPUP "Feedback"

+ 2 - 2
tools/assimp_view/resource.h

@@ -109,7 +109,6 @@
 #define IDC_SHOWSKELETON                1054
 #define IDC_BFCULL                      1055
 #define IDC_EDITSM                      1056
-#define IDC_TAB1                        1058
 #define ID_VIEWER_OPEN                  32771
 #define ID_VIEWER_CLOSETHIS             32772
 #define ID_VIEWER_CLOSEASSET            32773
@@ -218,6 +217,7 @@
 #define ID_VIEWER_PP_RRM2               32875
 #define ID_IMPORTSETTINGS_RESETTODEFAULT 32876
 #define ID_IMPORTSETTINGS_OPENPOST      32877
+#define ID_EXPORT                       32878
 #define IDC_STATIC                      -1
 
 // Next default values for new objects
@@ -226,7 +226,7 @@
 #ifndef APSTUDIO_READONLY_SYMBOLS
 #define _APS_NO_MFC                     1
 #define _APS_NEXT_RESOURCE_VALUE        160
-#define _APS_NEXT_COMMAND_VALUE         32878
+#define _APS_NEXT_COMMAND_VALUE         32879
 #define _APS_NEXT_CONTROL_VALUE         1059
 #define _APS_NEXT_SYMED_VALUE           110
 #endif