mirror of
https://github.com/OrcaSlicer/OrcaSlicer.git
synced 2026-11-24 06:20:30 -05:00
The slicing frame of a belt object started at its lowest vertex, but the belt under the leading end of an overhang lies below that, by the overhang's length times the tilt's shear. Every support generator works in layers at z >= 0, so none of them could reach it: normal supports stopped at the object's own lowest layer, and the two tree generators each carried a stack of hacks to extend themselves below it (a post-hoc copy of the lowest base area in TreeSupport, "virtual belt raft layers" in TreeSupport3D/TreeModelVolumes), sized from the pre-rotation bbox and capped at global z = 0, which is only right for the trailing half of the belt. Start the frame at the lowest belt-floor point under the footprint instead, less a 10 mm margin along the belt for the base of a support column (BeltSliceStrategy::apply_preslice_transforms and BeltTransformPipeline::compute_belt_height_and_floor agree on it). The layers between it and the first vertex come out empty, which belt slicing already tolerates, and the generators need no extension at all: - normal supports: the generator anchors its layer grid at the frame origin, so run it in the object frame and shift the global belt Z offset onto the result afterwards, as organic supports already did. With the offset on the object layers a top contact at negative z turned the intermediate-layer count negative and the generator allocated layers until the kernel killed it (any overhang in the leading half of the belt). Drop the first-layer flange expansion on a belt: the first support layer is the leading tip of the support, not a flange, and inflating it put lines in the air ahead of the belt. - classic tree: a node now keeps dropping until its whole circle is in the belt, so the branch tapers to a tip on the belt instead of stopping, a radius above it, when its centre crosses. - organic: the belt is no longer a support blocker. A blocker is a collision, and a branch descending onto one slides off it, down the tilted belt and ahead of the part; the belt is where branches end, which the per-layer m_belt_floor clipping already does. The belt brim is generated after the parallel support step instead of inside it: belt_brim_obstacles() reads every object's layers and support layers, which another object's support step rebuilds (and, now, shifts) at the same time. This is the race behind the Windows arm64 segfault in "Belt brim of each object precedes its perimeters on its own filament". Also: the belt tilt axis moves to Developer mode as its own row (a shared line is shown by its first option's mode), first_layer_plane band thickness, belt_support_floor_mode, belt_preslice_global and gcode_back_transform are retired and presumed on, the gravity arrow is a plain line along the up direction, and the "Show raw G-code (belt only)" preview toggle is gone. Regression test: "Belt supports reach the belt under a leading overhang" slices a cube with a fin whose underside is parallel to the layers, 20 mm ahead of the cube and up to 41 mm of slicing Z above the belt, for normal, organic and classic tree supports, and checks that the lowest support layer sits on the belt beneath its own lines. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
180 lines
7.0 KiB
C++
180 lines
7.0 KiB
C++
#include "BeltTransform.hpp"
|
||
#include "Model.hpp"
|
||
#include "BoundingBox.hpp"
|
||
#include "Config.hpp"
|
||
#include "Geometry.hpp"
|
||
#include "Point.hpp"
|
||
#include "PrintConfig.hpp"
|
||
#include "libslic3r.h"
|
||
|
||
#include <limits>
|
||
#include <algorithm>
|
||
#include <cmath>
|
||
#include <cstdlib>
|
||
|
||
namespace Slic3r {
|
||
|
||
// ---- Matrix builders ------------------------------------------------------
|
||
|
||
Matrix3d BeltTransformPipeline::build_rotation_matrix(const PrintConfig &config, bool *has_rot_out)
|
||
{
|
||
BeltRotationAxis axis = config.belt_slice_rotation.value;
|
||
double angle_deg = config.belt_slice_rotation_angle.value;
|
||
bool active = axis != BeltRotationAxis::None && std::abs(angle_deg) > EPSILON;
|
||
if (has_rot_out) *has_rot_out = active;
|
||
if (!active)
|
||
return Matrix3d::Identity();
|
||
double angle_rad = Geometry::deg2rad(angle_deg);
|
||
Vec3d unit_axis;
|
||
switch (axis) {
|
||
case BeltRotationAxis::X: unit_axis = Vec3d::UnitX(); break;
|
||
case BeltRotationAxis::Y: unit_axis = Vec3d::UnitY(); break;
|
||
case BeltRotationAxis::Z: unit_axis = Vec3d::UnitZ(); break;
|
||
default: return Matrix3d::Identity();
|
||
}
|
||
return Eigen::AngleAxisd(angle_rad, unit_axis).toRotationMatrix();
|
||
}
|
||
|
||
Transform3d BeltTransformPipeline::build_forward_transform(const PrintConfig &config)
|
||
{
|
||
// Mesh-side belt transform: the rotation. (Shear & scale are a g-code-side
|
||
// stage, not part of the mesh transform.)
|
||
Transform3d combined = Transform3d::Identity();
|
||
combined.linear() = build_rotation_matrix(config);
|
||
return combined;
|
||
}
|
||
|
||
// ---- Belt floor parameters ------------------------------------------------
|
||
|
||
// Shared implementation for both PrintConfig and DynamicPrintConfig.
|
||
// Template avoids duplicating the math for the two config types.
|
||
namespace {
|
||
|
||
// Belt floor in the rotated slicer frame: the image of z_machine = 0 under R.
|
||
// R(+α, X): point (·, y, 0) → (·, cos α · y, sin α · y) ⇒ z = tan(α) · y_s
|
||
// R(+α, Y): point (x, ·, 0) → (cos α · x, ·, -sin α · x) ⇒ z = -tan(α) · x_s
|
||
// R(+α, Z): point (·, ·, 0) → (·, ·, 0); no tilt → no floor
|
||
void belt_floor_shear(BeltRotationAxis rot_axis, double angle_rad, BeltTransformPipeline::BeltFloorParams &out)
|
||
{
|
||
double sin_a = std::sin(angle_rad), cos_a = std::cos(angle_rad);
|
||
switch (rot_axis) {
|
||
case BeltRotationAxis::X:
|
||
out.shear_factor = (std::abs(cos_a) > EPSILON) ? sin_a / cos_a : 0.;
|
||
out.from_axis = 1; // Y
|
||
break;
|
||
case BeltRotationAxis::Y:
|
||
out.shear_factor = (std::abs(cos_a) > EPSILON) ? -sin_a / cos_a : 0.;
|
||
out.from_axis = 0; // X
|
||
break;
|
||
case BeltRotationAxis::Z:
|
||
default:
|
||
out.shear_factor = 0.0;
|
||
out.from_axis = 1;
|
||
break;
|
||
}
|
||
}
|
||
|
||
// Z of the belt floor directly under a point of the rotated (unshifted) frame.
|
||
inline double belt_floor_z(const BeltTransformPipeline::BeltFloorParams &fp, const Vec3d &pt)
|
||
{
|
||
return fp.shear_factor * (fp.from_axis == 0 ? pt.x() : pt.y());
|
||
}
|
||
|
||
|
||
template<typename Config>
|
||
BeltTransformPipeline::BeltHeightResult compute_belt_height_and_floor_impl(
|
||
const Config &config, const BoundingBoxf3 &bb, double original_height)
|
||
{
|
||
BeltTransformPipeline::BeltHeightResult result;
|
||
result.object_height = original_height;
|
||
|
||
// Extract the mesh rotation from config (the sole mesh-side belt transform).
|
||
BeltRotationAxis rot_axis;
|
||
double rot_angle;
|
||
|
||
if constexpr (std::is_same_v<Config, PrintConfig>) {
|
||
rot_axis = config.belt_slice_rotation.value;
|
||
rot_angle = config.belt_slice_rotation_angle.value;
|
||
} else {
|
||
// DynamicPrintConfig path
|
||
auto get_float = [&](const char *key) {
|
||
auto *opt = config.template option<ConfigOptionFloat>(key);
|
||
return opt ? opt->value : 0.0;
|
||
};
|
||
auto get_rot_axis = [&](const char *key) {
|
||
auto *opt = config.template option<ConfigOptionEnum<BeltRotationAxis>>(key);
|
||
return opt ? opt->value : BeltRotationAxis::None;
|
||
};
|
||
rot_axis = get_rot_axis("belt_slice_rotation");
|
||
rot_angle = get_float("belt_slice_rotation_angle");
|
||
}
|
||
|
||
bool has_rotation = rot_axis != BeltRotationAxis::None && std::abs(rot_angle) > EPSILON;
|
||
if (!has_rotation)
|
||
return result;
|
||
|
||
// Rotation path: sweep the 8 bbox corners through R to get the rotated height,
|
||
// then derive the belt floor (the image of machine-Z = 0 under R).
|
||
double angle_rad = Geometry::deg2rad(rot_angle);
|
||
Vec3d unit_axis;
|
||
switch (rot_axis) {
|
||
case BeltRotationAxis::X: unit_axis = Vec3d::UnitX(); break;
|
||
case BeltRotationAxis::Y: unit_axis = Vec3d::UnitY(); break;
|
||
case BeltRotationAxis::Z: unit_axis = Vec3d::UnitZ(); break;
|
||
default: unit_axis = Vec3d::UnitX(); break;
|
||
}
|
||
Matrix3d R = Eigen::AngleAxisd(angle_rad, unit_axis).toRotationMatrix();
|
||
belt_floor_shear(rot_axis, angle_rad, result.floor_params);
|
||
// The slicing frame starts at the lowest point of the support region: the
|
||
// lowest belt-floor point under the footprint, not the lowest vertex. The
|
||
// belt under the leading end of an overhang lies below every vertex of the
|
||
// part, and supports have to be able to reach it (see
|
||
// BeltSliceStrategy::apply_preslice_transforms for the exact vertex-scan
|
||
// counterpart of this bbox estimate).
|
||
double min_rz = std::numeric_limits<double>::max();
|
||
double max_rz = std::numeric_limits<double>::lowest();
|
||
for (int i = 0; i < 8; ++i) {
|
||
Vec3d c((i & 1) ? bb.max.x() : bb.min.x(),
|
||
(i & 2) ? bb.max.y() : bb.min.y(),
|
||
(i & 4) ? bb.max.z() : bb.min.z());
|
||
Vec3d rc = R * c;
|
||
double z = rc.z();
|
||
min_rz = std::min(min_rz, z);
|
||
max_rz = std::max(max_rz, z);
|
||
min_rz = std::min(min_rz, belt_floor_z(result.floor_params, rc));
|
||
}
|
||
min_rz -= BeltTransformPipeline::frame_margin(result.floor_params);
|
||
result.object_height = max_rz - min_rz;
|
||
|
||
result.floor_params.z_shift = bb.min.z() + ((min_rz < 0.) ? -min_rz : 0.);
|
||
|
||
return result;
|
||
}
|
||
|
||
} // anonymous namespace
|
||
|
||
BeltTransformPipeline::BeltHeightResult BeltTransformPipeline::compute_belt_height_and_floor(
|
||
const PrintConfig &config, const BoundingBoxf3 &bbox, double original_height)
|
||
{
|
||
return compute_belt_height_and_floor_impl(config, bbox, original_height);
|
||
}
|
||
|
||
BeltTransformPipeline::BeltHeightResult BeltTransformPipeline::compute_belt_height_and_floor(
|
||
const DynamicPrintConfig &config, const BoundingBoxf3 &bbox, double original_height)
|
||
{
|
||
return compute_belt_height_and_floor_impl(config, bbox, original_height);
|
||
}
|
||
|
||
bool BeltTransformPipeline::floor_shear(const PrintConfig &config, BeltFloorParams &out)
|
||
{
|
||
out = BeltFloorParams{};
|
||
const BeltRotationAxis rot_axis = config.belt_slice_rotation.value;
|
||
const double rot_angle = config.belt_slice_rotation_angle.value;
|
||
if (rot_axis == BeltRotationAxis::None || std::abs(rot_angle) <= EPSILON)
|
||
return false;
|
||
belt_floor_shear(rot_axis, Geometry::deg2rad(rot_angle), out);
|
||
return std::abs(out.shear_factor) > EPSILON;
|
||
}
|
||
|
||
} // namespace Slic3r
|