[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [58635] branches/ soc-2013-meshdata_transfer/source/blender: UV transfer through faces: implemented basic copy -very basic interpolation- & Shapekey transfer through faces : small fix for a better copy result -and still the interpolation is so basic-
Walid Shouman
eng.walidshouman at gmail.com
Sat Jul 27 00:11:42 CEST 2013
Revision: 58635
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=58635
Author: walid
Date: 2013-07-26 22:11:41 +0000 (Fri, 26 Jul 2013)
Log Message:
-----------
UV transfer through faces: implemented basic copy -very basic interpolation- & Shapekey transfer through faces: small fix for a better copy result -and still the interpolation is so basic-
Modified Paths:
--------------
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.h
branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.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-26 21:42:28 UTC (rev 58634)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-07-26 22:11:41 UTC (rev 58635)
@@ -949,6 +949,8 @@
int src_lay_start, src_lay_end;
int dst_lay_start, dst_lay_end; //dst_lay_end currently isn't being used
+ float v_co[3];
+
//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
@@ -1011,16 +1013,16 @@
}
// Project onto face.
- //use a single coodrinate to get the tmp_co
- //we may need to use this function instead of using the first vert's coords
- //mid_poly_v3(v_co, v_co_list, v_count);
- project_v3_plane(tmp_co, f->no, f->l_first->v->co);
+ 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 ?
// 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");
- interp_weights_poly_v3(tmp_weight, v_co_list, v_count, tmp_co);
+ interp_weights_poly_v3(tmp_weight, v_co_list, v_count, v_co);
// Get weights from face.
zero_v3(v_dst_offset);
@@ -1040,3 +1042,133 @@
return true;
}
+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
+// MLoopUV *luv, *luv_src;
+ BMIter liter;
+ 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?
+
+ BMFace *f;
+ BMIter fiter;
+ BMVert *v2;
+ float (*v_co_list)[3];
+ int v_count;
+
+ int a;
+ //====algorithm definitions end
+
+ int CD_src, CD_dst;
+
+ //used for iterating the destination's verts
+ BMVert *v; //iterated vert
+ BMIter iter; //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
+
+ zero_v2(weight_accu);
+
+ //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
+ em_src = BKE_editmesh_create(bm_src, true); //create editmesh data from bm WITH tess.
+ //if it was false ... data other than
+ //em->bm won't be copied
+
+ 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
+
+ //get the faces tree
+ bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false);
+
+ if (replace_mode == ST_APPEND_SHAPEKEY_GROUPS) {
+ //add 1 to skip the basis
+ src_lay_start = 0;
+ src_lay_end = tot_layer_src;
+ dst_lay_start = tot_layer_dst - tot_layer_src + 1;
+ dst_lay_end = tot_layer_dst;
+ }
+
+ else if ((replace_mode == ST_REPLACE_ENOUGH_SHAPEKEY_GROUPS) || (replace_mode == ST_REPLACE_ALL_SHAPEKEY_GROUPS)) {
+ src_lay_start = 0;
+ src_lay_end = tot_layer_src;
+ dst_lay_start = 0;
+ dst_lay_end = tot_layer_src;
+ }
+
+ else if (replace_mode == ST_REPLACE_ACTIVE_SHAPEKEY_GROUP) {
+ //passed shapekey reperesents the # of shapekeys (starts from one), however lay_start uses it as an index
+ src_lay_start = act_shapekey_lay[0] - 1;
+ src_lay_end = act_shapekey_lay[0];
+ dst_lay_start = act_shapekey_lay[1] - 1;
+ dst_lay_end = act_shapekey_lay[1];
+ }
+
+ for (src_lay_iter = src_lay_start, dst_lay_iter = dst_lay_start; src_lay_iter < src_lay_end;
+ src_lay_iter++, dst_lay_iter++) {
+
+ //fix the layer index of the source & dest
+ 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)) {
+
+ // Transform into target space.
+ mul_v3_m4v3(tmp_co, tmp_mat, v->co);
+
+ // Node tree accelerated search for closest face.
+ f = BKE_bmbvh_find_face_closest(bmtree_src, tmp_co, FLT_MAX);
+
+ //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);
+ }
+
+ // 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 ?
+
+ // 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");
+
+ //spatially finding the weights from the face's vertices
+ interp_weights_poly_v3(tmp_weight, v_co_list, v_count, v_co);
+
+ // Interpolating according to the spatially found weights
+ zero_v2(weight_accu);
+ BM_ITER_ELEM_INDEX (v2, &fiter, f, BM_VERTS_OF_FACE, a) {
+ //within a single island, all the vert's loops have the same value
+ l = BM_vert_find_first_loop(v2);
+ madd_v2_v2fl(weight_accu, BM_ELEM_CD_GET_VOID_P(l, CD_src), tmp_weight[a]);
+ }
+
+ //shall we verify the indices!?
+ BM_ITER_ELEM (l, &liter, v, BM_LOOPS_OF_VERT) {
+ copy_v2_v2(BM_ELEM_CD_GET_VOID_P(l, CD_dst), weight_accu);
+ }
+ //end of interpolation
+ }
+ }
+
+ return true;
+}
+
Modified: branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h 2013-07-26 21:42:28 UTC (rev 58634)
+++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h 2013-07-26 22:11:41 UTC (rev 58635)
@@ -40,6 +40,10 @@
bool BM_mesh_uv_copy(BMesh *bm_src,BMesh *bm_dst, float tolerance, float radius_interp, int dist_pow, int no_pow,
bool USE_NORMALS);
+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]);
+
bool BM_mesh_shapekey_copy(BMesh *bm_src, BMesh *bm_dst, float tolerance, float radius_interp,
int interp_pow, int no_pow, bool USE_NORMALS, ST_ShapekeyGroupMode replace_mode,
int *act_shapekey_lay, bool auto_tol, float auto_tol_percentage);
Modified: branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c
===================================================================
--- branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c 2013-07-26 21:42:28 UTC (rev 58634)
+++ branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c 2013-07-26 22:11:41 UTC (rev 58635)
@@ -466,6 +466,19 @@
}
}
+typedef enum UT_UVTransferMode {
+ UT_USE_NEAREST_VERTEX = 1,
+ UT_USE_NEAREST_FACE = 2
+} UT_UVTransferMode;
+
+static EnumPropertyItem UT_transfer_mode_item[] = {
+ {UT_USE_NEAREST_VERTEX,
+ "UT_USE_NEAREST_VERTEX", 0, "Nearest vertex", "Copy from the nearest vertices"},
+ {UT_USE_NEAREST_FACE,
+ "UT_USE_NEAREST_FACE", 0, "Nearest face", "Copy from the nearest face"},
+ {0, NULL, 0, NULL, NULL}
+};
+
static bool ED_mesh_uv_transfer(Object *ob_dst, Object *ob_src, bContext *UNUSED(C), Scene *UNUSED(scene), wmOperator * op)
{
Mesh *me_dst, *me_src;
@@ -476,11 +489,17 @@
int interp_pow = RNA_int_get(op->ptr, "interp_power");
bool interp_normals = RNA_boolean_get(op->ptr, "interp_normals");
int no_pow = RNA_int_get(op->ptr, "normals_power");
+ UT_UVTransferMode transfer_mode = RNA_enum_get(op->ptr, "transfer_mode");
int num_src_lay, num_dst_lay;
int i;
+ float tmp_mat[4][4];
+
+ invert_m4_m4(ob_src->imat, ob_src->obmat);
+ mul_m4_m4m4(tmp_mat, ob_src->imat, ob_dst->obmat);
+
me_dst = ob_dst->data;
me_src = ob_src->data;
@@ -503,13 +522,23 @@
bm_src = BM_mesh_create(&bm_mesh_allocsize_default);
bm_dst = BM_mesh_create(&bm_mesh_allocsize_default);
- BM_mesh_bm_from_me(bm_src, me_src, TRUE, true, ob_src->shapenr); //TRUE -> should transfer shapekeys too!!
- BM_mesh_bm_from_me(bm_dst, me_dst, TRUE, true, ob_dst->shapenr);
+ BM_mesh_bm_from_me(bm_src, me_src, TRUE, true, 0); //TRUE -> should transfer shapekeys too!!
+ BM_mesh_bm_from_me(bm_dst, me_dst, TRUE, true, 0);
- if (!BM_mesh_uv_copy(bm_src, bm_dst, tolerance, radius_interp, interp_pow, no_pow, interp_normals)) {
- return false;
+ if (transfer_mode == UT_USE_NEAREST_FACE) {
+ if (!BM_mesh_uv_copy2(bm_src, bm_dst, tolerance, radius_interp, interp_pow, no_pow, interp_normals,
+ ST_REPLACE_ENOUGH_SHAPEKEY_GROUPS, NULL, tmp_mat)) {
+ return false;
+ }
}
+ //*******copy based on nearest vertex
+ else if (transfer_mode == UT_USE_NEAREST_VERTEX) {
+ if (!BM_mesh_uv_copy(bm_src, bm_dst, tolerance, radius_interp, interp_pow, no_pow, interp_normals)) {
+ return false;
+ }
+ }
+
//transfer the BMesh back to Mesh
BM_mesh_bm_to_me(bm_src, me_src, FALSE);
BM_mesh_bm_to_me(bm_dst, me_dst, TRUE);
@@ -831,7 +860,8 @@
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list