Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/transform/transform_convert_mask.c
| Show All 31 Lines | |||||
| #include "BKE_mask.h" | #include "BKE_mask.h" | ||||
| #include "BKE_report.h" | #include "BKE_report.h" | ||||
| #include "ED_clip.h" | #include "ED_clip.h" | ||||
| #include "ED_mask.h" | #include "ED_mask.h" | ||||
| #include "transform.h" | #include "transform.h" | ||||
| #include "transform_convert.h" | #include "transform_convert.h" | ||||
| #include "transform_data.h" | |||||
| typedef struct TransDataMasking { | typedef struct TransDataMasking { | ||||
| bool is_handle; | bool is_handle; | ||||
| float handle[2], orig_handle[2]; | float handle[2], orig_handle[2]; | ||||
| float vec[3][3]; | float vec[3][3]; | ||||
| struct MaskSplinePoint *point; | struct MaskSplinePoint *point; | ||||
| float parent_matrix[3][3]; | float parent_matrix[3][3]; | ||||
| float parent_inverse_matrix[3][3]; | float parent_inverse_matrix[3][3]; | ||||
| char orig_handle_type; | char orig_handle_type; | ||||
| eMaskWhichHandle which_handle; | eMaskWhichHandle which_handle; | ||||
| } TransDataMasking; | } TransDataMasking; | ||||
| /* -------------------------------------------------------------------- */ | /* -------------------------------------------------------------------- */ | ||||
| /** \name Masking Transform Creation | /** \name Masking Transform Creation | ||||
| * | * | ||||
| * \{ */ | * \{ */ | ||||
| static void MaskHandleToTransData(MaskSplinePoint *point, | static void MaskHandleToTransData(MaskSplinePoint *point, | ||||
| eMaskWhichHandle which_handle, | eMaskWhichHandle which_handle, | ||||
| TransData *td, | TransData *td, | ||||
| const int tdi, | |||||
| TransData2D *td2d, | TransData2D *td2d, | ||||
| TransDataMasking *tdm, | TransDataMasking *tdm, | ||||
| const float asp[2], | const float asp[2], | ||||
| /*const*/ const float parent_matrix[3][3], | /*const*/ const float parent_matrix[3][3], | ||||
| /*const*/ const float parent_inverse_matrix[3][3]) | /*const*/ const float parent_inverse_matrix[3][3]) | ||||
| { | { | ||||
| BezTriple *bezt = &point->bezt; | BezTriple *bezt = &point->bezt; | ||||
| const bool is_sel_any = MASKPOINT_ISSEL_ANY(point); | const bool is_sel_any = MASKPOINT_ISSEL_ANY(point); | ||||
| Show All 12 Lines | static void MaskHandleToTransData(MaskSplinePoint *point, | ||||
| mul_v2_m3v2(td2d->loc, parent_matrix, tdm->handle); | mul_v2_m3v2(td2d->loc, parent_matrix, tdm->handle); | ||||
| td2d->loc[0] *= asp[0]; | td2d->loc[0] *= asp[0]; | ||||
| td2d->loc[1] *= asp[1]; | td2d->loc[1] *= asp[1]; | ||||
| td2d->loc[2] = 0.0f; | td2d->loc[2] = 0.0f; | ||||
| td2d->loc2d = tdm->handle; | td2d->loc2d = tdm->handle; | ||||
| td->flag = 0; | td->basic[tdi].flag = 0; | ||||
| td->loc = td2d->loc; | td->basic[tdi].loc = td2d->loc; | ||||
| mul_v2_m3v2(td->center, parent_matrix, bezt->vec[1]); | mul_v2_m3v2(td->center[tdi], parent_matrix, bezt->vec[1]); | ||||
| td->center[0] *= asp[0]; | td->center[tdi][0] *= asp[0]; | ||||
| td->center[1] *= asp[1]; | td->center[tdi][1] *= asp[1]; | ||||
| copy_v3_v3(td->iloc, td->loc); | copy_v3_v3(td->basic[tdi].iloc, td->basic[tdi].loc); | ||||
| memset(td->axismtx, 0, sizeof(td->axismtx)); | const float axismtx[3][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}; | ||||
| td->axismtx[2][2] = 1.0f; | copy_m3_m3(td->space[tdi].axismtx, axismtx); | ||||
| td->ext = NULL; | td->special[tdi].val = NULL; | ||||
| td->val = NULL; | |||||
| if (is_sel_any) { | if (is_sel_any) { | ||||
| td->flag |= TD_SELECTED; | td->basic[tdi].flag |= TD_SELECTED; | ||||
| } | } | ||||
| td->dist = 0.0; | td->prop[tdi].dist = 0.0; | ||||
| unit_m3(td->mtx); | unit_m3(td->space[tdi].mtx); | ||||
| unit_m3(td->smtx); | unit_m3(td->space[tdi].smtx); | ||||
| if (which_handle == MASK_WHICH_HANDLE_LEFT) { | if (which_handle == MASK_WHICH_HANDLE_LEFT) { | ||||
| tdm->orig_handle_type = bezt->h1; | tdm->orig_handle_type = bezt->h1; | ||||
| } | } | ||||
| else if (which_handle == MASK_WHICH_HANDLE_RIGHT) { | else if (which_handle == MASK_WHICH_HANDLE_RIGHT) { | ||||
| tdm->orig_handle_type = bezt->h2; | tdm->orig_handle_type = bezt->h2; | ||||
| } | } | ||||
| } | } | ||||
| static void MaskPointToTransData(Scene *scene, | static void MaskPointToTransData(Scene *scene, | ||||
| MaskSplinePoint *point, | MaskSplinePoint *point, | ||||
| TransData *td, | TransData *td, | ||||
| int tdi, | |||||
| TransData2D *td2d, | TransData2D *td2d, | ||||
| TransDataMasking *tdm, | TransDataMasking *tdm, | ||||
| const bool is_prop_edit, | const bool is_prop_edit, | ||||
| const float asp[2]) | const float asp[2]) | ||||
| { | { | ||||
| BezTriple *bezt = &point->bezt; | BezTriple *bezt = &point->bezt; | ||||
| const bool is_sel_point = MASKPOINT_ISSEL_KNOT(point); | const bool is_sel_point = MASKPOINT_ISSEL_KNOT(point); | ||||
| const bool is_sel_any = MASKPOINT_ISSEL_ANY(point); | const bool is_sel_any = MASKPOINT_ISSEL_ANY(point); | ||||
| Show All 18 Lines | for (i = 0; i < 3; i++) { | ||||
| * and when the CV coords are flushed, these are converted each time */ | * and when the CV coords are flushed, these are converted each time */ | ||||
| mul_v2_m3v2(td2d->loc, parent_matrix, bezt->vec[i]); | mul_v2_m3v2(td2d->loc, parent_matrix, bezt->vec[i]); | ||||
| td2d->loc[0] *= asp[0]; | td2d->loc[0] *= asp[0]; | ||||
| td2d->loc[1] *= asp[1]; | td2d->loc[1] *= asp[1]; | ||||
| td2d->loc[2] = 0.0f; | td2d->loc[2] = 0.0f; | ||||
| td2d->loc2d = bezt->vec[i]; | td2d->loc2d = bezt->vec[i]; | ||||
| td->flag = 0; | td->basic[tdi].flag = 0; | ||||
| td->loc = td2d->loc; | td->basic[tdi].loc = td2d->loc; | ||||
| mul_v2_m3v2(td->center, parent_matrix, bezt->vec[1]); | mul_v2_m3v2(td->center[tdi], parent_matrix, bezt->vec[1]); | ||||
| td->center[0] *= asp[0]; | td->center[tdi][0] *= asp[0]; | ||||
| td->center[1] *= asp[1]; | td->center[tdi][1] *= asp[1]; | ||||
| copy_v3_v3(td->iloc, td->loc); | copy_v3_v3(td->basic[tdi].iloc, td->basic[tdi].loc); | ||||
| memset(td->axismtx, 0, sizeof(td->axismtx)); | const float axismtx[3][3] = {{0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 0.0f}, {0.0f, 0.0f, 1.0f}}; | ||||
| td->axismtx[2][2] = 1.0f; | copy_m3_m3(td->space[tdi].axismtx, axismtx); | ||||
| td->ext = NULL; | |||||
| if (i == 1) { | if (i == 1) { | ||||
| /* scaling weights */ | /* scaling weights */ | ||||
| td->val = &bezt->weight; | td->special[tdi].val = &bezt->weight; | ||||
| td->ival = *td->val; | td->special[tdi].ival = bezt->weight; | ||||
| } | } | ||||
| else { | else { | ||||
| td->val = NULL; | td->special[tdi].val = NULL; | ||||
| } | } | ||||
| if (is_sel_any) { | if (is_sel_any) { | ||||
| td->flag |= TD_SELECTED; | td->basic[tdi].flag |= TD_SELECTED; | ||||
| } | } | ||||
| td->dist = 0.0; | td->prop[tdi].dist = 0.0; | ||||
| unit_m3(td->mtx); | unit_m3(td->space[tdi].mtx); | ||||
| unit_m3(td->smtx); | unit_m3(td->space[tdi].smtx); | ||||
| if (i == 0) { | if (i == 0) { | ||||
| tdm->orig_handle_type = bezt->h1; | tdm->orig_handle_type = bezt->h1; | ||||
| } | } | ||||
| else if (i == 2) { | else if (i == 2) { | ||||
| tdm->orig_handle_type = bezt->h2; | tdm->orig_handle_type = bezt->h2; | ||||
| } | } | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) { | if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) { | ||||
| MaskHandleToTransData(point, | MaskHandleToTransData(point, | ||||
| MASK_WHICH_HANDLE_STICK, | MASK_WHICH_HANDLE_STICK, | ||||
| td, | td, | ||||
| tdi, | |||||
| td2d, | td2d, | ||||
| tdm, | tdm, | ||||
| asp, | asp, | ||||
| parent_matrix, | parent_matrix, | ||||
| parent_inverse_matrix); | parent_inverse_matrix); | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| else { | else { | ||||
| if (bezt->f1 & SELECT) { | if (bezt->f1 & SELECT) { | ||||
| MaskHandleToTransData(point, | MaskHandleToTransData(point, | ||||
| MASK_WHICH_HANDLE_LEFT, | MASK_WHICH_HANDLE_LEFT, | ||||
| td, | td, | ||||
| tdi, | |||||
| td2d, | td2d, | ||||
| tdm, | tdm, | ||||
| asp, | asp, | ||||
| parent_matrix, | parent_matrix, | ||||
| parent_inverse_matrix); | parent_inverse_matrix); | ||||
| if (bezt->h1 == HD_VECT) { | if (bezt->h1 == HD_VECT) { | ||||
| bezt->h1 = HD_FREE; | bezt->h1 = HD_FREE; | ||||
| } | } | ||||
| else if (bezt->h1 == HD_AUTO) { | else if (bezt->h1 == HD_AUTO) { | ||||
| bezt->h1 = HD_ALIGN_DOUBLESIDE; | bezt->h1 = HD_ALIGN_DOUBLESIDE; | ||||
| bezt->h2 = HD_ALIGN_DOUBLESIDE; | bezt->h2 = HD_ALIGN_DOUBLESIDE; | ||||
| } | } | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| if (bezt->f3 & SELECT) { | if (bezt->f3 & SELECT) { | ||||
| MaskHandleToTransData(point, | MaskHandleToTransData(point, | ||||
| MASK_WHICH_HANDLE_RIGHT, | MASK_WHICH_HANDLE_RIGHT, | ||||
| td, | td, | ||||
| tdi, | |||||
| td2d, | td2d, | ||||
| tdm, | tdm, | ||||
| asp, | asp, | ||||
| parent_matrix, | parent_matrix, | ||||
| parent_inverse_matrix); | parent_inverse_matrix); | ||||
| if (bezt->h2 == HD_VECT) { | if (bezt->h2 == HD_VECT) { | ||||
| bezt->h2 = HD_FREE; | bezt->h2 = HD_FREE; | ||||
| } | } | ||||
| else if (bezt->h2 == HD_AUTO) { | else if (bezt->h2 == HD_AUTO) { | ||||
| bezt->h1 = HD_ALIGN_DOUBLESIDE; | bezt->h1 = HD_ALIGN_DOUBLESIDE; | ||||
| bezt->h2 = HD_ALIGN_DOUBLESIDE; | bezt->h2 = HD_ALIGN_DOUBLESIDE; | ||||
| } | } | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| void createTransMaskingData(bContext *C, TransInfo *t) | void createTransMaskingData(bContext *C, TransInfo *t) | ||||
| { | { | ||||
| Scene *scene = CTX_data_scene(C); | Scene *scene = CTX_data_scene(C); | ||||
| Mask *mask = CTX_data_edit_mask(C); | Mask *mask = CTX_data_edit_mask(C); | ||||
| MaskLayer *masklay; | MaskLayer *masklay; | ||||
| TransData *td = NULL; | |||||
| TransData2D *td2d = NULL; | TransData2D *td2d = NULL; | ||||
| TransDataMasking *tdm = NULL; | TransDataMasking *tdm = NULL; | ||||
| int count = 0, countsel = 0; | int count = 0, countsel = 0; | ||||
| const bool is_prop_edit = (t->flag & T_PROP_EDIT); | const bool is_prop_edit = (t->flag & T_PROP_EDIT); | ||||
| float asp[2]; | float asp[2]; | ||||
| TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); | TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t); | ||||
| ▲ Show 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | void createTransMaskingData(bContext *C, TransInfo *t) | ||||
| /* note: in prop mode we need at least 1 selected */ | /* note: in prop mode we need at least 1 selected */ | ||||
| if (countsel == 0) { | if (countsel == 0) { | ||||
| return; | return; | ||||
| } | } | ||||
| ED_mask_get_aspect(t->area, t->region, &asp[0], &asp[1]); | ED_mask_get_aspect(t->area, t->region, &asp[0], &asp[1]); | ||||
| tc->data_len = (is_prop_edit) ? count : countsel; | tc->data_len = (is_prop_edit) ? count : countsel; | ||||
| td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Mask Editing)"); | TransData *td = tc->data = transform_data_alloc(tc->data_len, TD_BASIC_COMP); | ||||
| int tdi = 0; | |||||
| /* for each 2d uv coord a 3d vector is allocated, so that they can be | /* for each 2d uv coord a 3d vector is allocated, so that they can be | ||||
| * treated just as if they were 3d verts */ | * treated just as if they were 3d verts */ | ||||
| td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), | td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), | ||||
| "TransObData2D(Mask Editing)"); | "TransObData2D(Mask Editing)"); | ||||
| tc->custom.type.data = tdm = MEM_callocN(tc->data_len * sizeof(TransDataMasking), | tc->custom.type.data = tdm = MEM_callocN(tc->data_len * sizeof(TransDataMasking), | ||||
| "TransDataMasking(Mask Editing)"); | "TransDataMasking(Mask Editing)"); | ||||
| tc->custom.type.use_free = true; | tc->custom.type.use_free = true; | ||||
| /* create data */ | /* create data */ | ||||
| for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { | for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) { | ||||
| MaskSpline *spline; | MaskSpline *spline; | ||||
| if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | if (masklay->restrictflag & (MASK_RESTRICT_VIEW | MASK_RESTRICT_SELECT)) { | ||||
| continue; | continue; | ||||
| } | } | ||||
| for (spline = masklay->splines.first; spline; spline = spline->next) { | for (spline = masklay->splines.first; spline; spline = spline->next) { | ||||
| int i; | int i; | ||||
| for (i = 0; i < spline->tot_point; i++) { | for (i = 0; i < spline->tot_point; i++) { | ||||
| MaskSplinePoint *point = &spline->points[i]; | MaskSplinePoint *point = &spline->points[i]; | ||||
| if (is_prop_edit || MASKPOINT_ISSEL_ANY(point)) { | if (is_prop_edit || MASKPOINT_ISSEL_ANY(point)) { | ||||
| MaskPointToTransData(scene, point, td, td2d, tdm, is_prop_edit, asp); | MaskPointToTransData(scene, point, td, tdi, td2d, tdm, is_prop_edit, asp); | ||||
| if (is_prop_edit || MASKPOINT_ISSEL_KNOT(point)) { | if (is_prop_edit || MASKPOINT_ISSEL_KNOT(point)) { | ||||
| td += 3; | tdi += 3; | ||||
| td2d += 3; | td2d += 3; | ||||
| tdm += 3; | tdm += 3; | ||||
| } | } | ||||
| else { | else { | ||||
| if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) { | if (BKE_mask_point_handles_mode_get(point) == MASK_HANDLE_MODE_STICK) { | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| else { | else { | ||||
| BezTriple *bezt = &point->bezt; | BezTriple *bezt = &point->bezt; | ||||
| if (bezt->f1 & SELECT) { | if (bezt->f1 & SELECT) { | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| if (bezt->f3 & SELECT) { | if (bezt->f3 & SELECT) { | ||||
| td++; | tdi++; | ||||
| td2d++; | td2d++; | ||||
| tdm++; | tdm++; | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 50 Lines • Show Last 20 Lines | |||||