mirror of
https://git.mirrors.martin98.com/https://github.com/slic3r/Slic3r.git
synced 2025-08-04 21:30:41 +08:00
change bb-related transform functions
This commit is contained in:
parent
3fedb9b37f
commit
810bff9d00
@ -588,7 +588,7 @@ ModelObject::update_bounding_box()
|
|||||||
BoundingBoxf3 raw_bbox;
|
BoundingBoxf3 raw_bbox;
|
||||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||||
if ((*v)->modifier) continue;
|
if ((*v)->modifier) continue;
|
||||||
raw_bbox.merge((*v)->mesh.bounding_box());
|
raw_bbox.merge((*v)->get_transformed_bounding_box());
|
||||||
}
|
}
|
||||||
BoundingBoxf3 bb;
|
BoundingBoxf3 bb;
|
||||||
for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i)
|
for (ModelInstancePtrs::const_iterator i = this->instances.begin(); i != this->instances.end(); ++i)
|
||||||
@ -634,10 +634,11 @@ BoundingBoxf3
|
|||||||
ModelObject::raw_bounding_box() const
|
ModelObject::raw_bounding_box() const
|
||||||
{
|
{
|
||||||
BoundingBoxf3 bb;
|
BoundingBoxf3 bb;
|
||||||
|
if (this->instances.empty()) CONFESS("Can't call raw_bounding_box() with no instances");
|
||||||
|
TransformationMatrix trafo = this->instances.front()->get_trafo_matrix(true);
|
||||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||||
if ((*v)->modifier) continue;
|
if ((*v)->modifier) continue;
|
||||||
if (this->instances.empty()) CONFESS("Can't call raw_bounding_box() with no instances");
|
bb.merge((*v)->get_transformed_bounding_box(&trafo));
|
||||||
bb.merge(this->instances.front()->transform_mesh_bounding_box(&(*v)->mesh, true));
|
|
||||||
}
|
}
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
@ -647,9 +648,11 @@ BoundingBoxf3
|
|||||||
ModelObject::instance_bounding_box(size_t instance_idx) const
|
ModelObject::instance_bounding_box(size_t instance_idx) const
|
||||||
{
|
{
|
||||||
BoundingBoxf3 bb;
|
BoundingBoxf3 bb;
|
||||||
|
if (this->instances.size()<=instance_idx) CONFESS("Can't call instance_bounding_box(index) with insufficient amount of instances");
|
||||||
|
TransformationMatrix trafo = this->instances[instance_idx]->get_trafo_matrix(true);
|
||||||
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) {
|
||||||
if ((*v)->modifier) continue;
|
if ((*v)->modifier) continue;
|
||||||
bb.merge(this->instances[instance_idx]->transform_mesh_bounding_box(&(*v)->mesh, true));
|
bb.merge((*v)->get_transformed_bounding_box(&trafo));
|
||||||
}
|
}
|
||||||
return bb;
|
return bb;
|
||||||
}
|
}
|
||||||
@ -1077,6 +1080,31 @@ ModelVolume::get_transformed_mesh(TransformationMatrix const * additional_trafo)
|
|||||||
return this->mesh.get_transformed_mesh(trafo);
|
return this->mesh.get_transformed_mesh(trafo);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BoundingBoxf3
|
||||||
|
ModelVolume::get_transformed_bounding_box(TransformationMatrix const * additional_trafo) const
|
||||||
|
{
|
||||||
|
TransformationMatrix trafo = this->trafo;
|
||||||
|
if(additional_trafo)
|
||||||
|
{
|
||||||
|
trafo.applyLeft(*(additional_trafo));
|
||||||
|
}
|
||||||
|
BoundingBoxf3 bbox;
|
||||||
|
for (int i = 0; i < this->mesh.stl.stats.number_of_facets; ++ i) {
|
||||||
|
const stl_facet &facet = this->mesh.stl.facet_start[i];
|
||||||
|
for (int j = 0; j < 3; ++ j) {
|
||||||
|
double v_x = facet.vertex[j].x;
|
||||||
|
double v_y = facet.vertex[j].y;
|
||||||
|
double v_z = facet.vertex[j].z;
|
||||||
|
Pointf3 poi;
|
||||||
|
poi.x = float(trafo.m11*v_x + trafo.m12*v_y + trafo.m13*v_z + trafo.m14);
|
||||||
|
poi.y = float(trafo.m21*v_x + trafo.m22*v_y + trafo.m23*v_z + trafo.m24);
|
||||||
|
poi.z = float(trafo.m31*v_x + trafo.m32*v_y + trafo.m33*v_z + trafo.m34);
|
||||||
|
bbox.merge(poi);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bbox;
|
||||||
|
}
|
||||||
|
|
||||||
t_model_material_id
|
t_model_material_id
|
||||||
ModelVolume::material_id() const
|
ModelVolume::material_id() const
|
||||||
{
|
{
|
||||||
@ -1162,34 +1190,6 @@ void ModelInstance::set_local_trafo_matrix(bool dont_translate)
|
|||||||
this->trafo = this->get_trafo_matrix(dont_translate);
|
this->trafo = this->get_trafo_matrix(dont_translate);
|
||||||
}
|
}
|
||||||
|
|
||||||
BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const
|
|
||||||
{
|
|
||||||
// rotate around mesh origin
|
|
||||||
double c = cos(this->rotation);
|
|
||||||
double s = sin(this->rotation);
|
|
||||||
BoundingBoxf3 bbox;
|
|
||||||
for (int i = 0; i < mesh->stl.stats.number_of_facets; ++ i) {
|
|
||||||
const stl_facet &facet = mesh->stl.facet_start[i];
|
|
||||||
for (int j = 0; j < 3; ++ j) {
|
|
||||||
stl_vertex v = facet.vertex[j];
|
|
||||||
double xold = v.x;
|
|
||||||
double yold = v.y;
|
|
||||||
// Rotation around z axis.
|
|
||||||
v.x = float(c * xold - s * yold);
|
|
||||||
v.y = float(s * xold + c * yold);
|
|
||||||
v.x *= float(this->scaling_factor);
|
|
||||||
v.y *= float(this->scaling_factor);
|
|
||||||
v.z *= float(this->scaling_factor);
|
|
||||||
if (!dont_translate) {
|
|
||||||
v.x += this->offset.x;
|
|
||||||
v.y += this->offset.y;
|
|
||||||
}
|
|
||||||
bbox.merge(Pointf3(v.x, v.y, v.z));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bbox;
|
|
||||||
}
|
|
||||||
|
|
||||||
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
||||||
{
|
{
|
||||||
// rotate around mesh origin
|
// rotate around mesh origin
|
||||||
|
@ -484,6 +484,8 @@ class ModelVolume
|
|||||||
/// \return TriangleMesh the transformed mesh
|
/// \return TriangleMesh the transformed mesh
|
||||||
TriangleMesh get_transformed_mesh(TransformationMatrix const * additional_trafo = nullptr) const;
|
TriangleMesh get_transformed_mesh(TransformationMatrix const * additional_trafo = nullptr) const;
|
||||||
|
|
||||||
|
BoundingBoxf3 get_transformed_bounding_box(TransformationMatrix const * additional_trafo = nullptr) const;
|
||||||
|
|
||||||
/// Get the material id of this ModelVolume object
|
/// Get the material id of this ModelVolume object
|
||||||
/// \return t_model_material_id the material id string
|
/// \return t_model_material_id the material id string
|
||||||
t_model_material_id material_id() const;
|
t_model_material_id material_id() const;
|
||||||
@ -561,12 +563,6 @@ class ModelInstance
|
|||||||
/// \param dont_translate bool whether to translate the mesh or not
|
/// \param dont_translate bool whether to translate the mesh or not
|
||||||
void set_local_trafo_matrix(bool dont_translate);
|
void set_local_trafo_matrix(bool dont_translate);
|
||||||
|
|
||||||
/// Calculate a bounding box of a transformed mesh. To be called on an external mesh.
|
|
||||||
/// \param mesh TriangleMesh* pointer to the the mesh
|
|
||||||
/// \param dont_translate bool whether to translate the bounding box or not
|
|
||||||
/// \return BoundingBoxf3 the bounding box after transformation
|
|
||||||
BoundingBoxf3 transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate = false) const;
|
|
||||||
|
|
||||||
/// Transform an external bounding box.
|
/// Transform an external bounding box.
|
||||||
/// \param bbox BoundingBoxf3 the bounding box to be transformed
|
/// \param bbox BoundingBoxf3 the bounding box to be transformed
|
||||||
/// \param dont_translate bool whether to translate the bounding box or not
|
/// \param dont_translate bool whether to translate the bounding box or not
|
||||||
|
Loading…
x
Reference in New Issue
Block a user