Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEnrico Turri <enricoturri@seznam.cz>2018-03-09 12:40:42 +0300
committerEnrico Turri <enricoturri@seznam.cz>2018-03-09 12:40:42 +0300
commitbdd2d725c83fca0d3a84f19cf9ae25ce2525cbb9 (patch)
treef714c2d34bcf7db747040724323f2e5b6ed59447 /xs/src/libslic3r/Model.cpp
parent83a2d2af4b2748d1138d1520c11ddac7960fb644 (diff)
Out of bed detection - 1st installment
Diffstat (limited to 'xs/src/libslic3r/Model.cpp')
-rw-r--r--xs/src/libslic3r/Model.cpp72
1 files changed, 70 insertions, 2 deletions
diff --git a/xs/src/libslic3r/Model.cpp b/xs/src/libslic3r/Model.cpp
index 1de99bbf8..944bf7743 100644
--- a/xs/src/libslic3r/Model.cpp
+++ b/xs/src/libslic3r/Model.cpp
@@ -222,7 +222,7 @@ bool Model::add_default_instances()
}
// this returns the bounding box of the *transformed* instances
-BoundingBoxf3 Model::bounding_box()
+BoundingBoxf3 Model::bounding_box() const
{
BoundingBoxf3 bb;
for (ModelObject *o : this->objects)
@@ -230,6 +230,57 @@ BoundingBoxf3 Model::bounding_box()
return bb;
}
+BoundingBoxf3 Model::transformed_bounding_box() const
+{
+ BoundingBoxf3 bb;
+
+ for (const ModelObject* obj : this->objects)
+ {
+ for (const ModelVolume* vol : obj->volumes)
+ {
+ if (!vol->modifier)
+ {
+ for (const ModelInstance* inst : obj->instances)
+ {
+ double c = cos(inst->rotation);
+ double s = sin(inst->rotation);
+
+ for (int f = 0; f < vol->mesh.stl.stats.number_of_facets; ++f)
+ {
+ const stl_facet& facet = vol->mesh.stl.facet_start[f];
+
+ for (int i = 0; i < 3; ++i)
+ {
+ // original point
+ const stl_vertex& v = facet.vertex[i];
+ Pointf3 p((double)v.x, (double)v.y, (double)v.z);
+
+ // scale
+ p.x *= inst->scaling_factor;
+ p.y *= inst->scaling_factor;
+ p.z *= inst->scaling_factor;
+
+ // rotate Z
+ double x = p.x;
+ double y = p.y;
+ p.x = c * x - s * y;
+ p.y = s * x + c * y;
+
+ // translate
+ p.x += inst->offset.x;
+ p.y += inst->offset.y;
+
+ bb.merge(p);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ return bb;
+}
+
void Model::center_instances_around_point(const Pointf &point)
{
// BoundingBoxf3 bb = this->bounding_box();
@@ -409,6 +460,23 @@ void Model::convert_multipart_object()
this->objects.push_back(object);
}
+bool Model::fits_print_volume(const DynamicPrintConfig* config) const
+{
+ if (config == nullptr)
+ return false;
+
+ if (objects.empty())
+ return true;
+
+ const ConfigOptionPoints* opt = dynamic_cast<const ConfigOptionPoints*>(config->option("bed_shape"));
+ if (opt == nullptr)
+ return false;
+
+ BoundingBox bed_box_2D = get_extents(Polygon::new_scale(opt->values));
+ BoundingBoxf3 print_volume(Pointf3(unscale(bed_box_2D.min.x), unscale(bed_box_2D.min.y), 0.0), Pointf3(unscale(bed_box_2D.max.x), unscale(bed_box_2D.max.y), config->opt_float("max_print_height")));
+ return print_volume.contains(transformed_bounding_box());
+}
+
ModelObject::ModelObject(Model *model, const ModelObject &other, bool copy_volumes) :
name(other.name),
input_file(other.input_file),
@@ -671,7 +739,7 @@ void ModelObject::transform(const float* matrix3x4)
v->mesh.transform(matrix3x4);
}
- origin_translation = Pointf3(0.0f, 0.0f, 0.0f);
+ origin_translation = Pointf3(0.0, 0.0, 0.0);
invalidate_bounding_box();
}