Merge remote-tracking branch 'origin/scene_manipulators'
This commit is contained in:
commit
913cdef297
12 changed files with 238 additions and 63 deletions
|
@ -16,6 +16,8 @@
|
|||
|
||||
namespace Slic3r {
|
||||
|
||||
unsigned int Model::s_auto_extruder_id = 1;
|
||||
|
||||
Model::Model(const Model &other)
|
||||
{
|
||||
// copy materials
|
||||
|
@ -405,10 +407,19 @@ void Model::convert_multipart_object()
|
|||
|
||||
ModelObject* object = new ModelObject(this);
|
||||
object->input_file = this->objects.front()->input_file;
|
||||
|
||||
|
||||
reset_auto_extruder_id();
|
||||
|
||||
for (const ModelObject* o : this->objects)
|
||||
for (const ModelVolume* v : o->volumes)
|
||||
object->add_volume(*v)->name = o->name;
|
||||
{
|
||||
ModelVolume* new_v = object->add_volume(*v);
|
||||
if (new_v != nullptr)
|
||||
{
|
||||
new_v->name = o->name;
|
||||
new_v->config.set_deserialize("extruder", get_auto_extruder_id_as_string());
|
||||
}
|
||||
}
|
||||
|
||||
for (const ModelInstance* i : this->objects.front()->instances)
|
||||
object->add_instance(*i);
|
||||
|
@ -466,6 +477,28 @@ bool Model::fits_print_volume(const FullPrintConfig &config) const
|
|||
return print_volume.contains(transformed_bounding_box());
|
||||
}
|
||||
|
||||
unsigned int Model::get_auto_extruder_id()
|
||||
{
|
||||
unsigned int id = s_auto_extruder_id;
|
||||
|
||||
if (++s_auto_extruder_id > 4)
|
||||
reset_auto_extruder_id();
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
std::string Model::get_auto_extruder_id_as_string()
|
||||
{
|
||||
char str_extruder[64];
|
||||
sprintf(str_extruder, "%ud", get_auto_extruder_id());
|
||||
return str_extruder;
|
||||
}
|
||||
|
||||
void Model::reset_auto_extruder_id()
|
||||
{
|
||||
s_auto_extruder_id = 1;
|
||||
}
|
||||
|
||||
ModelObject::ModelObject(Model *model, const ModelObject &other, bool copy_volumes) :
|
||||
name(other.name),
|
||||
input_file(other.input_file),
|
||||
|
@ -830,33 +863,9 @@ void ModelObject::cut(coordf_t z, Model* model) const
|
|||
lower->add_volume(*volume);
|
||||
} else {
|
||||
TriangleMesh upper_mesh, lower_mesh;
|
||||
// TODO: shouldn't we use object bounding box instead of per-volume bb?
|
||||
coordf_t cut_z = z + volume->mesh.bounding_box().min.z;
|
||||
if (false) {
|
||||
// if (volume->mesh.has_multiple_patches()) {
|
||||
// Cutting algorithm does not work on intersecting meshes.
|
||||
// As we are not sure whether the meshes don't intersect,
|
||||
// we rather split the mesh into multiple non-intersecting pieces.
|
||||
TriangleMeshPtrs meshptrs = volume->mesh.split();
|
||||
for (TriangleMeshPtrs::iterator mesh = meshptrs.begin(); mesh != meshptrs.end(); ++mesh) {
|
||||
printf("Cutting mesh patch %d of %d\n", int(mesh - meshptrs.begin()), int(meshptrs.size()));
|
||||
(*mesh)->repair();
|
||||
TriangleMeshSlicer tms(*mesh);
|
||||
if (mesh == meshptrs.begin()) {
|
||||
tms.cut(cut_z, &upper_mesh, &lower_mesh);
|
||||
} else {
|
||||
TriangleMesh upper_mesh_this, lower_mesh_this;
|
||||
tms.cut(cut_z, &upper_mesh_this, &lower_mesh_this);
|
||||
upper_mesh.merge(upper_mesh_this);
|
||||
lower_mesh.merge(lower_mesh_this);
|
||||
}
|
||||
delete *mesh;
|
||||
}
|
||||
} else {
|
||||
printf("Cutting mesh patch\n");
|
||||
TriangleMeshSlicer tms(&volume->mesh);
|
||||
tms.cut(cut_z, &upper_mesh, &lower_mesh);
|
||||
}
|
||||
printf("Cutting mesh patch\n");
|
||||
TriangleMeshSlicer tms(&volume->mesh);
|
||||
tms.cut(z, &upper_mesh, &lower_mesh);
|
||||
|
||||
upper_mesh.repair();
|
||||
lower_mesh.repair();
|
||||
|
@ -995,6 +1004,9 @@ size_t ModelVolume::split()
|
|||
size_t idx = 0;
|
||||
size_t ivolume = std::find(this->object->volumes.begin(), this->object->volumes.end(), this) - this->object->volumes.begin();
|
||||
std::string name = this->name;
|
||||
|
||||
Model::reset_auto_extruder_id();
|
||||
|
||||
for (TriangleMesh *mesh : meshptrs) {
|
||||
mesh->repair();
|
||||
if (idx == 0)
|
||||
|
@ -1004,6 +1016,7 @@ size_t ModelVolume::split()
|
|||
char str_idx[64];
|
||||
sprintf(str_idx, "_%d", idx + 1);
|
||||
this->object->volumes[ivolume]->name = name + str_idx;
|
||||
this->object->volumes[ivolume]->config.set_deserialize("extruder", Model::get_auto_extruder_id_as_string());
|
||||
delete mesh;
|
||||
++ idx;
|
||||
}
|
||||
|
|
|
@ -230,6 +230,8 @@ private:
|
|||
// all objects may share mutliple materials.
|
||||
class Model
|
||||
{
|
||||
static unsigned int s_auto_extruder_id;
|
||||
|
||||
public:
|
||||
// Materials are owned by a model and referenced by objects through t_model_material_id.
|
||||
// Single material may be shared by multiple models.
|
||||
|
@ -288,6 +290,10 @@ public:
|
|||
bool fits_print_volume(const FullPrintConfig &config) const;
|
||||
|
||||
void print_info() const { for (const ModelObject *o : this->objects) o->print_info(); }
|
||||
|
||||
static unsigned int get_auto_extruder_id();
|
||||
static std::string get_auto_extruder_id_as_string();
|
||||
static void reset_auto_extruder_id();
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
#include "../../libslic3r/GCode/PreviewData.hpp"
|
||||
#include "../../libslic3r/Print.hpp"
|
||||
#include "../../libslic3r/Slicing.hpp"
|
||||
#include "../../slic3r/GUI/PresetBundle.hpp"
|
||||
#include "GCode/Analyzer.hpp"
|
||||
|
||||
#include <stdio.h>
|
||||
|
@ -304,7 +305,7 @@ void GLVolume::render_using_layer_height() const
|
|||
glUniform1f(z_texture_row_to_normalized_id, (GLfloat)(1.0f / layer_height_texture_height()));
|
||||
|
||||
if (z_cursor_id >= 0)
|
||||
glUniform1f(z_cursor_id, (GLfloat)(bounding_box.max.z * layer_height_texture_data.z_cursor_relative));
|
||||
glUniform1f(z_cursor_id, (GLfloat)(layer_height_texture_data.print_object->model_object()->bounding_box().max.z * layer_height_texture_data.z_cursor_relative));
|
||||
|
||||
if (z_cursor_band_width_id >= 0)
|
||||
glUniform1f(z_cursor_band_width_id, (GLfloat)layer_height_texture_data.edit_band_width);
|
||||
|
@ -326,6 +327,11 @@ void GLVolume::render_using_layer_height() const
|
|||
glUseProgram(current_program_id);
|
||||
}
|
||||
|
||||
double GLVolume::layer_height_texture_z_to_row_id() const
|
||||
{
|
||||
return (this->layer_height_texture.get() == nullptr) ? 0.0 : double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * this->layer_height_texture_data.print_object->model_object()->bounding_box().max.z);
|
||||
}
|
||||
|
||||
void GLVolume::generate_layer_height_texture(PrintObject *print_object, bool force)
|
||||
{
|
||||
GLTexture *tex = this->layer_height_texture.get();
|
||||
|
@ -381,6 +387,15 @@ std::vector<int> GLVolumeCollection::load_object(
|
|||
std::vector<int> volumes_idx;
|
||||
for (int volume_idx = 0; volume_idx < int(model_object->volumes.size()); ++ volume_idx) {
|
||||
const ModelVolume *model_volume = model_object->volumes[volume_idx];
|
||||
|
||||
int extruder_id = -1;
|
||||
if (!model_volume->modifier)
|
||||
{
|
||||
extruder_id = model_volume->config.has("extruder") ? model_volume->config.option("extruder")->getInt() : 0;
|
||||
if (extruder_id == 0)
|
||||
extruder_id = model_object->config.has("extruder") ? model_object->config.option("extruder")->getInt() : 0;
|
||||
}
|
||||
|
||||
for (int instance_idx : instance_idxs) {
|
||||
const ModelInstance *instance = model_object->instances[instance_idx];
|
||||
TriangleMesh mesh = model_volume->mesh;
|
||||
|
@ -410,8 +425,14 @@ std::vector<int> GLVolumeCollection::load_object(
|
|||
v.drag_group_id = obj_idx * 1000;
|
||||
else if (drag_by == "instance")
|
||||
v.drag_group_id = obj_idx * 1000 + instance_idx;
|
||||
if (! model_volume->modifier)
|
||||
|
||||
if (!model_volume->modifier)
|
||||
{
|
||||
v.layer_height_texture = layer_height_texture;
|
||||
if (extruder_id != -1)
|
||||
v.extruder_id = extruder_id;
|
||||
}
|
||||
v.is_modifier = model_volume->modifier;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -443,6 +464,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
|
|||
v.composite_id = obj_idx * 1000000;
|
||||
v.select_group_id = obj_idx * 1000000;
|
||||
v.drag_group_id = obj_idx * 1000;
|
||||
v.is_wipe_tower = true;
|
||||
return int(this->volumes.size() - 1);
|
||||
}
|
||||
|
||||
|
@ -647,6 +669,83 @@ void GLVolumeCollection::update_outside_state(const DynamicPrintConfig* config,
|
|||
}
|
||||
}
|
||||
|
||||
void GLVolumeCollection::update_colors_by_extruder(const DynamicPrintConfig* config)
|
||||
{
|
||||
static const float inv_255 = 1.0f / 255.0f;
|
||||
|
||||
struct Color
|
||||
{
|
||||
std::string text;
|
||||
unsigned char rgb[3];
|
||||
|
||||
Color()
|
||||
: text("")
|
||||
{
|
||||
rgb[0] = 255;
|
||||
rgb[1] = 255;
|
||||
rgb[2] = 255;
|
||||
}
|
||||
|
||||
void set(const std::string& text, unsigned char* rgb)
|
||||
{
|
||||
this->text = text;
|
||||
::memcpy((void*)this->rgb, (const void*)rgb, 3 * sizeof(unsigned char));
|
||||
}
|
||||
};
|
||||
|
||||
if (config == nullptr)
|
||||
return;
|
||||
|
||||
const ConfigOptionStrings* extruders_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("extruder_colour"));
|
||||
if (extruders_opt == nullptr)
|
||||
return;
|
||||
|
||||
const ConfigOptionStrings* filamemts_opt = dynamic_cast<const ConfigOptionStrings*>(config->option("filament_colour"));
|
||||
if (filamemts_opt == nullptr)
|
||||
return;
|
||||
|
||||
unsigned int colors_count = std::max((unsigned int)extruders_opt->values.size(), (unsigned int)filamemts_opt->values.size());
|
||||
if (colors_count == 0)
|
||||
return;
|
||||
|
||||
std::vector<Color> colors(colors_count);
|
||||
|
||||
unsigned char rgb[3];
|
||||
for (unsigned int i = 0; i < colors_count; ++i)
|
||||
{
|
||||
const std::string& txt_color = config->opt_string("extruder_colour", i);
|
||||
if (PresetBundle::parse_color(txt_color, rgb))
|
||||
{
|
||||
colors[i].set(txt_color, rgb);
|
||||
}
|
||||
else
|
||||
{
|
||||
const std::string& txt_color = config->opt_string("filament_colour", i);
|
||||
if (PresetBundle::parse_color(txt_color, rgb))
|
||||
colors[i].set(txt_color, rgb);
|
||||
}
|
||||
}
|
||||
|
||||
for (GLVolume* volume : volumes)
|
||||
{
|
||||
if ((volume == nullptr) || volume->is_modifier || volume->is_wipe_tower)
|
||||
continue;
|
||||
|
||||
int extruder_id = volume->extruder_id - 1;
|
||||
if ((extruder_id < 0) || ((unsigned int)colors.size() <= extruder_id))
|
||||
extruder_id = 0;
|
||||
|
||||
const Color& color = colors[extruder_id];
|
||||
if (!color.text.empty())
|
||||
{
|
||||
for (int i = 0; i < 3; ++i)
|
||||
{
|
||||
volume->color[i] = (float)color.rgb[i] * inv_255;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<double> GLVolumeCollection::get_current_print_zs() const
|
||||
{
|
||||
// Collect layer top positions of all volumes.
|
||||
|
|
|
@ -246,12 +246,15 @@ public:
|
|||
composite_id(-1),
|
||||
select_group_id(-1),
|
||||
drag_group_id(-1),
|
||||
extruder_id(0),
|
||||
selected(false),
|
||||
is_active(true),
|
||||
zoom_to_volumes(true),
|
||||
outside_printer_detection_enabled(true),
|
||||
is_outside(false),
|
||||
hover(false),
|
||||
is_modifier(false),
|
||||
is_wipe_tower(false),
|
||||
tverts_range(0, size_t(-1)),
|
||||
qverts_range(0, size_t(-1))
|
||||
{
|
||||
|
@ -287,6 +290,8 @@ public:
|
|||
int select_group_id;
|
||||
// An ID for group dragging. It may be the same for all meshes of all object instances, or for just a single object instance.
|
||||
int drag_group_id;
|
||||
// An ID containing the extruder ID (used to select color).
|
||||
int extruder_id;
|
||||
// Is this object selected?
|
||||
bool selected;
|
||||
// Whether or not this volume is active for rendering
|
||||
|
@ -299,6 +304,10 @@ public:
|
|||
bool is_outside;
|
||||
// Boolean: Is mouse over this object?
|
||||
bool hover;
|
||||
// Wheter or not this volume has been generated from a modifier
|
||||
bool is_modifier;
|
||||
// Wheter or not this volume has been generated from the wipe tower
|
||||
bool is_wipe_tower;
|
||||
|
||||
// Interleaved triangles & normals with indexed triangles & quads.
|
||||
GLIndexedVertexArray indexed_vertex_array;
|
||||
|
@ -352,10 +361,7 @@ public:
|
|||
return (layer_height_texture.get() == nullptr) ? 0 :
|
||||
(void*)(layer_height_texture->data.data() + layer_height_texture->width * layer_height_texture->height * 4);
|
||||
}
|
||||
double layer_height_texture_z_to_row_id() const {
|
||||
return (this->layer_height_texture.get() == nullptr) ? 0. :
|
||||
double(this->layer_height_texture->cells - 1) / (double(this->layer_height_texture->width) * bounding_box.max.z);
|
||||
}
|
||||
double layer_height_texture_z_to_row_id() const;
|
||||
void generate_layer_height_texture(PrintObject *print_object, bool force);
|
||||
|
||||
void set_layer_height_texture_data(unsigned int texture_id, unsigned int shader_id, PrintObject* print_object, float z_cursor_relative, float edit_band_width)
|
||||
|
@ -417,6 +423,7 @@ public:
|
|||
}
|
||||
|
||||
void update_outside_state(const DynamicPrintConfig* config, bool all_inside);
|
||||
void update_colors_by_extruder(const DynamicPrintConfig* config);
|
||||
|
||||
// Returns a vector containing the sorted list of all the print_zs of the volumes contained in this collection
|
||||
std::vector<double> get_current_print_zs() const;
|
||||
|
|
|
@ -990,7 +990,7 @@ static inline int hex_digit_to_int(const char c)
|
|||
(c >= 'a' && c <= 'f') ? int(c - 'a') + 10 : -1;
|
||||
}
|
||||
|
||||
static inline bool parse_color(const std::string &scolor, unsigned char *rgb_out)
|
||||
bool PresetBundle::parse_color(const std::string &scolor, unsigned char *rgb_out)
|
||||
{
|
||||
rgb_out[0] = rgb_out[1] = rgb_out[2] = 0;
|
||||
if (scolor.size() != 7 || scolor.front() != '#')
|
||||
|
|
|
@ -117,6 +117,8 @@ public:
|
|||
// preset if the current print or filament preset is not compatible.
|
||||
void update_compatible_with_printer(bool select_other_if_incompatible);
|
||||
|
||||
static bool parse_color(const std::string &scolor, unsigned char *rgb_out);
|
||||
|
||||
private:
|
||||
std::string load_system_presets();
|
||||
|
||||
|
|
|
@ -105,6 +105,7 @@
|
|||
|
||||
void set_print_box(float min_x, float min_y, float min_z, float max_x, float max_y, float max_z);
|
||||
void update_outside_state(DynamicPrintConfig* config, bool all_inside);
|
||||
void update_colors_by_extruder(DynamicPrintConfig* config);
|
||||
|
||||
bool move_volume_up(int idx)
|
||||
%code%{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue