BrunoLevy / GraphiteThree

Experimental 3D modeler
GNU General Public License v2.0
213 stars 18 forks source link

Unable to take snapshot #8

Closed GCoiffier closed 5 months ago

GCoiffier commented 5 months ago

Hi Bruno,

I have this old screenshot script that used to take a picture per object in my scene:

-- Lua
for i=0,scene_graph.nb_children-1 do
  scene_graph.ith_child(i).visible = false
end
for i=0,scene_graph.nb_children-1 do
  obj = scene_graph.ith_child(i)
  obj.visible = true
  name = obj.name
  main.draw()
  win.snapshot(name..'.jpeg')
  obj.visible = false  
end

However, in the newer version of Graphite, the variable win is not defined anymore. I found a snapshot function at main.render_area.snapshot but it takes a picture of the whole window, including GUI, while I want to snapshot only the mesh viewer. Is there a way to do so ? Maybe a command to hide all GUI elements beforehand ?

BrunoLevy commented 5 months ago

Hello Guillaume, Modify the 'snapshot()' function in 'skin_imgui/widgets/render_area.cpp' as follows:

    void RenderArea::snapshot(const std::string& filename, bool make_current) {
    if(rendering_context_ == nullptr) {
        Logger::warn("RenderArea")
        << "Cannot take a snapshot, not initialized yet"
        << std::endl;
    } else {
            Image image;
            draw_memorized_frame();  // add this line (it draws the memorized 3D graphics frame over the GUI)
            rendering_context_->snapshot(&image, make_current);
            ImageLibrary::instance()->save_image(filename,&image);
    }
    }

then use main.render_area.snapshot(). I'm adding now a with_gui parameter that will allow to chose between the two behaviors.

BrunoLevy commented 5 months ago

Pushed new version, if you update, now snapshot() works by default as you would expect (only captures 3D rendering, not the GUI).

GCoiffier commented 5 months ago

Thanks! Works great!