[Bf-blender-cvs] [3f5bfbb] soc-2014-shapekey: Initial rough support for Scratch Shapekey

Grigory Revzin noreply at git.blender.org
Fri May 16 02:02:39 CEST 2014


Commit: 3f5bfbbae558bb836fb14ae613c1ef08faaef185
Author: Grigory Revzin
Date:   Fri May 16 03:42:43 2014 +0400
https://developer.blender.org/rB3f5bfbbae558bb836fb14ae613c1ef08faaef185

Initial rough support for Scratch Shapekey

Scratch shape key types added to Key DNA. Modifications to file
reading/writing are done to save the Scratch's data.

Auto-commit property is added to the Scene's tool_settings. Versioning
code to set it to 1 by default is added.

EditMesh kernel module now has a hashing function to determine if the
mesh's topology has been changed.

editmesh_utils.c now has features to work with both the scratch shape key,
supporting scratch-based shape key recalculations, and sped-up
shapekey recalculation in case the Mesh didn't change topology.
This is draft rough buggy code yet.

UI: added Auto-Commit under the Shape Keys panel, removed Apply Shape keys
in Edit Mode - won't be needed later.

Next to do: check undo support.

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

M	release/scripts/startup/bl_ui/properties_data_mesh.py
M	source/blender/blenkernel/BKE_blender.h
M	source/blender/blenkernel/BKE_key.h
M	source/blender/blenkernel/intern/key.c
M	source/blender/blenlib/BLI_listbase.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_270.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/editors/include/ED_mesh.h
M	source/blender/editors/mesh/editmesh_utils.c
M	source/blender/editors/object/object_edit.c
M	source/blender/editors/object/object_shapekey.c
M	source/blender/makesdna/DNA_key_types.h
M	source/blender/makesdna/DNA_scene_types.h
M	source/blender/makesrna/intern/rna_object.c
M	source/blender/makesrna/intern/rna_scene.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_mesh.py b/release/scripts/startup/bl_ui/properties_data_mesh.py
index 3eac5e8..4c2829b 100644
--- a/release/scripts/startup/bl_ui/properties_data_mesh.py
+++ b/release/scripts/startup/bl_ui/properties_data_mesh.py
@@ -237,6 +237,7 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
         ob = context.object
         key = ob.data.shape_keys
         kb = ob.active_shape_key
+        ts = context.scene.tool_settings
 
         enable_edit = ob.mode != 'EDIT'
         enable_edit_value = False
@@ -273,16 +274,16 @@ class DATA_PT_shape_keys(MeshButtonsPanel, Panel):
             row = split.row()
             row.enabled = enable_edit
             row.prop(key, "use_relative")
-
             row = split.row()
+            if ob.mode == 'EDIT':    
+                row.prop(ts, "kb_auto_commit", text = "Auto-commit")
             row.alignment = 'RIGHT'
-
             sub = row.row(align=True)
             sub.label()  # XXX, for alignment only
             subsub = sub.row(align=True)
-            subsub.active = enable_edit_value
+            #subsub.active = enable_edit_value
             subsub.prop(ob, "show_only_shape_key", text="")
-            sub.prop(ob, "use_shape_key_edit_mode", text="")
+
 
             sub = row.row()
             if key.use_relative:
diff --git a/source/blender/blenkernel/BKE_blender.h b/source/blender/blenkernel/BKE_blender.h
index e4ebe0e..a3b7760 100644
--- a/source/blender/blenkernel/BKE_blender.h
+++ b/source/blender/blenkernel/BKE_blender.h
@@ -42,7 +42,7 @@ extern "C" {
  * and keep comment above the defines.
  * Use STRINGIFY() rather than defining with quotes */
 #define BLENDER_VERSION         270
-#define BLENDER_SUBVERSION      5
+#define BLENDER_SUBVERSION      295
 /* 262 was the last editmesh release but it has compatibility code for bmesh data */
 #define BLENDER_MINVERSION      270
 #define BLENDER_MINSUBVERSION   5
diff --git a/source/blender/blenkernel/BKE_key.h b/source/blender/blenkernel/BKE_key.h
index 3dcd46e..c70c054 100644
--- a/source/blender/blenkernel/BKE_key.h
+++ b/source/blender/blenkernel/BKE_key.h
@@ -43,6 +43,8 @@ typedef struct Scene Scene;
 typedef struct Lattice Lattice;
 typedef struct Mesh Mesh;
 typedef struct WeightsArrayCache WeightsArrayCache;
+typedef struct BMEditMesh BMEditMesh;
+typedef struct ScratchKeyBlock ScratchKeyBlock;
 
 /* Kernel prototypes */
 #ifdef __cplusplus
@@ -73,8 +75,25 @@ 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);
+void      BKE_keyblock_copy_settings(KeyBlock *kb_dst, const KeyBlock *kb_src);
+char     *BKE_keyblock_curval_rnapath_get(Key *key, KeyBlock *kb);
+
+/* ==== scratch keyblock ==== */
+
+/* performs a first-time setup of the scratch. if it's already inited 
+ * (e. g. existed in a mainfile), does nothing. */
+void BKE_key_init_scratch(Object *ob);
+
+/* moves current edit data to and from the scratch shape */
+void BKE_key_editdata_to_scratch(Object *ob, bool shapedata_indeces_in_sync);
+
+/* populates the current editdata from scratch shapekey */
+void BKE_key_editdata_from_scratch(Object *ob);
+
+/* evaluates the current shape key situation and puts it into the editmesh coordinates */
+void BKE_key_eval_editmesh_rel(BMEditMesh *edbm, bool pinned);
+
+/* ========================= */
 
 // needed for the GE
 typedef struct WeightsArrayCache {
@@ -98,17 +117,18 @@ 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 
  * the object's active shape index */
 void	BKE_keyblock_move(Object *ob, KeyBlock *key_block, int new_index);
 
 /* basic key math */
-float	(*BKE_keyblock_math_deltas(KeyBlock *a, KeyBlock *basis))[3];
-float	(*BKE_keyblock_math_deltas_mult(KeyBlock *a, KeyBlock *basis, float mult))[3];
+float	(*BKE_keyblock_math_deltas(Object *ob, KeyBlock *a, KeyBlock *basis))[3];
+float	(*BKE_keyblock_math_deltas_mult(Object *ob, KeyBlock *a, KeyBlock *basis, float mult, float dists[]))[3];
 
-void	BKE_keyblock_math_add(KeyBlock *r, KeyBlock *a, KeyBlock* basis, float mult);
-void	BKE_keyblock_math_interp(KeyBlock *r, KeyBlock *a, float mult);
+void	BKE_keyblock_math_add(Object *ob, KeyBlock *r, KeyBlock *a, KeyBlock* basis, float mult);
+void	BKE_keyblock_math_interp(Object *ob, KeyBlock *r, KeyBlock *a, float mult);
 
 
 /* key.c */
diff --git a/source/blender/blenkernel/intern/key.c b/source/blender/blenkernel/intern/key.c
index d86a669..b4ddcaf 100644
--- a/source/blender/blenkernel/intern/key.c
+++ b/source/blender/blenkernel/intern/key.c
@@ -73,10 +73,13 @@
 #define IPO_BEZTRIPLE   100
 #define IPO_BPOINT      101
 
+#define ELEMSIZE_MESH		(sizeof(float) * 3)
+#define ELEMSIZE_LATTICE	(sizeof(float) * 3)
+#define ELEMSIZE_CURVE		(sizeof(float) * 4)
+
 /* extern, not threadsafe */
 int slurph_opt = 1;
 
-
 void BKE_key_free(Key *key)
 {
 	KeyBlock *kb;
@@ -88,6 +91,9 @@ void BKE_key_free(Key *key)
 			MEM_freeN(kb->data);
 		MEM_freeN(kb);
 	}
+
+	if (key->scratch.data)
+		MEM_freeN(key->scratch.data);
 }
 
 void BKE_key_free_nolib(Key *key)
@@ -99,6 +105,9 @@ void BKE_key_free_nolib(Key *key)
 			MEM_freeN(kb->data);
 		MEM_freeN(kb);
 	}
+
+	if (key->scratch.data)
+		MEM_freeN(key->scratch.data);
 }
 
 Key *BKE_key_add(ID *id)    /* common function */
@@ -146,7 +155,6 @@ Key *BKE_key_add(ID *id)    /* common function */
 
 			break;
 	}
-	
 	return key;
 }
 
@@ -172,6 +180,9 @@ Key *BKE_key_copy(Key *key)
 		kb = kb->next;
 	}
 	
+	if (key->scratch.data)
+		keyn->scratch.data = MEM_dupallocN(key->scratch.data);
+
 	return keyn;
 }
 
@@ -196,10 +207,14 @@ Key *BKE_key_copy_nolib(Key *key)
 		
 		if (kbn->data) kbn->data = MEM_dupallocN(kbn->data);
 		if (kb == key->refkey) keyn->refkey = kbn;
+		if (kb == key->scratch.origin) keyn->scratch.origin = kbn;
 		
 		kbn = kbn->next;
 		kb = kb->next;
 	}
+
+	if (key->scratch.data)
+		keyn->scratch.data = MEM_dupallocN(key->scratch.data);
 	
 	return keyn;
 }
@@ -725,6 +740,7 @@ static void cp_cu_key(Curve *cu, Key *key, KeyBlock *actkb, KeyBlock *kb, const
 	}
 }
 
+
 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)
 {
@@ -1519,6 +1535,7 @@ KeyBlock *BKE_keyblock_add(Key *key, const char *name)
 	kb->type = KEY_CARDINAL;
 	
 	tot = BLI_countlist(&key->block);
+
 	if (name) {
 		BLI_strncpy(kb->name, name, sizeof(kb->name));
 	}
@@ -1693,6 +1710,7 @@ void BKE_key_convert_to_lattice(KeyBlock *kb, Lattice *lt)
 	}
 }
 
+
 /************************* Curve ************************/
 void BKE_key_convert_from_curve(Curve *cu, KeyBlock *kb, ListBase *nurb)
 {
@@ -2041,6 +2059,213 @@ void BKE_key_convert_from_offset(Object *ob, KeyBlock *kb, float (*ofs)[3])
 		}
 	}
 }
+/* ================== Scratch stuff ======================  */
+
+void BKE_key_init_scratch(Object *ob) 
+{
+	Key *key = BKE_key_from_object(ob);
+	KeyBlock *kb = BKE_keyblock_from_object(ob);
+	if (key && kb && key->totkey > 0) {
+		key->scratch.origin = kb;
+		if (!key->scratch.data) {
+			key->scratch.data = MEM_mallocN(key->elemsize * kb->totelem, "scratch keyblock data");
+			memcpy(key->scratch.data, kb->data, key->elemsize * kb->totelem);
+		}
+	}
+}
+
+void BKE_key_editdata_to_scratch(Object *ob, bool indeces_in_sync)
+{
+	BLI_assert(ELEM3(ob->type, OB_MESH, OB_LATTICE, OB_CURVE));
+	BLI_assert(ob->mode == OB_MODE_EDIT);
+	
+	Key *k = BKE_key_from_object(ob);
+	ScratchKeyBlock *skb = &k->scratch;
+	
+	if (ob->type == OB_MESH) {
+		Mesh *m = ob->data;
+		BMesh *bm = m->edit_btmesh->bm;
+		BMVert *v;
+		BMIter iter;
+		int a;
+		float(*co)[3] = skb->data;
+
+		if (indeces_in_sync) {
+			BM_ITER_MESH_INDEX(v, &iter, bm, BM_VERTS_OF_MESH, a) {
+				copy_v3_v3(co[a], v->co);
+			}
+		}
+		else {
+			/* note how we don't adjust the skb->data length here,
+			 * this is for preserving the indeces for bm_to_me     */
+			BM_ITER_MESH(v, &iter, bm, BM_VERTS_OF_MESH) {
+				a = *(int *) CustomData_bmesh_get(&bm->vdata, v->head.data, CD_SHAPE_KEYINDEX);
+				BLI_assert(a < bm->totvert);
+				if (a != ORIGINDEX_NONE) {
+					copy_v3_v3(co[a], v->co);
+				}
+			}
+		}
+	}
+	else if (ob->type == OB_LATTICE) {
+		BLI_assert(0); /* not done yet */
+	}
+	else if (ob->type == OB_CURVE) {
+		BLI_assert(0); /* not done yet */
+	}
+}
+
+void BKE_key_editdata_from_scratch(Object *ob)
+{
+	BLI_assert(ELEM3(ob->type, OB_MESH, OB_LATTICE, OB_CURVE));
+	BLI_assert(ob->mode == OB_MODE_EDIT);
+
+	ScratchKeyBlock *skb = &BKE_key_from_object(ob)->scratch;
+
+	if (ob->type == OB_MESH) {
+		Mesh *m = ob->data;
+		BMesh *bm = m->edit_btmesh->bm;
+		BMVert *v;
+		BMIter iter;
+		int a;
+		float(*co)[3] = skb->data;
+
+		BLI_assert(bm->totvert == skb->origin->totelem);
+
+		BM_ITER_MESH_INDEX(v, &iter, bm, BM_VERTS_OF_MESH, a) {
+			copy_v3_v3(v->co, co[a]);
+		}
+	}
+	else if (ob->type == OB_LATTICE) {
+		BLI_assert(0); /* not done yet */
+	}
+	else if (ob->type == OB_CURVE) {
+		BLI_assert(0); /* not done yet */
+	}
+}
+
+/*============ editmode mesh keyblock eval tools ===========*/
+
+#define KB_FOR_EACH_CO(kb, indexvar) \
+for ((indexvar) = 0; (indexvar) < (kb)->totelem; ++(indexvar))
+
+void key_block_mesh_get_deltas(Key *key, KeyBlock *kb, float (*out_deltas)[3])
+{
+	int a;
+	KeyBlock *basis = BLI_findlink(&key->block, kb->relative);
+	float (*basis_cos)[3];
+	float (*kb_cos)[3];
+	
+	BLI_assert(basis && basis->totelem == kb->totelem);
+
+	basis_cos = basis->data;
+	kb_cos = kb->data;
+
+	KB_FOR_EACH_CO(kb, a)
+		sub_v3_v3v3(out_deltas[a], kb_cos[a], basis_cos[a]);
+}
+
+v

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list