diff options
Diffstat (limited to 'source/blender/blenkernel')
-rw-r--r-- | source/blender/blenkernel/BKE_lattice.h | 5 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 63 |
2 files changed, 68 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); + } + } + } +} + |