mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-10-28 19:21:20 -06:00
Merge branch 'dev_native' of https://github.com/prusa3d/Slic3r into dev_native
This commit is contained in:
commit
85597a4039
25 changed files with 235 additions and 2522 deletions
|
|
@ -1329,11 +1329,18 @@ namespace Slic3r {
|
|||
|
||||
void _3MF_Importer::_apply_transform(ModelInstance& instance, const Transform3d& transform)
|
||||
{
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
Slic3r::Geometry::Transformation t(transform);
|
||||
// invalid scale value, return
|
||||
if (!t.get_scaling_factor().all())
|
||||
return;
|
||||
|
||||
instance.set_transformation(t);
|
||||
#else
|
||||
// translation
|
||||
Vec3d offset = transform.matrix().block(0, 3, 3, 1);
|
||||
|
||||
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
|
||||
#if ENABLE_MIRROR
|
||||
// mirror
|
||||
// it is impossible to reconstruct the original mirroring factors from a matrix,
|
||||
// we can only detect if the matrix contains a left handed reference system
|
||||
|
|
@ -1347,7 +1354,6 @@ namespace Slic3r {
|
|||
}
|
||||
|
||||
// scale
|
||||
#endif // ENABLE_MIRROR
|
||||
Vec3d scale(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm());
|
||||
|
||||
// invalid scale value, return
|
||||
|
|
@ -1364,9 +1370,8 @@ namespace Slic3r {
|
|||
instance.set_offset(offset);
|
||||
instance.set_scaling_factor(scale);
|
||||
instance.set_rotation(rotation);
|
||||
#if ENABLE_MIRROR
|
||||
instance.set_mirror(mirror);
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
}
|
||||
|
||||
bool _3MF_Importer::_handle_start_config(const char** attributes, unsigned int num_attributes)
|
||||
|
|
@ -1823,7 +1828,7 @@ namespace Slic3r {
|
|||
stream << " </" << COMPONENTS_TAG << ">\n";
|
||||
}
|
||||
|
||||
Transform3d t = instance->world_matrix();
|
||||
Transform3d t = instance->get_matrix();
|
||||
build_items.emplace_back(instance_id, t);
|
||||
|
||||
stream << " </" << OBJECT_TAG << ">\n";
|
||||
|
|
|
|||
|
|
@ -32,9 +32,7 @@
|
|||
// 2 : Added z component of offset
|
||||
// Added x and y components of rotation
|
||||
// Added x, y and z components of scale
|
||||
#if ENABLE_MIRROR
|
||||
// Added x, y and z components of mirror
|
||||
#endif // ENABLE_MIRROR
|
||||
const unsigned int VERSION_AMF = 2;
|
||||
const char* SLIC3RPE_AMF_VERSION = "slic3rpe_amf_version";
|
||||
|
||||
|
|
@ -132,24 +130,18 @@ struct AMFParserContext
|
|||
NODE_TYPE_SCALEX, // amf/constellation/instance/scalex
|
||||
NODE_TYPE_SCALEY, // amf/constellation/instance/scaley
|
||||
NODE_TYPE_SCALEZ, // amf/constellation/instance/scalez
|
||||
#if ENABLE_MIRROR
|
||||
NODE_TYPE_MIRRORX, // amf/constellation/instance/mirrorx
|
||||
NODE_TYPE_MIRRORY, // amf/constellation/instance/mirrory
|
||||
NODE_TYPE_MIRRORZ, // amf/constellation/instance/mirrorz
|
||||
#endif // ENABLE_MIRROR
|
||||
NODE_TYPE_METADATA, // anywhere under amf/*/metadata
|
||||
};
|
||||
|
||||
struct Instance {
|
||||
#if ENABLE_MIRROR
|
||||
Instance()
|
||||
: deltax_set(false), deltay_set(false), deltaz_set(false)
|
||||
, rx_set(false), ry_set(false), rz_set(false)
|
||||
, scalex_set(false), scaley_set(false), scalez_set(false)
|
||||
, mirrorx_set(false), mirrory_set(false), mirrorz_set(false) {}
|
||||
#else
|
||||
Instance() : deltax_set(false), deltay_set(false), deltaz_set(false), rx_set(false), ry_set(false), rz_set(false), scalex_set(false), scaley_set(false), scalez_set(false) {}
|
||||
#endif // ENABLE_MIRROR
|
||||
// Shift in the X axis.
|
||||
float deltax;
|
||||
bool deltax_set;
|
||||
|
|
@ -175,7 +167,6 @@ struct AMFParserContext
|
|||
bool scaley_set;
|
||||
float scalez;
|
||||
bool scalez_set;
|
||||
#if ENABLE_MIRROR
|
||||
// Mirroring factors
|
||||
float mirrorx;
|
||||
bool mirrorx_set;
|
||||
|
|
@ -183,7 +174,6 @@ struct AMFParserContext
|
|||
bool mirrory_set;
|
||||
float mirrorz;
|
||||
bool mirrorz_set;
|
||||
#endif // ENABLE_MIRROR
|
||||
};
|
||||
|
||||
struct Object {
|
||||
|
|
@ -314,14 +304,12 @@ void AMFParserContext::startElement(const char *name, const char **atts)
|
|||
node_type_new = NODE_TYPE_SCALEZ;
|
||||
else if (strcmp(name, "scale") == 0)
|
||||
node_type_new = NODE_TYPE_SCALE;
|
||||
#if ENABLE_MIRROR
|
||||
else if (strcmp(name, "mirrorx") == 0)
|
||||
node_type_new = NODE_TYPE_MIRRORX;
|
||||
else if (strcmp(name, "mirrory") == 0)
|
||||
node_type_new = NODE_TYPE_MIRRORY;
|
||||
else if (strcmp(name, "mirrorz") == 0)
|
||||
node_type_new = NODE_TYPE_MIRRORZ;
|
||||
#endif // ENABLE_MIRROR
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
|
|
@ -387,14 +375,10 @@ void AMFParserContext::characters(const XML_Char *s, int len)
|
|||
m_path.back() == NODE_TYPE_SCALEX ||
|
||||
m_path.back() == NODE_TYPE_SCALEY ||
|
||||
m_path.back() == NODE_TYPE_SCALEZ ||
|
||||
#if ENABLE_MIRROR
|
||||
m_path.back() == NODE_TYPE_SCALE ||
|
||||
m_path.back() == NODE_TYPE_MIRRORX ||
|
||||
m_path.back() == NODE_TYPE_MIRRORY ||
|
||||
m_path.back() == NODE_TYPE_MIRRORZ)
|
||||
#else
|
||||
m_path.back() == NODE_TYPE_SCALE)
|
||||
#endif // ENABLE_MIRROR
|
||||
m_value[0].append(s, len);
|
||||
break;
|
||||
case 6:
|
||||
|
|
@ -486,7 +470,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_instance->scalez_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#if ENABLE_MIRROR
|
||||
case NODE_TYPE_MIRRORX:
|
||||
assert(m_instance);
|
||||
m_instance->mirrorx = float(atof(m_value[0].c_str()));
|
||||
|
|
@ -505,7 +488,6 @@ void AMFParserContext::endElement(const char * /* name */)
|
|||
m_instance->mirrorz_set = true;
|
||||
m_value[0].clear();
|
||||
break;
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
// Object vertices:
|
||||
case NODE_TYPE_VERTEX:
|
||||
|
|
@ -665,9 +647,7 @@ void AMFParserContext::endDocument()
|
|||
mi->set_offset(Vec3d(instance.deltax_set ? (double)instance.deltax : 0.0, instance.deltay_set ? (double)instance.deltay : 0.0, instance.deltaz_set ? (double)instance.deltaz : 0.0));
|
||||
mi->set_rotation(Vec3d(instance.rx_set ? (double)instance.rx : 0.0, instance.ry_set ? (double)instance.ry : 0.0, instance.rz_set ? (double)instance.rz : 0.0));
|
||||
mi->set_scaling_factor(Vec3d(instance.scalex_set ? (double)instance.scalex : 1.0, instance.scaley_set ? (double)instance.scaley : 1.0, instance.scalez_set ? (double)instance.scalez : 1.0));
|
||||
#if ENABLE_MIRROR
|
||||
mi->set_mirror(Vec3d(instance.mirrorx_set ? (double)instance.mirrorx : 1.0, instance.mirrory_set ? (double)instance.mirrory : 1.0, instance.mirrorz_set ? (double)instance.mirrorz : 1.0));
|
||||
#endif // ENABLE_MIRROR
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -987,11 +967,9 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
" <scalex>%lf</scalex>\n"
|
||||
" <scaley>%lf</scaley>\n"
|
||||
" <scalez>%lf</scalez>\n"
|
||||
#if ENABLE_MIRROR
|
||||
" <mirrorx>%lf</mirrorx>\n"
|
||||
" <mirrory>%lf</mirrory>\n"
|
||||
" <mirrorz>%lf</mirrorz>\n"
|
||||
#endif // ENABLE_MIRROR
|
||||
" </instance>\n",
|
||||
object_id,
|
||||
instance->get_offset(X),
|
||||
|
|
@ -1002,14 +980,10 @@ bool store_amf(const char *path, Model *model, Print* print, bool export_print_c
|
|||
instance->get_rotation(Z),
|
||||
instance->get_scaling_factor(X),
|
||||
instance->get_scaling_factor(Y),
|
||||
#if ENABLE_MIRROR
|
||||
instance->get_scaling_factor(Z),
|
||||
instance->get_mirror(X),
|
||||
instance->get_mirror(Y),
|
||||
instance->get_mirror(Z));
|
||||
#else
|
||||
instance->get_scaling_factor(Z));
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
//FIXME missing instance->scaling_factor
|
||||
instances.append(buf);
|
||||
|
|
|
|||
|
|
@ -1161,11 +1161,7 @@ MedialAxis::retrieve_endpoint(const VD::cell_type* cell) const
|
|||
}
|
||||
}
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
void assemble_transform(Transform3d& transform, const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale, const Vec3d& mirror)
|
||||
#else
|
||||
void assemble_transform(Transform3d& transform, const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale)
|
||||
#endif // ENABLE_MIRROR
|
||||
{
|
||||
transform = Transform3d::Identity();
|
||||
transform.translate(translation);
|
||||
|
|
@ -1173,23 +1169,13 @@ void assemble_transform(Transform3d& transform, const Vec3d& translation, const
|
|||
transform.rotate(Eigen::AngleAxisd(rotation(1), Vec3d::UnitY()));
|
||||
transform.rotate(Eigen::AngleAxisd(rotation(0), Vec3d::UnitX()));
|
||||
transform.scale(scale);
|
||||
#if ENABLE_MIRROR
|
||||
transform.scale(mirror);
|
||||
#endif // ENABLE_MIRROR
|
||||
}
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale, const Vec3d& mirror)
|
||||
#else
|
||||
Transform3d assemble_transform(const Vec3d& translation, const Vec3d& rotation, const Vec3d& scale)
|
||||
#endif // ENABLE_MIRROR
|
||||
{
|
||||
Transform3d transform;
|
||||
#if ENABLE_MIRROR
|
||||
assemble_transform(transform, translation, rotation, scale, mirror);
|
||||
#else
|
||||
assemble_transform(transform, translation, rotation, scale);
|
||||
#endif // ENABLE_MIRROR
|
||||
return transform;
|
||||
}
|
||||
|
||||
|
|
@ -1232,13 +1218,10 @@ Transformation::Flags::Flags()
|
|||
: dont_translate(true)
|
||||
, dont_rotate(true)
|
||||
, dont_scale(true)
|
||||
#if ENABLE_MIRROR
|
||||
, dont_mirror(true)
|
||||
#endif // ENABLE_MIRROR
|
||||
{
|
||||
}
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
bool Transformation::Flags::needs_update(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
|
||||
{
|
||||
return (this->dont_translate != dont_translate) || (this->dont_rotate != dont_rotate) || (this->dont_scale != dont_scale) || (this->dont_mirror != dont_mirror);
|
||||
|
|
@ -1251,32 +1234,22 @@ void Transformation::Flags::set(bool dont_translate, bool dont_rotate, bool dont
|
|||
this->dont_scale = dont_scale;
|
||||
this->dont_mirror = dont_mirror;
|
||||
}
|
||||
#else
|
||||
bool Transformation::Flags::needs_update(bool dont_translate, bool dont_rotate, bool dont_scale) const
|
||||
{
|
||||
return (this->dont_translate != dont_translate) || (this->dont_rotate != dont_rotate) || (this->dont_scale != dont_scale);
|
||||
}
|
||||
|
||||
void Transformation::Flags::set(bool dont_translate, bool dont_rotate, bool dont_scale)
|
||||
{
|
||||
this->dont_translate = dont_translate;
|
||||
this->dont_rotate = dont_rotate;
|
||||
this->dont_scale = dont_scale;
|
||||
}
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
Transformation::Transformation()
|
||||
: m_offset(Vec3d::Zero())
|
||||
, m_rotation(Vec3d::Zero())
|
||||
, m_scaling_factor(Vec3d::Ones())
|
||||
#if ENABLE_MIRROR
|
||||
, m_mirror(Vec3d::Ones())
|
||||
#endif // ENABLE_MIRROR
|
||||
, m_matrix(Transform3d::Identity())
|
||||
, m_dirty(false)
|
||||
{
|
||||
}
|
||||
|
||||
Transformation::Transformation(const Transform3d& transform)
|
||||
{
|
||||
set_from_transform(transform);
|
||||
}
|
||||
|
||||
void Transformation::set_offset(const Vec3d& offset)
|
||||
{
|
||||
set_offset(X, offset(0));
|
||||
|
|
@ -1304,7 +1277,7 @@ void Transformation::set_rotation(Axis axis, double rotation)
|
|||
{
|
||||
rotation = angle_to_0_2PI(rotation);
|
||||
|
||||
if (m_rotation(axis) = rotation)
|
||||
if (m_rotation(axis) != rotation)
|
||||
{
|
||||
m_rotation(axis) = rotation;
|
||||
m_dirty = true;
|
||||
|
|
@ -1349,39 +1322,67 @@ void Transformation::set_mirror(Axis axis, double mirror)
|
|||
}
|
||||
}
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
const Transform3d& Transformation::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
|
||||
#else
|
||||
const Transform3d& Transformation::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
|
||||
#endif // ENABLE_MIRROR
|
||||
void Transformation::set_from_transform(const Transform3d& transform)
|
||||
{
|
||||
#if ENABLE_MIRROR
|
||||
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale, dont_mirror))
|
||||
#else
|
||||
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale))
|
||||
#endif // ENABLE_MIRROR
|
||||
{
|
||||
Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset;
|
||||
Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation;
|
||||
Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor;
|
||||
#if ENABLE_MIRROR
|
||||
Vec3d mirror = dont_mirror ? Vec3d::Ones() : m_mirror;
|
||||
m_matrix = Geometry::assemble_transform(translation, rotation, scale, mirror);
|
||||
#else
|
||||
m_matrix = Geometry::assemble_transform(translation, rotation, scale);
|
||||
#endif // ENABLE_MIRROR
|
||||
// offset
|
||||
set_offset(transform.matrix().block(0, 3, 3, 1));
|
||||
|
||||
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> m3x3 = transform.matrix().block(0, 0, 3, 3);
|
||||
|
||||
// mirror
|
||||
// it is impossible to reconstruct the original mirroring factors from a matrix,
|
||||
// we can only detect if the matrix contains a left handed reference system
|
||||
// in which case we reorient it back to right handed by mirroring the x axis
|
||||
Vec3d mirror = Vec3d::Ones();
|
||||
if (m3x3.col(0).dot(m3x3.col(1).cross(m3x3.col(2))) < 0.0)
|
||||
{
|
||||
mirror(0) = -1.0;
|
||||
// remove mirror
|
||||
m3x3.col(0) *= -1.0;
|
||||
}
|
||||
set_mirror(mirror);
|
||||
|
||||
// scale
|
||||
set_scaling_factor(Vec3d(m3x3.col(0).norm(), m3x3.col(1).norm(), m3x3.col(2).norm()));
|
||||
|
||||
// remove scale
|
||||
m3x3.col(0).normalize();
|
||||
m3x3.col(1).normalize();
|
||||
m3x3.col(2).normalize();
|
||||
|
||||
// rotation
|
||||
set_rotation(extract_euler_angles(m3x3));
|
||||
|
||||
// forces matrix recalculation matrix
|
||||
m_matrix = get_matrix();
|
||||
|
||||
// // debug check
|
||||
// if (!m_matrix.isApprox(transform))
|
||||
// std::cout << "something went wrong in extracting data from matrix" << std::endl;
|
||||
}
|
||||
|
||||
const Transform3d& Transformation::get_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
|
||||
{
|
||||
if (m_dirty || m_flags.needs_update(dont_translate, dont_rotate, dont_scale, dont_mirror))
|
||||
{
|
||||
m_matrix = Geometry::assemble_transform(
|
||||
dont_translate ? Vec3d::Zero() : m_offset,
|
||||
dont_rotate ? Vec3d::Zero() : m_rotation,
|
||||
dont_scale ? Vec3d::Ones() : m_scaling_factor,
|
||||
dont_mirror ? Vec3d::Ones() : m_mirror
|
||||
);
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
m_flags.set(dont_translate, dont_rotate, dont_scale, dont_mirror);
|
||||
#else
|
||||
m_flags.set(dont_translate, dont_rotate, dont_scale);
|
||||
#endif // ENABLE_MIRROR
|
||||
m_dirty = false;
|
||||
}
|
||||
|
||||
return m_matrix;
|
||||
}
|
||||
|
||||
Transformation Transformation::operator * (const Transformation& other) const
|
||||
{
|
||||
return Transformation(get_matrix() * other.get_matrix());
|
||||
}
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
} }
|
||||
|
|
|
|||
|
|
@ -172,7 +172,6 @@ class MedialAxis {
|
|||
};
|
||||
|
||||
// Sets the given transform by assembling the given transformations in the following order:
|
||||
#if ENABLE_MIRROR
|
||||
// 1) mirror
|
||||
// 2) scale
|
||||
// 3) rotate X
|
||||
|
|
@ -180,17 +179,8 @@ class MedialAxis {
|
|||
// 5) rotate Z
|
||||
// 6) translate
|
||||
void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones(), const Vec3d& mirror = Vec3d::Ones());
|
||||
#else
|
||||
// 1) scale
|
||||
// 2) rotate X
|
||||
// 3) rotate Y
|
||||
// 4) rotate Z
|
||||
// 5) translate
|
||||
void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones());
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
// Returns the transform obtained by assembling the given transformations in the following order:
|
||||
#if ENABLE_MIRROR
|
||||
// 1) mirror
|
||||
// 2) scale
|
||||
// 3) rotate X
|
||||
|
|
@ -198,14 +188,6 @@ void assemble_transform(Transform3d& transform, const Vec3d& translation = Vec3d
|
|||
// 5) rotate Z
|
||||
// 6) translate
|
||||
Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones(), const Vec3d& mirror = Vec3d::Ones());
|
||||
#else
|
||||
// 1) scale
|
||||
// 2) rotate X
|
||||
// 3) rotate Y
|
||||
// 4) rotate Z
|
||||
// 5) translate
|
||||
Transform3d assemble_transform(const Vec3d& translation = Vec3d::Zero(), const Vec3d& rotation = Vec3d::Zero(), const Vec3d& scale = Vec3d::Ones());
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
// Returns the euler angles extracted from the given rotation matrix
|
||||
// Warning -> The matrix should not contain any scale or shear !!!
|
||||
|
|
@ -223,34 +205,26 @@ class Transformation
|
|||
bool dont_translate;
|
||||
bool dont_rotate;
|
||||
bool dont_scale;
|
||||
#if ENABLE_MIRROR
|
||||
bool dont_mirror;
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
Flags();
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
bool needs_update(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const;
|
||||
void set(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror);
|
||||
#else
|
||||
bool needs_update(bool dont_translate, bool dont_rotate, bool dont_scale) const;
|
||||
void set(bool dont_translate, bool dont_rotate, bool dont_scale);
|
||||
#endif // ENABLE_MIRROR
|
||||
};
|
||||
|
||||
Vec3d m_offset; // In unscaled coordinates
|
||||
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
|
||||
Vec3d m_scaling_factor; // Scaling factors along the three axes
|
||||
#if ENABLE_MIRROR
|
||||
Vec3d m_mirror; // Mirroring along the three axes
|
||||
#endif // ENABLE_MIRROR
|
||||
mutable Transform3d m_matrix;
|
||||
|
||||
mutable Transform3d m_matrix;
|
||||
mutable Flags m_flags;
|
||||
mutable bool m_dirty;
|
||||
|
||||
public:
|
||||
Transformation();
|
||||
explicit Transformation(const Transform3d& transform);
|
||||
|
||||
const Vec3d& get_offset() const { return m_offset; }
|
||||
double get_offset(Axis axis) const { return m_offset(axis); }
|
||||
|
|
@ -267,7 +241,6 @@ public:
|
|||
Vec3d get_scaling_factor() const { return m_scaling_factor; }
|
||||
double get_scaling_factor(Axis axis) const { return m_scaling_factor(axis); }
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
void set_scaling_factor(const Vec3d& scaling_factor);
|
||||
void set_scaling_factor(Axis axis, double scaling_factor);
|
||||
|
||||
|
|
@ -277,13 +250,11 @@ public:
|
|||
void set_mirror(const Vec3d& mirror);
|
||||
void set_mirror(Axis axis, double mirror);
|
||||
|
||||
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
|
||||
#else
|
||||
void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; }
|
||||
void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; }
|
||||
void set_from_transform(const Transform3d& transform);
|
||||
|
||||
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const;
|
||||
#endif // ENABLE_MIRROR
|
||||
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
|
||||
|
||||
Transformation operator * (const Transformation& other) const;
|
||||
};
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
|
|
|
|||
|
|
@ -693,23 +693,12 @@ void ModelObject::center_around_origin()
|
|||
if (v->is_model_part())
|
||||
bb.merge(v->mesh.bounding_box());
|
||||
|
||||
#if ENABLE_EXTENDED_SELECTION
|
||||
// Shift is the vector from the center of the bounding box to the origin
|
||||
Vec3d shift = -bb.center();
|
||||
#else
|
||||
// Shift is the vector from the center of the bottom face of the bounding box to the origin
|
||||
Vec3d shift = -bb.center();
|
||||
shift(2) = -bb.min(2);
|
||||
#endif // ENABLE_EXTENDED_SELECTION
|
||||
|
||||
this->translate(shift);
|
||||
this->origin_translation += shift;
|
||||
|
||||
#if !ENABLE_EXTENDED_SELECTION
|
||||
// set z to zero, translation in z has already been done within the mesh
|
||||
shift(2) = 0.0;
|
||||
#endif // !ENABLE_EXTENDED_SELECTION
|
||||
|
||||
if (!this->instances.empty()) {
|
||||
for (ModelInstance *i : this->instances) {
|
||||
i->set_offset(i->get_offset() - shift);
|
||||
|
|
@ -738,7 +727,7 @@ void ModelObject::translate_instance(size_t instance_idx, const Vec3d& vector)
|
|||
invalidate_bounding_box();
|
||||
}
|
||||
|
||||
void ModelObject::translate(coordf_t x, coordf_t y, coordf_t z)
|
||||
void ModelObject::translate(double x, double y, double z)
|
||||
{
|
||||
for (ModelVolume *v : this->volumes)
|
||||
{
|
||||
|
|
@ -929,7 +918,7 @@ double ModelObject::get_instance_min_z(size_t instance_idx) const
|
|||
double min_z = DBL_MAX;
|
||||
|
||||
ModelInstance* inst = instances[instance_idx];
|
||||
const Transform3d& m = inst->world_matrix(true);
|
||||
const Transform3d& m = inst->get_matrix(true);
|
||||
|
||||
for (ModelVolume *v : volumes)
|
||||
{
|
||||
|
|
@ -956,7 +945,7 @@ unsigned int ModelObject::check_instances_print_volume_state(const BoundingBoxf3
|
|||
unsigned int inside_outside = 0;
|
||||
for (const ModelVolume *vol : this->volumes)
|
||||
if (vol->is_model_part()) {
|
||||
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(model_instance->world_matrix());
|
||||
BoundingBoxf3 bb = vol->get_convex_hull().transformed_bounding_box(model_instance->get_matrix());
|
||||
if (print_volume.contains(bb))
|
||||
inside_outside |= INSIDE;
|
||||
else if (print_volume.intersects(bb))
|
||||
|
|
@ -1053,11 +1042,6 @@ const TriangleMesh& ModelVolume::get_convex_hull() const
|
|||
return m_convex_hull;
|
||||
}
|
||||
|
||||
TriangleMesh& ModelVolume::get_convex_hull()
|
||||
{
|
||||
return m_convex_hull;
|
||||
}
|
||||
|
||||
ModelVolume::Type ModelVolume::type_from_string(const std::string &s)
|
||||
{
|
||||
// Legacy support
|
||||
|
|
@ -1124,6 +1108,17 @@ size_t ModelVolume::split(unsigned int max_extruders)
|
|||
return idx;
|
||||
}
|
||||
|
||||
void ModelVolume::translate(double x, double y, double z)
|
||||
{
|
||||
translate(Vec3d(x, y, z));
|
||||
}
|
||||
|
||||
void ModelVolume::translate(const Vec3d& displacement)
|
||||
{
|
||||
mesh.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
|
||||
m_convex_hull.translate((float)displacement(0), (float)displacement(1), (float)displacement(2));
|
||||
}
|
||||
|
||||
#if !ENABLE_MODELVOLUME_TRANSFORM
|
||||
void ModelInstance::set_rotation(const Vec3d& rotation)
|
||||
{
|
||||
|
|
@ -1146,7 +1141,6 @@ void ModelInstance::set_rotation(Axis axis, double rotation)
|
|||
m_rotation(axis) = rotation;
|
||||
}
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
void ModelInstance::set_scaling_factor(const Vec3d& scaling_factor)
|
||||
{
|
||||
set_scaling_factor(X, scaling_factor(0));
|
||||
|
|
@ -1176,23 +1170,18 @@ void ModelInstance::set_mirror(Axis axis, double mirror)
|
|||
|
||||
m_mirror(axis) = mirror;
|
||||
}
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
void ModelInstance::transform_mesh(TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
mesh->transform(world_matrix(dont_translate).cast<float>());
|
||||
mesh->transform(get_matrix(dont_translate).cast<float>());
|
||||
}
|
||||
|
||||
BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mesh, bool dont_translate) const
|
||||
{
|
||||
// Rotate around mesh origin.
|
||||
TriangleMesh copy(*mesh);
|
||||
#if ENABLE_MIRROR
|
||||
copy.transform(world_matrix(true, false, true, true).cast<float>());
|
||||
#else
|
||||
copy.transform(world_matrix(true, false, true).cast<float>());
|
||||
#endif // ENABLE_MIRROR
|
||||
copy.transform(get_matrix(true, false, true, true).cast<float>());
|
||||
BoundingBoxf3 bbox = copy.bounding_box();
|
||||
|
||||
if (!empty(bbox)) {
|
||||
|
|
@ -1229,12 +1218,12 @@ BoundingBoxf3 ModelInstance::transform_mesh_bounding_box(const TriangleMesh* mes
|
|||
|
||||
BoundingBoxf3 ModelInstance::transform_bounding_box(const BoundingBoxf3 &bbox, bool dont_translate) const
|
||||
{
|
||||
return bbox.transformed(world_matrix(dont_translate));
|
||||
return bbox.transformed(get_matrix(dont_translate));
|
||||
}
|
||||
|
||||
Vec3d ModelInstance::transform_vector(const Vec3d& v, bool dont_translate) const
|
||||
{
|
||||
return world_matrix(dont_translate) * v;
|
||||
return get_matrix(dont_translate) * v;
|
||||
}
|
||||
|
||||
void ModelInstance::transform_polygon(Polygon* polygon) const
|
||||
|
|
@ -1253,21 +1242,13 @@ void ModelInstance::transform_polygon(Polygon* polygon) const
|
|||
}
|
||||
|
||||
#if !ENABLE_MODELVOLUME_TRANSFORM
|
||||
#if ENABLE_MIRROR
|
||||
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale, bool dont_mirror) const
|
||||
#else
|
||||
Transform3d ModelInstance::world_matrix(bool dont_translate, bool dont_rotate, bool dont_scale) const
|
||||
#endif // ENABLE_MIRROR
|
||||
{
|
||||
Vec3d translation = dont_translate ? Vec3d::Zero() : m_offset;
|
||||
Vec3d rotation = dont_rotate ? Vec3d::Zero() : m_rotation;
|
||||
Vec3d scale = dont_scale ? Vec3d::Ones() : m_scaling_factor;
|
||||
#if ENABLE_MIRROR
|
||||
Vec3d mirror = dont_mirror ? Vec3d::Ones() : m_mirror;
|
||||
return Geometry::assemble_transform(translation, rotation, scale, mirror);
|
||||
#else
|
||||
return Geometry::assemble_transform(translation, rotation, scale);
|
||||
#endif // ENABLE_MIRROR
|
||||
}
|
||||
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public:
|
|||
void translate_instances(const Vec3d& vector);
|
||||
void translate_instance(size_t instance_idx, const Vec3d& vector);
|
||||
void translate(const Vec3d &vector) { this->translate(vector(0), vector(1), vector(2)); }
|
||||
void translate(coordf_t x, coordf_t y, coordf_t z);
|
||||
void translate(double x, double y, double z);
|
||||
void scale(const Vec3d &versor);
|
||||
void scale(const double s) { this->scale(Vec3d(s, s, s)); }
|
||||
void rotate(float angle, const Axis &axis);
|
||||
|
|
@ -210,13 +210,6 @@ class ModelVolume : public ModelBase
|
|||
{
|
||||
friend class ModelObject;
|
||||
|
||||
// The convex hull of this model's mesh.
|
||||
TriangleMesh m_convex_hull;
|
||||
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
Geometry::Transformation m_transformation;
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
public:
|
||||
std::string name;
|
||||
// The triangular model.
|
||||
|
|
@ -253,18 +246,22 @@ public:
|
|||
// Return the number of volumes created from this one.
|
||||
// This is useful to assign different materials to different volumes of an object.
|
||||
size_t split(unsigned int max_extruders);
|
||||
void translate(double x, double y, double z);
|
||||
void translate(const Vec3d& displacement);
|
||||
|
||||
ModelMaterial* assign_unique_material();
|
||||
|
||||
void calculate_convex_hull();
|
||||
const TriangleMesh& get_convex_hull() const;
|
||||
TriangleMesh& get_convex_hull();
|
||||
|
||||
// Helpers for loading / storing into AMF / 3MF files.
|
||||
static Type type_from_string(const std::string &s);
|
||||
static std::string type_to_string(const Type t);
|
||||
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
const Geometry::Transformation& get_transformation() const { return m_transformation; }
|
||||
void set_transformation(const Geometry::Transformation& transformation) { m_transformation = transformation; }
|
||||
|
||||
const Vec3d& get_offset() const { return m_transformation.get_offset(); }
|
||||
double get_offset(Axis axis) const { return m_transformation.get_offset(axis); }
|
||||
|
||||
|
|
@ -283,13 +280,13 @@ public:
|
|||
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); }
|
||||
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); }
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
const Vec3d& get_mirror() const { return m_transformation.get_mirror(); }
|
||||
double get_mirror(Axis axis) const { return m_transformation.get_mirror(axis); }
|
||||
|
||||
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); }
|
||||
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); }
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
private:
|
||||
|
|
@ -298,7 +295,12 @@ private:
|
|||
// Is it an object to be printed, or a modifier volume?
|
||||
Type m_type;
|
||||
t_model_material_id m_material_id;
|
||||
|
||||
// The convex hull of this model's mesh.
|
||||
TriangleMesh m_convex_hull;
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
Geometry::Transformation m_transformation;
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
ModelVolume(ModelObject *object, const TriangleMesh &mesh) : mesh(mesh), m_type(MODEL_PART), object(object)
|
||||
{
|
||||
if (mesh.stl.stats.number_of_facets > 1)
|
||||
|
|
@ -347,9 +349,7 @@ private:
|
|||
Vec3d m_offset; // in unscaled coordinates
|
||||
Vec3d m_rotation; // Rotation around the three axes, in radians around mesh center point
|
||||
Vec3d m_scaling_factor; // Scaling factors along the three axes
|
||||
#if ENABLE_MIRROR
|
||||
Vec3d m_mirror; // Mirroring along the three axes
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
public:
|
||||
|
|
@ -380,13 +380,11 @@ public:
|
|||
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); }
|
||||
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); }
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
const Vec3d& get_mirror() const { return m_transformation.get_mirror(); }
|
||||
double get_mirror(Axis axis) const { return m_transformation.get_mirror(axis); }
|
||||
|
||||
void set_mirror(const Vec3d& mirror) { m_transformation.set_mirror(mirror); }
|
||||
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); }
|
||||
#endif // ENABLE_MIRROR
|
||||
#else
|
||||
const Vec3d& get_offset() const { return m_offset; }
|
||||
double get_offset(Axis axis) const { return m_offset(axis); }
|
||||
|
|
@ -403,21 +401,14 @@ public:
|
|||
Vec3d get_scaling_factor() const { return m_scaling_factor; }
|
||||
double get_scaling_factor(Axis axis) const { return m_scaling_factor(axis); }
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
void set_scaling_factor(const Vec3d& scaling_factor);
|
||||
void set_scaling_factor(Axis axis, double scaling_factor);
|
||||
#else
|
||||
void set_scaling_factor(const Vec3d& scaling_factor) { m_scaling_factor = scaling_factor; }
|
||||
void set_scaling_factor(Axis axis, double scaling_factor) { m_scaling_factor(axis) = scaling_factor; }
|
||||
#endif // ENABLE_MIRROR
|
||||
|
||||
#if ENABLE_MIRROR
|
||||
const Vec3d& get_mirror() const { return m_mirror; }
|
||||
double get_mirror(Axis axis) const { return m_mirror(axis); }
|
||||
|
||||
void set_mirror(const Vec3d& mirror);
|
||||
void set_mirror(Axis axis, double mirror);
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
// To be called on an external mesh
|
||||
|
|
@ -432,17 +423,9 @@ public:
|
|||
void transform_polygon(Polygon* polygon) const;
|
||||
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
#if ENABLE_MIRROR
|
||||
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.world_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
|
||||
const Transform3d& get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const { return m_transformation.get_matrix(dont_translate, dont_rotate, dont_scale, dont_mirror); }
|
||||
#else
|
||||
const Transform3d& world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const { return m_transformation.world_matrix(dont_translate, dont_rotate, dont_scale); }
|
||||
#endif // ENABLE_MIRROR
|
||||
#else
|
||||
#if ENABLE_MIRROR
|
||||
Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
|
||||
#else
|
||||
Transform3d world_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false) const;
|
||||
#endif // ENABLE_MIRROR
|
||||
Transform3d get_matrix(bool dont_translate = false, bool dont_rotate = false, bool dont_scale = false, bool dont_mirror = false) const;
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
bool is_printable() const { return print_volume_state == PVS_Inside; }
|
||||
|
|
@ -456,15 +439,9 @@ private:
|
|||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
m_transformation(other.m_transformation), object(object), print_volume_state(PVS_Inside) {}
|
||||
#else
|
||||
#if ENABLE_MIRROR
|
||||
ModelInstance(ModelObject *object) : m_offset(Vec3d::Zero()), m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_mirror(Vec3d::Ones()), object(object), print_volume_state(PVS_Inside) {}
|
||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
m_offset(other.m_offset), m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_mirror(other.m_mirror), object(object), print_volume_state(PVS_Inside) {}
|
||||
#else
|
||||
ModelInstance(ModelObject *object) : m_rotation(Vec3d::Zero()), m_scaling_factor(Vec3d::Ones()), m_offset(Vec3d::Zero()), object(object), print_volume_state(PVS_Inside) {}
|
||||
ModelInstance(ModelObject *object, const ModelInstance &other) :
|
||||
m_rotation(other.m_rotation), m_scaling_factor(other.m_scaling_factor), m_offset(other.m_offset), object(object), print_volume_state(PVS_Inside) {}
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
explicit ModelInstance(ModelInstance &rhs) = delete;
|
||||
|
|
|
|||
|
|
@ -412,7 +412,7 @@ void Print::add_model_object(ModelObject* model_object, int idx)
|
|||
// Set the transformation matrix without translation from the first instance.
|
||||
if (! model_object->instances.empty()) {
|
||||
// Trafo and bounding box, both in world coordinate system.
|
||||
Transform3d trafo = model_object->instances.front()->world_matrix();
|
||||
Transform3d trafo = model_object->instances.front()->get_matrix();
|
||||
BoundingBoxf3 bbox = model_object->instance_bounding_box(0);
|
||||
// Now shift the object up to align it with the print bed.
|
||||
trafo.data()[14] -= bbox.min(2);
|
||||
|
|
@ -695,7 +695,7 @@ static std::vector<PrintInstances> print_objects_from_model_object(const ModelOb
|
|||
trafo.copies.assign(1, Point());
|
||||
for (ModelInstance *model_instance : model_object.instances)
|
||||
if (model_instance->is_printable()) {
|
||||
trafo.trafo = model_instance->world_matrix();
|
||||
trafo.trafo = model_instance->get_matrix();
|
||||
// Set the Z axis of the transformation.
|
||||
trafo.copies.front() = Point::new_scale(trafo.trafo.data()[12], trafo.trafo.data()[13]);
|
||||
trafo.trafo.data()[12] = 0;
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
#ifndef _technologies_h_
|
||||
#define _technologies_h_
|
||||
|
||||
//==============
|
||||
//============
|
||||
// debug techs
|
||||
//==============
|
||||
//============
|
||||
|
||||
// Shows camera target in the 3D scene
|
||||
#define ENABLE_SHOW_CAMERA_TARGET 1
|
||||
|
||||
//==============
|
||||
//=============
|
||||
// 1.42.0 techs
|
||||
//==============
|
||||
//=============
|
||||
#define ENABLE_1_42_0 1
|
||||
|
||||
// Add double click on gizmo grabbers to reset transformation components to their default value
|
||||
#define ENABLE_GIZMOS_RESET (1 && ENABLE_1_42_0)
|
||||
// Uses a unique opengl context
|
||||
#define ENABLE_USE_UNIQUE_GLCONTEXT (1 && ENABLE_1_42_0)
|
||||
// New selections
|
||||
#define ENABLE_EXTENDED_SELECTION (1 && ENABLE_1_42_0)
|
||||
#define DISABLE_INSTANCES_SYNCH (1 && ENABLE_EXTENDED_SELECTION)
|
||||
// Add mirror components along the three axes in ModelInstance and GLVolume
|
||||
#define ENABLE_MIRROR (1 && ENABLE_1_42_0)
|
||||
// Disable synchronization of unselected instances
|
||||
#define DISABLE_INSTANCES_SYNCH (1 && ENABLE_1_42_0)
|
||||
// Modified camera target behavior
|
||||
#define ENABLE_MODIFIED_CAMERA_TARGET (1 && ENABLE_1_42_0)
|
||||
// Add Geometry::Transformation class and use it into ModelInstance, ModelVolume and GLVolume
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue