mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2026-02-15 17:09:43 -07:00
ENH: 3dbed: support rendering extruder area with different color
JIRA: STUDIO-7494 Change-Id: I717999e8b7ab1d7d350299b412a3a270c6ba7a9e (cherry picked from commit 62b1d00d1fd6675fd067b76778d6a577dfae0c24)
This commit is contained in:
parent
f702ad9fd2
commit
6e063bdc8d
7 changed files with 157 additions and 6 deletions
|
|
@ -79,11 +79,24 @@ BuildVolume::BuildVolume(const std::vector<Vec2d> &printable_area, const double
|
|||
|
||||
if (m_extruder_shapes.size() > 0)
|
||||
{
|
||||
m_shared_volume.data[0] = m_bboxf.min.x();
|
||||
m_shared_volume.data[1] = m_bboxf.min.y();
|
||||
m_shared_volume.data[2] = m_bboxf.max.x();
|
||||
m_shared_volume.data[3] = m_bboxf.max.y();
|
||||
for (unsigned int index = 0; index < m_extruder_shapes.size(); index++)
|
||||
{
|
||||
std::vector<Vec2d>& extruder_shape = m_extruder_shapes[index];
|
||||
BuildExtruderVolume extruder_volume;
|
||||
|
||||
if (extruder_shape.empty())
|
||||
{
|
||||
//should not happen
|
||||
BOOST_LOG_TRIVIAL(warning) << boost::format("Found invalid extruder_printable_area of index %1%")%index;
|
||||
assert(false);
|
||||
m_extruder_shapes.clear();
|
||||
return;
|
||||
}
|
||||
|
||||
if (extruder_shape == printable_area) {
|
||||
extruder_volume.same_with_bed = true;
|
||||
extruder_volume.type = m_type;
|
||||
|
|
@ -137,7 +150,20 @@ BuildVolume::BuildVolume(const std::vector<Vec2d> &printable_area, const double
|
|||
}
|
||||
m_extruder_volumes.push_back(std::move(extruder_volume));
|
||||
}
|
||||
|
||||
if (m_shared_volume.data[0] < extruder_volume.bboxf.min.x())
|
||||
m_shared_volume.data[0] = extruder_volume.bboxf.min.x();
|
||||
if (m_shared_volume.data[1] < extruder_volume.bboxf.min.y())
|
||||
m_shared_volume.data[1] = extruder_volume.bboxf.min.y();
|
||||
if (m_shared_volume.data[2] > extruder_volume.bboxf.max.x())
|
||||
m_shared_volume.data[2] = extruder_volume.bboxf.max.x();
|
||||
if (m_shared_volume.data[3] > extruder_volume.bboxf.max.y())
|
||||
m_shared_volume.data[3] = extruder_volume.bboxf.max.y();
|
||||
}
|
||||
|
||||
m_shared_volume.type = static_cast<int>(m_type);
|
||||
m_shared_volume.zs[0] = 0.f;
|
||||
m_shared_volume.zs[1] = printable_height;
|
||||
}
|
||||
|
||||
BOOST_LOG_TRIVIAL(debug) << "BuildVolume printable_area clasified as: " << this->type_name();
|
||||
|
|
|
|||
|
|
@ -12,9 +12,9 @@
|
|||
namespace Slic3r {
|
||||
|
||||
struct GCodeProcessorResult;
|
||||
enum class BuildVolume_Type : unsigned char {
|
||||
enum class BuildVolume_Type : char {
|
||||
// Not set yet or undefined.
|
||||
Invalid,
|
||||
Invalid = -1,
|
||||
// Rectangular print bed. Most common, cheap to work with.
|
||||
Rectangle,
|
||||
// Circular print bed. Common on detals, cheap to work with.
|
||||
|
|
@ -24,6 +24,7 @@ enum class BuildVolume_Type : unsigned char {
|
|||
// Some non convex shape.
|
||||
Custom
|
||||
};
|
||||
|
||||
// For collision detection of objects and G-code (extrusion paths) against the build volume.
|
||||
class BuildVolume
|
||||
{
|
||||
|
|
@ -31,12 +32,26 @@ public:
|
|||
|
||||
struct BuildExtruderVolume {
|
||||
bool same_with_bed{false};
|
||||
Type type{Type::Invalid};
|
||||
BuildVolume_Type type{BuildVolume_Type::Invalid};
|
||||
BoundingBox bbox;
|
||||
BoundingBoxf3 bboxf;
|
||||
Geometry::Circled circle;
|
||||
};
|
||||
|
||||
struct BuildSharedVolume
|
||||
{
|
||||
// see: Bed3D::EShapeType
|
||||
int type{ 0 };
|
||||
// data contains:
|
||||
// Rectangle:
|
||||
// [0] = min.x, [1] = min.y, [2] = max.x, [3] = max.y
|
||||
// Circle:
|
||||
// [0] = center.x, [1] = center.y, [3] = radius
|
||||
std::array<float, 4> data;
|
||||
// [0] = min z, [1] = max z
|
||||
std::array<float, 2> zs;
|
||||
};
|
||||
|
||||
// Initialized to empty, all zeros, Invalid.
|
||||
BuildVolume() {}
|
||||
// Initialize from PrintConfig::printable_area and PrintConfig::printable_height
|
||||
|
|
@ -46,6 +61,7 @@ public:
|
|||
const std::vector<Vec2d>& printable_area() const { return m_bed_shape; }
|
||||
double printable_height() const { return m_max_print_height; }
|
||||
const std::vector<std::vector<Vec2d>>& extruder_areas() const { return m_extruder_shapes; }
|
||||
const BuildSharedVolume& get_shared_volume() const { return m_shared_volume; }
|
||||
|
||||
// Derived data
|
||||
BuildVolume_Type type() const { return m_type; }
|
||||
|
|
@ -118,8 +134,9 @@ private:
|
|||
// Source definition of the print bed geometry (PrintConfig::printable_area)
|
||||
std::vector<Vec2d> m_bed_shape;
|
||||
//BBS: extruder shapes
|
||||
std::vector<std::vector<Vec2d>> m_extruder_shapes;
|
||||
std::vector<std::vector<Vec2d>> m_extruder_shapes; //original data from config
|
||||
std::vector<BuildExtruderVolume> m_extruder_volumes;
|
||||
BuildSharedVolume m_shared_volume; //used for rendering
|
||||
// Source definition of the print volume height (PrintConfig::printable_height)
|
||||
double m_max_print_height { 0.f };
|
||||
|
||||
|
|
|
|||
|
|
@ -690,15 +690,32 @@ void Bed3D::render_model(const Transform3d& view_matrix, const Transform3d& proj
|
|||
}
|
||||
|
||||
if (!m_model.get_filename().empty()) {
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("gouraud_light");
|
||||
const Camera & camera = wxGetApp().plater()->get_camera();
|
||||
const Transform3d &view_matrix = camera.get_view_matrix();
|
||||
const Transform3d &projection_matrix = camera.get_projection_matrix();
|
||||
GLShaderProgram* shader = wxGetApp().get_shader("hotbed");
|
||||
if (shader != nullptr) {
|
||||
shader->start_using();
|
||||
shader->set_uniform("emission_factor", 0.0f);
|
||||
const Transform3d model_matrix = Geometry::assemble_transform(m_model_offset);
|
||||
shader->set_uniform("volume_world_matrix", model_matrix);
|
||||
shader->set_uniform("view_model_matrix", view_matrix * model_matrix);
|
||||
shader->set_uniform("projection_matrix", projection_matrix);
|
||||
const Matrix3d view_normal_matrix = view_matrix.matrix().block(0, 0, 3, 3) * model_matrix.matrix().block(0, 0, 3, 3).inverse().transpose();
|
||||
shader->set_uniform("view_normal_matrix", view_normal_matrix);
|
||||
if (m_build_volume.get_extruder_area_count() > 0) {
|
||||
const BuildVolume::BuildSharedVolume& shared_volume = m_build_volume.get_shared_volume();
|
||||
std::array<float, 4> xy_data = shared_volume.data;
|
||||
shader->set_uniform("print_volume.type", shared_volume.type);
|
||||
shader->set_uniform("print_volume.xy_data", xy_data);
|
||||
std::array<float, 2> zs = shared_volume.zs;
|
||||
zs[0] = -1;
|
||||
shader->set_uniform("print_volume.z_data", zs);
|
||||
}
|
||||
else {
|
||||
//use -1 ad a invalid type
|
||||
shader->set_uniform("print_volume.type", -1);
|
||||
}
|
||||
m_model.render();
|
||||
shader->stop_using();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@ std::pair<bool, std::string> GLShadersManager::init()
|
|||
valid &= append_shader("thumbnail", { prefix + "thumbnail.vs", prefix + "thumbnail.fs"});
|
||||
// used to render printbed
|
||||
valid &= append_shader("printbed", { prefix + "printbed.vs", prefix + "printbed.fs" });
|
||||
valid &= append_shader("hotbed", {"110/hotbed.vs", "110/hotbed.fs"});
|
||||
// used to render options in gcode preview
|
||||
if (GUI::wxGetApp().is_gl_version_greater_or_equal_to(3, 3)) {
|
||||
valid &= append_shader("gouraud_light_instanced", { prefix + "gouraud_light_instanced.vs", prefix + "gouraud_light_instanced.fs" });
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class Button;
|
|||
namespace Slic3r {
|
||||
|
||||
class BuildVolume;
|
||||
enum class BuildVolume_Type : unsigned char;
|
||||
enum class BuildVolume_Type : char;
|
||||
class Model;
|
||||
class ModelObject;
|
||||
class ModelInstance;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue