ShaderCSGDisplay.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "ShaderCSGDisplay.hpp"
  2. #include "libslic3r/SLAPrint.hpp"
  3. #include <GL/glew.h>
  4. namespace Slic3r { namespace GL {
  5. void ShaderCSGDisplay::add_mesh(const TriangleMesh &mesh)
  6. {
  7. auto v = std::make_shared<CSGVolume>();
  8. v->load_mesh(mesh);
  9. m_volumes.emplace_back(v);
  10. }
  11. void ShaderCSGDisplay::render_scene()
  12. {
  13. GLfloat color[] = {1.f, 1.f, 0.f, 0.f};
  14. glColor4fv(color);
  15. glDepthFunc(GL_LESS);
  16. for (auto &v : m_volumes) v->render();
  17. glFlush();
  18. }
  19. void ShaderCSGDisplay::on_scene_updated(const Scene &scene)
  20. {
  21. // TriangleMesh mesh = print->objects().front()->hollowed_interior_mesh();
  22. // Look at CSGDisplay::on_scene_updated to see how its done there.
  23. const SLAPrint *print = scene.get_print();
  24. if (!print) return;
  25. m_volumes.clear();
  26. for (const SLAPrintObject *po : print->objects()) {
  27. const ModelObject *mo = po->model_object();
  28. TriangleMesh msh = mo->raw_mesh();
  29. sla::DrainHoles holedata = mo->sla_drain_holes;
  30. for (const ModelInstance *mi : mo->instances) {
  31. TriangleMesh mshinst = msh;
  32. auto interior = po->hollowed_interior_mesh();
  33. interior.transform(po->trafo().inverse());
  34. mshinst.merge(interior);
  35. mi->transform_mesh(&mshinst);
  36. auto bb = mshinst.bounding_box();
  37. auto center = bb.center().cast<float>();
  38. mshinst.translate(-center);
  39. add_mesh(mshinst);
  40. }
  41. for (const sla::DrainHole &holept : holedata)
  42. add_mesh(sla::to_triangle_mesh(holept.to_mesh()));
  43. }
  44. repaint();
  45. }
  46. }} // namespace Slic3r::GL