mask transform now works in the image space

This commit is contained in:
Campbell Barton
2012-07-25 19:36:59 +00:00
parent a9614e732c
commit 927af4ccc9
8 changed files with 117 additions and 71 deletions

View File

@@ -263,7 +263,7 @@ void ED_mask_aspect(const bContext *C, float *aspx, float *aspy)
case SPACE_IMAGE:
{
SpaceImage *sima = sa->spacedata.first;
ED_space_image_get_uv_aspect(sima, aspx, aspy);
ED_space_image_get_aspect(sima, aspx, aspy);
break;
}
default:
@@ -312,7 +312,7 @@ void ED_mask_pixelspace_factor(const bContext *C, float *scalex, float *scaley)
ED_space_image_get_size(sima, &width, &height);
ED_space_image_get_zoom(sima, ar, &zoomx, &zoomy);
ED_space_image_get_uv_aspect(sima, &aspx, &aspy);
ED_space_image_get_aspect(sima, &aspx, &aspy);
*scalex = ((float)width * aspx) * zoomx;
*scaley = ((float)height * aspy) * zoomy;

View File

@@ -128,11 +128,11 @@ void ED_space_clip_get_size(const bContext *C, int *width, int *height)
{
SpaceClip *sc = CTX_wm_space_clip(C);
if (!sc->clip) {
*width = *height = 0;
if (sc->clip) {
BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
}
else {
BKE_movieclip_get_size(sc->clip, &sc->user, width, height);
*width = *height = IMG_SIZE_FALLBACK;
}
}

View File

@@ -149,8 +149,8 @@ void ED_image_get_size(Image *ima, int *width, int *height)
*height = ibuf->y;
}
else {
*width = 256;
*height = 256;
*width = IMG_SIZE_FALLBACK;
*height = IMG_SIZE_FALLBACK;
}
if (ima)
@@ -183,8 +183,8 @@ void ED_space_image_get_size(SpaceImage *sima, int *width, int *height)
/* I know a bit weak... but preview uses not actual image size */
// XXX else if (image_preview_active(sima, width, height));
else {
*width = 256;
*height = 256;
*width = IMG_SIZE_FALLBACK;
*height = IMG_SIZE_FALLBACK;
}
ED_space_image_release_buffer(sima, lock);

View File

@@ -120,16 +120,44 @@ void setTransformViewMatrices(TransInfo *t)
calculateCenter2D(t);
}
static void convertViewVec2D(View2D *v2d, float vec[3], int dx, int dy)
static void convertViewVec2D(View2D *v2d, float r_vec[3], int dx, int dy)
{
float divx, divy;
divx = v2d->mask.xmax - v2d->mask.xmin;
divy = v2d->mask.ymax - v2d->mask.ymin;
vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
vec[2] = 0.0f;
r_vec[0] = (v2d->cur.xmax - v2d->cur.xmin) * dx / divx;
r_vec[1] = (v2d->cur.ymax - v2d->cur.ymin) * dy / divy;
r_vec[2] = 0.0f;
}
static void convertViewVec2D_mask(View2D *v2d, float r_vec[3], int dx, int dy)
{
float divx, divy;
float mulx, muly;
divx = v2d->mask.xmax - v2d->mask.xmin;
divy = v2d->mask.ymax - v2d->mask.ymin;
mulx = (v2d->cur.xmax - v2d->cur.xmin);
muly = (v2d->cur.ymax - v2d->cur.ymin);
/* difference with convertViewVec2D */
/* clamp w/h, mask only */
if (mulx / divx < muly / divy) {
divy = divx;
muly = mulx;
}
else {
divx = divy;
mulx = muly;
}
/* end difference */
r_vec[0] = mulx * dx / divx;
r_vec[1] = muly * dy / divy;
r_vec[2] = 0.0f;
}
void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
@@ -143,11 +171,17 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
else if (t->spacetype == SPACE_IMAGE) {
float aspx, aspy;
convertViewVec2D(t->view, r_vec, dx, dy);
if (t->options & CTX_MASK) {
/* MASKTODO - see clip clamp w/h */
convertViewVec2D_mask(t->view, r_vec, dx, dy);
ED_space_image_get_aspect(t->sa->spacedata.first, &aspx, &aspy);
}
else {
convertViewVec2D(t->view, r_vec, dx, dy);
ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
}
ED_space_image_get_uv_aspect(t->sa->spacedata.first, &aspx, &aspy);
r_vec[0] *= aspx;
r_vec[1] *= aspy;
}
@@ -158,32 +192,14 @@ void convertViewVec(TransInfo *t, float r_vec[3], int dx, int dy)
convertViewVec2D(&t->ar->v2d, r_vec, dx, dy);
}
else if (t->spacetype == SPACE_CLIP) {
View2D *v2d = t->view;
float divx, divy;
float mulx, muly;
float aspx = 1.0f, aspy = 1.0f;
divx = v2d->mask.xmax - v2d->mask.xmin;
divy = v2d->mask.ymax - v2d->mask.ymin;
mulx = (v2d->cur.xmax - v2d->cur.xmin);
muly = (v2d->cur.ymax - v2d->cur.ymin);
float aspx, aspy;
if (t->options & CTX_MASK) {
/* clamp w/h, mask only */
if (mulx / divx < muly / divy) {
divy = divx;
muly = mulx;
}
else {
divx = divy;
mulx = muly;
}
convertViewVec2D_mask(t->view, r_vec, dx, dy);
}
else {
convertViewVec2D(t->view, r_vec, dx, dy);
}
r_vec[0] = mulx * (dx) / divx;
r_vec[1] = muly * (dy) / divy;
r_vec[2] = 0.0f;
if (t->options & CTX_MOVIECLIP) {
ED_space_clip_get_aspect_dimension_aware(t->sa->spacedata.first, &aspx, &aspy);

View File

@@ -4964,6 +4964,36 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o
}
}
static void special_aftertrans_update__mask(bContext *C, TransInfo *t)
{
Mask *mask;
if (t->spacetype == SPACE_CLIP) {
SpaceClip *sc = t->sa->spacedata.first;
mask = ED_space_clip_get_mask(sc);
}
else if (t->spacetype == SPACE_IMAGE) {
SpaceImage *sima = t->sa->spacedata.first;
mask = ED_space_image_get_mask(sima);
}
else {
BLI_assert(0);
}
if (t->scene->nodetree) {
/* tracks can be used for stabilization nodes,
* flush update for such nodes */
nodeUpdateID(t->scene->nodetree, &mask->id);
WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL);
}
/* TODO - dont key all masks... */
if (IS_AUTOKEY_ON(t->scene)) {
Scene *scene = t->scene;
ED_mask_layer_shape_auto_key_select(mask, CFRA);
}
}
/* inserting keys, pointcache, redraw events... */
/*
@@ -5033,7 +5063,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
}
}
else if (t->spacetype == SPACE_IMAGE) {
/* prevent this passing through to final 'else' which assumes objects */
if (t->options & CTX_MASK) {
special_aftertrans_update__mask(C, t);
}
}
else if (t->spacetype == SPACE_NODE) {
SpaceNode *snode = (SpaceNode *)t->sa->spacedata.first;
@@ -5059,22 +5091,7 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
}
}
else if (t->options & CTX_MASK) {
SpaceClip *sc = t->sa->spacedata.first;
Mask *mask = ED_space_clip_get_mask(sc);
if (t->scene->nodetree) {
/* tracks can be used for stabilization nodes,
* flush update for such nodes */
nodeUpdateID(t->scene->nodetree, &mask->id);
WM_event_add_notifier(C, NC_SCENE | ND_NODES, NULL);
}
/* TODO - dont key all masks... */
if (IS_AUTOKEY_ON(t->scene)) {
Scene *scene = t->scene;
ED_mask_layer_shape_auto_key_select(mask, CFRA);
}
special_aftertrans_update__mask(C, t);
}
}
else if (t->spacetype == SPACE_ACTION) {
@@ -6259,20 +6276,19 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
void flushTransMasking(TransInfo *t)
{
SpaceClip *sc = t->sa->spacedata.first;
TransData2D *td;
TransDataMasking *tdm;
int a;
float aspx, aspy, invx, invy;
float asp[2], inv[2];
ED_space_clip_get_aspect(sc, &aspx, &aspy);
invx = 1.0f / aspx;
invy = 1.0f / aspy;
ED_mask_aspect(t->context, &asp[0], &asp[1]);
inv[0] = 1.0f / asp[0];
inv[1] = 1.0f / asp[1];
/* flush to 2d vector from internally used 3d vector */
for (a = 0, td = t->data2d, tdm = t->customData; a < t->total; a++, td++, tdm++) {
td->loc2d[0] = td->loc[0] * invx;
td->loc2d[1] = td->loc[1] * invy;
td->loc2d[0] = td->loc[0] * inv[0];
td->loc2d[1] = td->loc[1] * inv[1];
if (tdm->is_handle)
BKE_mask_point_set_handle(tdm->point, td->loc2d, t->flag & T_ALT_TRANSFORM, tdm->orig_handle, tdm->vec);

View File

@@ -607,6 +607,15 @@ static void recalcData_nla(TransInfo *t)
}
}
static void recalcData_mask_common(TransInfo *t)
{
Mask *mask = CTX_data_edit_mask(t->context);
flushTransMasking(t);
DAG_id_tag_update(&mask->id, 0);
}
/* helper for recalcData() - for Image Editor transforms */
static void recalcData_image(TransInfo *t)
{
@@ -619,6 +628,9 @@ static void recalcData_image(TransInfo *t)
DAG_id_tag_update(t->obedit->data, 0);
}
else if (t->options & CTX_MASK) {
recalcData_mask_common(t);
}
}
/* helper for recalcData() - for Movie Clip transforms */
@@ -662,12 +674,8 @@ static void recalcData_spaceclip(TransInfo *t)
DAG_id_tag_update(&clip->id, 0);
}
else if (ED_space_clip_check_show_maskedit(sc)) {
Mask *mask = ED_space_clip_get_mask(sc);
flushTransMasking(t);
DAG_id_tag_update(&mask->id, 0);
else if (t->options & CTX_MASK) {
recalcData_mask_common(t);
}
}
@@ -908,6 +916,10 @@ void recalcData(TransInfo *t)
else if (t->spacetype == SPACE_CLIP) {
recalcData_spaceclip(t);
}
if (t->options & CTX_MASK) {
}
}
void drawLine(TransInfo *t, float *center, float *dir, char axis, short options)

View File

@@ -208,8 +208,8 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
ED_space_image_get_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp);
ED_space_image_width(t->sa->spacedata.first, &wi, &hi);
w = (((float)wi) / 256.0f) * G.sima->zoom * xuser_asp;
h = (((float)hi) / 256.0f) * G.sima->zoom * yuser_asp;
w = (((float)wi) / IMG_SIZE_FALLBACK) * G.sima->zoom * xuser_asp;
h = (((float)hi) / IMG_SIZE_FALLBACK) * G.sima->zoom * yuser_asp;
cpack(0xFFFFFF);
glTranslatef(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], 0.0f);

View File

@@ -1115,4 +1115,6 @@ typedef enum eSpace_Type {
SPACEICONMAX = SPACE_CLIP
} eSpace_Type;
#define IMG_SIZE_FALLBACK 256
#endif