goat3d
diff exporters/maxgoat_stub/src/stub.cc @ 58:d317eb4f83da
- made everything compile properly on windows again
- removed libanim/libvmath, we'll use them as external dependencies
- added new maxgoat_stub 3dsmax plugin project. Gets loaded as a max plugin and
loads the actual maxgoat (and later maxgoat_anim) exporters on demand, to
allow reloading the actual exporters without having to restart 3dsmax (which
takes AGES).
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Tue, 25 Mar 2014 03:19:55 +0200 |
parents | |
children | 0c3576325480 |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/exporters/maxgoat_stub/src/stub.cc Tue Mar 25 03:19:55 2014 +0200 1.3 @@ -0,0 +1,270 @@ 1.4 +#include <stdio.h> 1.5 +#include <string.h> 1.6 +#include <stdlib.h> 1.7 +#include <errno.h> 1.8 +#include <map> 1.9 +#include <windows.h> 1.10 +#include <shlobj.h> 1.11 +#include "max.h" 1.12 +#include "impexp.h" // SceneExport 1.13 +#include "iparamb2.h" // ClassDesc2 1.14 +#include "plugapi.h" 1.15 +#include "IGame.h" 1.16 +#include "IGameExport.h" 1.17 +#include "IConversionmanager.h" 1.18 + 1.19 + 1.20 +#pragma comment (lib, "core.lib") 1.21 +#pragma comment (lib, "geom.lib") 1.22 +#pragma comment (lib, "gfx.lib") 1.23 +#pragma comment (lib, "mesh.lib") 1.24 +#pragma comment (lib, "maxutil.lib") 1.25 +#pragma comment (lib, "maxscrpt.lib") 1.26 +#pragma comment (lib, "paramblk2.lib") 1.27 +#pragma comment (lib, "msxml2.lib") 1.28 +#pragma comment (lib, "igame.lib") 1.29 +#pragma comment (lib, "comctl32.lib") 1.30 + 1.31 + 1.32 +#define VER_MAJOR 1 1.33 +#define VER_MINOR 0 1.34 +#define VERSION(major, minor) \ 1.35 + ((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor))) 1.36 + 1.37 +typedef int (*PluginInitFunc)(); 1.38 +typedef int (*PluginShutdownFunc)(); 1.39 +typedef ClassDesc *(*PluginClassDescFunc)(int); 1.40 + 1.41 +static FILE *logfile; 1.42 +static HINSTANCE hinst; 1.43 + 1.44 +class GoatExporterStub : public SceneExport { 1.45 +private: 1.46 + 1.47 +public: 1.48 + IGameScene *igame; 1.49 + 1.50 + int ExtCount(); 1.51 + const TCHAR *Ext(int n); 1.52 + const TCHAR *LongDesc(); 1.53 + const TCHAR *ShortDesc(); 1.54 + const TCHAR *AuthorName(); 1.55 + const TCHAR *CopyrightMessage(); 1.56 + const TCHAR *OtherMessage1(); 1.57 + const TCHAR *OtherMessage2(); 1.58 + unsigned int Version(); 1.59 + void ShowAbout(HWND win); 1.60 + 1.61 + int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); 1.62 +}; 1.63 + 1.64 + 1.65 +int GoatExporterStub::ExtCount() 1.66 +{ 1.67 + return 1; 1.68 +} 1.69 + 1.70 +const TCHAR *GoatExporterStub::Ext(int n) 1.71 +{ 1.72 + return L"xml"; 1.73 +} 1.74 + 1.75 +const TCHAR *GoatExporterStub::LongDesc() 1.76 +{ 1.77 + return L"Goat3D scene file"; 1.78 +} 1.79 + 1.80 +const TCHAR *GoatExporterStub::ShortDesc() 1.81 +{ 1.82 + return L"Goat3D"; 1.83 +} 1.84 + 1.85 +const TCHAR *GoatExporterStub::AuthorName() 1.86 +{ 1.87 + return L"John Tsiombikas"; 1.88 +} 1.89 + 1.90 +const TCHAR *GoatExporterStub::CopyrightMessage() 1.91 +{ 1.92 + return L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details."; 1.93 +} 1.94 + 1.95 +const TCHAR *GoatExporterStub::OtherMessage1() 1.96 +{ 1.97 + return L"other1"; 1.98 +} 1.99 + 1.100 +const TCHAR *GoatExporterStub::OtherMessage2() 1.101 +{ 1.102 + return L"other2"; 1.103 +} 1.104 + 1.105 +unsigned int GoatExporterStub::Version() 1.106 +{ 1.107 + return VERSION(VER_MAJOR, VER_MINOR); 1.108 +} 1.109 + 1.110 +void GoatExporterStub::ShowAbout(HWND win) 1.111 +{ 1.112 + MessageBoxA(win, "Goat3D exporter stub", "About this plugin", 0); 1.113 +} 1.114 + 1.115 +static const char *find_dll_dir() 1.116 +{ 1.117 + static char path[MAX_PATH]; 1.118 + 1.119 + HMODULE dll; 1.120 + if(!GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS | GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT, 1.121 + (LPCSTR)find_dll_dir, &dll)) { 1.122 + return 0; 1.123 + } 1.124 + GetModuleFileNameA(dll, path, sizeof path); 1.125 + 1.126 + char *last_slash = strrchr(path, '\\'); 1.127 + if(last_slash && last_slash[1]) { 1.128 + *last_slash = 0; 1.129 + } 1.130 + 1.131 + return path; 1.132 +} 1.133 + 1.134 +/* TODO: open a dialog, let the user select goat3d or goat3danim, then load the correct dll 1.135 + */ 1.136 +int GoatExporterStub::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, 1.137 + BOOL non_interactive, DWORD opt) 1.138 +{ 1.139 + const char *dll_fname = "maxgoat.dll"; 1.140 + char *dll_path; 1.141 + HMODULE dll = 0; 1.142 + PluginInitFunc init; 1.143 + PluginShutdownFunc shutdown; 1.144 + PluginClassDescFunc get_class_desc; 1.145 + ClassDesc *desc; 1.146 + SceneExport *ex; 1.147 + int result = IMPEXP_FAIL; 1.148 + 1.149 + const char *plugdir = find_dll_dir(); 1.150 + if(plugdir) { 1.151 + dll_path = new char[strlen(dll_fname) + strlen(plugdir) + 2]; 1.152 + sprintf(dll_path, "%s\\%s", plugdir, dll_fname); 1.153 + } else { 1.154 + dll_path = new char[strlen(dll_fname) + 1]; 1.155 + strcpy(dll_path, dll_fname); 1.156 + } 1.157 + 1.158 + if(!(dll = LoadLibraryA(dll_path))) { 1.159 + fprintf(logfile, "failed to load exporter: %s\n", dll_path); 1.160 + goto done; 1.161 + } 1.162 + 1.163 + if(!(get_class_desc = (PluginClassDescFunc)GetProcAddress(dll, "LibClassDesc"))) { 1.164 + fprintf(logfile, "maxgoat.dll is invalid (no LibClassDesc function)\n"); 1.165 + goto done; 1.166 + } 1.167 + 1.168 + // first initialize the library 1.169 + if((init = (PluginInitFunc)GetProcAddress(dll, "LibInitialize"))) { 1.170 + if(!init()) { 1.171 + fprintf(logfile, "exporter initialization failed!\n"); 1.172 + goto done; 1.173 + } 1.174 + } 1.175 + 1.176 + // TODO: pass 1 for anim 1.177 + if(!(desc = get_class_desc(0))) { 1.178 + fprintf(logfile, "failed to get the class descriptor\n"); 1.179 + goto done; 1.180 + } 1.181 + 1.182 + if(!(ex = (SceneExport*)desc->Create())) { 1.183 + fprintf(logfile, "failed to create exporter class instance\n"); 1.184 + goto done; 1.185 + } 1.186 + 1.187 + result = ex->DoExport(name, eiface, iface); 1.188 + delete ex; 1.189 + 1.190 + if((shutdown = (PluginShutdownFunc)GetProcAddress(dll, "LibShutdown"))) { 1.191 + shutdown(); 1.192 + } 1.193 + 1.194 +done: 1.195 + delete [] dll_path; 1.196 + if(dll) { 1.197 + FreeLibrary(dll); 1.198 + } 1.199 + return result; 1.200 +} 1.201 + 1.202 + 1.203 +// ------------------------------------------ 1.204 + 1.205 +class GoatClassDesc : public ClassDesc2 { 1.206 +public: 1.207 + int IsPublic() { return TRUE; } 1.208 + void *Create(BOOL loading = FALSE) { return new GoatExporterStub; } 1.209 + const TCHAR *ClassName() { return L"GoatExporterStub"; } 1.210 + SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; } 1.211 + Class_ID ClassID() { return Class_ID(0x2e4e6311, 0x2b154d91); } 1.212 + const TCHAR *Category() { return L"Mutant Stargoat"; } 1.213 + 1.214 + const TCHAR *InternalName() { return L"GoatExporterStub"; } 1.215 + HINSTANCE HInstance() { return hinst; } 1.216 +}; 1.217 + 1.218 +static GoatClassDesc class_desc; 1.219 + 1.220 +BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved) 1.221 +{ 1.222 + if(reason == DLL_PROCESS_ATTACH) { 1.223 + hinst = inst_handle; 1.224 + DisableThreadLibraryCalls(hinst); 1.225 + } 1.226 + return TRUE; 1.227 +} 1.228 + 1.229 +extern "C" { 1.230 + 1.231 +__declspec(dllexport) const TCHAR *LibDescription() 1.232 +{ 1.233 + return L"Goat3D exporter stub"; 1.234 +} 1.235 + 1.236 +__declspec(dllexport) int LibNumberClasses() 1.237 +{ 1.238 + return 1; 1.239 +} 1.240 + 1.241 +__declspec(dllexport) ClassDesc *LibClassDesc(int i) 1.242 +{ 1.243 + return i == 0 ? &class_desc : 0; 1.244 +} 1.245 + 1.246 +__declspec(dllexport) ULONG LibVersion() 1.247 +{ 1.248 + return Get3DSMAXVersion(); 1.249 +} 1.250 + 1.251 +__declspec(dllexport) int LibInitialize() 1.252 +{ 1.253 + static char path[1024]; 1.254 + 1.255 + SHGetFolderPathA(0, CSIDL_PERSONAL, 0, 0, path); 1.256 + strcat(path, "/testexpstub.log"); 1.257 + 1.258 + if((logfile = fopen(path, "w"))) { 1.259 + setvbuf(logfile, 0, _IONBF, 0); 1.260 + } 1.261 + return TRUE; 1.262 +} 1.263 + 1.264 +__declspec(dllexport) int LibShutdown() 1.265 +{ 1.266 + if(logfile) { 1.267 + fclose(logfile); 1.268 + logfile = 0; 1.269 + } 1.270 + return TRUE; 1.271 +} 1.272 + 1.273 +} // extern "C" 1.274 \ No newline at end of file