71 const float surface_collision_distance)
77 const int max_collisions = 5;
80 for (
const int curve_i : segment) {
81 const IndexRange points = points_by_curve[curve_i];
85 bool revert_curve =
false;
86 for (
const int point_i : points.
drop_front(1)) {
87 const float goal_segment_length_cu = segment_lengths_cu[point_i - 1];
88 const float3 &prev_pos_cu = positions_cu[point_i - 1];
89 const float3 &start_pos_cu = start_positions_cu[point_i];
91 int used_iterations = 0;
92 for ([[maybe_unused]]
const int iteration :
IndexRange(max_collisions)) {
94 const float3 &old_pos_cu = positions_cu[point_i];
95 if (start_pos_cu == old_pos_cu) {
105 const float3 pos_diff_su = old_pos_su - start_pos_su;
106 float max_ray_length_su;
111 hit.
dist = max_ray_length_su + surface_collision_distance;
115 surface_collision_distance,
119 if (hit.
index == -1) {
123 const float3 hit_normal_su = hit.
no;
124 if (
math::dot(hit_normal_su, ray_direction_su) > 0.0f) {
138 const float3 plane_pos_cu = hit_pos_cu + hit_normal_cu * surface_collision_distance;
139 const float3 plane_normal_cu = hit_normal_cu;
143 const float3 collided_segment_cu = plane_pos_cu - prev_pos_cu;
144 const float3 slide_normal_cu = plane_normal_cu *
145 math::dot(collided_segment_cu, plane_normal_cu);
146 const float3 slide_direction_cu = collided_segment_cu - slide_normal_cu;
148 float slide_direction_length_cu;
150 slide_direction_cu, slide_direction_length_cu);
153 if (
pow2f(goal_segment_length_cu) > slide_normal_length_sq_cu) {
155 const float slide_distance_cu = std::sqrt(
pow2f(goal_segment_length_cu) -
156 slide_normal_length_sq_cu) -
157 slide_direction_length_cu;
158 positions_cu[point_i] = plane_pos_cu +
159 normalized_slide_direction_cu * slide_distance_cu;
164 positions_cu[point_i] = prev_pos_cu +
math::normalize(old_pos_su - prev_pos_cu) *
165 goal_segment_length_cu;
168 if (used_iterations == max_collisions) {
int BLI_bvhtree_ray_cast(const BVHTree *tree, const float co[3], const float dir[3], float radius, BVHTreeRayHit *hit, BVHTree_RayCastCallback callback, void *userdata)
void solve_length_and_collision_constraints(OffsetIndices< int > points_by_curve, const IndexMask &curve_selection, Span< float > segment_lengths, Span< float3 > start_positions, const Mesh &surface, const bke::CurvesSurfaceTransforms &transforms, MutableSpan< float3 > positions, const float surface_collision_distance)