[Bf-blender-cvs] [2b3810f] soc-2014-shapekey: Shape keys code cleanup round 1

Grigory Revzin noreply at git.blender.org
Tue May 13 14:07:24 CEST 2014


Commit: 2b3810f6729ba8a1c10bc6aa10e1a589da99b44b
Author: Grigory Revzin
Date:   Tue Apr 29 22:05:23 2014 +0400
https://developer.blender.org/rB2b3810f6729ba8a1c10bc6aa10e1a589da99b44b

Shape keys code cleanup round 1

BKE_key_move introduced. Moves a shape key to a given index in the shape
key list. Has a wrapper operator. Can implement shape key sorting now and other stuff.

TODO: need double triangle icon!

===================================================================

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenlib/BLI_listbase.h
M	source/blender/editors/object/object_intern.h
M	source/blender/editors/object/object_ops.c
M	source/blender/editors/object/object_shapekey.c

===================================================================

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 622c9ba..631fc53 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -249,7 +249,8 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
 
         rows = 2
         if kb:
-            rows = 4
+            rows = 7
+            
         row.template_list("MESH_UL_shape_keys", "", key, "key_blocks", ob, "active_shape_key_index", rows=rows)
 
         col = row.column()
@@ -263,8 +264,10 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
             col.separator()
 
             sub = col.column(align=True)
-            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").type = 'UP'
-            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").type = 'DOWN'
+            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").steps = -5
+            sub.operator("object.shape_key_move", icon='TRIA_UP', text="").steps = -1
+            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").steps = 1
+            sub.operator("object.shape_key_move", icon='TRIA_DOWN', text="").steps = 5
 
             split = layout.split(percentage=0.4)
             row = split.row()
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 6183df8..f441c4e 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -32,48 +32,49 @@
  *  \since March 2001
  *  \author nzc
  */
-struct Key;
-struct KeyBlock;
-struct ID;
-struct ListBase;
-struct Curve;
-struct Object;
-struct Scene;
-struct Lattice;
-struct Mesh;
-struct WeightsArrayCache;
+
+typedef struct Object Object;
+typedef struct Key Key;
+typedef struct KeyBlock KeyBlock;
+typedef struct ID ID;
+typedef struct ListBase ListBase;
+typedef struct Curve Curve;
+typedef struct Scene Scene;
+typedef struct Lattice Lattice;
+typedef struct Mesh Mesh;
+typedef struct WeightsArrayCache WeightsArrayCache;
 
 /* Kernel prototypes */
 #ifdef __cplusplus
 extern "C" {
 #endif
 
-void        BKE_key_free(struct Key *sc);
-void        BKE_key_free_nolib(struct Key *key);
-struct Key *BKE_key_add(struct ID *id);
-struct Key *BKE_key_copy(struct Key *key);
-struct Key *BKE_key_copy_nolib(struct Key *key);
-void        BKE_key_make_local(struct Key *key);
-void        BKE_key_sort(struct Key *key);
+void        BKE_key_free(Key *sc);
+void        BKE_key_free_nolib(Key *key);
+Key		   *BKE_key_add(ID *id);
+Key		   *BKE_key_copy(Key *key);
+Key		   *BKE_key_copy_nolib(Key *key);
+void        BKE_key_make_local(Key *key);
+void        BKE_key_sort(Key *key);
 
 void key_curve_position_weights(float t, float data[4], int type);
 void key_curve_tangent_weights(float t, float data[4], int type);
 void key_curve_normal_weights(float t, float data[4], int type);
 
-float *BKE_key_evaluate_object_ex(struct Scene *scene, struct Object *ob, int *r_totelem,
+float *BKE_key_evaluate_object_ex(Scene *scene, Object *ob, int *r_totelem,
                                   float *arr, size_t arr_size);
-float *BKE_key_evaluate_object(struct Scene *scene, struct Object *ob, int *r_totelem);
+float *BKE_key_evaluate_object(Scene *scene, Object *ob, int *r_totelem);
 
-struct Key      *BKE_key_from_object(struct Object *ob);
-struct KeyBlock *BKE_keyblock_from_object(struct Object *ob);
-struct KeyBlock *BKE_keyblock_from_object_reference(struct Object *ob);
+Key      *BKE_key_from_object(Object *ob);
+KeyBlock *BKE_keyblock_from_object(Object *ob);
+KeyBlock *BKE_keyblock_from_object_reference(Object *ob);
 
-struct KeyBlock *BKE_keyblock_add(struct Key *key, const char *name);
-struct KeyBlock *BKE_keyblock_add_ctime(struct Key *key, const char *name, const bool do_force);
-struct KeyBlock *BKE_keyblock_from_key(struct Key *key, int index);
-struct KeyBlock *BKE_keyblock_find_name(struct Key *key, const char name[]);
-void             BKE_keyblock_copy_settings(struct KeyBlock *kb_dst, const struct KeyBlock *kb_src);
-char            *BKE_keyblock_curval_rnapath_get(struct Key *key, struct KeyBlock *kb);
+KeyBlock *BKE_keyblock_add(Key *key, const char *name);
+KeyBlock *BKE_keyblock_add_ctime(Key *key, const char *name, const bool do_force);
+KeyBlock *BKE_keyblock_from_key(Key *key, int index);
+KeyBlock *BKE_keyblock_find_name(Key *key, const char name[]);
+void             BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src);
+char            *BKE_keyblock_curval_rnapath_get(Key *key, KeyBlock *kb);
 
 // needed for the GE
 typedef struct WeightsArrayCache {
@@ -81,21 +82,33 @@ typedef struct WeightsArrayCache {
 	float **defgroup_weights;
 } WeightsArrayCache;
 
-float **BKE_keyblock_get_per_block_weights(struct Object *ob, struct Key *key, struct WeightsArrayCache *cache);
-void BKE_keyblock_free_per_block_weights(struct Key *key, float **per_keyblock_weights, struct WeightsArrayCache *cache);
-void BKE_key_evaluate_relative(const int start, int end, const int tot, char *basispoin, struct Key *key, struct KeyBlock *actkb,
+float **BKE_keyblock_get_per_block_weights(Object *ob, Key *key, WeightsArrayCache *cache);
+void BKE_keyblock_free_per_block_weights(Key *key, float **per_keyblock_weights, WeightsArrayCache *cache);
+void BKE_key_evaluate_relative(const int start, int end, const int tot, char *basispoin, Key *key, KeyBlock *actkb,
                                float **per_keyblock_weights, const int mode);
 
 /* conversion functions */
-void    BKE_key_convert_to_mesh(struct KeyBlock *kb, struct Mesh *me);
-void    BKE_key_convert_from_mesh(struct Mesh *me, struct KeyBlock *kb);
-void    BKE_key_convert_to_lattice(struct KeyBlock *kb, struct Lattice *lt);
-void    BKE_key_convert_from_lattice(struct Lattice *lt, struct KeyBlock *kb);
-void    BKE_key_convert_to_curve(struct KeyBlock *kb, struct Curve  *cu, struct ListBase *nurb);
-void    BKE_key_convert_from_curve(struct Curve *cu, struct KeyBlock *kb, struct ListBase *nurb);
-float (*BKE_key_convert_to_vertcos(struct Object *ob, struct KeyBlock *kb))[3];
-void    BKE_key_convert_from_vertcos(struct Object *ob, struct KeyBlock *kb, float (*vertCos)[3]);
-void    BKE_key_convert_from_offset(struct Object *ob, struct KeyBlock *kb, float (*ofs)[3]);
+void    BKE_key_convert_to_mesh(KeyBlock *kb, Mesh *me);
+void    BKE_key_convert_from_mesh(Mesh *me, KeyBlock *kb);
+void    BKE_key_convert_to_lattice(KeyBlock *kb, Lattice *lt);
+void    BKE_key_convert_from_lattice(Lattice *lt, KeyBlock *kb);
+void    BKE_key_convert_to_curve(KeyBlock *kb, Curve  *cu, ListBase *nurb);
+void    BKE_key_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb);
+float (*BKE_key_convert_to_vertcos(Object *ob, KeyBlock *kb))[3];
+void    BKE_key_convert_from_vertcos(Object *ob, KeyBlock *kb, float (*vertCos)[3]);
+void    BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3]);
+
+/* other management */
+/* moves a shape key to new_index. safe, clamps index to key->totkey, updates reference keys and active shape */
+void	BKE_key_move(Object *ob, KeyBlock *key_block, int new_index);
+
+/* basic key math */
+float (*BKE_key_math_deltas(KeyBlock *a, KeyBlock *basis))[3];
+float (*BKE_key_math_deltas_mult(KeyBlock *a, KeyBlock *basis, float mult))[3]; 
+
+void	BKE_key_math_add(KeyBlock *r, KeyBlock *a, KeyBlock* basis, float mult);
+void	BKE_key_math_interp(KeyBlock *r, KeyBlock *a, float mult);
+
 
 /* key.c */
 extern int slurph_opt;
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index 0f04c03..560b0c3 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -2041,3 +2041,73 @@ void BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3])
 		}
 	}
 }
+
+void BKE_key_move(Object *ob, KeyBlock *key_block, int new_index) 
+{
+	Key *key = BKE_key_from_object(ob);
+	KeyBlock *kb;
+	int delete_index, insert_index;
+	int act_shape_index = ob->shapenr - 1;
+
+	/* find where to put */
+	delete_index = BLI_findindex(&key->block, key_block);
+	insert_index = new_index - 1;
+
+	CLAMP(new_index, 0, key->totkey - 1);
+
+	if (new_index == delete_index)
+		return;
+
+	BLI_remlink(&key->block, key_block);
+
+	if (insert_index >= key->totkey - 1) {
+		insert_index = key->totkey - 1;
+		kb = key->block.last;
+		BLI_insertlinkafter(&key->block, kb, key_block);
+	} 
+	else if (insert_index < 0) {
+		/* special case -- position 0 */
+		insert_index = 0;
+		kb = key->block.first;
+		BLI_insertlinkbefore(&key->block, kb, key_block);
+	}
+	else {
+		kb = BLI_findlink(&key->block, insert_index);
+		BLI_insertlinkafter(&key->block, kb, key_block);
+	}
+
+	/* patch refkey */
+	key->refkey = key->block.first;
+
+	/* fix abs positions */
+	SWAP(float, kb->pos, key_block->pos);
+
+	/* need to update active shape number if it's affected */
+	if (act_shape_index == delete_index) {
+		ob->shapenr = new_index + 1;
+	} 
+	else if (insert_index <= act_shape_index && delete_index > act_shape_index) {
+		/* insert before, remove after */
+		ob->shapenr++;
+	} 
+	else if (insert_index >= act_shape_index && delete_index < act_shape_index) {
+		/* insert after, remove before */
+		ob->shapenr--;
+	}
+
+	/* patch basis indeces*/
+	LISTBASE_ITER_FWD(key->block, kb) {
+		if (kb->relative == delete_index) {
+			kb->relative = new_index;
+			continue;
+		}
+		if (new_index <= kb->relative && delete_index > kb->relative) {
+			/* insert before, remove after */
+			kb->relative++;
+		} 
+		else if (new_index >= kb->relative && delete_index < kb->relative) {
+			/* insert after, remove before */
+			kb->relative--;
+		}
+	}
+}
diff --git a/source/blender/blenlib/BLI_listbase.h b/source/blender/blenlib/BLI_listbase.h
index 028892e..c0c345b 100644
--- a/source/blender/blenlib/BLI_listbase.h
+++ b/source/blender/blenlib/BLI_listbase.h
@@ -89,6 +89,15 @@ BLI_INLINE void BLI_listbase_clear(struct ListBase *lb) { lb->first = lb->last =
 /* create a generic list node containing link to provided data */
 struct LinkData *BLI_genericNodeN(void *data);
 
+
+/* Loops through the whole list fwd or bwd */
+
+#

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list