[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [51881] trunk/blender/source/blender/ blenkernel/intern/shrinkwrap.c: fix issue with shrinkwrap face projection distance comparisons when using both positive and negative projection .
Campbell Barton
ideasman42 at gmail.com
Mon Nov 5 06:08:07 CET 2012
Revision: 51881
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=51881
Author: campbellbarton
Date: 2012-11-05 05:07:57 +0000 (Mon, 05 Nov 2012)
Log Message:
-----------
fix issue with shrinkwrap face projection distance comparisons when using both positive and negative projection.
- don't attempt to convert the 'dist' value between local/target space, since all the projections are done in target space
and dist isnt used afterwards. Also, this could fail with non uniform scale - overwriting ray casts with larger dist values.
- added an assert to check larger dist values never overwrite smaller ones.
- remove use of sasqrt() since the value is checked beforehand anyway.
Modified Paths:
--------------
trunk/blender/source/blender/blenkernel/intern/shrinkwrap.c
Modified: trunk/blender/source/blender/blenkernel/intern/shrinkwrap.c
===================================================================
--- trunk/blender/source/blender/blenkernel/intern/shrinkwrap.c 2012-11-05 04:38:58 UTC (rev 51880)
+++ trunk/blender/source/blender/blenkernel/intern/shrinkwrap.c 2012-11-05 05:07:57 UTC (rev 51881)
@@ -159,7 +159,9 @@
float *co = calc->vertexCos[i];
float tmp_co[3];
float weight = defvert_array_find_weight_safe(calc->dvert, i, calc->vgroup);
- if (weight == 0.0f) continue;
+ if (weight == 0.0f) {
+ continue;
+ }
/* Convert the vertex to tree coordinates */
@@ -188,8 +190,10 @@
if (nearest.index != -1) {
/* Adjusting the vertex weight,
* so that after interpolating it keeps a certain distance from the nearest position */
- float dist = sasqrt(nearest.dist);
- if (dist > FLT_EPSILON) weight *= (dist - calc->keepDist) / dist;
+ if (nearest.dist > FLT_EPSILON) {
+ const float dist = sqrtf(nearest.dist);
+ weight *= (dist - calc->keepDist) / dist;
+ }
/* Convert the coordinates back to mesh coordinates */
copy_v3_v3(tmp_co, nearest.co);
@@ -202,6 +206,7 @@
free_bvhtree_from_mesh(&treeData);
}
+
/*
* This function raycast a single vertex and updates the hit if the "hit" is considered valid.
* Returns TRUE if "hit" was updated.
@@ -215,6 +220,11 @@
BVHTree *tree, BVHTreeRayHit *hit,
BVHTree_RayCastCallback callback, void *userdata)
{
+ /* don't use this because this dist value could be incompatible
+ * this value used by the callback for comparing prev/new dist values.
+ * also, at the moment there is no need to have a corrected 'dist' value */
+// #define USE_DIST_CORRECT
+
float tmp_co[3], tmp_no[3];
const float *co, *no;
BVHTreeRayHit hit_tmp;
@@ -232,7 +242,9 @@
space_transform_apply_normal(transf, tmp_no);
no = tmp_no;
+#ifdef USE_DIST_CORRECT
hit_tmp.dist *= mat4_to_scale(((SpaceTransform *)transf)->local2target);
+#endif
}
else {
co = vert;
@@ -262,9 +274,13 @@
if (transf) {
/* Inverting space transform (TODO make coeherent with the initial dist readjust) */
space_transform_invert(transf, hit_tmp.co);
+#ifdef USE_DIST_CORRECT
hit_tmp.dist = len_v3v3(vert, hit_tmp.co);
+#endif
}
+ BLI_assert(hit_tmp.dist <= hit->dist);
+
memcpy(hit, &hit_tmp, sizeof(hit_tmp));
return TRUE;
}
@@ -281,6 +297,10 @@
float proj_axis[3] = {0.0f, 0.0f, 0.0f};
/* Raycast and tree stuff */
+
+ /** \note 'hit.dist' is kept in the targets space, this is only used
+ * for finding the best hit, to get the real dist,
+ * measure the len_v3v3() from the input coord to hit.co */
BVHTreeRayHit hit;
BVHTreeFromMesh treeData = NULL_BVHTreeFromMesh;
More information about the Bf-blender-cvs
mailing list