mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-09-09 18:27:00 +00:00
Remap filament for pre-colored models (#10303)
* Add a new feature to allow users to remap filament for a pre-painted model. * Fix the color issues to support the theme * clean up code * Fix broken freetype-2.12.1.tar.gz link
This commit is contained in:
@@ -3,6 +3,8 @@
|
||||
|
||||
#include <boost/container/small_vector.hpp>
|
||||
#include <boost/log/trivial.hpp>
|
||||
#include <cstddef>
|
||||
#include <tbb/parallel_for.h>
|
||||
|
||||
#ifndef NDEBUG
|
||||
// #define EXPENSIVE_DEBUG_CHECKS
|
||||
@@ -1256,6 +1258,22 @@ void TriangleSelector::garbage_collect()
|
||||
m_free_vertices_head = -1;
|
||||
}
|
||||
|
||||
void TriangleSelector::remap_triangle_state(const EnforcerBlockerStateMap& state_map)
|
||||
{
|
||||
if (m_triangles.empty())
|
||||
return;
|
||||
|
||||
tbb::parallel_for(tbb::blocked_range<size_t>(0, m_triangles.size()), [this, &state_map](const tbb::blocked_range<size_t>& range) {
|
||||
for (size_t i = range.begin(); i != range.end(); ++i) {
|
||||
Triangle& tr = m_triangles[i];
|
||||
if (tr.valid()) {
|
||||
const auto current_state = static_cast<size_t>(tr.get_state());
|
||||
tr.set_state(state_map[current_state]);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
TriangleSelector::TriangleSelector(const TriangleMesh& mesh, float edge_limit)
|
||||
: m_mesh{mesh}, m_neighbors(its_face_neighbors(mesh.its)), m_face_normals(its_face_normals(mesh.its)), m_edge_limit(edge_limit)
|
||||
{
|
||||
|
||||
@@ -37,6 +37,9 @@ enum class EnforcerBlockerType : int8_t {
|
||||
ExtruderMax = Extruder16
|
||||
};
|
||||
|
||||
// Type alias for the state mapping array to improve code readability
|
||||
using EnforcerBlockerStateMap = std::array<EnforcerBlockerType, (size_t)EnforcerBlockerType::ExtruderMax + 1>;
|
||||
|
||||
// Following class holds information about selected triangles. It also has power
|
||||
// to recursively subdivide the triangles and make the selection finer.
|
||||
class TriangleSelector
|
||||
@@ -344,6 +347,10 @@ public:
|
||||
// Remove all unnecessary data.
|
||||
void garbage_collect();
|
||||
|
||||
// Orca: remap the state of triangles according to the state_map
|
||||
void remap_triangle_state(const EnforcerBlockerStateMap& state_map);
|
||||
|
||||
|
||||
// Store the division trees in compact form (a long stream of bits for each triangle of the original mesh).
|
||||
// First vector contains pairs of (triangle index, first bit in the second vector).
|
||||
TriangleSplittingData serialize() const;
|
||||
@@ -416,10 +423,17 @@ protected:
|
||||
// or index of a vertex shared by the two split edges (for number_of_splits == 2).
|
||||
// For number_of_splits == 3, special_side_idx is always zero.
|
||||
char special_side_idx { 0 };
|
||||
EnforcerBlockerType state;
|
||||
bool m_selected_by_seed_fill : 1;
|
||||
// Is this triangle valid or marked to be removed?
|
||||
bool m_valid : 1;
|
||||
|
||||
// Orca:
|
||||
// IMPORTANT: `state` is intentionally placed after all other small members
|
||||
// to prevent compilers from packing it in a way that would create
|
||||
// data races during parallel processing. A write to `state` could
|
||||
// otherwise become a non-atomic read-modify-write on a memory word
|
||||
// that also contains other (bit-field) members, causing race conditions.
|
||||
EnforcerBlockerType state;
|
||||
};
|
||||
|
||||
struct Vertex {
|
||||
|
||||
Reference in New Issue
Block a user