# HG changeset patch # User John Tsiombikas # Date 1399835094 -10800 # Node ID 70b7c41a4f178032b22f0464ae2c6889fb54a815 # Parent 7458b8568463c18dbc018c09021c45021ff19126 foo diff -r 7458b8568463 -r 70b7c41a4f17 goatview/Makefile --- a/goatview/Makefile Thu May 08 23:05:29 2014 +0300 +++ b/goatview/Makefile Sun May 11 22:04:54 2014 +0300 @@ -10,7 +10,7 @@ goat_root = .. -CFLAGS = -pedantic -Wall -g $(pic) -I$(goat_root)/src $(qtinc) +CFLAGS = -Wall -Wno-cpp -g $(pic) -I$(goat_root)/src $(qtinc) CXXFLAGS = -std=c++11 $(CFLAGS) LDFLAGS = $(libgoat) $(libgl) $(qtlib) -lvmath MOC = moc diff -r 7458b8568463 -r 70b7c41a4f17 goatview/src/goatview.cc --- a/goatview/src/goatview.cc Thu May 08 23:05:29 2014 +0300 +++ b/goatview/src/goatview.cc Sun May 11 22:04:54 2014 +0300 @@ -1,20 +1,47 @@ #include +#include "opengl.h" #include -#include "opengl.h" #include #include "goatview.h" #include "goat3d.h" +static void update_tree(QTreeWidget *tree); +static void add_tree(QTreeWidget *tree, goat3d_node *node, QTreeWidgetItem *parent); + static void draw_node(goat3d_node *node); +static void draw_mesh(goat3d_mesh *mesh); goat3d *scene; -QSettings *settings; static long anim_time; static float cam_theta, cam_phi, cam_dist = 8; static float fov = 60.0; +static bool use_nodes = true; -bool load_scene(const char *fname) + +GoatView::GoatView() +{ + glview = 0; + + make_menu(); + make_dock(); + make_center(); + + statusBar(); + + setWindowTitle("GoatView"); + + QSettings *settings = new QSettings; + resize(settings->value("main/size", QSize(1024, 768)).toSize()); + move(settings->value("main/pos", QPoint(100, 100)).toPoint()); + delete settings; +} + +GoatView::~GoatView() +{ +} + +bool GoatView::load_scene(const char *fname) { if(scene) { goat3d_free(scene); @@ -24,39 +51,27 @@ } float bmin[3], bmax[3]; - goat3d_get_bounds(scene, bmin, bmax); - float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length(); - cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0) + bsize; + if(goat3d_get_bounds(scene, bmin, bmax) != -1) { + float bsize = (Vector3(bmax[0], bmax[1], bmax[2]) - Vector3(bmin[0], bmin[1], bmin[2])).length(); + cam_dist = bsize / tan(DEG_TO_RAD(fov) / 2.0) + bsize; + printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist); + } - printf("bounds size: %f, cam_dist: %f\n", bsize, cam_dist); + update_tree(scntree); return true; } -GoatView::GoatView() -{ - make_menu(); - make_dock(); - make_center(); - - statusBar(); - - setWindowTitle("GoatView"); - resize(settings->value("main/size", QSize(1024, 768)).toSize()); - move(settings->value("main/pos", QPoint(100, 100)).toPoint()); -} - -GoatView::~GoatView() -{ -} - void GoatView::closeEvent(QCloseEvent *ev) { + QSettings *settings = new QSettings; settings->setValue("main/size", size()); settings->setValue("main/pos", pos()); + delete settings; } bool GoatView::make_menu() { + // file menu QMenu *menu_file = menuBar()->addMenu("&File"); QAction *act_open_sce = new QAction("&Open Scene", this); @@ -72,6 +87,15 @@ act_quit->setShortcuts(QKeySequence::Quit); connect(act_quit, &QAction::triggered, [&](){qApp->quit();}); menu_file->addAction(act_quit); + + // view menu + QMenu *menu_view = menuBar()->addMenu("&View"); + + QAction *act_use_nodes = new QAction("use nodes", this); + act_use_nodes->setCheckable(true); + act_use_nodes->setChecked(use_nodes); + connect(act_use_nodes, &QAction::triggered, this, [&](){use_nodes = !use_nodes; glview->updateGL();}); + menu_view->addAction(act_use_nodes); return true; } @@ -82,15 +106,27 @@ 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); + // make the tree view widget + scntree = new QTreeWidget; + scntree->setColumnCount(1); + QStringList hdrstr; + hdrstr << "Node";// << "Type"; + scntree->setHeaderItem(new QTreeWidgetItem((QTreeWidget*)0, hdrstr)); + scntree->setAlternatingRowColors(true); + dock_vbox->addWidget(scntree); + + update_tree(scntree); + + // misc + QPushButton *bn_quit = new QPushButton("quit"); + dock_vbox->addWidget(bn_quit); + connect(bn_quit, &QPushButton::clicked, [&](){qApp->quit();}); + // ---- bottom dock ---- dock_cont = new QWidget; QHBoxLayout *dock_hbox = new QHBoxLayout; @@ -110,8 +146,8 @@ bool GoatView::make_center() { - GoatViewport *vport = new GoatViewport; - setCentralWidget(vport); + glview = new GoatViewport(this); + setCentralWidget(glview); return true; } @@ -135,11 +171,48 @@ statusBar()->showMessage("opening animation..."); } +static void update_tree(QTreeWidget *tree) +{ + if(!scene) return; + + int num_nodes = goat3d_get_node_count(scene); + for(int i=0; iexpandAll(); +} + +static void add_tree(QTreeWidget *tree, goat3d_node *node, QTreeWidgetItem *parent) +{ + //char icon_name[64]; + //sprintf(icon_name, ":/icons/icons/icon_%s.png", node->get_type()); + + QStringList row; + row << goat3d_get_node_name(node) << "M"; + QTreeWidgetItem *item = new QTreeWidgetItem(parent, row); + //item->setIcon(0, QIcon(icon_name)); + tree->addTopLevelItem(item); + + int num_children = goat3d_get_node_child_count(node); + for(int i=0; imain_win = main_win; + initialized = false; } GoatViewport::~GoatViewport() @@ -151,10 +224,24 @@ return QSize(800, 600); } +#define CRITICAL(error, detail) \ + do { \ + fprintf(stderr, "%s: %s\n", error, detail); \ + QMessageBox::critical(main_win, error, detail); \ + abort(); \ + } while(0) + void GoatViewport::initializeGL() { + if(initialized) return; + initialized = true; + init_opengl(); + if(!GLEW_ARB_transpose_matrix) { + CRITICAL("OpenGL initialization failed", "ARB_transpose_matrix extension not found!"); + } + glClearColor(0.1f, 0.1f, 0.1f, 1.0f); glEnable(GL_DEPTH_TEST); @@ -179,61 +266,39 @@ glRotatef(cam_phi, 1, 0, 0); glRotatef(cam_theta, 0, 1, 0); - if(scene) { + if(!scene) return; + + if(use_nodes) { int node_count = goat3d_get_node_count(scene); for(int i=0; i +#define QT_NO_OPENGL_ES_2 #ifdef WIN32 #include @@ -25,4 +26,4 @@ } #endif -#endif /* OPENGL_G_ */ +#endif /* OPENGL_H_ */ diff -r 7458b8568463 -r 70b7c41a4f17 src/aabox.cc --- a/src/aabox.cc Thu May 08 23:05:29 2014 +0300 +++ b/src/aabox.cc Sun May 11 22:04:54 2014 +0300 @@ -14,6 +14,16 @@ { } +bool AABox::operator ==(const AABox &rhs) const +{ + return bmin == rhs.bmin && bmax == rhs.bmax; +} + +bool AABox::operator !=(const AABox &rhs) const +{ + return !(*this == rhs); +} + AABox g3dimpl::aabox_union(const AABox &a, const AABox &b) { Vector3 bmin, bmax; diff -r 7458b8568463 -r 70b7c41a4f17 src/aabox.h --- a/src/aabox.h Thu May 08 23:05:29 2014 +0300 +++ b/src/aabox.h Sun May 11 22:04:54 2014 +0300 @@ -11,6 +11,9 @@ AABox(); AABox(const Vector3 &b0, const Vector3 &b1); + + bool operator ==(const AABox &rhs) const; + bool operator !=(const AABox &rhs) const; }; AABox aabox_union(const AABox &a, const AABox &b); diff -r 7458b8568463 -r 70b7c41a4f17 src/goat3d.cc --- a/src/goat3d.cc Thu May 08 23:05:29 2014 +0300 +++ b/src/goat3d.cc Sun May 11 22:04:54 2014 +0300 @@ -253,13 +253,18 @@ return &g->scn->get_ambient().x; } -GOAT3DAPI void goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax) +GOAT3DAPI int goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax) { AABox bbox = g->scn->get_bounds(); + if(bbox == AABox()) { + return -1; + } + for(int i=0; i<3; i++) { bmin[i] = bbox.bmin[i]; bmax[i] = bbox.bmax[i]; } + return 0; } // ---- materials ---- @@ -926,7 +931,7 @@ GOAT3DAPI void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec) { - node->get_xform(tmsec, (Matrix4x4*)matrix); + node->get_node_xform(tmsec, (Matrix4x4*)matrix); } diff -r 7458b8568463 -r 70b7c41a4f17 src/goat3d.h --- a/src/goat3d.h Thu May 08 23:05:29 2014 +0300 +++ b/src/goat3d.h Sun May 11 22:04:54 2014 +0300 @@ -123,7 +123,7 @@ GOAT3DAPI void goat3d_set_ambient3f(struct goat3d *g, float ar, float ag, float ab); GOAT3DAPI const float *goat3d_get_ambient(const struct goat3d *g); -GOAT3DAPI void goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax); +GOAT3DAPI int goat3d_get_bounds(const struct goat3d *g, float *bmin, float *bmax); /* materials */ GOAT3DAPI void goat3d_add_mtl(struct goat3d *g, struct goat3d_material *mtl); diff -r 7458b8568463 -r 70b7c41a4f17 src/goat3d_writexml.cc --- a/src/goat3d_writexml.cc Thu May 08 23:05:29 2014 +0300 +++ b/src/goat3d_writexml.cc Sun May 11 22:04:54 2014 +0300 @@ -33,6 +33,8 @@ bool Scene::savexml(goat3d_io *io) const { + xmlout(io, 0, "\n"); + xmlout(io, 0, "\n"); xmlout(io, 0, "\n"); // write environment stuff @@ -62,6 +64,8 @@ bool Scene::save_anim_xml(goat3d_io *io) const { + xmlout(io, 0, "\n"); + xmlout(io, 0, "\n"); xmlout(io, 0, "\n"); if(!nodes.empty()) {