Index: source/blender/makesdna/DNA_lattice_types.h =================================================================== --- source/blender/makesdna/DNA_lattice_types.h (revision 57304) +++ source/blender/makesdna/DNA_lattice_types.h (working copy) @@ -56,8 +56,8 @@ short pntsu, pntsv, pntsw, flag; short opntsu, opntsv, opntsw, pad2; char typeu, typev, typew, pad3; - int pad; - + int actbp; /* active element index, unset with LT_ACTBP_NONE */ + float fu, fv, fw, du, dv, dw; struct BPoint *def; @@ -85,5 +85,7 @@ #define LT_INDEX(lt, u, v, w) ((w) * ((lt)->pntsu * (lt)->pntsv) + ((v) * (lt)->pntsu) + (u)) +#define LT_ACTBP_NONE -1 + #endif Index: source/blender/editors/object/object_vgroup.c =================================================================== --- source/blender/editors/object/object_vgroup.c (revision 57304) +++ source/blender/editors/object/object_vgroup.c (working copy) @@ -65,6 +65,7 @@ #include "BKE_DerivedMesh.h" #include "BKE_object_deform.h" #include "BKE_object.h" +#include "BKE_lattice.h" #include "RNA_access.h" #include "RNA_define.h" @@ -1108,7 +1109,7 @@ if (lt->dvert) { MDeformVert *dv; - BPoint *bp; + BPoint *bp, *actbp = BKE_lattice_active_point_get(ob); int a, tot; dv = lt->dvert; @@ -1117,7 +1118,10 @@ for (a = 0, bp = lt->def; a < tot; a++, bp++, dv++) { if (defvert_find_index(dv, def_nr)) { if (select) bp->f1 |= SELECT; - else bp->f1 &= ~SELECT; + else { + bp->f1 &= ~SELECT; + if (actbp && bp == actbp) lt->actbp = LT_ACTBP_NONE; + } } } } Index: source/blender/editors/object/object_lattice.c =================================================================== --- source/blender/editors/object/object_lattice.c (revision 57304) +++ source/blender/editors/object/object_lattice.c (working copy) @@ -154,6 +154,7 @@ lt->typeu = editlt->typeu; lt->typev = editlt->typev; lt->typew = editlt->typew; + lt->actbp = editlt->actbp; } if (lt->dvert) { @@ -180,7 +181,8 @@ bp = lt->editlatt->latt->def; a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; - + lt->editlatt->latt->actbp = LT_ACTBP_NONE; + while (a--) { if (bp->hide == 0) { bp->f1 = flag; @@ -224,6 +226,7 @@ case SEL_INVERT: bp = lt->editlatt->latt->def; a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; + lt->editlatt->latt->actbp = LT_ACTBP_NONE; while (a--) { if (bp->hide == 0) { @@ -642,8 +645,10 @@ { ViewContext vc; BPoint *bp = NULL; + Lattice *lt; view3d_set_viewcontext(C, &vc); + lt = ((Lattice *)vc.obedit->data)->editlatt->latt; bp = findnearestLattvert(&vc, mval, TRUE); if (bp) { @@ -661,6 +666,13 @@ bp->f1 |= SELECT; } + if (bp->f1 == SELECT) { + lt->actbp = bp - lt->def; + } + else { + lt->actbp = LT_ACTBP_NONE; + } + WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data); return true; @@ -673,7 +685,7 @@ typedef struct UndoLattice { BPoint *def; - int pntsu, pntsv, pntsw; + int pntsu, pntsv, pntsw, actbp; } UndoLattice; static void undoLatt_to_editLatt(void *data, void *edata, void *UNUSED(obdata)) @@ -683,6 +695,7 @@ int a = editlatt->latt->pntsu * editlatt->latt->pntsv * editlatt->latt->pntsw; memcpy(editlatt->latt->def, ult->def, a * sizeof(BPoint)); + editlatt->latt->actbp = ult->actbp; } static void *editLatt_to_undoLatt(void *edata, void *UNUSED(obdata)) @@ -694,6 +707,7 @@ ult->pntsu = editlatt->latt->pntsu; ult->pntsv = editlatt->latt->pntsv; ult->pntsw = editlatt->latt->pntsw; + ult->actbp = editlatt->latt->actbp; return ult; } Index: source/blender/editors/transform/transform_generics.c =================================================================== --- source/blender/editors/transform/transform_generics.c (revision 57304) +++ source/blender/editors/transform/transform_generics.c (working copy) @@ -1641,6 +1641,15 @@ break; } } + else if (t->obedit && t->obedit->type == OB_LATTICE) { + BPoint *actbp = BKE_lattice_active_point_get(t->obedit); + + if (actbp) { + copy_v3_v3(t->center, actbp->vec); + calculateCenter2D(t); + break; + } + } } /* END EDIT MODE ACTIVE ELEMENT */ calculateCenterMedian(t); Index: source/blender/editors/transform/transform_conversions.c =================================================================== --- source/blender/editors/transform/transform_conversions.c (revision 57304) +++ source/blender/editors/transform/transform_conversions.c (working copy) @@ -91,6 +91,7 @@ #include "BKE_editmesh.h" #include "BKE_tracking.h" #include "BKE_mask.h" +#include "BKE_lattice.h" #include "BIK_api.h" @@ -1554,7 +1555,7 @@ { Lattice *latt = ((Lattice *)t->obedit->data)->editlatt->latt; TransData *td = NULL; - BPoint *bp; + BPoint *bp, *actbp = BKE_lattice_active_point_get(t->obedit); float mtx[3][3], smtx[3][3]; int a; int count = 0, countsel = 0; @@ -1589,7 +1590,10 @@ copy_v3_v3(td->iloc, bp->vec); td->loc = bp->vec; copy_v3_v3(td->center, td->loc); - if (bp->f1 & SELECT) td->flag = TD_SELECTED; + if (bp->f1 & SELECT) { + td->flag = TD_SELECTED; + if (actbp && bp == actbp) td->flag |= TD_ACTIVE; + } else td->flag = 0; copy_m3_m3(td->smtx, smtx); copy_m3_m3(td->mtx, mtx); Index: source/blender/editors/transform/transform_manipulator.c =================================================================== --- source/blender/editors/transform/transform_manipulator.c (revision 57304) +++ source/blender/editors/transform/transform_manipulator.c (working copy) @@ -65,6 +65,7 @@ #include "BKE_particle.h" #include "BKE_pointcache.h" #include "BKE_editmesh.h" +#include "BKE_lattice.h" #include "BIF_gl.h" @@ -469,18 +470,23 @@ } } else if (obedit->type == OB_LATTICE) { - BPoint *bp; - Lattice *lt = obedit->data; + BPoint *bp = BKE_lattice_active_point_get(obedit); - bp = lt->editlatt->latt->def; - - a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; - while (a--) { - if (bp->f1 & SELECT) { - calc_tw_center(scene, bp->vec); - totsel++; + if (v3d->around == V3D_ACTIVE && bp) { + calc_tw_center(scene, bp->vec); + totsel++; + } + else { + Lattice *lt = obedit->data; + bp = lt->editlatt->latt->def; + a = lt->editlatt->latt->pntsu * lt->editlatt->latt->pntsv * lt->editlatt->latt->pntsw; + while (a--) { + if (bp->f1 & SELECT) { + calc_tw_center(scene, bp->vec); + totsel++; + } + bp++; } - bp++; } } Index: source/blender/editors/space_view3d/drawobject.c =================================================================== --- source/blender/editors/space_view3d/drawobject.c (revision 57304) +++ source/blender/editors/space_view3d/drawobject.c (working copy) @@ -1847,13 +1847,15 @@ glDisable(GL_BLEND); } -static void lattice_draw_verts(Lattice *lt, DispList *dl, short sel) +static void lattice_draw_verts(Lattice *lt, DispList *dl, BPoint *actbp, short sel) { BPoint *bp = lt->def; float *co = dl ? dl->verts : NULL; int u, v, w; - UI_ThemeColor(sel ? TH_VERTEX_SELECT : TH_VERTEX); + short color = sel ? TH_VERTEX_SELECT : TH_VERTEX; + UI_ThemeColor(color); + glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE)); bglBegin(GL_POINTS); @@ -1865,9 +1867,15 @@ int uxt = (u == 0 || u == lt->pntsu - 1); if (!(lt->flag & LT_OUTSIDE) || uxt || vxt || wxt) { if (bp->hide == 0) { - if ((bp->f1 & SELECT) == sel) { + /* check for active BPoint and ensure selected */ + if (actbp && bp == actbp && bp->f1 == SELECT) { + UI_ThemeColor(TH_LASTSEL_POINT); bglVertex3fv(dl ? co : bp->vec); + UI_ThemeColor(color); } + else if ((bp->f1 & SELECT) == sel) { + bglVertex3fv(dl ? co : bp->vec); + } } } } @@ -1954,10 +1962,12 @@ glShadeModel(GL_FLAT); if (is_edit) { + BPoint *actbp = BKE_lattice_active_point_get(ob); + if (v3d->zbuf) glDisable(GL_DEPTH_TEST); - lattice_draw_verts(lt, dl, 0); - lattice_draw_verts(lt, dl, 1); + lattice_draw_verts(lt, dl, actbp, 0); + lattice_draw_verts(lt, dl, actbp, 1); if (v3d->zbuf) glEnable(GL_DEPTH_TEST); } Index: source/blender/editors/space_view3d/view3d_snap.c =================================================================== --- source/blender/editors/space_view3d/view3d_snap.c (revision 57304) +++ source/blender/editors/space_view3d/view3d_snap.c (working copy) @@ -1015,6 +1015,14 @@ mul_m4_v3(obedit->obmat, curs); } + else if (obedit->type == OB_LATTICE) { + BPoint *actbp = BKE_lattice_active_point_get(obedit); + + if (actbp) { + copy_v3_v3(curs, actbp->vec); + mul_m4_v3(obedit->obmat, curs); + } + } } else { if (obact) { Index: source/blender/blenkernel/BKE_lattice.h =================================================================== --- source/blender/blenkernel/BKE_lattice.h (revision 57304) +++ source/blender/blenkernel/BKE_lattice.h (working copy) @@ -75,6 +75,7 @@ void BKE_lattice_modifiers_calc(struct Scene *scene, struct Object *ob); struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *lattice); +struct BPoint *BKE_lattice_active_point_get(struct Object *lattice); void BKE_lattice_minmax(struct Lattice *lt, float min[3], float max[3]); void BKE_lattice_center_median(struct Lattice *lt, float cent[3]); Index: source/blender/blenkernel/intern/lattice.c =================================================================== --- source/blender/blenkernel/intern/lattice.c (revision 57304) +++ source/blender/blenkernel/intern/lattice.c (working copy) @@ -168,6 +168,7 @@ lt->pntsv = vNew; lt->pntsw = wNew; + lt->actbp = LT_ACTBP_NONE; MEM_freeN(lt->def); lt->def = MEM_callocN(lt->pntsu * lt->pntsv * lt->pntsw * sizeof(BPoint), "lattice bp"); @@ -192,6 +193,7 @@ lt->def = MEM_callocN(sizeof(BPoint), "lattvert"); /* temporary */ BKE_lattice_resize(lt, 2, 2, 2, NULL); /* creates a uniform lattice */ + lt->actbp = LT_ACTBP_NONE; return lt; } @@ -1012,6 +1014,16 @@ return lt->dvert; } +struct BPoint *BKE_lattice_active_point_get(struct Object *oblatt) +{ + Lattice *lt = (Lattice *)oblatt->data; + BLI_assert(oblatt->type == OB_LATTICE); + if (lt->editlatt) lt = lt->editlatt->latt; + if (lt->actbp > LT_ACTBP_NONE) return <->def[lt->actbp]; + + return NULL; +} + void BKE_lattice_center_median(struct Lattice *lt, float cent[3]) { int i, numVerts;