diff options
author | Sebastian Parborg <darkdefende@gmail.com> | 2020-06-24 19:40:42 +0300 |
---|---|---|
committer | Sebastian Parborg <darkdefende@gmail.com> | 2020-06-24 19:40:42 +0300 |
commit | 2ccdf41da6f3cfb014296e7a98fdb3512cbdf02e (patch) | |
tree | bd75a623210f1b71cfb7a85e101710b7f4b4fa45 | |
parent | 105d94aa2bd0c56d12ffb2afa243431045d157e5 (diff) |
Clamp bayu weights to prevent extrapolated velocity values
-rw-r--r-- | source/blender/simulations/bparticles/simulate.cpp | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/source/blender/simulations/bparticles/simulate.cpp b/source/blender/simulations/bparticles/simulate.cpp index 43d4a474e6b..4937dbf25cc 100644 --- a/source/blender/simulations/bparticles/simulate.cpp +++ b/source/blender/simulations/bparticles/simulate.cpp @@ -110,8 +110,6 @@ static float collision_newton_rhapson(std::pair<float3, float3> &particle_points } for (int iter = 0; iter < 10; iter++) { //, itersum++) { - // printf("\nt1 %f\n", t1); - /* get current location */ collision_interpolate_element(tri_points, cur_tri_points, t1); p = float3::interpolate(particle_points.first, particle_points.second, t1); @@ -233,6 +231,10 @@ BLI_NOINLINE static void raycast_callback(void *userdata, dist = bvhtree_sphereray_tri_intersection(ray, ray->radius, hit->dist, v0, v1, v2); } + // TODO perhaps check if the new collision is inside the triangle and the distance is within + // COLLISION_MIN_DISTANCE, then we take the collision that is inside the face. Note that this + // only for the same coll object + if (dist >= 0.0f && dist < hit->dist) { hit->index = index; hit->dist = dist; @@ -297,7 +299,7 @@ BLI_NOINLINE static void raycast_callback(void *userdata, if (coll_time >= 0.f) { if (hit->index != -1 && dist >= 0.0f && dist >= hit->dist) { - /* We have already collided with and other object at closer distance */ + /* We have already collided with an other object at closer distance */ return; } // We have a collision! @@ -311,6 +313,10 @@ BLI_NOINLINE static void raycast_callback(void *userdata, // Calculate the velocity of the point we hit zero_v3(rd->hit_vel); for (int i = 0; i < 3; i++) { + // Make sure that all the weights are between 0-1. They can be negative or above 1 if the + // point lies slightly outside of the triangle. + CLAMP(hit_bary_weights[i], 0.f, 1.f); + rd->hit_vel += (tri_points[i].second - tri_points[i].first) * hit_bary_weights[i] / rd->duration; } |