ShaderCSGDisplay.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. mshinst.require_shared_vertices();
  36. mi->transform_mesh(&mshinst);
  37. auto bb = mshinst.bounding_box();
  38. auto center = bb.center().cast<float>();
  39. mshinst.translate(-center);
  40. mshinst.require_shared_vertices();
  41. add_mesh(mshinst);
  42. }
  43. for (const sla::DrainHole &holept : holedata) {
  44. TriangleMesh holemesh = sla::to_triangle_mesh(holept.to_mesh());
  45. holemesh.require_shared_vertices();
  46. add_mesh(holemesh);
  47. }
  48. }
  49. repaint();
  50. }
  51. }} // namespace Slic3r::GL