# HG changeset patch # User John Tsiombikas # Date 1400125921 -10800 # Node ID 7941e89798e5dbf244e56fb39eb2194f8c0fe525 # Parent f0277d348c2c8e7f9169a8df9fbde7a7d3e2e84c selections diff -r f0277d348c2c -r 7941e89798e5 goatview/src/goatview.cc --- a/goatview/src/goatview.cc Wed May 14 18:28:38 2014 +0300 +++ b/goatview/src/goatview.cc Thu May 15 06:52:01 2014 +0300 @@ -11,6 +11,7 @@ goat3d *scene; static SceneModel *sdata; +static GoatViewport *glview; static long anim_time; static float cam_theta, cam_phi, cam_dist = 8; @@ -18,6 +19,11 @@ static bool use_nodes = true; static bool use_lighting = true; +void post_redisplay() +{ + glview->updateGL(); +} + GoatView::GoatView() { @@ -105,7 +111,7 @@ act_use_nodes->setCheckable(true); act_use_nodes->setChecked(use_nodes); connect(act_use_nodes, &QAction::triggered, this, - [&](){ use_nodes = !use_nodes; glview->updateGL(); }); + [&](){ use_nodes = !use_nodes; post_redisplay(); }); menu_view->addAction(act_use_nodes); QAction *act_use_lighting = new QAction("lighting", this); @@ -137,19 +143,17 @@ // make the tree view widget treeview = new QTreeView; - /* - scntree->setColumnCount(1); - QStringList hdrstr; - hdrstr << "Node";// << "Type"; - scntree->setHeaderItem(new QTreeWidgetItem((QTreeWidget*)0, hdrstr)); - */ treeview->setAlternatingRowColors(true); + treeview->setSelectionMode(QAbstractItemView::SingleSelection); dock_vbox->addWidget(treeview); scene_model = new SceneModel; - connect(scene_model, &SceneModel::dataChanged, [&](){ glview->updateGL(); }); + connect(scene_model, &SceneModel::dataChanged, [&](){ post_redisplay(); }); treeview->setModel(scene_model); + connect(treeview->selectionModel(), &QItemSelectionModel::selectionChanged, + [&](){ scene_model->selchange(treeview->selectionModel()->selectedIndexes()); }); + // misc QPushButton *bn_quit = new QPushButton("quit"); dock_vbox->addWidget(bn_quit); @@ -174,7 +178,7 @@ bool GoatView::make_center() { - glview = new GoatViewport(this); + glview = ::glview = new GoatViewport(this); setCentralWidget(glview); return true; } @@ -316,6 +320,43 @@ goat3d_mesh *mesh = (goat3d_mesh*)goat3d_get_node_object(node); draw_mesh(mesh); + + if(data->selected) { + float bmin[3], bmax[3]; + goat3d_get_mesh_bounds(mesh, bmin, bmax); + + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_LIGHTING); + + glColor3f(0.3, 1, 0.2); + + glBegin(GL_LINE_LOOP); + glVertex3f(bmin[0], bmin[1], bmin[2]); + glVertex3f(bmax[0], bmin[1], bmin[2]); + glVertex3f(bmax[0], bmin[1], bmax[2]); + glVertex3f(bmin[0], bmin[1], bmax[2]); + glEnd(); + + glBegin(GL_LINE_LOOP); + glVertex3f(bmin[0], bmax[1], bmin[2]); + glVertex3f(bmax[0], bmax[1], bmin[2]); + glVertex3f(bmax[0], bmax[1], bmax[2]); + glVertex3f(bmin[0], bmax[1], bmax[2]); + glEnd(); + + glBegin(GL_LINES); + glVertex3f(bmin[0], bmin[1], bmin[2]); + glVertex3f(bmin[0], bmax[1], bmin[2]); + glVertex3f(bmin[0], bmin[1], bmax[2]); + glVertex3f(bmin[0], bmax[1], bmax[2]); + glVertex3f(bmax[0], bmin[1], bmin[2]); + glVertex3f(bmax[0], bmax[1], bmin[2]); + glVertex3f(bmax[0], bmin[1], bmax[2]); + glVertex3f(bmax[0], bmax[1], bmax[2]); + glEnd(); + + glPopAttrib(); + } } } diff -r f0277d348c2c -r 7941e89798e5 goatview/src/goatview.h --- a/goatview/src/goatview.h Wed May 14 18:28:38 2014 +0300 +++ b/goatview/src/goatview.h Thu May 15 06:52:01 2014 +0300 @@ -7,11 +7,12 @@ #include "goat3d.h" #include "scenemodel.h" +void post_redisplay(); + extern goat3d *scene; class GoatViewport; - class GoatView : public QMainWindow { private: Q_OBJECT diff -r f0277d348c2c -r 7941e89798e5 goatview/src/scenemodel.cc --- a/goatview/src/scenemodel.cc Wed May 14 18:28:38 2014 +0300 +++ b/goatview/src/scenemodel.cc Thu May 15 06:52:01 2014 +0300 @@ -1,5 +1,6 @@ #include #include "scenemodel.h" +#include "goatview.h" SceneModel::SceneModel() { @@ -25,6 +26,7 @@ SceneNodeData data; data.visible = true; + data.selected = false; node_data[node] = data; } @@ -246,3 +248,25 @@ return createIndex(pidx, 0, (void*)parent); } + + +void SceneModel::selchange(const QModelIndexList &selidx) +{ + // go over the previously selected and unselect them + std::set::iterator it = selected.begin(); + while(it != selected.end()) { + goat3d_node *node = *it++; + SceneNodeData *data = get_node_data(node); + data->selected = false; + } + selected.clear(); + + for(int i=0; iselected = true; + selected.insert(node); + } + + post_redisplay(); +} diff -r f0277d348c2c -r 7941e89798e5 goatview/src/scenemodel.h --- a/goatview/src/scenemodel.h Wed May 14 18:28:38 2014 +0300 +++ b/goatview/src/scenemodel.h Thu May 15 06:52:01 2014 +0300 @@ -2,11 +2,13 @@ #define SCENEMODEL_H_ #include +#include #include #include "goat3d.h" struct SceneNodeData { bool visible; + bool selected; }; class SceneModel : public QAbstractItemModel { @@ -15,6 +17,7 @@ goat3d *scn; std::map node_data; + std::set selected; public: SceneModel(); @@ -34,6 +37,8 @@ bool hasChildren(const QModelIndex &parent) const; QModelIndex index(int row, int column, const QModelIndex &parent) const; QModelIndex parent(const QModelIndex &index) const; + + void selchange(const QModelIndexList &selidx); }; #endif // SCENEMODEL_H_ diff -r f0277d348c2c -r 7941e89798e5 src/goat3d.cc --- a/src/goat3d.cc Wed May 14 18:28:38 2014 +0300 +++ b/src/goat3d.cc Thu May 15 06:52:01 2014 +0300 @@ -676,6 +676,17 @@ im_use[GOAT3D_MESH_ATTR_COLOR] = true; } + +GOAT3DAPI void goat3d_get_mesh_bounds(const struct goat3d_mesh *mesh, float *bmin, float *bmax) +{ + AABox box = mesh->get_bounds(Matrix4x4::identity); + + for(int i=0; i<3; i++) { + bmin[i] = box.bmin[i]; + bmax[i] = box.bmax[i]; + } +} + /* lights */ GOAT3DAPI void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt) { @@ -934,6 +945,15 @@ node->get_node_xform(tmsec, (Matrix4x4*)matrix); } +GOAT3DAPI void goat3d_get_node_bounds(const struct goat3d_node *node, float *bmin, float *bmax) +{ + AABox box = node->get_bounds(); + + for(int i=0; i<3; i++) { + bmin[i] = box.bmin[i]; + bmax[i] = box.bmax[i]; + } +} } // extern "C" diff -r f0277d348c2c -r 7941e89798e5 src/goat3d.h --- a/src/goat3d.h Wed May 14 18:28:38 2014 +0300 +++ b/src/goat3d.h Thu May 15 06:52:01 2014 +0300 @@ -213,6 +213,8 @@ GOAT3DAPI void goat3d_color3f(float x, float y, float z); GOAT3DAPI void goat3d_color4f(float x, float y, float z, float w); +GOAT3DAPI void goat3d_get_mesh_bounds(const struct goat3d_mesh *mesh, float *bmin, float *bmax); + /* lights */ GOAT3DAPI void goat3d_add_light(struct goat3d *g, struct goat3d_light *lt); GOAT3DAPI int goat3d_get_light_count(struct goat3d *g); @@ -278,6 +280,8 @@ GOAT3DAPI void goat3d_get_node_matrix(const struct goat3d_node *node, float *matrix, long tmsec); +GOAT3DAPI void goat3d_get_node_bounds(const struct goat3d_node *node, float *bmin, float *bmax); + #ifdef __cplusplus } #endif