call the now valid functions

This commit is contained in:
Michael Kirsch 2019-06-02 21:12:58 +02:00 committed by Joseph Lenox
parent e08eaef02f
commit 8b17156f1d

View File

@ -402,7 +402,7 @@ Model::looks_like_multipart_object() const
std::set<coordf_t> heights; std::set<coordf_t> heights;
for (const ModelObject* o : this->objects) for (const ModelObject* o : this->objects)
for (const ModelVolume* v : o->volumes) for (const ModelVolume* v : o->volumes)
heights.insert(v->get_transformed_bounding_box().min.z); heights.insert(v->bounding_box().min.z);
return heights.size() > 1; return heights.size() > 1;
} }
@ -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)->get_transformed_bounding_box()); raw_bbox.merge((*v)->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)
@ -613,7 +613,7 @@ ModelObject::mesh() const
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) {
TransformationMatrix instance_trafo = (*i)->get_trafo_matrix(); TransformationMatrix instance_trafo = (*i)->get_trafo_matrix();
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) {
mesh.merge((*v)->get_transformed_mesh(&instance_trafo)); mesh.merge((*v)->get_transformed_mesh(instance_trafo));
} }
} }
return mesh; return mesh;
@ -625,7 +625,7 @@ ModelObject::raw_mesh() const
TriangleMesh mesh; TriangleMesh mesh;
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;
mesh.merge((*v)->get_transformed_mesh()); mesh.merge((*v)->mesh);
} }
return mesh; return mesh;
} }
@ -638,7 +638,7 @@ ModelObject::raw_bounding_box() const
TransformationMatrix trafo = this->instances.front()->get_trafo_matrix(true); 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;
bb.merge((*v)->get_transformed_bounding_box(&trafo)); bb.merge((*v)->get_transformed_bounding_box(trafo));
} }
return bb; return bb;
} }
@ -652,7 +652,7 @@ ModelObject::instance_bounding_box(size_t instance_idx) const
TransformationMatrix trafo = this->instances[instance_idx]->get_trafo_matrix(true); 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((*v)->get_transformed_bounding_box(&trafo)); bb.merge((*v)->get_transformed_bounding_box(trafo));
} }
return bb; return bb;
} }
@ -681,7 +681,7 @@ ModelObject::align_to_ground()
BoundingBoxf3 bb; BoundingBoxf3 bb;
for (const ModelVolume* v : this->volumes) for (const ModelVolume* v : this->volumes)
if (!v->modifier) if (!v->modifier)
bb.merge(v->get_transformed_bounding_box()); bb.merge(v->bounding_box());
this->translate(0, 0, -bb.min.z); this->translate(0, 0, -bb.min.z);
this->origin_translation.translate(0, 0, -bb.min.z); this->origin_translation.translate(0, 0, -bb.min.z);
@ -695,7 +695,7 @@ ModelObject::center_around_origin()
BoundingBoxf3 bb; BoundingBoxf3 bb;
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) if (! (*v)->modifier)
bb.merge((*v)->get_transformed_bounding_box()); bb.merge((*v)->bounding_box());
// first align to origin on XYZ // first align to origin on XYZ
Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z); Vectorf3 vector(-bb.min.x, -bb.min.y, -bb.min.z);
@ -705,6 +705,9 @@ ModelObject::center_around_origin()
vector.x -= size.x/2; vector.x -= size.x/2;
vector.y -= size.y/2; vector.y -= size.y/2;
TransformationMatrix trafo = TransformationMatrix::mat_translation(-bb.center().x, -bb.center().y, -bb.min.z);
this->translate(vector); this->translate(vector);
this->origin_translation.translate(vector); this->origin_translation.translate(vector);
@ -730,9 +733,9 @@ ModelObject::translate(const Vectorf3 &vector)
void void
ModelObject::translate(coordf_t x, coordf_t y, coordf_t z) ModelObject::translate(coordf_t x, coordf_t y, coordf_t z)
{ {
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { TransformationMatrix trafo = TransformationMatrix::mat_translation(x, y, z);
(*v)->translate(x, y, z); this->apply_transformation(trafo);
}
if (this->_bounding_box_valid) this->_bounding_box.translate(x, y, z); if (this->_bounding_box_valid) this->_bounding_box.translate(x, y, z);
} }
@ -746,9 +749,8 @@ void
ModelObject::scale(const Pointf3 &versor) ModelObject::scale(const Pointf3 &versor)
{ {
if (versor.x == 1 && versor.y == 1 && versor.z == 1) return; if (versor.x == 1 && versor.y == 1 && versor.z == 1) return;
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { TransformationMatrix trafo = TransformationMatrix::mat_scale(versor.x, versor.y, versor.z);
(*v)->scale(versor); this->apply_transformation(trafo);
}
// reset origin translation since it doesn't make sense anymore // reset origin translation since it doesn't make sense anymore
this->origin_translation = Pointf3(0,0,0); this->origin_translation = Pointf3(0,0,0);
@ -773,9 +775,9 @@ void
ModelObject::rotate(double angle, const Axis &axis) ModelObject::rotate(double angle, const Axis &axis)
{ {
if (angle == 0) return; if (angle == 0) return;
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { TransformationMatrix trafo = TransformationMatrix::mat_rotation(angle, axis);
(*v)->rotate(angle, axis); this->apply_transformation(trafo);
}
this->origin_translation = Pointf3(0,0,0); this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
@ -784,9 +786,8 @@ void
ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target) ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target)
{ {
TransformationMatrix trafo = TransformationMatrix::mat_rotation(origin, target); TransformationMatrix trafo = TransformationMatrix::mat_rotation(origin, target);
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { this->apply_transformation(trafo);
(*v)->apply(trafo);
}
this->origin_translation = Pointf3(0,0,0); this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
@ -794,9 +795,9 @@ ModelObject::rotate(const Vectorf3 &origin, const Vectorf3 &target)
void void
ModelObject::mirror(const Axis &axis) ModelObject::mirror(const Axis &axis)
{ {
for (ModelVolumePtrs::const_iterator v = this->volumes.begin(); v != this->volumes.end(); ++v) { TransformationMatrix trafo = TransformationMatrix::mat_mirror(axis);
(*v)->mirror(axis); this->apply_transformation(trafo);
}
this->origin_translation = Pointf3(0,0,0); this->origin_translation = Pointf3(0,0,0);
this->invalidate_bounding_box(); this->invalidate_bounding_box();
} }
@ -814,10 +815,7 @@ ModelObject::transform_by_instance(ModelInstance instance, bool dont_translate)
{ {
// We get instance by copy because we would alter it in the loop below, // We get instance by copy because we would alter it in the loop below,
// causing inconsistent values in subsequent instances. // causing inconsistent values in subsequent instances.
this->rotate(instance.rotation, Z); TransformationMatrix trafo = instance.get_trafo_matrix(dont_translate);
this->scale(instance.scaling_factor);
if (!dont_translate)
this->translate(instance.offset.x, instance.offset.y, 0);
for (ModelInstance* i : this->instances) { for (ModelInstance* i : this->instances) {
i->rotation -= instance.rotation; i->rotation -= instance.rotation;