mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-07-28 11:32:00 +08:00
Fix wrong boundingbox (don't rotate the boudingbox, rotate the object!)
supermerill/SuperSlicer#1612
This commit is contained in:
parent
5abd2fcd32
commit
de554d577b
@ -1218,19 +1218,20 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu
|
|||||||
if (pos_dot != std::string::npos && pos_dot > 0)
|
if (pos_dot != std::string::npos && pos_dot > 0)
|
||||||
object_name = object_name.substr(0, pos_dot);
|
object_name = object_name.substr(0, pos_dot);
|
||||||
//get bounding box for the instance
|
//get bounding box for the instance
|
||||||
BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box();
|
//BoundingBoxf3 raw_bbox = print_object->model_object()->raw_mesh_bounding_box();
|
||||||
BoundingBoxf3 m_bounding_box = print_instance.model_instance->transform_bounding_box(raw_bbox);
|
//BoundingBoxf3 bounding_box;// = print_instance.model_instance->transform_bounding_box(raw_bbox);
|
||||||
|
BoundingBoxf3 bounding_box = print_object->model_object()->instance_bounding_box(*print_instance.model_instance, false);
|
||||||
if (global_bounding_box.size().norm() == 0) {
|
if (global_bounding_box.size().norm() == 0) {
|
||||||
global_bounding_box = m_bounding_box;
|
global_bounding_box = bounding_box;
|
||||||
} else {
|
} else {
|
||||||
global_bounding_box.merge(m_bounding_box);
|
global_bounding_box.merge(bounding_box);
|
||||||
}
|
}
|
||||||
if (this->config().gcode_label_objects) {
|
if (this->config().gcode_label_objects) {
|
||||||
_write_format(file, "; object:{\"name\":\"%s\",\"id\":\"%s id:%d copy %d\",\"object_center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n",
|
_write_format(file, "; object:{\"name\":\"%s\",\"id\":\"%s id:%d copy %d\",\"object_center\":[%f,%f,%f],\"boundingbox_center\":[%f,%f,%f],\"boundingbox_size\":[%f,%f,%f]}\n",
|
||||||
object_name.c_str(), print_object->model_object()->name.c_str(), this->m_ordered_objects.size() - 1, copy_id,
|
object_name.c_str(), print_object->model_object()->name.c_str(), this->m_ordered_objects.size() - 1, copy_id,
|
||||||
m_bounding_box.center().x(), m_bounding_box.center().y(), 0.,
|
bounding_box.center().x(), bounding_box.center().y(), 0.,
|
||||||
m_bounding_box.center().x(), m_bounding_box.center().y(), m_bounding_box.center().z(),
|
bounding_box.center().x(), bounding_box.center().y(), bounding_box.center().z(),
|
||||||
m_bounding_box.size().x(), m_bounding_box.size().y(), m_bounding_box.size().z()
|
bounding_box.size().x(), bounding_box.size().y(), bounding_box.size().z()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
copy_id++;
|
copy_id++;
|
||||||
|
@ -349,7 +349,7 @@ Point SeamPlacer::get_seam(const Layer& layer, SeamPosition seam_position,
|
|||||||
Point nearest = polygon.point_projection(xy_lambda);
|
Point nearest = polygon.point_projection(xy_lambda);
|
||||||
Vec3d polygon_3dpoint{ unscaled(nearest.x()), unscaled(nearest.y()), (double)layer.print_z };
|
Vec3d polygon_3dpoint{ unscaled(nearest.x()), unscaled(nearest.y()), (double)layer.print_z };
|
||||||
double test_lambda_dist = (polygon_3dpoint - test_lambda_pos).norm();
|
double test_lambda_dist = (polygon_3dpoint - test_lambda_pos).norm();
|
||||||
double sphere_radius = po->model_object()->instances.front()->transform_bounding_box(v->mesh().bounding_box(), true).size().x() / 2;
|
double sphere_radius = po->model_object()->instance_bounding_box(0, true).size().x() / 2;
|
||||||
//if (test_lambda_dist > sphere_radius)
|
//if (test_lambda_dist > sphere_radius)
|
||||||
// continue;
|
// continue;
|
||||||
|
|
||||||
|
@ -805,10 +805,9 @@ const BoundingBoxf3& ModelObject::bounding_box() const
|
|||||||
{
|
{
|
||||||
if (! m_bounding_box_valid) {
|
if (! m_bounding_box_valid) {
|
||||||
m_bounding_box_valid = true;
|
m_bounding_box_valid = true;
|
||||||
BoundingBoxf3 raw_bbox = this->raw_mesh_bounding_box();
|
|
||||||
m_bounding_box.reset();
|
m_bounding_box.reset();
|
||||||
for (const ModelInstance *i : this->instances)
|
for (size_t i = 0; i < instances.size(); ++i)
|
||||||
m_bounding_box.merge(i->transform_bounding_box(raw_bbox));
|
m_bounding_box.merge(instance_bounding_box(i, false));
|
||||||
}
|
}
|
||||||
return m_bounding_box;
|
return m_bounding_box;
|
||||||
}
|
}
|
||||||
@ -927,16 +926,20 @@ const BoundingBoxf3& ModelObject::raw_bounding_box() const
|
|||||||
return m_raw_bounding_box;
|
return m_raw_bounding_box;
|
||||||
}
|
}
|
||||||
|
|
||||||
// This returns an accurate snug bounding box of the transformed object instance, without the translation applied.
|
// This returns an accurate snug bounding box of the transformed object instance, with or without the translation applied.
|
||||||
BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_translate) const
|
BoundingBoxf3 ModelObject::instance_bounding_box(size_t instance_idx, bool dont_translate) const
|
||||||
|
{
|
||||||
|
return instance_bounding_box(*this->instances[instance_idx], dont_translate);
|
||||||
|
}
|
||||||
|
BoundingBoxf3 ModelObject::instance_bounding_box(const ModelInstance & instance, bool dont_translate) const
|
||||||
{
|
{
|
||||||
BoundingBoxf3 bb;
|
BoundingBoxf3 bb;
|
||||||
const Transform3d& inst_matrix = this->instances[instance_idx]->get_transformation().get_matrix(dont_translate);
|
const Transform3d& inst_matrix = instance.get_transformation().get_matrix(dont_translate);
|
||||||
for (ModelVolume *v : this->volumes)
|
for (ModelVolume* v : this->volumes)
|
||||||
{
|
{
|
||||||
if (v->is_model_part())
|
if (v->is_model_part())
|
||||||
bb.merge(v->mesh().transformed_bounding_box(inst_matrix * v->get_matrix()));
|
bb.merge(v->mesh().transformed_bounding_box(inst_matrix * v->get_matrix()));
|
||||||
}
|
}
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1925,11 +1928,6 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh& mes
|
|||||||
return bbox;
|
return bbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
|
||||||
{
|
|
||||||
return bbox.transformed(get_matrix(dont_translate));
|
|
||||||
}
|
|
||||||
|
|
||||||
Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
|
Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
|
||||||
{
|
{
|
||||||
return get_matrix(dont_translate) * v;
|
return get_matrix(dont_translate) * v;
|
||||||
|
@ -306,6 +306,7 @@ public:
|
|||||||
const BoundingBoxf3& raw_bounding_box() const;
|
const BoundingBoxf3& raw_bounding_box() const;
|
||||||
// A snug bounding box around the transformed non-modifier object volumes.
|
// A snug bounding box around the transformed non-modifier object volumes.
|
||||||
BoundingBoxf3 instance_bounding_box(size_t instance_idx, bool dont_translate = false) const;
|
BoundingBoxf3 instance_bounding_box(size_t instance_idx, bool dont_translate = false) const;
|
||||||
|
BoundingBoxf3 instance_bounding_box(const ModelInstance& instance, bool dont_translate = false) const;
|
||||||
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of non-modifier object volumes.
|
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of non-modifier object volumes.
|
||||||
const BoundingBoxf3& raw_mesh_bounding_box() const;
|
const BoundingBoxf3& raw_mesh_bounding_box() const;
|
||||||
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes.
|
// A snug bounding box of non-transformed (non-rotated, non-scaled, non-translated) sum of all object volumes.
|
||||||
@ -876,8 +877,6 @@ public:
|
|||||||
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
|
void transform_mesh(TriangleMesh* mesh, bool dont_translate = false) const;
|
||||||
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
||||||
BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh& mesh, bool dont_translate = false) const;
|
BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh& mesh, bool dont_translate = false) const;
|
||||||
// Transform an external bounding box.
|
|
||||||
BoundingBoxf3 transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate = false) const;
|
|
||||||
// Transform an external vector.
|
// Transform an external vector.
|
||||||
Vec3d transform_vector(const Vec3d& v, bool dont_translate = false) const;
|
Vec3d transform_vector(const Vec3d& v, bool dont_translate = false) const;
|
||||||
// To be called on an external polygon. It does not translate the polygon, only rotates and scales.
|
// To be called on an external polygon. It does not translate the polygon, only rotates and scales.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user