# HG changeset patch # User John Tsiombikas # Date 1397883403 -10800 # Node ID 3751aabbc5b3556ebaf2ed07353a279445bb7b6f # Parent cd7efb8757e152603c467b8b81638789d07296ed igame animation api is weird... diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/maxgoat.rc Binary file exporters/maxgoat/maxgoat.rc has changed diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/maxgoat.vcxproj --- a/exporters/maxgoat/maxgoat.vcxproj Tue Apr 01 13:11:04 2014 +0300 +++ b/exporters/maxgoat/maxgoat.vcxproj Sat Apr 19 07:56:43 2014 +0300 @@ -33,7 +33,7 @@ DynamicLibrary true - v100 + v110 Unicode @@ -46,7 +46,7 @@ DynamicLibrary false - v100 + v110 true Unicode @@ -109,7 +109,7 @@ $(TargetDir);%(AdditionalLibraryDirectories) - copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)" + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2015)plugins\$(TargetFileName)" @@ -151,25 +151,22 @@ $(TargetDir);%(AdditionalLibraryDirectories) - copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(TargetFileName)" + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2015)plugins\$(TargetFileName)" - - - diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/maxgoat.vcxproj.filters --- a/exporters/maxgoat/maxgoat.vcxproj.filters Tue Apr 01 13:11:04 2014 +0300 +++ b/exporters/maxgoat/maxgoat.vcxproj.filters Sat Apr 19 07:56:43 2014 +0300 @@ -10,17 +10,11 @@ src - - src - src - - src - src @@ -32,7 +26,6 @@ - \ No newline at end of file diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/resource.h Binary file exporters/maxgoat/resource.h has changed diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/src/maxgoat.cc --- a/exporters/maxgoat/src/maxgoat.cc Tue Apr 01 13:11:04 2014 +0300 +++ b/exporters/maxgoat/src/maxgoat.cc Sat Apr 19 07:56:43 2014 +0300 @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -11,9 +12,9 @@ #include "plugapi.h" #include "IGame.h" #include "IGameExport.h" +#include "IGameControl.h" #include "IConversionmanager.h" #include "goat3d.h" -#include "minwin.h" #include "config.h" #include "logger.h" #include "resource.h" @@ -31,9 +32,15 @@ #pragma comment (lib, "comctl32.lib") +#define COPYRIGHT \ + L"Copyright 2014 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details." #define VERSION(major, minor) \ ((major) * 100 + ((minor) < 10 ? (minor) * 10 : (minor))) +static INT_PTR CALLBACK scene_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); +static INT_PTR CALLBACK anim_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); +static const char *max_string(const MCHAR *wstr); + HINSTANCE hinst; class GoatExporter : public SceneExport { @@ -44,17 +51,6 @@ public: IGameScene *igame; - int ExtCount(); - const TCHAR *Ext(int n); - const TCHAR *LongDesc(); - const TCHAR *ShortDesc(); - const TCHAR *AuthorName(); - const TCHAR *CopyrightMessage(); - const TCHAR *OtherMessage1(); - const TCHAR *OtherMessage2(); - unsigned int Version(); - void ShowAbout(HWND win); - int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); void process_materials(goat3d *goat); @@ -64,96 +60,36 @@ void process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj); void process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj); void process_camera(goat3d *goat, goat3d_camera *cam, IGameObject *maxobj); + + + int ExtCount() { return 1; } + const TCHAR *Ext(int n) { return L"goatsce"; } + const TCHAR *LongDesc() { return L"Goat3D scene file"; } + const TCHAR *ShortDesc() { return L"Goat3D"; } + const TCHAR *AuthorName() { return L"John Tsiombikas"; } + const TCHAR *CopyrightMessage() { return COPYRIGHT; } + const TCHAR *OtherMessage1() { return L"other1"; } + const TCHAR *OtherMessage2() { return L"other2"; } + unsigned int Version() { return VERSION(VER_MAJOR, VER_MINOR); } + void ShowAbout(HWND win) { MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0); } }; +class GoatAnimExporter : public GoatExporter { +private: +public: + int DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent = FALSE, DWORD opt = 0); -int GoatExporter::ExtCount() -{ - return 1; -} + const TCHAR *Ext(int n) { return L"goatanm"; } + const TCHAR *LongDesc() { return L"Goat3D animation file"; } +}; -const TCHAR *GoatExporter::Ext(int n) -{ - return L"xml"; -} -const TCHAR *GoatExporter::LongDesc() -{ - return L"Goat3D scene file"; -} - -const TCHAR *GoatExporter::ShortDesc() -{ - return L"Goat3D"; -} - -const TCHAR *GoatExporter::AuthorName() -{ - return L"John Tsiombikas"; -} - -const TCHAR *GoatExporter::CopyrightMessage() -{ - return L"Copyright 2013 (C) John Tsiombikas - GNU General Public License v3, see COPYING for details."; -} - -const TCHAR *GoatExporter::OtherMessage1() -{ - return L"other1"; -} - -const TCHAR *GoatExporter::OtherMessage2() -{ - return L"other2"; -} - -unsigned int GoatExporter::Version() -{ - return VERSION(VER_MAJOR, VER_MINOR); -} - -void GoatExporter::ShowAbout(HWND win) -{ - MessageBoxA(win, "Goat3D exporter plugin", "About this plugin", 0); -} - -static INT_PTR CALLBACK handle_dlg_events(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) -{ - switch(msg) { - case WM_INITDIALOG: - CheckDlgButton(win, IDC_GOAT_NODES, 1); - CheckDlgButton(win, IDC_GOAT_MESHES, 1); - CheckDlgButton(win, IDC_GOAT_LIGHTS, 1); - CheckDlgButton(win, IDC_GOAT_CAMERAS, 1); - break; - - case WM_COMMAND: - switch(LOWORD(wparam)) { - case IDOK: - EndDialog(win, 1); - break; - - case IDCANCEL: - EndDialog(win, 0); - break; - - default: - return 0; - } - break; - - default: - return 0; - } - - return 1; -} +// ---- GoatExporter implementation ---- int GoatExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL non_interactive, DWORD opt) { - if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, handle_dlg_events)) { - maxlog("canceled!\n"); + if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_SCE), 0, scene_gui_handler)) { return IMPEXP_CANCEL; } @@ -162,6 +98,9 @@ char fname[512]; wcstombs(fname, name, sizeof fname - 1); + for(int i=0; fname[i]; i++) { + fname[i] = tolower(fname[i]); + } maxlog("Exporting Goat3D Scene (text) file: %s\n", fname); if(!(igame = GetIGameInterface())) { @@ -171,7 +110,6 @@ IGameConversionManager *cm = GetConversionManager(); cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); igame->InitialiseIGame(); - igame->SetStaticFrame(0); goat3d *goat = goat3d_create(); @@ -192,14 +130,6 @@ return IMPEXP_SUCCESS; } -static const char *max_string(const MCHAR *wstr) -{ - if(!wstr) return 0; - static char str[512]; - wcstombs(str, wstr, sizeof str - 1); - return str; -} - void GoatExporter::process_materials(goat3d *goat) { IGameProperty *prop; @@ -293,6 +223,10 @@ goat3d_node *node = goat3d_create_node(); goat3d_add_node(goat, node); + if(parent) { + goat3d_add_node_child(parent, node); + } + const char *name = max_string(maxnode->GetName()); if(name) { goat3d_set_node_name(node, name); @@ -356,7 +290,19 @@ // otherwise don't assign an object, essentially treating it as a null node break; } - + + // grab the animation data + IGameControl *ctrl = maxnode->GetIGameControl(); + + IGameKeyTab tm_keys; + if(ctrl->GetFullSampledKeys(tm_keys, 1, IGAME_TM)) { + maxlog("node: %s has %d keys\n", name, tm_keys.Count()); + /*for(int i=0; iGetChildCount(); i++) { process_node(goat, node, maxnode->GetNodeChild(i)); @@ -424,12 +370,117 @@ void GoatExporter::process_light(goat3d *goat, goat3d_light *light, IGameObject *maxobj) { + // TODO } void GoatExporter::process_camera(goat3d *goat, goat3d_camera *cam, IGameObject *maxobj) { + // TODO } +static INT_PTR CALLBACK scene_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) +{ + switch(msg) { + case WM_INITDIALOG: + CheckDlgButton(win, IDC_GOAT_NODES, 1); + CheckDlgButton(win, IDC_GOAT_MESHES, 1); + CheckDlgButton(win, IDC_GOAT_LIGHTS, 1); + CheckDlgButton(win, IDC_GOAT_CAMERAS, 1); + break; + + case WM_COMMAND: + switch(LOWORD(wparam)) { + case IDOK: + EndDialog(win, 1); + break; + + case IDCANCEL: + EndDialog(win, 0); + break; + + default: + return 0; + } + break; + + default: + return 0; + } + + return 1; +} + + + +// ---- GoatAnimExporter implementation ---- + +int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt) +{ + if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) { + return IMPEXP_CANCEL; + } + + char fname[512]; + wcstombs(fname, name, sizeof fname - 1); + for(int i=0; fname[i]; i++) { + fname[i] = tolower(fname[i]); + } + + maxlog("Exporting Goat3D Animation (text) file: %s\n", fname); + if(!(igame = GetIGameInterface())) { + maxlog("failed to get the igame interface\n"); + return IMPEXP_FAIL; + } + IGameConversionManager *cm = GetConversionManager(); + cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); + igame->InitialiseIGame(); + igame->SetStaticFrame(0); + + goat3d *goat = goat3d_create(); + + // process all nodes + for(int i=0; iGetTopLevelNodeCount(); i++) { + IGameNode *node = igame->GetTopLevelNode(i); + process_node(goat, 0, node); + } + + if(goat3d_save_anim(goat, fname) == -1) { + goat3d_free(goat); + return IMPEXP_FAIL; + } + + goat3d_free(goat); + return IMPEXP_SUCCESS; +} + +static INT_PTR CALLBACK anim_gui_handler(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) +{ + switch(msg) { + case WM_INITDIALOG: + CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1); + break; + + case WM_COMMAND: + switch(LOWORD(wparam)) { + case IDOK: + EndDialog(win, 1); + break; + + case IDCANCEL: + EndDialog(win, 0); + break; + + default: + return 0; + } + break; + + default: + return 0; + } + + return 1; +} // ------------------------------------------ @@ -446,8 +497,22 @@ HINSTANCE HInstance() { return hinst; } }; +class GoatAnimClassDesc : public ClassDesc2 { +public: + int IsPublic() { return TRUE; } + void *Create(BOOL loading = FALSE) { return new GoatAnimExporter; } + const TCHAR *ClassName() { return L"GoatAnimExporter"; } + SClass_ID SuperClassID() { return SCENE_EXPORT_CLASS_ID; } + Class_ID ClassID() { return Class_ID(0x51b94924, 0x2e0332f3); } + const TCHAR *Category() { return L"Mutant Stargoat"; } + + const TCHAR *InternalName() { return L"GoatAnimExporter"; } + HINSTANCE HInstance() { return hinst; } +}; + // TODO: make 2 class descriptors, one for goat3d, one for goat3danim static GoatClassDesc class_desc; +static GoatAnimClassDesc anim_class_desc; BOOL WINAPI DllMain(HINSTANCE inst_handle, ULONG reason, void *reserved) { @@ -472,7 +537,15 @@ __declspec(dllexport) ClassDesc *LibClassDesc(int i) { - return i == 0 ? &class_desc : 0; + switch(i) { + case 0: + return &class_desc; + case 1: + return &anim_class_desc; + default: + break; + } + return 0; } __declspec(dllexport) ULONG LibVersion() @@ -497,4 +570,13 @@ return TRUE; } -} // extern "C" \ No newline at end of file +} // extern "C" + + +static const char *max_string(const MCHAR *wstr) +{ + if(!wstr) return 0; + static char str[512]; + wcstombs(str, wstr, sizeof str - 1); + return str; +} \ No newline at end of file diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/src/minwin.cc --- a/exporters/maxgoat/src/minwin.cc Tue Apr 01 13:11:04 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,170 +0,0 @@ -#include -#include -#include "minwin.h" -#include "logger.h" - -#define GOATSCE_WCLASS "goatsce-window" - -struct MinWidget { - HWND win; - - MWCallback cbfunc; - void *cbcls; - - MinWidget() { win = 0; cbfunc = 0; cbcls = 0; } -}; - -static void init(); -static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name, - unsigned int style, int x, int y, int xsz, int ysz); -static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam); - -extern HINSTANCE hinst; // defined in maxgoat.cc - -void mw_set_callback(MinWidget *w, MWCallback func, void *cls) -{ - w->cbfunc = func; - w->cbcls = cls; -} - -MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz) -{ - unsigned int style = WS_OVERLAPPEDWINDOW | WS_VISIBLE; - if(parent) { - style |= WS_CHILD; - } - - maxlog("creating window: %s\n", name); - - MinWidget *w = createwin(parent, GOATSCE_WCLASS, name, style, x, y, xsz, ysz); - return w; -} - -MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz) -{ - unsigned int style = BS_PUSHBUTTON | WS_VISIBLE; - if(parent) { - style |= WS_CHILD; - } - - maxlog("creating button: %s\n", text); - - MinWidget *w = createwin(parent, "BUTTON", text, style, x, y, xsz, ysz); - return w; -} - -MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked) -{ - unsigned int style = BS_CHECKBOX | WS_VISIBLE; - if(parent) { - style |= WS_CHILD; - } - - maxlog("creating checkbox: %s\n", text); - - MinWidget *w = createwin(parent, "CHECKBOX", text, style, x, y, xsz, ysz); - return w; -} - -static DWORD WINAPI gui_thread_func(void *cls); - -void mw_test() -{ - init(); - - HANDLE thread = CreateThread(0, 0, gui_thread_func, 0, 0, 0); - //WaitForSingleObject(thread, 5000); -} - -static DWORD WINAPI gui_thread_func(void *cls) -{ - MinWidget *win = mw_create_window(0, "test window!", -1, -1, 400, 400); - MinWidget *bn_ok = mw_create_button(win, "Ok", 50, 100, 150, 40); - MinWidget *bn_cancel = mw_create_button(win, "Cancel", 250, 100, 150, 40); - MinWidget *ck_lights = mw_create_checkbox(win, "Export lights", 20, 20, 250, 40, true); - MinWidget *ck_cameras = mw_create_checkbox(win, "Export cameras", 20, 60, 250, 40, true); - - MSG msg; - while(GetMessage(&msg, win->win, 0, 0)) { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - - DestroyWindow(win->win); - delete bn_ok; - delete bn_cancel; - delete ck_lights; - delete ck_cameras; - delete win; - - return 0; -} - -static void init() -{ - static bool done_init; - if(done_init) { - return; - } - done_init = true; - - size_t sz = mbstowcs(0, GOATSCE_WCLASS, 0); - wchar_t *cname = new wchar_t[sz + 1]; - mbstowcs(cname, GOATSCE_WCLASS, sz + 1); - - WNDCLASS wc; - memset(&wc, 0, sizeof wc); - wc.lpszClassName = cname; - wc.hInstance = hinst; - wc.lpfnWndProc = handle_msg; - wc.style = CS_HREDRAW | CS_VREDRAW; - wc.hbrBackground = (HBRUSH)COLOR_WINDOW; - wc.hCursor = LoadCursor(0, IDC_ARROW); - - RegisterClass(&wc); -} - -static MinWidget *createwin(MinWidget *parent, const char *cls, const char *name, - unsigned int style, int x, int y, int xsz, int ysz) -{ - init(); - - MinWidget *w = new MinWidget; - - size_t sz = mbstowcs(0, cls, 0); - wchar_t *wcls = new wchar_t[sz + 1]; - mbstowcs(wcls, cls, sz + 1); - - sz = mbstowcs(0, name, 0); - wchar_t *wname = new wchar_t[sz + 1]; - mbstowcs(wname, name, sz + 1); - - if(x <= 0) x = CW_USEDEFAULT; - if(y <= 0) y = CW_USEDEFAULT; - - w->win = CreateWindow(wcls, wname, style, x, y, xsz, ysz, parent ? parent->win : 0, 0, hinst, 0); - - delete [] wcls; - delete [] wname; - - if(!w->win) { - delete w; - return 0; - } - return w; -} - - -static LRESULT CALLBACK handle_msg(HWND win, unsigned int msg, WPARAM wparam, LPARAM lparam) -{ - switch(msg) { - case WM_CLOSE: - DestroyWindow(win); - break; - - default: - return DefWindowProc(win, msg, wparam, lparam); - } - - return 0; -} \ No newline at end of file diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat/src/minwin.h --- a/exporters/maxgoat/src/minwin.h Tue Apr 01 13:11:04 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,15 +0,0 @@ -#ifndef MINWIN_H_ -#define MINWIN_H_ - -struct MinWidget; -typedef void (*MWCallback)(MinWidget*, void*); - -void mw_set_callback(MinWidget *w, MWCallback func, void *cls); - -MinWidget *mw_create_window(MinWidget *parent, const char *name, int x, int y, int xsz, int ysz); -MinWidget *mw_create_button(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz); -MinWidget *mw_create_checkbox(MinWidget *parent, const char *text, int x, int y, int xsz, int ysz, bool checked); - -void mw_test(); - -#endif // MINWIN_H_ \ No newline at end of file diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat_stub/maxgoat_stub.vcxproj --- a/exporters/maxgoat_stub/maxgoat_stub.vcxproj Tue Apr 01 13:11:04 2014 +0300 +++ b/exporters/maxgoat_stub/maxgoat_stub.vcxproj Sat Apr 19 07:56:43 2014 +0300 @@ -33,7 +33,7 @@ DynamicLibrary true - v100 + v110 Unicode @@ -46,7 +46,7 @@ DynamicLibrary false - v100 + v110 true Unicode @@ -105,7 +105,7 @@ true - copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle" + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2015)plugins\$(ProjectName).dle" @@ -143,7 +143,7 @@ true - copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2014)plugins\$(ProjectName).dle" + copy /Y "$(TargetPath)" "$(ADSK_3DSMAX_x64_2015)plugins\$(ProjectName).dle" diff -r cd7efb8757e1 -r 3751aabbc5b3 exporters/maxgoat_stub/src/stub.cc --- a/exporters/maxgoat_stub/src/stub.cc Tue Apr 01 13:11:04 2014 +0300 +++ b/exporters/maxgoat_stub/src/stub.cc Sat Apr 19 07:56:43 2014 +0300 @@ -143,7 +143,14 @@ goto done; } - result = ex->DoExport(name, eiface, iface); + __try { + result = ex->DoExport(name, eiface, iface); + } + __except(EXCEPTION_EXECUTE_HANDLER) { + fprintf(logfile, "Exception caught!\n"); + delete ex; + goto done; + } delete ex; if((shutdown = (PluginShutdownFunc)GetProcAddress(dll, "LibShutdown"))) { diff -r cd7efb8757e1 -r 3751aabbc5b3 goat3d.vcxproj --- a/goat3d.vcxproj Tue Apr 01 13:11:04 2014 +0300 +++ b/goat3d.vcxproj Sat Apr 19 07:56:43 2014 +0300 @@ -85,8 +85,8 @@ StaticLibrary true - v100 Unicode + v110 StaticLibrary @@ -98,9 +98,9 @@ StaticLibrary false - v100 true Unicode + v110 diff -r cd7efb8757e1 -r 3751aabbc5b3 src/goat3d.cc --- a/src/goat3d.cc Tue Apr 01 13:11:04 2014 +0300 +++ b/src/goat3d.cc Sat Apr 19 07:56:43 2014 +0300 @@ -780,7 +780,7 @@ GOAT3DAPI void goat3d_add_node_child(struct goat3d_node *node, struct goat3d_node *child) { - node->add_child(node); + node->add_child(child); } GOAT3DAPI int goat3d_get_node_child_count(const struct goat3d_node *node) diff -r cd7efb8757e1 -r 3751aabbc5b3 src/scene.cc --- a/src/scene.cc Tue Apr 01 13:11:04 2014 +0300 +++ b/src/scene.cc Sat Apr 19 07:56:43 2014 +0300 @@ -38,7 +38,7 @@ cameras.clear(); for(size_t i=0; ianm); child->parent = this;