# HG changeset patch # User John Tsiombikas # Date 1399336295 -10800 # Node ID 36e39632db75c1d65cda3e08f0988d49c8dc575b # Parent 39d8457e43dfa6069c5864acdfe523ce9022ab3a - fixed exporter animation bounds calculation - fixed missing scene name in exported meshes - rewritting goatview as a full GUI app with Qt diff -r 39d8457e43df -r 36e39632db75 exporters/maxgoat/src/maxgoat.cc --- a/exporters/maxgoat/src/maxgoat.cc Mon Apr 21 03:44:42 2014 +0300 +++ b/exporters/maxgoat/src/maxgoat.cc Tue May 06 03:31:35 2014 +0300 @@ -107,6 +107,10 @@ for(int i=0; fname[i]; i++) { fname[i] = tolower(fname[i]); } + char *basename = (char*)alloca(strlen(fname) + 1); + strcpy(basename, fname); + char *suffix = strrchr(basename, '.'); + if(suffix) *suffix = 0; maxlog("Exporting Goat3D Scene (text) file: %s\n", fname); if(!(igame = GetIGameInterface())) { @@ -118,6 +122,7 @@ igame->InitialiseIGame(); goat3d *goat = goat3d_create(); + goat3d_set_name(goat, basename); process_materials(goat); @@ -288,8 +293,6 @@ } // grab the animation data - IGameControl *ctrl = maxnode->GetIGameControl(); - if(!dynamic_cast(this)) { // no animation, just get the static PRS GMatrix maxmatrix = maxnode->GetObjectTM(); @@ -304,16 +307,21 @@ } else { // exporting animations (if available) // TODO sample keys if requested - if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || - ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { - get_position_keys(ctrl, node); - } - if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || - ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { - get_rotation_keys(ctrl, node); - } - if(ctrl->IsAnimated(IGAME_SCALE)) { - get_scaling_keys(ctrl, node); + IGameControl *ctrl = maxnode->GetIGameControl(); + if(ctrl) { + if(ctrl->IsAnimated(IGAME_POS) || ctrl->IsAnimated(IGAME_POS_X) || + ctrl->IsAnimated(IGAME_POS_Y) || ctrl->IsAnimated(IGAME_POS_Z)) { + get_position_keys(ctrl, node); + } + if(ctrl->IsAnimated(IGAME_ROT) || ctrl->IsAnimated(IGAME_EULER_X) || + ctrl->IsAnimated(IGAME_EULER_Y) || ctrl->IsAnimated(IGAME_EULER_Z)) { + get_rotation_keys(ctrl, node); + } + if(ctrl->IsAnimated(IGAME_SCALE)) { + get_scaling_keys(ctrl, node); + } + } else { + maxlog("%s: failed to get IGameControl for node: %s\n", __FUNCTION__, name); } } @@ -496,13 +504,13 @@ } } -#if 0 static bool get_anim_bounds(IGameNode *node, long *tstart, long *tend); +static bool get_node_anim_bounds(IGameNode *node, long *tstart, long *tend); static bool get_anim_bounds(IGameScene *igame, long *tstart, long *tend) { - int tmin = LONG_MAX; - int tmax = LONG_MIN; + long tmin = LONG_MAX; + long tmax = LONG_MIN; int num_nodes = igame->GetTopLevelNodeCount(); for(int i=0; iGetChildCount(); for(int i=0; iGetIGameObject(); + IGameControl *ctrl = node->GetIGameControl(); + if(!ctrl) { + maxlog("%s: failed to get IGameControl for node: %s\n", __FUNCTION__, max_string(node->GetName())); + return false; + } + + IGameKeyTab keys; + long t0, t1; + long tmin = LONG_MAX; + long tmax = LONG_MIN; + + for(int i=0; iGetBezierKeys(keys, ctypes[i]) && keys.Count()) { + t0 = KEY_TIME(keys[0]); + t1 = KEY_TIME(keys[keys.Count() - 1]); + if(t0 < tmin) tmin = t0; + if(t1 > tmax) tmax = t1; + } + if(ctrl->GetLinearKeys(keys, ctypes[i]) && keys.Count()) { + t0 = KEY_TIME(keys[0]); + t1 = KEY_TIME(keys[keys.Count() - 1]); + if(t0 < tmin) tmin = t0; + if(t1 > tmax) tmax = t1; + } + if(ctrl->GetTCBKeys(keys, ctypes[i]) && keys.Count()) { + t0 = KEY_TIME(keys[0]); + t1 = KEY_TIME(keys[keys.Count() - 1]); + if(t0 < tmin) tmin = t0; + if(t1 > tmax) tmax = t1; + } + } + + if(tmin != LONG_MAX) { + *tstart = tmin; + *tend = tmax; + return true; + } + return false; +} void GoatExporter::process_mesh(goat3d *goat, goat3d_mesh *mesh, IGameObject *maxobj) { @@ -648,6 +707,7 @@ // ---- GoatAnimExporter implementation ---- +static long tstart, tend; int GoatAnimExporter::DoExport(const MCHAR *name, ExpInterface *eiface, Interface *iface, BOOL silent, DWORD opt) { @@ -658,9 +718,10 @@ IGameConversionManager *cm = GetConversionManager(); cm->SetCoordSystem(IGameConversionManager::IGAME_OGL); igame->InitialiseIGame(); + igame->SetStaticFrame(0); - //long tstart = 0, tend = 0; - //get_anim_bounds(igame, &tstart, &tend); + tstart = tend = 0; + get_anim_bounds(igame, &tstart, &tend); if(!DialogBox(hinst, MAKEINTRESOURCE(IDD_GOAT_ANM), 0, anim_gui_handler)) { igame->ReleaseIGame(); @@ -674,7 +735,6 @@ } maxlog("Exporting Goat3D Animation (text) file: %s\n", fname); - igame->SetStaticFrame(0); goat3d *goat = goat3d_create(); @@ -699,8 +759,15 @@ { switch(msg) { case WM_INITDIALOG: - CheckDlgButton(win, IDC_GOAT_ANM_FULL, 1); - CheckDlgButton(win, IDC_RAD_KEYS_ORIG, 1); + { + wchar_t buf[128]; + CheckDlgButton(win, IDC_GOAT_ANM_FULL, BST_CHECKED); + CheckDlgButton(win, IDC_RAD_KEYS_ORIG, BST_CHECKED); + wsprintf(buf, L"%ld", tstart); + SetDlgItemText(win, IDC_EDIT_TSTART, buf); + wsprintf(buf, L"%ld", tend); + SetDlgItemText(win, IDC_EDIT_TEND, buf); + } break; case WM_COMMAND: diff -r 39d8457e43df -r 36e39632db75 goat3d-vs2012.sln --- a/goat3d-vs2012.sln Mon Apr 21 03:44:42 2014 +0300 +++ b/goat3d-vs2012.sln Tue May 06 03:31:35 2014 +0300 @@ -10,6 +10,8 @@ EndProject Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "maxgoat_stub", "exporters\maxgoat_stub\maxgoat_stub.vcxproj", "{941007A1-6375-4507-8745-FC3EA9DF010B}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "goatview", "goatview\goatview.vcxproj", "{26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Mixed Platforms = Debug|Mixed Platforms @@ -55,6 +57,17 @@ {941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.ActiveCfg = Release|Win32 {941007A1-6375-4507-8745-FC3EA9DF010B}.Release|Win32.Build.0 = Release|Win32 {941007A1-6375-4507-8745-FC3EA9DF010B}.Release|x64.ActiveCfg = Release|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|Mixed Platforms.ActiveCfg = Debug|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|Mixed Platforms.Build.0 = Debug|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|Win32.ActiveCfg = Debug|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|Win32.Build.0 = Debug|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|x64.ActiveCfg = Debug|x64 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Debug|x64.Build.0 = Debug|x64 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Release|Mixed Platforms.ActiveCfg = Release|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Release|Mixed Platforms.Build.0 = Release|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Release|Win32.ActiveCfg = Release|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Release|Win32.Build.0 = Release|Win32 + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A}.Release|x64.ActiveCfg = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff -r 39d8457e43df -r 36e39632db75 goatview/goatview.vcxproj --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goatview/goatview.vcxproj Tue May 06 03:31:35 2014 +0300 @@ -0,0 +1,181 @@ + + + + + Debug + Win32 + + + Debug + x64 + + + Release + Win32 + + + Release + x64 + + + + {26EB2DC7-B2FF-4587-95CD-5DF70287FA0A} + Win32Proj + goatview + + + + Application + true + v110 + Unicode + + + Application + true + v110 + Unicode + + + Application + false + v110 + true + Unicode + + + Application + false + v110 + true + Unicode + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + qtmaind.lib;Qt5Cored.lib;Qt5Widgetsd.lib;Qt5OpenGLd.lib;opengl32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + + + + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions) + + + Console + true + true + true + qtmain.lib;Qt5Widgets.lib;Qt5OpenGL.lib;opengl32.lib;%(AdditionalDependencies) + + + + + + + + + + + + + + Running MOC on src\goatview.h ... + moc.exe src\goatview.h -o src\moc_goatview.cc + src\moc_goatview.cc + + + + ClCompile + Link + + \ No newline at end of file diff -r 39d8457e43df -r 36e39632db75 goatview/goatview.vcxproj.filters --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goatview/goatview.vcxproj.filters Tue May 06 03:31:35 2014 +0300 @@ -0,0 +1,36 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + {a278f8f5-22fd-495a-a96f-0b1a9964828b} + + + + + Source Files + + + Source Files + + + moc + + + + + Header Files + + + \ No newline at end of file diff -r 39d8457e43df -r 36e39632db75 goatview/src/goatview.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goatview/src/goatview.cc Tue May 06 03:31:35 2014 +0300 @@ -0,0 +1,117 @@ +#include "goatview.h" + +GoatView::GoatView() +{ + make_menu(); + make_dock(); + make_center(); + + statusBar(); + + setWindowTitle("GoatView"); +} + +GoatView::~GoatView() +{ +} + +bool GoatView::make_menu() +{ + QMenu *menu_file = menuBar()->addMenu("&File"); + + QAction *act_open_sce = new QAction("&Open Scene", this); + act_open_sce->setShortcuts(QKeySequence::Open); + connect(act_open_sce, &QAction::triggered, this, &GoatView::open_scene); + menu_file->addAction(act_open_sce); + + QAction *act_open_anm = new QAction("Open &Animation", this); + connect(act_open_anm, &QAction::triggered, this, &GoatView::open_anim); + menu_file->addAction(act_open_anm); + + QAction *act_quit = new QAction("&Quit", this); + act_quit->setShortcuts(QKeySequence::Quit); + connect(act_quit, &QAction::triggered, [&](){qApp->quit();}); + menu_file->addAction(act_quit); + return true; +} + +bool GoatView::make_dock() +{ + // ---- side-dock ---- + QWidget *dock_cont = new QWidget; + QVBoxLayout *dock_vbox = new QVBoxLayout; + dock_cont->setLayout(dock_vbox); + + QPushButton *bn_quit = new QPushButton("quit"); + dock_vbox->addWidget(bn_quit); + connect(bn_quit, &QPushButton::clicked, [&](){qApp->quit();}); + + QDockWidget *dock = new QDockWidget("Scene graph", this); + dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); + dock->setWidget(dock_cont); + addDockWidget(Qt::LeftDockWidgetArea, dock); + + // ---- bottom dock ---- + dock_cont = new QWidget; + QHBoxLayout *dock_hbox = new QHBoxLayout; + dock_cont->setLayout(dock_hbox); + + QSlider *slider_time = new QSlider(Qt::Orientation::Horizontal); + slider_time->setDisabled(true); + dock_hbox->addWidget(slider_time); + + dock = new QDockWidget("Animation", this); + dock->setAllowedAreas(Qt::BottomDockWidgetArea); + dock->setWidget(dock_cont); + addDockWidget(Qt::BottomDockWidgetArea, dock); + + return true; +} + +bool GoatView::make_center() +{ + GoatViewport *vport = new GoatViewport; + setCentralWidget(vport); + return true; +} + +void GoatView::open_scene() +{ + statusBar()->showMessage("opening scene..."); +} + +void GoatView::open_anim() +{ + statusBar()->showMessage("opening animation..."); +} + + +// ---- OpenGL viewport ---- +GoatViewport::GoatViewport() + : QGLWidget(QGLFormat(QGL::DepthBuffer)) +{ +} + +GoatViewport::~GoatViewport() +{ +} + +QSize GoatViewport::sizeHint() const +{ + return QSize(800, 600); +} + +void GoatViewport::initializeGL() +{ +} + +void GoatViewport::resizeGL(int xsz, int ysz) +{ + glViewport(0, 0, xsz, ysz); +} + +void GoatViewport::paintGL() +{ + glClearColor(1, 0, 0, 1); + glClear(GL_COLOR_BUFFER_BIT); +} \ No newline at end of file diff -r 39d8457e43df -r 36e39632db75 goatview/src/goatview.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goatview/src/goatview.h Tue May 06 03:31:35 2014 +0300 @@ -0,0 +1,36 @@ +#ifndef GOATVIEW_H_ +#define GOATVIEW_H_ + +#include +#include + +class GoatView : public QMainWindow { + Q_OBJECT +private: + bool make_menu(); + bool make_dock(); + bool make_center(); + +private slots: + void open_scene(); + void open_anim(); + +public: + GoatView(); + ~GoatView(); +}; + +class GoatViewport : public QGLWidget { + Q_OBJECT +public: + GoatViewport(); + ~GoatViewport(); + + QSize sizeHint() const; + + void initializeGL(); + void resizeGL(int xsz, int ysz); + void paintGL(); +}; + +#endif // GOATVIEW_H_ \ No newline at end of file diff -r 39d8457e43df -r 36e39632db75 goatview/src/main.c --- a/goatview/src/main.c Mon Apr 21 03:44:42 2014 +0300 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,220 +0,0 @@ -#include -#include -#include -#ifndef __APPLE__ -#include -#else -#include -#endif -#include "goat3d.h" - -static void cleanup(void); -static void disp(void); -static void draw_scene(struct goat3d *g); -static void draw_mesh(struct goat3d_mesh *mesh); -static void reshape(int x, int y); -static void keyb(unsigned char key, int x, int y); -static void mouse(int bn, int st, int x, int y); -static void motion(int x, int y); - -static struct goat3d *goat; -static float cam_theta, cam_phi, cam_dist = 10; - -int main(int argc, char **argv) -{ - int i, nmeshes; - - glutInitWindowSize(800, 600); - glutInit(&argc, argv); - - if(!argv[1]) { - fprintf(stderr, "you must specify a goat3d scene file to open\n"); - return 1; - } - - if(!(goat = goat3d_create())) { - fprintf(stderr, "failed to create goat3d\n"); - return 1; - } - if(goat3d_load(goat, argv[1]) == -1) { - fprintf(stderr, "failed to load goat3d scene: %s\n", argv[1]); - goat3d_free(goat); - return 1; - } - - nmeshes = goat3d_get_mesh_count(goat); - printf("loaded %d meshes\n", nmeshes); - for(i=0; i 90) cam_phi = 90; - glutPostRedisplay(); - } - if(bnstate[2]) { - cam_dist += dy * 0.1; - - if(cam_dist < 0) cam_dist = 0; - glutPostRedisplay(); - } -} diff -r 39d8457e43df -r 36e39632db75 goatview/src/main.cc --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/goatview/src/main.cc Tue May 06 03:31:35 2014 +0300 @@ -0,0 +1,12 @@ +#include +#include "goatview.h" + +int main(int argc, char **argv) +{ + QApplication app(argc, argv); + + GoatView gview; + gview.show(); + + return app.exec(); +} \ No newline at end of file diff -r 39d8457e43df -r 36e39632db75 src/goat3d.cc --- a/src/goat3d.cc Mon Apr 21 03:44:42 2014 +0300 +++ b/src/goat3d.cc Tue May 06 03:31:35 2014 +0300 @@ -56,7 +56,6 @@ goat->flags = 0; goat->search_path = 0; goat->scn = new Scene; - goat->scn->goat = goat; goat3d_setopt(goat, GOAT3D_OPT_SAVEXML, 1); return goat;