From ef1af9f9c41a9cb33550bcaf396023ff840a3dab Mon Sep 17 00:00:00 2001 From: Campbell Barton Date: Thu, 4 Apr 2013 09:20:46 +0000 Subject: fix [#34802] Individual Transformation Confusing in Edit Mode Individual transformation now works in editmode mesh faces/edge, armature bones and metaballs. --- .../editors/transform/transform_conversions.c | 137 +++++++++++++-------- 1 file changed, 83 insertions(+), 54 deletions(-) (limited to 'source/blender/editors/transform/transform_conversions.c') diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c index f84c967711c..661d7055036 100644 --- a/source/blender/editors/transform/transform_conversions.c +++ b/source/blender/editors/transform/transform_conversions.c @@ -125,7 +125,7 @@ /* local function prototype - for Object/Bone Constraints */ -static short constraints_list_needinv(TransInfo *t, ListBase *list); +static bool constraints_list_needinv(TransInfo *t, ListBase *list); /* ************************** Functions *************************** */ @@ -1236,6 +1236,8 @@ static void createTransMBallVerts(TransInfo *t) copy_v3_v3(td->iloc, td->loc); copy_v3_v3(td->center, td->loc); + quat_to_mat3(td->axismtx, ml->quat); + if (ml->flag & SELECT) td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE; else td->flag = TD_USEQUAT; @@ -1858,32 +1860,29 @@ static void editmesh_set_connectivity_distance(BMEditMesh *em, float mtx[3][3], MEM_freeN(tots); } -/* loop-in-a-loop I know, but we need it! (ton) */ -static void get_face_center(float r_cent[3], BMVert *eve) - +static BMElem *bm_vert_single_select_face(BMVert *eve) { - BMFace *efa; + BMElem *ele; BMIter iter; - BM_ITER_ELEM (efa, &iter, eve, BM_FACES_OF_VERT) { - if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) { - BM_face_calc_center_mean(efa, r_cent); - break; + BM_ITER_ELEM (ele, &iter, eve, BM_FACES_OF_VERT) { + if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { + return ele; } } + return NULL; } - -static void get_edge_center(float r_cent[3], BMVert *eve) +static BMElem *bm_vert_single_select_edge(BMVert *eve) { - BMEdge *eed; + BMElem *ele; BMIter iter; - BM_ITER_ELEM (eed, &iter, eve, BM_EDGES_OF_VERT) { - if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) { - mid_v3_v3v3(r_cent, eed->v1->co, eed->v2->co); - break; + BM_ITER_ELEM (ele, &iter, eve, BM_EDGES_OF_VERT) { + if (BM_elem_flag_test(ele, BM_ELEM_SELECT)) { + return ele; } } + return NULL; } /* way to overwrite what data is edited with transform */ @@ -1895,25 +1894,51 @@ static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx // td->loc = key->co; //else td->loc = eve->co; - + copy_v3_v3(td->iloc, td->loc); copy_v3_v3(td->center, td->loc); if (t->around == V3D_LOCAL) { - if (em->selectmode & SCE_SELECT_FACE) - get_face_center(td->center, eve); - else if (em->selectmode & SCE_SELECT_EDGE) - get_edge_center(td->center, eve); + BMElem *ele; + bool is_axismat_set = false; + + if (em->selectmode & (SCE_SELECT_FACE | SCE_SELECT_EDGE) && + (ele = ((em->selectmode & SCE_SELECT_FACE) ? + bm_vert_single_select_face(eve) : + bm_vert_single_select_edge(eve)))) + { + float normal[3], tangent[3]; + + BMEditSelection ese; + ese.next = ese.prev = NULL; + ese.ele = ele; + ese.htype = ele->head.htype; + + BM_editselection_center(&ese, td->center); + BM_editselection_normal(&ese, normal); + BM_editselection_plane(&ese, tangent); + + if (createSpaceNormalTangent(td->axismtx, normal, tangent)) { + is_axismat_set = true; + } + } + + /* for verts or fallback when createSpaceNormalTangent fails */ + if (is_axismat_set == false) { + axis_dominant_v3_to_m3(td->axismtx, eve->no); + invert_m3(td->axismtx); + } + } + else { + /* Setting normals */ + copy_v3_v3(td->axismtx[2], eve->no); + td->axismtx[0][0] = + td->axismtx[0][1] = + td->axismtx[0][2] = + td->axismtx[1][0] = + td->axismtx[1][1] = + td->axismtx[1][2] = 0.0f; } - copy_v3_v3(td->iloc, td->loc); - // Setting normals - copy_v3_v3(td->axismtx[2], eve->no); - td->axismtx[0][0] = - td->axismtx[0][1] = - td->axismtx[0][2] = - td->axismtx[1][0] = - td->axismtx[1][1] = - td->axismtx[1][2] = 0.0f; td->ext = NULL; td->val = NULL; @@ -2503,7 +2528,7 @@ void flushTransUVs(TransInfo *t) } } -int clipUVTransform(TransInfo *t, float *vec, int resize) +bool clipUVTransform(TransInfo *t, float vec[2], const bool resize) { TransData *td; int a, clipx = 1, clipy = 1; @@ -2574,16 +2599,16 @@ void clipUVData(TransInfo *t) /* ********************* ANIMATION EDITORS (GENERAL) ************************* */ /* This function tests if a point is on the "mouse" side of the cursor/frame-marking */ -static short FrameOnMouseSide(char side, float frame, float cframe) +static bool FrameOnMouseSide(char side, float frame, float cframe) { /* both sides, so it doesn't matter */ - if (side == 'B') return 1; + if (side == 'B') return true; /* only on the named side */ if (side == 'R') - return (frame >= cframe) ? 1 : 0; + return (frame >= cframe); else - return (frame <= cframe) ? 1 : 0; + return (frame <= cframe); } /* ********************* NLA EDITOR ************************* */ @@ -4523,7 +4548,7 @@ static void createTransSeqData(bContext *C, TransInfo *t) * These particular constraints benefit from this, but others don't, hence * this semi-hack ;-) - Aligorith */ -static short constraints_list_needinv(TransInfo *t, ListBase *list) +static bool constraints_list_needinv(TransInfo *t, ListBase *list) { bConstraint *con; @@ -4536,26 +4561,30 @@ static short constraints_list_needinv(TransInfo *t, ListBase *list) if ((con->flag & CONSTRAINT_DISABLE) == 0 && (con->enforce != 0.0f)) { /* (affirmative) returns for specific constraints here... */ /* constraints that require this regardless */ - if (con->type == CONSTRAINT_TYPE_CHILDOF) return 1; - if (con->type == CONSTRAINT_TYPE_FOLLOWPATH) return 1; - if (con->type == CONSTRAINT_TYPE_CLAMPTO) return 1; - if (con->type == CONSTRAINT_TYPE_OBJECTSOLVER) return 1; - if (con->type == CONSTRAINT_TYPE_FOLLOWTRACK) return 1; - + if (ELEM5(con->type, + CONSTRAINT_TYPE_CHILDOF, + CONSTRAINT_TYPE_FOLLOWPATH, + CONSTRAINT_TYPE_CLAMPTO, + CONSTRAINT_TYPE_OBJECTSOLVER, + CONSTRAINT_TYPE_FOLLOWTRACK)) + { + return true; + } + /* constraints that require this only under special conditions */ if (con->type == CONSTRAINT_TYPE_ROTLIKE) { /* CopyRot constraint only does this when rotating, and offset is on */ bRotateLikeConstraint *data = (bRotateLikeConstraint *)con->data; if ((data->flag & ROTLIKE_OFFSET) && (t->mode == TFM_ROTATION)) - return 1; + return true; } } } } /* no appropriate candidates found */ - return 0; + return false; } /* transcribe given object into TransData for Transforming */ @@ -4563,8 +4592,8 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob) { Scene *scene = t->scene; float obmtx[3][3]; - short constinv; - short skip_invert = 0; + bool constinv; + bool skip_invert = false; if (t->mode != TFM_DUMMY && ob->rigidbody_object) { float rot[3][3], scale[3]; @@ -4602,15 +4631,15 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob) /* disable constraints inversion for dummy pass */ if (t->mode == TFM_DUMMY) - skip_invert = 1; + skip_invert = true; - if (skip_invert == 0 && constinv == 0) { - if (constinv == 0) + if (skip_invert == false && constinv == false) { + if (constinv == false) ob->transflag |= OB_NO_CONSTRAINTS; /* BKE_object_where_is_calc_time checks this */ BKE_object_where_is_calc(t->scene, ob); - if (constinv == 0) + if (constinv == false) ob->transflag &= ~OB_NO_CONSTRAINTS; } else @@ -4762,19 +4791,19 @@ static void set_trans_object_base_flags(TransInfo *t) } } -static int mark_children(Object *ob) +static bool mark_children(Object *ob) { if (ob->flag & (SELECT | BA_TRANSFORM_CHILD)) - return 1; + return true; if (ob->parent) { if (mark_children(ob->parent)) { ob->flag |= BA_TRANSFORM_CHILD; - return 1; + return true; } } - return 0; + return false; } static int count_proportional_objects(TransInfo *t) -- cgit v1.2.3