Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix-selectmode-when-delete #1928

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui/zenoedit/nodesys/zenosubgraphscene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<GroupNode *>(pNode))
{
GroupNode *pBlackboard = qobject_cast<GroupNode *>(pNode);
Expand Down
4 changes: 2 additions & 2 deletions ui/zenoedit/viewport/cameracontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down
12 changes: 8 additions & 4 deletions ui/zenoedit/viewport/displaywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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();
Expand All @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions ui/zenoedit/viewportinteraction/picker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -150,15 +150,15 @@ 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;
}
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);
}
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion zenovis/include/zenovis/Scene.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ enum class PICK_MODE {
struct Scene : zeno::disable_copy {
std::optional<zeno::vec4f> select_box = {};
std::unordered_set<std::string> selected = {};
PICK_MODE select_mode = PICK_MODE::PICK_OBJECT;
std::unordered_map<std::string, std::unordered_set<int>> selected_elements = {};
std::unique_ptr<Camera> camera;
std::unique_ptr<DrawOptions> drawOptions;
Expand All @@ -50,6 +49,10 @@ struct Scene : zeno::disable_copy {
bool cameraFocusOnNode(std::string const &nodeid, zeno::vec3f &center, 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
8 changes: 8 additions & 0 deletions zenovis/src/Scene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#ifdef ZENO_ENABLE_OPTIX
#include "../xinxinoptix/xinxinoptixapi.h"
#endif
//#include <magic_enum.hpp>
#include <cstdlib>
#include <map>

Expand Down Expand Up @@ -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")
{
Expand Down
12 changes: 6 additions & 6 deletions zenovis/src/bate/FrameBufferPicker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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];
}
Expand Down Expand Up @@ -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<unsigned int> selected_obj;
// fetch selected objects' ids
for (int i = 0; i < pixel_count; i++) {
Expand Down
8 changes: 4 additions & 4 deletions zenovis/src/bate/HudGraphicPrimHighlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<int> ind(selected_count);
Expand All @@ -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<vec2i> ind(selected_count);
Expand All @@ -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<vec3i> ind(selected_count);
int i = 0;
Expand Down
Loading