Changeset View
Changeset View
Standalone View
Standalone View
source/blender/blenkernel/intern/spline_bezier.cc
| Show First 20 Lines • Show All 327 Lines • ▼ Show 20 Lines | void BezierSpline::correct_end_tangents() const | ||||
| if (handle_positions_right_.first() != positions_.first()) { | if (handle_positions_right_.first() != positions_.first()) { | ||||
| tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); | tangents.first() = (handle_positions_right_.first() - positions_.first()).normalized(); | ||||
| } | } | ||||
| if (handle_positions_left_.last() != positions_.last()) { | if (handle_positions_left_.last() != positions_.last()) { | ||||
| tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); | tangents.last() = (positions_.last() - handle_positions_left_.last()).normalized(); | ||||
| } | } | ||||
| } | } | ||||
| /** | |||||
| * De Casteljau Bezier subdivision. | |||||
| * \param index: The index of the segment's start control point. | |||||
| * \param next_index: The index of the control point at the end of the segment. Could be 0, | |||||
| * if the spline is cyclic. | |||||
| * \param parameter: The factor along the segment, between 0 and 1. Note that this is used | |||||
| * directly by the calculation, it doesn't correspond to a portion of the evaluated length. | |||||
| * | |||||
| * <pre> | |||||
| * handle_prev handle_next | |||||
| * x----------------x | |||||
| * / \ | |||||
| * / x---O---x \ | |||||
| * / result \ | |||||
| * / \ | |||||
| * O O | |||||
| * point_prev point_next | |||||
| * </pre> | |||||
| */ | |||||
| BezierSpline::InsertResult BezierSpline::calculate_segment_insertion(const int index, | |||||
| const int next_index, | |||||
| const float parameter) | |||||
| { | |||||
| BLI_assert(parameter <= 1.0f && parameter >= 0.0f); | |||||
| BLI_assert(next_index == 0 || next_index == index + 1); | |||||
| const float3 &point_prev = positions_[index]; | |||||
| const float3 &handle_prev = handle_positions_right_[index]; | |||||
| const float3 &handle_next = handle_positions_left_[next_index]; | |||||
| const float3 &point_next = positions_[next_index]; | |||||
| const float3 center_point = float3::interpolate(handle_prev, handle_next, parameter); | |||||
| BezierSpline::InsertResult result; | |||||
| result.handle_prev = float3::interpolate(point_prev, handle_prev, parameter); | |||||
| result.handle_next = float3::interpolate(handle_next, point_next, parameter); | |||||
| result.left_handle = float3::interpolate(result.handle_prev, center_point, parameter); | |||||
| result.right_handle = float3::interpolate(center_point, result.handle_next, parameter); | |||||
| result.position = float3::interpolate(result.left_handle, result.right_handle, parameter); | |||||
| return result; | |||||
| } | |||||
| static void bezier_forward_difference_3d(const float3 &point_0, | static void bezier_forward_difference_3d(const float3 &point_0, | ||||
| const float3 &point_1, | const float3 &point_1, | ||||
| const float3 &point_2, | const float3 &point_2, | ||||
| const float3 &point_3, | const float3 &point_3, | ||||
| MutableSpan<float3> result) | MutableSpan<float3> result) | ||||
| { | { | ||||
| BLI_assert(result.size() > 0); | BLI_assert(result.size() > 0); | ||||
| const float inv_len = 1.0f / static_cast<float>(result.size()); | const float inv_len = 1.0f / static_cast<float>(result.size()); | ||||
| ▲ Show 20 Lines • Show All 256 Lines • Show Last 20 Lines | |||||