Add back Blend From Shape in mesh edit mode.
authorBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 16 Oct 2009 10:05:58 +0000 (10:05 +0000)
committerBrecht Van Lommel <brechtvanlommel@pandora.be>
Fri, 16 Oct 2009 10:05:58 +0000 (10:05 +0000)
release/scripts/ui/space_view3d.py
source/blender/blenlib/BLI_arithb.h
source/blender/editors/mesh/editmesh_tools.c
source/blender/editors/mesh/mesh_intern.h
source/blender/editors/mesh/mesh_ops.c

index 3a596766c89a9a5ddccd9f2fdd758a27ec7b0625..2382e8660912afe6837987e610fcf242e85d980d 100644 (file)
@@ -794,18 +794,18 @@ class VIEW3D_MT_edit_mesh_specials(bpy.types.Menu):
                layout.itemO("mesh.subdivide", text="Subdivide")
                layout.item_floatO("mesh.subdivide", "smoothness", 1.0, text="Subdivide Smooth")
                layout.itemO("mesh.merge", text="Merge...")
-               layout.itemO("mesh.remove_doubles", text="Remove Doubles")
+               layout.itemO("mesh.remove_doubles")
                layout.itemO("mesh.hide", text="Hide")
                layout.itemO("mesh.reveal", text="Reveal")
-               layout.itemO("mesh.select_inverse", text="Select Inverse")
+               layout.itemO("mesh.select_inverse")
                layout.itemO("mesh.flip_normals")
                layout.itemO("mesh.vertices_smooth", text="Smooth")
                # layout.itemO("mesh.bevel", text="Bevel")
                layout.itemO("mesh.faces_shade_smooth")
                layout.itemO("mesh.faces_shade_flat")
-               # layout.itemO("mesh.blend_from_shape", text="Blend From Shape")
-               # layout.itemO("mesh.shape_propagate_to_all", text="Propagate to All Shapes")
-               layout.itemO("mesh.select_vertex_path", text="Select Vertex Path")
+               layout.itemO("mesh.blend_from_shape")
+               # layout.itemO("mesh.shape_propagate_to_all")
+               layout.itemO("mesh.select_vertex_path")
 
 class VIEW3D_MT_edit_mesh_vertices(bpy.types.Menu):
        __label__ = "Vertices"
@@ -824,9 +824,9 @@ class VIEW3D_MT_edit_mesh_vertices(bpy.types.Menu):
                layout.itemO("mesh.vertices_smooth")
                layout.itemO("mesh.remove_doubles")
                
-               layout.itemO("mesh.select_vertex_path", text="Select Vertex Path")
+               layout.itemO("mesh.select_vertex_path")
                
-               # uiItemO(layout, "Blend From Shape", 0, "mesh.blend_from_shape");
+               layout.itemO("mesh.blend_from_shape")
                # uiItemO(layout, "Propagate to All Shapes", 0, "mesh.shape_propagate_to_all");
 
 class VIEW3D_MT_edit_mesh_edges(bpy.types.Menu):
index e6aded12f3b2ed294aa692a6e354edd49532dfb0..fdccb3854a609f666c820b23a2964f46e60e547e 100644 (file)
@@ -457,6 +457,7 @@ void i_window(
 #define BLI_CS_CIE             2
 
 #define RAD2DEG(_rad) ((_rad)*(180.0/M_PI))
+#define DEG2RAD(_deg) ((_deg)*(M_PI/180.0))
 
 void hsv_to_rgb(float h, float s, float v, float *r, float *g, float *b);
 void hex_to_rgb(char *hexcol, float *r, float *g, float *b);
index d447040e8eae7a1978aebbad40b7584fa9ec4b0f..30fda95cf9bb30474632e1900b84da32786bb3e7 100644 (file)
@@ -69,6 +69,7 @@ editmesh_tool.c: UI called tools for editmesh, geometry changes here, otherwise
 #include "BKE_customdata.h"
 #include "BKE_depsgraph.h"
 #include "BKE_global.h"
+#include "BKE_key.h"
 #include "BKE_library.h"
 #include "BKE_mesh.h"
 #include "BKE_object.h"
@@ -5024,6 +5025,7 @@ void MESH_OT_rip(wmOperatorType *ot)
 
 /************************ Shape Operators *************************/
 
+#if 0
 void shape_propagate(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op)
 {
        EditVert *ev = NULL;
@@ -5065,152 +5067,110 @@ void shape_propagate(Scene *scene, Object *obedit, EditMesh *em, wmOperator *op)
        DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
        return;
 }
+#endif
 
-void shape_copy_from_lerp(EditMesh *em, KeyBlock* thisBlock, KeyBlock* fromBlock)
+static int blend_from_shape_exec(bContext *C, wmOperator *op)
 {
-       EditVert *ev = NULL;
-       short mval[2], curval[2], event = 0, finished = 0, canceled = 0, fullcopy=0 ;
-       float perc = 0;
-       char str[64];
-       float *data, *odata;
-
-       data  = fromBlock->data;
-       odata = thisBlock->data;
-
-// XXX getmouseco_areawin(mval);
-       curval[0] = mval[0] + 1; curval[1] = mval[1] + 1;
-
-       while (finished == 0)
-       {
-// XXX         getmouseco_areawin(mval);
-               if (mval[0] != curval[0] || mval[1] != curval[1])
-               {
-
-                       if(mval[0] > curval[0])
-                               perc += 0.1;
-                       else if(mval[0] < curval[0])
-                               perc -= 0.1;
-
-                       if(perc < 0) perc = 0;
-                       if(perc > 1) perc = 1;
-
-                       curval[0] = mval[0];
-                       curval[1] = mval[1];
+       Object *obedit= CTX_data_edit_object(C);
+       Mesh *me= obedit->data;
+       Key *key= me->key;
+       EditMesh *em= BKE_mesh_get_editmesh(me);
+       EditVert *eve;
+       KeyBlock *kb;
+       float *data, co[3];
+       float blend= RNA_float_get(op->ptr, "blend");
+       int shape= RNA_enum_get(op->ptr, "shape");
+       int add= RNA_int_get(op->ptr, "add");
+       int blended= 0;
 
-                       if(fullcopy == 1){
-                               perc = 1;
-                       }
+       kb= BLI_findlink(&key->block, shape);
 
-                       for(ev = em->verts.first; ev ; ev = ev->next){
-                               if(ev->f & SELECT){
-                                       VecLerpf(ev->co,odata+(ev->keyindex*3),data+(ev->keyindex*3),perc);
-                               }
-                       }
-                       sprintf(str,"Blending at %d%c  MMB to Copy at 100%c",(int)(perc*100),'%','%');
-//                     DAG_id_flush_update(obedit->data, OB_RECALC_DATA);
-//                     headerprint(str);
-//                     force_draw(0);
+       if(kb) {
+               data= kb->data;
 
-                       if(fullcopy == 1){
-                               break;
-                       }
+               for(eve=em->verts.first; eve; eve=eve->next){
+                       if(eve->f & SELECT) {
+                               if(eve->keyindex >= 0 && eve->keyindex < kb->totelem) {
+                                       VECCOPY(co, data + eve->keyindex*3);
 
-               } else {
-                       PIL_sleep_ms(10);
-               }
+                                       if(add) {
+                                               VecMulf(co, blend);
+                                               VecAddf(eve->co, eve->co, co);
+                                       }
+                                       else
+                                               VecLerpf(eve->co, eve->co, co, blend);
 
-               while(qtest()) {
-                       short val=0;
-                       event= extern_qread(&val);
-                       if(val){
-                               if(ELEM3(event, PADENTER, LEFTMOUSE, RETKEY)){
-                                       finished = 1;
-                               }
-                               else if (event == MIDDLEMOUSE){
-                                       fullcopy = 1;
-                               }
-                               else if (ELEM3(event,ESCKEY,RIGHTMOUSE,RIGHTMOUSE)){
-                                       canceled = 1;
-                                       finished = 1;
+                                       blended= 1;
                                }
                        }
                }
        }
-       if(!canceled);
-       else
-               for(ev = em->verts.first; ev ; ev = ev->next){
-                       if(ev->f & SELECT){
-                               VECCOPY(ev->co, odata+(ev->keyindex*3));
-                       }
-               }
-       return;
-}
 
+       BKE_mesh_end_editmesh(me, em);
 
+       if(!blended)
+               return OPERATOR_CANCELLED;
 
-void shape_copy_select_from(Object *obedit, EditMesh *em, wmOperator *op)
-{
-       Mesh* me = (Mesh*)obedit->data;
-       EditVert *ev = NULL;
-       int totverts = 0,curshape = obedit->shapenr;
+       DAG_id_flush_update(&me->id, OB_RECALC_DATA);
+       WM_event_add_notifier(C, NC_GEOM|ND_DATA, me);
 
-       Key*  ky = NULL;
-       KeyBlock *kb = NULL,*thisBlock = NULL;
-       int maxlen=32, nr=0, a=0;
-       char *menu;
-
-       if(me->key){
-               ky = me->key;
-       } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Key");
-               return;
-       }
+       return OPERATOR_FINISHED;
+}
 
-       if(ky->block.first){
-               for(kb=ky->block.first;kb;kb = kb->next){
-                       maxlen += 40; // Size of a block name
-                       if(a == curshape-1){
-                                       thisBlock = kb;
-                       }
+static EnumPropertyItem *shape_itemf(bContext *C, PointerRNA *ptr, int *free)
+{      
+       Object *obedit= CTX_data_edit_object(C);
+       Mesh *me= obedit->data;
+       Key *key;
+       KeyBlock *kb, *actkb;
+       EnumPropertyItem tmp= {0, "", 0, "", ""}, *item= NULL;
+       int totitem= 0, a;
 
-                       a++;
-               }
-               a=0;
-               menu = MEM_callocN(maxlen, "Copy Shape Menu Text");
-               strcpy(menu, "Copy Vert Positions from Shape %t|");
-               for(kb=ky->block.first;kb;kb = kb->next){
-                       if(a != curshape-1){
-                               sprintf(menu,"%s %s %cx%d|",menu,kb->name,'%',a);
+       if(obedit && obedit->type == OB_MESH) {
+               key= me->key;
+               actkb= ob_get_keyblock(obedit);
+
+               if(key && actkb) {
+                       for(kb=key->block.first, a=0; kb; kb=kb->next, a++) {
+                               if(kb != actkb) {
+                                       tmp.value= a;
+                                       tmp.identifier= kb->name;
+                                       tmp.name= kb->name;
+                                       RNA_enum_item_add(&item, &totitem, &tmp);
+                               }
                        }
-                       a++;
                }
-// XXX         nr = pupmenu_col(menu, 20);
-               MEM_freeN(menu);
-       } else {
-               BKE_report(op->reports, RPT_ERROR, "Object Has No Blendshapes");
-               return;
        }
 
-       a = 0;
+       RNA_enum_item_end(&item, &totitem);
+       *free= 1;
+
+       return item;
+}
 
-       for(kb=ky->block.first;kb;kb = kb->next){
-               if(a == nr){
+void MESH_OT_blend_from_shape(wmOperatorType *ot)
+{
+       PropertyRNA *prop;
+       static EnumPropertyItem shape_items[]= {{0, NULL, 0, NULL, NULL}};
 
-                       for(ev = em->verts.first;ev;ev = ev->next){
-                               totverts++;
-                       }
+       /* identifiers */
+       ot->name= "Blend From Shape";
+       ot->description= "Blend in shape from a shape key.";
+       ot->idname= "MESH_OT_blend_from_shape";
 
-                       if(me->totvert != totverts){
-                               BKE_report(op->reports, RPT_ERROR, "Shape Has had Verts Added/Removed, please cycle editmode before copying");
-                               return;
-                       }
-                       shape_copy_from_lerp(em, thisBlock,kb);
+       /* api callbacks */
+       ot->exec= blend_from_shape_exec;
+       ot->invoke= WM_operator_props_popup;
+       ot->poll= ED_operator_editmesh;
 
-                       return;
-               }
-               a++;
-       }
-       return;
+       /* flags */
+       ot->flag= OPTYPE_REGISTER|OPTYPE_UNDO;
+
+       /* properties */
+       prop= RNA_def_enum(ot->srna, "shape", shape_items, 0, "Shape", "Shape key to use for blending.");
+       RNA_def_enum_funcs(prop, shape_itemf);
+       RNA_def_float(ot->srna, "blend", 1.0f, -FLT_MAX, FLT_MAX, "Blend", "Blending factor.", -2.0f, 2.0f);
+       RNA_def_boolean(ot->srna, "add", 1, "Add", "Add rather then blend between shapes.");
 }
 
 /************************ Merge Operator *************************/
index 7ee7fe1ebde7ce207a7f7ebf2f3e1dba063b3dda..8b55afa4a0d924ae14b146e85024a0b622a24510 100644 (file)
@@ -227,6 +227,8 @@ void MESH_OT_colors_mirror(struct wmOperatorType *ot);
 void MESH_OT_delete(struct wmOperatorType *ot);
 void MESH_OT_rip(struct wmOperatorType *ot);
 
+void MESH_OT_blend_from_shape(struct wmOperatorType *ot);
+
 /* ******************* mesh_layers.c */
 
 void MESH_OT_uv_texture_add(struct wmOperatorType *ot);
index c8d85aace47f77ceaff2debae7db90bf51b534fc..df80b74f19f459fa1c06213927cf2904ab27312e 100644 (file)
@@ -139,6 +139,7 @@ void ED_operatortypes_mesh(void)
        WM_operatortype_append(MESH_OT_flip_normals);
        WM_operatortype_append(MESH_OT_knife_cut);
        WM_operatortype_append(MESH_OT_rip);
+       WM_operatortype_append(MESH_OT_blend_from_shape);
        
        WM_operatortype_append(MESH_OT_uv_texture_add);
        WM_operatortype_append(MESH_OT_uv_texture_remove);