GUI_3DScene.xsp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. %module{Slic3r::XS};
  2. #include <xsinit.h>
  3. #include "slic3r/GUI/GLShader.hpp"
  4. #include "slic3r/GUI/3DScene.hpp"
  5. %name{Slic3r::GUI::_3DScene::GLShader} class GLShader {
  6. GLShader();
  7. ~GLShader();
  8. bool load(const char *fragment_shader, const char *vertex_shader);
  9. void release();
  10. int get_attrib_location(const char *name) const;
  11. int get_uniform_location(const char *name) const;
  12. bool set_uniform(const char *name, float value) const;
  13. void enable() const;
  14. void disable() const;
  15. std::string last_error() const
  16. %code%{ RETVAL = THIS->last_error; %};
  17. };
  18. %name{Slic3r::GUI::_3DScene::GLVolume} class GLVolume {
  19. GLVolume();
  20. ~GLVolume();
  21. std::vector<double> color()
  22. %code%{ RETVAL.reserve(4); RETVAL.push_back(THIS->color[0]); RETVAL.push_back(THIS->color[1]); RETVAL.push_back(THIS->color[2]); RETVAL.push_back(THIS->color[3]); %};
  23. int select_group_id()
  24. %code%{ RETVAL = THIS->select_group_id; %};
  25. int drag_group_id()
  26. %code%{ RETVAL = THIS->drag_group_id; %};
  27. int selected()
  28. %code%{ RETVAL = THIS->selected; %};
  29. void set_selected(int i)
  30. %code%{ THIS->selected = i; %};
  31. int hover()
  32. %code%{ RETVAL = THIS->hover; %};
  33. void set_hover(int i)
  34. %code%{ THIS->hover = i; %};
  35. int object_idx() const;
  36. int volume_idx() const;
  37. int instance_idx() const;
  38. Clone<Pointf3> origin() const
  39. %code%{ RETVAL = THIS->origin; %};
  40. void translate(double x, double y, double z)
  41. %code%{ THIS->origin.translate(x, y, z); %};
  42. Clone<BoundingBoxf3> bounding_box() const
  43. %code%{ RETVAL = THIS->bounding_box; %};
  44. Clone<BoundingBoxf3> transformed_bounding_box() const;
  45. bool empty() const;
  46. bool indexed() const;
  47. void render() const;
  48. bool has_layer_height_texture();
  49. int layer_height_texture_width();
  50. int layer_height_texture_height();
  51. int layer_height_texture_cells();
  52. void* layer_height_texture_data_ptr_level0();
  53. void* layer_height_texture_data_ptr_level1();
  54. double layer_height_texture_z_to_row_id() const;
  55. void generate_layer_height_texture(PrintObject *print_object, bool force);
  56. };
  57. %name{Slic3r::GUI::_3DScene::GLVolume::Collection} class GLVolumeCollection {
  58. GLVolumeCollection();
  59. ~GLVolumeCollection();
  60. std::vector<int> load_object(ModelObject *object, int obj_idx, std::vector<int> instance_idxs, std::string color_by, std::string select_by, std::string drag_by, bool use_VBOs);
  61. int load_wipe_tower_preview(int obj_idx, float pos_x, float pos_y, float width, float depth, float height, bool use_VBOs);
  62. void erase()
  63. %code{% THIS->clear(); %};
  64. int count()
  65. %code{% RETVAL = THIS->volumes.size(); %};
  66. void set_range(double low, double high);
  67. void render_VBOs() const;
  68. void render_legacy() const;
  69. void finalize_geometry(bool use_VBOs);
  70. void release_geometry();
  71. bool move_volume_up(int idx)
  72. %code%{
  73. if (idx > 0 && idx < int(THIS->volumes.size())) {
  74. std::swap(THIS->volumes[idx-1], THIS->volumes[idx]);
  75. std::swap(THIS->volumes[idx-1]->composite_id, THIS->volumes[idx]->composite_id);
  76. std::swap(THIS->volumes[idx-1]->select_group_id, THIS->volumes[idx]->select_group_id);
  77. std::swap(THIS->volumes[idx-1]->drag_group_id, THIS->volumes[idx]->drag_group_id);
  78. RETVAL = true;
  79. } else
  80. RETVAL = false;
  81. %};
  82. bool move_volume_down(int idx)
  83. %code%{
  84. if (idx >= 0 && idx + 1 < int(THIS->volumes.size())) {
  85. std::swap(THIS->volumes[idx+1], THIS->volumes[idx]);
  86. std::swap(THIS->volumes[idx+1]->composite_id, THIS->volumes[idx]->composite_id);
  87. std::swap(THIS->volumes[idx+1]->select_group_id, THIS->volumes[idx]->select_group_id);
  88. std::swap(THIS->volumes[idx+1]->drag_group_id, THIS->volumes[idx]->drag_group_id);
  89. RETVAL = true;
  90. } else
  91. RETVAL = false;
  92. %};
  93. %{
  94. SV*
  95. GLVolumeCollection::arrayref()
  96. CODE:
  97. AV* av = newAV();
  98. av_fill(av, THIS->volumes.size()-1);
  99. int i = 0;
  100. for (GLVolume *v : THIS->volumes) {
  101. av_store(av, i++, perl_to_SV_ref(*v));
  102. }
  103. RETVAL = newRV_noinc((SV*)av);
  104. OUTPUT:
  105. RETVAL
  106. %}
  107. };
  108. %package{Slic3r::GUI::_3DScene};
  109. %{
  110. void
  111. _glew_init()
  112. CODE:
  113. _3DScene::_glew_init();
  114. void
  115. _load_print_toolpaths(print, volumes, tool_colors, use_VBOs)
  116. Print *print;
  117. GLVolumeCollection *volumes;
  118. std::vector<std::string> tool_colors;
  119. int use_VBOs;
  120. CODE:
  121. _3DScene::_load_print_toolpaths(print, volumes, tool_colors, use_VBOs != 0);
  122. void
  123. _load_print_object_toolpaths(print_object, volumes, tool_colors, use_VBOs)
  124. PrintObject *print_object;
  125. GLVolumeCollection *volumes;
  126. std::vector<std::string> tool_colors;
  127. int use_VBOs;
  128. CODE:
  129. _3DScene::_load_print_object_toolpaths(print_object, volumes, tool_colors, use_VBOs != 0);
  130. void
  131. _load_wipe_tower_toolpaths(print, volumes, tool_colors, use_VBOs)
  132. Print *print;
  133. GLVolumeCollection *volumes;
  134. std::vector<std::string> tool_colors;
  135. int use_VBOs;
  136. CODE:
  137. _3DScene::_load_wipe_tower_toolpaths(print, volumes, tool_colors, use_VBOs != 0);
  138. %}