mirror of
https://github.com/SoftFever/OrcaSlicer.git
synced 2025-07-21 13:47:59 -06:00
Added Geometry::Transformation class. Use it into ModelInstance, ModelVolume and GLVolume
This commit is contained in:
parent
7f08f460f1
commit
d6d632d4fc
8 changed files with 449 additions and 8 deletions
|
@ -195,6 +195,9 @@ const float GLVolume::OUTSIDE_COLOR[4] = { 0.0f, 0.38f, 0.8f, 1.0f };
|
|||
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)
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
: m_transformed_bounding_box_dirty(true)
|
||||
#else
|
||||
: m_offset(Vec3d::Zero())
|
||||
, m_rotation(Vec3d::Zero())
|
||||
, m_scaling_factor(Vec3d::Ones())
|
||||
|
@ -204,6 +207,7 @@ GLVolume::GLVolume(float r, float g, float b, float a)
|
|||
, m_world_matrix(Transform3f::Identity())
|
||||
, m_world_matrix_dirty(true)
|
||||
, m_transformed_bounding_box_dirty(true)
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
, m_transformed_convex_hull_bounding_box_dirty(true)
|
||||
, m_convex_hull(nullptr)
|
||||
, composite_id(-1)
|
||||
|
@ -260,6 +264,7 @@ void GLVolume::set_render_color()
|
|||
set_render_color(color, 4);
|
||||
}
|
||||
|
||||
#if !ENABLE_MODELVOLUME_TRANSFORM
|
||||
const Vec3d& GLVolume::get_rotation() const
|
||||
{
|
||||
return m_rotation;
|
||||
|
@ -360,6 +365,7 @@ void GLVolume::set_mirror(Axis axis, double mirror)
|
|||
}
|
||||
}
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
void GLVolume::set_convex_hull(const TriangleMesh& convex_hull)
|
||||
{
|
||||
|
@ -386,6 +392,7 @@ void GLVolume::set_drag_group_id(const std::string& drag_by)
|
|||
}
|
||||
#endif // !ENABLE_EXTENDED_SELECTION
|
||||
|
||||
#if !ENABLE_MODELVOLUME_TRANSFORM
|
||||
const Transform3f& GLVolume::world_matrix() const
|
||||
{
|
||||
if (m_world_matrix_dirty)
|
||||
|
@ -399,12 +406,17 @@ const Transform3f& GLVolume::world_matrix() const
|
|||
}
|
||||
return m_world_matrix;
|
||||
}
|
||||
#endif // !ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -415,10 +427,17 @@ 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;
|
||||
}
|
||||
|
@ -469,7 +488,11 @@ 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
|
||||
|
@ -507,7 +530,11 @@ 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();
|
||||
|
@ -567,7 +594,11 @@ 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();
|
||||
|
||||
|
@ -586,7 +617,11 @@ 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)));
|
||||
|
@ -594,7 +629,11 @@ 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)
|
||||
{
|
||||
|
@ -638,7 +677,11 @@ 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);
|
||||
|
@ -767,12 +810,16 @@ 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_MODELVOLUME_TRANSFORM
|
||||
v.set_transformation(instance->get_transformation());
|
||||
#else
|
||||
v.set_offset(instance->get_offset());
|
||||
v.set_rotation(instance->get_rotation());
|
||||
v.set_scaling_factor(instance->get_scaling_factor());
|
||||
#if ENABLE_MIRROR
|
||||
v.set_mirror(instance->get_mirror());
|
||||
#endif // ENABLE_MIRROR
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -254,6 +254,9 @@ public:
|
|||
GLVolume(const float *rgba) : GLVolume(rgba[0], rgba[1], rgba[2], rgba[3]) {}
|
||||
|
||||
private:
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
Geometry::Transformation m_transformation;
|
||||
#else
|
||||
// Offset of the volume to be rendered.
|
||||
Vec3d m_offset;
|
||||
// Rotation around three axes of the volume to be rendered.
|
||||
|
@ -268,6 +271,7 @@ private:
|
|||
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
|
||||
// Bounding box of this volume, in unscaled coordinates.
|
||||
mutable BoundingBoxf3 m_transformed_bounding_box;
|
||||
// Whether or not is needed to recalculate the transformed bounding box.
|
||||
|
@ -280,7 +284,6 @@ private:
|
|||
mutable bool m_transformed_convex_hull_bounding_box_dirty;
|
||||
|
||||
public:
|
||||
|
||||
// Bounding box of this volume, in unscaled coordinates.
|
||||
BoundingBoxf3 bounding_box;
|
||||
// Color of the triangles / quads held by this volume.
|
||||
|
@ -333,6 +336,36 @@ public:
|
|||
// Sets render color in dependence of current state
|
||||
void set_render_color();
|
||||
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
const Geometry::Transformation& get_transformation() const { return m_transformation; }
|
||||
void set_transformation(const Geometry::Transformation& transformation) { m_transformation = transformation; set_bounding_boxes_as_dirty(); }
|
||||
|
||||
const Vec3d& get_offset() const { return m_transformation.get_offset(); }
|
||||
double get_offset(Axis axis) const { return m_transformation.get_offset(axis); }
|
||||
|
||||
void set_offset(const Vec3d& offset) { m_transformation.set_offset(offset); set_bounding_boxes_as_dirty(); }
|
||||
void set_offset(Axis axis, double offset) { m_transformation.set_offset(axis, offset); set_bounding_boxes_as_dirty(); }
|
||||
|
||||
const Vec3d& get_rotation() const { return m_transformation.get_rotation(); }
|
||||
double get_rotation(Axis axis) const { return m_transformation.get_rotation(axis); }
|
||||
|
||||
void set_rotation(const Vec3d& rotation) { m_transformation.set_rotation(rotation); set_bounding_boxes_as_dirty(); }
|
||||
void set_rotation(Axis axis, double rotation) { m_transformation.set_rotation(axis, rotation); set_bounding_boxes_as_dirty(); }
|
||||
|
||||
Vec3d get_scaling_factor() const { return m_transformation.get_scaling_factor(); }
|
||||
double get_scaling_factor(Axis axis) const { return m_transformation.get_scaling_factor(axis); }
|
||||
|
||||
void set_scaling_factor(const Vec3d& scaling_factor) { m_transformation.set_scaling_factor(scaling_factor); set_bounding_boxes_as_dirty(); }
|
||||
void set_scaling_factor(Axis axis, double scaling_factor) { m_transformation.set_scaling_factor(axis, scaling_factor); set_bounding_boxes_as_dirty(); }
|
||||
|
||||
#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); set_bounding_boxes_as_dirty(); }
|
||||
void set_mirror(Axis axis, double mirror) { m_transformation.set_mirror(axis, mirror); set_bounding_boxes_as_dirty(); }
|
||||
#endif // ENABLE_MIRROR
|
||||
#else
|
||||
const Vec3d& get_rotation() const;
|
||||
void set_rotation(const Vec3d& rotation);
|
||||
|
||||
|
@ -350,6 +383,7 @@ public:
|
|||
|
||||
const Vec3d& get_offset() const;
|
||||
void set_offset(const Vec3d& offset);
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
void set_convex_hull(const TriangleMesh& convex_hull);
|
||||
|
||||
|
@ -362,7 +396,11 @@ public:
|
|||
int volume_idx() const { return (this->composite_id / 1000) % 1000; }
|
||||
int instance_idx() const { return this->composite_id % 1000; }
|
||||
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
const Transform3d& world_matrix() const { return m_transformation.world_matrix(); }
|
||||
#else
|
||||
const Transform3f& world_matrix() const;
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
const BoundingBoxf3& transformed_bounding_box() const;
|
||||
const BoundingBoxf3& transformed_convex_hull_bounding_box() const;
|
||||
|
||||
|
@ -412,6 +450,10 @@ 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
|
||||
};
|
||||
|
||||
#if ENABLE_EXTENDED_SELECTION
|
||||
|
|
|
@ -926,7 +926,11 @@ void GLGizmoScale3D::on_render(const BoundingBoxf3& box) const
|
|||
|
||||
// gets transform from first selected volume
|
||||
const GLVolume* v = selection.get_volume(*idxs.begin());
|
||||
#if ENABLE_MODELVOLUME_TRANSFORM
|
||||
transform = v->world_matrix();
|
||||
#else
|
||||
transform = v->world_matrix().cast<double>();
|
||||
#endif // ENABLE_MODELVOLUME_TRANSFORM
|
||||
|
||||
// gets angles from first selected volume
|
||||
angles = v->get_rotation();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue