mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-05-17 02:22:17 +00:00
* Update eigen from v3.3.7 to v5.0.1. This updates eigen from v3.3.7 released on December 11, 2018-12-11 to v5.0.1 released on 2025-11-11. There have be a large number of bug-fixes, optimizations, and improvements between these releases. See the details at; https://gitlab.com/libeigen/eigen/-/releases It retains the previous custom minimal `CMakeLists.txt`, and adds a README-OrcaSlicer.md that explains what version and parts of the upstream eigen release have been included, and where the full release can be found. * Update libigl from v2.0.0 (or older) to v2.6.0. This updates libigl from what was probably v2.0.0 released on 2018-10-16 to v2.6.0 released on 2025-05-15. It's possible the old version was even older than that but there is no version indicators in the code and I ran out of patience identifying missing changes and only went back as far as v2.0.0. There have been a large number of bug-fixes, optimizations, and improvements between these versions. See the following for details; https://github.com/libigl/libigl/releases I retained the minimal custom `CMakeLists.txt`, added `README.md` from the libigl distribution which identifies the version, and added a README-OrcaSlicer.md that details the version and parts that have been included. * Update libslic3r for libigl v2.6.0 changes. This updates libslic3r for all changes moving to eigen v5.0.1 and libigl v2.6.0. Despite the large number of updates to both dependencies, no changes were required for the eigen update, and only one change was required for the libigl update. For libigl, `igl::Hit` was changed to a template taking the Scalar type to use. Previously it was hard-coded to `float`, so to minimize possible impact I've updated all places it is used from `igl::Hit` to `igl::Hit<float>`. * Add compiler option `-DNOMINMAX` for libigl with MSVC. MSVC by default defines `min(()` and `max()` macros that break `std::numeric_limits<>::max()`. The upstream cmake that we don't include adds `-DNOMINMAX` for the libigl module when compiling with MSVC, so we need to add the same thing here. * Fix src/libslic3r/TriangleMeshDeal.cpp for the unmodified upstream libigl. This fixes `TriangleMeshDeal.cpp` to work with the unmodified upstream libigl v2.6.0. loop.{h,cpp} implementation. This file and feature was added in PR "BBS Port: Mesh Subdivision" (#12150) which included changes to `loop.{h,cpp}` in the old version of libigl. This PR avoids modifying the included dependencies, and uses the updated upstream versions of those files without any modifications, which requires fixing TriangleMeshDeal.cpp to work with them. In particular, the modifications made to `loop.{h,cpp}` included changing the return type from void to bool, adding additional validation checking of the input meshes, and returning false if they failed validation. These added checks looked unnecessary and would only have caught problems if the input mesh was very corrupt. To make `TriangleMeshDeal.cpp` work without this built-in checking functionality, I removed checking/handling of any `false` return value. There was also a hell of a lot of redundant copying and casting back and forth between float and double, so I cleaned that up. The input and output meshs use floats for the vertexes, and there would be no accuracy benefits from casting to and from doubles for the simple weighted average operations done by igl::loop(). So this just uses `Eigen:Map` to use the original input mesh vertex data directly without requiring any copy or casting. * Move eigen from included `deps_src` to externaly fetched `deps`. This copys what PrusaSlicer did and moved it from an included dependency under `deps_src` to an externaly fetched dependency under `deps`. This requires updating some `CMakeList.txt` configs and removing the old and obsolete `cmake/modules/FindEigen3.cmake`. The details of when this was done in PrusaSlicer and the followup fixes are at; *21116995d7* https://github.com/prusa3d/PrusaSlicer/issues/13608 * https://github.com/prusa3d/PrusaSlicer/pull/13609 *e3c277b9eeFor some reason I don't fully understand this also required fixing `src/slic3r/GUI/GUI_App.cpp` by adding `#include <boost/nowide/cstdio.hpp>` to fix an `error: ‘remove’ is not a member of ‘boost::nowide'`. The main thing I don't understand is how it worked before. Note that this include is in the PrusaSlicer version of this file, but it also significantly deviates from what is currently in OrcaSlicer in many other ways. * Whups... I missed adding the deps/Eigen/Eigen.cmake file... * Tidy some whitespace indenting in CMakeLists.txt. * Ugh... tabs indenting needing fixes. * Change the include order of deps/Eigen. It turns out that although Boost includes some references to Eigen, Eigen also includes some references to Boost for supporting some of it's additional numeric types. I don't think it matters much since we are not using these features, but I think technically its more correct to say Eigen depends on Boost than the other way around, so I've re-ordered them. * Add source for Eigen 5.0.1 download to flatpak yml config. * Add explicit `DEPENDS dep_Boost to deps/Eigen. I missed this before. This ensures we don't rely on include orders to make sure Boost is installed before we configure Eigen. * Add `DEPENDS dep_Boost dep_GMP dep_MPFR` to deps/Eigen. It turns out Eigen can also use GMP and MPFR for multi-precision and multi-precision-rounded numeric types if they are available. Again, I don't think we are using these so it doesn't really matter, but it is technically correct and ensures they are there if we ever do need them. * Fix deps DEPENDENCY ordering for GMP, MPFR, Eigen, and CGAL. I think this is finally correct. Apparently CGAL also optionally depends on Eigen, so the correct dependency order from lowest to highest is GMP, MPFR, Eigen, and CGAL. --------- Co-authored-by: Donovan Baarda <dbaarda@google.com> Co-authored-by: Noisyfox <timemanager.rick@gmail.com>
298 lines
9.3 KiB
C++
298 lines
9.3 KiB
C++
// This file is part of libigl, a simple c++ geometry processing library.
|
||
//
|
||
// Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@gmail.com>
|
||
//
|
||
// This Source Code Form is subject to the terms of the Mozilla Public License
|
||
// v. 2.0. If a copy of the MPL was not distributed with this file, You can
|
||
// obtain one at http://mozilla.org/MPL/2.0/.
|
||
#ifndef IGL_OPENGL_VIEWERCORE_H
|
||
#define IGL_OPENGL_VIEWERCORE_H
|
||
|
||
#include "MeshGL.h"
|
||
|
||
#include "../igl_inline.h"
|
||
#include <Eigen/Geometry>
|
||
#include <Eigen/Core>
|
||
|
||
namespace igl
|
||
{
|
||
namespace opengl
|
||
{
|
||
|
||
// Forward declaration
|
||
class ViewerData;
|
||
|
||
/// Basic class of the 3D mesh viewer
|
||
class ViewerCore
|
||
{
|
||
public:
|
||
using GLuint = MeshGL::GLuint;
|
||
IGL_INLINE ViewerCore();
|
||
|
||
/// Initialization
|
||
IGL_INLINE void init();
|
||
|
||
/// Shutdown
|
||
IGL_INLINE void shut();
|
||
|
||
/// Serialization code
|
||
IGL_INLINE void InitSerialization();
|
||
|
||
/// Adjust the view to see the entire model
|
||
/// @param[in] V #V by 3 list of vertex positions
|
||
/// @param[in] F #F by 3 list of triangle indices into V
|
||
IGL_INLINE void align_camera_center(
|
||
const Eigen::MatrixXd& V,
|
||
const Eigen::MatrixXi& F);
|
||
/// \overload
|
||
IGL_INLINE void align_camera_center(
|
||
const Eigen::MatrixXd& V);
|
||
|
||
/// Determines how much to zoom and shift such that the mesh fills the unit
|
||
/// box (centered at the origin)
|
||
/// @param[in] V #V by 3 list of vertex positions
|
||
/// @param[in] F #F by 3 list of triangle indices into V
|
||
/// @param[out] zoom zoom factor
|
||
/// @param[out] shift 3d shift
|
||
IGL_INLINE void get_scale_and_shift_to_fit_mesh(
|
||
const Eigen::MatrixXd& V,
|
||
const Eigen::MatrixXi& F,
|
||
float & zoom,
|
||
Eigen::Vector3f& shift);
|
||
/// \overload
|
||
IGL_INLINE void get_scale_and_shift_to_fit_mesh(
|
||
const Eigen::MatrixXd& V,
|
||
float & zoom,
|
||
Eigen::Vector3f& shift);
|
||
|
||
/// Clear the frame buffers
|
||
IGL_INLINE void clear_framebuffers();
|
||
|
||
/// Draw everything
|
||
///
|
||
/// \note data cannot be const because it is being set to "clean"
|
||
///
|
||
/// @param[in] data which ViewerData to draw
|
||
/// @param[in] update_matrices whether to update view, proj, and norm
|
||
/// matrices in shaders
|
||
IGL_INLINE void draw(ViewerData& data, bool update_matrices = true);
|
||
/// initialize shadow pass
|
||
IGL_INLINE void initialize_shadow_pass();
|
||
/// deinitialize shadow pass
|
||
IGL_INLINE void deinitialize_shadow_pass();
|
||
/// Draw everything to shadow map
|
||
/// @param[in] data which ViewerData to draw
|
||
/// @param[in] update_matrices whether to update view, proj, and norm
|
||
IGL_INLINE void draw_shadow_pass(ViewerData& data, bool update_matrices = true);
|
||
/// Render given ViewerData to a buffer. The width and height are determined by
|
||
/// non-zeros dimensions of R (and G,B,A should match) or – if both are zero —
|
||
/// are set to this core's viewport sizes.
|
||
///
|
||
/// @param[in] data which ViewerData to draw
|
||
/// @param[in] update_matrices whether to update view, proj, and norm matrices in
|
||
/// shaders
|
||
/// @param[out] R width by height red pixel color values
|
||
/// @param[out] G width by height green pixel color values
|
||
/// @param[out] B width by height blue pixel color values
|
||
/// @param[out] A width by height alpha pixel color values
|
||
///
|
||
IGL_INLINE void draw_buffer(
|
||
ViewerData& data,
|
||
bool update_matrices,
|
||
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& R,
|
||
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& G,
|
||
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& B,
|
||
Eigen::Matrix<unsigned char,Eigen::Dynamic,Eigen::Dynamic>& A);
|
||
/// Draw the text lables
|
||
/// @param[in] data which ViewerData to draw
|
||
/// @param[in] labels text labels to draw
|
||
IGL_INLINE void draw_labels(
|
||
ViewerData& data,
|
||
const igl::opengl::MeshGL::TextGL& labels
|
||
);
|
||
|
||
/// Type of user interface for changing the view rotation based on the mouse
|
||
/// draggin.
|
||
enum RotationType
|
||
{
|
||
/// Typical trackball rotation (like Meshlab)
|
||
ROTATION_TYPE_TRACKBALL = 0,
|
||
/// Fixed up rotation (like Blender, Maya, etc.)
|
||
ROTATION_TYPE_TWO_AXIS_VALUATOR_FIXED_UP = 1,
|
||
/// No rotation suitable for 2D
|
||
ROTATION_TYPE_NO_ROTATION = 2,
|
||
/// Total number of rotation types
|
||
NUM_ROTATION_TYPES = 3
|
||
};
|
||
/// Set the current rotation type
|
||
/// @param[in] value the new rotation type
|
||
IGL_INLINE void set_rotation_type(const RotationType & value);
|
||
|
||
/// Set a ViewerData visualization option for this viewport
|
||
/// @param[in] property_mask a bit mask of visualization option
|
||
/// @param[in] value whether to set or unset the property
|
||
IGL_INLINE void set(unsigned int &property_mask, bool value = true) const;
|
||
|
||
/// Unset a ViewerData visualization option for this viewport
|
||
/// @param[in] property_mask a bit mask of visualization option
|
||
IGL_INLINE void unset(unsigned int &property_mask) const;
|
||
|
||
/// Toggle a ViewerData visualization option for this viewport
|
||
/// @param[in] property_mask a bit mask of visualization option
|
||
IGL_INLINE void toggle(unsigned int &property_mask) const;
|
||
|
||
/// Check whether a ViewerData visualization option is set for this viewport
|
||
/// @param[in] property_mask a bit mask of visualization option
|
||
/// @returns whether the property is set
|
||
IGL_INLINE bool is_set(unsigned int property_mask) const;
|
||
|
||
/// delete the shadow buffers
|
||
IGL_INLINE void delete_shadow_buffers();
|
||
/// generate the shadow buffers
|
||
IGL_INLINE void generate_shadow_buffers();
|
||
|
||
// ------------------- Properties
|
||
|
||
/// Unique identifier
|
||
unsigned int id = 1u;
|
||
|
||
/// Background color as RGBA
|
||
Eigen::Vector4f background_color;
|
||
|
||
/// Light position (or direction to light)
|
||
Eigen::Vector3f light_position;
|
||
/// Whether to treat `light_position` as a point or direction
|
||
bool is_directional_light;
|
||
/// Whether shadow mapping is on
|
||
bool is_shadow_mapping;
|
||
/// Width of the shadow map
|
||
GLuint shadow_width;
|
||
/// Height of the shadow map
|
||
GLuint shadow_height;
|
||
/// Shadow map depth texture
|
||
GLuint shadow_depth_tex;
|
||
/// Shadow map depth framebuffer object
|
||
GLuint shadow_depth_fbo;
|
||
/// Shadow map color render buffer object
|
||
GLuint shadow_color_rbo;
|
||
/// Factor of lighting (0: no lighting, 1: full lighting)
|
||
float lighting_factor;
|
||
|
||
/// Type of rotation interaction
|
||
RotationType rotation_type;
|
||
/// View rotation as quaternion
|
||
Eigen::Quaternionf trackball_angle;
|
||
|
||
/// Base zoom of camera
|
||
float camera_base_zoom;
|
||
/// Current zoom of camera
|
||
float camera_zoom;
|
||
/// Whether camera is orthographic (or perspective)
|
||
bool orthographic;
|
||
/// Base translation of camera
|
||
Eigen::Vector3f camera_base_translation;
|
||
/// Current translation of camera
|
||
Eigen::Vector3f camera_translation;
|
||
/// Current "eye" / origin position of camera
|
||
Eigen::Vector3f camera_eye;
|
||
/// Current "up" vector of camera
|
||
Eigen::Vector3f camera_up;
|
||
/// Current "look at" position of camera
|
||
Eigen::Vector3f camera_center;
|
||
/// Current view angle of camera
|
||
float camera_view_angle;
|
||
/// Near plane of camera
|
||
float camera_dnear;
|
||
/// Far plane of camera
|
||
float camera_dfar;
|
||
|
||
/// Whether testing for depth is enabled
|
||
bool depth_test;
|
||
|
||
/// Whether "animating" (continuous drawing) is enabled
|
||
bool is_animating;
|
||
/// Max fps of animation loop (e.g. 30fps or 60fps)
|
||
double animation_max_fps;
|
||
|
||
/// Caches the two-norm between the min/max point of the bounding box
|
||
float object_scale;
|
||
|
||
/// Viewport size
|
||
Eigen::Vector4f viewport;
|
||
|
||
/// OpenGL view transformation matrix on last render pass
|
||
Eigen::Matrix4f view;
|
||
/// OpenGL proj transformation matrix on last render pass
|
||
Eigen::Matrix4f proj;
|
||
/// OpenGL norm transformation matrix on last render pass
|
||
Eigen::Matrix4f norm;
|
||
/// OpenGL shadow_view transformation matrix on last render pass
|
||
Eigen::Matrix4f shadow_view;
|
||
/// OpenGL shadow_proj transformation matrix on last render pass
|
||
Eigen::Matrix4f shadow_proj;
|
||
public:
|
||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
|
||
};
|
||
|
||
}
|
||
}
|
||
|
||
#include "../serialize.h"
|
||
namespace igl {
|
||
namespace serialization {
|
||
|
||
inline void serialization(bool s, igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
|
||
{
|
||
|
||
SERIALIZE_MEMBER(background_color);
|
||
|
||
SERIALIZE_MEMBER(light_position);
|
||
SERIALIZE_MEMBER(lighting_factor);
|
||
|
||
SERIALIZE_MEMBER(trackball_angle);
|
||
SERIALIZE_MEMBER(rotation_type);
|
||
|
||
SERIALIZE_MEMBER(camera_base_zoom);
|
||
SERIALIZE_MEMBER(camera_zoom);
|
||
SERIALIZE_MEMBER(orthographic);
|
||
SERIALIZE_MEMBER(camera_base_translation);
|
||
SERIALIZE_MEMBER(camera_translation);
|
||
SERIALIZE_MEMBER(camera_view_angle);
|
||
SERIALIZE_MEMBER(camera_dnear);
|
||
SERIALIZE_MEMBER(camera_dfar);
|
||
SERIALIZE_MEMBER(camera_eye);
|
||
SERIALIZE_MEMBER(camera_center);
|
||
SERIALIZE_MEMBER(camera_up);
|
||
|
||
SERIALIZE_MEMBER(depth_test);
|
||
SERIALIZE_MEMBER(is_animating);
|
||
SERIALIZE_MEMBER(animation_max_fps);
|
||
|
||
SERIALIZE_MEMBER(object_scale);
|
||
|
||
SERIALIZE_MEMBER(viewport);
|
||
SERIALIZE_MEMBER(view);
|
||
SERIALIZE_MEMBER(proj);
|
||
SERIALIZE_MEMBER(norm);
|
||
}
|
||
|
||
template<>
|
||
inline void serialize(const igl::opengl::ViewerCore& obj, std::vector<char>& buffer)
|
||
{
|
||
serialization(true, const_cast<igl::opengl::ViewerCore&>(obj), buffer);
|
||
}
|
||
|
||
template<>
|
||
inline void deserialize(igl::opengl::ViewerCore& obj, const std::vector<char>& buffer)
|
||
{
|
||
serialization(false, obj, const_cast<std::vector<char>&>(buffer));
|
||
}
|
||
}
|
||
}
|
||
|
||
#ifndef IGL_STATIC_LIBRARY
|
||
# include "ViewerCore.cpp"
|
||
#endif
|
||
|
||
#endif
|