[Bf-blender-cvs] [2f78fa3] mesh-transfer-data: 'Transfer DataLayout' operator (WIP).

Bastien Montagne noreply at git.blender.org
Tue Nov 18 12:58:33 CET 2014


Commit: 2f78fa38a8f40a80f5c8b14c7077f6364ecb880f
Author: Bastien Montagne
Date:   Tue Nov 18 12:52:30 2014 +0100
Branches: mesh-transfer-data
https://developer.blender.org/rB2f78fa38a8f40a80f5c8b14c7077f6364ecb880f

'Transfer DataLayout' operator (WIP).

Functionnal, but not complete yet. Should be mostly usable though from modifier.

Notes:
* The logic of current 'transferdata' pre-process on data layout is reused here,
  avoids duplicating code and ensure consistency in behavior, and does not add
  *too* much complexity.
* Also fixed some issues and mistakes in that part that were affecting
  TransferData feature itself too. Will need at least one more review pass,
  though, this is complex logical code.
* VGroup: The 'delete' part is not yet implemented (option of plain operator,
          to get an exact same data layout as source).
          Need to first transfer some vgroup stuff from ED to BKE (esp. delete logic),
          will do that in master as separate patch.
* Standalone part of the op is empty right now (but this should be mostly monkey coding).

===================================================================

M	release/scripts/startup/bl_ui/properties_data_modifier.py
M	source/blender/blenkernel/BKE_object_data_transfer.h
M	source/blender/blenkernel/intern/data_transfer_intern.h
M	source/blender/blenkernel/intern/deform.c
M	source/blender/blenkernel/intern/object_data_transfer.c
M	source/blender/editors/object/object_data_transfer.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_modifier.c
M	source/blender/editors/object/object_ops.c
M	source/blender/makesrna/RNA_access.h

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index a5474fe..14c88a6 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -1330,7 +1330,7 @@ class DATA_PT_modifiers(ModifierButtonsPanel, Panel):
         col.prop(md, "mix_factor")
 
         col = split.column()
-        col.label("")
+        col.operator("object.datalayout_transfer", text="Generate Data Layers")
         row = col.row(align=True)
         row.prop_search(md, "vertex_group", ob, "vertex_groups", text="")
         sub = row.row(align=True)
diff --git a/source/blender/blenkernel/BKE_object_data_transfer.h b/source/blender/blenkernel/BKE_object_data_transfer.h
index 858534c..6b69740 100644
--- a/source/blender/blenkernel/BKE_object_data_transfer.h
+++ b/source/blender/blenkernel/BKE_object_data_transfer.h
@@ -124,9 +124,13 @@ enum {
 #endif
 };
 
+void BKE_object_data_transfer_layout(
+        struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_delete,
+        const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX]);
+
 bool BKE_object_data_transfer_mesh(
         struct Scene *scene,
-        struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_create,
+        struct Object *ob_src, struct Object *ob_dst, const int data_types, bool use_create,
         const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
         struct SpaceTransform *space_transform, const float max_distance, const float precision,
         const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
@@ -135,7 +139,7 @@ bool BKE_object_data_transfer_mesh(
 bool BKE_object_data_transfer_dm(
         struct Scene *scene,
         struct Object *ob_src, struct Object *ob_dst, struct DerivedMesh *dm_dst,
-        const int data_types, const bool use_create,
+        const int data_types, bool use_create,
         const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
         struct SpaceTransform *space_transform, const float max_distance, const float ray_radius,
         const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
diff --git a/source/blender/blenkernel/intern/data_transfer_intern.h b/source/blender/blenkernel/intern/data_transfer_intern.h
index 54e5e16..1858641 100644
--- a/source/blender/blenkernel/intern/data_transfer_intern.h
+++ b/source/blender/blenkernel/intern/data_transfer_intern.h
@@ -52,9 +52,9 @@ void data_transfer_layersmapping_add_item(
 /* Type-specific. */
 
 bool data_transfer_layersmapping_vgroups(
-        struct ListBase *r_map, const int mix_mode, const float mix_factor,
-        const float *mix_weights, const int num_elem_dst, const bool use_create,
+        struct ListBase *r_map, const int mix_mode, const float mix_factor, const float *mix_weights,
+        const int num_elem_dst, const bool use_create, const bool use_delete,
         struct Object *ob_src, struct Object *ob_dst, struct CustomData *cd_src, struct CustomData *cd_dst,
-        const bool dup_dst, const int fromlayers, const int tolayers);
+        const bool use_dupref_dst, const int fromlayers, const int tolayers);
 
 #endif  /* __DATA_TRANSFER_INTERN_H__ */
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 6420db4..7615c78 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -1112,18 +1112,20 @@ static void vgroups_datatransfer_interp(const CustomDataTransferLayerMap *laymap
 
 static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(
         ListBase *r_map, const int mix_mode, const float mix_factor, const float *mix_weights,
-        const int UNUSED(num_elem_dst), const bool use_create,
-        Object *ob_src, Object *ob_dst, MDeformVert *data_src, MDeformVert *data_dst, const bool UNUSED(dup_dst),
+        const int num_elem_dst, const bool use_create, const bool use_delete,
+        Object *ob_src, Object *ob_dst, MDeformVert *data_src, MDeformVert *data_dst,
+        CustomData *UNUSED(cd_src), CustomData *cd_dst, const bool UNUSED(use_dupref_dst),
         const int tolayers, bool *use_layers_src, const int num_layers_src)
 {
 	int idx_src;
 	int idx_dst;
+	int tot_dst = BLI_listbase_count(&ob_dst->defbase);
 
 	const size_t elem_size = sizeof(*((MDeformVert *)NULL));
 
 	switch (tolayers) {
 		case DT_LAYERS_INDEX_DST:
-			idx_dst = BLI_listbase_count(&ob_dst->defbase);
+			idx_dst = tot_dst;
 
 			/* Find last source actually used! */
 			idx_src = num_layers_src;
@@ -1140,19 +1142,44 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(
 					ob_dst->actdef = BLI_listbase_count(&ob_dst->defbase);
 				}
 			}
-			while (idx_src--) {
-				if (!use_layers_src[idx_src]) {
-					continue;
+			else if (use_delete && idx_dst > idx_src) {
+				while (idx_dst-- > idx_src) {
+					/* TODO - needs refactor of vgroup code first (move some func from ED to BKE) */
+				}
+			}
+			if (r_map) {
+				/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
+				 * Again, use_create is not relevant in this case */
+				if (!data_dst) {
+					data_dst = CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_CALLOC, NULL, num_elem_dst);
+				}
+
+				while (idx_src--) {
+					if (!use_layers_src[idx_src]) {
+						continue;
+					}
+					data_transfer_layersmapping_add_item(r_map, CD_FAKE_MDEFORMVERT, mix_mode, mix_factor, mix_weights,
+					                                     data_src, data_dst, idx_src, idx_src,
+					                                     elem_size, 0, 0, 0, vgroups_datatransfer_interp);
 				}
-				data_transfer_layersmapping_add_item(r_map, CD_FAKE_MDEFORMVERT, mix_mode, mix_factor, mix_weights,
-				                                     data_src, data_dst, idx_src, idx_src,
-				                                     elem_size, 0, 0, 0, vgroups_datatransfer_interp);
 			}
 			break;
 		case DT_LAYERS_NAME_DST:
 			{
 				bDeformGroup *dg_src;
-				for (idx_src = 0, dg_src = ob_src->defbase.first; idx_src < num_layers_src; idx_src++, dg_src = dg_src->next) {
+				bool *data_dst_to_delete = NULL;
+
+				if (use_delete) {
+					if (tot_dst) {
+						data_dst_to_delete = MEM_mallocN(sizeof(*data_dst_to_delete) * (size_t)tot_dst, __func__);
+						memset(data_dst_to_delete, true, sizeof(*data_dst_to_delete) * (size_t)tot_dst);
+					}
+				}
+
+				for (idx_src = 0, dg_src = ob_src->defbase.first;
+				     idx_src < num_layers_src;
+				     idx_src++, dg_src = dg_src->next)
+				{
 					if (!use_layers_src[idx_src]) {
 						continue;
 					}
@@ -1166,9 +1193,34 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(
 						ob_dst->actdef = BLI_listbase_count(&ob_dst->defbase);
 						idx_dst = ob_dst->actdef - 1;
 					}
-					data_transfer_layersmapping_add_item(r_map, CD_FAKE_MDEFORMVERT, mix_mode, mix_factor, mix_weights,
-					                                     data_src, data_dst, idx_src, idx_dst,
-					                                     elem_size, 0, 0, 0, vgroups_datatransfer_interp);
+					else if (data_dst_to_delete) {
+						data_dst_to_delete[idx_dst] = false;
+					}
+					if (r_map) {
+						/* At this stage, we **need** a valid CD_MDEFORMVERT layer on dest!
+						 * Again, use_create is not relevant in this case */
+						if (!data_dst) {
+							data_dst = CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_CALLOC, NULL, num_elem_dst);
+						}
+
+						data_transfer_layersmapping_add_item(
+						        r_map, CD_FAKE_MDEFORMVERT, mix_mode, mix_factor, mix_weights,
+						        data_src, data_dst, idx_src, idx_dst,
+						        elem_size, 0, 0, 0, vgroups_datatransfer_interp);
+					}
+				}
+				if (data_dst_to_delete) {
+					/* Note: This won't affect newly created vgroups, if any, since tot_dst has not been updated!
+					 *       Also, looping backward ensures us we do not suffer from index shifting
+					 *       when deleting a vgroup.
+					 */
+					for (idx_dst = tot_dst; idx_dst--;) {
+						if (data_dst_to_delete[idx_dst]) {
+							/* TODO - needs refactor of vgroup code first (move some func from ED to BKE) */
+						}
+					}
+
+					MEM_freeN(data_dst_to_delete);
 				}
 				break;
 			}
@@ -1181,26 +1233,29 @@ static bool data_transfer_layersmapping_vgroups_multisrc_to_dst(
 
 bool data_transfer_layersmapping_vgroups(
         ListBase *r_map, const int mix_mode, const float mix_factor, const float *mix_weights,
-        const int num_elem_dst, const bool use_create, Object *ob_src, Object *ob_dst,
-        CustomData *cd_src, CustomData *cd_dst, const bool dup_dst, const int fromlayers, const int tolayers)
+        const int num_elem_dst, const bool use_create, const bool use_delete, Object *ob_src, Object *ob_dst,
+        CustomData *cd_src, CustomData *cd_dst, const bool use_dupref_dst, const int fromlayers, const int tolayers)
 {
 	int idx_src, idx_dst;
 	MDeformVert *data_src, *data_dst = NULL;
 
 	const size_t elem_size = sizeof(*((MDeformVert *)NULL));
 
+	/* Note: in theory, we could still create vgroup layout on dest (if asked for it), but... :/ */
 	if (!(data_src = CustomData_get_layer(cd_src, CD_MDEFORMVERT))) {
-		return false;
+		if (use_delete) {
+			/* TODO - needs refactor of vgroup code first (move some func from ED to BKE) */
+		}
+		return true;
 	}
 
-	if (!CustomData_has_layer(cd_dst, CD_MDEFORMVERT)) {
-		/* Note: with vgroups, datalayer is a mere container, we can create it */
-		/* TODO: do not create when not needed (i.e. !use_create and no already existing vgroup), will be done in ongoing refactor. */
-		data_dst = CustomData_add_layer(cd_dst, CD_MDEFORMVERT, CD_CALLOC, NULL, num_elem_dst);
-	}
-	else {
+	/* Note: VGroups are a bit hairy, we may have (empty) vgroups with no data_dst, so we do not 'fail' on missing
+	 *       cdlayer, nor create it right now.
+	 *       In other words, we have to take care of p

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list