mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-23 06:01:14 -05:00
* Variable layer height on several objects, and with the prime tower on objects of different heights The variable layer height tool now opens with several objects selected. Adaptive, Smooth, Reset and manual edits apply to all of them: they share one profile, the finest layer height any of them asks for at each Z, unless "Each object separately" is ticked. Every selected object is painted with its layer heights. With a profile each, up to three objects get a bar of their own, drawn to one scale, and the bar under the mouse is the one edited. The prime tower check compares the layers objects are sliced at over the height they share, rather than the raw profiles, which never matched once the profile of a lower object ended at its own top. Precise Z height, which fits the last layers of each object to its own height, is left out of such a print, with a warning. * Check the prime tower layers on the sliced objects, and note the new strings for translators * Include what the new tests use * Compare the layers as sliced, before the prime tower is generated from them * Check that precise Z height stays on without a prime tower * Keep each object's layer height texture on the GPU, and mark only lower tops The variable layer height tool sent a 1024x1024 texture to the GPU for every selected object on every frame, and set_config(), run after every edit, dropped the other objects' textures so that each was generated again. Each other object now has a texture of its own on the GPU. It is generated and sent only when its profile, its height or the slicing parameters it shows change, which set_config() now only asks to check. The object shown sends its texture only when it is generated, and while the objects share one profile, those on its layers are drawn with its texture and need none of their own. The textures of objects no longer selected are freed. The bars and the layer height curves are built again only when what they show changes, and each bar is scaled with its own object's layer heights. A lower object's top is marked only when it is lower than the object shown, objects ending at the same height share one label, and a label stays on the canvas and below the one above it. The comment on precise_z_height_overridden() now says what the override trades: the tower can join the off-grid layers to the tower layer below, but a joined layer holds two purges, which makes the tower deeper. * Fix the precise Z warning, shared profiles across first layers and the bar clicked - The precise Z override, and its warning, now need an object with precise Z height on. Every plate with a prime tower and variable layer height on objects of different heights warned about a setting that is off by default. - The objects the override slices again get their slicing parameters back at once, since validate() reads them before slicing. - When the objects share one profile, an object that starts its layers elsewhere than the object shown, with a raft of its own say, keeps its own. The shared profile starts with the first layer of the object shown, and PrintObject::update_layer_height_profile() dropped it on such an object, which then printed at the preset layer height. - Clicking a bar edits its object, even when no frame was drawn since the mouse got there. - Select all is ignored while a profile is painted, and select all plates while the tool is open. - The bars' models are made again, not copied, when their number changes: a copy shares the GPU buffers that the original deletes. - Objects with no height above the bed are left out of the tool, and a profile fitted within EPSILON above one of its entries no longer runs past it. * Keep the object top labels below the toolbar row When the toolbar row ends next to the bar, the label of an object that ends near the top of the tallest one covered the toolbar's last buttons. Such a label now starts below the row, with its arrow pointing up to the line on the bar. * Fill the layer height texture up to the top of the object The last layer can end under the top of the object, by up to half a layer, and no layer wrote the cells there. The top face is drawn with them, so it showed what the buffer held before: black on the texture of an object made for the first time, or the colours of another object. The last layer now fills them, with the shade of its top. * Draw horizontal faces without the layer stripes A horizontal face lies at one height, so the stripes cannot show on it, only the shade they have there. That shade changed whenever a layer under it moved, and the tops flickered at every stroke. Such a face now gets the plain colour of its layer height, from the 2nd level of the texture. That level is now read at its own level of detail instead of with a bias. On a horizontal face the texture coordinates do not change, so the GPU picks the 1st level however large the bias, and read it at the coordinates of the 2nd: the tops showed black, or the colour of another height. The 110 shader does so where GL_ARB_shader_texture_lod is available, and keeps the stripes elsewhere. * Include ObjectID.hpp where ObjectWithTimestamp is used clang-tidy (misc-include-cleaner) asks for the header to be included directly. * Find the horizontal faces with the inverse transpose of the world matrix The variable layer height shader took the normals to world space with the world matrix itself, which is only right under a uniform scale. With a non-uniform scale it drew sloped faces as flat, and once the object was also rotated it missed real flat ones. The normals now go through the inverse transpose of the world matrix, which render_object_volumes() already built for the view normal matrix. * Note why the precise Z override keys on has_wipe_tower() Since #16999 the tower is printed only when slicing finds it is needed, so the override also applies on plates where no tower is printed in the end.
130 lines
6.1 KiB
C++
130 lines
6.1 KiB
C++
#include <catch2/catch_test_macros.hpp>
|
|
#include <catch2/catch_message.hpp>
|
|
#include <catch2/matchers/catch_matchers_floating_point.hpp>
|
|
#include <catch2/matchers/catch_matchers.hpp>
|
|
|
|
#include <vector>
|
|
#include <cstddef>
|
|
|
|
#include "libslic3r/Slicing.hpp"
|
|
#include "libslic3r/libslic3r.h"
|
|
|
|
using namespace Slic3r;
|
|
|
|
// Profiles are flat lists of (z, layer height) pairs.
|
|
static void check_profile(const std::vector<coordf_t> &profile, const std::vector<coordf_t> &expected)
|
|
{
|
|
REQUIRE(profile.size() == expected.size());
|
|
for (size_t i = 0; i < expected.size(); ++i) {
|
|
INFO("entry " << i);
|
|
CHECK_THAT(profile[i], Catch::Matchers::WithinAbs(expected[i], 1e-9));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("A layer height profile fitted to a lower object is cut at its top", "[Slicing]")
|
|
{
|
|
// 0.2 mm up to 5 mm, thinning to 0.1 mm at 10 mm: halfway through the ramp, 7.5 mm, is 0.15 mm.
|
|
const std::vector<coordf_t> profile = { 0., 0.2, 5., 0.2, 10., 0.1, 20., 0.1 };
|
|
check_profile(layer_height_profile_fit_to_height(profile, 7.5), { 0., 0.2, 5., 0.2, 7.5, 0.15 });
|
|
}
|
|
|
|
TEST_CASE("A layer height profile fitted just above one of its entries does not run past it", "[Slicing]")
|
|
{
|
|
// The entry at 9.99999 mm lies within EPSILON under the top, so the cut falls between it and the one
|
|
// below and must take its layer height, not run on past it to below 0.1 mm.
|
|
const std::vector<coordf_t> profile = { 0., 0.2, 9.9, 0.2, 9.99999, 0.1, 20., 0.1 };
|
|
const std::vector<coordf_t> fitted = layer_height_profile_fit_to_height(profile, 10.);
|
|
REQUIRE(fitted.size() == 6);
|
|
CHECK_THAT(fitted[4], Catch::Matchers::WithinAbs(10., 1e-12));
|
|
CHECK(fitted[5] >= 0.1);
|
|
CHECK(fitted[5] <= 0.2);
|
|
}
|
|
|
|
TEST_CASE("A layer height profile fitted to a taller object carries its last layer height up", "[Slicing]")
|
|
{
|
|
const std::vector<coordf_t> profile = { 0., 0.2, 5., 0.2, 10., 0.1 };
|
|
check_profile(layer_height_profile_fit_to_height(profile, 30.), { 0., 0.2, 5., 0.2, 10., 0.1, 30., 0.1 });
|
|
}
|
|
|
|
TEST_CASE("A layer height profile fitted to its own height is unchanged", "[Slicing]")
|
|
{
|
|
const std::vector<coordf_t> profile = { 0., 0.2, 5., 0.2, 10., 0.1 };
|
|
check_profile(layer_height_profile_fit_to_height(profile, 10.), profile);
|
|
}
|
|
|
|
TEST_CASE("Merged layer height profiles take the finest layer height up to the top of each object", "[Slicing]")
|
|
{
|
|
// A 20 mm object at a constant 0.2 mm, and a 10 mm one thinning to 0.1 mm at 5 mm. The 0.3 mm
|
|
// entry closing the lower profile is not a layer height the object asks for.
|
|
const std::vector<coordf_t> tall = { 0., 0.2, 10., 0.2, 20., 0.2 };
|
|
const std::vector<coordf_t> lower = { 0., 0.2, 5., 0.1, 10., 0.3 };
|
|
const std::vector<coordf_t> merged = layer_height_profile_merge_finest({ tall, lower });
|
|
|
|
REQUIRE(merged.size() >= 4);
|
|
REQUIRE(merged.size() % 2 == 0);
|
|
CHECK_THAT(merged[0], Catch::Matchers::WithinAbs(0., 1e-9));
|
|
CHECK_THAT(merged[1], Catch::Matchers::WithinAbs(0.2, 1e-9));
|
|
CHECK_THAT(merged[merged.size() - 2], Catch::Matchers::WithinAbs(20., 1e-9));
|
|
for (size_t i = 2; i + 2 < merged.size(); i += 2) {
|
|
INFO("entry at z = " << merged[i]);
|
|
// One entry per layer: each starts where the layer before it ended.
|
|
if (i + 4 < merged.size())
|
|
CHECK_THAT(merged[i + 2], Catch::Matchers::WithinAbs(merged[i] + merged[i + 1], 1e-9));
|
|
if (merged[i] < 5.)
|
|
// Thinning with the lower object: 0.2 mm at the bed, 0.1 mm at 5 mm.
|
|
CHECK_THAT(merged[i + 1], Catch::Matchers::WithinAbs(0.2 - 0.02 * merged[i], 1e-9));
|
|
else if (merged[i] < 10.)
|
|
CHECK_THAT(merged[i + 1], Catch::Matchers::WithinAbs(0.1, 1e-9));
|
|
else {
|
|
// Above the lower object the layers grow back to the 0.2 mm of the tall one, by no
|
|
// more than the 0.04 mm the adaptive profile allows from one layer to the next.
|
|
CHECK(merged[i + 1] <= 0.2 + 1e-9);
|
|
CHECK(merged[i + 1] - merged[i - 1] <= 0.04 + 1e-9);
|
|
}
|
|
if (merged[i] > 11.)
|
|
CHECK_THAT(merged[i + 1], Catch::Matchers::WithinAbs(0.2, 1e-9));
|
|
}
|
|
}
|
|
|
|
TEST_CASE("The layer height texture is filled up to the top of an object whose last layer ends under it", "[Slicing]")
|
|
{
|
|
// A 10 mm object with 0.15 mm layers: the last one ends at 9.9 mm, as generate_object_layers() leaves it
|
|
// when one more layer would end too far above the top. The top face is drawn with the cells above 9.9 mm.
|
|
SlicingParameters params;
|
|
params.object_print_z_min = 0.;
|
|
params.object_print_z_max = 10.;
|
|
params.layer_height = 0.2;
|
|
params.min_layer_height = 0.07;
|
|
params.max_layer_height = 0.28;
|
|
std::vector<coordf_t> layers;
|
|
for (int i = 0; i < 66; ++i) {
|
|
layers.push_back(0.15 * i);
|
|
layers.push_back(0.15 * (i + 1));
|
|
}
|
|
REQUIRE_THAT(layers.back(), Catch::Matchers::WithinAbs(9.9, 1e-9));
|
|
|
|
// The buffer starts out black and transparent, as the texture of an object is made the first time.
|
|
const int rows = 256;
|
|
const int cols = 256;
|
|
std::vector<unsigned char> data(size_t(rows) * size_t(cols) * 5, 0);
|
|
const int ncells = generate_layer_height_texture(params, layers, data.data(), rows, cols, true);
|
|
REQUIRE(ncells > 0);
|
|
// Each cell, up to the last, is written: opaque.
|
|
for (int cell = 0; cell < ncells; ++cell) {
|
|
const int row = cell / (cols - 1);
|
|
const int col = cell - row * (cols - 1);
|
|
INFO("cell " << cell << " of " << ncells);
|
|
CHECK(int(data[(size_t(row) * cols + col) * 4 + 3]) == 255);
|
|
}
|
|
// And so in the second level of detail, half as many cells in a texture half as wide.
|
|
const unsigned char *data1 = data.data() + size_t(rows) * cols * 4;
|
|
const int cols1 = cols / 2;
|
|
const int ncells1 = ncells / 2;
|
|
for (int cell = 0; cell < ncells1; ++cell) {
|
|
const int row = cell / (cols1 - 1);
|
|
const int col = cell - row * (cols1 - 1);
|
|
INFO("second level cell " << cell << " of " << ncells1);
|
|
CHECK(int(data1[(size_t(row) * cols1 + col) * 4 + 3]) == 255);
|
|
}
|
|
}
|