goat3d
diff exporters/maxgoat/src/maxgoat.cc @ 66:3751aabbc5b3
igame animation api is weird...
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 19 Apr 2014 07:56:43 +0300 |
parents | fdece14403ff |
children | 8ecaf9cd3ce7 |
line diff
1.1 --- a/exporters/maxgoat/src/maxgoat.cc Tue Apr 01 13:11:04 2014 +0300 1.2 +++ b/exporters/maxgoat/src/maxgoat.cc Sat Apr 19 07:56:43 2014 +0300 1.3 @@ -1,6 +1,7 @@ 1.4 #include <stdio.h> 1.5 #include <string.h> 1.6 #include <stdlib.h> 1.7 +#include <ctype.h> 1.8 #include <errno.h> 1.9 #include <map> 1.10 #include <windows.h> 1.11 @@ -11,9 +12,9 @@ 1.12 #include "plugapi.h" 1.13 #include "IGame.h" 1.14 #include "IGameExport.h" 1.15 +#include "IGameControl.h" 1.16 #include "IConversionmanager.h" 1.17 #include "goat3d.h" 1.18 -#include "minwin.h" 1.19 #include "config.h" 1.20 #include "logger.h" 1.21 #include "resource.h" 1.22 @@ -31,9 +32,15 @@ 1.23 #pragma comment (lib, "comctl32.lib") 1.24 1.25 1.26 +#define COPYRIGHT \ 1.27 + L"Copyright 2014 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details." 1.28 #define VERSION(major, minor) \ 1.29 ((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor))) 1.30 1.31 +static INT_PTR CALLBACK scene_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); 1.32 +static INT_PTR CALLBACK anim_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); 1.33 +static const char *max_string(const MCHAR *wstr); 1.34 + 1.35 HINSTANCE hinst; 1.36 1.37 class GoatExporter : public SceneExport { 1.38 @@ -44,17 +51,6 @@ 1.39 public: 1.40 IGameScene *igame; 1.41 1.42 - int ExtCount(); 1.43 - const TCHAR *Ext(int n); 1.44 - const TCHAR *LongDesc(); 1.45 - const TCHAR *ShortDesc(); 1.46 - const TCHAR *AuthorName(); 1.47 - const TCHAR *CopyrightMessage(); 1.48 - const TCHAR *OtherMessage1(); 1.49 - const TCHAR *OtherMessage2(); 1.50 - unsigned int Version(); 1.51 - void ShowAbout(HWND win); 1.52 - 1.53 int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); 1.54 1.55 void process_materials(goat3d *goat); 1.56 @@ -64,96 +60,36 @@ 1.57 void process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj); 1.58 void process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj); 1.59 void process_camera(goat3d *goat, goat3d_camera *cam, IGameObject *maxobj); 1.60 + 1.61 + 1.62 + int ExtCount() { return 1; } 1.63 + const TCHAR *Ext(int n) { return L"goatsce"; } 1.64 + const TCHAR *LongDesc() { return L"Goat3D scene file"; } 1.65 + const TCHAR *ShortDesc() { return L"Goat3D"; } 1.66 + const TCHAR *AuthorName() { return L"John Tsiombikas"; } 1.67 + const TCHAR *CopyrightMessage() { return COPYRIGHT; } 1.68 + const TCHAR *OtherMessage1() { return L"other1"; } 1.69 + const TCHAR *OtherMessage2() { return L"other2"; } 1.70 + unsigned int Version() { return VERSION(VER_MAJOR, VER_MINOR); } 1.71 + void ShowAbout(HWND win) { MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0); } 1.72 }; 1.73 1.74 +class GoatAnimExporter : public GoatExporter { 1.75 +private: 1.76 +public: 1.77 + int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); 1.78 1.79 -int GoatExporter::ExtCount() 1.80 -{ 1.81 - return 1; 1.82 -} 1.83 + const TCHAR *Ext(int n) { return L"goatanm"; } 1.84 + const TCHAR *LongDesc() { return L"Goat3D animation file"; } 1.85 +}; 1.86 1.87 -const TCHAR *GoatExporter::Ext(int n) 1.88 -{ 1.89 - return L"xml"; 1.90 -} 1.91 1.92 -const TCHAR *GoatExporter::LongDesc() 1.93 -{ 1.94 - return L"Goat3D scene file"; 1.95 -} 1.96 - 1.97 -const TCHAR *GoatExporter::ShortDesc() 1.98 -{ 1.99 - return L"Goat3D"; 1.100 -} 1.101 - 1.102 -const TCHAR *GoatExporter::AuthorName() 1.103 -{ 1.104 - return L"John Tsiombikas"; 1.105 -} 1.106 - 1.107 -const TCHAR *GoatExporter::CopyrightMessage() 1.108 -{ 1.109 - return L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details."; 1.110 -} 1.111 - 1.112 -const TCHAR *GoatExporter::OtherMessage1() 1.113 -{ 1.114 - return L"other1"; 1.115 -} 1.116 - 1.117 -const TCHAR *GoatExporter::OtherMessage2() 1.118 -{ 1.119 - return L"other2"; 1.120 -} 1.121 - 1.122 -unsigned int GoatExporter::Version() 1.123 -{ 1.124 - return VERSION(VER_MAJOR, VER_MINOR); 1.125 -} 1.126 - 1.127 -void GoatExporter::ShowAbout(HWND win) 1.128 -{ 1.129 - MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0); 1.130 -} 1.131 - 1.132 -static INT_PTR CALLBACK handle_dlg_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) 1.133 -{ 1.134 - switch(msg) { 1.135 - case WM_INITDIALOG: 1.136 - CheckDlgButton(win, IDC_GOAT_NODES, 1); 1.137 - CheckDlgButton(win, IDC_GOAT_MESHES, 1); 1.138 - CheckDlgButton(win, IDC_GOAT_LIGHTS, 1); 1.139 - CheckDlgButton(win, IDC_GOAT_CAMERAS, 1); 1.140 - break; 1.141 - 1.142 - case WM_COMMAND: 1.143 - switch(LOWORD(wparam)) { 1.144 - case IDOK: 1.145 - EndDialog(win, 1); 1.146 - break; 1.147 - 1.148 - case IDCANCEL: 1.149 - EndDialog(win, 0); 1.150 - break; 1.151 - 1.152 - default: 1.153 - return 0; 1.154 - } 1.155 - break; 1.156 - 1.157 - default: 1.158 - return 0; 1.159 - } 1.160 - 1.161 - return 1; 1.162 -} 1.163 +// ---- GoatExporter implementation ---- 1.164 1.165 int GoatExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, 1.166 BOOL non_interactive, DWORD opt) 1.167 { 1.168 - if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, handle_dlg_events)) { 1.169 - maxlog("canceled!\n"); 1.170 + if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, scene_gui_handler)) { 1.171 return IMPEXP_CANCEL; 1.172 } 1.173 1.174 @@ -162,6 +98,9 @@ 1.175 1.176 char fname[512]; 1.177 wcstombs(fname, name, sizeof fname - 1); 1.178 + for(int i=0; fname[i]; i++) { 1.179 + fname[i] = tolower(fname[i]); 1.180 + } 1.181 1.182 maxlog("Exporting Goat3D Scene (text) file: %s\n", fname); 1.183 if(!(igame = GetIGameInterface())) { 1.184 @@ -171,7 +110,6 @@ 1.185 IGameConversionManager *cm = GetConversionManager(); 1.186 cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); 1.187 igame->InitialiseIGame(); 1.188 - igame->SetStaticFrame(0); 1.189 1.190 goat3d *goat = goat3d_create(); 1.191 1.192 @@ -192,14 +130,6 @@ 1.193 return IMPEXP_SUCCESS; 1.194 } 1.195 1.196 -static const char *max_string(const MCHAR *wstr) 1.197 -{ 1.198 - if(!wstr) return 0; 1.199 - static char str[512]; 1.200 - wcstombs(str, wstr, sizeof str - 1); 1.201 - return str; 1.202 -} 1.203 - 1.204 void GoatExporter::process_materials(goat3d *goat) 1.205 { 1.206 IGameProperty *prop; 1.207 @@ -293,6 +223,10 @@ 1.208 goat3d_node *node = goat3d_create_node(); 1.209 goat3d_add_node(goat, node); 1.210 1.211 + if(parent) { 1.212 + goat3d_add_node_child(parent, node); 1.213 + } 1.214 + 1.215 const char *name = max_string(maxnode->GetName()); 1.216 if(name) { 1.217 goat3d_set_node_name(node, name); 1.218 @@ -356,7 +290,19 @@ 1.219 // otherwise don't assign an object, essentially treating it as a null node 1.220 break; 1.221 } 1.222 - 1.223 + 1.224 + // grab the animation data 1.225 + IGameControl *ctrl = maxnode->GetIGameControl(); 1.226 + 1.227 + IGameKeyTab tm_keys; 1.228 + if(ctrl->GetFullSampledKeys(tm_keys, 1, IGAME_TM)) { 1.229 + maxlog("node: %s has %d keys\n", name, tm_keys.Count()); 1.230 + /*for(int i=0; i<pkeys.Count(); i++) { 1.231 + Point3 p = pkeys[i].linearKey.pval; 1.232 + TimeValue t = pkeys[i].t; 1.233 + goat3d_set_node_position(node, p.x, p.y, p.z, TicksToSec(t)); 1.234 + }*/ 1.235 + } 1.236 1.237 for(int i=0; i<maxnode->GetChildCount(); i++) { 1.238 process_node(goat, node, maxnode->GetNodeChild(i)); 1.239 @@ -424,12 +370,117 @@ 1.240 1.241 void GoatExporter::process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj) 1.242 { 1.243 + // TODO 1.244 } 1.245 1.246 void GoatExporter::process_camera(goat3d *goat, goat3d_camera *cam, IGameObject *maxobj) 1.247 { 1.248 + // TODO 1.249 } 1.250 1.251 +static INT_PTR CALLBACK scene_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) 1.252 +{ 1.253 + switch(msg) { 1.254 + case WM_INITDIALOG: 1.255 + CheckDlgButton(win, IDC_GOAT_NODES, 1); 1.256 + CheckDlgButton(win, IDC_GOAT_MESHES, 1); 1.257 + CheckDlgButton(win, IDC_GOAT_LIGHTS, 1); 1.258 + CheckDlgButton(win, IDC_GOAT_CAMERAS, 1); 1.259 + break; 1.260 + 1.261 + case WM_COMMAND: 1.262 + switch(LOWORD(wparam)) { 1.263 + case IDOK: 1.264 + EndDialog(win, 1); 1.265 + break; 1.266 + 1.267 + case IDCANCEL: 1.268 + EndDialog(win, 0); 1.269 + break; 1.270 + 1.271 + default: 1.272 + return 0; 1.273 + } 1.274 + break; 1.275 + 1.276 + default: 1.277 + return 0; 1.278 + } 1.279 + 1.280 + return 1; 1.281 +} 1.282 + 1.283 + 1.284 + 1.285 +// ---- GoatAnimExporter implementation ---- 1.286 + 1.287 +int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt) 1.288 +{ 1.289 + if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) { 1.290 + return IMPEXP_CANCEL; 1.291 + } 1.292 + 1.293 + char fname[512]; 1.294 + wcstombs(fname, name, sizeof fname - 1); 1.295 + for(int i=0; fname[i]; i++) { 1.296 + fname[i] = tolower(fname[i]); 1.297 + } 1.298 + 1.299 + maxlog("Exporting Goat3D Animation (text) file: %s\n", fname); 1.300 + if(!(igame = GetIGameInterface())) { 1.301 + maxlog("failed to get the igame interface\n"); 1.302 + return IMPEXP_FAIL; 1.303 + } 1.304 + IGameConversionManager *cm = GetConversionManager(); 1.305 + cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); 1.306 + igame->InitialiseIGame(); 1.307 + igame->SetStaticFrame(0); 1.308 + 1.309 + goat3d *goat = goat3d_create(); 1.310 + 1.311 + // process all nodes 1.312 + for(int i=0; i<igame->GetTopLevelNodeCount(); i++) { 1.313 + IGameNode *node = igame->GetTopLevelNode(i); 1.314 + process_node(goat, 0, node); 1.315 + } 1.316 + 1.317 + if(goat3d_save_anim(goat, fname) == -1) { 1.318 + goat3d_free(goat); 1.319 + return IMPEXP_FAIL; 1.320 + } 1.321 + 1.322 + goat3d_free(goat); 1.323 + return IMPEXP_SUCCESS; 1.324 +} 1.325 + 1.326 +static INT_PTR CALLBACK anim_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) 1.327 +{ 1.328 + switch(msg) { 1.329 + case WM_INITDIALOG: 1.330 + CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1); 1.331 + break; 1.332 + 1.333 + case WM_COMMAND: 1.334 + switch(LOWORD(wparam)) { 1.335 + case IDOK: 1.336 + EndDialog(win, 1); 1.337 + break; 1.338 + 1.339 + case IDCANCEL: 1.340 + EndDialog(win, 0); 1.341 + break; 1.342 + 1.343 + default: 1.344 + return 0; 1.345 + } 1.346 + break; 1.347 + 1.348 + default: 1.349 + return 0; 1.350 + } 1.351 + 1.352 + return 1; 1.353 +} 1.354 1.355 // ------------------------------------------ 1.356 1.357 @@ -446,8 +497,22 @@ 1.358 HINSTANCE HInstance() { return hinst; } 1.359 }; 1.360 1.361 +class GoatAnimClassDesc : public ClassDesc2 { 1.362 +public: 1.363 + int IsPublic() { return TRUE; } 1.364 + void *Create(BOOL loading = FALSE) { return new GoatAnimExporter; } 1.365 + const TCHAR *ClassName() { return L"GoatAnimExporter"; } 1.366 + SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; } 1.367 + Class_ID ClassID() { return Class_ID(0x51b94924, 0x2e0332f3); } 1.368 + const TCHAR *Category() { return L"Mutant Stargoat"; } 1.369 + 1.370 + const TCHAR *InternalName() { return L"GoatAnimExporter"; } 1.371 + HINSTANCE HInstance() { return hinst; } 1.372 +}; 1.373 + 1.374 // TODO: make 2 class descriptors, one for goat3d, one for goat3danim 1.375 static GoatClassDesc class_desc; 1.376 +static GoatAnimClassDesc anim_class_desc; 1.377 1.378 BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved) 1.379 { 1.380 @@ -472,7 +537,15 @@ 1.381 1.382 __declspec(dllexport) ClassDesc *LibClassDesc(int i) 1.383 { 1.384 - return i == 0 ? &class_desc : 0; 1.385 + switch(i) { 1.386 + case 0: 1.387 + return &class_desc; 1.388 + case 1: 1.389 + return &anim_class_desc; 1.390 + default: 1.391 + break; 1.392 + } 1.393 + return 0; 1.394 } 1.395 1.396 __declspec(dllexport) ULONG LibVersion() 1.397 @@ -497,4 +570,13 @@ 1.398 return TRUE; 1.399 } 1.400 1.401 -} // extern "C" 1.402 \ No newline at end of file 1.403 +} // extern "C" 1.404 + 1.405 + 1.406 +static const char *max_string(const MCHAR *wstr) 1.407 +{ 1.408 + if(!wstr) return 0; 1.409 + static char str[512]; 1.410 + wcstombs(str, wstr, sizeof str - 1); 1.411 + return str; 1.412 +} 1.413 \ No newline at end of file