[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [47223] branches/soc-2012-bratwurst/source /blender/editors/transform: UV transform correction tool
Antony Riakiotakis
kalast at gmail.com
Wed May 30 15:22:52 CEST 2012
Revision: 47223
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47223
Author: psy-fi
Date: 2012-05-30 13:22:51 +0000 (Wed, 30 May 2012)
Log Message:
-----------
UV transform correction tool
=============================
Commit work so far to have a stable backup where I
can diff against. The first part of the tool should be "finished" but
the code is disabled because i get crashes. I expect that when I resolve
the crashes I will at least have a working tool for uvs that do not
reside on stitches. Due to my misdesigning the tool I didn't account for
that but it will be added later, plus it will be a good test to see if
the principle works.
Modified Paths:
--------------
branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c
branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h
branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c
branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c 2012-05-30 13:21:13 UTC (rev 47222)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.c 2012-05-30 13:22:51 UTC (rev 47223)
@@ -1820,10 +1820,8 @@
* apply funtion */
if(t->flag & T_IMAGE_PRESERVE_CALC) {
/* can be invalidated if for instance we change the radius of proportional editing */
- if(!t->uvtc->init)
- calculateUVTransformCorrection(t);
-
- //ED
+ //if(!t->uvtc->init)
+ //calculateUVTransformCorrection(t);
}
/* If auto confirm is on, break after one pass */
Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h 2012-05-30 13:21:13 UTC (rev 47222)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform.h 2012-05-30 13:22:51 UTC (rev 47223)
@@ -221,13 +221,23 @@
int curr_sv_index;
} SlideData;
+
+typedef struct UVTransCorrInfoUV {
+ float init_uv[2]; /* initial uv value */
+ float *uv; /* pointer to the corresponding luv->uv */
+ struct UVTransCorrInfoUV *next; /* next uv for same vertex */
+}UVTransCorrInfoUV;
+
/* unwrap transform correction structure, will contain mesh elements that will be used for unwrapping */
typedef struct UVTransCorrect {
- struct BMEdge **boundary_edges;
- struct BMFace **unwrapped_faces;
+// struct BMEdge **boundary_edges;
+// struct BMFace **unwrapped_faces;
struct BMVert **affected_verts;
- int num_boundary_edges;
- int num_unwrapped_faces;
+ UVTransCorrInfoUV **initial_uvs;
+ int *vert_indices;
+// int total_boundary_edges;
+// int total_unwrapped_faces;
+ int total_verts;
char init;
} UVTransCorrect;
Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c 2012-05-30 13:21:13 UTC (rev 47222)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_conversions.c 2012-05-30 13:22:51 UTC (rev 47223)
@@ -1940,7 +1940,10 @@
BMEditMesh *em = BMEdit_FromObject(t->obedit);
BMesh *bm = em->bm;
BMVert *eve, **affected_verts;
+ UVTransCorrect *uvtc;
+ UVTransCorrInfoUV **initial_uvs;
BMIter iter;
+ BMLoop *l;
BMVert *eve_act = NULL;
float *mappedcos = NULL, *quats= NULL;
float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
@@ -2043,8 +2046,17 @@
/* now we need to allocate store for affected verts if we do maintain image */
if(t->flag & T_IMAGE_PRESERVE_CALC) {
- t->uvtc = MEM_callocN(sizeof(*t->uvtc), "UVTransformCorrect");
- t->uvtc->affected_verts = affected_verts = MEM_mallocN(t->total * sizeof(*t->uvtc->affected_verts), "BMVert Map");
+ int duck;
+ uvtc = t->uvtc = MEM_callocN(sizeof(*t->uvtc), "UVTransformCorrect");
+ uvtc->affected_verts = affected_verts = MEM_mallocN(t->total * sizeof(*t->uvtc->affected_verts), "uvtc_verts");
+ uvtc->initial_uvs = initial_uvs = MEM_mallocN(bm->totvert * sizeof(*t->uvtc->initial_uvs), "uvtc_inituvs");
+ uvtc->vert_indices = MEM_mallocN(bm->totvert * sizeof(*t->uvtc->vert_indices), "uvtc_indices");
+ uvtc->total_verts = bm->totvert;
+ duck = bm->totvert * sizeof(*t->uvtc->initial_uvs);
+ BM_mesh_elem_index_ensure(bm, BM_VERT);
+
+ if(!uvtc->initial_uvs || !uvtc->vert_indices)
+ printf("skata sta moutra sou");
}
tob= t->data= MEM_callocN(t->total*sizeof(TransData), "TransObData(Mesh EditMode)");
@@ -2099,6 +2111,11 @@
eve = BM_iter_new(&iter, bm, BM_VERTS_OF_MESH, NULL);
for (a=0, i=0; eve; eve=BM_iter_step(&iter), a++) {
+ if(t->flag & T_IMAGE_PRESERVE_CALC) {
+ uvtc->vert_indices[BM_elem_index_get(eve)] = -1;
+ initial_uvs[BM_elem_index_get(eve)] = NULL;
+ }
+
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
if (propmode || selstate[a]) {
float *bweight = CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_BWEIGHT);
@@ -2107,9 +2124,29 @@
if (tx)
tx++;
- if(t->flag & T_IMAGE_PRESERVE_CALC)
+ if(t->flag & T_IMAGE_PRESERVE_CALC) {
+ BMIter iter2;
+ UVTransCorrInfoUV **uvtcuv = initial_uvs + a;
+ UVTransCorrInfoUV *uvprev = NULL;
+
affected_verts[i] = eve;
+ t->uvtc->vert_indices[BM_elem_index_get(eve)] = i;
+ BM_ITER_ELEM(l, &iter2, eve, BM_LOOPS_OF_VERT) {
+ MLoopUV *luv = CustomData_bmesh_get(&em->bm->ldata, l->head.data, CD_MLOOPUV);
+
+ *uvtcuv = MEM_mallocN(sizeof(**uvtcuv), "uvtcelem");
+ if(uvprev)
+ uvprev->next = *uvtcuv;
+ uvprev = *uvtcuv;
+
+ copy_v2_v2((*uvtcuv)->init_uv, luv->uv);
+ (*uvtcuv)->uv = luv->uv;
+ (*uvtcuv)->next = NULL;
+ uvtcuv = &((*uvtcuv)->next);
+ }
+ }
+
/* selected */
if (selstate[a]) tob->flag |= TD_SELECTED;
Modified: branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c 2012-05-30 13:21:13 UTC (rev 47222)
+++ branches/soc-2012-bratwurst/source/blender/editors/transform/transform_generics.c 2012-05-30 13:22:51 UTC (rev 47223)
@@ -1049,8 +1049,9 @@
v3d->twtype = 0;
}
- if(ts->uvcalc_flag & UVCALC_TRANSFORM_CORRECT)
+ if(ts->uvcalc_flag & UVCALC_TRANSFORM_CORRECT && EDBM_mtexpoly_check(BMEdit_FromObject(obedit))) {
t->flag |= T_IMAGE_PRESERVE_CALC;
+ }
if (v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
t->around = v3d->around;
@@ -1217,6 +1218,7 @@
void deleteUVTransCorrect(struct UVTransCorrect *uvtc)
{
+ /*
if(uvtc->boundary_edges) {
MEM_freeN(uvtc->boundary_edges);
uvtc->boundary_edges = NULL;
@@ -1225,10 +1227,32 @@
MEM_freeN(uvtc->unwrapped_faces);
uvtc->unwrapped_faces = NULL;
}
+ */
if(uvtc->affected_verts) {
MEM_freeN(uvtc->affected_verts);
uvtc->affected_verts = NULL;
}
+ if(uvtc->vert_indices) {
+ MEM_freeN(uvtc->vert_indices);
+ uvtc->vert_indices = NULL;
+ }
+ if(uvtc->initial_uvs) {
+ int i;
+ for(i = 0; i < uvtc->total_verts; i++) {
+ UVTransCorrInfoUV *uvtcuv;
+ uvtcuv = uvtc->initial_uvs[i];
+ if(uvtcuv) {
+ while(uvtcuv->next) {
+ UVTransCorrInfoUV *uvtcuvtmp = uvtcuv->next;
+ MEM_freeN(uvtcuv);
+ uvtcuv = uvtcuvtmp;
+ }
+ MEM_freeN(uvtcuv);
+ }
+ }
+ MEM_freeN(uvtc->initial_uvs);
+ uvtc->initial_uvs = NULL;
+ }
}
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
@@ -1619,104 +1643,74 @@
* These elements will be artificially pinned for this first attempt at the algorithm */
void calculateUVTransformCorrection(TransInfo *t)
{
- int i, edge_counter = 0, boundary_edge_counter = 0;
+ int i, index;
BMIter iter;
- BMFace *f;
- BMEdge **edge_list, **edge_boundaries;
- BMEdge *e;
- GHashIterator *ghiter;
- GHash *face_hash = BLI_ghash_ptr_new("maintain_image_face_hash");
- GHash *edge_hash = BLI_ghash_ptr_new("maintain_image_edge_hash");
+ BMLoop *l;
+ BMEditMesh *em = BMEdit_FromObject(t->obedit);
TransData *td = t->data;
UVTransCorrect *uvtc = t->uvtc;
+// float modelviewprojmat[4][4];
char not_prop_edit = !(t->flag & T_PROP_EDIT);
- /* cleanup previous data if it exists */
- if(uvtc->boundary_edges)
- MEM_freeN(uvtc->boundary_edges);
- if(uvtc->unwrapped_faces)
- MEM_freeN(uvtc->unwrapped_faces);
+ /* transform the edge vectors to view space */
+ //mult_m4_m4m4(modelviewprojmat, t->persmat, t->viewmat);
+ //mult_m4_m4m4(modelviewprojmat, modelviewprojmat, t->obedit->obmat);
- /* store faces adjacent to verts */
- for (i = 0 ; i < t->total; i++, td++) {
+ /* iterate through loops of vert and calculate image space diff of uvs */
+ for (i = 0 ; i < t->total; i++) {
BMVert *v = uvtc->affected_verts[i];
- if(not_prop_edit || td->factor > 0.0) {
- BM_ITER_ELEM(f, &iter, v, BM_FACES_OF_VERT) {
- if(!BLI_ghash_haskey(face_hash, f)){
- BLI_ghash_insert(face_hash, f, NULL);
- }
- }
- }
- }
+ if(not_prop_edit || td[i].factor > 0.0) {
+ float uv_tot[2] = {0.0, 0.0};
+ int uv_counter = 0;
- ghiter = BLI_ghashIterator_new(face_hash);
+ index = uvtc->vert_indices[BM_elem_index_get(v)];
- /* count edges */
- for(; !BLI_ghashIterator_isDone(ghiter); BLI_ghashIterator_step(ghiter)) {
- f = BLI_ghashIterator_getKey(ghiter);
+ BM_ITER_ELEM(l, &iter, v, BM_LOOPS_OF_VERT) {
+ float edge_len_init;
+ float edge_len_final;
+// float edge_uv_len_init;
+ float edge_vec_init[3];
+ float edge_vec_final[3];
+ float edge_uv_init[2];
+ float uvdiff[2];
+ int index_other;
+ BMLoop *l_other;
+ MLoopUV *luv_other;
+ l_other = BM_loop_other_vert_loop(l, v);
- BM_ITER_ELEM(e, &iter, f, BM_EDGES_OF_FACE) {
- if(!BLI_ghash_haskey(edge_hash, e)) {
- BLI_ghash_insert(edge_hash, e, NULL);
- edge_counter++;
- }
- }
- }
+ luv_other = CustomData_bmesh_get(&em->bm->ldata, l_other->head.data, CD_MLOOPUV);
- edge_list = MEM_mallocN(edge_counter*sizeof(*edge_list), "maintain_image_edge_list");
- /* allocate more than we will need to avoid recounting */
- uvtc->boundary_edges = edge_boundaries = MEM_mallocN(edge_counter*sizeof(*edge_boundaries), "maintain_image_boundary_list");
+ index_other = uvtc->vert_indices[BM_elem_index_get(l_other->v)];
- BLI_ghashIterator_init(ghiter, edge_hash);
- /* fill with count values */
- for(i = 0; !BLI_ghashIterator_isDone(ghiter); BLI_ghashIterator_step(ghiter)) {
- edge_list[i++] = BLI_ghashIterator_getKey(ghiter);
- }
+ /* find initial and final edge lengths */
+ if(index_other == -1) {
+ /* get BMvert coords since the vertex hasn't changed */
+ sub_v3_v3v3(edge_vec_init, l_other->v->co, td[i].iloc);
+ sub_v2_v2v2(edge_uv_init, luv_other->uv, uvtc->initial_uvs[index]->init_uv);
+ } else {
+ sub_v3_v3v3(edge_vec_init, td[index_other].iloc, td[i].iloc);
+ sub_v2_v2v2(edge_uv_init, uvtc->initial_uvs[index_other]->init_uv, uvtc->initial_uvs[index]->init_uv);
+ }
+ sub_v3_v3v3(edge_vec_final, l_other->v->co, v->co);
- BLI_ghashIterator_free(ghiter);
- BLI_ghash_free(edge_hash, NULL, NULL);
+ edge_len_init = len_v3(edge_vec_init);
+ edge_len_final = len_v3(edge_vec_final);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list