diff --git a/ui/zenoedit/nodesys/zenosubgraphscene.cpp b/ui/zenoedit/nodesys/zenosubgraphscene.cpp index 35f3089b2d..789d3c4eb4 100644 --- a/ui/zenoedit/nodesys/zenosubgraphscene.cpp +++ b/ui/zenoedit/nodesys/zenosubgraphscene.cpp @@ -48,6 +48,9 @@ ZenoSubGraphScene::ZenoSubGraphScene(QObject *parent) // bsp tree index causes crash when removeItem and delete item. for safety, disable it. // https://stackoverflow.com/questions/38458830/crash-after-qgraphicssceneremoveitem-with-custom-item-class setItemIndexMethod(QGraphicsScene::NoIndex); + connect(this, &ZenoSubGraphScene::selectionChanged, this, [=]() { + afterSelectionChanged(); + }); } ZenoSubGraphScene::~ZenoSubGraphScene() @@ -1015,6 +1018,7 @@ void ZenoSubGraphScene::onRowsAboutToBeRemoved(const QModelIndex& subgIdx, const QString id = idx.data(ROLE_OBJID).toString(); ZASSERT_EXIT(m_nodes.find(id) != m_nodes.end()); ZenoNode* pNode = m_nodes[id]; + pNode->setSelected(false); if (qobject_cast(pNode)) { GroupNode *pBlackboard = qobject_cast(pNode); diff --git a/ui/zenoedit/viewport/cameracontrol.cpp b/ui/zenoedit/viewport/cameracontrol.cpp index 2978c63ba2..3ee954ef05 100644 --- a/ui/zenoedit/viewport/cameracontrol.cpp +++ b/ui/zenoedit/viewport/cameracontrol.cpp @@ -668,7 +668,7 @@ void CameraControl::fakeMouseReleaseEvent(QMouseEvent *event) { } else { m_picker->pick(releasePos.x(), releasePos.y()); m_picker->sync_to_scene(); - if (scene->select_mode == zenovis::PICK_MODE::PICK_OBJECT) + if (scene->get_select_mode() == zenovis::PICK_MODE::PICK_OBJECT) onPrimSelected(); m_transformer->clear(); m_transformer->addObject(m_picker->get_picked_prims()); @@ -703,7 +703,7 @@ void CameraControl::fakeMouseReleaseEvent(QMouseEvent *event) { m_picker->pick(x0, y0, x1, y1, mode); m_picker->sync_to_scene(); - if (scene->select_mode == zenovis::PICK_MODE::PICK_OBJECT) + if (scene->get_select_mode() == zenovis::PICK_MODE::PICK_OBJECT) onPrimSelected(); m_transformer->clear(); m_transformer->addObject(m_picker->get_picked_prims()); diff --git a/ui/zenoedit/viewport/displaywidget.cpp b/ui/zenoedit/viewport/displaywidget.cpp index 920d3dfe8d..5a01efa4ef 100644 --- a/ui/zenoedit/viewport/displaywidget.cpp +++ b/ui/zenoedit/viewport/displaywidget.cpp @@ -1337,11 +1337,11 @@ void DisplayWidget::onNodeSelected(const QModelIndex &subgIdx, const QModelIndex // read selected mode auto select_mode_str = zeno::NodeSyncMgr::GetInstance().getInputValString(nodes[0], "mode"); if (select_mode_str == "triangle") - scene->select_mode = zenovis::PICK_MODE::PICK_MESH; + scene->set_select_mode(zenovis::PICK_MODE::PICK_MESH); else if (select_mode_str == "line") - scene->select_mode = zenovis::PICK_MODE::PICK_LINE; + scene->set_select_mode(zenovis::PICK_MODE::PICK_LINE); else - scene->select_mode = zenovis::PICK_MODE::PICK_VERTEX; + scene->set_select_mode(zenovis::PICK_MODE::PICK_VERTEX); // read selected elements string node_context; auto node_selected_str = zeno::NodeSyncMgr::GetInstance().getParamValString(nodes[0], "selected"); @@ -1353,7 +1353,7 @@ void DisplayWidget::onNodeSelected(const QModelIndex &subgIdx, const QModelIndex node_context += prim_name + ":" + e.toStdString() + " "; if (picker) - picker->load_from_str(node_context, scene->select_mode, zeno::SELECTION_MODE::NORMAL); + picker->load_from_str(node_context, scene->get_select_mode(), zeno::SELECTION_MODE::NORMAL); } if (picker) { picker->sync_to_scene(); @@ -1365,6 +1365,10 @@ void DisplayWidget::onNodeSelected(const QModelIndex &subgIdx, const QModelIndex picker->sync_to_scene(); picker->focus(""); picker->set_picked_elems_callback({}); + { + picker->clear(); + scene->set_select_mode(zenovis::PICK_MODE::PICK_OBJECT); + } } } zenoApp->getMainWindow()->updateViewport(); diff --git a/ui/zenoedit/viewportinteraction/picker.cpp b/ui/zenoedit/viewportinteraction/picker.cpp index 2f9714d141..43ded13b37 100644 --- a/ui/zenoedit/viewportinteraction/picker.cpp +++ b/ui/zenoedit/viewportinteraction/picker.cpp @@ -108,7 +108,7 @@ void Picker::pick(int x, int y) { // scene->select_mode = zenovis::PICK_MODE::PICK_MESH; auto selected = picker->getPicked(x, y); - if (scene->select_mode == zenovis::PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == zenovis::PICK_MODE::PICK_OBJECT) { if (selected.empty()) { selected_prims.clear(); return; @@ -150,7 +150,7 @@ void Picker::pick(int x0, int y0, int x1, int y1, SELECTION_MODE mode) { ZASSERT_EXIT(scene); auto selected = picker->getPicked(x0, y0, x1, y1); // qDebug() << "pick: " << selected.c_str(); - if (scene->select_mode == zenovis::PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == zenovis::PICK_MODE::PICK_OBJECT) { if (selected.empty()) { selected_prims.clear(); return; @@ -158,7 +158,7 @@ void Picker::pick(int x0, int y0, int x1, int y1, SELECTION_MODE mode) { load_from_str(selected, zenovis::PICK_MODE::PICK_OBJECT, SELECTION_MODE::NORMAL); } else { - load_from_str(selected, scene->select_mode, mode); + load_from_str(selected, scene->get_select_mode(), mode); if (picked_elems_callback) picked_elems_callback(selected_elements); } } @@ -177,10 +177,10 @@ string Picker::just_pick_prim(int x, int y) { auto scene = this->scene(); ZASSERT_EXIT(scene, ""); - auto store_mode = scene->select_mode; - scene->select_mode = zenovis::PICK_MODE::PICK_OBJECT; + auto store_mode = scene->get_select_mode(); + scene->set_select_mode(zenovis::PICK_MODE::PICK_OBJECT); auto res = picker->getPicked(x, y); - scene->select_mode = store_mode; + scene->set_select_mode(store_mode); return res; } @@ -252,7 +252,7 @@ void Picker::save_context() { auto scene = this->scene(); ZASSERT_EXIT(scene); - select_mode_context = scene->select_mode; + select_mode_context = scene->get_select_mode(); selected_prims_context = std::move(selected_prims); selected_elements_context = std::move(selected_elements); } @@ -263,7 +263,7 @@ void Picker::load_context() { auto scene = this->scene(); ZASSERT_EXIT(scene); - scene->select_mode = select_mode_context; + scene->set_select_mode(select_mode_context); selected_prims = std::move(selected_prims_context); selected_elements = std::move(selected_elements_context); select_mode_context = zenovis::PICK_MODE::PICK_NONE; diff --git a/zenovis/include/zenovis/Scene.h b/zenovis/include/zenovis/Scene.h index 2d379bc035..45f358bd0c 100644 --- a/zenovis/include/zenovis/Scene.h +++ b/zenovis/include/zenovis/Scene.h @@ -30,7 +30,6 @@ enum class PICK_MODE { struct Scene : zeno::disable_copy { std::optional select_box = {}; std::unordered_set selected = {}; - PICK_MODE select_mode = PICK_MODE::PICK_OBJECT; std::unordered_map> selected_elements = {}; std::unique_ptr camera; std::unique_ptr drawOptions; @@ -50,6 +49,10 @@ struct Scene : zeno::disable_copy { bool cameraFocusOnNode(std::string const &nodeid, zeno::vec3f ¢er, float &radius); static void loadGLAPI(void *procaddr); void* getOptixImg(int &w, int &h); + void set_select_mode(PICK_MODE _select_mode); + PICK_MODE get_select_mode(); +private: + PICK_MODE select_mode = PICK_MODE::PICK_OBJECT; }; } // namespace zenovis diff --git a/zenovis/src/Scene.cpp b/zenovis/src/Scene.cpp index 11df211415..c54654e662 100644 --- a/zenovis/src/Scene.cpp +++ b/zenovis/src/Scene.cpp @@ -15,6 +15,7 @@ #ifdef ZENO_ENABLE_OPTIX #include "../xinxinoptix/xinxinoptixapi.h" #endif +//#include #include #include @@ -113,6 +114,13 @@ bool Scene::loadFrameObjects(int frameid) { return inserted; } +void Scene::set_select_mode(PICK_MODE _select_mode) { +// zeno::log_info("{} -> {}", magic_enum::enum_name(select_mode), magic_enum::enum_name(_select_mode)); + select_mode = _select_mode; +} +PICK_MODE Scene::get_select_mode() { + return select_mode; +} void Scene::draw(bool record) { if (renderMan->getDefaultEngineName() != "optx") { diff --git a/zenovis/src/bate/FrameBufferPicker.cpp b/zenovis/src/bate/FrameBufferPicker.cpp index c414589810..c0e8ffafc3 100644 --- a/zenovis/src/bate/FrameBufferPicker.cpp +++ b/zenovis/src/bate/FrameBufferPicker.cpp @@ -309,7 +309,7 @@ struct FrameBufferPicker : IPicker { vbo->attribute(0, sizeof(float) * 0, sizeof(float) * 3, GL_FLOAT, 3); bool pick_particle = false; - if (scene->select_mode == PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == PICK_MODE::PICK_OBJECT) { pick_particle = prim->tris->empty() && prim->quads->empty() && prim->polys->empty() && prim->loops->empty(); CHECK_GL(glEnable(GL_DEPTH_TEST)); CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)); @@ -343,7 +343,7 @@ struct FrameBufferPicker : IPicker { CHECK_GL(glDisable(GL_DEPTH_TEST)); } - if (scene->select_mode == PICK_MODE::PICK_VERTEX || pick_particle) { + if (scene->get_select_mode() == PICK_MODE::PICK_VERTEX || pick_particle) { // ----- enable depth test ----- CHECK_GL(glEnable(GL_DEPTH_TEST)); CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)); @@ -387,7 +387,7 @@ struct FrameBufferPicker : IPicker { CHECK_GL(glDisable(GL_DEPTH_TEST)); } - if (scene->select_mode == PICK_MODE::PICK_LINE) { + if (scene->get_select_mode() == PICK_MODE::PICK_LINE) { // ----- enable depth test ----- CHECK_GL(glEnable(GL_DEPTH_TEST)); CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)); @@ -454,7 +454,7 @@ struct FrameBufferPicker : IPicker { CHECK_GL(glDisable(GL_DEPTH_TEST)); } - if (scene->select_mode == PICK_MODE::PICK_MESH) { + if (scene->get_select_mode() == PICK_MODE::PICK_MESH) { // ----- enable depth test ----- CHECK_GL(glEnable(GL_DEPTH_TEST)); CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)); @@ -541,7 +541,7 @@ struct FrameBufferPicker : IPicker { fbo->unbind(); string result; - if (scene->select_mode == PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == PICK_MODE::PICK_OBJECT) { if (!pixel.has_object() || !id_table.count(pixel.obj_id)) return ""; result = id_table[pixel.obj_id]; } @@ -594,7 +594,7 @@ struct FrameBufferPicker : IPicker { fbo->unbind(); string result; - if (scene->select_mode == PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == PICK_MODE::PICK_OBJECT) { unordered_set selected_obj; // fetch selected objects' ids for (int i = 0; i < pixel_count; i++) { diff --git a/zenovis/src/bate/HudGraphicPrimHighlight.cpp b/zenovis/src/bate/HudGraphicPrimHighlight.cpp index 833dcc5028..1e6cbee273 100644 --- a/zenovis/src/bate/HudGraphicPrimHighlight.cpp +++ b/zenovis/src/bate/HudGraphicPrimHighlight.cpp @@ -75,7 +75,7 @@ struct PrimitiveHighlight : IGraphicDraw { CHECK_GL(glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE)); glDepthFunc(GL_GREATER); CHECK_GL(glClearDepth(0.0)); - if (scene->select_mode == PICK_MODE::PICK_OBJECT) { + if (scene->get_select_mode() == PICK_MODE::PICK_OBJECT) { for (const auto &prim_id : scene->selected) { // ----- get primitive ----- PrimitiveObject *prim = nullptr; @@ -143,7 +143,7 @@ struct PrimitiveHighlight : IGraphicDraw { vbo->attribute(0, sizeof(float) * 0, sizeof(float) * 3, GL_FLOAT, 3); // ----- draw selected vertices ----- - if (scene->select_mode == PICK_MODE::PICK_VERTEX) { + if (scene->get_select_mode() == PICK_MODE::PICK_VERTEX) { // prepare indices CHECK_GL(glEnable(GL_PROGRAM_POINT_SIZE)); vector ind(selected_count); @@ -159,7 +159,7 @@ struct PrimitiveHighlight : IGraphicDraw { } // ----- draw selected edges ----- - if (scene->select_mode == PICK_MODE::PICK_LINE) { + if (scene->get_select_mode() == PICK_MODE::PICK_LINE) { if (prim->lines->empty()) return; // prepare indices vector ind(selected_count); @@ -175,7 +175,7 @@ struct PrimitiveHighlight : IGraphicDraw { } // ----- draw selected meshes ----- - if (scene->select_mode == PICK_MODE::PICK_MESH) { + if (scene->get_select_mode() == PICK_MODE::PICK_MESH) { // prepare indices vector ind(selected_count); int i = 0;