Tech ENABLE_TRANSFORMATIONS_BY_MATRICES - Reoworked calculation of volume matrix for newly added modifiers and parts
Fixed conflicts during rebase with master
This commit is contained in:
parent
2602c6bf92
commit
e3d648c802
3 changed files with 17 additions and 5 deletions
|
@ -764,6 +764,7 @@ Transformation Transformation::operator * (const Transformation& other) const
|
||||||
return Transformation(get_matrix() * other.get_matrix());
|
return Transformation(get_matrix() * other.get_matrix());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if !ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
Transformation Transformation::volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox)
|
Transformation Transformation::volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox)
|
||||||
{
|
{
|
||||||
Transformation out;
|
Transformation out;
|
||||||
|
@ -771,11 +772,7 @@ Transformation Transformation::volume_to_bed_transformation(const Transformation
|
||||||
if (instance_transformation.is_scaling_uniform()) {
|
if (instance_transformation.is_scaling_uniform()) {
|
||||||
// No need to run the non-linear least squares fitting for uniform scaling.
|
// No need to run the non-linear least squares fitting for uniform scaling.
|
||||||
// Just set the inverse.
|
// Just set the inverse.
|
||||||
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
|
||||||
out.set_matrix(instance_transformation.get_matrix_no_offset().inverse());
|
|
||||||
#else
|
|
||||||
out.set_from_transform(instance_transformation.get_matrix(true).inverse());
|
out.set_from_transform(instance_transformation.get_matrix(true).inverse());
|
||||||
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
|
||||||
}
|
}
|
||||||
else if (is_rotation_ninety_degrees(instance_transformation.get_rotation())) {
|
else if (is_rotation_ninety_degrees(instance_transformation.get_rotation())) {
|
||||||
// Anisotropic scaling, rotation by multiples of ninety degrees.
|
// Anisotropic scaling, rotation by multiples of ninety degrees.
|
||||||
|
@ -823,6 +820,7 @@ Transformation Transformation::volume_to_bed_transformation(const Transformation
|
||||||
|
|
||||||
return out;
|
return out;
|
||||||
}
|
}
|
||||||
|
#endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
|
|
||||||
// For parsing a transformation matrix from 3MF / AMF.
|
// For parsing a transformation matrix from 3MF / AMF.
|
||||||
Transform3d transform3d_from_string(const std::string& transform_str)
|
Transform3d transform3d_from_string(const std::string& transform_str)
|
||||||
|
|
|
@ -509,10 +509,12 @@ public:
|
||||||
|
|
||||||
Transformation operator * (const Transformation& other) const;
|
Transformation operator * (const Transformation& other) const;
|
||||||
|
|
||||||
|
#if !ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
// Find volume transformation, so that the chained (instance_trafo * volume_trafo) will be as close to identity
|
// Find volume transformation, so that the chained (instance_trafo * volume_trafo) will be as close to identity
|
||||||
// as possible in least squares norm in regard to the 8 corners of bbox.
|
// as possible in least squares norm in regard to the 8 corners of bbox.
|
||||||
// Bounding box is expected to be centered around zero in all axes.
|
// Bounding box is expected to be centered around zero in all axes.
|
||||||
static Transformation volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox);
|
static Transformation volume_to_bed_transformation(const Transformation& instance_transformation, const BoundingBoxf3& bbox);
|
||||||
|
#endif // !ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class cereal::access;
|
friend class cereal::access;
|
||||||
|
|
|
@ -1584,9 +1584,15 @@ void ObjectList::load_modifier(const wxArrayString& input_files, ModelObject& mo
|
||||||
new_volume->source.mesh_offset = model.objects.front()->volumes.front()->source.mesh_offset;
|
new_volume->source.mesh_offset = model.objects.front()->volumes.front()->source.mesh_offset;
|
||||||
|
|
||||||
if (from_galery) {
|
if (from_galery) {
|
||||||
|
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
|
new_volume->set_transformation(v->get_instance_transformation().get_matrix_no_offset().inverse());
|
||||||
|
// Transform the new modifier to be aligned with the print bed.
|
||||||
|
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
||||||
|
#else
|
||||||
// Transform the new modifier to be aligned with the print bed.
|
// Transform the new modifier to be aligned with the print bed.
|
||||||
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
||||||
new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(inst_transform, mesh_bb));
|
new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(inst_transform, mesh_bb));
|
||||||
|
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
// Set the modifier position.
|
// Set the modifier position.
|
||||||
// Translate the new modifier to be pickable: move to the left front corner of the instance's bounding box, lift to print bed.
|
// Translate the new modifier to be pickable: move to the left front corner of the instance's bounding box, lift to print bed.
|
||||||
const Vec3d offset = Vec3d(instance_bb.max.x(), instance_bb.min.y(), instance_bb.min.z()) + 0.5 * mesh_bb.size() - instance_offset;
|
const Vec3d offset = Vec3d(instance_bb.max.x(), instance_bb.min.y(), instance_bb.min.z()) + 0.5 * mesh_bb.size() - instance_offset;
|
||||||
|
@ -1655,9 +1661,15 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const Mode
|
||||||
|
|
||||||
// First (any) GLVolume of the selected instance. They all share the same instance matrix.
|
// First (any) GLVolume of the selected instance. They all share the same instance matrix.
|
||||||
const GLVolume* v = selection.get_first_volume();
|
const GLVolume* v = selection.get_first_volume();
|
||||||
|
#if ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
|
new_volume->set_transformation(v->get_instance_transformation().get_matrix_no_offset().inverse());
|
||||||
// Transform the new modifier to be aligned with the print bed.
|
// Transform the new modifier to be aligned with the print bed.
|
||||||
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
||||||
|
#else
|
||||||
|
// Transform the new modifier to be aligned with the print bed.
|
||||||
|
const BoundingBoxf3 mesh_bb = new_volume->mesh().bounding_box();
|
||||||
new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(v->get_instance_transformation(), mesh_bb));
|
new_volume->set_transformation(Geometry::Transformation::volume_to_bed_transformation(v->get_instance_transformation(), mesh_bb));
|
||||||
|
#endif // ENABLE_TRANSFORMATIONS_BY_MATRICES
|
||||||
// Set the modifier position.
|
// Set the modifier position.
|
||||||
auto offset = (type_name == "Slab") ?
|
auto offset = (type_name == "Slab") ?
|
||||||
// Slab: Lift to print bed
|
// Slab: Lift to print bed
|
||||||
|
|
Loading…
Reference in a new issue