- object.add_shape_key(name="Key", from_mix=True)

- ensure new shape key names are unique
- Transfer ShapeKey now can have its settings changes (redo operator)
This commit is contained in:
2009-12-28 18:03:04 +00:00
parent 32656ad4ba
commit 8177f343a0
9 changed files with 62 additions and 31 deletions

View File

@@ -170,7 +170,6 @@ class ShapeTransfer(bpy.types.Operator):
default=False)
def _main(self, ob_act, objects, mode='OFFSET', use_clamp=False):
def me_nos(verts):
return [v.normal.copy() for v in verts]
@@ -178,11 +177,10 @@ class ShapeTransfer(bpy.types.Operator):
return [v.co.copy() for v in verts]
def ob_add_shape(ob):
C_tmp = {"object": ob}
me = ob.data
if me.shape_keys is None: # add basis
bpy.ops.object.shape_key_add(C_tmp)
bpy.ops.object.shape_key_add(C_tmp)
ob.add_shape_key(from_mix=False)
if len(me.shape_keys.keys) == 1:
ob.add_shape_key(from_mix=False) # we need a rest
ob.active_shape_key_index = len(me.shape_keys.keys) - 1
ob.shape_key_lock = True

View File

@@ -59,7 +59,7 @@ void key_curve_normal_weights(float t, float *data, int type);
float *do_ob_key(struct Scene *scene, struct Object *ob);
struct Key *ob_get_key(struct Object *ob);
struct KeyBlock *add_keyblock(struct Key *key);
struct KeyBlock *add_keyblock(struct Key *key, char *name);
struct KeyBlock *ob_get_keyblock(struct Object *ob);
struct KeyBlock *ob_get_reference_keyblock(struct Object *ob);
struct KeyBlock *key_get_keyblock(struct Key *key, int index);

View File

@@ -120,7 +120,7 @@ int give_obdata_texspace(struct Object *ob, short **texflag, float **loc, float
int object_insert_ptcache(struct Object *ob);
// void object_delete_ptcache(struct Object *ob, int index);
int object_insert_shape_key(struct Scene *scene, struct Object *ob, int from_mix);
struct KeyBlock *object_insert_shape_key(struct Scene *scene, struct Object *ob, char *name, int from_mix);
#ifdef __cplusplus

View File

@@ -32,6 +32,7 @@
#include <math.h>
#include <string.h>
#include <stddef.h>
#include "MEM_guardedalloc.h"
@@ -1395,7 +1396,7 @@ Key *ob_get_key(Object *ob)
return NULL;
}
KeyBlock *add_keyblock(Key *key)
KeyBlock *add_keyblock(Key *key, char *name)
{
KeyBlock *kb;
float curpos= -0.1;
@@ -1409,9 +1410,15 @@ KeyBlock *add_keyblock(Key *key)
kb->type= KEY_CARDINAL;
tot= BLI_countlist(&key->block);
if(tot==1) strcpy(kb->name, "Basis");
else sprintf(kb->name, "Key %d", tot-1);
if(name) {
strncpy(kb->name, name, sizeof(kb->name));
} else {
if(tot==1) strcpy(kb->name, "Basis");
else sprintf(kb->name, "Key %d", tot-1);
}
BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), sizeof(kb->name));
// XXX this is old anim system stuff? (i.e. the 'index' of the shapekey)
kb->adrcode= tot-1;

View File

@@ -2634,7 +2634,7 @@ void object_delete_ptcache(Object *ob, int index)
/* shape key utility function */
/************************* Mesh ************************/
static void insert_meshkey(Scene *scene, Object *ob, int from_mix)
static KeyBlock *insert_meshkey(Scene *scene, Object *ob, char *name, int from_mix)
{
Mesh *me= ob->data;
Key *key= me->key;
@@ -2647,7 +2647,7 @@ static void insert_meshkey(Scene *scene, Object *ob, int from_mix)
newkey= 1;
}
kb= add_keyblock(key);
kb= add_keyblock(key, name);
if(newkey || from_mix==FALSE) {
/* create from mesh */
@@ -2658,9 +2658,11 @@ static void insert_meshkey(Scene *scene, Object *ob, int from_mix)
kb->data= do_ob_key(scene, ob);
kb->totelem= me->totvert;
}
return kb;
}
/************************* Lattice ************************/
static void insert_lattkey(Scene *scene, Object *ob, int from_mix)
static KeyBlock *insert_lattkey(Scene *scene, Object *ob, char *name, int from_mix)
{
Lattice *lt= ob->data;
Key *key= lt->key;
@@ -2673,7 +2675,7 @@ static void insert_lattkey(Scene *scene, Object *ob, int from_mix)
newkey= 1;
}
kb= add_keyblock(key);
kb= add_keyblock(key, name);
if(newkey || from_mix==FALSE) {
/* create from lattice */
@@ -2684,9 +2686,11 @@ static void insert_lattkey(Scene *scene, Object *ob, int from_mix)
kb->totelem= lt->pntsu*lt->pntsv*lt->pntsw;
kb->data= do_ob_key(scene, ob);
}
return kb;
}
/************************* Curve ************************/
static void insert_curvekey(Scene *scene, Object *ob, int from_mix)
static KeyBlock *insert_curvekey(Scene *scene, Object *ob, char *name, int from_mix)
{
Curve *cu= ob->data;
Key *key= cu->key;
@@ -2700,7 +2704,7 @@ static void insert_curvekey(Scene *scene, Object *ob, int from_mix)
newkey= 1;
}
kb= add_keyblock(key);
kb= add_keyblock(key, name);
if(newkey || from_mix==FALSE) {
/* create from curve */
@@ -2712,14 +2716,14 @@ static void insert_curvekey(Scene *scene, Object *ob, int from_mix)
kb->data= do_ob_key(scene, ob);
}
return kb;
}
int object_insert_shape_key(Scene *scene, Object *ob, int from_mix)
KeyBlock *object_insert_shape_key(Scene *scene, Object *ob, char *name, int from_mix)
{
if(ob->type==OB_MESH) insert_meshkey(scene, ob, from_mix);
else if ELEM(ob->type, OB_CURVE, OB_SURF) insert_curvekey(scene, ob, from_mix);
else if(ob->type==OB_LATTICE) insert_lattkey(scene, ob, from_mix);
else return 0;
return 1;
if(ob->type==OB_MESH) return insert_meshkey(scene, ob, name, from_mix);
else if ELEM(ob->type, OB_CURVE, OB_SURF)return insert_curvekey(scene, ob, name, from_mix);
else if(ob->type==OB_LATTICE) return insert_lattkey(scene, ob, name, from_mix);
else return NULL;
}

View File

@@ -588,7 +588,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
key->type= KEY_RELATIVE;
/* first key added, so it was the basis. initialise it with the existing mesh */
kb= add_keyblock(key);
kb= add_keyblock(key, NULL);
mesh_to_key(me, kb);
}
@@ -604,9 +604,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
if (!dm) continue;
kb= add_keyblock(key);
strcpy(kb->name, base->object->id.name+2);
BLI_uniquename(&key->block, kb, "Key", '.', offsetof(KeyBlock, name), 32);
kb= add_keyblock(key, base->object->id.name+2);
DM_to_meshkey(dm, me, kb);

View File

@@ -370,11 +370,11 @@ static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, M
key->type= KEY_RELATIVE;
/* if that was the first key block added, then it was the basis.
* Initialise it with the mesh, and add another for the modifier */
kb= add_keyblock(key);
kb= add_keyblock(key, NULL);
mesh_to_key(me, kb);
}
kb= add_keyblock(key);
kb= add_keyblock(key, md->name);
DM_to_meshkey(dm, me, kb);
dm->release(dm);

View File

@@ -84,7 +84,7 @@
static void ED_object_shape_key_add(bContext *C, Scene *scene, Object *ob, int from_mix)
{
if(object_insert_shape_key(scene, ob, from_mix)) {
if(object_insert_shape_key(scene, ob, NULL, from_mix)) {
Key *key= ob_get_key(ob);
ob->shapenr= BLI_countlist(&key->block);
@@ -241,7 +241,7 @@ static int shape_key_add_exec(bContext *C, wmOperator *op)
int from_mix = RNA_boolean_get(op->ptr, "from_mix");
ED_object_shape_key_add(C, scene, ob, from_mix);
return OPERATOR_FINISHED;
}

View File

@@ -309,6 +309,21 @@ static Object *rna_Object_find_armature(Object *ob)
return ob_arm;
}
static KeyBlock *rna_Object_add_shape_key(Object *ob, bContext *C, ReportList *reports, char *name, int from_mix)
{
Scene *scene= CTX_data_scene(C);
KeyBlock *kb= NULL;
if((kb=object_insert_shape_key(scene, ob, name, from_mix))) {
WM_event_add_notifier(C, NC_OBJECT|ND_DRAW, ob);
}
else {
BKE_reportf(reports, RPT_ERROR, "Object \"%s\"does not support shapes.", ob->id.name+2);
}
return kb;
}
int rna_Object_is_visible(Object *ob, bContext *C)
{
return !(ob->restrictflag & OB_RESTRICT_VIEW) && ob->lay & CTX_data_scene(C)->lay;
@@ -414,6 +429,15 @@ void RNA_api_object(StructRNA *srna)
parm= RNA_def_pointer(func, "ob_arm", "Object", "", "Armature object influencing this object or NULL.");
RNA_def_function_return(func, parm);
/* Shape key */
func= RNA_def_function(srna, "add_shape_key", "rna_Object_add_shape_key");
RNA_def_function_ui_description(func, "Add shape key to an object.");
RNA_def_function_flag(func, FUNC_USE_CONTEXT|FUNC_USE_REPORTS);
parm= RNA_def_string(func, "name", "Key", 0, "", "Unique name for the new keylock."); /* optional */
parm= RNA_def_boolean(func, "from_mix", 1, "", "Create new shape from existing mix of shapes.");
parm= RNA_def_pointer(func, "key", "ShapeKey", "", "New shape keyblock.");
RNA_def_function_return(func, parm);
/* DAG */
func= RNA_def_function(srna, "make_display_list", "rna_Object_make_display_list");
RNA_def_function_ui_description(func, "Update object's display data."); /* XXX describe better */