ModelInstance's full 3D transform set as default

This commit is contained in:
Enrico Turri 2018-10-16 09:51:30 +02:00
parent fb6c1a885c
commit 059ab4a05c
20 changed files with 2 additions and 630 deletions

View file

@ -196,13 +196,8 @@ const float GLVolume::SELECTED_OUTSIDE_COLOR[4] = { 0.19f, 0.58f, 1.0f, 1.0f };
GLVolume::GLVolume(float r, float g, float b, float a)
: m_offset(Vec3d::Zero())
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
, m_rotation(Vec3d::Zero())
, m_scaling_factor(Vec3d::Ones())
#else
, m_rotation(0.0)
, m_scaling_factor(1.0)
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
, m_world_matrix(Transform3f::Identity())
, m_world_matrix_dirty(true)
, m_transformed_bounding_box_dirty(true)
@ -262,7 +257,6 @@ void GLVolume::set_render_color()
set_render_color(color, 4);
}
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& GLVolume::get_rotation() const
{
return m_rotation;
@ -295,23 +289,6 @@ void GLVolume::set_rotation(const Vec3d& rotation)
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#else
double GLVolume::get_rotation() const
{
return m_rotation;
}
void GLVolume::set_rotation(double rotation)
{
if (m_rotation != rotation)
{
m_rotation = rotation;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
const Vec3d& GLVolume::get_offset() const
{
@ -329,7 +306,6 @@ void GLVolume::set_offset(const Vec3d& offset)
}
}
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
#if ENABLE_EXTENDED_SELECTION
const Vec3d& GLVolume::get_scaling_factor() const
{
@ -347,18 +323,6 @@ void GLVolume::set_scaling_factor(const Vec3d& scaling_factor)
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#else
void GLVolume::set_scaling_factor(double factor)
{
if (m_scaling_factor != factor)
{
m_scaling_factor = factor;
m_world_matrix_dirty = true;
m_transformed_bounding_box_dirty = true;
m_transformed_convex_hull_bounding_box_dirty = true;
}
}
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
{
@ -389,14 +353,7 @@ const Transform3f& GLVolume::world_matrix() const
{
if (m_world_matrix_dirty)
{
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_world_matrix = Geometry::assemble_transform(m_offset, m_rotation, m_scaling_factor).cast<float>();
#else
m_world_matrix = Transform3f::Identity();
m_world_matrix.translate(m_offset.cast<float>());
m_world_matrix.rotate(Eigen::AngleAxisf((float)m_rotation, Vec3f::UnitZ()));
m_world_matrix.scale((float)m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
m_world_matrix_dirty = false;
}
return m_world_matrix;
@ -471,13 +428,7 @@ void GLVolume::render() const
::glCullFace(GL_BACK);
::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (this->indexed_vertex_array.indexed())
this->indexed_vertex_array.render(this->tverts_range, this->qverts_range);
else
@ -602,13 +553,7 @@ void GLVolume::render_VBOs(int color_id, int detection_id, int worldmatrix_id) c
::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (n_triangles > 0)
{
@ -652,13 +597,7 @@ void GLVolume::render_legacy() const
::glPushMatrix();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
::glMultMatrixf(world_matrix().data());
#else
::glTranslated(m_offset(0), m_offset(1), m_offset(2));
::glRotated(m_rotation * 180.0 / (double)PI, 0.0, 0.0, 1.0);
::glScaled(m_scaling_factor, m_scaling_factor, m_scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
if (n_triangles > 0)
::glDrawElements(GL_TRIANGLES, n_triangles, GL_UNSIGNED_INT, indexed_vertex_array.triangle_indices.data() + tverts_range.first);
@ -787,15 +726,9 @@ std::vector<int> GLVolumeCollection::load_object(
}
v.is_modifier = ! model_volume->is_model_part();
v.shader_outside_printer_detection_enabled = model_volume->is_model_part();
#if ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
v.set_offset(instance->get_offset());
v.set_rotation(instance->get_rotation());
v.set_scaling_factor(instance->get_scaling_factor());
#else
v.set_offset(Vec3d(instance->offset(0), instance->offset(1), 0.0));
v.set_rotation(instance->rotation);
v.set_scaling_factor(instance->scaling_factor);
#endif // ENABLE_MODELINSTANCE_3D_FULL_TRANSFORM
}
}