From 569a097c4a47437d06b937b35a72c3b76b638c6c Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Sun, 17 May 2020 13:29:27 +0200 Subject: [PATCH] Initial implementation of Layer view (not effective, but integrated in mixer). --- FrameBuffer.cpp | 2 +- ImGuiVisitor.cpp | 69 +++++++++++++++++++++++----------------- Mesh.cpp | 5 +-- Mixer.cpp | 22 ++++++++++--- Mixer.h | 1 + Session.cpp | 1 + SessionCreator.cpp | 1 + Source.cpp | 7 +++- UserInterfaceManager.cpp | 3 +- View.cpp | 46 ++++++++++++++++++++++----- View.h | 6 ++-- 11 files changed, 111 insertions(+), 52 deletions(-) diff --git a/FrameBuffer.cpp b/FrameBuffer.cpp index af8b720..2168239 100644 --- a/FrameBuffer.cpp +++ b/FrameBuffer.cpp @@ -84,7 +84,7 @@ uint FrameBuffer::texture() const float FrameBuffer::aspectRatio() const { - return static_cast(width()) / static_cast(height()); + return static_cast(attrib_.viewport.x) / static_cast(attrib_.viewport.y); } diff --git a/ImGuiVisitor.cpp b/ImGuiVisitor.cpp index 607d26c..b02cd6d 100644 --- a/ImGuiVisitor.cpp +++ b/ImGuiVisitor.cpp @@ -35,37 +35,48 @@ void ImGuiVisitor::visit(Group &n) // if (ImGui::TreeNode(id.c_str(), "Group %d", n.id())) // { // MODEL VIEW - if (ImGuiToolkit::ButtonIcon(6, 15)) { - n.translation_.x = 0.f; - n.translation_.y = 0.f; - } - 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]; - n.translation_.y = translation[1]; - } - 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(1, 16)) { + n.translation_.x = 0.f; + n.translation_.y = 0.f; + n.rotation_.z = 0.f; + n.scale_.x = 1.f; + n.scale_.y = 1.f; + } + ImGui::SameLine(0, 10); + ImGui::Text("Geometry"); - if (ImGuiToolkit::ButtonIcon(3, 15)) { - n.scale_.x = 1.f; - n.scale_.y = 1.f; - } - ImGui::SameLine(0, 10); - 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[0]; - n.scale_.y = scale[1]; - } + if (ImGuiToolkit::ButtonIcon(6, 15)) { + n.translation_.x = 0.f; + n.translation_.y = 0.f; + } + 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]; + n.translation_.y = translation[1]; + } + + if (ImGuiToolkit::ButtonIcon(18, 9)) + 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)) { + n.scale_.x = 1.f; + n.scale_.y = 1.f; + } + ImGui::SameLine(0, 10); + 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[0]; + n.scale_.y = scale[1]; + } // // loop over members of a group // for (NodeSet::iterator node = n.begin(); node != n.end(); node++) { diff --git a/Mesh.cpp b/Mesh.cpp index 20d4311..bdcd3ff 100644 --- a/Mesh.cpp +++ b/Mesh.cpp @@ -466,10 +466,9 @@ Handles::Handles(Type type) : Node(), type_(type) if ( type_ == ROTATE ) { handle_ = new Mesh("mesh/border_handles_rotation.ply"); -// handle_->scale_ = glm::vec3( 0.01f, 0.01f, 1.f); } else { - handle_ = new LineSquare(color, 3); + handle_ = new LineSquare(color, 2); handle_->scale_ = glm::vec3( 0.05f, 0.05f, 1.f); } // handle_ = new Mesh("mesh/border_handles_overlay.ply"); @@ -499,7 +498,6 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) // set color handle_->shader()->color = color; -// handle_->scale_ = glm::vec3( 0.01f, 0.01f, 1.f); glm::mat4 ctm; @@ -535,7 +533,6 @@ void Handles::draw(glm::mat4 modelview, glm::mat4 projection) } else if ( type_ == ROTATE ){ // only once in upper top right corner -// ctm = modelview * glm::translate(glm::identity(), glm::vec3(1.08f, +1.08f, 0.f)); glm::vec4 pos = modelview * glm::vec4(1.08f, 1.08f, 0.f, 1.f); ctm = GlmToolkit::transform(glm::vec3(pos), glm::vec3(0.f), glm::vec3(1.f)); handle_->draw( ctm, projection ); diff --git a/Mixer.cpp b/Mixer.cpp index 4b92a18..a311532 100644 --- a/Mixer.cpp +++ b/Mixer.cpp @@ -89,6 +89,10 @@ static void saveSession(const std::string& filename, Session *session) geometry->InsertEndChild( SessionVisitor::NodeToXML(*session->config(View::GEOMETRY), &xmlDoc)); views->InsertEndChild(geometry); + XMLElement *layer = xmlDoc.NewElement( "Layer" ); + layer->InsertEndChild( SessionVisitor::NodeToXML(*session->config(View::LAYER), &xmlDoc)); + views->InsertEndChild(layer); + XMLElement *render = xmlDoc.NewElement( "Rendering" ); render->InsertEndChild( SessionVisitor::NodeToXML(*session->config(View::RENDERING), &xmlDoc)); views->InsertEndChild(render); @@ -157,6 +161,7 @@ void Mixer::update() // update views mixing_.update(dt); geometry_.update(dt); + layer_.update(dt); // TODO other views @@ -190,11 +195,10 @@ void Mixer::insertSource(Source *s) // Add source to Session and set it as current setCurrentSource( session_->addSource(s) ); - // add sources Nodes to ALL views - // Mixing Node + // add sources Nodes to all views mixing_.scene.fg()->attach(s->group(View::MIXING)); - // Geometry Node geometry_.scene.fg()->attach(s->group(View::GEOMETRY)); + layer_.scene.fg()->attach(s->group(View::LAYER)); } @@ -209,9 +213,10 @@ void Mixer::deleteSource(Source *s) // in case.. unsetCurrentSource(); - // remove source Nodes from views + // remove source Nodes from all views mixing_.scene.fg()->detatch( s->group(View::MIXING) ); geometry_.scene.fg()->detatch( s->group(View::GEOMETRY) ); + layer_.scene.fg()->detatch( s->group(View::LAYER) ); // delete source session_->deleteSource(s); @@ -309,6 +314,9 @@ void Mixer::setCurrentView(View::Mode m) case View::GEOMETRY: current_view_ = &geometry_; break; + case View::LAYER: + current_view_ = &layer_; + break; case View::MIXING: default: current_view_ = &mixing_; @@ -323,6 +331,8 @@ View *Mixer::getView(View::Mode m) switch (m) { case View::GEOMETRY: return &geometry_; + case View::LAYER: + return &layer_; case View::MIXING: return &mixing_; default: @@ -352,6 +362,7 @@ void Mixer::saveas(const std::string& filename) // optional copy of views config session_->config(View::MIXING)->copyTransform( mixing_.scene.root() ); session_->config(View::GEOMETRY)->copyTransform( geometry_.scene.root() ); + session_->config(View::LAYER)->copyTransform( layer_.scene.root() ); // launch a thread to save the session std::thread (saveSession, filename, session_).detach(); @@ -386,6 +397,7 @@ void Mixer::swap() { mixing_.scene.fg()->detatch( (*source_iter)->group(View::MIXING) ); geometry_.scene.fg()->detatch( (*source_iter)->group(View::GEOMETRY) ); + layer_.scene.fg()->detatch( (*source_iter)->group(View::LAYER) ); } } @@ -399,11 +411,13 @@ void Mixer::swap() { mixing_.scene.fg()->attach( (*source_iter)->group(View::MIXING) ); geometry_.scene.fg()->attach( (*source_iter)->group(View::GEOMETRY) ); + layer_.scene.fg()->attach( (*source_iter)->group(View::LAYER) ); } // optional copy of views config mixing_.scene.root()->copyTransform( session_->config(View::MIXING) ); geometry_.scene.root()->copyTransform( session_->config(View::GEOMETRY) ); + layer_.scene.root()->copyTransform( session_->config(View::LAYER) ); // set resolution session_->setResolution( session_->config(View::RENDERING)->scale_ ); diff --git a/Mixer.h b/Mixer.h index 7092906..a71ca49 100644 --- a/Mixer.h +++ b/Mixer.h @@ -82,6 +82,7 @@ protected: MixingView mixing_; GeometryView geometry_; + LayerView layer_; View *current_view_; gint64 update_time_; diff --git a/Session.cpp b/Session.cpp index 2659033..243c598 100644 --- a/Session.cpp +++ b/Session.cpp @@ -10,6 +10,7 @@ Session::Session() config_[View::RENDERING] = new Group; config_[View::RENDERING]->scale_ = render_.resolution(); config_[View::GEOMETRY] = new Group; + config_[View::LAYER] = new Group; config_[View::MIXING] = new Group; } diff --git a/SessionCreator.cpp b/SessionCreator.cpp index a9edbbf..0459a4b 100644 --- a/SessionCreator.cpp +++ b/SessionCreator.cpp @@ -85,6 +85,7 @@ void SessionCreator::loadConfig(XMLElement *viewsNode) // ok, ready to read views SessionCreator::XMLToNode( viewsNode->FirstChildElement("Mixing"), *session_->config(View::MIXING)); SessionCreator::XMLToNode( viewsNode->FirstChildElement("Geometry"), *session_->config(View::GEOMETRY)); + SessionCreator::XMLToNode( viewsNode->FirstChildElement("Layer"), *session_->config(View::LAYER)); SessionCreator::XMLToNode( viewsNode->FirstChildElement("Rendering"), *session_->config(View::RENDERING)); } } diff --git a/Source.cpp b/Source.cpp index 5543592..8302768 100644 --- a/Source.cpp +++ b/Source.cpp @@ -49,7 +49,12 @@ Source::Source(const std::string &name) : name_(name), initialized_(false) groups_[View::GEOMETRY]->attach(overlays_[View::GEOMETRY]); // default mixing nodes - groups_[View::LAYER] = new Group; + groups_[View::LAYER] = new Group; + frame = new Frame(Frame::ROUND_THIN); + frame->translation_.z = 0.1; + frame->color = glm::vec4( COLOR_DEFAULT_SOURCE, 0.9f); + groups_[View::LAYER]->attach(frame); + overlays_[View::LAYER] = new Group; overlays_[View::LAYER]->translation_.z = 0.15; overlays_[View::LAYER]->visible_ = false; diff --git a/UserInterfaceManager.cpp b/UserInterfaceManager.cpp index 9c6a4c9..1341fc8 100644 --- a/UserInterfaceManager.cpp +++ b/UserInterfaceManager.cpp @@ -978,7 +978,7 @@ void Navigator::Render() } if (ImGui::Selectable( ICON_FA_LAYER_GROUP, &selected_view[3], 0, iconsize)) { - // TODO : Layers view + Mixer::manager().setCurrentView(View::LAYER); } } ImGui::End(); @@ -1049,7 +1049,6 @@ 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(" "); diff --git a/View.cpp b/View.cpp index 1647950..01e51ea 100644 --- a/View.cpp +++ b/View.cpp @@ -349,23 +349,53 @@ void GeometryView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pairscale_ = glm::vec3(1.0f, 1.0f, 1.0f); + saveSettings(); + } + else + restoreSettings(); -void LayersView::draw () + // Geometry Scene background + Surface *rect = new Surface; + scene.bg()->attach(rect); + + Frame *border = new Frame(Frame::SHARP_THIN); + border->color = glm::vec4( 0.8f, 0.f, 0.8f, 1.f ); + scene.bg()->attach(border); +} + +LayerView::~LayerView() { } -void LayersView::zoom (float factor) +void LayerView::draw () +{ + // draw scene of this view + scene.root()->draw(glm::identity(), Rendering::manager().Projection()); + +} + +void LayerView::zoom (float factor) +{ + float z = scene.root()->scale_.x; + z = CLAMP( z + 0.1f * factor, 0.2f, 10.f); + scene.root()->scale_.x = z; + scene.root()->scale_.y = z; +} + +void LayerView::drag (glm::vec2 from, glm::vec2 to) { } -void LayersView::drag (glm::vec2 from, glm::vec2 to) -{ - -} - -void LayersView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick) +void LayerView::grab (glm::vec2 from, glm::vec2 to, Source *s, std::pair pick) { } diff --git a/View.h b/View.h index bc1d987..2ea0184 100644 --- a/View.h +++ b/View.h @@ -79,11 +79,11 @@ private: }; -class LayersView : public View +class LayerView : public View { public: - LayersView(); - ~LayersView(); + LayerView(); + ~LayerView(); void draw () override; void zoom (float factor) override;