Model's volume transform set as default

This commit is contained in:
Enrico Turri 2019-01-02 10:49:13 +01:00
parent 4b04e4e552
commit 611d9aa0d8
15 changed files with 6 additions and 792 deletions

View file

@ -205,17 +205,7 @@ const float GLVolume::SLA_SUPPORT_COLOR[4] = { 0.75f, 0.75f, 0.75f, 1.0f };
const float GLVolume::SLA_PAD_COLOR[4] = { 0.0f, 0.2f, 0.0f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a)
#if ENABLE_MODELVOLUME_TRANSFORM
: m_transformed_bounding_box_dirty(true)
#else
: m_offset(Vec3d::Zero())
, m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones())
, m_mirror(Vec3d::Ones())
, m_world_matrix(Transform3f::Identity())
, m_world_matrix_dirty(true)
, m_transformed_bounding_box_dirty(true)
#endif // ENABLE_MODELVOLUME_TRANSFORM
, m_sla_shift_z(0.0)
, m_transformed_convex_hull_bounding_box_dirty(true)
, m_convex_hull(nullptr)
@ -300,125 +290,18 @@ void GLVolume::set_color_from_model_volume(const ModelVolume *model_volume)
color[3] = model_volume->is_model_part() ? 1.f : 0.5f;
}
#if !ENABLE_MODELVOLUME_TRANSFORM
const Vec3d& GLVolume::get_rotation() const
{
return m_rotation;
}
void GLVolume::set_rotation(const Vec3d& rotation)
{
static const double TWO_PI = 2.0 * (double)PI;
if (m_rotation != rotation)
{
m_rotation = rotation;
for (int i = 0; i < 3; ++i)
{
while (m_rotation(i) < 0.0)
{
m_rotation(i) += TWO_PI;
}
while (TWO_PI < m_rotation(i))
{
m_rotation(i) -= TWO_PI;
}
}
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
const Vec3d& GLVolume::get_offset() const
{
return m_offset;
}
void GLVolume::set_offset(const Vec3d& offset)
{
if (m_offset != offset)
{
m_offset = offset;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
const Vec3d& GLVolume::get_scaling_factor() const
{
return m_scaling_factor;
}
void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
{
if (m_scaling_factor != scaling_factor)
{
m_scaling_factor = scaling_factor;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
const Vec3d& GLVolume::get_mirror() const
{
return m_mirror;
}
double GLVolume::get_mirror(Axis axis) const
{
return m_mirror(axis);
}
void GLVolume::set_mirror(const Vec3d& mirror)
{
if (m_mirror != mirror)
{
m_mirror = mirror;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
void GLVolume::set_mirror(Axis axis, double mirror)
{
if (m_mirror(axis) != mirror)
{
m_mirror(axis) = mirror;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // !ENABLE_MODELVOLUME_TRANSFORM
void GLVolume::set_convex_hull(const TriangleMesh *convex_hull, bool owned)
{
m_convex_hull = convex_hull;
m_convex_hull_owned = owned;
}
#if ENABLE_MODELVOLUME_TRANSFORM
Transform3d GLVolume::world_matrix() const
{
Transform3d m = m_instance_transformation.get_matrix() * m_volume_transformation.get_matrix();
m.translation()(2) += m_sla_shift_z;
return m;
}
#else
const Transform3f& GLVolume::world_matrix() const
{
if (m_world_matrix_dirty)
{
m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor, m_mirror).cast<float>();
m_world_matrix_dirty = false;
}
return m_world_matrix;
}
#endif // ENABLE_MODELVOLUME_TRANSFORM
const BoundingBoxf3& GLVolume::transformed_bounding_box() const
{
@ -426,11 +309,7 @@ const BoundingBoxf3& GLVolume::transformed_bounding_box() const
if (m_transformed_bounding_box_dirty)
{
#if ENABLE_MODELVOLUME_TRANSFORM
m_transformed_bounding_box = bounding_box.transformed(world_matrix());
#else
m_transformed_bounding_box = bounding_box.transformed(world_matrix().cast<double>());
#endif // ENABLE_MODELVOLUME_TRANSFORM
m_transformed_bounding_box_dirty = false;
}
@ -441,17 +320,10 @@ const BoundingBoxf3& GLVolume::transformed_convex_hull_bounding_box() const
{
if (m_transformed_convex_hull_bounding_box_dirty)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if ((m_convex_hull != nullptr) && (m_convex_hull->stl.stats.number_of_facets > 0))
m_transformed_convex_hull_bounding_box = m_convex_hull->transformed_bounding_box(world_matrix());
else
m_transformed_convex_hull_bounding_box = bounding_box.transformed(world_matrix());
#else
if ((m_convex_hull != nullptr) && (m_convex_hull->stl.stats.number_of_facets > 0))
m_transformed_convex_hull_bounding_box = m_convex_hull->transformed_bounding_box(world_matrix().cast<double>());
else
m_transformed_convex_hull_bounding_box = bounding_box.transformed(world_matrix().cast<double>());
#endif // ENABLE_MODELVOLUME_TRANSFORM
m_transformed_convex_hull_bounding_box_dirty = false;
}
@ -502,11 +374,7 @@ void GLVolume::render() const
::glCullFace(GL_BACK);
::glPushMatrix();
#if ENABLE_MODELVOLUME_TRANSFORM
::glMultMatrixd(world_matrix().data());
#else
::glMultMatrixf(world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
if (this->indexed_vertex_array.indexed())
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
else
@ -544,11 +412,7 @@ void GLVolume::render_using_layer_height() const
glUniform1f(z_cursor_band_width_id, (GLfloat)layer_height_texture_data.edit_band_width);
if (world_matrix_id >= 0)
#if ENABLE_MODELVOLUME_TRANSFORM
::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().cast<float>().data());
#else
::glUniformMatrix4fv(world_matrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
GLsizei w = (GLsizei)layer_height_texture_width();
GLsizei h = (GLsizei)layer_height_texture_height();
@ -608,11 +472,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glUniform1i(detection_id, shader_outside_printer_detection_enabled ? 1 : 0);
if (worldmatrix_id != -1)
#if ENABLE_MODELVOLUME_TRANSFORM
::glUniformMatrix4fv(worldmatrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().cast<float>().data());
#else
::glUniformMatrix4fv(worldmatrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
render();
@ -631,11 +491,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glUniform1i(detection_id, shader_outside_printer_detection_enabled ? 1 : 0);
if (worldmatrix_id != -1)
#if ENABLE_MODELVOLUME_TRANSFORM
::glUniformMatrix4fv(worldmatrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().cast<float>().data());
#else
::glUniformMatrix4fv(worldmatrix_id, 1, GL_FALSE, (const GLfloat*)world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
::glBindBuffer(GL_ARRAY_BUFFER, indexed_vertex_array.vertices_and_normals_interleaved_VBO_id);
::glVertexPointer(3, GL_FLOAT, 6 * sizeof(float), (const void*)(3 * sizeof(float)));
@ -643,11 +499,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glPushMatrix();
#if ENABLE_MODELVOLUME_TRANSFORM
::glMultMatrixd(world_matrix().data());
#else
::glMultMatrixf(world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
if (n_triangles > 0)
{
@ -691,11 +543,7 @@ void GLVolume::render_legacy() const
::glPushMatrix();
#if ENABLE_MODELVOLUME_TRANSFORM
::glMultMatrixd(world_matrix().data());
#else
::glMultMatrixf(world_matrix().data());
#endif // ENABLE_MODELVOLUME_TRANSFORM
if (n_triangles > 0)
::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first);
@ -780,11 +628,7 @@ int GLVolumeCollection::load_object_volume(
const ModelVolume *model_volume = model_object->volumes[volume_idx];
const int extruder_id = model_volume->extruder_id();
const ModelInstance *instance = model_object->instances[instance_idx];
#if ENABLE_MODELVOLUME_TRANSFORM
const TriangleMesh& mesh = model_volume->mesh;
#else
TriangleMesh mesh = model_volume->mesh;
#endif // ENABLE_MODELVOLUME_TRANSFORM
float color[4];
memcpy(color, colors[((color_by == "volume") ? volume_idx : obj_idx) % 4], sizeof(float) * 3);
/* if (model_volume->is_support_blocker()) {
@ -822,15 +666,8 @@ int GLVolumeCollection::load_object_volume(
}
v.is_modifier = ! model_volume->is_model_part();
v.shader_outside_printer_detection_enabled = model_volume->is_model_part();
#if ENABLE_MODELVOLUME_TRANSFORM
v.set_instance_transformation(instance->get_transformation());
v.set_volume_transformation(model_volume->get_transformation());
#else
v.set_offset(instance->get_offset());
v.set_rotation(instance->get_rotation());
v.set_scaling_factor(instance->get_scaling_factor());
v.set_mirror(instance->get_mirror());
#endif // ENABLE_MODELVOLUME_TRANSFORM
return int(this->volumes.size() - 1);
}
@ -941,11 +778,7 @@ int GLVolumeCollection::load_wipe_tower_preview(
else
v.indexed_vertex_array.load_mesh_flat_shading(mesh);
#if ENABLE_MODELVOLUME_TRANSFORM
v.set_volume_offset(Vec3d(pos_x, pos_y, 0.0));
#else
v.set_offset(Vec3d(pos_x, pos_y, 0.0));
#endif // ENABLE_MODELVOLUME_TRANSFORM
// finalize_geometry() clears the vertex arrays, therefore the bounding box has to be computed before finalize_geometry().
v.bounding_box = v.indexed_vertex_array.bounding_box();

View file

@ -257,23 +257,9 @@ public:
~GLVolume();
private:
#if ENABLE_MODELVOLUME_TRANSFORM
Geometry::Transformation m_instance_transformation;
Geometry::Transformation m_volume_transformation;
#else
// Offset of the volume to be rendered.
Vec3d m_offset;
// Rotation around three axes of the volume to be rendered.
Vec3d m_rotation;
// Scale factor along the three axes of the volume to be rendered.
Vec3d m_scaling_factor;
// Mirroring along the three axes of the volume to be rendered.
Vec3d m_mirror;
// World matrix of the volume to be rendered.
mutable Transform3f m_world_matrix;
// Whether or not is needed to recalculate the world matrix.
mutable bool m_world_matrix_dirty;
#endif // ENABLE_MODELVOLUME_TRANSFORM
// Shift in z required by sla supports+pad
double m_sla_shift_z;
// Bounding box of this volume, in unscaled coordinates.
@ -357,7 +343,6 @@ public:
// set color according to model volume
void set_color_from_model_volume(const ModelVolume *model_volume);
#if ENABLE_MODELVOLUME_TRANSFORM
const Geometry::Transformation& get_instance_transformation() const { return m_instance_transformation; }
void set_instance_transformation(const Geometry::Transformation& transformation) { m_instance_transformation = transformation; set_bounding_boxes_as_dirty(); }
@ -411,21 +396,6 @@ public:
void set_volume_mirror(const Vec3d& mirror) { m_volume_transformation.set_mirror(mirror); set_bounding_boxes_as_dirty(); }
void set_volume_mirror(Axis axis, double mirror) { m_volume_transformation.set_mirror(axis, mirror); set_bounding_boxes_as_dirty(); }
#else
const Vec3d& get_rotation() const;
void set_rotation(const Vec3d& rotation);
const Vec3d& get_scaling_factor() const;
void set_scaling_factor(const Vec3d& scaling_factor);
const Vec3d& get_mirror() const;
double get_mirror(Axis axis) const;
void set_mirror(const Vec3d& mirror);
void set_mirror(Axis axis, double mirror);
const Vec3d& get_offset() const;
void set_offset(const Vec3d& offset);
#endif // ENABLE_MODELVOLUME_TRANSFORM
double get_sla_shift_z() const { return m_sla_shift_z; }
void set_sla_shift_z(double z) { m_sla_shift_z = z; }
@ -436,11 +406,8 @@ public:
int volume_idx() const { return this->composite_id.volume_id; }
int instance_idx() const { return this->composite_id.instance_id; }
#if ENABLE_MODELVOLUME_TRANSFORM
Transform3d world_matrix() const;
#else
const Transform3f& world_matrix() const;
#endif // ENABLE_MODELVOLUME_TRANSFORM
const BoundingBoxf3& transformed_bounding_box() const;
const BoundingBoxf3& transformed_convex_hull_bounding_box() const;
@ -491,9 +458,7 @@ public:
void reset_layer_height_texture_data() { layer_height_texture_data.reset(); }
#if ENABLE_MODELVOLUME_TRANSFORM
void set_bounding_boxes_as_dirty() { m_transformed_bounding_box_dirty = true; m_transformed_convex_hull_bounding_box_dirty = true; }
#endif // ENABLE_MODELVOLUME_TRANSFORM
};
typedef std::vector<GLVolume*> GLVolumePtrs;

View file

@ -1104,7 +1104,6 @@ bool GLCanvas3D::Mouse::is_start_position_3D_defined() const
return (drag.start_position_3D != Drag::Invalid_3D_Point);
}
#if ENABLE_MODELVOLUME_TRANSFORM
GLCanvas3D::Selection::VolumeCache::TransformCache::TransformCache()
: position(Vec3d::Zero())
, rotation(Vec3d::Zero())
@ -1132,25 +1131,6 @@ GLCanvas3D::Selection::VolumeCache::VolumeCache(const Geometry::Transformation&
, m_instance(instance_transform)
{
}
#else
GLCanvas3D::Selection::VolumeCache::VolumeCache()
: m_position(Vec3d::Zero())
, m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones())
{
m_rotation_matrix = Transform3d::Identity();
m_scale_matrix = Transform3d::Identity();
}
GLCanvas3D::Selection::VolumeCache::VolumeCache(const Vec3d& position, const Vec3d& rotation, const Vec3d& scaling_factor)
: m_position(position)
, m_rotation(rotation)
, m_scaling_factor(scaling_factor)
{
m_rotation_matrix = Geometry::assemble_transform(Vec3d::Zero(), m_rotation);
m_scale_matrix = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), m_scaling_factor);
}
#endif // ENABLE_MODELVOLUME_TRANSFORM
GLCanvas3D::Selection::Selection()
: m_volumes(nullptr)
@ -1241,13 +1221,6 @@ void GLCanvas3D::Selection::add(unsigned int volume_idx, bool as_single_selectio
_add_instance(volume->object_idx(), volume->instance_idx());
break;
}
#if !ENABLE_MODELVOLUME_TRANSFORM
case Object:
{
_add_object(volume->object_idx());
break;
}
#endif // !ENABLE_MODELVOLUME_TRANSFORM
}
_update_type();
@ -1273,13 +1246,6 @@ void GLCanvas3D::Selection::remove(unsigned int volume_idx)
_remove_instance(volume->object_idx(), volume->instance_idx());
break;
}
#if !ENABLE_MODELVOLUME_TRANSFORM
case Object:
{
_remove_object(volume->object_idx());
break;
}
#endif // !ENABLE_MODELVOLUME_TRANSFORM
}
_update_type();
@ -1552,7 +1518,6 @@ void GLCanvas3D::Selection::translate(const Vec3d& displacement, bool local)
for (unsigned int i : m_list)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if ((m_mode == Volume) || (*m_volumes)[i]->is_wipe_tower)
{
if (local)
@ -1565,9 +1530,6 @@ void GLCanvas3D::Selection::translate(const Vec3d& displacement, bool local)
}
else if (m_mode == Instance)
(*m_volumes)[i]->set_instance_offset(m_cache.volumes_data[i].get_instance_position() + displacement);
#else
(*m_volumes)[i]->set_offset(m_cache.volumes_data[i].get_position() + displacement);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
#if !DISABLE_INSTANCES_SYNCH
@ -1600,13 +1562,8 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
}
}
#else
#if ENABLE_MODELVOLUME_TRANSFORM
(*m_volumes)[i]->set_instance_rotation(rotation);
#else
(*m_volumes)[i]->set_rotation(rotation);
#endif // ENABLE_MODELVOLUME_TRANSFORM
#endif // ENABLE_WORLD_ROTATIONS
#if ENABLE_MODELVOLUME_TRANSFORM
else if (is_single_volume() || is_single_modifier())
#if ENABLE_WORLD_ROTATIONS
{
@ -1623,11 +1580,9 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
#else
(*m_volumes)[i]->set_volume_rotation(rotation);
#endif // ENABLE_WORLD_ROTATIONS
#endif // ENABLE_MODELVOLUME_TRANSFORM
else
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), rotation);
#if ENABLE_MODELVOLUME_TRANSFORM
if (m_mode == Instance)
{
// extracts rotations from the composed transformation
@ -1648,12 +1603,6 @@ void GLCanvas3D::Selection::rotate(const Vec3d& rotation, bool local)
}
(*m_volumes)[i]->set_volume_rotation(new_rotation);
}
#else
// extracts rotations from the composed transformation
Vec3d new_rotation = Geometry::extract_euler_angles(m * m_cache.volumes_data[i].get_rotation_matrix());
(*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center));
(*m_volumes)[i]->set_rotation(new_rotation);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
}
@ -1678,7 +1627,6 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal)
for (unsigned int i : m_list)
{
#if ENABLE_MODELVOLUME_TRANSFORM
Transform3d wst = m_cache.volumes_data[i].get_instance_scale_matrix() * m_cache.volumes_data[i].get_volume_scale_matrix();
Vec3d scaling_factor = Vec3d(1./wst(0,0), 1./wst(1,1), 1./wst(2,2));
@ -1694,23 +1642,6 @@ void GLCanvas3D::Selection::flattening_rotate(const Vec3d& normal)
Vec3d new_rotation = Geometry::extract_euler_angles(extra_rotation * m_cache.volumes_data[i].get_instance_rotation_matrix() );
(*m_volumes)[i]->set_instance_rotation(new_rotation);
#else
Transform3d wst = m_cache.volumes_data[i].get_scale_matrix() * m_cache.volumes_data[i].get_scale_matrix();
Vec3d scaling_factor = Vec3d(1. / wst(0, 0), 1. / wst(1, 1), 1. / wst(2, 2));
Vec3d rotation = Geometry::extract_euler_angles(m_cache.volumes_data[i].get_rotation_matrix() * m_cache.volumes_data[i].get_rotation_matrix());
Vec3d transformed_normal = Geometry::assemble_transform(Vec3d::Zero(), rotation, scaling_factor) * normal;
transformed_normal.normalize();
Vec3d axis = transformed_normal(2) > 0.999f ? Vec3d(1., 0., 0.) : Vec3d(transformed_normal.cross(Vec3d(0., 0., -1.)));
axis.normalize();
Transform3d extra_rotation = Transform3d::Identity();
extra_rotation.rotate(Eigen::AngleAxisd(acos(-transformed_normal(2)), axis));
Vec3d new_rotation = Geometry::extract_euler_angles(extra_rotation * m_cache.volumes_data[i].get_rotation_matrix());
(*m_volumes)[i]->set_rotation(new_rotation);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
#if !DISABLE_INSTANCES_SYNCH
@ -1729,19 +1660,12 @@ void GLCanvas3D::Selection::scale(const Vec3d& scale, bool local)
for (unsigned int i : m_list)
{
if (is_single_full_instance())
#if ENABLE_MODELVOLUME_TRANSFORM
(*m_volumes)[i]->set_instance_scaling_factor(scale);
#else
(*m_volumes)[i]->set_scaling_factor(scale);
#endif // ENABLE_MODELVOLUME_TRANSFORM
#if ENABLE_MODELVOLUME_TRANSFORM
else if (is_single_volume() || is_single_modifier())
(*m_volumes)[i]->set_volume_scaling_factor(scale);
#endif // ENABLE_MODELVOLUME_TRANSFORM
else
{
Transform3d m = Geometry::assemble_transform(Vec3d::Zero(), Vec3d::Zero(), scale);
#if ENABLE_MODELVOLUME_TRANSFORM
if (m_mode == Instance)
{
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_instance_scale_matrix()).matrix().block(0, 0, 3, 3);
@ -1764,13 +1688,6 @@ void GLCanvas3D::Selection::scale(const Vec3d& scale, bool local)
}
(*m_volumes)[i]->set_volume_scaling_factor(new_scale);
}
#else
Eigen::Matrix<double, 3, 3, Eigen::DontAlign> new_matrix = (m * m_cache.volumes_data[i].get_scale_matrix()).matrix().block(0, 0, 3, 3);
// extracts scaling factors from the composed transformation
Vec3d new_scale(new_matrix.col(0).norm(), new_matrix.col(1).norm(), new_matrix.col(2).norm());
(*m_volumes)[i]->set_offset(m_cache.dragging_center + m * (m_cache.volumes_data[i].get_position() - m_cache.dragging_center));
(*m_volumes)[i]->set_scaling_factor(new_scale);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
}
@ -1798,13 +1715,9 @@ void GLCanvas3D::Selection::mirror(Axis axis)
for (unsigned int i : m_list)
{
if (single_full_instance)
#if ENABLE_MODELVOLUME_TRANSFORM
(*m_volumes)[i]->set_instance_mirror(axis, -(*m_volumes)[i]->get_instance_mirror(axis));
else if (m_mode == Volume)
(*m_volumes)[i]->set_volume_mirror(axis, -(*m_volumes)[i]->get_volume_mirror(axis));
#else
(*m_volumes)[i]->set_mirror(axis, -(*m_volumes)[i]->get_mirror(axis));
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
#if !DISABLE_INSTANCES_SYNCH
@ -1826,11 +1739,7 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, const Vec3d& disp
{
GLVolume* v = (*m_volumes)[i];
if (v->object_idx() == object_idx)
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_instance_offset(v->get_instance_offset() + displacement);
#else
v->set_offset(v->get_offset() + displacement);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
std::set<unsigned int> done; // prevent processing volumes twice
@ -1858,11 +1767,7 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, const Vec3d& disp
if (v->object_idx() != object_idx)
continue;
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_instance_offset(v->get_instance_offset() + displacement);
#else
v->set_offset(v->get_offset() + displacement);
#endif // ENABLE_MODELVOLUME_TRANSFORM
done.insert(j);
}
}
@ -1879,11 +1784,7 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, unsigned int inst
{
GLVolume* v = (*m_volumes)[i];
if ((v->object_idx() == object_idx) && (v->instance_idx() == instance_idx))
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_instance_offset(v->get_instance_offset() + displacement);
#else
v->set_offset(v->get_offset() + displacement);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
std::set<unsigned int> done; // prevent processing volumes twice
@ -1911,11 +1812,7 @@ void GLCanvas3D::Selection::translate(unsigned int object_idx, unsigned int inst
if ((v->object_idx() != object_idx) || (v->instance_idx() != instance_idx))
continue;
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_instance_offset(v->get_instance_offset() + displacement);
#else
v->set_offset(v->get_offset() + displacement);
#endif // ENABLE_MODELVOLUME_TRANSFORM
done.insert(j);
}
}
@ -2366,11 +2263,7 @@ void GLCanvas3D::Selection::_set_caches()
for (unsigned int i : m_list)
{
const GLVolume* v = (*m_volumes)[i];
#if ENABLE_MODELVOLUME_TRANSFORM
m_cache.volumes_data.emplace(i, VolumeCache(v->get_volume_transformation(), v->get_instance_transformation()));
#else
m_cache.volumes_data.emplace(i, VolumeCache(v->get_offset(), v->get_rotation(), v->get_scaling_factor()));
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
m_cache.dragging_center = get_bounding_box().center();
}
@ -2641,15 +2534,9 @@ void GLCanvas3D::Selection::_synchronize_unselected_instances()
continue;
int instance_idx = volume->instance_idx();
#if ENABLE_MODELVOLUME_TRANSFORM
const Vec3d& rotation = volume->get_instance_rotation();
const Vec3d& scaling_factor = volume->get_instance_scaling_factor();
const Vec3d& mirror = volume->get_instance_mirror();
#else
const Vec3d& rotation = volume->get_rotation();
const Vec3d& scaling_factor = volume->get_scaling_factor();
const Vec3d& mirror = volume->get_mirror();
#endif // ENABLE_MODELVOLUME_TRANSFORM
// Process unselected instances.
for (unsigned int j = 0; j < (unsigned int)m_volumes->size(); ++j)
@ -2664,15 +2551,9 @@ void GLCanvas3D::Selection::_synchronize_unselected_instances()
if ((v->object_idx() != object_idx) || (v->instance_idx() == instance_idx))
continue;
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_instance_rotation(Vec3d(rotation(0), rotation(1), v->get_instance_rotation()(2)));
v->set_instance_scaling_factor(scaling_factor);
v->set_instance_mirror(mirror);
#else
v->set_rotation(Vec3d(rotation(0), rotation(1), v->get_rotation()(2)));
v->set_scaling_factor(scaling_factor);
v->set_mirror(mirror);
#endif // ENABLE_MODELVOLUME_TRANSFORM
done.insert(j);
}
@ -2689,17 +2570,10 @@ void GLCanvas3D::Selection::_synchronize_unselected_volumes()
continue;
int volume_idx = volume->volume_idx();
#if ENABLE_MODELVOLUME_TRANSFORM
const Vec3d& offset = volume->get_volume_offset();
const Vec3d& rotation = volume->get_volume_rotation();
const Vec3d& scaling_factor = volume->get_volume_scaling_factor();
const Vec3d& mirror = volume->get_volume_mirror();
#else
const Vec3d& offset = volume->get_offset();
const Vec3d& rotation = volume->get_rotation();
const Vec3d& scaling_factor = volume->get_scaling_factor();
const Vec3d& mirror = volume->get_mirror();
#endif // ENABLE_MODELVOLUME_TRANSFORM
// Process unselected volumes.
for (unsigned int j = 0; j < (unsigned int)m_volumes->size(); ++j)
@ -2711,17 +2585,10 @@ void GLCanvas3D::Selection::_synchronize_unselected_volumes()
if ((v->object_idx() != object_idx) || (v->volume_idx() != volume_idx))
continue;
#if ENABLE_MODELVOLUME_TRANSFORM
v->set_volume_offset(offset);
v->set_volume_rotation(rotation);
v->set_volume_scaling_factor(scaling_factor);
v->set_volume_mirror(mirror);
#else
v->set_offset(offset);
v->set_rotation(Vec3d(rotation));
v->set_scaling_factor(scaling_factor);
v->set_mirror(mirror);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
}
}
@ -5571,7 +5438,6 @@ void GLCanvas3D::do_move()
ModelObject* model_object = m_model->objects[object_idx];
if (model_object != nullptr)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection_mode == Selection::Instance)
{
model_object->instances[instance_idx]->set_offset(v->get_instance_offset());
@ -5583,20 +5449,12 @@ void GLCanvas3D::do_move()
object_moved = true;
}
if (object_moved)
#else
model_object->instances[instance_idx]->set_offset(v->get_offset());
object_moved = true;
#endif // ENABLE_MODELVOLUME_TRANSFORM
model_object->invalidate_bounding_box();
}
}
else if (object_idx == 1000)
// Move a wipe tower proxy.
#if ENABLE_MODELVOLUME_TRANSFORM
wipe_tower_origin = v->get_volume_offset();
#else
wipe_tower_origin = v->get_offset();
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
// Fixes sinking/flying instances
@ -5639,7 +5497,6 @@ void GLCanvas3D::do_rotate()
ModelObject* model_object = m_model->objects[object_idx];
if (model_object != nullptr)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection_mode == Selection::Instance)
{
model_object->instances[instance_idx]->set_rotation(v->get_instance_rotation());
@ -5650,10 +5507,6 @@ void GLCanvas3D::do_rotate()
model_object->volumes[volume_idx]->set_rotation(v->get_volume_rotation());
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
}
#else
model_object->instances[instance_idx]->set_rotation(v->get_rotation());
model_object->instances[instance_idx]->set_offset(v->get_offset());
#endif // ENABLE_MODELVOLUME_TRANSFORM
model_object->invalidate_bounding_box();
}
}
@ -5694,7 +5547,6 @@ void GLCanvas3D::do_scale()
ModelObject* model_object = m_model->objects[object_idx];
if (model_object != nullptr)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection_mode == Selection::Instance)
{
model_object->instances[instance_idx]->set_scaling_factor(v->get_instance_scaling_factor());
@ -5706,10 +5558,6 @@ void GLCanvas3D::do_scale()
model_object->volumes[volume_idx]->set_scaling_factor(v->get_volume_scaling_factor());
model_object->volumes[volume_idx]->set_offset(v->get_volume_offset());
}
#else
model_object->instances[instance_idx]->set_scaling_factor(v->get_scaling_factor());
model_object->instances[instance_idx]->set_offset(v->get_offset());
#endif // ENABLE_MODELVOLUME_TRANSFORM
model_object->invalidate_bounding_box();
}
}
@ -5755,14 +5603,11 @@ void GLCanvas3D::do_mirror()
ModelObject* model_object = m_model->objects[object_idx];
if (model_object != nullptr)
{
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection_mode == Selection::Instance)
model_object->instances[instance_idx]->set_mirror(v->get_instance_mirror());
else if (selection_mode == Selection::Volume)
model_object->volumes[volume_idx]->set_mirror(v->get_volume_mirror());
#else
model_object->instances[instance_idx]->set_mirror(v->get_mirror());
#endif // ENABLE_MODELVOLUME_TRANSFORM
model_object->invalidate_bounding_box();
}
}
@ -6801,7 +6646,6 @@ void GLCanvas3D::_update_gizmos_data()
if (m_selection.is_single_full_instance())
{
#if ENABLE_MODELVOLUME_TRANSFORM
// all volumes in the selection belongs to the same instance, any of them contains the needed data, so we take the first
const GLVolume* volume = m_volumes.volumes[*m_selection.get_volume_idxs().begin()];
m_gizmos.set_scale(volume->get_instance_scaling_factor());
@ -6817,24 +6661,7 @@ void GLCanvas3D::_update_gizmos_data()
#else
m_gizmos.set_model_object_ptr(model_object);
#endif // ENABLE_SLA_SUPPORT_GIZMO_MOD
#else
ModelObject* model_object = m_model->objects[m_selection.get_object_idx()];
ModelInstance* model_instance = model_object->instances[m_selection.get_instance_idx()];
m_gizmos.set_scale(model_instance->get_scaling_factor());
#if ENABLE_WORLD_ROTATIONS
m_gizmos.set_rotation(Vec3d::Zero());
#else
m_gizmos.set_rotation(model_instance->get_rotation());
#endif // ENABLE_WORLD_ROTATIONS
m_gizmos.set_flattening_data(model_object);
#if ENABLE_SLA_SUPPORT_GIZMO_MOD
m_gizmos.set_sla_support_data(model_object, m_selection);
#else
m_gizmos.set_model_object_ptr(model_object);
#endif // ENABLE_SLA_SUPPORT_GIZMO_MOD
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
#if ENABLE_MODELVOLUME_TRANSFORM
else if (m_selection.is_single_volume() || m_selection.is_single_modifier())
{
const GLVolume* volume = m_volumes.volumes[*m_selection.get_volume_idxs().begin()];
@ -6851,7 +6678,6 @@ void GLCanvas3D::_update_gizmos_data()
m_gizmos.set_model_object_ptr(nullptr);
#endif // ENABLE_SLA_SUPPORT_GIZMO_MOD
}
#endif // ENABLE_MODELVOLUME_TRANSFORM
else
{
m_gizmos.set_scale(Vec3d::Ones());

View file

@ -367,14 +367,8 @@ public:
enum EMode : unsigned char
{
#if ENABLE_MODELVOLUME_TRANSFORM
Volume,
Instance
#else
Volume,
Instance,
Object
#endif // ENABLE_MODELVOLUME_TRANSFORM
};
enum EType : unsigned char
@ -397,7 +391,6 @@ public:
struct VolumeCache
{
private:
#if ENABLE_MODELVOLUME_TRANSFORM
struct TransformCache
{
Vec3d position;
@ -414,24 +407,11 @@ public:
TransformCache m_volume;
TransformCache m_instance;
#else
Vec3d m_position;
Vec3d m_rotation;
Vec3d m_scaling_factor;
Transform3d m_rotation_matrix;
Transform3d m_scale_matrix;
#endif // ENABLE_MODELVOLUME_TRANSFORM
public:
#if ENABLE_MODELVOLUME_TRANSFORM
VolumeCache() {}
VolumeCache(const Geometry::Transformation& volume_transform, const Geometry::Transformation& instance_transform);
#else
VolumeCache();
VolumeCache(const Vec3d& position, const Vec3d& rotation, const Vec3d& scaling_factor);
#endif // ENABLE_MODELVOLUME_TRANSFORM
#if ENABLE_MODELVOLUME_TRANSFORM
const Vec3d& get_volume_position() const { return m_volume.position; }
const Vec3d& get_volume_rotation() const { return m_volume.rotation; }
const Vec3d& get_volume_scaling_factor() const { return m_volume.scaling_factor; }
@ -447,13 +427,6 @@ public:
const Transform3d& get_instance_rotation_matrix() const { return m_instance.rotation_matrix; }
const Transform3d& get_instance_scale_matrix() const { return m_instance.scale_matrix; }
const Transform3d& get_instance_mirror_matrix() const { return m_instance.mirror_matrix; }
#else
const Vec3d& get_position() const { return m_position; }
const Vec3d& get_rotation() const { return m_rotation; }
const Vec3d& get_scaling_factor() const { return m_scaling_factor; }
const Transform3d& get_rotation_matrix() const { return m_rotation_matrix; }
const Transform3d& get_scale_matrix() const { return m_scale_matrix; }
#endif // ENABLE_MODELVOLUME_TRANSFORM
};
typedef std::map<unsigned int, VolumeCache> VolumesCache;

View file

@ -860,14 +860,10 @@ void GLGizmoScale3D::on_render(const GLCanvas3D::Selection& selection) const
bool single_selection = single_instance || single_volume;
Vec3f scale = 100.0f * Vec3f::Ones();
#if ENABLE_MODELVOLUME_TRANSFORM
if (single_instance)
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_instance_scaling_factor().cast<float>();
else if (single_volume)
scale = 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_volume_scaling_factor().cast<float>();
#else
Vec3f scale = single_instance ? 100.0f * selection.get_volume(*selection.get_volume_idxs().begin())->get_scaling_factor().cast<float>() : 100.0f * m_scale.cast<float>();
#endif // ENABLE_MODELVOLUME_TRANSFORM
if ((single_selection && ((m_hover_id == 0) || (m_hover_id == 1))) || m_grabbers[0].dragging || m_grabbers[1].dragging)
set_tooltip("X: " + format(scale(0), 4) + "%");
@ -915,37 +911,22 @@ void GLGizmoScale3D::on_render(const GLCanvas3D::Selection& selection) const
// gets transform from first selected volume
const GLVolume* v = selection.get_volume(*idxs.begin());
#if ENABLE_MODELVOLUME_TRANSFORM
transform = v->get_instance_transformation().get_matrix();
// gets angles from first selected volume
angles = v->get_instance_rotation();
// consider rotation+mirror only components of the transform for offsets
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles, Vec3d::Ones(), v->get_instance_mirror());
grabber_size = v->get_instance_transformation().get_matrix(true, true, false, true) * box.size();
#else
transform = v->world_matrix().cast<double>();
// gets angles from first selected volume
angles = v->get_rotation();
// consider rotation+mirror only components of the transform for offsets
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles, Vec3d::Ones(), v->get_mirror());
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
else if (single_volume)
{
const GLVolume* v = selection.get_volume(*selection.get_volume_idxs().begin());
box = v->bounding_box;
#if ENABLE_MODELVOLUME_TRANSFORM
transform = v->world_matrix();
angles = Geometry::extract_euler_angles(transform);
// consider rotation+mirror only components of the transform for offsets
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles, Vec3d::Ones(), v->get_instance_mirror());
grabber_size = v->get_volume_transformation().get_matrix(true, true, false, true) * box.size();
#else
transform = v->world_matrix().cast<double>();
angles = Geometry::extract_euler_angles(transform);
// consider rotation+mirror only components of the transform for offsets
offsets_transform = Geometry::assemble_transform(Vec3d::Zero(), angles, Vec3d::Ones(), v->get_mirror());
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
else
{
@ -1529,7 +1510,6 @@ void GLGizmoFlatten::update_planes()
{
TriangleMesh ch;
for (const ModelVolume* vol : m_model_object->volumes)
#if ENABLE_MODELVOLUME_TRANSFORM
{
if (vol->type() != ModelVolume::Type::MODEL_PART)
continue;
@ -1537,9 +1517,6 @@ void GLGizmoFlatten::update_planes()
vol_ch.transform(vol->get_matrix());
ch.merge(vol_ch);
}
#else
ch.merge(vol->get_convex_hull());
#endif // ENABLE_MODELVOLUME_TRANSFORM
ch = ch.convex_hull_3d();

View file

@ -840,27 +840,17 @@ void ObjectList::load_part( ModelObject* model_object,
if (model_object->origin_translation != Vec3d::Zero())
{
object->center_around_origin();
#if !ENABLE_MODELVOLUME_TRANSFORM
object->ensure_on_bed();
#endif // !ENABLE_MODELVOLUME_TRANSFORM
delta = model_object->origin_translation - object->origin_translation;
}
for (auto volume : object->volumes) {
#if ENABLE_MODELVOLUME_TRANSFORM
volume->center_geometry();
volume->translate(delta);
#endif // ENABLE_MODELVOLUME_TRANSFORM
auto new_volume = model_object->add_volume(*volume);
new_volume->set_type(static_cast<ModelVolume::Type>(type));
new_volume->name = boost::filesystem::path(input_file).filename().string();
part_names.Add(new_volume->name);
#if !ENABLE_MODELVOLUME_TRANSFORM
if (delta != Vec3d::Zero())
new_volume->translate(delta);
#endif // !ENABLE_MODELVOLUME_TRANSFORM
// set a default extruder value, since user can't add it manually
new_volume->config.set_key_value("extruder", new ConfigOptionInt(0));
@ -903,10 +893,8 @@ void ObjectList::load_generic_subobject(const std::string& type_name, const int
auto new_volume = (*m_objects)[obj_idx]->add_volume(mesh);
new_volume->set_type(static_cast<ModelVolume::Type>(type));
#if ENABLE_MODELVOLUME_TRANSFORM
new_volume->set_offset(Vec3d(0.0, 0.0, (*m_objects)[obj_idx]->origin_translation(2) - mesh.stl.stats.min(2)));
new_volume->center_geometry();
#endif // ENABLE_MODELVOLUME_TRANSFORM
new_volume->name = name;
// set a default extruder value, since user can't add it manually

View file

@ -195,30 +195,10 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
m_new_move_label_string = L("Position:");
m_new_rotate_label_string = L("Rotation:");
m_new_scale_label_string = L("Scale factors:");
#if ENABLE_MODELVOLUME_TRANSFORM
if (selection.is_single_full_instance())
#else
if (selection.is_single_full_object())
{
auto obj_idx = selection.get_object_idx();
if (obj_idx >=0 && !wxGetApp().model_objects()->empty() && (*wxGetApp().model_objects())[obj_idx]->instances.size() == 1)
{
// all volumes in the selection belongs to the same instance, any of them contains the needed data, so we take the first
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
m_new_position = volume->get_offset();
m_new_rotation = volume->get_rotation();
m_new_scale = volume->get_scaling_factor();
m_new_enabled = true;
}
else
reset_settings_value();
}
else if (selection.is_single_full_instance())
#endif // ENABLE_MODELVOLUME_TRANSFORM
{
// all volumes in the selection belongs to the same instance, any of them contains the needed instance data, so we take the first one
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
#if ENABLE_MODELVOLUME_TRANSFORM
m_new_position = volume->get_instance_offset();
m_new_rotation = volume->get_instance_rotation();
m_new_scale = volume->get_instance_scaling_factor();
@ -228,11 +208,7 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
else
// this should never happen
m_new_size = Vec3d::Zero();
#else
m_new_position = volume->get_offset();
m_new_rotation = volume->get_rotation();
m_new_scale = volume->get_scaling_factor();
#endif // ENABLE_MODELVOLUME_TRANSFORM
m_new_enabled = true;
}
else if (selection.is_single_full_object())
@ -250,16 +226,10 @@ void ObjectManipulation::update_settings_value(const GLCanvas3D::Selection& sele
{
// the selection contains a single volume
const GLVolume* volume = selection.get_volume(*selection.get_volume_idxs().begin());
#if ENABLE_MODELVOLUME_TRANSFORM
m_new_position = volume->get_volume_offset();
m_new_rotation = volume->get_volume_rotation();
m_new_scale = volume->get_volume_scaling_factor();
m_new_size = volume->get_instance_transformation().get_matrix(true, true) * volume->get_volume_transformation().get_matrix(true, true) * volume->bounding_box.size();
#else
m_new_position = volume->get_offset();
m_new_rotation = volume->get_rotation();
m_new_scale = volume->get_scaling_factor();
#endif // ENABLE_MODELVOLUME_TRANSFORM
m_new_enabled = true;
}
else if (wxGetApp().obj_list()->multiple_selection())

View file

@ -1514,9 +1514,6 @@ std::vector<size_t> Plater::priv::load_files(const std::vector<fs::path>& input_
std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &model_objects)
{
const BoundingBoxf bed_shape = bed_shape_bb();
#if !ENABLE_MODELVOLUME_TRANSFORM
const Vec3d bed_center = Slic3r::to_3d(bed_shape.center().cast<double>(), 0.0);
#endif // !ENABLE_MODELVOLUME_TRANSFORM
const Vec3d bed_size = Slic3r::to_3d(bed_shape.size().cast<double>(), 1.0) - 2.0 * Vec3d::Ones();
bool need_arrange = false;
@ -1536,11 +1533,7 @@ std::vector<size_t> Plater::priv::load_model_objects(const ModelObjectPtrs &mode
// add a default instance and center object around origin
object->center_around_origin(); // also aligns object to Z = 0
ModelInstance* instance = object->add_instance();
#if ENABLE_MODELVOLUME_TRANSFORM
instance->set_offset(Slic3r::to_3d(bed_shape.center().cast<double>(), -object->origin_translation(2)));
#else
instance->set_offset(bed_center);
#endif // ENABLE_MODELVOLUME_TRANSFORM
}
const Vec3d size = object->bounding_box().size();
@ -3340,9 +3333,6 @@ void Plater::changed_object(int obj_idx)
if (list->is_parts_changed()) {
// recenter and re - align to Z = 0
auto model_object = p->model.objects[obj_idx];
#if !ENABLE_MODELVOLUME_TRANSFORM
model_object->center_around_origin();
#endif // !ENABLE_MODELVOLUME_TRANSFORM
model_object->ensure_on_bed();
if (this->p->printer_technology == ptSLA) {
// Update the SLAPrint from the current Model, so that the reload_scene()