[Bf-blender-cvs] [7af5cd8] strand_editmode: Extended Mesh <-> BMesh copy function versions for specifying custom data masks explicitly.

Lukas Tönne noreply at git.blender.org
Fri Jan 30 10:56:54 CET 2015


Commit: 7af5cd858d4a5fdc28808bdbd7b63fa7a739e3db
Author: Lukas Tönne
Date:   Fri Jan 30 10:54:05 2015 +0100
Branches: strand_editmode
https://developer.blender.org/rB7af5cd858d4a5fdc28808bdbd7b63fa7a739e3db

Extended Mesh <-> BMesh copy function versions for specifying custom
data masks explicitly.

A dummy mesh is used for strand edit undo storage like in mesh edit
to prevent unnecessary code duplication. However, when copying from/to
BMesh only the mesh data layers are copied by default, omitting the new
data layers for strands (currently only MSurfaceSample hair root data).

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

M	source/blender/blenkernel/BKE_customdata.h
M	source/blender/blenkernel/intern/customdata.c
M	source/blender/bmesh/intern/bmesh_mesh_conv.c
M	source/blender/bmesh/intern/bmesh_mesh_conv.h
M	source/blender/editors/hair/hair_undo.c

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

diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 285bd7f..86e66f7 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -58,6 +58,7 @@ extern const CustomDataMask CD_MASK_EDITMESH;
 extern const CustomDataMask CD_MASK_DERIVEDMESH;
 extern const CustomDataMask CD_MASK_BMESH;
 extern const CustomDataMask CD_MASK_FACECORNERS;
+extern const CustomDataMask CD_MASK_STRANDS;
 extern const CustomDataMask CD_MASK_EVERYTHING;
 
 /* for ORIGINDEX layer type, indicates no original index for this element */
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index 99bd42d..3bb19cb 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -1320,6 +1320,12 @@ const CustomDataMask CD_MASK_BMESH =
 const CustomDataMask CD_MASK_FACECORNERS =  /* XXX Not used anywhere! */
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
     CD_MASK_MLOOPCOL | CD_MASK_NORMAL | CD_MASK_MLOOPTANGENT;
+const CustomDataMask CD_MASK_STRANDS =
+    CD_MASK_MVERT | CD_MASK_MEDGE |
+    CD_MASK_MSTICKY | CD_MASK_MDEFORMVERT | CD_MASK_MCOL |
+    CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
+    CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
+    CD_MASK_MSURFACE_SAMPLE;
 const CustomDataMask CD_MASK_EVERYTHING =
     CD_MASK_MVERT | CD_MASK_MSTICKY /* DEPRECATED */ | CD_MASK_MDEFORMVERT | CD_MASK_MEDGE | CD_MASK_MFACE |
     CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_NORMAL /* | CD_MASK_POLYINDEX */ | CD_MASK_PROP_FLT |
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index cb75d75..9852113 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -227,6 +227,17 @@ static BMFace *bm_face_create_from_mpoly(MPoly *mp, MLoop *ml,
 void BM_mesh_bm_from_me(BMesh *bm, Mesh *me,
                         const bool calc_face_normal, const bool set_key, int act_key_nr)
 {
+	BM_mesh_bm_from_me_ex(bm, me, CD_MASK_BMESH, calc_face_normal, set_key, act_key_nr);
+}
+
+/**
+ * \brief Mesh -> BMesh
+ *
+ * \warning This function doesn't calculate face normals.
+ */
+void BM_mesh_bm_from_me_ex(BMesh *bm, Mesh *me, CustomDataMask mask,
+                           const bool calc_face_normal, const bool set_key, int act_key_nr)
+{
 	MVert *mvert;
 	MEdge *medge;
 	MLoop *mloop;
@@ -252,10 +263,10 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me,
 
 	if (!me || !me->totvert) {
 		if (me) { /*no verts? still copy customdata layout*/
-			CustomData_copy(&me->vdata, &bm->vdata, CD_MASK_BMESH, CD_ASSIGN, 0);
-			CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_ASSIGN, 0);
-			CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_ASSIGN, 0);
-			CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_ASSIGN, 0);
+			CustomData_copy(&me->vdata, &bm->vdata, mask, CD_ASSIGN, 0);
+			CustomData_copy(&me->edata, &bm->edata, mask, CD_ASSIGN, 0);
+			CustomData_copy(&me->ldata, &bm->ldata, mask, CD_ASSIGN, 0);
+			CustomData_copy(&me->pdata, &bm->pdata, mask, CD_ASSIGN, 0);
 
 			CustomData_bmesh_init_pool(&bm->vdata, me->totvert, BM_VERT);
 			CustomData_bmesh_init_pool(&bm->edata, me->totedge, BM_EDGE);
@@ -267,10 +278,10 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me,
 
 	vtable = MEM_mallocN(sizeof(void **) * me->totvert, "mesh to bmesh vtable");
 
-	CustomData_copy(&me->vdata, &bm->vdata, CD_MASK_BMESH, CD_CALLOC, 0);
-	CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
-	CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
-	CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
+	CustomData_copy(&me->vdata, &bm->vdata, mask, CD_CALLOC, 0);
+	CustomData_copy(&me->edata, &bm->edata, mask, CD_CALLOC, 0);
+	CustomData_copy(&me->ldata, &bm->ldata, mask, CD_CALLOC, 0);
+	CustomData_copy(&me->pdata, &bm->pdata, mask, CD_CALLOC, 0);
 
 	/* make sure uv layer names are consisten */
 	totuv = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
@@ -571,6 +582,11 @@ BLI_INLINE void bmesh_quick_edgedraw_flag(MEdge *med, BMEdge *e)
 
 void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface)
 {
+	BM_mesh_bm_to_me_ex(bm, me, CD_MASK_MESH, do_tessface);
+}
+
+void BM_mesh_bm_to_me_ex(BMesh *bm, Mesh *me, CustomDataMask mask, bool do_tessface)
+{
 	MLoop *mloop;
 	MPoly *mpoly;
 	MVert *mvert, *oldverts;
@@ -630,10 +646,10 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, bool do_tessface)
 	me->totface = 0;
 	me->act_face = -1;
 
-	CustomData_copy(&bm->vdata, &me->vdata, CD_MASK_MESH, CD_CALLOC, me->totvert);
-	CustomData_copy(&bm->edata, &me->edata, CD_MASK_MESH, CD_CALLOC, me->totedge);
-	CustomData_copy(&bm->ldata, &me->ldata, CD_MASK_MESH, CD_CALLOC, me->totloop);
-	CustomData_copy(&bm->pdata, &me->pdata, CD_MASK_MESH, CD_CALLOC, me->totpoly);
+	CustomData_copy(&bm->vdata, &me->vdata, mask, CD_CALLOC, me->totvert);
+	CustomData_copy(&bm->edata, &me->edata, mask, CD_CALLOC, me->totedge);
+	CustomData_copy(&bm->ldata, &me->ldata, mask, CD_CALLOC, me->totloop);
+	CustomData_copy(&bm->pdata, &me->pdata, mask, CD_CALLOC, me->totpoly);
 
 	CustomData_add_layer(&me->vdata, CD_MVERT, CD_ASSIGN, mvert, me->totvert);
 	CustomData_add_layer(&me->edata, CD_MEDGE, CD_ASSIGN, medge, me->totedge);
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.h b/source/blender/bmesh/intern/bmesh_mesh_conv.h
index ab9d7a0..f910c69 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.h
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.h
@@ -32,7 +32,10 @@
  *  \ingroup bmesh
  */
 
+#include "BLI_sys_types.h"
+
 struct Mesh;
+typedef uint64_t CustomDataMask;
 
 void BM_mesh_cd_validate(BMesh *bm);
 void BM_mesh_cd_flag_ensure(BMesh *bm, struct Mesh *mesh, const char cd_flag);
@@ -41,6 +44,9 @@ char BM_mesh_cd_flag_from_bmesh(BMesh *bm);
 
 void BM_mesh_bm_from_me(BMesh *bm, struct Mesh *me,
                         const bool calc_face_normal, const bool set_key, int act_key_nr);
+void BM_mesh_bm_from_me_ex(BMesh *bm, struct Mesh *me, CustomDataMask mask,
+                        const bool calc_face_normal, const bool set_key, int act_key_nr);
 void BM_mesh_bm_to_me(BMesh *bm, struct Mesh *me, bool do_tessface);
+void BM_mesh_bm_to_me_ex(BMesh *bm, struct Mesh *me, CustomDataMask mask, bool do_tessface);
 
 #endif /* __BMESH_MESH_CONV_H__ */
diff --git a/source/blender/editors/hair/hair_undo.c b/source/blender/editors/hair/hair_undo.c
index 1459768..c3096e5 100644
--- a/source/blender/editors/hair/hair_undo.c
+++ b/source/blender/editors/hair/hair_undo.c
@@ -96,7 +96,7 @@ static void *strands_edit_to_undo(void *editv, void *UNUSED(obdata))
 
 	/* BM_mesh_validate(em->bm); */ /* for troubleshooting */
 
-	BM_mesh_bm_to_me(edit->bm, &undo->me, false);
+	BM_mesh_bm_to_me_ex(edit->bm, &undo->me, CD_MASK_STRANDS, false);
 
 	undo->selectmode = edit->bm->selectmode;
 	undo->shapenr = edit->bm->shapenr;
@@ -126,7 +126,7 @@ static void strands_undo_to_edit(void *undov, void *editv, void *UNUSED(obdata))
 	
 	BKE_editstrands_free(edit);
 	
-	BM_mesh_bm_from_me(bm, &undo->me, true, false, undo->shapenr);
+	BM_mesh_bm_from_me_ex(bm, &undo->me, CD_MASK_STRANDS, false, false, undo->shapenr);
 	
 	*edit = *edit_tmp;




More information about the Bf-blender-cvs mailing list