From 54d4bc2abad662e89827a71bcd7a058190f8cc39 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sun, 17 May 2020 11:40:48 +0200 Subject: [PATCH] Added Source Geometry properties. Started implementing Layers View. --- ImGuiToolkit.cpp | 6 ++++++ ImGuiToolkit.h | 1 + ImGuiVisitor.cpp | 29 ++++++++++++++++------------- Mesh.cpp | 34 +++++++++++++++++----------------- Mesh.h | 5 +++-- PickingVisitor.cpp | 3 ++- Primitives.cpp | 7 +++++-- Source.cpp | 28 ++++++++++++++++++++-------- UserInterfaceManager.cpp | 2 ++ View.cpp | 21 +++++++++++++++++++++ View.h | 15 +++++++++++++++ defines.h | 1 + 12 files changed, 109 insertions(+), 43 deletions(-) diff --git a/ImGuiToolkit.cpp b/ImGuiToolkit.cpp index 01ac20b..c61f0cb 100644 --- a/ImGuiToolkit.cpp +++ b/ImGuiToolkit.cpp @@ -797,6 +797,12 @@ void ImGuiToolkit::ShowStats(bool *p_open, int* p_corner) ImGui::End(); } +ImVec4 ImGuiToolkit::GetHighlightColor() +{ + ImVec4* colors = ImGui::GetStyle().Colors; + return colors[ImGuiCol_CheckMark]; +} + void ImGuiToolkit::SetAccentColor(accent_color color) { ImVec4* colors = ImGui::GetStyle().Colors; diff --git a/ImGuiToolkit.h b/ImGuiToolkit.h index 2ec3371..fe4076d 100644 --- a/ImGuiToolkit.h +++ b/ImGuiToolkit.h @@ -49,6 +49,7 @@ namespace ImGuiToolkit ACCENT_GREY } accent_color; void SetAccentColor(accent_color color); + struct ImVec4 GetHighlightColor(); void ShowStats(bool* p_open, int* p_corner); diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index b6b0428..607d26c 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -31,9 +31,9 @@ void ImGuiVisitor::visit(Node &n) void ImGuiVisitor::visit(Group &n) { - std::string id = std::to_string(n.id()); - if (ImGui::TreeNode(id.c_str(), "Group %d", n.id())) - { +// std::string id = std::to_string(n.id()); +// if (ImGui::TreeNode(id.c_str(), "Group %d", n.id())) +// { // MODEL VIEW if (ImGuiToolkit::ButtonIcon(6, 15)) { n.translation_.x = 0.f; @@ -41,6 +41,7 @@ void ImGuiVisitor::visit(Group &n) } ImGui::SameLine(0, 10); float translation[2] = { n.translation_.x, n.translation_.y}; + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); if ( ImGui::SliderFloat2("position", translation, -5.0, 5.0) ) { n.translation_.x = translation[0]; @@ -50,6 +51,7 @@ void ImGuiVisitor::visit(Group &n) if (ImGuiToolkit::ButtonIcon(4, 15)) n.rotation_.z = 0.f; ImGui::SameLine(0, 10); + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); ImGui::SliderAngle("angle", &(n.rotation_.z), -180.f, 180.f) ; if (ImGuiToolkit::ButtonIcon(3, 15)) { @@ -57,20 +59,21 @@ void ImGuiVisitor::visit(Group &n) n.scale_.y = 1.f; } ImGui::SameLine(0, 10); - float scale = n.scale_.y; - if ( ImGui::SliderFloat("scale", &scale, 0.1f, 10.f, "%.3f", 3.f) ) + float scale[2] = { n.scale_.x, n.scale_.y} ; + ImGui::SetNextItemWidth(IMGUI_RIGHT_ALIGN); + if ( ImGui::SliderFloat2("scale", scale, -5.0, 5.0, "%.2f") ) { - n.scale_.x = scale; - n.scale_.y = scale; + n.scale_.x = scale[0]; + n.scale_.y = scale[1]; } - // loop over members of a group - for (NodeSet::iterator node = n.begin(); node != n.end(); node++) { - (*node)->accept(*this); - } +// // loop over members of a group +// for (NodeSet::iterator node = n.begin(); node != n.end(); node++) { +// (*node)->accept(*this); +// } - ImGui::TreePop(); - } +// ImGui::TreePop(); +// } } void ImGuiVisitor::visit(Switch &n) diff --git a/Mesh.cpp b/Mesh.cpp index d8924b9..20d4311 100644 --- a/Mesh.cpp +++ b/Mesh.cpp @@ -387,7 +387,7 @@ Frame::Frame(Type style) : Node() color = glm::vec4( 1.f, 1.f, 1.f, 1.f); switch (style) { case SHARP_LARGE: - border_ = new Mesh("mesh/border_large_sharp.ply"); + border_ = nullptr; //new Mesh("mesh/border_large_sharp.ply"); shadow_ = new Mesh("mesh/shadow.ply", "images/shadow.png"); break; case SHARP_THIN: @@ -429,25 +429,25 @@ void Frame::draw(glm::mat4 modelview, glm::mat4 projection) if(shadow_) shadow_->draw( modelview * transform_, projection); - - // right side - float ar = scale_.x / scale_.y; - glm::vec3 s(1.f, 1.f, 1.f); -// glm::vec3 s(scale_.y, scale_.y, 1.0); - glm::vec3 t(translation_.x - 1.0 + ar, translation_.y, translation_.z); - glm::mat4 ctm = modelview * GlmToolkit::transform(t, rotation_, s); - if(border_) { // right side - border_->shader()->color = color; - border_->draw( ctm, projection ); - // left side - t.x = -t.x; - s.x = -s.x; - ctm = modelview * GlmToolkit::transform(t, rotation_, s); - border_->draw( ctm, projection ); - } + float ar = scale_.x / scale_.y; + glm::vec3 s(1.f, 1.f, 1.f); + // glm::vec3 s(scale_.y, scale_.y, 1.0); + glm::vec3 t(translation_.x - 1.0 + ar, translation_.y, translation_.z); + glm::mat4 ctm = modelview * GlmToolkit::transform(t, rotation_, s); + if(border_) { + // right side + border_->shader()->color = color; + border_->draw( ctm, projection ); + // left side + t.x = -t.x; + s.x = -s.x; + ctm = modelview * GlmToolkit::transform(t, rotation_, s); + border_->draw( ctm, projection ); + } + } // enable antialiasing glDisable(GL_MULTISAMPLE_ARB); } diff --git a/Mesh.h b/Mesh.h index 5bc963d..0afc8f4 100644 --- a/Mesh.h +++ b/Mesh.h @@ -63,15 +63,16 @@ public: Handles(Type type); ~Handles(); + void update (float dt) override; void draw (glm::mat4 modelview, glm::mat4 projection) override; void accept (Visitor& v) override; Type type() const { return type_; } - Mesh *handle() const { return handle_; } + Primitive *handle() const { return handle_; } glm::vec4 color; protected: - Mesh *handle_; + Primitive *handle_; Type type_; }; diff --git a/PickingVisitor.cpp b/PickingVisitor.cpp index d11656a..6199983 100644 --- a/PickingVisitor.cpp +++ b/PickingVisitor.cpp @@ -65,7 +65,8 @@ void PickingVisitor::visit(Surface &n) void PickingVisitor::visit(Frame &n) { - n.border()->accept(*this); + if (n.border()) + n.border()->accept(*this); } void PickingVisitor::visit(Handles &n) diff --git a/Primitives.cpp b/Primitives.cpp index 696040a..aaafb7f 100644 --- a/Primitives.cpp +++ b/Primitives.cpp @@ -251,12 +251,15 @@ void LineStrip::draw(glm::mat4 modelview, glm::mat4 projection) init(); glLineWidth(linewidth_); - glEnable(GL_LINE_SMOOTH); +// glEnable(GL_LINE_SMOOTH); + // enable antialiasing + glEnable(GL_MULTISAMPLE_ARB); Primitive::draw(modelview, projection); glLineWidth(1); - glDisable(GL_LINE_SMOOTH); + glDisable(GL_MULTISAMPLE_ARB); +// glDisable(GL_LINE_SMOOTH); } void LineStrip::accept(Visitor& v) diff --git a/Source.cpp b/Source.cpp index 051a58c..5543592 100644 --- a/Source.cpp +++ b/Source.cpp @@ -27,7 +27,7 @@ Source::Source(const std::string &name) : name_(name), initialized_(false) groups_[View::MIXING] = new Group; Frame *frame = new Frame(Frame::ROUND_THIN); frame->translation_.z = 0.1; - frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 0.9f); + frame->color = glm::vec4( COLOR_DEFAULT_SOURCE, 0.9f); groups_[View::MIXING]->attach(frame); groups_[View::MIXING]->scale_ = glm::vec3(0.15f, 0.15f, 1.f); @@ -40,7 +40,7 @@ Source::Source(const std::string &name) : name_(name), initialized_(false) groups_[View::GEOMETRY] = new Group; frame = new Frame(Frame::SHARP_THIN); frame->translation_.z = 0.1; - frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 0.9f); + frame->color = glm::vec4( COLOR_DEFAULT_SOURCE, 0.9f); groups_[View::GEOMETRY]->attach(frame); overlays_[View::GEOMETRY] = new Group; @@ -48,6 +48,13 @@ Source::Source(const std::string &name) : name_(name), initialized_(false) overlays_[View::GEOMETRY]->visible_ = false; groups_[View::GEOMETRY]->attach(overlays_[View::GEOMETRY]); + // default mixing nodes + groups_[View::LAYER] = new Group; + overlays_[View::LAYER] = new Group; + overlays_[View::LAYER]->translation_.z = 0.15; + overlays_[View::LAYER]->visible_ = false; + groups_[View::LAYER]->attach(overlays_[View::LAYER]); + // will be associated to nodes later blendingshader_ = new ImageShader; rendershader_ = new ImageProcessingShader; @@ -70,6 +77,7 @@ Source::~Source() delete groups_[View::RENDERING]; delete groups_[View::MIXING]; delete groups_[View::GEOMETRY]; + delete groups_[View::LAYER]; groups_.clear(); @@ -119,6 +127,9 @@ bool hasNode::operator()(const Source* elem) const if (sv.found()) return true; elem->group(View::RENDERING)->accept(sv); + if (sv.found()) + return sv.found(); + elem->group(View::LAYER)->accept(sv); return sv.found(); } @@ -139,27 +150,27 @@ MediaSource::MediaSource(const std::string &name) : Source(name), path_("") // extra overlay for mixing view Frame *frame = new Frame(Frame::ROUND_LARGE); frame->translation_.z = 0.1; - frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + frame->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); overlays_[View::MIXING]->attach(frame); // extra overlays for geometry view frame = new Frame(Frame::SHARP_LARGE); - frame->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + frame->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); overlays_[View::GEOMETRY]->attach(frame); resize_handle_ = new Handles(Handles::RESIZE); - resize_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + resize_handle_->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); resize_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_handle_); resize_H_handle_ = new Handles(Handles::RESIZE_H); - resize_H_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + resize_H_handle_->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); resize_H_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_H_handle_); resize_V_handle_ = new Handles(Handles::RESIZE_V); - resize_V_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + resize_V_handle_->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); resize_V_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(resize_V_handle_); rotate_handle_ = new Handles(Handles::ROTATE); - rotate_handle_->color = glm::vec4( 0.8f, 0.8f, 0.0f, 1.f); + rotate_handle_->color = glm::vec4( COLOR_DEFAULT_SOURCE, 1.f); rotate_handle_->translation_.z = 0.1; overlays_[View::GEOMETRY]->attach(rotate_handle_); @@ -222,6 +233,7 @@ void MediaSource::init() groups_[View::RENDERING]->attach(rendersurface_); groups_[View::GEOMETRY]->attach(rendersurface_); groups_[View::MIXING]->attach(rendersurface_); + groups_[View::LAYER]->attach(rendersurface_); // for mixing view, add another surface to overlay (for stippled view in transparency) Surface *surfacemix = new FrameBufferSurface(renderbuffer_); diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index d7f816d..9c6a4c9 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -1049,6 +1049,8 @@ void Navigator::RenderSourcePannel(Source *s) ImGui::Image((void*)(uintptr_t) s->frame()->texture(), imagesize); // image processing pannel s->processingShader()->accept(v); + ImGui::Text("Geometry"); + s->groupNode(View::GEOMETRY)->accept(v); // delete button ImGui::Text(" "); if ( ImGui::Button("Delete", ImVec2(ImGui::GetContentRegionAvail().x, 0)) ) { diff --git a/View.cpp b/View.cpp index 6a68673..1647950 100644 --- a/View.cpp +++ b/View.cpp @@ -349,3 +349,24 @@ void GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick) +{ + +} + diff --git a/View.h b/View.h index d1e4be5..bc1d987 100644 --- a/View.h +++ b/View.h @@ -79,5 +79,20 @@ private: }; +class LayersView : public View +{ +public: + LayersView(); + ~LayersView(); + + void draw () override; + void zoom (float factor) override; + void drag (glm::vec2 from, glm::vec2 to) override; + void grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick) override; + +private: + +}; + #endif // VIEW_H diff --git a/defines.h b/defines.h index 34136a7..bafe1e2 100644 --- a/defines.h +++ b/defines.h @@ -36,6 +36,7 @@ #define COLOR_BGROUND 0.2f, 0.2f, 0.2f #define COLOR_NAVIGATOR 0.1f, 0.1f, 0.1f +#define COLOR_DEFAULT_SOURCE 1.f, 1.f, 1.f // from glmixer #define TEXTURE_REQUIRED_MAXIMUM 2048