Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2009-10-16 17:04:59 +0400
committerCampbell Barton <ideasman42@gmail.com>2009-10-16 17:04:59 +0400
commit299adde803de5f0bb6f5fd7cc95ea9e61219aea2 (patch)
tree4fa1d895537fc4516600d0c1c228a322e1cc58ed /source/blender/editors/object/object_shapekey.c
parentf6494ff3cf132e326cd18b4ec74b9d9ee61406fa (diff)
shape key mirror tool, access from shapekey list buttons
Diffstat (limited to 'source/blender/editors/object/object_shapekey.c')
-rw-r--r--source/blender/editors/object/object_shapekey.c88
1 files changed, 86 insertions, 2 deletions
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index b7db3a20ed1..442b86abd98 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -70,6 +70,7 @@
#include "BLO_sys_types.h" // for intptr_t support
#include "ED_object.h"
+#include "ED_mesh.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -401,7 +402,7 @@ void insert_curvekey(Scene *scene, Curve *cu, short rel)
/*********************** add shape key ***********************/
-void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob)
+static void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob)
{
Key *key;
@@ -417,7 +418,7 @@ void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob)
/*********************** remove shape key ***********************/
-int ED_object_shape_key_remove(bContext *C, Object *ob)
+static int ED_object_shape_key_remove(bContext *C, Object *ob)
{
Main *bmain= CTX_data_main(C);
KeyBlock *kb, *rkb;
@@ -480,6 +481,63 @@ int ED_object_shape_key_remove(bContext *C, Object *ob)
return 1;
}
+static int ED_object_shape_key_mirror(bContext *C, Scene *scene, Object *ob)
+{
+ KeyBlock *kb;
+ Key *key;
+
+ key= ob_get_key(ob);
+ if(key==NULL)
+ return 0;
+
+ kb= BLI_findlink(&key->block, ob->shapenr-1);
+
+ if(kb) {
+ int i1, i2;
+ float *fp1, *fp2;
+ float tvec[3];
+ char *tag_elem= MEM_callocN(sizeof(char) * kb->totelem, "shape_key_mirror");
+
+
+ if(ob->type==OB_MESH) {
+ Mesh *me= ob->data;
+ MVert *mv;
+
+ mesh_octree_table(ob, NULL, NULL, 's');
+
+ for(i1=0, mv=me->mvert; i1<me->totvert; i1++, mv++) {
+ i2= mesh_get_x_mirror_vert(ob, i1);
+ if(i2 != -1) {
+ if(tag_elem[i1]==0 && tag_elem[i2]==0) {
+ fp1= ((float *)kb->data) + i1*3;
+ fp2= ((float *)kb->data) + i2*3;
+
+ VECCOPY(tvec, fp1);
+ VECCOPY(fp1, fp2);
+ VECCOPY(fp2, tvec);
+
+ /* flip x axis */
+ fp1[0] = -fp1[0];
+ fp2[0] = -fp2[0];
+ }
+ tag_elem[i1]= tag_elem[i2]= 1;
+ }
+
+ }
+
+ mesh_octree_table(ob, NULL, NULL, 'e');
+ }
+ /* todo, other types? */
+
+ MEM_freeN(tag_elem);
+ }
+
+ DAG_id_flush_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
+
+ return 1;
+}
+
/********************** shape key operators *********************/
static int shape_key_poll(bContext *C)
@@ -572,3 +630,29 @@ void OBJECT_OT_shape_key_clear(wmOperatorType *ot)
ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
}
+
+static int shape_key_mirror_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene= CTX_data_scene(C);
+ Object *ob= CTX_data_pointer_get_type(C, "object", &RNA_Object).data;
+
+ if(!ED_object_shape_key_mirror(C, scene, ob))
+ return OPERATOR_CANCELLED;
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_shape_key_mirror(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name= "Mirror Shape Key";
+ ot->idname= "OBJECT_OT_shape_key_mirror";
+
+ /* api callbacks */
+ ot->poll= shape_key_poll;
+ ot->exec= shape_key_mirror_exec;
+
+ /* flags */
+ ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+}
+