diff options
author | Campbell Barton <ideasman42@gmail.com> | 2013-02-11 14:56:21 +0400 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2013-02-11 14:56:21 +0400 |
commit | 3a192ca3591d0ed5a6356f791c86cbd2a3d0209a (patch) | |
tree | a3fa776da8d43d4d058984b9f863b72a880f384f /source/blender/editors | |
parent | c1ca09b8c80a4fc063f7b804f68cd5c86db9f517 (diff) |
patch [#33697] Apply transformation added to metaballs.
from Jesse Werner (vidjogamer), with own addition of RNA function, scale and rotation support.
Diffstat (limited to 'source/blender/editors')
-rw-r--r-- | source/blender/editors/include/ED_mball.h | 4 | ||||
-rw-r--r-- | source/blender/editors/metaball/mball_edit.c | 24 | ||||
-rw-r--r-- | source/blender/editors/object/object_transform.c | 11 |
3 files changed, 38 insertions, 1 deletions
diff --git a/source/blender/editors/include/ED_mball.h b/source/blender/editors/include/ED_mball.h index 1321765588d..4655188a3dd 100644 --- a/source/blender/editors/include/ED_mball.h +++ b/source/blender/editors/include/ED_mball.h @@ -32,6 +32,7 @@ #define __ED_MBALL_H__ struct bContext; +struct MetaBall; struct Object; struct wmKeyConfig; @@ -48,5 +49,6 @@ void load_editMball(struct Object *obedit); void undo_push_mball(struct bContext *C, const char *name); -#endif +void ED_mball_transform(struct MetaBall *mb, float *mat); +#endif /* __ED_MBALL_H__ */ diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c index 8633a7a9b38..477a6dd815e 100644 --- a/source/blender/editors/metaball/mball_edit.c +++ b/source/blender/editors/metaball/mball_edit.c @@ -586,3 +586,27 @@ void undo_push_mball(bContext *C, const char *name) undo_editmode_push(C, name, get_data, free_undoMball, undoMball_to_editMball, editMball_to_undoMball, NULL); } +/* matrix is 4x4 */ +void ED_mball_transform(MetaBall *mb, float *mat) +{ + MetaElem *me; + float quat[4]; + const float scale = mat4_to_scale((float (*)[4])mat); + const float scale_sqrt = sqrtf(scale); + + mat4_to_quat(quat, (float (*)[4])mat); + + for (me = mb->elems.first; me; me = me->next) { + mul_m4_v3((float (*)[4])mat, &me->x); + mul_qt_qtqt(me->quat, quat, me->quat); + me->rad *= scale; + /* hrmf, probably elems shouldn't be + * treating scale differently - campbell */ + if (ELEM3(me->type, MB_CUBE, MB_PLANE, MB_TUBE)) { + mul_v3_fl(&me->expx, scale); + } + else { + mul_v3_fl(&me->expx, scale_sqrt); + } + } +} diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c index 68075e7b6f9..9dd34623739 100644 --- a/source/blender/editors/object/object_transform.c +++ b/source/blender/editors/object/object_transform.c @@ -67,6 +67,7 @@ #include "ED_armature.h" #include "ED_keyframing.h" +#include "ED_mball.h" #include "ED_mesh.h" #include "ED_screen.h" #include "ED_view3d.h" @@ -407,6 +408,12 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo change = 0; } } + else if (ob->type == OB_MBALL) { + if (ID_REAL_USERS(ob->data) > 1) { + BKE_report(reports, RPT_ERROR, "Cannot apply to a multi user metaball, doing nothing"); + change = 0; + } + } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu; @@ -516,6 +523,10 @@ static int apply_objects_internal(bContext *C, ReportList *reports, int apply_lo bp++; } } + else if (ob->type == OB_MBALL) { + MetaBall *mb = ob->data; + ED_mball_transform(mb, (float *)mat); + } else if (ELEM(ob->type, OB_CURVE, OB_SURF)) { Curve *cu = ob->data; |