Merge branch 'tm_opencsg' into lm_tm_hollowing
This commit is contained in:
commit
6b482be74e
@ -2,7 +2,10 @@ cmake_minimum_required(VERSION 3.0)
|
||||
|
||||
project(OpenCSG-example)
|
||||
|
||||
add_executable(opencsg_example WIN32 main.cpp Engine.hpp Engine.cpp
|
||||
add_executable(opencsg_example WIN32
|
||||
main.cpp
|
||||
Engine.hpp Engine.cpp
|
||||
ShaderCSGDisplay.hpp ShaderCSGDisplay.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/ProgressStatusBar.cpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.hpp
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/../../src/slic3r/GUI/I18N.cpp)
|
||||
|
@ -1,7 +1,6 @@
|
||||
#include "Engine.hpp"
|
||||
#include <libslic3r/Utils.hpp>
|
||||
#include <libslic3r/SLAPrint.hpp>
|
||||
#include <libslic3r/MTUtils.hpp>
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
@ -66,22 +65,6 @@ void CSGDisplay::render_scene()
|
||||
glFlush();
|
||||
}
|
||||
|
||||
template<class It,
|
||||
class Trafo,
|
||||
class GetPt,
|
||||
class V = typename std::iterator_traits<It>::value_type>
|
||||
std::vector<V> transform_pts(
|
||||
It from, It to, Trafo &&tr, GetPt &&point)
|
||||
{
|
||||
auto ret = reserve_vector<V>(to - from);
|
||||
for(auto it = from; it != to; ++it) {
|
||||
V v = *it;
|
||||
v.pos = tr * point(*it);
|
||||
ret.emplace_back(std::move(v));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void Scene::set_print(uqptr<SLAPrint> &&print)
|
||||
{
|
||||
m_print = std::move(print);
|
||||
@ -287,7 +270,7 @@ void IndexedVertexArray::shrink_to_fit() {
|
||||
this->quad_indices.shrink_to_fit();
|
||||
}
|
||||
|
||||
void Primitive::render()
|
||||
void Volume::render()
|
||||
{
|
||||
glsafe(::glPushMatrix());
|
||||
glsafe(::glMultMatrixd(m_trafo.get_matrix().data()));
|
||||
|
@ -1,5 +1,5 @@
|
||||
#ifndef SLIC3R_OCSG_EXMP_ENGINE_HPP
|
||||
#define SLIC3R_OCSG_EXMP_ENGINE_HPP_HPP
|
||||
#define SLIC3R_OCSG_EXMP_ENGINE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@ -25,7 +25,7 @@ template<class T> using wkptr = std::weak_ptr<T>;
|
||||
template<class T, class A = std::allocator<T>> using vector = std::vector<T, A>;
|
||||
|
||||
// remove empty weak pointers from a vector
|
||||
template<class L> void cleanup(vector<std::weak_ptr<L>> &listeners) {
|
||||
template<class L> inline void cleanup(vector<std::weak_ptr<L>> &listeners) {
|
||||
auto it = std::remove_if(listeners.begin(), listeners.end(),
|
||||
[](auto &l) { return !l.lock(); });
|
||||
listeners.erase(it, listeners.end());
|
||||
@ -34,7 +34,7 @@ template<class L> void cleanup(vector<std::weak_ptr<L>> &listeners) {
|
||||
// Call a class method on each element of a vector of objects (weak pointers)
|
||||
// of the same type.
|
||||
template<class F, class L, class...Args>
|
||||
void call(F &&f, vector<std::weak_ptr<L>> &listeners, Args&&... args) {
|
||||
inline void call(F &&f, vector<std::weak_ptr<L>> &listeners, Args&&... args) {
|
||||
for (auto &l : listeners)
|
||||
if (auto p = l.lock()) ((p.get())->*f)(std::forward<Args>(args)...);
|
||||
}
|
||||
@ -171,19 +171,30 @@ public:
|
||||
// Try to enable or disable multisampling.
|
||||
bool enable_multisampling(bool e = true);
|
||||
|
||||
// A primitive that can be used with OpenCSG rendering algorithms.
|
||||
// Does a similar job to GLVolume.
|
||||
class Primitive : public OpenCSG::Primitive
|
||||
template<class It,
|
||||
class Trafo,
|
||||
class GetPt,
|
||||
class V = typename std::iterator_traits<It>::value_type>
|
||||
inline std::vector<V> transform_pts(
|
||||
It from, It to, Trafo &&tr, GetPt &&point)
|
||||
{
|
||||
vector<V> ret;
|
||||
ret.reserve(to - from);
|
||||
for(auto it = from; it != to; ++it) {
|
||||
V v = *it;
|
||||
v.pos = tr * point(*it);
|
||||
ret.emplace_back(std::move(v));
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
class Volume {
|
||||
IndexedVertexArray m_geom;
|
||||
Geometry::Transformation m_trafo;
|
||||
|
||||
public:
|
||||
|
||||
using OpenCSG::Primitive::Primitive;
|
||||
|
||||
Primitive() : OpenCSG::Primitive(OpenCSG::Intersection, 1) {}
|
||||
|
||||
void render() override;
|
||||
void render();
|
||||
|
||||
void translation(const Vec3d &offset) { m_trafo.set_offset(offset); }
|
||||
void rotation(const Vec3d &rot) { m_trafo.set_rotation(rot); }
|
||||
@ -197,6 +208,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
// A primitive that can be used with OpenCSG rendering algorithms.
|
||||
// Does a similar job to GLVolume.
|
||||
class Primitive : public Volume, public OpenCSG::Primitive
|
||||
{
|
||||
public:
|
||||
using OpenCSG::Primitive::Primitive;
|
||||
|
||||
Primitive() : OpenCSG::Primitive(OpenCSG::Intersection, 1) {}
|
||||
|
||||
void render() override { Volume::render(); }
|
||||
};
|
||||
|
||||
// A simple representation of a camera in a 3D scene
|
||||
class Camera {
|
||||
protected:
|
||||
@ -286,13 +309,25 @@ private:
|
||||
|
||||
public:
|
||||
int get_algo() const { return int(m_csgalg); }
|
||||
void set_algo(OpenCSG::Algorithm alg) { m_csgalg = alg; }
|
||||
void set_algo(int alg)
|
||||
{
|
||||
if (alg < OpenCSG::Algorithm::AlgorithmUnused)
|
||||
m_csgalg = OpenCSG::Algorithm(alg);
|
||||
}
|
||||
|
||||
int get_depth_algo() const { return int(m_depth_algo); }
|
||||
void set_depth_algo(OpenCSG::DepthComplexityAlgorithm alg) { m_depth_algo = alg; }
|
||||
void set_depth_algo(int alg)
|
||||
{
|
||||
if (alg < OpenCSG::DepthComplexityAlgorithmUnused)
|
||||
m_depth_algo = OpenCSG::DepthComplexityAlgorithm(alg);
|
||||
}
|
||||
|
||||
int get_optimization() const { return int(m_optim); }
|
||||
void set_optimization(OpenCSG::Optimization o) { m_optim = o; }
|
||||
void set_optimization(int o)
|
||||
{
|
||||
if (o < OpenCSG::Optimization::OptimizationUnused)
|
||||
m_optim = OpenCSG::Optimization(o);
|
||||
}
|
||||
|
||||
void enable_csg(bool en = true) { m_enable = en; }
|
||||
bool is_enabled() const { return m_enable; }
|
||||
@ -359,7 +394,9 @@ public:
|
||||
|
||||
~Display() override;
|
||||
|
||||
Camera * camera() { return m_camera.get(); }
|
||||
shptr<const Camera> get_camera() const { return m_camera; }
|
||||
shptr<Camera> get_camera() { return m_camera; }
|
||||
void set_camera(shptr<Camera> cam) { m_camera = cam; }
|
||||
|
||||
virtual void swap_buffers() = 0;
|
||||
virtual void set_active(long width, long height);
|
||||
@ -433,8 +470,8 @@ class Controller : public std::enable_shared_from_this<Controller>,
|
||||
template<class F, class...Args>
|
||||
void call_cameras(F &&f, Args&&... args) {
|
||||
for (wkptr<Display> &l : m_displays)
|
||||
if (auto disp = l.lock()) if (disp->camera())
|
||||
(disp->camera()->*f)(std::forward<Args>(args)...);
|
||||
if (auto disp = l.lock()) if (auto cam = disp->get_camera())
|
||||
(cam.get()->*f)(std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
public:
|
||||
@ -454,6 +491,8 @@ public:
|
||||
cleanup(m_displays);
|
||||
}
|
||||
|
||||
void remove_displays() { m_displays = {}; }
|
||||
|
||||
void on_scene_updated(const Scene &scene) override;
|
||||
|
||||
void on_left_click_down() override { m_left_btn = true; }
|
||||
|
81
sandboxes/opencsg/ShaderCSGDisplay.cpp
Normal file
81
sandboxes/opencsg/ShaderCSGDisplay.cpp
Normal file
@ -0,0 +1,81 @@
|
||||
#include "ShaderCSGDisplay.hpp"
|
||||
#include "libslic3r/SLAPrint.hpp"
|
||||
#include <GL/glew.h>
|
||||
|
||||
namespace Slic3r { namespace GL {
|
||||
|
||||
void ShaderCSGDisplay::add_mesh(const TriangleMesh &mesh)
|
||||
{
|
||||
auto v = std::make_shared<CSGVolume>();
|
||||
v->load_mesh(mesh);
|
||||
m_volumes.emplace_back(v);
|
||||
}
|
||||
|
||||
void ShaderCSGDisplay::render_scene()
|
||||
{
|
||||
GLfloat color[] = {1.f, 1.f, 0.f, 0.f};
|
||||
glColor4fv(color);
|
||||
glDepthFunc(GL_LESS);
|
||||
for (auto &v : m_volumes) v->render();
|
||||
glFlush();
|
||||
}
|
||||
|
||||
void ShaderCSGDisplay::on_scene_updated(const Scene &scene)
|
||||
{
|
||||
// TriangleMesh mesh = print->objects().front()->hollowed_interior_mesh();
|
||||
// Look at CSGDisplay::on_scene_updated to see how its done there.
|
||||
|
||||
const SLAPrint *print = scene.get_print();
|
||||
if (!print) return;
|
||||
|
||||
m_volumes.clear();
|
||||
|
||||
for (const SLAPrintObject *po : print->objects()) {
|
||||
const ModelObject *mo = po->model_object();
|
||||
TriangleMesh msh = mo->raw_mesh();
|
||||
|
||||
sla::DrainHoles holedata = mo->sla_drain_holes;
|
||||
|
||||
for (const ModelInstance *mi : mo->instances) {
|
||||
|
||||
TriangleMesh mshinst = msh;
|
||||
auto interior = po->hollowed_interior_mesh();
|
||||
interior.transform(po->trafo().inverse());
|
||||
|
||||
mshinst.merge(interior);
|
||||
mshinst.require_shared_vertices();
|
||||
|
||||
mi->transform_mesh(&mshinst);
|
||||
|
||||
auto bb = mshinst.bounding_box();
|
||||
auto center = bb.center().cast<float>();
|
||||
mshinst.translate(-center);
|
||||
|
||||
mshinst.require_shared_vertices();
|
||||
add_mesh(mshinst);
|
||||
|
||||
auto tr = Transform3f::Identity();
|
||||
tr.translate(-center);
|
||||
|
||||
transform_pts(holedata.begin(), holedata.end(), tr,
|
||||
[](const sla::DrainHole &dh) {
|
||||
return dh.pos;
|
||||
});
|
||||
|
||||
transform_pts(holedata.begin(), holedata.end(), tr,
|
||||
[](const sla::DrainHole &dh) {
|
||||
return dh.normal;
|
||||
});
|
||||
}
|
||||
|
||||
for (const sla::DrainHole &holept : holedata) {
|
||||
TriangleMesh holemesh = sla::to_triangle_mesh(holept.to_mesh());
|
||||
holemesh.require_shared_vertices();
|
||||
add_mesh(holemesh);
|
||||
}
|
||||
}
|
||||
|
||||
repaint();
|
||||
}
|
||||
|
||||
}} // namespace Slic3r::GL
|
27
sandboxes/opencsg/ShaderCSGDisplay.hpp
Normal file
27
sandboxes/opencsg/ShaderCSGDisplay.hpp
Normal file
@ -0,0 +1,27 @@
|
||||
#ifndef SHADERCSGDISPLAY_HPP
|
||||
#define SHADERCSGDISPLAY_HPP
|
||||
|
||||
#include "Engine.hpp"
|
||||
|
||||
namespace Slic3r { namespace GL {
|
||||
|
||||
class CSGVolume: public Volume
|
||||
{
|
||||
// Extend...
|
||||
};
|
||||
|
||||
class ShaderCSGDisplay: public Display {
|
||||
protected:
|
||||
vector<shptr<CSGVolume>> m_volumes;
|
||||
|
||||
void add_mesh(const TriangleMesh &mesh);
|
||||
public:
|
||||
|
||||
void render_scene() override;
|
||||
|
||||
void on_scene_updated(const Scene &scene) override;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
#endif // SHADERCSGDISPLAY_HPP
|
@ -3,6 +3,7 @@
|
||||
#include <memory>
|
||||
|
||||
#include "Engine.hpp"
|
||||
#include "ShaderCSGDisplay.hpp"
|
||||
|
||||
#include <GL/glew.h>
|
||||
|
||||
@ -30,17 +31,13 @@
|
||||
|
||||
using namespace Slic3r::GL;
|
||||
|
||||
// The opengl rendering facility. Here we implement the rendering objects.
|
||||
class Canvas: public wxGLCanvas
|
||||
{
|
||||
|
||||
// Tell the CSGDisplay how to swap buffers and set the gl context.
|
||||
class OCSGRenderer: public Slic3r::GL::CSGDisplay {
|
||||
Canvas *m_canvas;
|
||||
class Renderer {
|
||||
protected:
|
||||
wxGLCanvas *m_canvas;
|
||||
shptr<wxGLContext> m_context;
|
||||
public:
|
||||
|
||||
OCSGRenderer(Canvas *c): m_canvas{c} {
|
||||
Renderer(wxGLCanvas *c): m_canvas{c} {
|
||||
auto ctx = new wxGLContext(m_canvas);
|
||||
if (!ctx || !ctx->IsOK()) {
|
||||
wxMessageBox("Could not create OpenGL context.", "Error",
|
||||
@ -51,25 +48,45 @@ class Canvas: public wxGLCanvas
|
||||
m_context.reset(ctx);
|
||||
}
|
||||
|
||||
wxGLContext * context() { return m_context.get(); }
|
||||
const wxGLContext * context() const { return m_context.get(); }
|
||||
};
|
||||
|
||||
// Tell the CSGDisplay how to swap buffers and set the gl context.
|
||||
class OCSGRenderer: public Renderer, public Slic3r::GL::CSGDisplay {
|
||||
public:
|
||||
|
||||
OCSGRenderer(wxGLCanvas *c): Renderer{c} {}
|
||||
|
||||
void set_active(long w, long h) override
|
||||
{
|
||||
m_canvas->SetCurrent(*m_context);
|
||||
Slic3r::GL::Display::set_active(w, h);
|
||||
}
|
||||
|
||||
wxGLContext * context() { return m_context.get(); }
|
||||
const wxGLContext * context() const { return m_context.get(); }
|
||||
|
||||
void swap_buffers() override { m_canvas->SwapBuffers(); }
|
||||
|
||||
~OCSGRenderer() override { m_scene_cache.clear(); }
|
||||
};
|
||||
|
||||
// Create the OCSGDisplay for rendering with OpenCSG algorithms
|
||||
shptr<OCSGRenderer> m_ocsgdisplay = std::make_shared<OCSGRenderer>(this);
|
||||
// Tell the CSGDisplay how to swap buffers and set the gl context.
|
||||
class ShaderCSGRenderer : public Renderer, public Slic3r::GL::ShaderCSGDisplay {
|
||||
public:
|
||||
|
||||
ShaderCSGRenderer(wxGLCanvas *c): Renderer{c} {}
|
||||
|
||||
void set_active(long w, long h) override
|
||||
{
|
||||
m_canvas->SetCurrent(*m_context);
|
||||
Slic3r::GL::Display::set_active(w, h);
|
||||
}
|
||||
|
||||
void swap_buffers() override { m_canvas->SwapBuffers(); }
|
||||
};
|
||||
|
||||
// The opengl rendering facility. Here we implement the rendering objects.
|
||||
class Canvas: public wxGLCanvas
|
||||
{
|
||||
// One display is active at a time, the OCSGRenderer by default.
|
||||
shptr<Slic3r::GL::Display> m_display = m_ocsgdisplay;
|
||||
shptr<Slic3r::GL::Display> m_display;
|
||||
|
||||
public:
|
||||
|
||||
@ -90,13 +107,18 @@ public:
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
|
||||
m_display->set_screen_size(ClientSize.x, ClientSize.y);
|
||||
m_display->repaint();
|
||||
});
|
||||
|
||||
Bind(wxEVT_SIZE, [this](wxSizeEvent &) {
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
m_display->set_screen_size(ClientSize.x, ClientSize.y);
|
||||
});
|
||||
}
|
||||
|
||||
shptr<Slic3r::GL::Display> get_display() const { return m_display; }
|
||||
void set_display(shptr<Slic3r::GL::Display> d) { m_display = d; }
|
||||
|
||||
shptr<Slic3r::GL::CSGDisplay> get_ocsg_display() const { return m_ocsgdisplay; }
|
||||
void set_display(shptr<Slic3r::GL::Display> d) { m_display = d; }
|
||||
};
|
||||
|
||||
// Enumerate possible mouse events, we will record them.
|
||||
@ -183,10 +205,15 @@ public:
|
||||
case MV: MouseInput::move_to(evt.a, evt.b); break;
|
||||
}
|
||||
|
||||
wxSafeYield();
|
||||
wxTheApp->Yield();
|
||||
if (!m_playing)
|
||||
break;
|
||||
}
|
||||
m_playing = false;
|
||||
}
|
||||
|
||||
void stop() { m_playing = false; }
|
||||
bool is_playing() const { return m_playing; }
|
||||
};
|
||||
|
||||
// The top level frame of the application.
|
||||
@ -194,7 +221,9 @@ class MyFrame: public wxFrame
|
||||
{
|
||||
// Instantiate the 3D engine.
|
||||
shptr<Scene> m_scene; // Model
|
||||
shptr<Canvas> m_canvas; // View
|
||||
shptr<Canvas> m_canvas; // Views store
|
||||
shptr<OCSGRenderer> m_ocsgdisplay; // View
|
||||
shptr<ShaderCSGRenderer> m_shadercsg_display; // Another view
|
||||
shptr<Controller> m_ctl; // Controller
|
||||
|
||||
// Add a status bar with progress indication.
|
||||
@ -236,11 +265,29 @@ class MyFrame: public wxFrame
|
||||
// To keep track of the running average of measured fps values.
|
||||
double m_fps_avg = 0.;
|
||||
|
||||
// We need the record button across methods
|
||||
wxToggleButton *m_record_btn;
|
||||
wxComboBox * m_alg_select;
|
||||
wxComboBox * m_depth_select;
|
||||
wxComboBox * m_optimization_select;
|
||||
wxSpinCtrl * m_convexity_spin;
|
||||
wxToggleButton *m_csg_toggle;
|
||||
wxToggleButton *m_ms_toggle;
|
||||
wxStaticText *m_fpstext;
|
||||
|
||||
CSGSettings m_csg_settings;
|
||||
|
||||
void read_csg_settings(const wxCmdLineParser &parser);
|
||||
|
||||
void set_renderer_algorithm(const wxString &alg);
|
||||
|
||||
void activate_canvas_display();
|
||||
|
||||
public:
|
||||
MyFrame(const wxString & title,
|
||||
const wxPoint & pos,
|
||||
const wxSize & size,
|
||||
const Slic3r::GL::CSGSettings &settings);
|
||||
const wxCmdLineParser &parser);
|
||||
|
||||
// Grab a 3mf and load (hollow it out) within the UI job.
|
||||
void load_model(const std::string &fname) {
|
||||
@ -258,11 +305,15 @@ public:
|
||||
std::getline(stream, model_name);
|
||||
load_model(model_name);
|
||||
|
||||
while (!m_ui_job->is_finalized())
|
||||
wxTheApp->Yield();;
|
||||
|
||||
int w, h;
|
||||
stream >> w >> h;
|
||||
SetSize(w, h);
|
||||
|
||||
m_mouse.load(stream);
|
||||
if (m_record_btn) m_record_btn->Disable();
|
||||
m_mouse.play();
|
||||
}
|
||||
}
|
||||
@ -278,13 +329,19 @@ public:
|
||||
|
||||
// Possible OpenCSG configuration values. Will be used on the command line and
|
||||
// on the UI widgets.
|
||||
static const std::vector<wxString> CSG_ALGS = {"Auto", "Goldfeather", "SCS"};
|
||||
static const std::vector<wxString> CSG_ALGS = {"Auto", "Goldfeather", "SCS", "EnricoShader"};
|
||||
static const std::vector<wxString> CSG_DEPTH = {"Off", "OcclusionQuery", "On"};
|
||||
static const std::vector<wxString> CSG_OPT = { "Default", "ForceOn", "On", "Off" };
|
||||
|
||||
inline long get_idx(const wxString &a, const std::vector<wxString> &v)
|
||||
{
|
||||
auto it = std::find(v.begin(), v.end(), a.ToStdString());
|
||||
return it - v.begin();
|
||||
};
|
||||
|
||||
class App : public wxApp {
|
||||
MyFrame *m_frame = nullptr;
|
||||
|
||||
wxString m_fname;
|
||||
public:
|
||||
bool OnInit() override {
|
||||
|
||||
@ -299,9 +356,29 @@ public:
|
||||
|
||||
parser.Parse();
|
||||
|
||||
wxString fname;
|
||||
bool is_play = parser.Found("play", &fname);
|
||||
bool is_play = parser.Found("play", &m_fname);
|
||||
|
||||
m_frame = new MyFrame("PrusaSlicer OpenCSG Demo", wxDefaultPosition, wxSize(1024, 768), parser);
|
||||
|
||||
if (is_play) {
|
||||
Bind(wxEVT_IDLE, &App::Play, this);
|
||||
m_frame->Show( true );
|
||||
} else m_frame->Show( true );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Play(wxIdleEvent &) {
|
||||
Unbind(wxEVT_IDLE, &App::Play, this);
|
||||
m_frame->play_back_mouse(m_fname.ToStdString());
|
||||
m_frame->Destroy();
|
||||
}
|
||||
};
|
||||
|
||||
wxIMPLEMENT_APP(App);
|
||||
|
||||
void MyFrame::read_csg_settings(const wxCmdLineParser &parser)
|
||||
{
|
||||
wxString alg;
|
||||
parser.Found("algorithm", &alg);
|
||||
|
||||
@ -316,43 +393,90 @@ public:
|
||||
|
||||
bool csg_off = parser.Found("disable-csg");
|
||||
|
||||
auto get_idx = [](const wxString &a, const std::vector<wxString> &v) {
|
||||
auto it = std::find(v.begin(), v.end(), a.ToStdString());
|
||||
return it - v.begin();
|
||||
};
|
||||
|
||||
Slic3r::GL::CSGSettings settings;
|
||||
|
||||
if (auto a = get_idx(alg, CSG_ALGS) < OpenCSG::AlgorithmUnused)
|
||||
settings.set_algo(OpenCSG::Algorithm(a));
|
||||
m_csg_settings.set_algo(OpenCSG::Algorithm(a));
|
||||
|
||||
if (auto a = get_idx(depth, CSG_DEPTH) < OpenCSG::DepthComplexityAlgorithmUnused)
|
||||
settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(a));
|
||||
m_csg_settings.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(a));
|
||||
|
||||
if (auto a = get_idx(opt, CSG_OPT) < OpenCSG::OptimizationUnused)
|
||||
settings.set_optimization(OpenCSG::Optimization(a));
|
||||
m_csg_settings.set_optimization(OpenCSG::Optimization(a));
|
||||
|
||||
settings.set_convexity(unsigned(convexity));
|
||||
settings.enable_csg(!csg_off);
|
||||
m_csg_settings.set_convexity(unsigned(convexity));
|
||||
m_csg_settings.enable_csg(!csg_off);
|
||||
|
||||
m_frame = new MyFrame("PrusaSlicer OpenCSG Demo", wxDefaultPosition, wxSize(1024, 768), settings);
|
||||
|
||||
if (is_play) {
|
||||
m_frame->Show( true );
|
||||
m_frame->play_back_mouse(fname.ToStdString());
|
||||
m_frame->Close( true );
|
||||
std::cout << m_frame->get_fps_average() << std::endl;
|
||||
|
||||
} else m_frame->Show( true );
|
||||
|
||||
return true;
|
||||
if (m_ocsgdisplay) m_ocsgdisplay->apply_csgsettings(m_csg_settings);
|
||||
}
|
||||
};
|
||||
|
||||
wxIMPLEMENT_APP(App);
|
||||
void MyFrame::set_renderer_algorithm(const wxString &alg)
|
||||
{
|
||||
long alg_idx = get_idx("EnricoShader", CSG_ALGS);
|
||||
if (alg_idx < 0 || alg_idx >= CSG_ALGS.size()) return;
|
||||
|
||||
// If there is a valid display in place, save its camera.
|
||||
auto cam = m_canvas->get_display() ?
|
||||
m_canvas->get_display()->get_camera() : nullptr;
|
||||
|
||||
if (alg == "EnricoShader") {
|
||||
m_alg_select->SetSelection(int(alg_idx));
|
||||
m_depth_select->Disable();
|
||||
m_optimization_select->Disable();
|
||||
m_csg_toggle->Disable();
|
||||
|
||||
m_ocsgdisplay.reset();
|
||||
canvas()->set_display(nullptr);
|
||||
m_shadercsg_display = std::make_shared<ShaderCSGRenderer>(canvas());
|
||||
canvas()->set_display(m_shadercsg_display);
|
||||
} else {
|
||||
if (m_csg_settings.get_algo() > 0) m_depth_select->Enable(true);
|
||||
m_alg_select->SetSelection(m_csg_settings.get_algo());
|
||||
m_depth_select->SetSelection(m_csg_settings.get_depth_algo());
|
||||
m_optimization_select->SetSelection(m_csg_settings.get_optimization());
|
||||
m_convexity_spin->SetValue(int(m_csg_settings.get_convexity()));
|
||||
m_csg_toggle->SetValue(m_csg_settings.is_enabled());
|
||||
m_optimization_select->Enable();
|
||||
m_csg_toggle->Enable();
|
||||
|
||||
m_shadercsg_display.reset();
|
||||
canvas()->set_display(nullptr);
|
||||
m_ocsgdisplay = std::make_shared<OCSGRenderer>(canvas());
|
||||
m_ocsgdisplay->apply_csgsettings(m_csg_settings);
|
||||
canvas()->set_display(m_ocsgdisplay);
|
||||
}
|
||||
|
||||
if (cam)
|
||||
m_canvas->get_display()->set_camera(cam);
|
||||
|
||||
m_ctl->remove_displays();
|
||||
m_ctl->add_display(m_canvas->get_display());
|
||||
m_canvas->get_display()->get_fps_counter().add_listener([this](double fps) {
|
||||
m_fpstext->SetLabel(wxString::Format("fps: %.2f", fps));
|
||||
m_fps_avg = 0.9 * m_fps_avg + 0.1 * fps;
|
||||
});
|
||||
|
||||
if (IsShown()) {
|
||||
activate_canvas_display();
|
||||
m_canvas->get_display()->on_scene_updated(*m_scene);
|
||||
}
|
||||
}
|
||||
|
||||
void MyFrame::activate_canvas_display()
|
||||
{
|
||||
const wxSize ClientSize = m_canvas->GetClientSize();
|
||||
m_canvas->get_display()->set_active(ClientSize.x, ClientSize.y);
|
||||
enable_multisampling(m_ms_toggle->GetValue());
|
||||
|
||||
// Do the repaint continuously
|
||||
m_canvas->Bind(wxEVT_IDLE, [this](wxIdleEvent &evt) {
|
||||
m_canvas->get_display()->repaint();
|
||||
evt.RequestMore();
|
||||
});
|
||||
|
||||
bind_canvas_events(m_mouse);
|
||||
}
|
||||
|
||||
MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
const Slic3r::GL::CSGSettings &settings):
|
||||
const wxCmdLineParser &parser):
|
||||
wxFrame(nullptr, wxID_ANY, title, pos, size)
|
||||
{
|
||||
wxMenu *menuFile = new wxMenu;
|
||||
@ -377,7 +501,7 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
// glReadPixels would not return the alpha channel on NVIDIA if
|
||||
// not requested when the GL context is created.
|
||||
WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8, WX_GL_STENCIL_SIZE, 8,
|
||||
/*WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4,*/ 0};
|
||||
WX_GL_SAMPLE_BUFFERS, GL_TRUE, WX_GL_SAMPLES, 4, 0};
|
||||
|
||||
m_scene = std::make_shared<Scene>();
|
||||
m_ctl = std::make_shared<Controller>();
|
||||
@ -387,9 +511,7 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
wxDefaultPosition, wxDefaultSize,
|
||||
wxWANTS_CHARS | wxFULL_REPAINT_ON_RESIZE);
|
||||
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(settings);
|
||||
|
||||
m_ctl->add_display(m_canvas->get_display());
|
||||
read_csg_settings(parser);
|
||||
|
||||
wxPanel *control_panel = new wxPanel(this);
|
||||
|
||||
@ -402,12 +524,12 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
wxSL_VERTICAL);
|
||||
slider_sizer->Add(slider, 1, wxEXPAND);
|
||||
|
||||
auto ms_toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling");
|
||||
console_sizer->Add(ms_toggle, 0, wxALL | wxEXPAND, 5);
|
||||
m_ms_toggle = new wxToggleButton(control_panel, wxID_ANY, "Multisampling");
|
||||
console_sizer->Add(m_ms_toggle, 0, wxALL | wxEXPAND, 5);
|
||||
|
||||
auto csg_toggle = new wxToggleButton(control_panel, wxID_ANY, "CSG");
|
||||
csg_toggle->SetValue(true);
|
||||
console_sizer->Add(csg_toggle, 0, wxALL | wxEXPAND, 5);
|
||||
m_csg_toggle = new wxToggleButton(control_panel, wxID_ANY, "CSG");
|
||||
m_csg_toggle->SetValue(true);
|
||||
console_sizer->Add(m_csg_toggle, 0, wxALL | wxEXPAND, 5);
|
||||
|
||||
auto add_combobox = [control_panel, console_sizer]
|
||||
(const wxString &label, const std::vector<wxString> &list)
|
||||
@ -441,22 +563,17 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
return widget;
|
||||
};
|
||||
|
||||
auto convexity_spin = add_spinctl("Convexity", CSGSettings::DEFAULT_CONVEXITY, 0, 100);
|
||||
m_convexity_spin = add_spinctl("Convexity", CSGSettings::DEFAULT_CONVEXITY, 0, 100);
|
||||
|
||||
auto alg_select = add_combobox("Algorithm", CSG_ALGS);
|
||||
auto depth_select = add_combobox("Depth Complexity", CSG_DEPTH);
|
||||
auto optimization_select = add_combobox("Optimization", CSG_OPT);
|
||||
depth_select->Disable();
|
||||
m_alg_select = add_combobox("Algorithm", CSG_ALGS);
|
||||
m_depth_select = add_combobox("Depth Complexity", CSG_DEPTH);
|
||||
m_optimization_select = add_combobox("Optimization", CSG_OPT);
|
||||
|
||||
auto fpstext = new wxStaticText(control_panel, wxID_ANY, "");
|
||||
console_sizer->Add(fpstext, 0, wxALL, 5);
|
||||
m_canvas->get_ocsg_display()->get_fps_counter().add_listener([this, fpstext](double fps) {
|
||||
fpstext->SetLabel(wxString::Format("fps: %.2f", fps) );
|
||||
m_fps_avg = 0.9 * m_fps_avg + 0.1 * fps;
|
||||
});
|
||||
m_fpstext = new wxStaticText(control_panel, wxID_ANY, "");
|
||||
console_sizer->Add(m_fpstext, 0, wxALL, 5);
|
||||
|
||||
auto record_btn = new wxToggleButton(control_panel, wxID_ANY, "Record");
|
||||
console_sizer->Add(record_btn, 0, wxALL | wxEXPAND, 5);
|
||||
m_record_btn = new wxToggleButton(control_panel, wxID_ANY, "Record");
|
||||
console_sizer->Add(m_record_btn, 0, wxALL | wxEXPAND, 5);
|
||||
|
||||
controlsizer->Add(slider_sizer, 0, wxEXPAND);
|
||||
controlsizer->Add(console_sizer, 1, wxEXPAND);
|
||||
@ -468,17 +585,16 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
sizer->Add(control_panel, 0, wxEXPAND);
|
||||
SetSizer(sizer);
|
||||
|
||||
if (settings.get_algo() > 0) depth_select->Enable(true);
|
||||
alg_select->SetSelection(settings.get_algo());
|
||||
depth_select->SetSelection(settings.get_depth_algo());
|
||||
optimization_select->SetSelection(settings.get_optimization());
|
||||
convexity_spin->SetValue(int(settings.get_convexity()));
|
||||
csg_toggle->SetValue(settings.is_enabled());
|
||||
wxString alg;
|
||||
if (!parser.Found("algorithm", &alg)) alg = "Auto";
|
||||
|
||||
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent &){
|
||||
RemoveChild(m_canvas.get());
|
||||
set_renderer_algorithm(alg);
|
||||
|
||||
Bind(wxEVT_CLOSE_WINDOW, [this](wxCloseEvent &evt){
|
||||
if (m_canvas) RemoveChild(m_canvas.get());
|
||||
m_canvas.reset();
|
||||
Destroy();
|
||||
if (!m_mouse.is_playing()) evt.Skip();
|
||||
else m_mouse.stop();
|
||||
});
|
||||
|
||||
Bind(wxEVT_MENU, [this](wxCommandEvent &) {
|
||||
@ -490,70 +606,60 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
|
||||
Bind(wxEVT_MENU, [this](wxCommandEvent &) { Close(true); }, wxID_EXIT);
|
||||
|
||||
Bind(wxEVT_SHOW, [this, ms_toggle](wxShowEvent &) {
|
||||
const wxSize ClientSize = GetClientSize();
|
||||
m_canvas->get_display()->set_active(ClientSize.x, ClientSize.y);
|
||||
enable_multisampling(ms_toggle->GetValue());
|
||||
Bind(wxEVT_SHOW, [this](wxShowEvent &) {
|
||||
activate_canvas_display();
|
||||
});
|
||||
|
||||
Bind(wxEVT_SLIDER, [this, slider](wxCommandEvent &) {
|
||||
m_ctl->move_clip_plane(double(slider->GetValue()));
|
||||
});
|
||||
|
||||
ms_toggle->Bind(wxEVT_TOGGLEBUTTON, [this, ms_toggle](wxCommandEvent &){
|
||||
enable_multisampling(ms_toggle->GetValue());
|
||||
m_ms_toggle->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &){
|
||||
enable_multisampling(m_ms_toggle->GetValue());
|
||||
m_canvas->get_display()->repaint();
|
||||
});
|
||||
|
||||
csg_toggle->Bind(wxEVT_TOGGLEBUTTON, [this, csg_toggle](wxCommandEvent &){
|
||||
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
||||
stt.enable_csg(csg_toggle->GetValue());
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
||||
m_csg_toggle->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &){
|
||||
CSGSettings stt = m_ocsgdisplay->get_csgsettings();
|
||||
stt.enable_csg(m_csg_toggle->GetValue());
|
||||
m_ocsgdisplay->apply_csgsettings(stt);
|
||||
});
|
||||
|
||||
alg_select->Bind(wxEVT_COMBOBOX,
|
||||
[this, alg_select, depth_select](wxCommandEvent &)
|
||||
{
|
||||
int sel = alg_select->GetSelection();
|
||||
depth_select->Enable(sel > 0);
|
||||
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
||||
stt.set_algo(OpenCSG::Algorithm(sel));
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
||||
m_alg_select->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &) {
|
||||
wxString alg = m_alg_select->GetValue();
|
||||
int sel = m_alg_select->GetSelection();
|
||||
m_csg_settings.set_algo(sel);
|
||||
set_renderer_algorithm(alg);
|
||||
});
|
||||
|
||||
depth_select->Bind(wxEVT_COMBOBOX, [this, depth_select](wxCommandEvent &) {
|
||||
int sel = depth_select->GetSelection();
|
||||
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
||||
stt.set_depth_algo(OpenCSG::DepthComplexityAlgorithm(sel));
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
||||
m_depth_select->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &) {
|
||||
int sel = m_depth_select->GetSelection();
|
||||
m_csg_settings.set_depth_algo(sel);
|
||||
if (m_ocsgdisplay) m_ocsgdisplay->apply_csgsettings(m_csg_settings);
|
||||
});
|
||||
|
||||
optimization_select->Bind(wxEVT_COMBOBOX,
|
||||
[this, optimization_select](wxCommandEvent &) {
|
||||
int sel = optimization_select->GetSelection();
|
||||
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
||||
stt.set_optimization(OpenCSG::Optimization(sel));
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
||||
m_optimization_select->Bind(wxEVT_COMBOBOX, [this](wxCommandEvent &) {
|
||||
int sel = m_optimization_select->GetSelection();
|
||||
m_csg_settings.set_optimization(sel);
|
||||
if (m_ocsgdisplay) m_ocsgdisplay->apply_csgsettings(m_csg_settings);
|
||||
});
|
||||
|
||||
convexity_spin->Bind(wxEVT_SPINCTRL, [this, convexity_spin](wxSpinEvent &) {
|
||||
CSGSettings stt = m_canvas->get_ocsg_display()->get_csgsettings();
|
||||
int c = convexity_spin->GetValue();
|
||||
|
||||
m_convexity_spin->Bind(wxEVT_SPINCTRL, [this](wxSpinEvent &) {
|
||||
int c = m_convexity_spin->GetValue();
|
||||
if (c > 0) {
|
||||
stt.set_convexity(unsigned(c));
|
||||
m_canvas->get_ocsg_display()->apply_csgsettings(stt);
|
||||
m_csg_settings.set_convexity(unsigned(c));
|
||||
if (m_ocsgdisplay) m_ocsgdisplay->apply_csgsettings(m_csg_settings);
|
||||
}
|
||||
});
|
||||
|
||||
record_btn->Bind(wxEVT_TOGGLEBUTTON, [this, record_btn](wxCommandEvent &) {
|
||||
m_record_btn->Bind(wxEVT_TOGGLEBUTTON, [this](wxCommandEvent &) {
|
||||
if (!m_ui_job) {
|
||||
m_stbar->set_status_text("No project loaded!");
|
||||
return;
|
||||
}
|
||||
|
||||
if (record_btn->GetValue()) {
|
||||
if (auto c = m_canvas->get_display()->camera()) reset(*c);
|
||||
if (m_record_btn->GetValue()) {
|
||||
if (auto c = m_canvas->get_display()->get_camera()) reset(*c);
|
||||
m_ctl->on_scene_updated(*m_scene);
|
||||
m_mouse.record(true);
|
||||
} else {
|
||||
@ -575,14 +681,6 @@ MyFrame::MyFrame(const wxString &title, const wxPoint &pos, const wxSize &size,
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Do the repaint continuously
|
||||
m_canvas->Bind(wxEVT_IDLE, [this](wxIdleEvent &evt) {
|
||||
if (m_canvas->IsShown()) m_canvas->get_display()->repaint();
|
||||
evt.RequestMore();
|
||||
});
|
||||
|
||||
bind_canvas_events(m_mouse);
|
||||
}
|
||||
|
||||
void MyFrame::bind_canvas_events(MouseInput &ms)
|
||||
|
@ -62,7 +62,6 @@ protected:
|
||||
// Launched when the job is finished. It refreshes the 3Dscene by def.
|
||||
virtual void finalize() { m_finalized = true; }
|
||||
|
||||
bool is_finalized() const { return m_finalized; }
|
||||
|
||||
public:
|
||||
Job(std::shared_ptr<ProgressIndicator> pri) : m_progress(pri)
|
||||
@ -89,6 +88,8 @@ public:
|
||||
});
|
||||
}
|
||||
|
||||
bool is_finalized() const { return m_finalized; }
|
||||
|
||||
Job(const Job &) = delete;
|
||||
Job(Job &&) = delete;
|
||||
Job &operator=(const Job &) = delete;
|
||||
|
Loading…
Reference in New Issue
Block a user