don't store bevel weights or edge crease customdata layers in editmode unless they...
authorCampbell Barton <ideasman42@gmail.com>
Thu, 10 Jan 2013 04:43:31 +0000 (04:43 +0000)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 10 Jan 2013 04:43:31 +0000 (04:43 +0000)
configurable in 'Geometry Data' panel, will be added when running crease edges transform for example.

20 files changed:
release/scripts/startup/bl_ui/properties_data_mesh.py
source/blender/blenkernel/BKE_DerivedMesh.h
source/blender/blenkernel/BKE_blender.h
source/blender/blenkernel/BKE_customdata.h
source/blender/blenkernel/BKE_mesh.h
source/blender/blenkernel/intern/DerivedMesh.c
source/blender/blenkernel/intern/cdderivedmesh.c
source/blender/blenkernel/intern/customdata.c
source/blender/blenkernel/intern/editderivedmesh.c
source/blender/blenkernel/intern/mesh.c
source/blender/blenkernel/intern/modifiers_bmesh.c
source/blender/blenloader/intern/readfile.c
source/blender/bmesh/bmesh_class.h
source/blender/bmesh/intern/bmesh_mesh_conv.c
source/blender/bmesh/intern/bmesh_mesh_conv.h
source/blender/editors/mesh/editmesh_select.c
source/blender/editors/space_view3d/view3d_buttons.c
source/blender/editors/transform/transform_conversions.c
source/blender/makesdna/DNA_mesh_types.h
source/blender/makesrna/intern/rna_mesh.c

index 538063cb038f543e2e2fd6c70c4a6d45ef7dbb93..373d727063ea716f0b93988933062c04dea49f09 100644 (file)
@@ -372,17 +372,20 @@ class DATA_PT_customdata(MeshButtonsPanel, Panel):
     def draw(self, context):
         layout = self.layout
 
-        # me = context.mesh
+        obj = context.object
+        me = context.mesh
         col = layout.column()
-        # sticky has no UI access since 2.49 - we may remove
-        '''
-        row = col.row(align=True)
-        row.operator("mesh.customdata_create_sticky")
-        row.operator("mesh.customdata_clear_sticky", icon='X')
-        '''
+
         col.operator("mesh.customdata_clear_mask", icon='X')
         col.operator("mesh.customdata_clear_skin", icon='X')
 
+        col = layout.column()
+
+        col.enabled = (obj.mode != 'EDIT')
+        col.prop(me, "use_customdata_vertex_bevel")
+        col.prop(me, "use_customdata_edge_bevel")
+        col.prop(me, "use_customdata_edge_crease")
+
 
 class DATA_PT_custom_props_mesh(MeshButtonsPanel, PropertyPanel, Panel):
     COMPAT_ENGINES = {'BLENDER_RENDER', 'BLENDER_GAME'}
index ed90c63d9493b6c4e2540872b6bc849cb43f5b66..f06547fe2e3745c12975bc80edb42522d08d5a4c 100644 (file)
@@ -173,6 +173,9 @@ struct DerivedMesh {
        float auto_bump_scale;
        DMDirtyFlag dirty;
 
+       /* use for converting to BMesh which doesn't store bevel weight and edge crease by default */
+       char cd_flag;
+
        /** Calculate vert and face normals */
        void (*calcNormals)(DerivedMesh *dm);
 
index 49301f47df67b3bc33dd906559a59c94419fe653..9c6d26c08bcb188ea6ea022e5d9b1be344fc8e96 100644 (file)
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         265
-#define BLENDER_SUBVERSION      7
+#define BLENDER_SUBVERSION      8
 
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      262
index 3a65c8d3b721eccd0e79ee5d8127ebe8fcae4c3d..6f9e046f212b7d29e824b4ac929acb83f5e74ade 100644 (file)
@@ -249,6 +249,7 @@ 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);
+int CustomData_get_offset(const struct CustomData *data, int type);
 
 int CustomData_get_layer_index(const struct CustomData *data, int type);
 int CustomData_get_layer_index_n(const struct CustomData *data, int type, int n);
index db9f1228f768dd29ad30aa1b22eef1e7fe5dfdd6..5f4cc65ae7ed42fafd982f835e1348db4f365a50 100644 (file)
@@ -334,6 +334,8 @@ void BKE_mesh_loops_to_mface_corners(struct CustomData *fdata, struct CustomData
 void BKE_mesh_poly_calc_angles(struct MVert *mvert, struct MLoop *mloop,
                                struct MPoly *mp, float angles[]);
 
+void BKE_mesh_do_versions_cd_flag_init(struct Mesh *mesh);
+
 #ifdef __cplusplus
 }
 #endif
index ec8d37e1ae36976bd48c7b2b0feecb5b71ea8533..4ffbc3e6de18aaf16192bed3f6450defc865e74d 100644 (file)
@@ -313,6 +313,8 @@ void DM_from_template(DerivedMesh *dm, DerivedMesh *source, DerivedMeshType type
        CustomData_copy(&source->polyData, &dm->polyData, CD_MASK_DERIVEDMESH,
                        CD_CALLOC, numPolys);
 
+       dm->cd_flag = source->cd_flag;
+
        dm->type = type;
        dm->numVertData = numVerts;
        dm->numEdgeData = numEdges;
@@ -488,6 +490,7 @@ void DM_to_mesh(DerivedMesh *dm, Mesh *me, Object *ob)
        CustomData_copy(&dm->edgeData, &tmp.edata, CD_MASK_MESH, CD_DUPLICATE, totedge);
        CustomData_copy(&dm->loopData, &tmp.ldata, CD_MASK_MESH, CD_DUPLICATE, totloop);
        CustomData_copy(&dm->polyData, &tmp.pdata, CD_MASK_MESH, CD_DUPLICATE, totpoly);
+       me->cd_flag = dm->cd_flag;
 
        if (CustomData_has_layer(&dm->vertData, CD_SHAPEKEY)) {
                KeyBlock *kb;
index 517a5d6f6c656bd18dce4fc23d06aaa58e84c69c..0321b96325640af18de059f0351d7cd91e0f8402 100644 (file)
@@ -1743,6 +1743,7 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh, Object *UNUSED(ob))
                mesh->totloop, mesh->totpoly);
 
        dm->deformedOnly = 1;
+       dm->cd_flag = mesh->cd_flag;
 
        alloctype = CD_REFERENCE;
 
@@ -1926,13 +1927,12 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps,
        int numCol = CustomData_number_of_layers(&bm->ldata, CD_MLOOPCOL);
        int numTex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
        int *index, add_orig;
-       int has_crease, has_edge_bweight, has_vert_bweight;
        CustomDataMask mask;
        unsigned int i, j;
        
-       has_edge_bweight = CustomData_has_layer(&bm->edata, CD_BWEIGHT);
-       has_vert_bweight = CustomData_has_layer(&bm->vdata, CD_BWEIGHT);
-       has_crease = CustomData_has_layer(&bm->edata, CD_CREASE);
+       const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
+       const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+       const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
        
        dm->deformedOnly = 1;
        
@@ -1972,8 +1972,7 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps,
 
                mv->flag = BM_vert_flag_to_mflag(eve);
 
-               if (has_vert_bweight)
-                       mv->bweight = (unsigned char)(BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
+               if (cd_vert_bweight_offset != -1) mv->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset);
 
                if (add_orig) *index = i;
 
@@ -1991,11 +1990,6 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps,
                med->v1 = BM_elem_index_get(eed->v1);
                med->v2 = BM_elem_index_get(eed->v2);
 
-               if (has_crease)
-                       med->crease = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f);
-               if (has_edge_bweight)
-                       med->bweight = (unsigned char)(BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f);
-               
                med->flag = BM_edge_flag_to_mflag(eed);
 
                /* handle this differently to editmode switching,
@@ -2006,6 +2000,9 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps,
                        }
                }
 
+               if (cd_edge_crease_offset  != -1) med->crease  = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset);
+               if (cd_edge_bweight_offset != -1) med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset);
+
                CustomData_from_bmesh_block(&bm->edata, &dm->edgeData, eed->head.data, i);
                if (add_orig) *index = i;
        }
@@ -2068,6 +2065,8 @@ static DerivedMesh *cddm_from_bmesh_ex(struct BMesh *bm, int use_mdisps,
        }
        bm->elem_index_dirty &= ~BM_FACE;
 
+       dm->cd_flag = BM_mesh_cd_flag_from_bmesh(bm);
+
        return dm;
 }
 
@@ -2105,6 +2104,7 @@ static DerivedMesh *cddm_copy_ex(DerivedMesh *source, int faces_from_tessfaces)
        DM_from_template(dm, source, DM_TYPE_CDDM, numVerts, numEdges, numTessFaces,
                         numLoops, numPolys);
        dm->deformedOnly = source->deformedOnly;
+       dm->cd_flag = source->cd_flag;
        dm->dirty = source->dirty;
 
        CustomData_copy_data(&source->vertData, &dm->vertData, 0, 0, numVerts);
index 4c6b0c081589465a32575ea6d3d0c10f8cd5b9a9..82c0535254bf01cbc27c1ae2ef6ae393dd60fc01 100644 (file)
@@ -2095,6 +2095,14 @@ void *CustomData_get_layer_named(const struct CustomData *data, int type,
        return data->layers[layer_index].data;
 }
 
+int CustomData_get_offset(const CustomData *data, int type)
+{
+       /* get the layer index of the active layer of type */
+       int layer_index = CustomData_get_layer_index(data, type);
+       if (layer_index < 0) return -1;
+
+       return data->layers[layer_index].offset;
+}
 
 int CustomData_set_layer_name(const CustomData *data, int type, int n, const char *name)
 {
index c3587f6b188cc6d8f983d789da05764f9659df79..fd7c3f55bb0226386626bf236bdf3ad4d9f034ca 100644 (file)
@@ -1402,7 +1402,7 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
        BMesh *bm = bmdm->tc->bm;
        BMVert *eve;
        BMIter iter;
-       const int has_bweight = CustomData_has_layer(&bm->vdata, CD_BWEIGHT);
+       const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
 
        if (bmdm->vertexCos) {
                int i;
@@ -1412,9 +1412,8 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
                        normal_float_to_short_v3(vert_r->no, eve->no);
                        vert_r->flag = BM_vert_flag_to_mflag(eve);
 
-                       if (has_bweight) {
-                               vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
-                       }
+                       if (cd_vert_bweight_offset != -1) vert_r->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset);
+
                        vert_r++;
                }
        }
@@ -1424,9 +1423,8 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *vert_r)
                        normal_float_to_short_v3(vert_r->no, eve->no);
                        vert_r->flag = BM_vert_flag_to_mflag(eve);
 
-                       if (has_bweight) {
-                               vert_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->vdata, eve, CD_BWEIGHT) * 255.0f);
-                       }
+                       if (cd_vert_bweight_offset != -1) vert_r->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eve, cd_vert_bweight_offset);
+
                        vert_r++;
                }
        }
@@ -1437,24 +1435,20 @@ static void emDM_copyEdgeArray(DerivedMesh *dm, MEdge *edge_r)
        BMesh *bm = ((EditDerivedBMesh *)dm)->tc->bm;
        BMEdge *eed;
        BMIter iter;
-       const int has_bweight = CustomData_has_layer(&bm->edata, CD_BWEIGHT);
-       const int has_crease = CustomData_has_layer(&bm->edata, CD_CREASE);
+
+       const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+       const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
 
        BM_mesh_elem_index_ensure(bm, BM_VERT);
 
        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
-               if (has_bweight) {
-                       edge_r->bweight = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_BWEIGHT) * 255.0f);
-               }
-
-               if (has_crease) {
-                       edge_r->crease = (unsigned char) (BM_elem_float_data_get(&bm->edata, eed, CD_CREASE) * 255.0f);
-               }
+               edge_r->v1 = BM_elem_index_get(eed->v1);
+               edge_r->v2 = BM_elem_index_get(eed->v2);
 
                edge_r->flag = BM_edge_flag_to_mflag(eed);
 
-               edge_r->v1 = BM_elem_index_get(eed->v1);
-               edge_r->v2 = BM_elem_index_get(eed->v2);
+               if (cd_edge_crease_offset  != -1) edge_r->crease  = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_crease_offset);
+               if (cd_edge_bweight_offset != -1) edge_r->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(eed, cd_edge_bweight_offset);
 
                edge_r++;
        }
@@ -1662,6 +1656,9 @@ DerivedMesh *getEditDerivedBMesh(BMEditMesh *em,
        DM_init((DerivedMesh *)bmdm, DM_TYPE_EDITBMESH, em->bm->totvert,
                em->bm->totedge, em->tottri, em->bm->totloop, em->bm->totface);
 
+       /* could also get from the objects mesh directly */
+       bmdm->dm.cd_flag = BM_mesh_cd_flag_from_bmesh(bm);
+
        bmdm->dm.getVertCos = emDM_getVertCos;
        bmdm->dm.getMinMax = emDM_getMinMax;
 
index 30e7cb3bb36717d78952df9537bfc3c95ccb321c..806df92a4cb60d6e5ceacaf57dc0d0fb385df536 100644 (file)
@@ -3337,3 +3337,39 @@ void BKE_mesh_poly_calc_angles(MVert *mvert, MLoop *mloop,
        }
 }
 #endif
+
+
+void BKE_mesh_do_versions_cd_flag_init(Mesh *mesh)
+{
+       if (UNLIKELY(mesh->cd_flag)) {
+               return;
+       }
+       else {
+               MVert *mv;
+               MEdge *med;
+               int i;
+
+               for (mv = mesh->mvert, i = 0; i < mesh->totvert; mv++, i++) {
+                       if (mv->bweight != 0) {
+                               mesh->cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
+                               break;
+                       }
+               }
+
+               for (med = mesh->medge, i = 0; i < mesh->totedge; med++, i++) {
+                       if (med->bweight != 0) {
+                               mesh->cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
+                               if (mesh->cd_flag & ME_CDFLAG_EDGE_CREASE) {
+                                       break;
+                               }
+                       }
+                       if (med->crease != 0) {
+                               mesh->cd_flag |= ME_CDFLAG_EDGE_CREASE;
+                               if (mesh->cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
+                                       break;
+                               }
+                       }
+               }
+
+       }
+}
index 3939c45a436936b4ba11bb8c9807e942bc462aaf..849471a083b8cc52c7e792b09062f39c311fd65e 100644 (file)
@@ -62,6 +62,10 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm)
        int is_init = (bm->totvert == 0) && (bm->totedge == 0) && (bm->totface == 0);
        char has_orig_hflag = 0;
 
+       int cd_vert_bweight_offset;
+       int cd_edge_bweight_offset;
+       int cd_edge_crease_offset;
+
        if (is_init == FALSE) {
                /* check if we have an origflag */
                has_orig_hflag |= CustomData_has_layer(&bm->vdata, CD_ORIGINDEX) ? BM_VERT : 0;
@@ -75,16 +79,18 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm)
        CustomData_bmesh_merge(&dm->loopData, &bm->ldata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_LOOP);
        CustomData_bmesh_merge(&dm->polyData, &bm->pdata, CD_MASK_DERIVEDMESH, CD_CALLOC, bm, BM_FACE);
 
+       if (is_init) {
+               BM_mesh_cd_flag_apply(bm, dm->cd_flag);
+       }
+
+       cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
+       cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+       cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
+
        totvert = dm->getNumVerts(dm);
        totedge = dm->getNumEdges(dm);
        /* totface = dm->getNumPolys(dm); */ /* UNUSED */
 
-       /* add crease layer */
-       BM_data_layer_add(bm, &bm->edata, CD_CREASE);
-       /* add bevel weight layers */
-       BM_data_layer_add(bm, &bm->edata, CD_BWEIGHT);
-       BM_data_layer_add(bm, &bm->vdata, CD_BWEIGHT);
-
        vtable = MEM_callocN(sizeof(void **) * totvert, __func__);
        etable = MEM_callocN(sizeof(void **) * totedge, __func__);
 
@@ -100,7 +106,7 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm)
                vtable[i] = v;
 
                /* add bevel weight */
-               BM_elem_float_data_set(&bm->vdata, v, CD_BWEIGHT, (float)mv->bweight / 255.0f);
+               if (cd_vert_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(v, cd_vert_bweight_offset, (float)mv->bweight / 255.0f);
 
                if (UNLIKELY(has_orig_hflag & BM_VERT)) {
                        int *orig_index = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_ORIGINDEX);
@@ -121,10 +127,8 @@ void DM_to_bmesh_ex(DerivedMesh *dm, BMesh *bm)
                CustomData_to_bmesh_block(&dm->edgeData, &bm->edata, i, &e->head.data, true);
                etable[i] = e;
 
-               /* add crease */
-               BM_elem_float_data_set(&bm->edata, e, CD_CREASE, (float)me->crease / 255.0f);
-               /* add bevel weight */
-               BM_elem_float_data_set(&bm->edata, e, CD_BWEIGHT, (float)me->bweight / 255.0f);
+               if (cd_edge_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_bweight_offset, (float)me->bweight / 255.0f);
+               if (cd_edge_crease_offset  != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_crease_offset,  (float)me->crease  / 255.0f);
 
                if (UNLIKELY(has_orig_hflag & BM_EDGE)) {
                        int *orig_index = CustomData_bmesh_get(&bm->edata, e->head.data, CD_ORIGINDEX);
index c8bd02e2776b9837c2665aeab955a564545641dc..2235906329df4eaea8425dc3ad4c55fff03d59ec 100644 (file)
@@ -8645,6 +8645,15 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
                }
        }
 
+       if (!MAIN_VERSION_ATLEAST(main, 265, 8)) {
+               Mesh *me;
+               for (me = main->mesh.first; me; me = me->id.next) {
+                       BKE_mesh_do_versions_cd_flag_init(me);
+               }
+       }
+
+       // if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 7)) {
+
        /* WATCH IT!!!: pointers from libdata have not been converted yet here! */
        /* WATCH IT 2!: Userdef struct init has to be in editors/interface/resources.c! */
 
index 5d7ded2024ddb66f8cfd96019e66874ae00d86bc..824884fb4e46a770021e1fddce69665c60a9379c 100644 (file)
@@ -254,6 +254,18 @@ enum {
 
 /* defines */
 
+#define BM_ELEM_CD_GET_VOID_P(ele, offset) \
+       ((void)0, (void *)((char *)(ele)->head.data + (offset)))
+
+#define BM_ELEM_CD_SET_FLOAT(ele, offset, f) \
+       { *((float *)((char *)(ele)->head.data + (offset))) = (f); } (void)0
+
+#define BM_ELEM_CD_GET_FLOAT(ele, offset) \
+       ((void)0, *((float *)((char *)(ele)->head.data + (offset))))
+
+#define BM_ELEM_CD_GET_FLOAT_AS_UCHAR(ele, offset) \
+       (unsigned char)(BM_ELEM_CD_GET_FLOAT(ele, offset) * 255.0f)
+
 /*forward declarations*/
 
 #ifdef USE_BMESH_HOLES
index 53b29a4ce7491461b47e8875f88480ef80b4c95d..8198e30bac6b2c2dc7bd3f423e7ca195116ada3d 100644 (file)
 #include "bmesh.h"
 #include "intern/bmesh_private.h" /* for element checking */
 
+void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
+{
+       const char cd_flag_all = BM_mesh_cd_flag_from_bmesh(bm) | cd_flag;
+       BM_mesh_cd_flag_apply(bm, cd_flag_all);
+       if (mesh) {
+               mesh->cd_flag = cd_flag_all;
+       }
+}
+
+void BM_mesh_cd_flag_apply(BMesh *bm, const char cd_flag)
+{
+       /* CustomData_bmesh_init_pool() must run first */
+       BLI_assert(bm->vdata.totlayer == 0 || bm->vdata.pool != NULL);
+       BLI_assert(bm->edata.totlayer == 0 || bm->edata.pool != NULL);
+
+       if (cd_flag & ME_CDFLAG_VERT_BWEIGHT) {
+               if (!CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
+                       BM_data_layer_add(bm, &bm->vdata, CD_BWEIGHT);
+               }
+       }
+       else {
+               if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
+                       BM_data_layer_free(bm, &bm->vdata, CD_BWEIGHT);
+               }
+       }
+
+       if (cd_flag & ME_CDFLAG_EDGE_BWEIGHT) {
+               if (!CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
+                       BM_data_layer_add(bm, &bm->edata, CD_BWEIGHT);
+               }
+       }
+       else {
+               if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
+                       BM_data_layer_free(bm, &bm->edata, CD_BWEIGHT);
+               }
+       }
+
+       if (cd_flag & ME_CDFLAG_EDGE_CREASE) {
+               if (!CustomData_has_layer(&bm->edata, CD_CREASE)) {
+                       BM_data_layer_add(bm, &bm->edata, CD_CREASE);
+               }
+       }
+       else {
+               if (CustomData_has_layer(&bm->edata, CD_CREASE)) {
+                       BM_data_layer_free(bm, &bm->edata, CD_CREASE);
+               }
+       }
+}
+
+char BM_mesh_cd_flag_from_bmesh(BMesh *bm)
+{
+       char cd_flag = 0;
+       if (CustomData_has_layer(&bm->vdata, CD_BWEIGHT)) {
+               cd_flag |= ME_CDFLAG_VERT_BWEIGHT;
+       }
+       if (CustomData_has_layer(&bm->edata, CD_BWEIGHT)) {
+               cd_flag |= ME_CDFLAG_EDGE_BWEIGHT;
+       }
+       if (CustomData_has_layer(&bm->edata, CD_CREASE)) {
+               cd_flag |= ME_CDFLAG_EDGE_CREASE;
+       }
+       return cd_flag;
+}
+
 /* Mesh -> BMesh */
 void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
 {
@@ -116,6 +180,10 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
        int *keyi;
        int totuv, i, j;
 
+       int cd_vert_bweight_offset;
+       int cd_edge_bweight_offset;
+       int cd_edge_crease_offset;
+
        /* free custom data */
        /* this isnt needed in most cases but do just incase */
        CustomData_free(&bm->vdata, bm->totvert);
@@ -152,15 +220,6 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
                CustomData_set_layer_name(&bm->ldata, CD_MLOOPUV, i, bm->pdata.layers[li].name);
        }
 
-       if (!CustomData_has_layer(&bm->edata, CD_CREASE))
-               CustomData_add_layer(&bm->edata, CD_CREASE, CD_ASSIGN, NULL, 0);
-
-       if (!CustomData_has_layer(&bm->edata, CD_BWEIGHT))
-               CustomData_add_layer(&bm->edata, CD_BWEIGHT, CD_ASSIGN, NULL, 0);
-
-       if (!CustomData_has_layer(&bm->vdata, CD_BWEIGHT))
-               CustomData_add_layer(&bm->vdata, CD_BWEIGHT, CD_ASSIGN, NULL, 0);
-
        if ((act_key_nr != 0) && (me->key != NULL)) {
                actkey = BLI_findlink(&me->key->block, act_key_nr - 1);
        }
@@ -205,6 +264,12 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
        CustomData_bmesh_init_pool(&bm->ldata, me->totloop, BM_LOOP);
        CustomData_bmesh_init_pool(&bm->pdata, me->totpoly, BM_FACE);
 
+       BM_mesh_cd_flag_apply(bm, me->cd_flag);
+
+       cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
+       cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+       cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
+
        for (i = 0, mvert = me->mvert; i < me->totvert; i++, mvert++) {
                v = BM_vert_create(bm, keyco && set_key ? keyco[i] : mvert->co, NULL, BM_CREATE_SKIP_CD);
                BM_elem_index_set(v, i); /* set_ok */
@@ -223,7 +288,7 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
                /* Copy Custom Data */
                CustomData_to_bmesh_block(&me->vdata, &bm->vdata, i, &v->head.data, true);
 
-               BM_elem_float_data_set(&bm->vdata, v, CD_BWEIGHT, (float)mvert->bweight / 255.0f);
+               if (cd_vert_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(v, cd_vert_bweight_offset, (float)mvert->bweight / 255.0f);
 
                /* set shapekey data */
                if (me->key) {
@@ -269,8 +334,9 @@ void BM_mesh_bm_from_me(BMesh *bm, Mesh *me, int set_key, int act_key_nr)
                /* Copy Custom Data */
                CustomData_to_bmesh_block(&me->edata, &bm->edata, i, &e->head.data, true);
 
-               BM_elem_float_data_set(&bm->edata, e, CD_CREASE, (float)medge->crease / 255.0f);
-               BM_elem_float_data_set(&bm->edata, e, CD_BWEIGHT, (float)medge->bweight / 255.0f);
+               if (cd_edge_bweight_offset != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_bweight_offset, (float)medge->bweight / 255.0f);
+               if (cd_edge_crease_offset  != -1) BM_ELEM_CD_SET_FLOAT(e, cd_edge_crease_offset,  (float)medge->crease  / 255.0f);
+
        }
 
        bm->elem_index_dirty &= ~BM_EDGE; /* added in order, clear dirty flag */
@@ -496,6 +562,10 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess)
        BMIter iter, liter;
        int i, j, ototvert;
 
+       const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
+       const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+       const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
+
        ototvert = me->totvert;
 
        /* new vertex block */
@@ -555,10 +625,6 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess)
 
        i = 0;
        BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
-               float *bweight = CustomData_bmesh_get(&bm->vdata, v->head.data, CD_BWEIGHT);
-
-               mvert->bweight = bweight ? (char)((*bweight) * 255) : 0;
-
                copy_v3_v3(mvert->co, v->co);
                normal_float_to_short_v3(mvert->no, v->no);
 
@@ -569,6 +635,8 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess)
                /* copy over customdat */
                CustomData_from_bmesh_block(&bm->vdata, &me->vdata, v->head.data, i);
 
+               if (cd_vert_bweight_offset != -1) mvert->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(v, cd_vert_bweight_offset);
+
                i++;
                mvert++;
 
@@ -579,13 +647,8 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess)
        med = medge;
        i = 0;
        BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
-               float *crease = CustomData_bmesh_get(&bm->edata, e->head.data, CD_CREASE);
-               float *bweight = CustomData_bmesh_get(&bm->edata, e->head.data, CD_BWEIGHT);
-
                med->v1 = BM_elem_index_get(e->v1);
                med->v2 = BM_elem_index_get(e->v2);
-               med->crease = crease ? (char)((*crease) * 255) : 0;
-               med->bweight = bweight ? (char)((*bweight) * 255) : 0;
 
                med->flag = BM_edge_flag_to_mflag(e);
 
@@ -596,6 +659,9 @@ void BM_mesh_bm_to_me(BMesh *bm, Mesh *me, int dotess)
 
                bmesh_quick_edgedraw_flag(med, e);
 
+               if (cd_edge_crease_offset  != -1) med->crease  = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_crease_offset);
+               if (cd_edge_bweight_offset != -1) med->bweight = BM_ELEM_CD_GET_FLOAT_AS_UCHAR(e, cd_edge_bweight_offset);
+
                i++;
                med++;
                BM_CHECK_ELEMENT(e);
index f9c51584081ed4aa1af7e089e2053dd49bdb08a9..55ac39c6745857771330d5d960c9adc09d9da61f 100644 (file)
 
 struct Mesh;
 
+void BM_mesh_cd_flag_ensure(BMesh *bm, struct Mesh *mesh, const char cd_flag);
+void BM_mesh_cd_flag_apply(BMesh *bm, const char cd_flag);
+char BM_mesh_cd_flag_from_bmesh(BMesh *bm);
+
 void BM_mesh_bm_from_me(BMesh *bm, struct Mesh *me, int set_key, int act_key_nr);
 void BM_mesh_bm_to_me(BMesh *bm, struct Mesh *me, int dotess);
 
index 0735b95588e8cbce85ef80aa310137965f1232ce..0af2913dae00300bb2e642e04abf67cf52aeee75 100644 (file)
@@ -42,6 +42,7 @@
 #include "BKE_displist.h"
 #include "BKE_report.h"
 #include "BKE_paint.h"
+#include "BKE_mesh.h"
 #include "BKE_tessmesh.h"
 
 #include "IMB_imbuf_types.h"
@@ -1351,6 +1352,17 @@ static int edgetag_shortest_path(Scene *scene, BMesh *bm, BMEdge *e_src, BMEdge
        /* note, would pass BM_EDGE except we are looping over all edges anyway */
        BM_mesh_elem_index_ensure(bm, BM_VERT /* | BM_EDGE */);
 
+       switch (scene->toolsettings->edge_mode) {
+               case EDGE_MODE_TAG_CREASE:
+                       BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(OBACT), ME_CDFLAG_EDGE_CREASE);
+                       break;
+               case EDGE_MODE_TAG_BEVEL:
+                       BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(OBACT), ME_CDFLAG_EDGE_BWEIGHT);
+                       break;
+               default:
+                       break;
+       }
+
        BM_ITER_MESH_INDEX (e, &eiter, bm, BM_EDGES_OF_MESH, i) {
                if (BM_elem_flag_test(e, BM_ELEM_HIDDEN) == FALSE) {
                        BM_elem_flag_disable(e, BM_ELEM_TAG);
index 6a095a8d2b1d94e5fc718125b08dc0ad0204add1..cc3885b5327680e87dc67536175e6228e45543e3 100644 (file)
@@ -179,6 +179,11 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                BMEdge *eed;
                BMIter iter;
 
+               const int cd_vert_skin_offset    = CustomData_get_offset(&bm->vdata, CD_MVERT_SKIN);
+               const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
+               const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+               const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
+
                BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
                        if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
                                MVertSkin *vs;
@@ -187,24 +192,32 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                tot++;
                                add_v3_v3(&median[LOC_X], eve->co);
 
-                               vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
-                               if (vs) {
+                               /* TODO cd_vert_bweight_offset */
+                               (void)cd_vert_bweight_offset;
+
+                               if (cd_vert_skin_offset != -1) {
+                                       vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
                                        add_v2_v2(&median[M_SKIN_X], vs->radius); /* Third val not used currently. */
                                        totskinradius++;
                                }
                        }
                }
 
-               BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
-                       if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
-                               float *f;
+               if ((cd_edge_bweight_offset != -1) ||
+                   (cd_edge_crease_offset  != -1))
+               {
+                       BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+                               if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
+                                       if (cd_edge_bweight_offset != -1) {
+                                               median[M_WEIGHT] += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_bweight_offset);
+                                       }
 
-                               totedgedata++;
-                               f = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_CREASE);
-                               median[M_CREASE] += f ? *f : 0.0f;
+                                       if (cd_edge_crease_offset != -1) {
+                                               median[M_CREASE] += BM_ELEM_CD_GET_FLOAT(eed, cd_edge_crease_offset);
+                                       }
 
-                               f = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_BWEIGHT);
-                               median[M_WEIGHT] += f ? *f : 0.0f;
+                                       totedgedata++;
+                               }
                        }
                }
 
@@ -412,14 +425,26 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                /* Meshes... */
                if (meshdata) {
                        if (totedgedata) {
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
-                                             totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"),
-                                             0, yi -= buth + but_margin, 200, buth,
-                                             &(tfp->ve_median[M_CREASE]), 0.0, 1.0, 1, 3, TIP_("Weight used by SubSurf modifier"));
-                               uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
-                                             totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
-                                             0, yi -= buth + but_margin, 200, buth,
-                                             &(tfp->ve_median[M_WEIGHT]), 0.0, 1.0, 1, 3, TIP_("Weight used by Bevel modifier"));
+                               Mesh *me = ob->data;
+                               BMEditMesh *em = me->edit_btmesh;
+                               BMesh *bm = em->bm;
+
+                               const int cd_edge_bweight_offset = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+                               const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
+
+                               if (cd_edge_crease_offset != -1) {
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
+                                                 totedgedata == 1 ? IFACE_("Crease:") : IFACE_("Mean Crease:"),
+                                                 0, yi -= buth + but_margin, 200, buth,
+                                                 &(tfp->ve_median[M_CREASE]), 0.0, 1.0, 1, 3, TIP_("Weight used by SubSurf modifier"));
+                               }
+
+                               if (cd_edge_bweight_offset != -1) {
+                                       uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
+                                                 totedgedata == 1 ? IFACE_("Bevel Weight:") : IFACE_("Mean Bevel Weight:"),
+                                                 0, yi -= buth + but_margin, 200, buth,
+                                                 &(tfp->ve_median[M_WEIGHT]), 0.0, 1.0, 1, 3, TIP_("Weight used by Bevel modifier"));
+                               }
                        }
                        if (totskinradius) {
                                uiDefButF(block, NUM, B_OBJECTPANELMEDIAN,
@@ -502,91 +527,85 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                        }
 
                        if (median[M_CREASE] != 0.0f) {
-                               BMEdge *eed;
+                               const int cd_edge_crease_offset  = CustomData_get_offset(&bm->edata, CD_CREASE);
                                const float sca = compute_scale_factor(ve_median[M_CREASE], median[M_CREASE]);
+                               BMEdge *eed;
 
                                if (ELEM(sca, 0.0f, 1.0f)) {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
-                                                       float *crease = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_CREASE);
-                                                       if (crease) {
-                                                               *crease = sca;
-                                                       }
+                                                       BM_ELEM_CD_SET_FLOAT(eed, cd_edge_crease_offset, sca);
                                                }
                                        }
                                }
                                else if (sca > 0.0f) {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-                                                       float *crease = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_CREASE);
-                                                       if (crease) {
-                                                               *crease *= sca;
-                                                               CLAMP(*crease, 0.0f, 1.0f);
-                                                       }
+                                                       float *crease = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_crease_offset);
+                                                       *crease *= sca;
+                                                       CLAMP(*crease, 0.0f, 1.0f);
                                                }
                                        }
                                }
                                else {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-                                                       float *crease = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_CREASE);
-                                                       if (crease) {
-                                                               *crease = 1.0f + ((1.0f - *crease) * sca);
-                                                               CLAMP(*crease, 0.0f, 1.0f);
-                                                       }
+                                                       float *crease = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_crease_offset);
+                                                       *crease = 1.0f + ((1.0f - *crease) * sca);
+                                                       CLAMP(*crease, 0.0f, 1.0f);
                                                }
                                        }
                                }
                        }
 
                        if (median[M_WEIGHT] != 0.0f) {
-                               BMEdge *eed;
+                               const int cd_edge_bweight_offset  = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
                                const float sca = compute_scale_factor(ve_median[M_WEIGHT], median[M_WEIGHT]);
+                               BMEdge *eed;
+
+                               BLI_assert(cd_edge_bweight_offset != -1);
 
                                if (ELEM(sca, 0.0f, 1.0f)) {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
-                                                       float *bweight = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_BWEIGHT);
-                                                       if (bweight) {
-                                                               *bweight = sca;
-                                                       }
+                                                       float *bweight = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_bweight_offset);
+                                                       *bweight = sca;
                                                }
                                        }
                                }
                                else if (sca > 0.0f) {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-                                                       float *bweight = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_BWEIGHT);
-                                                       if (bweight) {
-                                                               *bweight *= sca;
-                                                               CLAMP(*bweight, 0.0f, 1.0f);
-                                                       }
+                                                       float *bweight = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_bweight_offset);
+                                                       *bweight *= sca;
+                                                       CLAMP(*bweight, 0.0f, 1.0f);
                                                }
                                        }
                                }
                                else {
                                        BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
                                                if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
-                                                       float *bweight = (float *)CustomData_bmesh_get(&bm->edata, eed->head.data, CD_BWEIGHT);
-                                                       if (bweight) {
-                                                               *bweight = 1.0f + ((1.0f - *bweight) * sca);
-                                                               CLAMP(*bweight, 0.0f, 1.0f);
-                                                       }
+                                                       float *bweight = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_bweight_offset);
+                                                       *bweight = 1.0f + ((1.0f - *bweight) * sca);
+                                                       CLAMP(*bweight, 0.0f, 1.0f);
                                                }
                                        }
                                }
                        }
 
                        if (median[M_SKIN_X] != 0.0f) {
-                               BMVert *eve;
+                               const int cd_vert_skin_offset = CustomData_get_offset(&bm->vdata, CD_MVERT_SKIN);
                                /* That one is not clamped to [0.0, 1.0]. */
                                float sca = ve_median[M_SKIN_X];
+                               BMVert *eve;
+
+                               BLI_assert(cd_vert_skin_offset != -1);
+
                                if (ve_median[M_SKIN_X] - median[M_SKIN_X] == 0.0f) {
                                        BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
                                                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                                       MVertSkin *vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
-                                                       if (vs)
-                                                               vs->radius[0] = sca;
+                                                       MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
+                                                       vs->radius[0] = sca;
                                                }
                                        }
                                }
@@ -594,23 +613,25 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                        sca /= (ve_median[M_SKIN_X] - median[M_SKIN_X]);
                                        BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
                                                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                                       MVertSkin *vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
-                                                       if (vs)
-                                                               vs->radius[0] *= sca;
+                                                       MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
+                                                       vs->radius[0] *= sca;
                                                }
                                        }
                                }
                        }
                        if (median[M_SKIN_Y] != 0.0f) {
-                               BMVert *eve;
+                               const int cd_vert_skin_offset = CustomData_get_offset(&bm->vdata, CD_MVERT_SKIN);
                                /* That one is not clamped to [0.0, 1.0]. */
                                float sca = ve_median[M_SKIN_Y];
+                               BMVert *eve;
+
+                               BLI_assert(cd_vert_skin_offset != -1);
+
                                if (ve_median[M_SKIN_Y] - median[M_SKIN_Y] == 0.0f) {
                                        BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
                                                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                                       MVertSkin *vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
-                                                       if (vs)
-                                                               vs->radius[1] = sca;
+                                                       MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
+                                                       vs->radius[1] = sca;
                                                }
                                        }
                                }
@@ -618,9 +639,8 @@ static void v3d_editvertex_buts(uiLayout *layout, View3D *v3d, Object *ob, float
                                        sca /= (ve_median[M_SKIN_Y] - median[M_SKIN_Y]);
                                        BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
                                                if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
-                                                       MVertSkin *vs = (MVertSkin *)CustomData_bmesh_get(&bm->vdata, eve->head.data, CD_MVERT_SKIN);
-                                                       if (vs)
-                                                               vs->radius[1] *= sca;
+                                                       MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, cd_vert_skin_offset);
+                                                       vs->radius[1] *= sca;
                                                }
                                        }
                                }
index 63eea8b8d4c356823b862e54a5674e0211f51b22..cc5a56a34f8db763b47153119adc107bfc128cdb 100644 (file)
@@ -289,6 +289,7 @@ static void createTransEdge(TransInfo *t)
        float mtx[3][3], smtx[3][3];
        int count = 0, countsel = 0;
        int propmode = t->flag & T_PROP_EDIT;
+       int cd_edge_float_offset;
 
        BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
                if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
@@ -312,8 +313,22 @@ static void createTransEdge(TransInfo *t)
        copy_m3_m4(mtx, t->obedit->obmat);
        pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
 
+       /* create data we need */
+       if (t->mode == TFM_BWEIGHT) {
+               BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_BWEIGHT);
+               cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT);
+       }
+       else { //if (t->mode == TFM_CREASE) {
+               BLI_assert(t->mode == TFM_CREASE);
+               BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_CREASE);
+               cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE);
+       }
+
+       BLI_assert(cd_edge_float_offset != -1);
+
        BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
                if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && (BM_elem_flag_test(eed, BM_ELEM_SELECT) || propmode)) {
+                       float *fl_ptr;
                        /* need to set center for center calculations */
                        mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co);
 
@@ -327,17 +342,10 @@ static void createTransEdge(TransInfo *t)
                        copy_m3_m3(td->mtx, mtx);
 
                        td->ext = NULL;
-                       if (t->mode == TFM_BWEIGHT) {
-                               float *bweight = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_BWEIGHT);
-                               td->val = bweight;
-                               td->ival = bweight ? *bweight : 1.0f;
-                       }
-                       else {
-                               float *crease = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_CREASE);
-                               BLI_assert(t->mode == TFM_CREASE);
-                               td->val = crease;
-                               td->ival = crease ? *crease : 0.0f;
-                       }
+
+                       fl_ptr = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset);
+                       td->val  =  fl_ptr;
+                       td->ival = *fl_ptr;
 
                        td++;
                }
index 4c9f6014445ea717bb197a3d337246011efd241a..0c708ddcbef8531df40bd1a23f57500010cc07d0 100644 (file)
@@ -119,7 +119,10 @@ typedef struct Mesh {
        short texflag, drawflag;
        short smoothresh, flag;
 
-       short subdiv  DNA_DEPRECATED, subdivr  DNA_DEPRECATED;
+       /* customdata flag, for bevel-weight and crease, which are now optional */
+       char cd_flag, pad;
+
+       char subdiv  DNA_DEPRECATED, subdivr  DNA_DEPRECATED;
        char subsurftype  DNA_DEPRECATED; /* only kept for backwards compat, not used anymore */
        char editflag;
 
@@ -172,6 +175,11 @@ typedef struct TFace {
 #define ME_DS_EXPAND   512
 #define ME_SCULPT_DYNAMIC_TOPOLOGY 1024
 
+/* me->cd_flag */
+#define ME_CDFLAG_VERT_BWEIGHT (1 << 0)
+#define ME_CDFLAG_EDGE_BWEIGHT (1 << 1)
+#define ME_CDFLAG_EDGE_CREASE  (1 << 2)
+
 /* me->drawflag, short */
 #define ME_DRAWEDGES   (1 << 0)
 #define ME_DRAWFACES   (1 << 1)
index d6ded23ffeda1a01a3c770d902556b3c331b39bd..d5b8e4cddeb8381177052c9ec94de9fd049bd0fd 100644 (file)
@@ -2998,6 +2998,22 @@ static void rna_def_mesh(BlenderRNA *brna)
        RNA_def_property_ui_icon(prop, ICON_VERTEXSEL, 0);
        RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_Mesh_update_vertmask");
 
+
+
+       /* customdata flags */
+       prop = RNA_def_property(srna, "use_customdata_vertex_bevel", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_VERT_BWEIGHT);
+       RNA_def_property_ui_text(prop, "Store Vertex Bevel Weight", "");
+
+       prop = RNA_def_property(srna, "use_customdata_edge_bevel", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_EDGE_BWEIGHT);
+       RNA_def_property_ui_text(prop, "Store Edge Bevel Weight", "");
+
+       prop = RNA_def_property(srna, "use_customdata_edge_crease", PROP_BOOLEAN, PROP_NONE);
+       RNA_def_property_boolean_sdna(prop, NULL, "cd_flag", ME_CDFLAG_EDGE_CREASE);
+       RNA_def_property_ui_text(prop, "Store Edge Crease", "");
+
+
        /* readonly editmesh info - use for extrude menu */
        prop = RNA_def_property(srna, "total_vert_sel", PROP_INT, PROP_UNSIGNED);
        RNA_def_property_int_funcs(prop, "rna_Mesh_tot_vert_get", NULL, NULL);