Skip to content

Commit 6bc04ce

Browse files
Copilotcochcoder
andcommitted
Fix tree supports not generating: transfer Rust FFI polygon data to SupportLayer objects
Co-authored-by: cochcoder <103969142+cochcoder@users.noreply.github.com>
1 parent fe5b4f3 commit 6bc04ce

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

src/libslic3r/PrintObject.cpp

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
#include "Support/SupportSpotsGenerator.hpp"
1313
#ifdef HAS_RUST_TREE_SUPPORTS
1414
#include "Support/TreeSupportRust/include/orca_tree_supports.h"
15+
#include "Support/SupportCommon.hpp"
16+
#include "Support/SupportParameters.hpp"
1517
#endif
1618
#include "Surface.hpp"
1719
#include "Slicing.hpp"
@@ -4018,15 +4020,44 @@ void PrintObject::_generate_support_material()
40184020
TreeSupportHandle *handle = orca_tree_support_create(&cfg, &mesh_data);
40194021
if (handle) {
40204022
SupportOutput *output = orca_tree_support_generate(handle);
4021-
if (output && output->success) {
4022-
// Convert Rust output to SupportLayer objects
4023-
// Note: layer.z is already in millimeters (not scaled)
4023+
if (output && output->success && output->layer_count > 0) {
4024+
// Set up support parameters and flow for extrusion generation
4025+
SupportParameters support_params(*this);
4026+
Flow support_flow = Slic3r::support_material_flow(this, float(m_slicing_params.layer_height));
4027+
4028+
// Convert Rust output to SupportLayer objects with polygon data
40244029
for (uint32_t i = 0; i < output->layer_count; i++) {
40254030
const auto &layer = output->layers[i];
40264031
coordf_t print_z = layer.z;
40274032
coordf_t height = (i > 0) ? print_z - output->layers[i - 1].z : print_z;
4028-
add_tree_support_layer(static_cast<int>(i), height, print_z, print_z - 0.5 * height);
4033+
SupportLayer *support_layer = add_tree_support_layer(static_cast<int>(i), height, print_z, print_z - 0.5 * height);
4034+
4035+
// Convert Rust polygon data to Slic3r Polygons
4036+
Polygons polygons;
4037+
if (layer.polygon_count > 0 && layer.polygon_points != nullptr && layer.polygon_sizes != nullptr) {
4038+
uint32_t point_offset = 0;
4039+
for (uint32_t p = 0; p < layer.polygon_count; p++) {
4040+
uint32_t poly_size = layer.polygon_sizes[p];
4041+
Polygon polygon;
4042+
polygon.points.reserve(poly_size);
4043+
for (uint32_t j = 0; j < poly_size; j++) {
4044+
const auto &pt = layer.polygon_points[point_offset + j];
4045+
polygon.points.emplace_back(static_cast<coord_t>(pt.x), static_cast<coord_t>(pt.y));
4046+
}
4047+
point_offset += poly_size;
4048+
if (!polygon.points.empty())
4049+
polygons.push_back(std::move(polygon));
4050+
}
4051+
}
4052+
4053+
if (!polygons.empty()) {
4054+
// Store as base_areas for retraction suppression
4055+
support_layer->base_areas = union_ex(polygons);
4056+
// Generate extrusion fills for G-code output
4057+
tree_supports_generate_paths(support_layer->support_fills.entities, polygons, support_flow, support_params);
4058+
}
40294059
}
4060+
BOOST_LOG_TRIVIAL(info) << "Rust tree support generated " << output->layer_count << " layers, " << output->branch_count << " branches";
40304061
} else if (output && !output->success) {
40314062
BOOST_LOG_TRIVIAL(error) << "Rust tree support generation failed";
40324063
} else {

0 commit comments

Comments
 (0)