Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_mode_tosphere.c
| Show All 30 Lines | |||||
| #include "ED_screen.h" | #include "ED_screen.h" | ||||
| #include "UI_interface.h" | #include "UI_interface.h" | ||||
| #include "BLT_translation.h" | #include "BLT_translation.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_data.h" | |||||
| #include "transform_mode.h" | #include "transform_mode.h" | ||||
| #include "transform_snap.h" | #include "transform_snap.h" | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /* Transform (ToSphere) */ | /* Transform (ToSphere) */ | ||||
| /** \name Transform ToSphere | /** \name Transform ToSphere | ||||
| * \{ */ | * \{ */ | ||||
| static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) | static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) | ||||
| { | { | ||||
| float vec[3]; | float vec[3]; | ||||
| float ratio, radius; | float ratio, radius; | ||||
| int i; | |||||
| char str[UI_MAX_DRAW_STR]; | char str[UI_MAX_DRAW_STR]; | ||||
| ratio = t->values[0]; | ratio = t->values[0]; | ||||
| snapGridIncrement(t, &ratio); | snapGridIncrement(t, &ratio); | ||||
| applyNumInput(&t->num, &ratio); | applyNumInput(&t->num, &ratio); | ||||
| Show All 11 Lines | static void applyToSphere(TransInfo *t, const int UNUSED(mval[2])) | ||||
| } | } | ||||
| else { | else { | ||||
| /* default header print */ | /* default header print */ | ||||
| BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %.4f %s"), ratio, t->proptext); | BLI_snprintf(str, sizeof(str), TIP_("To Sphere: %.4f %s"), ratio, t->proptext); | ||||
| } | } | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransData *td = tc->data; | TransData *td = tc->data; | ||||
| for (i = 0; i < tc->data_len; i++, td++) { | for (int tdi = 0; tdi < tc->data_len; tdi++) { | ||||
| float tratio; | float tratio; | ||||
| if (td->flag & TD_SKIP) { | if (td->basic[tdi].flag & TD_SKIP) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| sub_v3_v3v3(vec, td->iloc, tc->center_local); | sub_v3_v3v3(vec, td->basic[tdi].iloc, tc->center_local); | ||||
| radius = normalize_v3(vec); | radius = normalize_v3(vec); | ||||
| tratio = ratio * td->factor; | tratio = ratio * td->prop[tdi].factor; | ||||
| mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio); | mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio); | ||||
| add_v3_v3v3(td->loc, tc->center_local, vec); | add_v3_v3v3(td->basic[tdi].loc, tc->center_local, vec); | ||||
| } | } | ||||
| } | } | ||||
| recalcData(t); | recalcData(t); | ||||
| ED_area_status_text(t->area, str); | ED_area_status_text(t->area, str); | ||||
| } | } | ||||
| void initToSphere(TransInfo *t) | void initToSphere(TransInfo *t) | ||||
| { | { | ||||
| int i; | |||||
| t->mode = TFM_TOSPHERE; | t->mode = TFM_TOSPHERE; | ||||
| t->transform = applyToSphere; | t->transform = applyToSphere; | ||||
| initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO); | initMouseInputMode(t, &t->mouse, INPUT_HORIZONTAL_RATIO); | ||||
| t->idx_max = 0; | t->idx_max = 0; | ||||
| t->num.idx_max = 0; | t->num.idx_max = 0; | ||||
| t->snap[0] = 0.0f; | t->snap[0] = 0.0f; | ||||
| t->snap[1] = 0.1f; | t->snap[1] = 0.1f; | ||||
| t->snap[2] = t->snap[1] * 0.1f; | t->snap[2] = t->snap[1] * 0.1f; | ||||
| copy_v3_fl(t->num.val_inc, t->snap[1]); | copy_v3_fl(t->num.val_inc, t->snap[1]); | ||||
| t->num.unit_sys = t->scene->unit.system; | t->num.unit_sys = t->scene->unit.system; | ||||
| t->num.unit_type[0] = B_UNIT_NONE; | t->num.unit_type[0] = B_UNIT_NONE; | ||||
| t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE; | t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE; | ||||
| t->flag |= T_NO_CONSTRAINT; | t->flag |= T_NO_CONSTRAINT; | ||||
| // Calculate average radius | // Calculate average radius | ||||
| FOREACH_TRANS_DATA_CONTAINER (t, tc) { | FOREACH_TRANS_DATA_CONTAINER (t, tc) { | ||||
| TransData *td = tc->data; | TransData *td = tc->data; | ||||
| for (i = 0; i < tc->data_len; i++, td++) { | for (int tdi = 0; tdi < tc->data_len; tdi++) { | ||||
| t->val += len_v3v3(tc->center_local, td->iloc); | t->val += len_v3v3(tc->center_local, td->basic[tdi].iloc); | ||||
| } | } | ||||
| } | } | ||||
| t->val /= (float)t->data_len_all; | t->val /= (float)t->data_len_all; | ||||
| } | } | ||||
| /** \} */ | /** \} */ | ||||