diff --git a/source/blender/editors/mesh/editmesh_mods.c b/source/blender/editors/mesh/editmesh_mods.c index 7df1fe234d9..e9c88d095b4 100644 --- a/source/blender/editors/mesh/editmesh_mods.c +++ b/source/blender/editors/mesh/editmesh_mods.c @@ -4064,179 +4064,6 @@ void MESH_OT_normals_make_consistent(wmOperatorType *ot) RNA_def_boolean(ot->srna, "inside", 0, "Inside", ""); } -/* ********** ALIGN WITH VIEW **************** */ - -static void editmesh_calc_selvert_center(EditMesh *em, float cent_r[3]) -{ - EditVert *eve; - int nsel= 0; - - zero_v3(cent_r); - - for (eve= em->verts.first; eve; eve= eve->next) { - if (eve->f & SELECT) { - cent_r[0]+= eve->co[0]; - cent_r[1]+= eve->co[1]; - cent_r[2]+= eve->co[2]; - nsel++; - } - } - - if (nsel) { - cent_r[0]/= nsel; - cent_r[1]/= nsel; - cent_r[2]/= nsel; - } -} - -static int mface_is_selected(MFace *mf) -{ - return (!(mf->flag & ME_HIDE) && (mf->flag & ME_FACE_SEL)); -} - - /* XXX, code for both these functions should be abstract, - * then unified, then written for other things (like objects, - * which would use same as vertices method), then added - * to interface! Hoera! - zr - */ -static void faceselect_align_view_to_selected(View3D *v3d, RegionView3D *rv3d, Mesh *me, wmOperator *op, int axis) -{ - float norm[3]; - int i, totselected = 0; - - norm[0]= norm[1]= norm[2]= 0.0; - for (i=0; itotface; i++) { - MFace *mf= ((MFace*) me->mface) + i; - - if (mface_is_selected(mf)) { - float *v1, *v2, *v3, fno[3]; - - v1= me->mvert[mf->v1].co; - v2= me->mvert[mf->v2].co; - v3= me->mvert[mf->v3].co; - if (mf->v4) { - float *v4= me->mvert[mf->v4].co; - normal_quad_v3( fno,v1, v2, v3, v4); - } else { - normal_tri_v3( fno,v1, v2, v3); - } - - norm[0]+= fno[0]; - norm[1]+= fno[1]; - norm[2]+= fno[2]; - - totselected++; - } - } - - if (totselected == 0) - BKE_report(op->reports, RPT_WARNING, "No faces selected."); - else - view3d_align_axis_to_vector(v3d, rv3d, axis, norm); -} - -/* helper for below, to survive non-uniform scaled objects */ -static void face_getnormal_obspace(Object *obedit, EditFace *efa, float *fno) -{ - float vec[4][3]; - - VECCOPY(vec[0], efa->v1->co); - mul_mat3_m4_v3(obedit->obmat, vec[0]); - VECCOPY(vec[1], efa->v2->co); - mul_mat3_m4_v3(obedit->obmat, vec[1]); - VECCOPY(vec[2], efa->v3->co); - mul_mat3_m4_v3(obedit->obmat, vec[2]); - if(efa->v4) { - VECCOPY(vec[3], efa->v4->co); - mul_mat3_m4_v3(obedit->obmat, vec[3]); - - normal_quad_v3( fno,vec[0], vec[1], vec[2], vec[3]); - } - else normal_tri_v3( fno,vec[0], vec[1], vec[2]); -} - - -static void editmesh_align_view_to_selected(Object *obedit, EditMesh *em, wmOperator *op, View3D *v3d, RegionView3D *rv3d, int axis) -{ - int nselverts= EM_nvertices_selected(em); - float norm[3]={0.0, 0.0, 0.0}; /* used for storing the mesh normal */ - - if (nselverts==0) { - BKE_report(op->reports, RPT_WARNING, "No faces or vertices selected."); - } - else if (EM_nfaces_selected(em)) { - EditFace *efa; - for (efa= em->faces.first; efa; efa= efa->next) { - if (faceselectedAND(efa, SELECT)) { - float fno[3]; - - face_getnormal_obspace(obedit, efa, fno); - norm[0]+= fno[0]; - norm[1]+= fno[1]; - norm[2]+= fno[2]; - } - } - - view3d_align_axis_to_vector(v3d, rv3d, axis, norm); - } - else if (nselverts>2) { - float cent[3]; - EditVert *eve, *leve= NULL; - - editmesh_calc_selvert_center(em, cent); - for (eve= em->verts.first; eve; eve= eve->next) { - if (eve->f & SELECT) { - if (leve) { - float tno[3]; - normal_tri_v3( tno,cent, leve->co, eve->co); - - /* XXX, fixme, should be flipped intp a - * consistent direction. -zr - */ - norm[0]+= tno[0]; - norm[1]+= tno[1]; - norm[2]+= tno[2]; - } - leve= eve; - } - } - - mul_mat3_m4_v3(obedit->obmat, norm); - view3d_align_axis_to_vector(v3d, rv3d, axis, norm); - } - else if (nselverts==2) { /* Align view to edge (or 2 verts) */ - EditVert *eve, *leve= NULL; - - for (eve= em->verts.first; eve; eve= eve->next) { - if (eve->f & SELECT) { - if (leve) { - norm[0]= leve->co[0] - eve->co[0]; - norm[1]= leve->co[1] - eve->co[1]; - norm[2]= leve->co[2] - eve->co[2]; - break; /* we know there are only 2 verts so no need to keep looking */ - } - leve= eve; - } - } - mul_mat3_m4_v3(obedit->obmat, norm); - view3d_align_axis_to_vector(v3d, rv3d, axis, norm); - } - else if (nselverts==1) { /* Align view to vert normal */ - EditVert *eve; - - for (eve= em->verts.first; eve; eve= eve->next) { - if (eve->f & SELECT) { - norm[0]= eve->no[0]; - norm[1]= eve->no[1]; - norm[2]= eve->no[2]; - break; /* we know this is the only selected vert, so no need to keep looking */ - } - } - mul_mat3_m4_v3(obedit->obmat, norm); - view3d_align_axis_to_vector(v3d, rv3d, axis, norm); - } -} - /* **************** VERTEX DEFORMS *************** */ static int smooth_vertex(bContext *C, wmOperator *op)