[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [48898] branches/soc-2012-bratwurst/source /blender/editors/transform/transform_generics.c: UV transform correction
Antony Riakiotakis
kalast at gmail.com
Fri Jul 13 23:43:49 CEST 2012
Revision: 48898
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=48898
Author: psy-fi
Date: 2012-07-13 21:43:48 +0000 (Fri, 13 Jul 2012)
Log Message:
-----------
UV transform correction
=========================
* Add visual debug code, slightly offsets edges whose loops are used for
projection
* Numerical robustness: Clamp dot products to avoid nans in acos.
With this commit, I consider UV transform correction robust for use.
Feel free to test and send comments/bugs.
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c 2012-07-13 20:50:32 UTC (rev 48897)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c 2012-07-13 21:43:48 UTC (rev 48898)
@@ -52,6 +52,7 @@
#include "DNA_mask_types.h"
#include "BLI_math.h"
+#include "BLI_math_base.h"
#include "BLI_blenlib.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
@@ -1700,6 +1701,7 @@
char prev; /* is loop previous from central vertex. Helps to evaluate direction of outward vector */
} UVTCLoop;
+//#define UVTC_VISUAL_DEBUG
/* flush the calculated displacement to uvs of the same uv island */
static void flushUVdisplacement(UVTransCorrInfoUV *first, UVTCLoop loops[2], BMEditMesh *em, TransData *td, UVTransCorrect *uvtc)
@@ -1714,7 +1716,9 @@
BMLoop *l1 = loops[0].loop;
BMLoop *l2 = loops[1].loop;
- float offset[3] = {0.0, 0.0, 1.0};
+ #ifdef UVTC_VISUAL_DEBUG
+ float offset[3] = {0.0, 0.0, 0.1};
+ #endif
int index = BM_elem_index_get(td->eve);
int index1 = BM_elem_index_get(l1->v);
@@ -1900,11 +1904,19 @@
luv = CustomData_bmesh_get(&em->bm->ldata, l_flush->head.data, CD_MLOOPUV);
copy_v2_v2(luv->uv, uv_result);
+
+ #ifdef UVTC_VISUAL_DEBUG
+ copy_v3_v3(l_flush->prev->v->co, uvtc->init_vec[BM_elem_index_get(l_flush->prev->v)]);
+ copy_v3_v3(l_flush->next->v->co, uvtc->init_vec[BM_elem_index_get(l_flush->next->v)]);
+ #endif
+
uvtcuv = uvtcuv->next;
}
- //add_v3_v3v3(l1->v->co, uvtc->init_vec[index1], offset);
- //add_v3_v3v3(l2->v->co, uvtc->init_vec[index2], offset);
+#ifdef UVTC_VISUAL_DEBUG
+ add_v3_v3v3(l1->v->co, uvtc->init_vec[index1], offset);
+ add_v3_v3v3(l2->v->co, uvtc->init_vec[index2], offset);
+#endif
}
@@ -1994,13 +2006,17 @@
/* now calculate the angles between the edges and the displacement vector */
dot_tmp = dot_v3v3(projv, projv);
- angle1 = acos(dot_v3v3(projv, proj_next)/(sqrtf(dot_tmp*dot_v3v3(proj_next, proj_next))));
- angle2 = acos(dot_v3v3(projv, proj_prev)/(sqrtf(dot_tmp*dot_v3v3(proj_prev, proj_prev))));
+ angle1 = dot_v3v3(projv, proj_next)/(sqrtf(dot_tmp*dot_v3v3(proj_next, proj_next)));
+ CLAMP(angle1, -1.0, 1.0);
+ angle1 = acos(angle1);
+ angle2 = dot_v3v3(projv, proj_prev)/(sqrtf(dot_tmp*dot_v3v3(proj_prev, proj_prev)));
+ CLAMP(angle2, -1.0, 1.0);
+ angle2 = acos(angle2);
- if(signf(dot_v3v3(cross1, uvtc->init_normal[index])) > 0.0) {
+ if(signf(dot_v3v3(cross1, uvtc->init_normal[index])) < 0.0) {
angle1 = 2*M_PI - angle1;
}
- if(signf(dot_v3v3(cross2, uvtc->init_normal[index])) > 0.0) {
+ if(signf(dot_v3v3(cross2, uvtc->init_normal[index])) < 0.0) {
angle2 = 2*M_PI - angle2;
}
More information about the Bf-blender-cvs
mailing list