diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-01 19:17:39 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-02-01 19:17:39 +0400 |
commit | 496c3e4f8fc8c1e9319477f3f2f75f6474bb4b5f (patch) | |
tree | ad72e0a9840a8535ccfae20f17b3e7ced65e5b50 /source | |
parent | 2a71e4e4f0c703a613b74fb1d0710b341987e6e3 (diff) |
Fix #34070: set origin operator did not work for lattice objects.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_lattice.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 63 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 14 |
3 files changed, 82 insertions, 0 deletions
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index a0bebd752b5..fe88f0c580a 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -75,5 +75,10 @@ void BKE_lattice_modifiers_calc(struct Scene *scene, struct Object *ob); struct MDeformVert *BKE_lattice_deform_verts_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]); +void BKE_lattice_center_bounds(struct Lattice *lt, float cent[3]); +void BKE_lattice_translate(struct Lattice *lt, float offset[3], int do_keys); + #endif diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index fa01e9fd933..05d7933e1b5 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -1003,3 +1003,66 @@ struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *oblatt) if (lt->editlatt) lt = lt->editlatt->latt; return lt->dvert; } + +void BKE_lattice_center_median(struct Lattice *lt, float cent[3]) +{ + int i, numVerts; + + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + zero_v3(cent); + + for (i = 0; i < numVerts; i++) + add_v3_v3(cent, lt->def[i].vec); + + mul_v3_fl(cent, 1.0f / (float)numVerts); +} + +void BKE_lattice_minmax(struct Lattice *lt, float min[3], float max[3]) +{ + int i, numVerts; + + if (lt->editlatt) lt = lt->editlatt->latt; + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + for (i = 0; i < numVerts; i++) + minmax_v3v3_v3(min, max, lt->def[i].vec); +} + +void BKE_lattice_center_bounds(struct Lattice *lt, float cent[3]) +{ + float min[3], max[3]; + + INIT_MINMAX(min, max); + + BKE_lattice_minmax(lt, min, max); + mid_v3_v3v3(cent, min, max); +} + +void BKE_lattice_translate(Lattice *lt, float offset[3], int do_keys) +{ + int i, numVerts; + + numVerts = lt->pntsu * lt->pntsv * lt->pntsw; + + if (lt->def) + for (i = 0; i < numVerts; i++) + add_v3_v3(lt->def[i].vec, offset); + + if (lt->editlatt) + for (i = 0; i < numVerts; i++) + add_v3_v3(lt->editlatt->latt->def[i].vec, offset); + + if (do_keys && lt->key) { + KeyBlock *kb; + + for (kb = lt->key->block.first; kb; kb = kb->next) { + float *fp = kb->data; + for (i = kb->totelem; i--; fp += 3) { + add_v3_v3(fp, offset); + } + } + } +} + diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 7a2eb5667a2..d933a6de166 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -899,6 +899,20 @@ static int object_origin_set_exec(bContext *C, wmOperator *op) break; } } + else if (ob->type == OB_LATTICE) { + Lattice *lt = ob->data; + + if (centermode == ORIGIN_TO_CURSOR) { /* done */ } + else if (around == V3D_CENTROID) { BKE_lattice_center_median(lt, cent); } + else { BKE_lattice_center_bounds(lt, cent); } + + negate_v3_v3(cent_neg, cent); + BKE_lattice_translate(lt, cent_neg, 1); + + tot_change++; + lt->id.flag |= LIB_DOIT; + do_inverse_offset = TRUE; + } /* offset other selected objects */ if (do_inverse_offset && (centermode != GEOMETRY_TO_ORIGIN)) { |