[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58757] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c : UV transfer through faces: added portion to connect UVs after transfer -WIP-
Walid Shouman
eng.walidshouman at gmail.com
Wed Jul 31 10:01:30 CEST 2013
Revision: 58757
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58757
Author: walid
Date: 2013-07-31 08:01:29 +0000 (Wed, 31 Jul 2013)
Log Message:
-----------
UV transfer through faces: added portion to connect UVs after transfer -WIP-
Modified Paths:
--------------
branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-07-31 07:34:09 UTC (rev 58756)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-07-31 08:01:29 UTC (rev 58757)
@@ -1242,6 +1242,19 @@
return ((bool*)user_data)[e->head.index];
}
*/
+
+/** loop face mapping
+ * loops of the destination are mapped into the source face that they've inherited there values from
+ * used to connect the dst loops of different dst faces that should be mapped to a single island according to the
+ * connected source faces
+ */
+
+typedef struct BM_loops_per_face_mapping{
+ struct BMFace *f; //the source face
+ struct BMLoop **l; //the corresponding loops
+ int count; //count of the corresponding loops
+} BM_loops_per_face_mapping;
+
bool BM_mesh_uv_copy2(BMesh *bm_src, BMesh *bm_dst, float UNUSED(tolerance), float UNUSED(radius_interp),
int UNUSED(dist_pow), int UNUSED(no_pow), bool UNUSED(USE_NORMALS),
ST_ShapekeyGroupMode replace_mode, int *act_shapekey_lay, float tmp_mat[4][4])
@@ -1267,7 +1280,7 @@
int v_src_count;
int v_dst_count;
- int a;
+ int a, b, c, d, g;
//====algorithm definitions end
int CD_src, CD_dst;
@@ -1281,6 +1294,24 @@
//replace mode variables
int src_lay_start, src_lay_end;
int dst_lay_start, dst_lay_end; //dst_lay_end currently isn't being used
+
+ //------loops connecting definitions //we connect the loops (faces) after we map them to avoid the expensive
+ //computation for an island based algorithm
+ //using a table for a faster access when we check whether the face was already added or not
+ //calloc cause unmapped faces should be nulled!!
+ BM_loops_per_face_mapping *fl_table = MEM_callocN(sizeof(*fl_table) * bm_src->totface, "fl_table bmesh_data_transfer.c");
+
+ //used to hold the source faces that we inherited from only, looping over them would be faster than looping over
+ //all the faces with the index ... specially if we inherited from a small portion of the source faces
+ //note: the effective size should be f_src_count
+ BMFace **f_src_table = MEM_mallocN(sizeof(*f_src_table) * bm_src->totface, "f_src_table bmesh_data_transfer.c");
+ int f_src_count = 0;
+ BMFace *fa, *fb, *f_n;
+ BMEdge *e;
+ BMIter eiter;
+ float (*uv_buffer)[2] = MEM_mallocN(sizeof(*uv_buffer) * bm_src->totloop, "uv_buffer bmesh_data_transfer.c");
+ //======end of loops connnecting definitions
+
/*
//-------island finding definitions
int* count = NULL;
@@ -1502,9 +1533,20 @@
mul_v3_m4v3(tmp_co, tmp_mat, f_mid_dst); //to start searching for a match
// Node tree accelerated search for closest face.
- f_src = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX);
+ f_src = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX); //would return null if the source didn't
+ //have faces within the radius range!!
///fork from here to map each vertex into the projection
+ if (fl_table[f_src->head.index].f == NULL) { //if the face source reperesnts a new entry
+ f_src_table[f_src_count] = f_src;
+ f_src_count++;
+ }
+
+ fl_table[f_src->head.index].f = f_src;
+ fl_table[f_src->head.index].count += f_dst->len; //we need count to be init with zero (calloc) in adv
+ ///check the type inside sizeof
+ fl_table[f_src->head.index].l = MEM_mallocN(sizeof(*(fl_table[f_src->head.index].l)) * (fl_table[f_src->head.index].count), "fl_table.l bmesh_data_transfer.c");
+
//get a coordinate list of the f verts
BM_ITER_ELEM_INDEX (v2, &iter2, f_src, BM_VERTS_OF_FACE, v_src_count) {
v_co_list_src = MEM_reallocN(v_co_list_src, sizeof(*v_co_list_src) * (v_src_count + 1));
@@ -1513,8 +1555,10 @@
zero_v3(f_mid_src);
mid_poly_v3(f_mid_src, v_co_list_src, v_src_count); //get the mid point of the source face
- BM_ITER_ELEM (l, &liter, f_dst, BM_LOOPS_OF_FACE) {
+ BM_ITER_ELEM_INDEX (l, &liter, f_dst, BM_LOOPS_OF_FACE, b) {
+ fl_table[f_src->head.index].l[b + (fl_table[f_src->head.index].count - f_dst->len)] = l;
+
zero_v3(tmp_co);
// Transform into target space.
mul_v3_m4v3(tmp_co, tmp_mat, l->v->co);
@@ -1542,8 +1586,67 @@
copy_v2_v2(BM_ELEM_CD_GET_VOID_P(l, CD_dst), weight_accu);
//end of interpolation
+ copy_v2_v2(uv_buffer[l->head.index], BM_ELEM_CD_GET_VOID_P(l, CD_dst));
}
}
+
+ //loop over the src faces
+ for (c = 0; c < f_src_count; c++) {
+ f_src = f_src_table[c];
+
+ //within it search for the neighboring faces
+ BM_ITER_ELEM (e, &eiter, f_src, BM_EDGES_OF_FACE) {
+ if (BM_edge_face_pair (e, &fa, &fb) == true) {
+
+ f_n = (fa->head.index == f_src->head.index) ? fb: fa;
+ //if any of them was found in our src tables
+ if (fl_table[f_n->head.index].f != NULL) { ///we're missing a check ... that they're in the same island
+
+ //search within the mapped -to the src face- loops in fl_table
+ //for the loops that share the same vertex between f_src and f_n
+ for (d = 0; d < fl_table[f_src->head.index].count; d++) {
+
+ for (g = 0; g < fl_table[f_n->head.index].count; g++) {
+
+ if (fl_table[f_src->head.index].l[d]->v->head.index ==
+ fl_table[f_src->head.index].l[g]->v->head.index) {
+ //we finally found loops that shall be averaged from different faces!
+ //we now shall average them into a buffer!
+ //currently we've a buffer that's the same size as as the dst loops
+
+ mid_v2_v2v2(uv_buffer[fl_table[f_src->head.index].l[d]->head.index],
+ uv_buffer[fl_table[f_src->head.index].l[d]->head.index],
+ uv_buffer[fl_table[f_src->head.index].l[g]->head.index]);
+
+ copy_v2_v2(uv_buffer[fl_table[f_src->head.index].l[g]->head.index],
+ uv_buffer[fl_table[f_src->head.index].l[d]->head.index]);
+ }
+ }
+ }
+ }
+ }
+
+ else { //a manifold exists! not supported till we're sure it will generalize well
+ return false;
+ }
+
+ }
+
+ }
+ ///we need an optimized way for having a buffer, note: a way that optimizes for the speed
+ //get the mid of UVs into a buffer
+ //get the UV coords after looping over the src faces!!
+
+ //loop over the src faces to apply the changes made to the buffer
+ for (c = 0; c < f_src_count; c++) {
+ f_src = f_src_table[c];
+
+ for (d = 0; d < fl_table[f_src->head.index].count; d++) {
+ copy_v2_v2(BM_ELEM_CD_GET_VOID_P(fl_table[f_src->head.index].l[d], CD_dst),
+ uv_buffer[fl_table[f_src->head.index].l[d]->head.index]);
+ }
+ }
+
}
return true;
More information about the Bf-blender-cvs
mailing list