diff options
Diffstat (limited to 'source/blender/editors/transform/transform.c')
-rw-r--r-- | source/blender/editors/transform/transform.c | 199 |
1 files changed, 51 insertions, 148 deletions
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c index 181fb0f0aac..1796bd4e928 100644 --- a/source/blender/editors/transform/transform.c +++ b/source/blender/editors/transform/transform.c @@ -969,7 +969,7 @@ int transformEvent(TransInfo *t, wmEvent *event) break; case OKEY: if (t->flag & T_PROP_EDIT && event->shift) { - t->prop_mode = (t->prop_mode + 1) % 6; + t->prop_mode = (t->prop_mode + 1) % PROP_MODE_MAX; calculatePropRatio(t); t->redraw |= TREDRAW_HARD; } @@ -1006,9 +1006,6 @@ int transformEvent(TransInfo *t, wmEvent *event) else view_editmove(event->type); t->redraw= 1; break; -// case NDOFMOTION: -// viewmoveNDOF(1); - // break; default: handled = 0; break; @@ -1017,43 +1014,6 @@ int transformEvent(TransInfo *t, wmEvent *event) // Numerical input events t->redraw |= handleNumInput(&(t->num), event); - // NDof input events - switch(handleNDofInput(&(t->ndof), event)) - { - case NDOF_CONFIRM: - if ((t->options & CTX_NDOF) == 0) - { - /* Confirm on normal transform only */ - t->state = TRANS_CONFIRM; - } - break; - case NDOF_CANCEL: - if (t->options & CTX_NDOF) - { - /* Cancel on pure NDOF transform */ - t->state = TRANS_CANCEL; - } - else - { - /* Otherwise, just redraw, NDof input was cancelled */ - t->redraw |= TREDRAW_HARD; - } - break; - case NDOF_NOMOVE: - if (t->options & CTX_NDOF) - { - /* Confirm on pure NDOF transform */ - t->state = TRANS_CONFIRM; - } - break; - case NDOF_REFRESH: - t->redraw |= TREDRAW_HARD; - break; - default: - handled = 0; - break; - } - // Snapping events t->redraw |= handleSnapping(t, event); @@ -1396,16 +1356,15 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op) ToolSettings *ts = CTX_data_tool_settings(C); int constraint_axis[3] = {0, 0, 0}; int proportional = 0; + PropertyRNA *prop; - if (RNA_struct_find_property(op->ptr, "value")) - { - if (t->flag & T_AUTOVALUES) - { - RNA_float_set_array(op->ptr, "value", t->auto_values); + if ((prop= RNA_struct_find_property(op->ptr, "value"))) { + float *values= (t->flag & T_AUTOVALUES) ? t->auto_values : t->values; + if (RNA_property_array_check(prop)) { + RNA_property_float_set_array(op->ptr, prop, values); } - else - { - RNA_float_set_array(op->ptr, "value", t->values); + else { + RNA_property_float_set(op->ptr, prop, values[0]); } } @@ -1719,7 +1678,14 @@ int initTransform(bContext *C, TransInfo *t, wmOperator *op, wmEvent *event, int if (RNA_property_is_set(op->ptr, "value")) { float values[4]= {0}; /* incase value isn't length 4, avoid uninitialized memory */ - RNA_float_get_array(op->ptr, "value", values); + PropertyRNA *prop= RNA_struct_find_property(op->ptr, "value"); + + if(RNA_property_array_check(prop)) { + RNA_float_get_array(op->ptr, "value", values); + } else { + values[0]= RNA_float_get(op->ptr, "value"); + } + QUATCOPY(t->values, values); QUATCOPY(t->auto_values, values); t->flag |= T_AUTOVALUES; @@ -1982,12 +1948,15 @@ static void protectedQuaternionBits(short protectflag, float *quat, float *oldqu /* ******************* TRANSFORM LIMITS ********************** */ -static void constraintTransLim(TransInfo *UNUSED(t), TransData *td) +static void constraintTransLim(TransInfo *t, TransData *td) { if (td->con) { - bConstraintTypeInfo *cti= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT); + bConstraintTypeInfo *ctiLoc= get_constraint_typeinfo(CONSTRAINT_TYPE_LOCLIMIT); + bConstraintTypeInfo *ctiDist= get_constraint_typeinfo(CONSTRAINT_TYPE_DISTLIMIT); + bConstraintOb cob= {NULL}; bConstraint *con; + float ctime = (float)(t->scene->r.cfra); /* Make a temporary bConstraintOb for using these limit constraints * - they only care that cob->matrix is correctly set ;-) @@ -1998,6 +1967,8 @@ static void constraintTransLim(TransInfo *UNUSED(t), TransData *td) /* Evaluate valid constraints */ for (con= td->con; con; con= con->next) { + bConstraintTypeInfo *cti = NULL; + ListBase targets = {NULL, NULL}; float tmat[4][4]; /* only consider constraint if enabled */ @@ -2010,7 +1981,17 @@ static void constraintTransLim(TransInfo *UNUSED(t), TransData *td) if ((data->flag2 & LIMIT_TRANSFORM)==0) continue; + cti = ctiLoc; + } + else if (con->type == CONSTRAINT_TYPE_DISTLIMIT) { + bDistLimitConstraint *data= con->data; + if ((data->flag & LIMITDIST_TRANSFORM)==0) + continue; + cti = ctiDist; + } + + if (cti) { /* do space conversions */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { /* just multiply by td->mtx (this should be ok) */ @@ -2022,8 +2003,11 @@ static void constraintTransLim(TransInfo *UNUSED(t), TransData *td) continue; } + /* get constraint targets if needed */ + get_constraint_targets_for_solving(con, &cob, &targets, ctime); + /* do constraint */ - cti->evaluate_constraint(con, &cob, NULL); + cti->evaluate_constraint(con, &cob, &targets); /* convert spaces again */ if (con->ownspace == CONSTRAINT_SPACE_WORLD) { @@ -2031,6 +2015,9 @@ static void constraintTransLim(TransInfo *UNUSED(t), TransData *td) copy_m4_m4(tmat, cob.matrix); mul_m4_m3m4(cob.matrix, td->smtx, tmat); } + + /* free targets list */ + BLI_freelistN(&targets); } } @@ -2886,10 +2873,6 @@ void initRotation(TransInfo *t) setInputPostFct(&t->mouse, postInputRotation); initMouseInputMode(t, &t->mouse, INPUT_ANGLE); - t->ndof.axis = 16; - /* Scale down and flip input for rotation */ - t->ndof.factor[0] = -0.2f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3161,8 +3144,6 @@ int Rotation(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - applyNDofInput(&t->ndof, &final); - snapGrid(t, &final); if ((t->con.mode & CON_APPLY) && t->con.applyRot) { @@ -3216,11 +3197,6 @@ void initTrackball(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_TRACKBALL); - t->ndof.axis = 40; - /* Scale down input for rotation */ - t->ndof.factor[0] = 0.2f; - t->ndof.factor[1] = 0.2f; - t->idx_max = 1; t->num.idx_max = 1; t->snap[0] = 0.0f; @@ -3276,8 +3252,6 @@ int Trackball(TransInfo *t, const int UNUSED(mval[2])) phi[0] = t->values[0]; phi[1] = t->values[1]; - applyNDofInput(&t->ndof, phi); - snapGrid(t, phi); if (hasNumInput(&t->num)) { @@ -3331,8 +3305,6 @@ void initTranslation(TransInfo *t) t->num.flag = 0; t->num.idx_max = t->idx_max; - t->ndof.axis = (t->flag & T_2D_EDIT)? 1|2: 1|2|4; - if(t->spacetype == SPACE_VIEW3D) { RegionView3D *rv3d = t->ar->regiondata; @@ -3507,7 +3479,6 @@ int Translation(TransInfo *t, const int UNUSED(mval[2])) headerTranslation(t, pvec, str); } else { - applyNDofInput(&t->ndof, t->values); snapGrid(t, t->values); applyNumInput(&t->num, t->values); if (hasNumInput(&t->num)) { @@ -3616,10 +3587,6 @@ void initTilt(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_ANGLE); - t->ndof.axis = 16; - /* Scale down and flip input for rotation */ - t->ndof.factor[0] = -0.2f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3643,8 +3610,6 @@ int Tilt(TransInfo *t, const int UNUSED(mval[2])) final = t->values[0]; - applyNDofInput(&t->ndof, &final); - snapGrid(t, &final); if (hasNumInput(&t->num)) { @@ -3759,10 +3724,6 @@ void initPushPull(TransInfo *t) initMouseInputMode(t, &t->mouse, INPUT_VERTICAL_ABSOLUTE); - t->ndof.axis = 4; - /* Flip direction */ - t->ndof.factor[0] = -1.0f; - t->idx_max = 0; t->num.idx_max = 0; t->snap[0] = 0.0f; @@ -3783,8 +3744,6 @@ int PushPull(TransInfo *t, const int UNUSED(mval[2])) distance = t->values[0]; - applyNDofInput(&t->ndof, &distance); - snapGrid(t, &distance); applyNumInput(&t->num, &distance); @@ -4306,7 +4265,7 @@ static int createSlideVerts(TransInfo *t) /* UV correction vars */ GHash **uvarray= NULL; SlideData *sld = MEM_callocN(sizeof(*sld), "sld"); - int uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE); + const int uvlay_tot= (t->settings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) ? CustomData_number_of_layers(&em->fdata, CD_MTFACE) : 0; int uvlay_idx; TransDataSlideUv *slideuvs=NULL, *suv=NULL, *suv_last=NULL; RegionView3D *v3d = t->ar ? t->ar->regiondata : NULL; /* background mode support */ @@ -4659,7 +4618,7 @@ static int createSlideVerts(TransInfo *t) #define EDGE_SLIDE_MIN 30 if (len_squared_v2v2(start, end) < (EDGE_SLIDE_MIN * EDGE_SLIDE_MIN)) { if(ABS(start[0]-end[0]) + ABS(start[1]-end[1]) < 4.0f) { - /* even more exceptional case, points are ontop of eachother */ + /* even more exceptional case, points are ontop of each other */ end[0]= start[0]; end[1]= start[1] + EDGE_SLIDE_MIN; } @@ -4678,7 +4637,7 @@ static int createSlideVerts(TransInfo *t) sld->end[0] = (int) end[0]; sld->end[1] = (int) end[1]; - if (uvlay_tot) { // XXX && (scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT)) { + if (uvlay_tot) { int maxnum = 0; uvarray = MEM_callocN( uvlay_tot * sizeof(GHash *), "SlideUVs Array"); @@ -4717,7 +4676,7 @@ static int createSlideVerts(TransInfo *t) uv_new = tf->uv[k]; if (ev->tmp.l) { - if (fabs(suv->origuv[0]-uv_new[0]) > 0.0001f || fabs(suv->origuv[1]-uv_new[1]) > 0.0001f) { + if (fabsf(suv->origuv[0]-uv_new[0]) > 0.0001f || fabs(suv->origuv[1]-uv_new[1]) > 0.0001f) { ev->tmp.l = -1; /* Tag as invalid */ BLI_linklist_free(suv->fuv_list,NULL); suv->fuv_list = NULL; @@ -4868,8 +4827,6 @@ void initEdgeSlide(TransInfo *t) int doEdgeSlide(TransInfo *t, float perc) { - Mesh *me= t->obedit->data; - EditMesh *em = me->edit_mesh; SlideData *sld = t->customData; EditVert *ev, *nearest = sld->nearest; EditVert *centerVert, *upVert, *downVert; @@ -4880,7 +4837,7 @@ int doEdgeSlide(TransInfo *t, float perc) int prop=1, flip=0; /* UV correction vars */ GHash **uvarray= sld->uvhash; - int uvlay_tot= CustomData_number_of_layers(&em->fdata, CD_MTFACE); + const int uvlay_tot= sld->uvlay_tot; int uvlay_idx; TransDataSlideUv *suv; float uv_tmp[2]; @@ -4906,7 +4863,7 @@ int doEdgeSlide(TransInfo *t, float perc) tempev = editedge_getOtherVert((perc>=0)?tempsv->up:tempsv->down, ev); interp_v3_v3v3(ev->co, tempsv->origvert.co, tempev->co, fabs(perc)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); if (suv && suv->fuv_list && suv->uv_up && suv->uv_down) { @@ -4936,7 +4893,7 @@ int doEdgeSlide(TransInfo *t, float perc) if(newlen < 0.0f) {newlen = 0.0;} if(flip == 0) { interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->down,ev)->co, editedge_getOtherVert(tempsv->up,ev)->co, fabs(newlen)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); @@ -4953,7 +4910,7 @@ int doEdgeSlide(TransInfo *t, float perc) } else{ interp_v3_v3v3(ev->co, editedge_getOtherVert(tempsv->up,ev)->co, editedge_getOtherVert(tempsv->down,ev)->co, fabs(newlen)); - if (uvlay_tot) { // XXX scene->toolsettings->uvcalc_flag & UVCALC_TRANSFORM_CORRECT) { + if (uvlay_tot) { /* dont do anything if no UVs */ for (uvlay_idx=0; uvlay_idx<uvlay_tot; uvlay_idx++) { suv = BLI_ghash_lookup( uvarray[uvlay_idx], ev ); @@ -5309,8 +5266,6 @@ void initSeqSlide(TransInfo *t) t->num.flag = 0; t->num.idx_max = t->idx_max; - t->ndof.axis = 1|2; - t->snap[0] = 0.0f; t->snap[1] = floor(t->scene->r.frs_sec / t->scene->r.frs_sec_base); t->snap[2] = 10.0f; @@ -5365,7 +5320,6 @@ int SeqSlide(TransInfo *t, const int UNUSED(mval[2])) VECCOPY(t->values, tvec); } else { - applyNDofInput(&t->ndof, t->values); snapGrid(t, t->values); applyNumInput(&t->num, t->values); } @@ -5530,7 +5484,7 @@ static void doAnimEdit_SnapFrame(TransInfo *t, TransData *td, TransData2D *td2d, void initTimeTranslate(TransInfo *t) { /* this tool is only really available in the Action Editor... */ - if (t->spacetype != SPACE_ACTION) { + if (!ELEM(t->spacetype, SPACE_ACTION, SPACE_SEQ)) { t->state = TRANS_CANCEL; } @@ -5783,8 +5737,8 @@ int TimeSlide(TransInfo *t, const int mval[2]) char str[200]; /* calculate mouse co-ordinates */ - UI_view2d_region_to_view(v2d, mval[0], mval[0], &cval[0], &cval[1]); - UI_view2d_region_to_view(v2d, t->imval[0], t->imval[0], &sval[0], &sval[1]); + UI_view2d_region_to_view(v2d, mval[0], mval[1], &cval[0], &cval[1]); + UI_view2d_region_to_view(v2d, t->imval[0], t->imval[1], &sval[0], &sval[1]); /* t->values[0] stores cval[0], which is the current mouse-pointer location (in frames) */ // XXX Need to be able to repeat this @@ -5925,54 +5879,3 @@ void BIF_TransformSetUndo(char *UNUSED(str)) // TRANSFORM_FIX_ME //Trans.undostr= str; } - - -#if 0 // TRANSFORM_FIX_ME -static void NDofTransform(void) -{ - float fval[7]; - float maxval = 50.0f; // also serves as threshold - int axis = -1; - int mode = 0; - int i; - - getndof(fval); - - for(i = 0; i < 6; i++) - { - float val = fabs(fval[i]); - if (val > maxval) - { - axis = i; - maxval = val; - } - } - - switch(axis) - { - case -1: - /* No proper axis found */ - break; - case 0: - case 1: - case 2: - mode = TFM_TRANSLATION; - break; - case 4: - mode = TFM_ROTATION; - break; - case 3: - case 5: - mode = TFM_TRACKBALL; - break; - default: - printf("ndof: what we are doing here ?"); - } - - if (mode != 0) - { - initTransform(mode, CTX_NDOF); - Transform(); - } -} -#endif |