[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [39918] branches/vgroup_modifiers/source/ blender/modifiers/intern: - vertex group modifiers isDisabled functions were incorrect, need to check if the string is set: == NULL will never be true.
Campbell Barton
ideasman42 at gmail.com
Mon Sep 5 07:28:32 CEST 2011
Revision: 39918
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=39918
Author: campbellbarton
Date: 2011-09-05 05:28:32 +0000 (Mon, 05 Sep 2011)
Log Message:
-----------
- vertex group modifiers isDisabled functions were incorrect, need to check if the string is set: == NULL will never be true.
- was doing NULL checks on freeing memory in cases where the values were already accessed (blender would have crashed anyway), so remove the NULL checks.
- use deform.c api weight functions to replace inline weight lookups in some cases.
- change if checks in weightvg_do_mask() so its more obvious whats going on.
Modified Paths:
--------------
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgedit.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgmix.c
branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c 2011-09-05 04:53:23 UTC (rev 39917)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvg_util.c 2011-09-05 05:28:32 UTC (rev 39918)
@@ -66,7 +66,6 @@
const char *tex_uvlayer_name)
{
int ref_didx;
- MDeformVert *dvert = NULL;
int i;
/* If influence factor is null, nothing to do! */
@@ -139,16 +138,16 @@
}
MEM_freeN(tex_co);
- return;
}
+ else if ((ref_didx = defgroup_name_index(ob, defgrp_name)) != -1) {
+ MDeformVert *dvert = NULL;
- /* Check whether we want to set vgroup weights from a constant weight factor or a vertex
- * group.
- */
- /* Get vgroup idx from its name. */
- ref_didx = defgroup_name_index(ob, defgrp_name);
- /* Proceed only if vgroup is valid, else use constant factor. */
- if (ref_didx >= 0) {
+ /* Check whether we want to set vgroup weights from a constant weight factor or a vertex
+ * group.
+ */
+ /* Get vgroup idx from its name. */
+
+ /* Proceed only if vgroup is valid, else use constant factor. */
/* Get actual dverts (ie vertex group data). */
dvert = dm->getVertDataArray(dm, CD_MDEFORMVERT);
/* Proceed only if vgroup is valid, else assume factor = O. */
@@ -157,23 +156,18 @@
/* For each weight (vertex), make the mix between org and new weights. */
for (i = 0; i < num; i++) {
int idx = indices ? indices[i] : i;
- int j;
- for (j = 0; j < dvert[idx].totweight; j++) {
- if(dvert[idx].dw[j].def_nr == ref_didx) {
- float f = dvert[idx].dw[j].weight * fact;
- org_w[i] = (new_w[i] * f) + (org_w[i] * (1.0-f));
- break;
- }
- }
+ const float f= defvert_find_weight(&dvert[idx], ref_didx) * fact;
+ org_w[i] = (new_w[i] * f) + (org_w[i] * (1.0f-f));
/* If that vertex is not in ref vgroup, assume null factor, and hence do nothing! */
}
- return;
}
-
- /* Default "influence" behavior. */
- /* For each weight (vertex), make the mix between org and new weights. */
- for (i = 0; i < num; i++) {
- org_w[i] = (new_w[i] * fact) + (org_w[i] * (1.0-fact));
+ else {
+ /* Default "influence" behavior. */
+ /* For each weight (vertex), make the mix between org and new weights. */
+ const float ifact= 1.0-fact;
+ for (i = 0; i < num; i++) {
+ org_w[i] = (new_w[i] * fact) + (org_w[i] * ifact);
+ }
}
}
@@ -189,7 +183,7 @@
for (i = 0; i < num; i++) {
int j;
- char add2vg = do_add;
+ int add2vg = do_add;
float w = weights[i];
MDeformVert *dv = &dvert[indices ? indices[i] : i];
MDeformWeight *newdw;
@@ -207,6 +201,8 @@
if (dv->dw[j].def_nr == defgrp_idx) {
/* Remove the vertex from this vgroup if needed. */
if (do_rem && w < rem_thresh) {
+ /* TODO, move this into deform.c to make into a generic function */
+
dv->totweight--;
/* If there are still other deform weights attached to this vert then remove
* this deform weight, and reshuffle the others.
@@ -230,14 +226,16 @@
else {
dv->dw[j].weight = w;
}
- add2vg = 0;
+ add2vg = FALSE;
break;
}
}
/* If the vert wasn't in the deform group, add it if needed!
*/
- if (add2vg && w > add_thresh) {
+ if ((add2vg == TRUE) && w > add_thresh) {
+ /* TODO, mvoe into deform.c and make into a generic function, this assumes the vertex
+ * groups have already been checked, so this has to remain low level */
newdw = MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "WeightVGEdit Modifier, deformWeight");
if(dv->dw) {
memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight);
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgedit.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgedit.c 2011-09-05 04:53:23 UTC (rev 39917)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgedit.c 2011-09-05 05:28:32 UTC (rev 39918)
@@ -173,7 +173,7 @@
{
WeightVGEditModifierData *wmd = (WeightVGEditModifierData*) md;
/* If no vertex group, bypass. */
- return (wmd->defgrp_name == NULL);
+ return (wmd->defgrp_name[0] == '\0');
}
static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
@@ -185,17 +185,16 @@
Mesh *ob_m = NULL;
#endif
MDeformVert *dvert = NULL;
- float *org_w = NULL; /* Array original weights. */
- float *new_w = NULL; /* Array new weights. */
+ float *org_w; /* Array original weights. */
+ float *new_w; /* Array new weights. */
int numVerts;
int defgrp_idx;
int i;
char rel_ret = 0; /* Boolean, whether we have to release ret dm or not, when not using it! */
- float *mapf = NULL; /* Cache for mapping factors. */
/* Flags. */
- char do_map = wmd->edit_flags & MOD_WVG_EDIT_CMAP;
- char do_add = wmd->edit_flags & MOD_WVG_EDIT_ADD2VG;
- char do_rem = wmd->edit_flags & MOD_WVG_EDIT_REMFVG;
+ int do_map = (wmd->edit_flags & MOD_WVG_EDIT_CMAP) != 0;
+ int do_add = (wmd->edit_flags & MOD_WVG_EDIT_ADD2VG) != 0;
+ int do_rem = (wmd->edit_flags & MOD_WVG_EDIT_REMFVG) != 0;
/* Get number of verts. */
numVerts = dm->getNumVerts(dm);
@@ -259,17 +258,17 @@
org_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w");
new_w = MEM_mallocN(sizeof(float) * numVerts, "WeightVGEdit Modifier, org_w");
for (i = 0; i < numVerts; i++) {
- int j;
+ MDeformWeight *dw= defvert_find_index(&dvert[i], defgrp_idx);
org_w[i] = new_w[i] = wmd->default_weight;
- for (j = 0; j < dvert[i].totweight; j++) {
- if(dvert[i].dw[j].def_nr == defgrp_idx) {
- org_w[i] = new_w[i] = dvert[i].dw[j].weight;
- break;
- }
+
+ if(dw) {
+ org_w[i] = new_w[i] = dw->weight;
}
+
/* Do mapping. */
- if (do_map)
+ if (do_map) {
new_w[i] = curvemapping_evaluateF(wmd->cmap_curve, 0, new_w[i]);
+ }
}
/* Do masking. */
@@ -282,12 +281,8 @@
do_rem, wmd->rem_threshold);
/* Freeing stuff. */
- if (org_w)
- MEM_freeN(org_w);
- if (new_w)
- MEM_freeN(new_w);
- if (mapf)
- MEM_freeN(mapf);
+ MEM_freeN(org_w);
+ MEM_freeN(new_w);
/* Return the vgroup-modified mesh. */
return ret;
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgmix.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgmix.c 2011-09-05 04:53:23 UTC (rev 39917)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgmix.c 2011-09-05 05:28:32 UTC (rev 39918)
@@ -217,7 +217,7 @@
{
WeightVGMixModifierData *wmd = (WeightVGMixModifierData*) md;
/* If no vertex group, bypass. */
- return (wmd->defgrp_name_a == NULL);
+ return (wmd->defgrp_name_a[0] == '\0');
}
static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
@@ -231,8 +231,8 @@
MDeformVert *dvert = NULL;
int numVerts;
int defgrp_idx, defgrp_idx2 = -1;
- float *org_w = NULL;
- float *new_w = NULL;
+ float *org_w;
+ float *new_w;
int *tidx, *indices = NULL;
int numIdx = 0;
int i, j;
@@ -416,13 +416,12 @@
/* Update (add to) vgroup.
* XXX Depending on the MOD_WVG_SET_xxx option chosen, we might have to add vertices to vgroup.
*/
- weightvg_update_vg(dvert, defgrp_idx, numIdx, indices, org_w, 1, -FLT_MAX, 0, 0.0f);
+ weightvg_update_vg(dvert, defgrp_idx, numIdx, indices, org_w, TRUE, -FLT_MAX, 0, 0.0f);
/* Freeing stuff. */
- if (org_w)
- MEM_freeN(org_w);
- if (new_w)
- MEM_freeN(new_w);
+ MEM_freeN(org_w);
+ MEM_freeN(new_w);
+
if (indices)
MEM_freeN(indices);
Modified: branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c
===================================================================
--- branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c 2011-09-05 04:53:23 UTC (rev 39917)
+++ branches/vgroup_modifiers/source/blender/modifiers/intern/MOD_weightvgproximity.c 2011-09-05 05:28:32 UTC (rev 39918)
@@ -327,7 +327,7 @@
{
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData*) md;
/* If no vertex group, bypass. */
- if (wmd->defgrp_name == NULL) return 1;
+ if (wmd->defgrp_name[0] == '\0') return 1;
/* If no target object, bypass. */
return (wmd->proximity_ob_target == NULL);
}
@@ -505,14 +505,10 @@
weightvg_update_vg(dvert, defgrp_idx, numIdx, indices, org_w, 0, 0.0f, 0, 0.0f);
/* Freeing stuff. */
- if (org_w)
- MEM_freeN(org_w);
- if (new_w)
- MEM_freeN(new_w);
- if (indices)
- MEM_freeN(indices);
- if (v_cos)
- MEM_freeN(v_cos);
+ MEM_freeN(org_w);
+ MEM_freeN(new_w);
+ MEM_freeN(indices);
+ MEM_freeN(v_cos);
/* Return the vgroup-modified mesh. */
return ret;
More information about the Bf-blender-cvs
mailing list