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:
lane.wei
2024-09-02 19:51:02 +08:00
committed by Noisyfox
parent f702ad9fd2
commit 6e063bdc8d
7 changed files with 157 additions and 6 deletions

View File

@@ -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();

View File

@@ -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 };