[Bf-blender-cvs] [ee4453f] master: Transfer Data: add main core code and operators.

Bastien Montagne noreply at git.blender.org
Fri Jan 9 19:40:53 CET 2015


Commit: ee4453f08369d8cf910a88763bfb14392ea489cf
Author: Bastien Montagne
Date:   Fri Jan 9 19:11:40 2015 +0100
Branches: master
https://developer.blender.org/rBee4453f08369d8cf910a88763bfb14392ea489cf

Transfer Data: add main core code and operators.

This add code needed to map a CD data layout from source mesh towards destination one,
and code needed to actually transfer data, using BKE's mesh remap generated data.

This allows to transfer most CD layers (vgroups, vcols, uvs...) as well as fake, boolean ones
(like smooth/sharp edges/faces, etc.). Some types are not yet transferable, mainly
shape keys, this is known TODO.

Data transfer can also use some advanced mixing in some cases (mostly, vgroups and vcols).

Notes:
* New transfer operators transfer data from active object towards selected ones.
* Modifier will be committed separately.
* Old weight transfer code (for vgroups) is kept for now, mostly because it is the only
  usable one in weightpaint mode (it transfers from selected object to active one,
  this is not sensible in Object mode, but needed in WeightPaint one). This will be addressed soon.

Again, heavily reviewed and enhanced by Campbell, thanks!

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

M	release/scripts/startup/bl_ui/space_view3d.py
M	release/scripts/startup/bl_ui/space_view3d_toolbar.py
M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/BKE_deform.h
A	source/blender/blenkernel/BKE_object_data_transfer.h
M	source/blender/blenkernel/BKE_object_deform.h
M	source/blender/blenkernel/CMakeLists.txt
M	source/blender/blenkernel/intern/customdata.c
A	source/blender/blenkernel/intern/data_transfer_intern.h
M	source/blender/blenkernel/intern/deform.c
A	source/blender/blenkernel/intern/object_data_transfer.c
M	source/blender/editors/object/CMakeLists.txt
A	source/blender/editors/object/object_data_transfer.c
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/makesrna/RNA_enum_types.h
M	source/blender/makesrna/intern/rna_modifier.c

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

diff --git a/release/scripts/startup/bl_ui/space_view3d.py b/release/scripts/startup/bl_ui/space_view3d.py
index 6120e42..6bd2c4c 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -1095,6 +1095,8 @@ class VIEW3D_MT_object(Menu):
         layout.separator()
 
         layout.operator("object.join")
+        layout.operator("object.data_transfer")
+        layout.operator("object.datalayout_transfer")
 
         layout.separator()
 
diff --git a/release/scripts/startup/bl_ui/space_view3d_toolbar.py b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
index b7fe9c6..7aa80bc 100644
--- a/release/scripts/startup/bl_ui/space_view3d_toolbar.py
+++ b/release/scripts/startup/bl_ui/space_view3d_toolbar.py
@@ -100,6 +100,13 @@ class VIEW3D_PT_tools_object(View3DPanel, Panel):
                 row.operator("object.shade_smooth", text="Smooth")
                 row.operator("object.shade_flat", text="Flat")
 
+            if obj_type in {'MESH'}:
+                col = layout.column(align=True)
+                col.label(text="Data Transfer:")
+                row = col.row(align=True)
+                row.operator("object.data_transfer", text="Data")
+                row.operator("object.datalayout_transfer", text="Data Layout")
+
 
 class VIEW3D_PT_tools_add_object(View3DPanel, Panel):
     bl_category = "Create"
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 30a5889..08edde1 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -41,6 +41,8 @@ extern "C" {
 #include "BLI_sys_types.h"
 #include "BLI_utildefines.h"
 
+#include "DNA_customdata_types.h"
+
 struct BMesh;
 struct ID;
 struct CustomData;
@@ -77,6 +79,9 @@ extern const CustomDataMask CD_MASK_EVERYTHING;
 
 void customData_mask_layers__print(CustomDataMask mask);
 
+typedef void (*cd_interp)(void **sources, const float *weights, const float *sub_weights, int count, void *dest);
+typedef void (*cd_copy)(const void *source, void *dest, int count);
+
 /**
  * Checks if the layer at physical offset \a layer_n (in data->layers) support math
  * the below operations.
@@ -96,6 +101,9 @@ bool CustomData_bmesh_has_free(const struct CustomData *data);
  * implemented for mloopuv/mloopcol, for now.*/
 void CustomData_data_copy_value(int type, const void *source, void *dest);
 
+/* Same as above, but doing advanced mixing. Only available for a few types of data (like colors...). */
+void CustomData_data_mix_value(int type, const void *source, void *dest, const int mixmode, const float mixfactor);
+
 /* compares if data1 is equal to data2.  type is a valid CustomData type
  * enum (e.g. CD_MLOOPUV). the layer type's equal function is used to compare
  * the data, if it exists, otherwise memcmp is used.*/
@@ -246,14 +254,14 @@ void *CustomData_bmesh_get_n(const struct CustomData *data, void *block, int typ
 void *CustomData_bmesh_get_layer_n(const struct CustomData *data, void *block, int n);
 
 bool CustomData_set_layer_name(const struct CustomData *data, int type, int n, const char *name);
+const char *CustomData_get_layer_name(const struct CustomData *data, int type, int n);
 
 /* gets a pointer to the active or first layer of type
  * returns NULL if there is no layer of type
  */
 void *CustomData_get_layer(const struct CustomData *data, int type);
 void *CustomData_get_layer_n(const struct CustomData *data, int type, int n);
-void *CustomData_get_layer_named(const struct CustomData *data, int type,
-                                 const char *name);
+void *CustomData_get_layer_named(const struct CustomData *data, int type, const char *name);
 int CustomData_get_offset(const struct CustomData *data, int type);
 int CustomData_get_n_offset(const struct CustomData *data, int type, int n);
 
@@ -362,6 +370,82 @@ void CustomData_external_read(struct CustomData *data,
 void CustomData_external_reload(struct CustomData *data,
                                 struct ID *id, CustomDataMask mask, int totelem);
 
+/* Mesh-to-mesh transfer data. */
+
+struct MeshPairRemap;
+typedef struct CustomDataTransferLayerMap CustomDataTransferLayerMap;
+
+typedef void (*cd_datatransfer_interp)(
+        const CustomDataTransferLayerMap *laymap, void *dest,
+        void **sources, const float *weights, const int count, const float mix_factor);
+
+/**
+ * Fake CD_LAYERS (those are actually 'real' data stored directly into elements' structs, or otherwise not (directly)
+ * accessible to usual CDLayer system). */
+enum {
+	CD_FAKE             = 1 << 8,
+
+	/* Vertices. */
+	CD_FAKE_MDEFORMVERT = CD_FAKE | CD_MDEFORMVERT,  /* *sigh* due to how vgroups are stored :( . */
+	CD_FAKE_SHAPEKEY    = CD_FAKE | CD_SHAPEKEY,  /* Not available as real CD layer in non-bmesh context. */
+
+	/* Edges. */
+	CD_FAKE_SEAM        = CD_FAKE | 100,  /* UV seam flag for edges. */
+	CD_FAKE_CREASE      = CD_FAKE | CD_CREASE,  /* *sigh*. */
+
+	/* Multiple types of mesh elements... */
+	CD_FAKE_BWEIGHT     = CD_FAKE | CD_BWEIGHT,  /* *sigh*. */
+	CD_FAKE_UV          = CD_FAKE | CD_MLOOPUV,  /* UV flag, because we handle both loop's UVs and poly's textures. */
+
+	CD_FAKE_SHARP       = CD_FAKE | 200,  /* Sharp flag for edges, smooth flag for faces. */
+};
+
+enum {
+	ME_VERT = 1 << 0,
+	ME_EDGE = 1 << 1,
+	ME_POLY = 1 << 2,
+	ME_LOOP = 1 << 3,
+};
+
+/**
+ * How to filter out some elements (to leave untouched).
+ * Note those options are highly dependent on type of transferred data! */
+enum {
+	CDT_MIX_NOMIX                   = -1,  /* Special case, only used because we abuse 'copy' CD callback. */
+	CDT_MIX_TRANSFER                = 0,
+	CDT_MIX_REPLACE_ABOVE_THRESHOLD = 1,
+	CDT_MIX_REPLACE_BELOW_THRESHOLD = 2,
+	CDT_MIX_MIX                     = 16,
+	CDT_MIX_ADD                     = 17,
+	CDT_MIX_SUB                     = 18,
+	CDT_MIX_MUL                     = 19,
+	/* etc. etc. */
+};
+
+typedef struct CustomDataTransferLayerMap {
+	CustomDataTransferLayerMap *next, *prev;
+
+	int data_type;
+	int mix_mode;
+	float mix_factor;
+	const float *mix_weights;  /* If non-NULL, array of weights, one for each dest item, replaces mix_factor. */
+
+	void *data_src;      /* Data source array (can be regular CD data, vertices/edges/etc., keyblocks...). */
+	void *data_dst;      /* Data dest array (same type as dat_src). */
+	int   data_src_n;    /* Index to affect in data_src (used e.g. for vgroups). */
+	int   data_dst_n;    /* Index to affect in data_dst (used e.g. for vgroups). */
+	size_t elem_size;    /* Size of one element of data_src/data_dst. */
+
+	size_t data_size;    /* Size of actual data we transfer. */
+	size_t data_offset;  /* Offset of actual data we transfer (in element contained in data_src/dst). */
+	uint64_t data_flag;  /* For bitflag transfer, flag(s) to affect in transfered data. */
+
+	cd_datatransfer_interp interp;
+} CustomDataTransferLayerMap;
+
+/* Those functions assume src_n and dst_n layers of given type exist in resp. src and dst. */
+void CustomData_data_transfer(const struct MeshPairRemap *me_remap, const CustomDataTransferLayerMap *laymap);
+
 #ifdef __cplusplus
 }
 #endif
diff --git a/source/blender/blenkernel/BKE_deform.h b/source/blender/blenkernel/BKE_deform.h
index e203549..0831203 100644
--- a/source/blender/blenkernel/BKE_deform.h
+++ b/source/blender/blenkernel/BKE_deform.h
@@ -39,6 +39,10 @@ struct Object;
 struct ListBase;
 struct bDeformGroup;
 struct MDeformVert;
+struct MVert;
+struct MEdge;
+struct MLoop;
+struct MPoly;
 
 struct bDeformGroup *BKE_defgroup_new(struct Object *ob, const char *name);
 void                 defgroup_copy_list(struct ListBase *lb1, struct ListBase *lb2);
@@ -85,6 +89,19 @@ void defvert_normalize_lock_map(struct MDeformVert *dvert,
                                 const bool *vgroup_subset, const int vgroup_tot,
                                 const bool *lock_flags, const int defbase_tot);
 
+/* Utilities to 'extract' a given vgroup into a simple float array, for verts, but also edges/polys/loops. */
+void BKE_defvert_extract_vgroup_to_vertweights(
+        struct MDeformVert *dvert, const int defgroup, const int num_verts, float *r_weights, const bool invert_vgroup);
+void BKE_defvert_extract_vgroup_to_edgeweights(
+        struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MEdge *edges, const int num_edges,
+        float *r_weights, const bool invert_vgroup);
+void BKE_defvert_extract_vgroup_to_loopweights(
+        struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MLoop *loops, const int num_loops,
+        float *r_weights, const bool invert_vgroup);
+void BKE_defvert_extract_vgroup_to_polyweights(
+        struct MDeformVert *dvert, const int defgroup, const int num_verts, struct MLoop *loops, const int num_loops,
+        struct MPoly *polys, const int num_polys, float *r_weights, const bool invert_vgroup);
+
 /* utility function, note that MAX_VGROUP_NAME chars is the maximum string length since its only
  * used with defgroups currently */
 
diff --git a/source/blender/blenkernel/BKE_object_data_transfer.h b/source/blender/blenkernel/BKE_object_data_transfer.h
new file mode 100644
index 0000000..fe21890
--- /dev/null
+++ b/source/blender/blenkernel/BKE_object_data_transfer.h
@@ -0,0 +1,158 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software  Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserve

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list