31 [&](
const int curve_i) {
32 const IndexRange src_points = src_points_by_curve[curve_i];
33 const IndexRange dst_points = dst_points_by_curve[curve_i];
38 src.
slice(src_points),
39 dst.
slice(dst_points));
56 [&](
const int curve_i) {
57 const IndexRange src_points = src_points_by_curve[curve_i];
65 for (
int &count : point_counts) {
68 count = std::max(count, 0) + 1;
70 if (!cyclic[curve_i]) {
72 point_counts.
first() = 1;
73 point_counts.
last() = 1;
78 if (radii[src_points[i]] == 0.0f) {
86 dst_curve_offsets[curve_i] = point_offsets.
last();
119 const int i_prev = i == 0 ? i_last : i - 1;
120 if (angles[i] >= std::numbers::pi_v<float> ||
math::is_zero(directions[i_prev]) ||
135 const float3 &position_next,
136 const float angle_prev,
138 const float angle_next,
139 const float radius_prev,
141 const float radius_next)
143 const float displacement = radius * std::tan(
angle / 2.0f);
145 const float displacement_prev = radius_prev * std::tan(angle_prev / 2.0f);
147 const float total_displacement_prev = displacement_prev + displacement;
148 const float factor_prev = std::clamp(
151 const float displacement_next = radius_next * std::tan(angle_next / 2.0f);
153 const float total_displacement_next = displacement_next + displacement;
154 const float factor_next = std::clamp(
157 return radius * std::min(factor_prev, factor_next);
179 const int i_prev = i - 1;
180 const int i_next = i + 1;
205 radii_clamped.
first() = 0.0f;
208 const int i_prev = i - 1;
209 const int i_next = i + 1;
212 const float radius_prev = i_prev == 0 ? 0.0f : radii[i_prev];
213 const float radius_next = i_next == i_last ? 0.0f : radii[i_next];
225 radii_clamped.
last() = 0.0f;
238 for (const int i_src : range) {
239 const IndexRange arc = dst_offsets[i_src];
240 const float3 &src = src_positions[i_src];
241 if (arc.size() == 1) {
242 dst[arc.first()] = src;
246 const int i_src_prev = i_src == 0 ? i_src_last : i_src - 1;
247 const float angle = angles[i_src];
248 const float radius = radii[i_src];
249 const float displacement = radius * std::tan(angle / 2.0f);
250 const float3 prev_dir = -directions[i_src_prev];
251 const float3 &next_dir = directions[i_src];
252 const float3 arc_start = src + prev_dir * displacement;
253 const float3 arc_end = src + next_dir * displacement;
255 dst[arc.first()] = arc_start;
256 dst[arc.last()] = arc_end;
258 const IndexRange middle = arc.drop_front(1).drop_back(1);
259 if (middle.is_empty()) {
263 const float3 axis = -math::normalize(math::cross(prev_dir, next_dir));
264 const float3 center_direction = math::normalize(math::midpoint(next_dir, prev_dir));
265 const float distance_to_center = std::sqrt(pow2f(radius) + pow2f(displacement));
266 const float3 center = src + center_direction * distance_to_center;
269 const float segment_angle = angle / (middle.size() + 1);
270 for (const int i : IndexRange(middle.size())) {
271 const int point_i = middle[i];
272 dst[point_i] = math::rotate_around_axis(arc_start, center, axis, segment_angle * (i + 1));
285 const float3 &other_handle)
292 if (
math::dot(handle_offset, other_direction) >= 0.0f) {
300 constexpr double unit_roundoff =
FLT_EPSILON / 2.0;
301 constexpr double relative_error = 12 * unit_roundoff / (1 - 12 * unit_roundoff);
305 const double rounding_bound = relative_error *
length +
306 unit_roundoff * (std::abs(
double(
position[axis])) +
307 std::abs(
double(handle[axis])));
308 if (std::abs(
double(aligned_handle[axis]) - handle[axis]) > rounding_bound) {
337 for (const int i_src : range) {
338 const IndexRange arc = dst_offsets[i_src];
339 if (arc.size() == 1) {
340 dst_handles_l[arc.first()] = src_handles_l[i_src];
341 dst_handles_r[arc.first()] = src_handles_r[i_src];
342 dst_types_l[arc.first()] = src_types_l[i_src];
343 dst_types_r[arc.first()] = src_types_r[i_src];
346 BLI_assert(arc.size() == 2);
347 const int i_dst_a = arc.first();
348 const int i_dst_b = arc.last();
350 const int i_src_prev = i_src == 0 ? i_src_last : i_src - 1;
351 const float angle = angles[i_src];
352 const float radius = radii[i_src];
353 const float3 prev_dir = -directions[i_src_prev];
354 const float3 &next_dir = directions[i_src];
356 const float3 &arc_start = dst_positions[arc.first()];
357 const float3 &arc_end = dst_positions[arc.last()];
361 const int i_dst_prev = i_dst_a == 0 ? i_dst_last : i_dst_a - 1;
362 const int i_dst_next = i_dst_b == i_dst_last ? 0 : i_dst_b + 1;
363 dst_handles_l[i_dst_a] = bke::curves::bezier::calculate_vector_handle(
364 dst_positions[i_dst_a], dst_positions[i_dst_prev]);
365 dst_handles_r[i_dst_b] = bke::curves::bezier::calculate_vector_handle(
366 dst_positions[i_dst_b], dst_positions[i_dst_next]);
367 dst_types_l[i_dst_a] = BEZIER_HANDLE_VECTOR;
368 dst_types_r[i_dst_b] = BEZIER_HANDLE_VECTOR;
372 const float handle_length = (4.0f / 3.0f) * radius * std::tan(angle / 4.0f);
373 dst_handles_r[i_dst_a] = arc_start - prev_dir * handle_length;
374 dst_handles_l[i_dst_b] = arc_end - next_dir * handle_length;
375 dst_types_r[i_dst_a] = fillet_handle_type(
376 arc_start, dst_handles_r[i_dst_a], dst_handles_l[i_dst_a]);
377 dst_types_l[i_dst_b] = fillet_handle_type(
378 arc_end, dst_handles_l[i_dst_b], dst_handles_r[i_dst_b]);
400 for (const int i_src : range) {
401 const IndexRange arc = dst_offsets[i_src];
402 if (arc.size() == 1) {
403 dst_handles_l[arc.first()] = src_handles_l[i_src];
404 dst_handles_r[arc.first()] = src_handles_r[i_src];
405 dst_types_l[arc.first()] = src_types_l[i_src];
406 dst_types_r[arc.first()] = src_types_r[i_src];
411 dst_types_l.slice(arc).fill(BEZIER_HANDLE_VECTOR);
412 dst_types_r.slice(arc).fill(BEZIER_HANDLE_VECTOR);
417 const int i_dst_prev = arc.first() == 0 ? i_dst_last : arc.one_before_start();
418 const int i_dst_next = arc.last() == i_dst_last ? 0 : arc.one_after_last();
419 dst_handles_l[arc.first()] = bke::curves::bezier::calculate_vector_handle(
420 dst_positions[arc.first()], dst_positions[i_dst_prev]);
421 dst_handles_r[arc.last()] = bke::curves::bezier::calculate_vector_handle(
422 dst_positions[arc.last()], dst_positions[i_dst_next]);
425 const IndexRange middle = arc.drop_front(1).drop_back(1);
426 for (const int i : middle) {
427 dst_handles_r[i] = bke::curves::bezier::calculate_vector_handle(dst_positions[i],
428 dst_positions[i - 1]);
429 dst_handles_l[i] = bke::curves::bezier::calculate_vector_handle(dst_positions[i],
430 dst_positions[i + 1]);
441 const bool use_bezier_mode,
500 for (
const int curve_i : segment) {
501 const IndexRange src_points = src_points_by_curve[curve_i];
505 const IndexRange dst_points = dst_points_by_curve[curve_i];
519 limit_radii(src_positions, angles, input_radii_buffer, cyclic[curve_i], radii);
531 dst_positions.
slice(dst_points));
534 if (use_bezier_mode) {
536 src_handles_r.
slice(src_points),
537 src_types_l.
slice(src_points),
538 src_types_r.
slice(src_points),
543 dst_positions.
slice(dst_points),
544 dst_handles_l.
slice(dst_points),
545 dst_handles_r.
slice(dst_points),
546 dst_types_l.
slice(dst_points),
547 dst_types_r.
slice(dst_points));
551 src_handles_r.
slice(src_points),
552 src_types_l.
slice(src_points),
553 src_types_r.
slice(src_points),
555 dst_positions.
slice(dst_points),
556 dst_handles_l.
slice(dst_points),
557 dst_handles_r.
slice(dst_points),
558 dst_types_l.
slice(dst_points),
559 dst_types_r.
slice(dst_points));
610 src_curves, curve_selection, radius, count,
limit_radius,
false, attribute_filter);
Low-level operations for curves.
Low-level operations for curves.
SIMD_FORCE_INLINE btScalar angle(const btVector3 &v) const
Return the angle between this and another vector.
Span< T > as_span() const
void reinitialize(const int64_t new_size)
GMutableSpan slice(const int64_t start, int64_t size) const
GSpan slice(const int64_t start, int64_t size) const
constexpr IndexRange drop_back(int64_t n) const
constexpr int64_t last(const int64_t n=0) const
constexpr int64_t size() const
constexpr IndexRange()=default
constexpr IndexRange drop_front(int64_t n) const
constexpr MutableSpan slice(const int64_t start, const int64_t size) const
constexpr MutableSpan drop_back(const int64_t n) const
constexpr T & first() const
constexpr IndexRange index_range() const
constexpr T & last(const int64_t n=0) const
constexpr Span slice(int64_t start, int64_t size) const
constexpr const T & first() const
constexpr const T & last(const int64_t n=0) const
constexpr IndexRange index_range() const
void materialize_compressed(const IndexMask &mask, MutableSpan< T > r_span) const
static VArray from_single(T value, const int64_t size)
MutableSpan< int8_t > handle_types_left_for_write()
void calculate_bezier_auto_handles()
MutableSpan< float3 > positions_for_write()
MutableSpan< int8_t > handle_types_right_for_write()
std::optional< Span< float3 > > handle_positions_right() const
void resize(int points_num, int curves_num)
VArray< bool > cyclic() const
AttributeAccessor attributes() const
Span< float3 > positions() const
MutableSpan< float3 > handle_positions_right_for_write()
bool nurbs_has_custom_knots() const
std::optional< Span< float3 > > handle_positions_left() const
IndexRange curves_range() const
VArray< int8_t > handle_types_left() const
MutableSpan< float3 > handle_positions_left_for_write()
Span< int > offsets() const
bool has_curve_with_type(CurveType type) const
MutableSpan< int > offsets_for_write()
VArray< int8_t > handle_types_right() const
OffsetIndices< int > points_by_curve() const
MutableAttributeAccessor attributes_for_write()
constexpr Span slice(int64_t start, int64_t size) const
void foreach_segment(Fn &&fn, Mode mode=exec_mode::serial) const
void foreach_index(Fn &&fn, Mode mode=exec_mode::serial) const
IndexMask complement(const IndexMask &universe, LinearAllocator<> &memory) const
float length(VecOp< float, D >) RET
void gather_to_groups(OffsetIndices< int > dst_offsets, const IndexMask &src_selection, GSpan src, GMutableSpan dst)
void update_custom_knot_modes(const IndexMask &mask, const KnotsMode mode_for_regular, const KnotsMode mode_for_cyclic, bke::CurvesGeometry &curves)
bke::CurvesGeometry copy_only_curve_domain(const bke::CurvesGeometry &src_curves)
IndexRange per_curve_point_offsets_range(const IndexRange points, const int curve_index)
auto attribute_filter_with_skip_ref(const AttributeFilter &filter, const Span< StringRef > skip)
Vector< AttributeTransferData > retrieve_attributes_for_transfer(const AttributeAccessor src_attributes, MutableAttributeAccessor dst_attributes, Span< AttrDomain > domains, const AttributeFilter &attribute_filter={})
void copy_attributes_group_to_group(AttributeAccessor src_attributes, AttrDomain src_domain, AttrDomain dst_domain, const AttributeFilter &attribute_filter, OffsetIndices< int > src_offsets, OffsetIndices< int > dst_offsets, const IndexMask &selection, MutableAttributeAccessor dst_attributes)
constexpr ParallelGrainSize grain_size(int grain_size)
static void calculate_bezier_handles_poly_mode(const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const OffsetIndices< int > dst_offsets, const Span< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
bke::CurvesGeometry fillet_curves_bezier(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, bool limit_radius, const bke::AttributeFilter &attribute_filter)
static void calculate_result_offsets(const OffsetIndices< int > src_points_by_curve, const IndexMask &selection, const IndexMask &unselected, const VArray< float > &radii, const VArray< int > &counts, const Span< bool > cyclic, MutableSpan< int > dst_curve_offsets, MutableSpan< int > dst_point_offsets)
static HandleType fillet_handle_type(const float3 &position, const float3 &handle, const float3 &other_handle)
static void limit_radii(const Span< float3 > positions, const Span< float > angles, const Span< float > radii, const bool cyclic, MutableSpan< float > radii_clamped)
static void calculate_angles(const Span< float3 > directions, MutableSpan< float > angles)
static float limit_radius(const float3 &position_prev, const float3 &position, const float3 &position_next, const float angle_prev, const float angle, const float angle_next, const float radius_prev, const float radius, const float radius_next)
bke::CurvesGeometry fillet_curves_poly(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius, const VArray< int > &counts, bool limit_radius, const bke::AttributeFilter &attribute_filter)
static void calculate_fillet_positions(const Span< float3 > src_positions, const Span< float > angles, const Span< float > radii, const Span< float3 > directions, const OffsetIndices< int > dst_offsets, MutableSpan< float3 > dst)
static bke::CurvesGeometry fillet_curves(const bke::CurvesGeometry &src_curves, const IndexMask &curve_selection, const VArray< float > &radius_input, const VArray< int > &counts, const bool limit_radius, const bool use_bezier_mode, const bke::AttributeFilter &attribute_filter)
static void calculate_directions(const Span< float3 > positions, MutableSpan< float3 > directions)
static void zero_degenerate_radii(const Span< float3 > directions, const Span< float > angles, MutableSpan< float > radii)
static void calculate_bezier_handles_bezier_mode(const Span< float3 > src_handles_l, const Span< float3 > src_handles_r, const Span< int8_t > src_types_l, const Span< int8_t > src_types_r, const Span< float > angles, const Span< float > radii, const Span< float3 > directions, const OffsetIndices< int > dst_offsets, const Span< float3 > dst_positions, MutableSpan< float3 > dst_handles_l, MutableSpan< float3 > dst_handles_r, MutableSpan< int8_t > dst_types_l, MutableSpan< int8_t > dst_types_r)
static void duplicate_fillet_point_data(const OffsetIndices< int > src_points_by_curve, const OffsetIndices< int > dst_points_by_curve, const IndexMask &curve_selection, const Span< int > all_point_offsets, const GSpan src, GMutableSpan dst)
T safe_divide(const T &a, const T &b)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
void copy_group_sizes(OffsetIndices< int > offsets, const IndexMask &mask, MutableSpan< int > sizes)
OffsetIndices< int > accumulate_counts_to_offsets(MutableSpan< int > counts_to_offsets, int start_offset=0)
void parallel_for(const IndexRange range, const int64_t grain_size, const Function &function, const TaskSizeHints &size_hints=detail::TaskSizeHints_Static(1))
void devirtualize_varray(const VArray< T > &varray, const Func &func, bool enable=true)
float angle_v3v3(const float a[3], const float b[3]) ATTR_WARN_UNUSED_RESULT
VecBase< float, 3 > float3