Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Gavrilov <angavrilov@gmail.com>2018-07-07 18:39:45 +0300
committerAlexander Gavrilov <angavrilov@gmail.com>2018-09-26 16:52:58 +0300
commit3378782eeeb55a6ed64dba479e37f8b98fab63b1 (patch)
tree1ae6e8fd713d4c7b22a05a4024f2f7dbc09efe2b /source/blender/blenkernel/intern/constraint.c
parent310f1b057926d6250adf11db6621f2606b61827f (diff)
Implement additional modes for Shrinkwrap to a surface.
In addition to the original map to surface and Keep Above Surface, add modes that only affect vertices that are inside or outside the object. This is inspired by the Limit Distance constraint, and can be useful for crude collision detection in rigs. The inside/outside test works based on face normals and may not be completely reliable near 90 degree or sharper angles in the target. Reviewers: campbellbarton, mont29 Differential Revision: https://developer.blender.org/D3717
Diffstat (limited to 'source/blender/blenkernel/intern/constraint.c')
-rw-r--r--source/blender/blenkernel/intern/constraint.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 3ea2f4e0ee4..b1a7c98dc9c 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -3456,7 +3456,6 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *depsgraph, bConstraint *con,
case MOD_SHRINKWRAP_NEAREST_VERTEX:
{
BVHTreeNearest nearest;
- float dist;
nearest.index = -1;
nearest.dist_sq = FLT_MAX;
@@ -3475,10 +3474,22 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *depsgraph, bConstraint *con,
BLI_bvhtree_find_nearest(treeData.tree, co, &nearest, treeData.nearest_callback, &treeData);
- dist = len_v3v3(co, nearest.co);
- if (dist != 0.0f) {
- interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist) / dist); /* linear interpolation */
+ if (nearest.index < 0) {
+ fail = true;
+ break;
}
+
+ if (scon->shrinkType == MOD_SHRINKWRAP_NEAREST_SURFACE) {
+ BKE_shrinkwrap_snap_point_to_surface(scon->shrinkMode, nearest.co, nearest.no, scon->dist, co, co);
+ }
+ else {
+ const float dist = len_v3v3(co, nearest.co);
+
+ if (dist != 0.0f) {
+ interp_v3_v3v3(co, co, nearest.co, (dist - scon->dist) / dist); /* linear interpolation */
+ }
+ }
+
BLI_space_transform_invert(&transform, co);
break;
}
@@ -3522,13 +3533,14 @@ static void shrinkwrap_get_tarmat(struct Depsgraph *depsgraph, bConstraint *con,
break;
}
- if (BKE_shrinkwrap_project_normal(0, co, no, scon->dist, &transform, treeData.tree,
+ if (BKE_shrinkwrap_project_normal(0, co, no, 0.0f, &transform, treeData.tree,
&hit, treeData.raycast_callback, &treeData) == false)
{
fail = true;
break;
}
- copy_v3_v3(co, hit.co);
+
+ BKE_shrinkwrap_snap_point_to_surface(scon->shrinkMode, hit.co, hit.no, scon->dist, co, co);
break;
}
}