code cleanup: favor braces when blocks have mixed brace use.
[blender.git] / source / blender / editors / mesh / meshtools.c
index 22f7eb707abbd2c89d2ec2806cd03f044f5c0c4a..3d4d204299f491baa8de8beff992707e78306750 100644 (file)
@@ -149,7 +149,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                return OPERATOR_CANCELLED;
        }
 
                return OPERATOR_CANCELLED;
        }
 
-       /* remove tessface to ensure we don't old references to invalid faces */
+       /* remove tessface to ensure we don't hold references to invalid faces */
        BKE_mesh_tessface_clear(me);
 
        /* new material indices and material array */
        BKE_mesh_tessface_clear(me);
 
        /* new material indices and material array */
@@ -309,6 +309,10 @@ int join_mesh_exec(bContext *C, wmOperator *op)
                        me = base->object->data;
                        
                        if (me->totvert) {
                        me = base->object->data;
                        
                        if (me->totvert) {
+
+                               /* merge customdata flag */
+                               ((Mesh *)ob->data)->cd_flag |= me->cd_flag;
+
                                /* standard data */
                                CustomData_merge(&me->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert);
                                CustomData_copy_data(&me->vdata, &vdata, 0, vertofs, me->totvert);
                                /* standard data */
                                CustomData_merge(&me->vdata, &vdata, CD_MASK_MESH, CD_DEFAULT, totvert);
                                CustomData_copy_data(&me->vdata, &vdata, 0, vertofs, me->totvert);
@@ -502,6 +506,9 @@ int join_mesh_exec(bContext *C, wmOperator *op)
 
        /* tessface data removed above, no need to update */
        mesh_update_customdata_pointers(me, FALSE);
 
        /* tessface data removed above, no need to update */
        mesh_update_customdata_pointers(me, FALSE);
+
+       /* update normals in case objects with non-uniform scale are joined */
+       ED_mesh_calc_normals(me);
        
        /* old material array */
        for (a = 1; a <= ob->totcol; a++) {
        
        /* old material array */
        for (a = 1; a <= ob->totcol; a++) {
@@ -556,7 +563,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
        }
 
 
        }
 
 
-       DAG_scene_sort(bmain, scene);   // removed objects, need to rebuild dag before editmode call
+       DAG_relations_tag_update(bmain);   // removed objects, need to rebuild dag
 
 #if 0
        ED_object_enter_editmode(C, EM_WAITCURSOR);
 
 #if 0
        ED_object_enter_editmode(C, EM_WAITCURSOR);
@@ -782,7 +789,9 @@ static intptr_t mesh_octree_find_index(MocNode **bt, MVert *mvert, const float c
                                        return (*bt)->index[a];
                        }
                }
                                        return (*bt)->index[a];
                        }
                }
-               else return -1;
+               else {
+                       return -1;
+               }
        }
        if ( (*bt)->next)
                return mesh_octree_find_index(&(*bt)->next, mvert, co);
        }
        if ( (*bt)->next)
                return mesh_octree_find_index(&(*bt)->next, mvert, co);
@@ -1261,6 +1270,32 @@ int ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned
  *
  * \return boolean TRUE == Found
  */
  *
  * \return boolean TRUE == Found
  */
+typedef struct VertPickData {
+       const MVert *mvert;
+       const float *mval_f;  /* [2] */
+       ARegion *ar;
+
+       /* runtime */
+       float len_best;
+       int v_idx_best;
+} VertPickData;
+
+static void ed_mesh_pick_vert__mapFunc(void *userData, int index, const float co[3],
+                                       const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
+{
+       VertPickData *data = userData;
+       if ((data->mvert[index].flag & ME_HIDE) == 0) {
+               float sco[2];
+
+               if (ED_view3d_project_float_object(data->ar, co, sco, V3D_PROJ_TEST_CLIP_DEFAULT) == V3D_PROJ_RET_OK) {
+                       const float len = len_manhattan_v2v2(data->mval_f, sco);
+                       if (len < data->len_best) {
+                               data->len_best = len;
+                               data->v_idx_best = index;
+                       }
+               }
+       }
+}
 int ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, int use_zbuf)
 {
        ViewContext vc;
 int ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size, int use_zbuf)
 {
        ViewContext vc;
@@ -1294,46 +1329,37 @@ int ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int *
        else {
                /* derived mesh to find deformed locations */
                DerivedMesh *dm = mesh_get_derived_final(vc.scene, ob, CD_MASK_BAREMESH);
        else {
                /* derived mesh to find deformed locations */
                DerivedMesh *dm = mesh_get_derived_final(vc.scene, ob, CD_MASK_BAREMESH);
-               struct ARegion *ar = vc.ar;
+               ARegion *ar = vc.ar;
+               RegionView3D *rv3d = ar->regiondata;
 
 
-               int v_idx_best = -1;
-               int v_idx;
+               /* find the vert closest to 'mval' */
+               const float mval_f[2] = {(float)mval[0],
+                                        (float)mval[1]};
+
+               VertPickData data = {0};
 
 
+               ED_view3d_init_mats_rv3d(ob, rv3d);
 
                if (dm == NULL) {
                        return 0;
                }
 
 
                if (dm == NULL) {
                        return 0;
                }
 
-               if (dm->getVertCo) {
-                       RegionView3D *rv3d = ar->regiondata;
+               /* setup data */
+               data.mvert = me->mvert;
+               data.ar = ar;
+               data.mval_f = mval_f;
+               data.len_best = FLT_MAX;
+               data.v_idx_best = -1;
 
 
-                       /* find the vert closest to 'mval' */
-                       const float mval_f[2] = {(float)mval[0],
-                                                (float)mval[1]};
-                       float len_best = FLT_MAX;
-
-                       ED_view3d_init_mats_rv3d(ob, rv3d);
-
-                       v_idx = me->totvert - 1;
-                       do {
-                               float co[3], sco[2], len;
-                               dm->getVertCo(dm, v_idx, co);
-                               if (ED_view3d_project_float_object(ar, co, sco, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-                                       len = len_manhattan_v2v2(mval_f, sco);
-                                       if (len < len_best) {
-                                               len_best = len;
-                                               v_idx_best = v_idx;
-                                       }
-                               }
-                       } while (v_idx--);
-               }
+               dm->foreachMappedVert(dm, ed_mesh_pick_vert__mapFunc, &data);
 
                dm->release(dm);
 
 
                dm->release(dm);
 
-               if (v_idx_best != -1) {
-                       *index = v_idx_best;
-                       return 1;
+               if (data.v_idx_best == -1) {
+                       return 0;
                }
                }
+
+               *index = data.v_idx_best;
        }
 
        return 1;
        }
 
        return 1;