Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2011-12-08 07:47:45 +0400
committerCampbell Barton <ideasman42@gmail.com>2011-12-08 07:47:45 +0400
commit2b8249854499199299a4a067f9edfa691a14bbe9 (patch)
tree6bd8992da5c84fee2b76ca3ec7dac85cce2a9aeb /source/blender/blenkernel/intern/deform.c
parenta5fb261016f0dd9a1393da4aadc76272a0c248b0 (diff)
minor refactor of vertex group functions,
- defvert_remove_index's index wasnt used anywhere, rename to defvert_remove_group - defvert_add_to_group was local in MOD_weightvg_util.c, moved to deform.c and renamed to defvert_add_index_notest real fix coming next...
Diffstat (limited to 'source/blender/blenkernel/intern/deform.c')
-rw-r--r--source/blender/blenkernel/intern/deform.c79
1 files changed, 47 insertions, 32 deletions
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 1f09d98d697..8dfd7e25bfb 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -574,46 +574,61 @@ MDeformWeight *defvert_verify_index(MDeformVert *dvert, const int defgroup)
return dw_new;
}
-/* Removes the given vertex from the vertex group, specified either by its defgrp_idx,
- * or directly by its MDeformWeight pointer, if dw is not NULL.
- * WARNING: This function frees the given MDeformWeight, do not use it afterward! */
-void defvert_remove_index(MDeformVert *dvert, int defgroup, MDeformWeight *dw)
+/* TODO. merge with code above! */
+
+/* Adds the given vertex to the specified vertex group, with given weight.
+ * warning, this does NOT check for existign, assume caller already knows its not there */
+void defvert_add_index_notest(MDeformVert *dvert, int defgroup, const float weight)
{
MDeformWeight *dw_new;
- int i;
- /* Get index of removed MDeformWeight. */
- if (dw == NULL) {
- dw = dvert->dw;
- for (i = dvert->totweight; i > 0; i--, dw++) {
- if (dw->def_nr == defgroup)
- break;
- }
- i--;
+ /* do this check always, this function is used to check for it */
+ if (!dvert || defgroup < 0)
+ return;
+
+ dw_new = MEM_callocN(sizeof(MDeformWeight)*(dvert->totweight+1), "defvert_add_to group, new deformWeight");
+ if(dvert->dw) {
+ memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*dvert->totweight);
+ MEM_freeN(dvert->dw);
}
- else {
- i = dw - dvert->dw;
+ dvert->dw = dw_new;
+ dw_new += dvert->totweight;
+ dw_new->weight = weight;
+ dw_new->def_nr = defgroup;
+ dvert->totweight++;
+}
+
+
+/* Removes the given vertex from the vertex group.
+ * WARNING: This function frees the given MDeformWeight, do not use it afterward! */
+void defvert_remove_group(MDeformVert *dvert, MDeformWeight *dw)
+{
+ if (dvert && dw) {
+ MDeformWeight *dw_new;
+ int i = dw - dvert->dw;
+
/* Security check! */
- if(i < 0 || i >= dvert->totweight)
+ if(i < 0 || i >= dvert->totweight) {
return;
- }
+ }
- dvert->totweight--;
- /* If there are still other deform weights attached to this vert then remove
- * this deform weight, and reshuffle the others.
- */
- if (dvert->totweight) {
- dw_new = MEM_mallocN(sizeof(MDeformWeight)*(dvert->totweight), __func__);
- if (dvert->dw){
- memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*i);
- memcpy(dw_new+i, dvert->dw+i+1, sizeof(MDeformWeight)*(dvert->totweight-i));
+ dvert->totweight--;
+ /* If there are still other deform weights attached to this vert then remove
+ * this deform weight, and reshuffle the others.
+ */
+ if (dvert->totweight) {
+ dw_new = MEM_mallocN(sizeof(MDeformWeight)*(dvert->totweight), __func__);
+ if (dvert->dw){
+ memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*i);
+ memcpy(dw_new+i, dvert->dw+i+1, sizeof(MDeformWeight)*(dvert->totweight-i));
+ MEM_freeN(dvert->dw);
+ }
+ dvert->dw = dw_new;
+ }
+ else {
+ /* If there are no other deform weights left then just remove this one. */
MEM_freeN(dvert->dw);
+ dvert->dw = NULL;
}
- dvert->dw = dw_new;
- }
- else {
- /* If there are no other deform weights left then just remove this one. */
- MEM_freeN(dvert->dw);
- dvert->dw = NULL;
}
}