[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58722] branches/ soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c : UV transfer through faces: using face to face mapping and commenting the island finding part as it' s currently not needed in the face to face mapping -WIP-
Walid Shouman
eng.walidshouman at gmail.com
Mon Jul 29 20:09:32 CEST 2013
Revision: 58722
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58722
Author: walid
Date: 2013-07-29 18:09:32 +0000 (Mon, 29 Jul 2013)
Log Message:
-----------
UV transfer through faces: using face to face mapping and commenting the island finding part as it's currently not needed in the face to face mapping -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-29 17:27:27 UTC (rev 58721)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-07-29 18:09:32 UTC (rev 58722)
@@ -1236,32 +1236,36 @@
return true;
}
-
+//callback used for the island finding
+/*
static bool check_e_table_cb(BMEdge *e, void *user_data) {
return ((bool*)user_data)[e->head.index];
}
-
+*/
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])
{
//-----uv dependent variables
- BMLoop *l; //used for iterating the destination's loops
+ BMLoop *l, *l2; //used for iterating the destination's loops
// MLoopUV *luv, *luv_src;
- BMIter liter;
+ BMIter liter, liter2;
float weight_accu[2];
//-----algorithm definitions start
BMEditMesh *em_src; //tree variable
struct BMBVHTree *bmtree_src = NULL; //tree variable
float *tmp_weight = NULL;
- float tmp_co[3], v_co[3]; //****** will be replaced?
+ float tmp_co[3];
+ float f_mid_src[3], f_mid_dst[3];
- BMFace *f;
+ BMFace *f_src, *f_dst;
BMIter fiter;
BMVert *v2;
- float (*v_co_list)[3];
- int v_count;
+ float (*v_co_list_src)[3];
+ float (*v_co_list_dst)[3];
+ int v_src_count;
+ int v_dst_count;
int a;
//====algorithm definitions end
@@ -1270,14 +1274,14 @@
//used for iterating the destination's verts
BMVert *v; //iterated vert
- BMIter iter; //vertex iterator
+ BMIter iter, iter2; //vertex iterator
int tot_layer_src,tot_layer_dst;
int src_lay_iter, dst_lay_iter;
//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
-
+/*
//-------island finding definitions
int* count = NULL;
int path_count;
@@ -1304,7 +1308,7 @@
LinkNode *vert_path_fragment;
LinkNode *vert_path_iter;
//=======end of island finding def
-
+*/
//Is that good to support edit mesh mode at the cost of receiving me_src too ?
//if (me_src->edit_btmesh != NULL) em_src = me_src->edit_btmesh; //edit mesh mode
//else
@@ -1315,6 +1319,7 @@
//get the faces tree
bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false);
+/*
//-----------start finding the source island boundaries and importing them into a list
//this will give us a list of seams from the starting edge
@@ -1368,36 +1373,7 @@
edge_paths[path_count - 1] = BM_mesh_calc_path_edge2(bm_src, e_start, ind_e_table, false, ind_e_table,
check_e_table_cb);
}
-/*
- BM_ITER_MESH (e_start, &eiter1, bm_src, BM_EDGES_OF_MESH) {
- //if the start was already in a previous path, skip it!
- //search for an edge within each of the preserved paths
- if (BM_edge_in_paths(edge_paths, e_start, path_count)){
- continue;
- }
- BM_ITER_MESH (e_end, &eiter2, bm_src, BM_EDGES_OF_MESH) {
- //we get paths between each starting/ending edges
- temp_path = BM_mesh_calc_path_edge(bm_src, e_start, e_end, use_length, visited_edges, test_marked_unvisited_callback);
-
- //OPS BM_mesh_calc_path_edge USE TAGS ALSO TO SEARCH!!!!!!!!!!!
- //flag_islands can't count :/ ... we shall compute the number of islands from another
-// flag_islands(bm_src, count, false, false, true);
-
- //only one condition is needed and the other isn't
- if ((edge_paths[j]->next == e_end) || (edge_paths[j]->next == e_end)) {
- path_count++;
- edge_paths = MEM_reallocN(edge_paths, sizeof(*edge_paths) * (path_count));
- edge_paths[j] = temp_path;
- j++; //j is an iterator
-
- //if we found an end for the current seam start .. break to another start
- //we're sure that it won't skip any island as each seam consists of at least one new edge
- break;
- }
- }
- }
-*/
//reset the seams
BM_ITER_MESH_INDEX (e, &eiter1, bm_src, BM_EDGES_OF_MESH, a) {
BM_elem_flag_set(e, BM_ELEM_SEAM, seam_backup[a]);
@@ -1469,11 +1445,11 @@
path_count_dst = path_count - island_miss;
//============end of getting the source vertices representing each of the source paths
+*/
- flag_islands(bm_src, NULL, true, false , false);
+ v_co_list_dst = MEM_mallocN(sizeof(*v_co_list_dst), "v_co_list_dst bmesh_data_transfer.c");
+ v_co_list_src = MEM_mallocN(sizeof(*v_co_list_src), "v_co_list bmesh_data_transfer.c");
- zero_v2(weight_accu);
-
tot_layer_src = CustomData_number_of_layers(&bm_src->ldata, CD_MLOOPUV);//to change the last one
tot_layer_dst = CustomData_number_of_layers(&bm_dst->ldata, CD_MLOOPUV); //get the number of Shapekey layers
//within the target
@@ -1508,46 +1484,65 @@
CD_src = CustomData_get_n_offset(&bm_src->ldata, CD_MLOOPUV, src_lay_iter); //get the offset of the
CD_dst = CustomData_get_n_offset(&bm_dst->ldata, CD_MLOOPUV, dst_lay_iter); //lay_iter(th)CD_SHAPEKEY layer
- //the way we do it is by looping over each vertex!!
- for (v = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL); v; v = BM_iter_step(&iter)) {
+ //the way we do it is by looping over each face!!
+ BM_ITER_MESH (f_dst, &fiter, bm_dst, BM_FACES_OF_MESH) {
+
+ //get a coordinate list of the f_dst verts
+ //used to get the the f_mid_dst for mid_poly_v3
+ BM_ITER_ELEM_INDEX (v, &iter, f_dst, BM_VERTS_OF_FACE, v_dst_count) {
+ v_co_list_dst = MEM_reallocN(v_co_list_dst, sizeof(*v_co_list_dst) * (v_dst_count + 1));
+ copy_v3_v3(v_co_list_dst[v_dst_count], v->co);
+ }
+
+ zero_v3(f_mid_dst);
+ mid_poly_v3(f_mid_dst, v_co_list_dst, v_dst_count);
+
// Transform into target space.
- mul_v3_m4v3(tmp_co, tmp_mat, v->co);
+ mul_v3_m4v3(tmp_co, tmp_mat, f_mid_dst); //to start searching for a match
// Node tree accelerated search for closest face.
- f = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX);
+ f_src = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX);
+ ///fork from here to map each vertex into the projection
//get a coordinate list of the f verts
- BM_ITER_ELEM_INDEX (v2, &fiter, f, BM_VERTS_OF_FACE, v_count) {
- v_co_list = MEM_reallocN(v_co_list, sizeof(*v_co_list) * (v_count + 1));
- copy_v3_v3(v_co_list[v_count], v2->co);
+ 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));
+ copy_v3_v3(v_co_list_src[v_src_count], v2->co);
}
+ 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
- // Project onto face.
- zero_v3(v_co);
- mid_poly_v3(v_co, v_co_list, v_count); //v_co <= face center of the basis!
- project_v3_plane(tmp_co, f->no, v_co);
- //project_v3_plane(tmp_co, f->no, f->l_first->v->co);//not sure, do we really have to use an actual vertex ?
+ BM_ITER_ELEM (l, &liter, f_dst, BM_LOOPS_OF_FACE) {
- // Interpolate weights over face.
- //check that v_count will equal to n not n-1!!
- tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * v_count, "tmp_weight bmesh_data_transfer.c");
+ zero_v3(tmp_co);
+ // Transform into target space.
+ mul_v3_m4v3(tmp_co, tmp_mat, l->v->co);
- //spatially finding the weights from the face's vertices
- interp_weights_poly_v3(tmp_weight, v_co_list, v_count, tmp_co);
+ // Project each vertex onto face.
+ project_v3_plane(tmp_co, f_src->no, f_mid_src);
+ //project_v3_plane(tmp_co, f->no, f->l_first->v->co);//not sure, do we really have to use an actual vertex ?
- // Interpolating according to the spatially found weights
- zero_v2(weight_accu);
- //we need to ensure the first loop match with the first vertex!
- BM_ITER_ELEM_INDEX (l, &liter, f, BM_LOOPS_OF_FACE, a) {
- madd_v2_v2fl(weight_accu, BM_ELEM_CD_GET_VOID_P(l, CD_src), tmp_weight[a]);
- }
+ // Interpolate weights over face.
+ //check that v_count will equal to n not n-1!!
+ tmp_weight = MEM_mallocN(sizeof(*tmp_weight) * v_src_count, "tmp_weight bmesh_data_transfer.c");
- //shall we verify the indices!?
- BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
+ //spatially finding the weights from the face's vertices
+ interp_weights_poly_v3(tmp_weight, v_co_list_src, v_src_count, tmp_co);
+
+ // Interpolating according to the spatially found weights
+ zero_v2(weight_accu);
+ //we need to ensure the first loop from this search matches with the first vert from the prev search!
+ BM_ITER_ELEM_INDEX (l2, &liter2, f_src, BM_LOOPS_OF_FACE, a) {
+ madd_v2_v2fl(weight_accu, BM_ELEM_CD_GET_VOID_P(l2, CD_src), tmp_weight[a]);
+ }
+
+ //shall we verify the indices!?
+ // copy for each loop directly
copy_v2_v2(BM_ELEM_CD_GET_VOID_P(l, CD_dst), weight_accu);
+
+ //end of interpolation
}
- //end of interpolation
}
}
More information about the Bf-blender-cvs
mailing list