Commit 11a5e11c authored by TheNumbat's avatar TheNumbat
Browse files

more halfedge updates

parent 7a98a7a1
......@@ -88,7 +88,7 @@ bool Manager::keydown(Undo &undo, SDL_Keysym key, Scene &scene, Camera &cam) {
return true;
case SDLK_f: {
if (mode == Mode::rig) {
cam.look_at(Vec3{}, -cam.front() * cam.dist());
cam.look_at(Vec3{}, cam.front() - cam.dist());
return true;
} else if (layout.selected()) {
frame(scene, cam);
......
......@@ -65,6 +65,12 @@ void Model::update_vertex(Halfedge_Mesh::VertexRef vert) {
size_t idx = id_to_info[h->face()->id()].instance;
face_viz(h->face(), face_mesh.edit_verts(), face_mesh.edit_indices(), idx);
Halfedge_Mesh::HalfedgeRef fh = h->face()->halfedge();
do {
halfedge_viz(fh, arrows.get(id_to_info[fh->id()].instance).transform);
fh = fh->next();
} while (fh != h->face()->halfedge());
h = h->twin()->next();
} while (h != vert->halfedge());
......@@ -283,10 +289,20 @@ void Model::halfedge_viz(Halfedge_Mesh::HalfedgeRef h, Mat4 &transform) {
float v0s = vert_sizes[v_0->id()], v1s = vert_sizes[v_1->id()];
float s = 0.3f * (v0s < v1s ? v0s : v1s);
// Move to center of edge and away from edge
// Move to center of edge and towards center of face
Vec3 offset = (v1 - v0) * 0.2f;
Vec3 face_n = h->face()->normal();
offset += cross(face_n, dir).unit() * s * 0.2f + face_n * s * 0.05f;
Vec3 base = h->face()->halfedge()->vertex()->pos;
if(base == v0) {
base = h->next()->next()->vertex()->pos;
} else if(base == v1) {
Halfedge_Mesh::HalfedgeRef hf = h;
do { hf = hf->next(); } while(hf->next() != h);
base = hf->vertex()->pos;
}
Vec3 face_n = cross(base - v0, base - v1).unit();
offset += cross(face_n, dir).unit() * s * 0.2f;
// Align edge
if (dir.y == 1.0f || dir.y == -1.0f) {
......@@ -553,12 +569,20 @@ void Model::zoom_to(Halfedge_Mesh::ElementRef ref, Camera &cam) {
float d = cam.dist();
Vec3 center = Halfedge_Mesh::center_of(ref);
Vec3 pos = center - my_mesh->normal_of(ref) * d;
Vec3 pos = center + my_mesh->normal_of(ref) * d;
cam.look_at(center, pos);
}
std::string Model::UIsidebar(Undo &undo, Widgets &widgets, Scene_Maybe obj_opt, Camera &camera) {
if(ImGui::CollapsingHeader("Edit Colors")) {
ImGui::ColorEdit3("Face", f_col.data);
ImGui::ColorEdit3("Vertex", v_col.data);
ImGui::ColorEdit3("Edge", e_col.data);
ImGui::ColorEdit3("Halfedge", he_col.data);
}
ImGui::Separator();
if (!obj_opt.has_value())
return {};
......@@ -752,7 +776,10 @@ void Model::render(Scene_Maybe obj_opt, Widgets &widgets, Camera &cam) {
Renderer::HalfedgeOpt opts(*this);
opts.modelview = view;
opts.color = obj.material.layout_color();
opts.v_color = v_col;
opts.f_color = f_col;
opts.e_color = e_col;
opts.he_color = he_col;
Renderer::get().halfedge_editor(opts);
auto elem = selected_element();
......
......@@ -72,6 +72,7 @@ private:
Transform_Data trans_begin;
GL::Instances spheres, cylinders, arrows;
GL::Mesh face_mesh;
Vec3 f_col = Vec3{1.0f}, v_col = Vec3{1.0f}, e_col = Vec3{0.8f}, he_col = Vec3{0.6f};
// This all needs to be updated when the mesh connectivity changes
unsigned int selected_elem_id = UINT32_MAX, hovered_elem_id = UINT32_MAX;
......
......@@ -264,7 +264,7 @@ void Renderer::halfedge_editor(Renderer::HalfedgeOpt opt) {
MeshOpt fopt = MeshOpt();
fopt.modelview = opt.modelview;
fopt.color = opt.color;
fopt.color = opt.f_color;
fopt.per_vert_id = true;
fopt.sel_color = Gui::Color::outline;
fopt.sel_id = opt.editor.select_id();
......@@ -278,14 +278,16 @@ void Renderer::halfedge_editor(Renderer::HalfedgeOpt opt) {
inst_shader.uniform("solid", false);
inst_shader.uniform("proj", _proj);
inst_shader.uniform("modelview", opt.modelview);
inst_shader.uniform("color", opt.color);
inst_shader.uniform("alpha", fopt.alpha);
inst_shader.uniform("sel_color", Gui::Color::outline);
inst_shader.uniform("hov_color", Gui::Color::hover);
inst_shader.uniform("sel_id", fopt.sel_id);
inst_shader.uniform("hov_id", fopt.hov_id);
inst_shader.uniform("color", opt.v_color);
spheres.render();
inst_shader.uniform("color", opt.e_color);
cylinders.render();
inst_shader.uniform("color", opt.he_color);
arrows.render();
}
......@@ -44,7 +44,10 @@ public:
HalfedgeOpt(Gui::Model &e) : editor(e) {}
Gui::Model &editor;
Mat4 modelview;
Vec3 color;
Vec3 f_color = Vec3{1.0f};
Vec3 v_color = Vec3{1.0f};
Vec3 e_color = Vec3{0.8f};
Vec3 he_color = Vec3{0.6f};
};
// NOTE(max): updates & uses the indices in mesh for selection/traversal
......
......@@ -22,7 +22,10 @@ void Camera::look_at(Vec3 cent, Vec3 pos) {
position = pos;
looking_at = cent;
radius = (pos - cent).norm();
rot = Quat::euler(Mat4::rotate_z_to(front()).to_euler());
if(dot(front(), UP) == -1.0f)
rot = Quat::euler(Vec3{270.0f, 0.0f, 0.0f});
else
rot = Quat::euler(Mat4::rotate_z_to(front()).to_euler());
update_pos();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment