diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c index e4d7181c66b..fcb03fcc6db 100644 --- a/source/blender/blenkernel/intern/key.c +++ b/source/blender/blenkernel/intern/key.c @@ -63,6 +63,8 @@ #include "BLI_blenlib.h" +#include "blendef.h" + #ifdef HAVE_CONFIG_H #include #endif @@ -1302,6 +1304,11 @@ int do_ob_key(Object *ob) if(key==NULL) return 0; + + /* Don't apply key for sculptmode */ + if(key==NULL || ((G.f & G_SCULPTMODE) && !G.obedit && ob==OBACT)) + return 0; + if(ob->shapeflag & (OB_SHAPE_LOCK|OB_SHAPE_TEMPLOCK)) { KeyBlock *kb= BLI_findlink(&key->block, ob->shapenr-1); diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c index 8c65a3b5baa..79e20cdb9a6 100644 --- a/source/blender/blenloader/intern/readfile.c +++ b/source/blender/blenloader/intern/readfile.c @@ -3134,6 +3134,7 @@ static void direct_link_scene(FileData *fd, Scene *sce) sce->toolsettings= newdataadr(fd, sce->toolsettings); + sce->sculptdata.session= NULL; /* SculptData textures */ for(a=0; asculptdata.mtex[a]= newdataadr(fd,sce->sculptdata.mtex[a]); diff --git a/source/blender/include/BDR_sculptmode.h b/source/blender/include/BDR_sculptmode.h index 94c3af95203..ebc9a7018f0 100644 --- a/source/blender/include/BDR_sculptmode.h +++ b/source/blender/include/BDR_sculptmode.h @@ -33,7 +33,7 @@ struct uiBlock; struct BrushData; struct IndexNode; -struct Key; +struct KeyBlock; struct Mesh; struct Object; struct PartialVisibility; @@ -59,6 +59,8 @@ typedef struct PropsetData { } PropsetData; typedef struct SculptSession { + struct Object *active_ob; + /* Cache of the OpenGL matrices */ double modelviewmat[16]; double projectionmat[16]; @@ -82,7 +84,7 @@ typedef struct SculptSession { /* For rotating around a pivot point */ vec3f pivot; - struct Key *key; + struct KeyBlock *keyblock; } SculptSession; SculptSession *sculpt_session(); diff --git a/source/blender/src/buttons_editing.c b/source/blender/src/buttons_editing.c index aa31056571b..abc09ec701f 100644 --- a/source/blender/src/buttons_editing.c +++ b/source/blender/src/buttons_editing.c @@ -600,9 +600,11 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an case B_ADDKEY: insert_shapekey(ob); + set_sculpt_object(ob); break; case B_SETKEY: ob->shapeflag |= OB_SHAPE_TEMPLOCK; + set_sculpt_object(ob); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWIPO, 0); @@ -610,6 +612,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an break; case B_LOCKKEY: ob->shapeflag &= ~OB_SHAPE_TEMPLOCK; + set_sculpt_object(ob); DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); allqueue(REDRAWVIEW3D, 0); allqueue(REDRAWIPO, 0); @@ -621,6 +624,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an if(ob->shapenr == BLI_countlist(&key->block)) ob->shapenr= 1; else ob->shapenr++; + set_sculpt_object(ob); do_common_editbuts(B_SETKEY); break; } @@ -630,6 +634,7 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an if(ob->shapenr <= 1) ob->shapenr= BLI_countlist(&key->block); else ob->shapenr--; + set_sculpt_object(ob); do_common_editbuts(B_SETKEY); break; } @@ -638,7 +643,9 @@ void do_common_editbuts(unsigned short event) // old name, is a mix of object an allqueue (REDRAWIPO, 0); break; case B_DELKEY: + set_sculpt_object(NULL); delete_key(OBACT); + set_sculpt_object(ob); allqueue(REDRAWACTION, 0); break; diff --git a/source/blender/src/sculptmode.c b/source/blender/src/sculptmode.c index 6fa4abace89..3193cfe4c4f 100644 --- a/source/blender/src/sculptmode.c +++ b/source/blender/src/sculptmode.c @@ -194,9 +194,11 @@ void sculptmode_init(Scene *sce) sd->tablet_strength=10; } +void sculptmode_undo_init(); void sculpt_init_session() { sculpt_data()->session= MEM_callocN(sizeof(SculptSession), "SculptSession"); + sculptmode_undo_init(); } /* Free G.sculptdata->vertexusers */ @@ -595,8 +597,31 @@ void calc_vertex_users() void set_sculpt_object(Object *ob) { - if(ob) - calc_vertex_users(); + SculptSession *ss= sculpt_session(); + + if(ss) { + if(ss->keyblock) { + Mesh *me= get_mesh(ss->active_ob); + if(me) { + mesh_to_key(me, ss->keyblock); + DAG_object_flush_update(G.scene, ss->active_ob, OB_RECALC_DATA); + } + } + + if(ob) { + Mesh *me= get_mesh(ob); + calc_vertex_users(); + + /* Load in key */ + ss->keyblock= ob_get_keyblock(ob); + if(ss->keyblock) + key_to_mesh(ss->keyblock, me); + + DAG_object_flush_update(G.scene, ob, OB_RECALC_DATA); + } + + ss->active_ob= ob; + } } /* ===== INTERFACE ===== @@ -1597,8 +1622,8 @@ void sculptmode_draw_mesh(int only_damaged) { void sculptmode_correct_state() { - //if(get_mesh( != get_mesh(OBACT)) - //set_sculpt_object(OBACT); + if(get_mesh(sculpt_session()->active_ob) != get_mesh(OBACT)) + set_sculpt_object(OBACT); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY); @@ -1823,8 +1848,6 @@ void set_sculptmode() set_sculpt_object(NULL); sculptmode_free_session(G.scene); - - DAG_object_flush_update(G.scene, OBACT, OB_RECALC_DATA); } else { G.f |= G_SCULPTMODE; @@ -1835,8 +1858,6 @@ void set_sculptmode() sculpt_init_session(); set_sculpt_object(OBACT); - - sculptmode_undo_init(); glEnableClientState(GL_VERTEX_ARRAY); glEnableClientState(GL_NORMAL_ARRAY);