[Bf-blender-cvs] [2a72704] soc-2014-shapekey: Tweaks to skey compression: switch from userpref option to savefile op option.

Bastien Montagne noreply at git.blender.org
Sat Nov 1 21:40:21 CET 2014


Commit: 2a72704c1612cf2717da520c16dd7b41f1d0fb33
Author: Bastien Montagne
Date:   Sat Nov 1 21:37:57 2014 +0100
Branches: soc-2014-shapekey
https://developer.blender.org/rB2a72704c1612cf2717da520c16dd7b41f1d0fb33

Tweaks to skey compression: switch from userpref option to savefile op option.

Makes more sense, and follow what we did e.g. for BMesh.

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

M	release/scripts/startup/bl_ui/space_userpref.py
M	source/blender/blenkernel/BKE_global.h
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/makesdna/DNA_key_types.h
M	source/blender/makesdna/DNA_userdef_types.h
M	source/blender/makesrna/intern/rna_userdef.c
M	source/blender/windowmanager/intern/wm_operators.c

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

diff --git a/release/scripts/startup/bl_ui/space_userpref.py b/release/scripts/startup/bl_ui/space_userpref.py
index e9d19aa..3390361 100644
--- a/release/scripts/startup/bl_ui/space_userpref.py
+++ b/release/scripts/startup/bl_ui/space_userpref.py
@@ -929,7 +929,6 @@ class USERPREF_PT_file(Panel):
         col.prop(paths, "hide_recent_locations")
         col.prop(paths, "hide_system_bookmarks")
         col.prop(paths, "show_thumbnails")
-        col.prop(paths, "legacy_keyblocks")
 
         col.separator()
 
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index a7aa4c6..2e51034 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -166,6 +166,7 @@ enum {
 #define G_FILE_HISTORY           (1 << 25)
 #define G_FILE_MESH_COMPAT       (1 << 26)              /* BMesh option to save as older mesh format */
 #define G_FILE_SAVE_COPY         (1 << 27)              /* restore paths after editing them */
+#define G_FILE_SHAPEKEY_COMPAT   (1 << 28)              /* Option to save as older shapekey format (no compression) */
 
 #define G_FILE_FLAGS_RUNTIME (G_FILE_NO_UI | G_FILE_RELATIVE_REMAP | G_FILE_MESH_COMPAT | G_FILE_SAVE_COPY)
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 66fbb2f..c98d845 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -3118,7 +3118,7 @@ static void switch_endian_keyblock(Key *key, KeyBlock *kb)
 	const char *data, *poin, *cp;
 	data = kb->data;
 
-	if (kb->compressed) {
+	if (kb->flag & KEY_COMPRESSED) {
 		CompressedMeshVertex *verts = (CompressedMeshVertex *)data;
 		for (a = 0; a < kb->totelem; ++a) {
 			BLI_endian_switch_int32(&verts[a].vertex_index);
@@ -3170,7 +3170,7 @@ static void direct_link_key(FileData *fd, Key *key)
 		if (fd->flags & FD_FLAGS_SWITCH_ENDIAN)
 			switch_endian_keyblock(key, kb);
 		
-		if (kb->compressed && key->refkey != kb) {
+		if ((kb->flag & KEY_COMPRESSED) && key->refkey != kb) {
 			uncompress_kb(key, kb);
 		}
 	}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 27592af..9c99457 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -310,6 +310,7 @@ typedef struct {
 #ifdef USE_BMESH_SAVE_AS_COMPAT
 	char use_mesh_compat; /* option to save with older mesh format */
 #endif
+	char use_skey_compat; /* option to save skeys without compression */
 } WriteData;
 
 static WriteData *writedata_new(WriteWrap *ww)
@@ -1708,10 +1709,10 @@ static void compress_kb(KeyBlock *kb, Key *key_owner)
 
 	BLI_assert(kb->data); /* should not happen at any time! */
 
-	n_changed_verts = 0; /* counts CompressedMeshVertexes */
+	n_changed_verts = 0; /* counts CompressedMeshVertex's */
 	for (a = 0; a < rk->totelem; ++a) {
 		sub_v3_v3v3(diff, rkbco[a], kbco[a]);
-		if (len_squared_v3(diff) > 0.0001f) {
+		if (len_squared_v3(diff) > KEY_MIN_SQUARED_LEN) {
 			/* this vert's pos has changed from the base */
 			copy_v3_v3(verts[n_changed_verts].co, kbco[a]);
 			verts[n_changed_verts].vertex_index = a;
@@ -1720,9 +1721,9 @@ static void compress_kb(KeyBlock *kb, Key *key_owner)
 	}
 
 	/* time to decide if we're going to win space by saving to compressed format */
+	/*    size we get with compress        size we get without compress */
 	if (n_changed_verts * sizeof(verts) < rk->totelem * sizeof(float)* 3) {
-		/*       size we get with compress      */   /* size we get without compress */
-		kb->compressed = 1;
+		kb->flag |= KEY_COMPRESSED;
 		kb->totelem = n_changed_verts;
 
 		MEM_freeN(kb->data);
@@ -1730,13 +1731,13 @@ static void compress_kb(KeyBlock *kb, Key *key_owner)
 
 		if (G.debug_value == 1) {
 			printf("Compressed Shape Key %s, %.2f times smaller\n", kb->name,
-				(rk->totelem * sizeof(float) * 3.0f) / (n_changed_verts * sizeof(CompressedMeshVertex)));
+			       (rk->totelem * sizeof(float) * 3.0f) / (n_changed_verts * sizeof(CompressedMeshVertex)));
 		}
 	}
 	else {
 		MEM_freeN(verts);
 		/* just ensure */
-		kb->compressed = 0;
+		kb->flag &= ~KEY_COMPRESSED;
 	}
 }
 
@@ -1760,7 +1761,7 @@ static void write_keys(WriteData *wd, ListBase *idbase)
 	while (key) {
 		if (key->id.us>0 || wd->current) {
 			/* direct data */
-			if (GS(key->from->name) == ID_ME && !(U.flag & USER_LEGACY_KEYBLOCKS_FMT)) {
+			if (GS(key->from->name) == ID_ME && !wd->use_skey_compat) {
 				ListBase lb = key->block;
 
 				/* if mesh keys, save a compressed copy */
@@ -1782,15 +1783,12 @@ static void write_keys(WriteData *wd, ListBase *idbase)
 				compress_keyblocks(dupe);
 
 				/* direct */
-				kb = key->block.first;
-
-				while (kb) {
+				for (kb = key->block.first; kb; kb = kb->next) {
 					writestruct(wd, DATA, "KeyBlock", 1, kb);
-					if (kb->compressed) 
-						writedata(wd, DATA, sizeof(CompressedMeshVertex)* kb->totelem, kb->data);
+					if (kb->flag & KEY_COMPRESSED)
+						writedata(wd, DATA, kb->totelem * sizeof(CompressedMeshVertex), kb->data);
 					else
 						writedata(wd, DATA, kb->totelem * key->elemsize, kb->data);
-					kb = kb->next;
 				}
 
 				/* restore key data */
@@ -1810,12 +1808,10 @@ static void write_keys(WriteData *wd, ListBase *idbase)
 					write_animdata(wd, key->adt);
 
 				/* direct */
-				kb = key->block.first;
-				while (kb) {
-					kb->compressed = 0;
+				for (kb = key->block.first; kb; kb = kb->next) {
+					kb->flag &= ~KEY_COMPRESSED;
 					writestruct(wd, DATA, "KeyBlock", 1, kb);
 					if (kb->data) writedata(wd, DATA, kb->totelem * key->elemsize, kb->data);
-					kb = kb->next;
 				}
 			}
 		}
@@ -3607,6 +3603,8 @@ static int write_file_handle(
 	wd->use_mesh_compat = (write_flags & G_FILE_MESH_COMPAT) != 0;
 #endif
 
+	wd->use_skey_compat = (write_flags & G_FILE_SHAPEKEY_COMPAT) != 0;
+
 #ifdef USE_NODE_COMPAT_CUSTOMNODES
 	/* don't write compatibility data on undo */
 	if (!current) {
diff --git a/source/blender/makesdna/DNA_key_types.h b/source/blender/makesdna/DNA_key_types.h
index 6143547..ae8c81d 100644
--- a/source/blender/makesdna/DNA_key_types.h
+++ b/source/blender/makesdna/DNA_key_types.h
@@ -58,9 +58,7 @@ typedef struct KeyBlock {
 	float curval;      /* influence (typically [0 - 1] but can be more), (Key->type == KEY_RELATIVE) only.*/
 
 	short type;        /* interpolation type (Key->type == KEY_NORMAL) only. */
-	short compressed;  /* for disk write/read; if 1, then they key's data is laid out as an array of
-	                    * CompressedMeshVertex structs (total totelem).
-	                    * Mesh only. Does not do anything useful at runtime */
+	short pad1;
 
 	short relative;    /* relative == 0 means first key is reference, otherwise the index of Key->blocks */
 	short flag;
@@ -146,9 +144,15 @@ enum {
 
 /* Key->flag */
 enum {
-	KEY_DS_EXPAND   = 1
+	KEY_DS_EXPAND   = 1 << 0,
+	/* File save only - if set, key's data is laid out as an array of CompressedMeshVertex structs (total totelem).
+	 * Mesh only. Does not do anything useful at runtime */
+	KEY_COMPRESSED  = 1 << 1,
 };
 
+/* Min squared distance between org vertex and skey one, to store the skey in file (compressed mode only). */
+#define KEY_MIN_SQUARED_LEN 1e-6f
+
 /* KeyBlock->type */
 enum {
 	KEY_LINEAR      = 0,
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index fee9e3b..d8653e1 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -594,7 +594,6 @@ typedef enum eUserPref_Flag {
 	USER_NONEGFRAMES		= (1 << 24),
 	USER_TXT_TABSTOSPACES_DISABLE	= (1 << 25),
 	USER_TOOLTIPS_PYTHON    = (1 << 26),
-	USER_LEGACY_KEYBLOCKS_FMT       = (1 << 27)
 } eUserPref_Flag;
 
 /* flag */
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index 5e1995a..a23c3ea 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -4332,10 +4332,6 @@ static void rna_def_userdef_filepaths(BlenderRNA *brna)
 	RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_FILECOMPRESS);
 	RNA_def_property_ui_text(prop, "Compress File", "Enable file compression when saving .blend files");
 
-	prop = RNA_def_property(srna, "legacy_keyblocks", PROP_BOOLEAN, PROP_NONE);
-	RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_LEGACY_KEYBLOCKS_FMT);
-	RNA_def_property_ui_text(prop, "Legacy Keyblocks", "Don't compress keyblocks so previous Blender versions will be able to open the file");
-
 	prop = RNA_def_property(srna, "use_load_ui", PROP_BOOLEAN, PROP_NONE);
 	RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", USER_FILENOUI);
 	RNA_def_property_ui_text(prop, "Load UI", "Load user interface setup when loading .blend files");
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index 3b0fa04..1483e21 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -2842,6 +2842,9 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
 	                 G_FILE_MESH_COMPAT);
 #endif
 
+	BKE_BIT_TEST_SET(fileflags, RNA_boolean_get(op->ptr, "use_shapekey_compat"),
+	                 G_FILE_SHAPEKEY_COMPAT);
+
 	if (wm_file_write(C, path, fileflags, op->reports) != 0)
 		return OPERATOR_CANCELLED;
 
@@ -2891,6 +2894,8 @@ static void WM_OT_save_as_mainfile(wmOperatorType *ot)
 	                "Save using legacy mesh format (no ngons) - WARNING: only saves tris and quads, other ngons will "
 	                "be lost (no implicit triangulation)");
 #endif
+	RNA_def_boolean(ot->srna, "use_shapekey_compat", false, "Legacy ShapeKey Format",
+	                "Save using legacy ShapeKey format (no compression)");
 }
 
 /* *************** save file directly ******** */
@@ -2958,6 +2963,8 @@ static void WM_OT_save_mainfile(wmOperatorType *ot)
 	                               WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY);
 	RNA_def_boolean(ot->srna, "compress", 0, "Compress", "Write compressed .blend file");
 	RNA_def_boolean(ot->srna, "relative_

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list