diff --git a/lib/Slic3r/Print/SupportMaterial.pm b/lib/Slic3r/Print/SupportMaterial.pm index 8cb66721a..05d5cf7b7 100644 --- a/lib/Slic3r/Print/SupportMaterial.pm +++ b/lib/Slic3r/Print/SupportMaterial.pm @@ -33,9 +33,9 @@ sub generate { # that it will be effective, regardless of how it's built below. my ($contact, $overhang) = $self->contact_area($object); - # Determine the top surfaces of the object. We need these to determine - # the layer heights of support material and to clip support to the object - # silhouette. + # // Determine the top surfaces of the object. We need these to determine + # // the layer heights of support material and to clip support to the object + # // silhouette. my ($top) = $self->object_top($object, $contact); # We now know the upper and lower boundaries for our support material object diff --git a/xs/src/libslic3r/SupportMaterial.cpp b/xs/src/libslic3r/SupportMaterial.cpp index 4c4735b42..8e541b2a2 100644 --- a/xs/src/libslic3r/SupportMaterial.cpp +++ b/xs/src/libslic3r/SupportMaterial.cpp @@ -53,8 +53,25 @@ SupportMaterial::contact_distance(coordf_t layer_height, coordf_t nozzle_diamete } vector -SupportMaterial::support_layers_z(vector contact_z, - vector top_z, +SupportMaterial::get_keys_sorted(map _map) { + vector ret; + for (auto el : _map) + ret.push_back(el.first); + sort(ret.begin(), ret.end()); + return ret; +} + +coordf_t +SupportMaterial::get_max_layer_height(PrintObject* object) { + coordf_t ret = -1; + for (auto layer : object->layers) + ret = max(ret, layer->height); + return ret; +} + +vector +SupportMaterial::support_layers_z(vector contact_z, + vector top_z, coordf_t max_object_layer_height) { // Quick table to check whether a given Z is a top surface. @@ -629,7 +646,7 @@ SupportMaterial::contact_area(PrintObject *object) overhang[contact_z] = m_overhang; } } - + return make_pair(contact, overhang); } diff --git a/xs/src/libslic3r/SupportMaterial.hpp b/xs/src/libslic3r/SupportMaterial.hpp index 73f6ba513..6b9099e58 100644 --- a/xs/src/libslic3r/SupportMaterial.hpp +++ b/xs/src/libslic3r/SupportMaterial.hpp @@ -16,9 +16,6 @@ #include "ExPolygon.hpp" #include "SVG.hpp" -// Supports Material tests. - - using namespace std; namespace Slic3r @@ -53,8 +50,61 @@ public: object(nullptr) {} - void generate() - {} + void generate(PrintObject *object) + { + // Determine the top surfaces of the support, defined as: + // contact = overhangs - clearance + margin + // This method is responsible for identifying what contact surfaces + // should the support material expose to the object in order to guarantee + // that it will be effective, regardless of how it's built below. + pair, map> contact_overhang = contact_area(object); + map &contact = contact_overhang.first; + map &overhang = contact_overhang.second; + + + // Determine the top surfaces of the object. We need these to determine + // the layer heights of support material and to clip support to the object + // silhouette. + map top = object_top(object, &contact); + + // We now know the upper and lower boundaries for our support material object + // (@$contact_z and @$top_z), so we can generate intermediate layers. + vector support_z = support_layers_z(get_keys_sorted(contact), + get_keys_sorted(top), + get_max_layer_height(object)); + + // If we wanted to apply some special logic to the first support layers lying on + // object's top surfaces this is the place to detect them. TODO + + + // Propagate contact layers downwards to generate interface layers. TODO + + // Propagate contact layers and interface layers downwards to generate + // the main support layers. TODO + + + // Detect what part of base support layers are "reverse interfaces" because they + // lie above object's top surfaces. TODO + + + // Install support layers into object. + for (int i = 0; i < support_z.size(); i++) { + object->add_support_layer( + i, // id. + (i == 0) ? support_z[0] - 0 : (support_z[i] - support_z[i-1]), // height. + support_z[i] // print_z + ); + + if (i >= 1) { + object->support_layers.end()[-2]->upper_layer = object->support_layers.end()[-1]; + object->support_layers.end()[-1]->lower_layer = object->support_layers.end()[-2]; + } + } + + // Generate the actual toolpaths and save them into each layer. + generate_toolpaths(object, overhang, contact, interface, base); + + } void generate_interface_layers() {} @@ -89,7 +139,9 @@ public: /// This method returns the indices of the layers overlapping with the given one. vector overlapping_layers(int layer_idx, vector support_z); - vector support_layers_z(vector contact_z, vector top_z, coordf_t max_object_layer_height); + vector support_layers_z(vector contact_z, + vector top_z, + coordf_t max_object_layer_height); coordf_t contact_distance(coordf_t layer_height, coordf_t nozzle_diameter); @@ -99,6 +151,10 @@ public: void append_polygons(Polygons &dst, Polygons &src); + vector get_keys_sorted(map _map); + + coordf_t get_max_layer_height(PrintObject *object); + void process_layer(int layer_id) { SupportLayer *layer = this->object->support_layers[layer_id]; @@ -133,6 +189,7 @@ private: }; // To Be converted to catch. +// Supports Material tests. class SupportMaterialTests { public: @@ -158,8 +215,8 @@ public: print.default_object_config.set_deserialize("layer_height", "0.2"); print.config.set_deserialize("first_layer_height", "0.3"); - vector contact_z; - vector top_z; + vector contact_z; + vector top_z; contact_z.push_back(1.9); top_z.push_back(1.9);