diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-06-24 17:45:35 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-06-24 17:45:35 +0400 |
commit | 1a55b53375cf45481e3916d9d3a96c7ce4204e73 (patch) | |
tree | e087353ec83945db6a9ee807745b4390a0b0d8ca /source | |
parent | c42c9cb234524fcde6248df686d359c2fa827fcd (diff) |
lattice: use functions rather then defines, also added a function to get uvw from an index.
- BKE_lattice_index_from_uvw()
- BKE_lattice_index_to_uvw()
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/blenkernel/BKE_lattice.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/lattice.c | 15 | ||||
-rw-r--r-- | source/blender/editors/object/object_shapekey.c | 7 | ||||
-rw-r--r-- | source/blender/editors/object/object_vgroup.c | 4 | ||||
-rw-r--r-- | source/blender/makesdna/DNA_lattice_types.h | 2 | ||||
-rw-r--r-- | source/blender/makesrna/intern/rna_lattice.c | 16 |
6 files changed, 31 insertions, 16 deletions
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h index b0bf9513814..9b29412675b 100644 --- a/source/blender/blenkernel/BKE_lattice.h +++ b/source/blender/blenkernel/BKE_lattice.h @@ -82,5 +82,8 @@ 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); +int BKE_lattice_index_from_uvw(struct Lattice *lt, const int u, const int v, const int w); +void BKE_lattice_index_to_uvw(struct Lattice *lt, const int index, int *r_u, int *r_v, int *r_w); + #endif diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c index feb82a34708..23368446675 100644 --- a/source/blender/blenkernel/intern/lattice.c +++ b/source/blender/blenkernel/intern/lattice.c @@ -62,6 +62,19 @@ #include "BKE_deform.h" +int BKE_lattice_index_from_uvw(struct Lattice *lt, + const int u, const int v, const int w) +{ + return (w * (lt->pntsu * lt->pntsv) + (v * lt->pntsu) + u); +} + +void BKE_lattice_index_to_uvw(struct Lattice *lt, const int index, + int *r_u, int *r_v, int *r_w) +{ + *r_u = (index % lt->pntsu); + *r_v = (index / lt->pntsu) % lt->pntsv; + *r_w = (index / (lt->pntsu * lt->pntsv)); +} void calc_lat_fudu(int flag, int res, float *r_fu, float *r_du) { @@ -867,7 +880,7 @@ int object_deform_mball(Object *ob, ListBase *dispbase) static BPoint *latt_bp(Lattice *lt, int u, int v, int w) { - return <->def[LT_INDEX(lt, u, v, w)]; + return <->def[BKE_lattice_index_from_uvw(lt, u, v, w)]; } void outside_lattice(Lattice *lt) diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c index f9704343fdd..8fead6024fb 100644 --- a/source/blender/editors/object/object_shapekey.c +++ b/source/blender/editors/object/object_shapekey.c @@ -57,6 +57,7 @@ #include "BKE_library.h" #include "BKE_main.h" #include "BKE_object.h" +#include "BKE_lattice.h" #include "BKE_curve.h" #include "BLI_sys_types.h" // for intptr_t support @@ -244,14 +245,14 @@ static bool object_shape_key_mirror(bContext *C, Object *ob, int u_inv = (lt->pntsu - 1) - u; float tvec[3]; if (u == u_inv) { - i1 = LT_INDEX(lt, u, v, w); + i1 = BKE_lattice_index_from_uvw(lt, u, v, w); fp1 = ((float *)kb->data) + i1 * 3; fp1[0] = -fp1[0]; totmirr++; } else { - i1 = LT_INDEX(lt, u, v, w); - i2 = LT_INDEX(lt, u_inv, v, w); + i1 = BKE_lattice_index_from_uvw(lt, u, v, w); + i2 = BKE_lattice_index_from_uvw(lt, u_inv, v, w); fp1 = ((float *)kb->data) + i1 * 3; fp2 = ((float *)kb->data) + i2 * 3; diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c index 2f163a358bc..c5efa91d105 100644 --- a/source/blender/editors/object/object_vgroup.c +++ b/source/blender/editors/object/object_vgroup.c @@ -2477,8 +2477,8 @@ void ED_vgroup_mirror(Object *ob, if (u != u_inv) { BPoint *bp, *bp_mirr; - i1 = LT_INDEX(lt, u, v, w); - i2 = LT_INDEX(lt, u_inv, v, w); + i1 = BKE_lattice_index_from_uvw(lt, u, v, w); + i2 = BKE_lattice_index_from_uvw(lt, u_inv, v, w); bp = <->def[i1]; bp_mirr = <->def[i2]; diff --git a/source/blender/makesdna/DNA_lattice_types.h b/source/blender/makesdna/DNA_lattice_types.h index 500b4ab88c3..837f0c354e6 100644 --- a/source/blender/makesdna/DNA_lattice_types.h +++ b/source/blender/makesdna/DNA_lattice_types.h @@ -83,8 +83,6 @@ typedef struct Lattice { #define LT_DS_EXPAND 4 -#define LT_INDEX(lt, u, v, w) ((w) * ((lt)->pntsu * (lt)->pntsv) + ((v) * (lt)->pntsu) + (u)) - #define LT_ACTBP_NONE -1 #endif diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c index b2790a25e47..0cd5fec57df 100644 --- a/source/blender/makesrna/intern/rna_lattice.c +++ b/source/blender/makesrna/intern/rna_lattice.c @@ -54,14 +54,14 @@ static void rna_LatticePoint_co_get(PointerRNA *ptr, float *values) { Lattice *lt = (Lattice *)ptr->id.data; BPoint *bp = (BPoint *)ptr->data; - int a = bp - lt->def; - int x = a % lt->pntsu; - int y = (a / lt->pntsu) % lt->pntsv; - int z = (a / (lt->pntsu * lt->pntsv)); - - values[0] = lt->fu + x * lt->du; - values[1] = lt->fv + y * lt->dv; - values[2] = lt->fw + z * lt->dw; + int index = bp - lt->def; + int u, v, w; + + BKE_lattice_index_to_uvw(lt, index, &u, &v, &w); + + values[0] = lt->fu + u * lt->du; + values[1] = lt->fv + v * lt->dv; + values[2] = lt->fw + w * lt->dw; } static void rna_LatticePoint_groups_begin(CollectionPropertyIterator *iter, PointerRNA *ptr) |