[Bf-blender-cvs] [89eff38] temp-modifier-deltamush-experimental: Don't write deltas to disk (keep as runtime cache)
Campbell Barton
noreply at git.blender.org
Sun Mar 29 22:52:01 CEST 2015
Commit: 89eff38e14f1335e1b4b9457afb03c2dd331e509
Author: Campbell Barton
Date: Mon Mar 30 07:51:24 2015 +1100
Branches: temp-modifier-deltamush-experimental
https://developer.blender.org/rB89eff38e14f1335e1b4b9457afb03c2dd331e509
Don't write deltas to disk (keep as runtime cache)
===================================================================
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/makesrna/intern/rna_modifier.c
M source/blender/modifiers/intern/MOD_deltamush.c
===================================================================
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 124a0ca..b7479ea 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -4952,18 +4952,14 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
else if (md->type == eModifierType_DeltaMush) {
DeltaMushModifierData *dmmd = (DeltaMushModifierData*)md;
- if (dmmd->deltas) {
- dmmd->deltas = newdataadr(fd, dmmd->deltas);
- if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
- BLI_endian_switch_float_array((float *)dmmd->deltas, dmmd->positions_num * 3);
- }
- }
if (dmmd->positions) {
dmmd->positions = newdataadr(fd, dmmd->positions);
if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
BLI_endian_switch_float_array((float *)dmmd->positions, dmmd->positions_num * 3);
}
}
+
+ dmmd->positions_delta_cache = NULL;
}
}
}
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index f188d93..e9509ec 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1623,9 +1623,6 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
else if (md->type == eModifierType_DeltaMush) {
DeltaMushModifierData *dmmd = (DeltaMushModifierData*)md;
- if (dmmd->deltas) {
- writedata(wd, DATA, sizeof(float[3]) * dmmd->positions_num, dmmd->deltas);
- }
if (dmmd->positions) {
writedata(wd, DATA, sizeof(float[3]) * dmmd->positions_num, dmmd->positions);
}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 7cbf23f..9f51cb3 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1292,13 +1292,16 @@ enum {
typedef struct DeltaMushModifierData {
ModifierData modifier;
- float (*deltas)[3];
float (*positions)[3];
float lambda;
char defgrp_name[64]; /* MAX_VGROUP_NAME */
short repeat, flag;
unsigned int positions_num, pad;
+
+ /* runtime-only cache (delta's between),
+ * delta's between the original positions and the smoothed positions */
+ float (*positions_delta_cache)[3];
} DeltaMushModifierData;
/* Delta Mush modifier flags */
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 7b1fba3..4b61916 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -1042,10 +1042,9 @@ static EnumPropertyItem *rna_DataTransferModifier_mix_mode_itemf(bContext *C, Po
static void rna_DeltaMushModifier_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
DeltaMushModifierData *dmmd = (DeltaMushModifierData *)ptr->data;
- if(dmmd->deltas) {
- MEM_freeN(dmmd->deltas);
- dmmd->deltas = NULL;
- }
+
+ MEM_SAFE_FREE(dmmd->positions_delta_cache);
+
rna_Modifier_update(bmain, scene, ptr);
}
diff --git a/source/blender/modifiers/intern/MOD_deltamush.c b/source/blender/modifiers/intern/MOD_deltamush.c
index ab04118..c85b05b 100644
--- a/source/blender/modifiers/intern/MOD_deltamush.c
+++ b/source/blender/modifiers/intern/MOD_deltamush.c
@@ -74,9 +74,9 @@ static void initData(ModifierData *md)
DeltaMushModifierData *dmmd = (DeltaMushModifierData *)md;
dmmd->flag = MOD_DELTAMUSH_PIN_BOUNDARY;
- dmmd->deltas = NULL;
dmmd->positions = NULL;
dmmd->positions_num = 0;
+ dmmd->positions_delta_cache = NULL;
dmmd->lambda = 0.5f;
dmmd->repeat = 5;
dmmd->defgrp_name[0] = '\0';
@@ -90,27 +90,16 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
- if (dmmd->deltas) {
- t_dmmd->deltas = MEM_dupallocN(dmmd->deltas);
- }
-
if (dmmd->positions) {
t_dmmd->positions = MEM_dupallocN(dmmd->positions);
}
}
-static void freeBind(DeltaMushModifierData * dmmd)
+static void freeBind(DeltaMushModifierData *dmmd)
{
- if (dmmd->deltas) {
- MEM_freeN(dmmd->deltas);
- dmmd->deltas = NULL;
- }
-
- if (dmmd->positions) {
- MEM_freeN(dmmd->positions);
- dmmd->positions = NULL;
- }
+ MEM_SAFE_FREE(dmmd->positions);
+ MEM_SAFE_FREE(dmmd->positions_delta_cache);
dmmd->positions_num = 0;
}
@@ -611,8 +600,8 @@ static void calc_deltas(
tangent_spaces = MEM_callocN((size_t)(numVerts) * sizeof(float[3][3]), "delta mush tangents");
dmmd->positions_num = numVerts;
/* allocate deltas if they have not yet been allocated, otheriwse we will just write over them */
- if (!dmmd->deltas) {
- dmmd->deltas = MEM_mallocN((size_t)numVerts * sizeof(float[3]), "delta mush deltas");
+ if (!dmmd->positions_delta_cache) {
+ dmmd->positions_delta_cache = MEM_mallocN((size_t)numVerts * sizeof(float[3]), "delta mush deltas");
}
smooth_verts(dmmd, dm, dvert, defgrp_index, smooth_vertex_cos, numVerts);
@@ -630,7 +619,7 @@ static void calc_deltas(
if (UNLIKELY(!invert_m3_m3(imat, tangent_spaces[i]))) {
transpose_m3_m3(imat, tangent_spaces[i]);
}
- mul_v3_m3v3(dmmd->deltas[i], imat, delta);
+ mul_v3_m3v3(dmmd->positions_delta_cache[i], imat, delta);
}
MEM_freeN(smooth_vertex_cos);
@@ -668,17 +657,17 @@ static void deltamushmodifier_do(
/* If the number of verts has changed, the bind is invalid, so we do nothing */
if (dmmd->positions_num != numVerts) {
modifier_setError(md, "Verts changed from %d to %d", dmmd->positions_num, numVerts);
- MEM_SAFE_FREE(dmmd->deltas);
+ MEM_SAFE_FREE(dmmd->positions_delta_cache);
return;
}
/* check to see if our deltas are still valid */
- if (!dmmd->deltas) {
+ if (!dmmd->positions_delta_cache) {
calc_deltas(dmmd, dm, dvert, defgrp_index, dmmd->positions, numVerts);
}
/* this could be a check, but at this point it _must_ be valid */
- BLI_assert(dmmd->positions_num == numVerts && dmmd->deltas);
+ BLI_assert(dmmd->positions_num == numVerts && dmmd->positions_delta_cache);
#ifdef DEBUG_TIME
@@ -705,7 +694,7 @@ static void deltamushmodifier_do(
calc_tangent_ortho(tangent_spaces[i]);
#endif
- mul_v3_m3v3(delta, tangent_spaces[i], dmmd->deltas[i]);
+ mul_v3_m3v3(delta, tangent_spaces[i], dmmd->positions_delta_cache[i]);
add_v3_v3(vertexCos[i], delta);
}
More information about the Bf-blender-cvs
mailing list