forked from bartvdbraak/blender
use consistent naming for deform.c, also moved defvert_remove_index into deform.c, was local in modifier code.
This commit is contained in:
parent
b202bf0564
commit
064d46eef0
@ -52,14 +52,16 @@ void defgroup_unique_name(struct bDeformGroup *dg, struct Object *ob);
|
||||
|
||||
struct MDeformWeight *defvert_find_index(const struct MDeformVert *dv, const int defgroup);
|
||||
struct MDeformWeight *defvert_verify_index(struct MDeformVert *dv, const int defgroup);
|
||||
void defvert_remove_index(struct MDeformVert *dvert, int defgroup, struct MDeformWeight *dw);
|
||||
|
||||
float defvert_find_weight(const struct MDeformVert *dvert, const int group_num);
|
||||
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index, int group_num);
|
||||
float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup);
|
||||
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int index, const int defgroup);
|
||||
|
||||
void defvert_copy(struct MDeformVert *dvert_r, const struct MDeformVert *dvert);
|
||||
void defvert_copy_index(struct MDeformVert *dv_dst, const struct MDeformVert *dv_src, const int defgroup);
|
||||
void defvert_sync(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, int use_verify);
|
||||
void defvert_sync_mapped(struct MDeformVert *dvert_r, const struct MDeformVert *dvert, const int *flip_map, const int flip_map_len, const int use_verify);
|
||||
void defvert_copy(struct MDeformVert *dvert_dst, const struct MDeformVert *dvert_src);
|
||||
void defvert_copy_index(struct MDeformVert *dvert_dst, const struct MDeformVert *dvert_src, const int defgroup);
|
||||
void defvert_sync(struct MDeformVert *dvert_dst, const struct MDeformVert *dvert_src, int use_verify);
|
||||
void defvert_sync_mapped(struct MDeformVert *dvert_dst, const struct MDeformVert *dvert_src,
|
||||
const int *flip_map, const int flip_map_len, const int use_verify);
|
||||
void defvert_remap (struct MDeformVert *dvert, int *map);
|
||||
void defvert_flip(struct MDeformVert *dvert, const int *flip_map, const int flip_map_len);
|
||||
void defvert_normalize(struct MDeformVert *dvert);
|
||||
|
@ -75,22 +75,22 @@ bDeformGroup *defgroup_duplicate (bDeformGroup *ingroup)
|
||||
}
|
||||
|
||||
/* copy & overwrite weights */
|
||||
void defvert_copy (MDeformVert *dvert_r, const MDeformVert *dvert)
|
||||
void defvert_copy(MDeformVert *dvert_dst, const MDeformVert *dvert_src)
|
||||
{
|
||||
if(dvert_r->totweight == dvert->totweight) {
|
||||
if(dvert->totweight)
|
||||
memcpy(dvert_r->dw, dvert->dw, dvert->totweight * sizeof(MDeformWeight));
|
||||
if (dvert_dst->totweight == dvert_src->totweight) {
|
||||
if (dvert_src->totweight)
|
||||
memcpy(dvert_dst->dw, dvert_src->dw, dvert_src->totweight * sizeof(MDeformWeight));
|
||||
}
|
||||
else {
|
||||
if(dvert_r->dw)
|
||||
MEM_freeN(dvert_r->dw);
|
||||
if (dvert_dst->dw)
|
||||
MEM_freeN(dvert_dst->dw);
|
||||
|
||||
if(dvert->totweight)
|
||||
dvert_r->dw= MEM_dupallocN(dvert->dw);
|
||||
if (dvert_src->totweight)
|
||||
dvert_dst->dw= MEM_dupallocN(dvert_src->dw);
|
||||
else
|
||||
dvert_r->dw= NULL;
|
||||
dvert_dst->dw= NULL;
|
||||
|
||||
dvert_r->totweight = dvert->totweight;
|
||||
dvert_dst->totweight = dvert_src->totweight;
|
||||
}
|
||||
}
|
||||
|
||||
@ -98,20 +98,20 @@ void defvert_copy (MDeformVert *dvert_r, const MDeformVert *dvert)
|
||||
* - do nothing if neither are set.
|
||||
* - add destination weight if needed.
|
||||
*/
|
||||
void defvert_copy_index (MDeformVert *dv_dst, const MDeformVert *dv_src, const int defgroup)
|
||||
void defvert_copy_index(MDeformVert *dvert_dst, const MDeformVert *dvert_src, const int defgroup)
|
||||
{
|
||||
MDeformWeight *dw_src, *dw_dst;
|
||||
|
||||
dw_src= defvert_find_index(dv_src, defgroup);
|
||||
dw_src= defvert_find_index(dvert_src, defgroup);
|
||||
|
||||
if (dw_src) {
|
||||
/* source is valid, verify destination */
|
||||
dw_dst= defvert_verify_index(dv_dst, defgroup);
|
||||
dw_dst= defvert_verify_index(dvert_dst, defgroup);
|
||||
dw_dst->weight= dw_src->weight;
|
||||
}
|
||||
else {
|
||||
/* source was NULL, assign zero, could also remove */
|
||||
dw_dst= defvert_find_index(dv_dst, defgroup);
|
||||
dw_dst= defvert_find_index(dvert_dst, defgroup);
|
||||
|
||||
if (dw_dst) {
|
||||
dw_dst->weight= 0.0f;
|
||||
@ -122,37 +122,38 @@ void defvert_copy_index (MDeformVert *dv_dst, const MDeformVert *dv_src, const i
|
||||
/* only sync over matching weights, don't add or remove groups
|
||||
* warning, loop within loop.
|
||||
*/
|
||||
void defvert_sync (MDeformVert *dvert_r, const MDeformVert *dvert, int use_verify)
|
||||
void defvert_sync(MDeformVert *dvert_dst, const MDeformVert *dvert_src, int use_verify)
|
||||
{
|
||||
if(dvert->totweight && dvert_r->totweight) {
|
||||
if (dvert_src->totweight && dvert_dst->totweight) {
|
||||
int i;
|
||||
MDeformWeight *dw;
|
||||
for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
|
||||
MDeformWeight *dw_r;
|
||||
if(use_verify) dw_r= defvert_verify_index(dvert_r, dw->def_nr);
|
||||
else dw_r= defvert_find_index(dvert_r, dw->def_nr);
|
||||
MDeformWeight *dw_src;
|
||||
for (i=0, dw_src=dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) {
|
||||
MDeformWeight *dw_dst;
|
||||
if (use_verify) dw_dst= defvert_verify_index(dvert_dst, dw_src->def_nr);
|
||||
else dw_dst= defvert_find_index(dvert_dst, dw_src->def_nr);
|
||||
|
||||
if(dw_r) {
|
||||
dw_r->weight= dw->weight;
|
||||
if (dw_dst) {
|
||||
dw_dst->weight= dw_src->weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* be sure all flip_map values are valid */
|
||||
void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, const int *flip_map, const int flip_map_len, const int use_verify)
|
||||
void defvert_sync_mapped(MDeformVert *dvert_dst, const MDeformVert *dvert_src,
|
||||
const int *flip_map, const int flip_map_len, const int use_verify)
|
||||
{
|
||||
if (dvert->totweight && dvert_r->totweight) {
|
||||
if (dvert_src->totweight && dvert_dst->totweight) {
|
||||
int i;
|
||||
MDeformWeight *dw;
|
||||
for (i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++) {
|
||||
if (dw->def_nr < flip_map_len) {
|
||||
MDeformWeight *dw_r;
|
||||
if(use_verify) dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]);
|
||||
else dw_r= defvert_find_index(dvert_r, flip_map[dw->def_nr]);
|
||||
MDeformWeight *dw_src;
|
||||
for (i=0, dw_src=dvert_src->dw; i < dvert_src->totweight; i++, dw_src++) {
|
||||
if (dw_src->def_nr < flip_map_len) {
|
||||
MDeformWeight *dw_dst;
|
||||
if (use_verify) dw_dst= defvert_verify_index(dvert_dst, flip_map[dw_src->def_nr]);
|
||||
else dw_dst= defvert_find_index(dvert_dst, flip_map[dw_src->def_nr]);
|
||||
|
||||
if(dw_r) {
|
||||
dw_r->weight= dw->weight;
|
||||
if (dw_dst) {
|
||||
dw_dst->weight= dw_src->weight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -512,18 +513,18 @@ void flip_side_name (char name[MAX_VGROUP_NAME], const char from_name[MAX_VGROUP
|
||||
BLI_snprintf (name, MAX_VGROUP_NAME, "%s%s%s%s", prefix, replace, suffix, number);
|
||||
}
|
||||
|
||||
float defvert_find_weight(const struct MDeformVert *dvert, const int group_num)
|
||||
float defvert_find_weight(const struct MDeformVert *dvert, const int defgroup)
|
||||
{
|
||||
MDeformWeight *dw= defvert_find_index(dvert, group_num);
|
||||
MDeformWeight *dw= defvert_find_index(dvert, defgroup);
|
||||
return dw ? dw->weight : 0.0f;
|
||||
}
|
||||
|
||||
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index, int group_num)
|
||||
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, const int index, const int defgroup)
|
||||
{
|
||||
if(group_num == -1 || dvert == NULL)
|
||||
if (defgroup == -1 || dvert == NULL)
|
||||
return 1.0f;
|
||||
|
||||
return defvert_find_weight(dvert+index, group_num);
|
||||
return defvert_find_weight(dvert+index, defgroup);
|
||||
}
|
||||
|
||||
|
||||
@ -533,40 +534,86 @@ MDeformWeight *defvert_find_index(const MDeformVert *dvert, const int defgroup)
|
||||
MDeformWeight *dw = dvert->dw;
|
||||
int i;
|
||||
|
||||
for(i=dvert->totweight; i>0; i--, dw++)
|
||||
if(dw->def_nr == defgroup)
|
||||
for (i=dvert->totweight; i>0; i--, dw++) {
|
||||
if (dw->def_nr == defgroup) {
|
||||
return dw;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Ensures that mv has a deform weight entry for the specified defweight group */
|
||||
/* Note this function is mirrored in editmesh_tools.c, for use for editvertices */
|
||||
MDeformWeight *defvert_verify_index(MDeformVert *dv, const int defgroup)
|
||||
MDeformWeight *defvert_verify_index(MDeformVert *dvert, const int defgroup)
|
||||
{
|
||||
MDeformWeight *newdw;
|
||||
MDeformWeight *dw_new;
|
||||
|
||||
/* do this check always, this function is used to check for it */
|
||||
if(!dv || defgroup < 0)
|
||||
if (!dvert || defgroup < 0)
|
||||
return NULL;
|
||||
|
||||
newdw= defvert_find_index(dv, defgroup);
|
||||
if(newdw)
|
||||
return newdw;
|
||||
dw_new= defvert_find_index(dvert, defgroup);
|
||||
if (dw_new)
|
||||
return dw_new;
|
||||
|
||||
newdw= MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight");
|
||||
if (dv->dw) {
|
||||
memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight);
|
||||
MEM_freeN(dv->dw);
|
||||
dw_new= MEM_callocN(sizeof(MDeformWeight)*(dvert->totweight+1), "deformWeight");
|
||||
if (dvert->dw) {
|
||||
memcpy(dw_new, dvert->dw, sizeof(MDeformWeight)*dvert->totweight);
|
||||
MEM_freeN(dvert->dw);
|
||||
}
|
||||
dv->dw= newdw;
|
||||
newdw += dv->totweight;
|
||||
newdw->weight= 0.0f;
|
||||
newdw->def_nr= defgroup;
|
||||
dvert->dw= dw_new;
|
||||
dw_new += dvert->totweight;
|
||||
dw_new->weight= 0.0f;
|
||||
dw_new->def_nr= defgroup;
|
||||
/* Group index */
|
||||
|
||||
dv->totweight++;
|
||||
dvert->totweight++;
|
||||
|
||||
return newdw;
|
||||
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)
|
||||
{
|
||||
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--;
|
||||
}
|
||||
else {
|
||||
i = dw - dvert->dw;
|
||||
/* Security check! */
|
||||
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));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -240,51 +240,6 @@ static void defvert_add_to_group(MDeformVert *dv, int defgrp_idx, const float we
|
||||
dv->totweight++;
|
||||
}
|
||||
|
||||
/* 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! */
|
||||
static void defvert_remove_from_group(MDeformVert *dv, int defgrp_idx, MDeformWeight *dw)
|
||||
{
|
||||
/* TODO, move this into deform.c as a generic function. */
|
||||
MDeformWeight *newdw;
|
||||
int i;
|
||||
|
||||
/* Get index of removed MDeformWeight. */
|
||||
if(dw == NULL) {
|
||||
dw = dv->dw;
|
||||
for (i = dv->totweight; i > 0; i--, dw++) {
|
||||
if (dw->def_nr == defgrp_idx)
|
||||
break;
|
||||
}
|
||||
i--;
|
||||
}
|
||||
else {
|
||||
i = dw - dv->dw;
|
||||
/* Security check! */
|
||||
if(i < 0 || i >= dv->totweight)
|
||||
return;
|
||||
}
|
||||
|
||||
dv->totweight--;
|
||||
/* If there are still other deform weights attached to this vert then remove
|
||||
* this deform weight, and reshuffle the others.
|
||||
*/
|
||||
if(dv->totweight) {
|
||||
newdw = MEM_mallocN(sizeof(MDeformWeight)*(dv->totweight), "defvert_remove_from_group, new deformWeight");
|
||||
if(dv->dw){
|
||||
memcpy(newdw, dv->dw, sizeof(MDeformWeight)*i);
|
||||
memcpy(newdw+i, dv->dw+i+1, sizeof(MDeformWeight)*(dv->totweight-i));
|
||||
MEM_freeN(dv->dw);
|
||||
}
|
||||
dv->dw = newdw;
|
||||
}
|
||||
/* If there are no other deform weights left then just remove this one. */
|
||||
else {
|
||||
MEM_freeN(dv->dw);
|
||||
dv->dw = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Applies weights to given vgroup (defgroup), and optionnaly add/remove vertices from the group.
|
||||
* If dws is not NULL, it must be an array of MDeformWeight pointers of same length as weights (and
|
||||
@ -309,7 +264,7 @@ void weightvg_update_vg(MDeformVert *dvert, int defgrp_idx, MDeformWeight **dws,
|
||||
/* If the vertex is in this vgroup, remove it if needed, or just update it. */
|
||||
if(dw != NULL) {
|
||||
if(do_rem && w < rem_thresh) {
|
||||
defvert_remove_from_group(dv, defgrp_idx, dw);
|
||||
defvert_remove_index(dv, defgrp_idx, dw);
|
||||
}
|
||||
else {
|
||||
dw->weight = w;
|
||||
|
Loading…
Reference in New Issue
Block a user