Revision: 60043 http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=60043 Author: walid Date: 2013-09-11 11:41:11 +0000 (Wed, 11 Sep 2013) Log Message: ----------- code rewrite: adding transfer by topology for vertex based data types
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 branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_shapekey.c branches/soc-2013-meshdata_transfer/source/blender/editors/object/object_vgroup.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-09-11 11:18:08 UTC (rev 60042) +++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.c 2013-09-11 11:41:11 UTC (rev 60043) @@ -78,12 +78,6 @@ return true; } -typedef enum TransferMode { - TRANSFER_BY_INDEX = 1, - TRANSFER_BY_TOPOLOGY = 2, - TRANSFER_BY_INTERPOLATION = 3, -} TransferMode; - typedef struct BMFace_match { BMFace *f_src; BMFace *f_dst; @@ -96,14 +90,28 @@ BMVert *v_dst; } BMVert_match; -static void BM_mesh_cd_array_transfer(CustomData *cd_src, BMElem **array_src, int array_src_count, +//---------------helping functions----------------------- +void *BM_mesh_mapping(BMesh *bm_src, BMesh *bm_dst, const char htype); + +//--------------index based transfer functions ---------- +static void BM_mesh_cd_transfer_array(CustomData *cd_src, BMElem **array_src, int array_src_count, + CustomData *cd_dst, BMElem **array_dst, int array_dst_count, + const int layer_type, const struct ReplaceLayerInfo *UNUSED_replace_info); + +static void BM_mesh_transfer_aligned(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, + const struct ReplaceLayerInfo *replace_info); + +//--------------topology based transfer functions ------ +void BM_mesh_cd_transfer_mapped(CustomData *cd_src, BMElem **array_src, int array_src_count, CustomData *cd_dst, BMElem **array_dst, int array_dst_count, - const int layer_type, const struct ReplaceLayerInfo *UNUSED_replace_info); + const int layer_type, const struct ReplaceLayerInfo *UNUSED_replace_info, + int *index_mapping); -static void BM_mesh_aligned_transfer(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, - const struct ReplaceLayerInfo *replace_info); +static void BM_mesh_transfer_mapped(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, + const struct ReplaceLayerInfo *replace_info); -bool BM_mesh_data_copy2(BMesh *bm_src, BMesh* bm_dst, const struct ReplaceLayerInfo *replace_info, int type) +bool BM_mesh_data_copy2(BMesh *bm_src, BMesh* bm_dst, const struct ReplaceLayerInfo *replace_info, int type, + TransferMode transfer_mode) { /* BMFace *f_src, *f_dst; @@ -112,7 +120,8 @@ int a; */ //stub - TransferMode transfer_mode = TRANSFER_BY_INDEX; +// TransferMode transfer_mode = TRANSFER_BY_INDEX; //working for the UV, Colors & DeformVert +// TransferMode transfer_mode = TRANSFER_BY_TOPOLOGY; //+-------------+ //| | @@ -146,15 +155,28 @@ switch (type) { case CD_SHAPEKEY: case CD_MDEFORMVERT: - BM_mesh_aligned_transfer(bm_src, bm_dst, BM_VERT, CD_SHAPEKEY, replace_info); + BM_mesh_transfer_aligned(bm_src, bm_dst, BM_VERT, type, replace_info); break; case CD_MLOOPCOL: case CD_MLOOPUV: - BM_mesh_aligned_transfer(bm_src, bm_dst, BM_LOOP, type, replace_info); + BM_mesh_transfer_aligned(bm_src, bm_dst, BM_LOOP, type, replace_info); } } + else if(transfer_mode == TRANSFER_BY_TOPOLOGY) { + switch (type) { + case CD_SHAPEKEY: + case CD_MDEFORMVERT: + BM_mesh_transfer_mapped(bm_src, bm_dst, BM_VERT, type, replace_info); + break; + + case CD_MLOOPCOL: + case CD_MLOOPUV: + BM_mesh_transfer_mapped(bm_src, bm_dst, BM_LOOP, type, replace_info); + } + } + //transfer by interpolation (3.1) // | // | @@ -196,7 +218,7 @@ return true; } -static void BM_mesh_cd_array_transfer(CustomData *cd_src, BMElem **array_src, int array_src_count, +static void BM_mesh_cd_transfer_array(CustomData *cd_src, BMElem **array_src, int array_src_count, CustomData *cd_dst, BMElem **array_dst, int array_dst_count, const int layer_type, const struct ReplaceLayerInfo *UNUSED(replace_info)) { @@ -218,7 +240,38 @@ } } -static void BM_mesh_aligned_transfer(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, +void BM_mesh_cd_transfer_mapped(CustomData *cd_src, BMElem **array_src, int array_src_count, + CustomData *cd_dst, BMElem **array_dst, int array_dst_count, + const int layer_type, const struct ReplaceLayerInfo *UNUSED(replace_info), + int *index_mapping) +{ + //... copy between arrays with a mapping! ... + + if ((array_dst && array_src) && (array_src_count == array_dst_count)) { + int i; + + void *ptr; + + for (i = 0; i < array_dst_count; i++) { + + BMElem *ele_src; + BMElem *ele_dst; + + if (index_mapping[i] == -1) { //shall never be reached!! + continue; + } + + ele_src = array_src[index_mapping[i]]; + ele_dst = array_dst[i]; + + ptr = CustomData_bmesh_get(cd_src, ele_src->head.data, layer_type); + CustomData_bmesh_set(cd_dst, ele_dst->head.data, layer_type, ptr); + + } + } +} + +static void BM_mesh_transfer_aligned(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, const struct ReplaceLayerInfo *replace_info) { int array_dst_len; @@ -286,6 +339,106 @@ ///should the pdata be associated to the FACES_OF_MESH? } - BM_mesh_cd_array_transfer(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info); + BM_mesh_cd_transfer_array(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info); } +static void BM_mesh_transfer_mapped(BMesh *bm_src, BMesh *bm_dst, const char htype, const int layer_type, + const struct ReplaceLayerInfo *replace_info) +{ + int array_dst_len; + int array_src_len; + + BMElem **array_src; + BMElem **array_dst; + + CustomData *cd_dst; + CustomData *cd_src; + + int *index_mapping; + switch (htype) { + case BM_VERT: + array_src = BM_iter_as_arrayN(bm_src, BM_VERTS_OF_MESH, NULL, &array_src_len, NULL, 0); + array_dst = BM_iter_as_arrayN(bm_dst, BM_VERTS_OF_MESH, NULL, &array_dst_len, NULL, 0); + index_mapping = BM_mesh_mapping(bm_src, bm_dst, BM_VERT); + break; + + case BM_LOOP: + break; + + default: + break; + } + + + /* this could be its own function even */ + switch (htype) { + case BM_VERT: + cd_src = &bm_src->vdata; + cd_dst = &bm_dst->vdata; + break; + + case BM_EDGE: + cd_src = &bm_src->edata; + cd_dst = &bm_dst->edata; + break; + + case BM_LOOP: + cd_src = &bm_src->ldata; + cd_dst = &bm_dst->ldata; + break; + + ///should the pdata be associated to the FACES_OF_MESH? + } + +// BM_mesh_cd_transfer_array(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info); + + BM_mesh_cd_transfer_mapped(cd_src, array_src, array_src_len, cd_dst, array_dst, array_dst_len, layer_type, replace_info, + index_mapping); +} + +void *BM_mesh_mapping(BMesh *bm_src, BMesh *bm_dst, const char htype) +{ + BMVert *v_src, *v_dst; + BMIter iter; + int a; + int *index_mapping; + + //does the bm_src get affected when we do_tesselation ? + BMBVHTree *bmtree_src; + + BMEditMesh *em_src;// = BKE_editmesh_create(bm_src, true); + em_src = BKE_editmesh_create(bm_src, true); + bmtree_src = BKE_bmbvh_new(em_src, 0, NULL, false); + + switch (htype) { + case BM_VERT: + index_mapping = MEM_mallocN(bm_dst->totvert, "index_mapping bmesh_data_transfer.c"); +/// BM_ITER_MESH_INDEX (v_dst, &iter, bm_dst, BM_VERTS_OF_MESH, a) { + for (v_dst = BM_iter_new(&iter, bm_dst, BM_VERTS_OF_MESH, NULL), a = 0; v_dst; v_dst = BM_iter_step(&iter), (a)++) { + + v_src = BKE_bmbvh_find_vert_closest(bmtree_src, v_dst->co, FLT_MAX); + if (v_src != NULL) { + index_mapping[a] = v_src->head.index; + } + else { + index_mapping[a] = -1; + } + + } + + break; + case BM_FACE: + + break; + default: + ///raises an error! +// BKE_bmbvh_free(bmtree_src); + return false; + //break; + } + +///raises an error! +// BKE_bmbvh_free(bmtree_src); + + return index_mapping; +} 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-09-11 11:18:08 UTC (rev 60042) +++ branches/soc-2013-meshdata_transfer/source/blender/bmesh/tools/bmesh_data_transfer.h 2013-09-11 11:41:11 UTC (rev 60043) @@ -48,6 +48,12 @@ int dst_lay_end; } ReplaceLayerInfo; +typedef enum TransferMode { + TRANSFER_BY_INDEX = 1, + TRANSFER_BY_TOPOLOGY = 2, + TRANSFER_BY_INTERPOLATION = 3, +} TransferMode; + struct BM_loops_per_face_mapping; bool BKE_bmesh_calc_relative_deform(const int v_count, const float (*vert_cos_src)[], const float (*vert_cos_dst)[], @@ -79,7 +85,8 @@ struct BM_loops_per_face_mapping *fl_table); bool BM_mesh_data_copy(BMesh *bm_src, BMesh* bm_dst, int type, const struct ReplaceLayerInfo *replace_info, bool relative_to_target, float tmp_mat[4][4], bool use_tolerance, float tolerance); -bool BM_mesh_data_copy2(BMesh *bm_src, BMesh* bm_dst, const struct ReplaceLayerInfo *replace_info, int type); +bool BM_mesh_data_copy2(BMesh *bm_src, BMesh* bm_dst, const struct ReplaceLayerInfo *replace_info, int type, + TransferMode transfer_mode); #endif /* __BMESH_DATA_TRANSFER_H__ */ 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-09-11 11:18:08 UTC (rev 60042) +++ branches/soc-2013-meshdata_transfer/source/blender/editors/mesh/mesh_data.c 2013-09-11 11:41:11 UTC (rev 60043) @@ -491,6 +491,16 @@ {0, NULL, 0, NULL, NULL} }; +static EnumPropertyItem transfer_mode_item[] = { + {TRANSFER_BY_INDEX, + "TRANSFER_BY_INDEX", 0, "By index", "copy between identical indices meshes"}, + {TRANSFER_BY_TOPOLOGY, @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs