2002-10-12 11:37:38 +00:00
|
|
|
/* deform.c June 2001
|
|
|
|
*
|
|
|
|
* support for deformation groups
|
|
|
|
*
|
|
|
|
* Reevan McKay
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** BEGIN GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
2008-04-16 22:40:48 +00:00
|
|
|
* of the License, or (at your option) any later version.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software Foundation,
|
2010-02-12 13:34:04 +00:00
|
|
|
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-10-12 11:37:38 +00:00
|
|
|
*
|
|
|
|
* The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* The Original Code is: all of this file.
|
|
|
|
*
|
|
|
|
* Contributor(s): none yet.
|
|
|
|
*
|
2008-04-16 22:40:48 +00:00
|
|
|
* ***** END GPL LICENSE BLOCK *****
|
2002-10-12 11:37:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
2004-11-06 21:59:35 +00:00
|
|
|
#include <math.h>
|
2010-01-15 17:28:00 +00:00
|
|
|
#include "ctype.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "MEM_guardedalloc.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
|
|
|
#include "DNA_meshdata_types.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "DNA_object_types.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
2002-10-12 11:37:38 +00:00
|
|
|
#include "BKE_deform.h"
|
2004-09-14 19:03:11 +00:00
|
|
|
|
|
|
|
#include "BLI_blenlib.h"
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
void defgroup_copy_list (ListBase *outbase, ListBase *inbase)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bDeformGroup *defgroup, *defgroupn;
|
|
|
|
|
2011-02-13 10:52:18 +00:00
|
|
|
outbase->first= outbase->last= NULL;
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
for (defgroup = inbase->first; defgroup; defgroup=defgroup->next){
|
2010-01-26 13:50:17 +00:00
|
|
|
defgroupn= defgroup_duplicate(defgroup);
|
2002-10-12 11:37:38 +00:00
|
|
|
BLI_addtail(outbase, defgroupn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
bDeformGroup *defgroup_duplicate (bDeformGroup *ingroup)
|
2002-10-12 11:37:38 +00:00
|
|
|
{
|
|
|
|
bDeformGroup *outgroup;
|
|
|
|
|
|
|
|
if (!ingroup)
|
|
|
|
return NULL;
|
|
|
|
|
2005-10-20 20:38:08 +00:00
|
|
|
outgroup=MEM_callocN(sizeof(bDeformGroup), "copy deformGroup");
|
2002-10-12 11:37:38 +00:00
|
|
|
|
|
|
|
/* For now, just copy everything over. */
|
|
|
|
memcpy (outgroup, ingroup, sizeof(bDeformGroup));
|
|
|
|
|
|
|
|
outgroup->next=outgroup->prev=NULL;
|
|
|
|
|
|
|
|
return outgroup;
|
|
|
|
}
|
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
/* copy & overwrite weights */
|
2010-01-26 13:50:17 +00:00
|
|
|
void defvert_copy (MDeformVert *dvert_r, const MDeformVert *dvert)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
|
|
|
if(dvert_r->totweight == dvert->totweight) {
|
|
|
|
if(dvert->totweight)
|
|
|
|
memcpy(dvert_r->dw, dvert->dw, dvert->totweight * sizeof(MDeformWeight));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if(dvert_r->dw)
|
|
|
|
MEM_freeN(dvert_r->dw);
|
|
|
|
|
|
|
|
if(dvert->totweight)
|
|
|
|
dvert_r->dw= MEM_dupallocN(dvert->dw);
|
|
|
|
else
|
|
|
|
dvert_r->dw= NULL;
|
|
|
|
|
|
|
|
dvert_r->totweight = dvert->totweight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
/* 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)
|
|
|
|
{
|
|
|
|
if(dvert->totweight && dvert_r->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_find_index(dvert_r, dw->def_nr);
|
|
|
|
else dw_r= defvert_verify_index(dvert_r, dw->def_nr);
|
|
|
|
|
|
|
|
if(dw_r) {
|
|
|
|
dw_r->weight= dw->weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* be sure all flip_map values are valid */
|
|
|
|
void defvert_sync_mapped (MDeformVert *dvert_r, const MDeformVert *dvert, int *flip_map, int use_verify)
|
|
|
|
{
|
|
|
|
if(dvert->totweight && dvert_r->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_find_index(dvert_r, flip_map[dw->def_nr]);
|
|
|
|
else dw_r= defvert_verify_index(dvert_r, flip_map[dw->def_nr]);
|
|
|
|
|
|
|
|
if(dw_r) {
|
|
|
|
dw_r->weight= dw->weight;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-02-02 21:43:26 +00:00
|
|
|
/* be sure all flip_map values are valid */
|
|
|
|
void defvert_remap (MDeformVert *dvert, int *map)
|
|
|
|
{
|
|
|
|
MDeformWeight *dw;
|
|
|
|
int i;
|
|
|
|
for(i=0, dw=dvert->dw; i<dvert->totweight; i++, dw++) {
|
|
|
|
dw->def_nr= map[dw->def_nr];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
void defvert_normalize (MDeformVert *dvert)
|
2010-01-25 23:12:02 +00:00
|
|
|
{
|
|
|
|
if(dvert->totweight<=0) {
|
|
|
|
/* nothing */
|
|
|
|
}
|
|
|
|
else if (dvert->totweight==1) {
|
|
|
|
dvert->dw[0].weight= 1.0f;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
int i;
|
|
|
|
float tot= 0.0f;
|
|
|
|
MDeformWeight *dw;
|
|
|
|
for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++)
|
|
|
|
tot += dw->weight;
|
|
|
|
|
|
|
|
if(tot > 0.0f) {
|
|
|
|
for(i=0, dw=dvert->dw; i < dvert->totweight; i++, dw++)
|
|
|
|
dw->weight /= tot;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
void defvert_flip (MDeformVert *dvert, int *flip_map)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
|
|
|
MDeformWeight *dw;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for(dw= dvert->dw, i=0; i<dvert->totweight; dw++, i++)
|
|
|
|
if(flip_map[dw->def_nr] >= 0)
|
|
|
|
dw->def_nr= flip_map[dw->def_nr];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-22 14:15:28 +00:00
|
|
|
bDeformGroup *defgroup_find_name (Object *ob, const char *name)
|
2005-01-12 23:57:33 +00:00
|
|
|
{
|
|
|
|
/* return a pointer to the deform group with this name
|
|
|
|
* or return NULL otherwise.
|
|
|
|
*/
|
|
|
|
bDeformGroup *curdef;
|
|
|
|
|
2007-04-27 11:16:35 +00:00
|
|
|
for (curdef = ob->defbase.first; curdef; curdef=curdef->next) {
|
|
|
|
if (!strcmp(curdef->name, name)) {
|
2005-01-12 23:57:33 +00:00
|
|
|
return curdef;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
int defgroup_name_index (Object *ob, const char *name)
|
2007-08-17 11:23:48 +00:00
|
|
|
{
|
|
|
|
/* Return the location of the named deform group within the list of
|
2010-01-26 13:50:17 +00:00
|
|
|
* deform groups. This function is a combination of defgroup_find_index and
|
|
|
|
* defgroup_find_name. The other two could be called instead, but that
|
2007-08-17 11:23:48 +00:00
|
|
|
* require looping over the vertexgroups twice.
|
|
|
|
*/
|
|
|
|
bDeformGroup *curdef;
|
|
|
|
int def_nr;
|
|
|
|
|
2010-04-23 20:05:16 +00:00
|
|
|
if(name && name[0] != '\0') {
|
2010-01-26 09:36:33 +00:00
|
|
|
for (curdef=ob->defbase.first, def_nr=0; curdef; curdef=curdef->next, def_nr++) {
|
|
|
|
if (!strcmp(curdef->name, name))
|
|
|
|
return def_nr;
|
|
|
|
}
|
2007-08-17 11:23:48 +00:00
|
|
|
}
|
2010-01-26 09:36:33 +00:00
|
|
|
|
2007-08-17 11:23:48 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
int defgroup_find_index (Object *ob, bDeformGroup *dg)
|
2005-01-12 23:57:33 +00:00
|
|
|
{
|
|
|
|
/* Fetch the location of this deform group
|
|
|
|
* within the linked list of deform groups.
|
|
|
|
* (this number is stored in the deform
|
|
|
|
* weights of the deform verts to link them
|
2007-08-17 11:23:48 +00:00
|
|
|
* to this deform group).
|
2010-01-18 16:21:23 +00:00
|
|
|
*
|
|
|
|
* note: this is zero based, ob->actdef starts at 1.
|
2005-01-12 23:57:33 +00:00
|
|
|
*/
|
|
|
|
|
2007-04-27 11:16:35 +00:00
|
|
|
bDeformGroup *eg;
|
2005-01-12 23:57:33 +00:00
|
|
|
int def_nr;
|
|
|
|
|
|
|
|
eg = ob->defbase.first;
|
|
|
|
def_nr = 0;
|
|
|
|
|
2007-08-17 11:23:48 +00:00
|
|
|
/* loop through all deform groups */
|
2007-04-27 11:16:35 +00:00
|
|
|
while (eg != NULL) {
|
2005-01-12 23:57:33 +00:00
|
|
|
|
|
|
|
/* if the current deform group is
|
|
|
|
* the one we are after, return
|
|
|
|
* def_nr
|
|
|
|
*/
|
2007-04-27 11:16:35 +00:00
|
|
|
if (eg == dg) {
|
2005-01-12 23:57:33 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
++def_nr;
|
|
|
|
eg = eg->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* if there was no deform group found then
|
|
|
|
* return -1 (should set up a nice symbolic
|
|
|
|
* constant for this)
|
|
|
|
*/
|
|
|
|
if (eg == NULL) return -1;
|
|
|
|
|
|
|
|
return def_nr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-01-15 17:28:00 +00:00
|
|
|
/* note, must be freed */
|
2010-01-26 17:07:47 +00:00
|
|
|
int *defgroup_flip_map(Object *ob, int use_default)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
|
|
|
bDeformGroup *dg;
|
|
|
|
int totdg= BLI_countlist(&ob->defbase);
|
|
|
|
|
|
|
|
if(totdg==0) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
char name[sizeof(dg->name)];
|
|
|
|
int i, flip_num, *map= MEM_mallocN(totdg * sizeof(int), "get_defgroup_flip_map");
|
2010-01-26 17:07:47 +00:00
|
|
|
|
2010-01-15 17:28:00 +00:00
|
|
|
memset(map, -1, totdg * sizeof(int));
|
|
|
|
|
|
|
|
for (dg=ob->defbase.first, i=0; dg; dg=dg->next, i++) {
|
|
|
|
if(map[i] == -1) { /* may be calculated previously */
|
2010-01-26 17:07:47 +00:00
|
|
|
|
|
|
|
/* incase no valid value is found, use this */
|
|
|
|
if(use_default)
|
|
|
|
map[i]= i;
|
|
|
|
|
2010-01-26 13:50:17 +00:00
|
|
|
flip_side_name(name, dg->name, 0);
|
2010-01-15 17:28:00 +00:00
|
|
|
if(strcmp(name, dg->name)) {
|
2010-01-26 13:50:17 +00:00
|
|
|
flip_num= defgroup_name_index(ob, name);
|
2010-01-26 17:07:47 +00:00
|
|
|
if(flip_num >= 0) {
|
2010-01-15 17:28:00 +00:00
|
|
|
map[i]= flip_num;
|
|
|
|
map[flip_num]= i; /* save an extra lookup */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return map;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
int defgroup_flip_index(Object *ob, int index, int use_default)
|
|
|
|
{
|
|
|
|
bDeformGroup *dg= BLI_findlink(&ob->defbase, index);
|
|
|
|
int flip_index = -1;
|
|
|
|
|
|
|
|
if(dg) {
|
|
|
|
char name[sizeof(dg->name)];
|
|
|
|
flip_side_name(name, dg->name, 0);
|
|
|
|
|
|
|
|
if(strcmp(name, dg->name))
|
|
|
|
flip_index= defgroup_name_index(ob, name);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (flip_index==-1 && use_default) ? index : flip_index;
|
|
|
|
}
|
|
|
|
|
2010-11-01 07:19:41 +00:00
|
|
|
static int defgroup_find_name_dupe(const char *name, bDeformGroup *dg, Object *ob)
|
2007-04-27 11:16:35 +00:00
|
|
|
{
|
|
|
|
bDeformGroup *curdef;
|
|
|
|
|
2010-11-01 07:19:41 +00:00
|
|
|
for (curdef = ob->defbase.first; curdef; curdef=curdef->next) {
|
|
|
|
if (dg!=curdef) {
|
|
|
|
if (!strcmp(curdef->name, name)) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-11-07 08:49:07 +00:00
|
|
|
static int defgroup_unique_check(void *arg, const char *name)
|
|
|
|
{
|
|
|
|
struct {Object *ob; void *dg;} *data= arg;
|
|
|
|
return defgroup_find_name_dupe(name, data->dg, data->ob);
|
|
|
|
}
|
|
|
|
|
2010-11-01 07:19:41 +00:00
|
|
|
void defgroup_unique_name (bDeformGroup *dg, Object *ob)
|
2010-11-07 08:49:07 +00:00
|
|
|
{
|
|
|
|
struct {Object *ob; void *dg;} data;
|
|
|
|
data.ob= ob;
|
|
|
|
data.dg= dg;
|
2008-07-04 19:56:31 +00:00
|
|
|
|
2010-11-07 08:49:07 +00:00
|
|
|
BLI_uniquename_cb(defgroup_unique_check, &data, "Group", '.', dg->name, sizeof(dg->name));
|
2010-11-01 07:19:41 +00:00
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
|
|
|
|
/* finds the best possible flipped name. For renaming; check for unique names afterwards */
|
|
|
|
/* if strip_number: removes number extensions */
|
2010-01-26 13:50:17 +00:00
|
|
|
void flip_side_name (char *name, const char *from_name, int strip_number)
|
2010-01-15 17:28:00 +00:00
|
|
|
{
|
|
|
|
int len;
|
2011-02-12 16:54:24 +00:00
|
|
|
char prefix[sizeof(((bDeformGroup *)NULL)->name)]= ""; /* The part before the facing */
|
|
|
|
char suffix[sizeof(((bDeformGroup *)NULL)->name)]= ""; /* The part after the facing */
|
|
|
|
char replace[sizeof(((bDeformGroup *)NULL)->name)]= ""; /* The replacement string */
|
|
|
|
char number[sizeof(((bDeformGroup *)NULL)->name)]= ""; /* The number extension string */
|
2010-01-15 17:28:00 +00:00
|
|
|
char *index=NULL;
|
|
|
|
|
2010-01-17 16:00:54 +00:00
|
|
|
len= strlen(from_name);
|
2010-01-15 17:28:00 +00:00
|
|
|
if(len<3) return; // we don't do names like .R or .L
|
|
|
|
|
2011-02-13 07:39:43 +00:00
|
|
|
strcpy(name, from_name);
|
2010-01-17 16:00:54 +00:00
|
|
|
|
2010-01-15 17:28:00 +00:00
|
|
|
/* We first check the case with a .### extension, let's find the last period */
|
|
|
|
if(isdigit(name[len-1])) {
|
|
|
|
index= strrchr(name, '.'); // last occurrence
|
|
|
|
if (index && isdigit(index[1]) ) { // doesnt handle case bone.1abc2 correct..., whatever!
|
|
|
|
if(strip_number==0)
|
2011-02-13 07:39:43 +00:00
|
|
|
strcpy(number, index);
|
2010-01-15 17:28:00 +00:00
|
|
|
*index= 0;
|
|
|
|
len= strlen(name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-13 07:39:43 +00:00
|
|
|
strcpy(prefix, name);
|
2010-01-15 17:28:00 +00:00
|
|
|
|
|
|
|
#define IS_SEPARATOR(a) ((a)=='.' || (a)==' ' || (a)=='-' || (a)=='_')
|
|
|
|
|
|
|
|
/* first case; separator . - _ with extensions r R l L */
|
|
|
|
if( IS_SEPARATOR(name[len-2]) ) {
|
|
|
|
switch(name[len-1]) {
|
|
|
|
case 'l':
|
|
|
|
prefix[len-1]= 0;
|
|
|
|
strcpy(replace, "r");
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
prefix[len-1]= 0;
|
|
|
|
strcpy(replace, "l");
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
prefix[len-1]= 0;
|
|
|
|
strcpy(replace, "R");
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
prefix[len-1]= 0;
|
|
|
|
strcpy(replace, "L");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* case; beginning with r R l L , with separator after it */
|
|
|
|
else if( IS_SEPARATOR(name[1]) ) {
|
|
|
|
switch(name[0]) {
|
|
|
|
case 'l':
|
|
|
|
strcpy(replace, "r");
|
|
|
|
strcpy(suffix, name+1);
|
|
|
|
prefix[0]= 0;
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
strcpy(replace, "l");
|
|
|
|
strcpy(suffix, name+1);
|
|
|
|
prefix[0]= 0;
|
|
|
|
break;
|
|
|
|
case 'L':
|
|
|
|
strcpy(replace, "R");
|
|
|
|
strcpy(suffix, name+1);
|
|
|
|
prefix[0]= 0;
|
|
|
|
break;
|
|
|
|
case 'R':
|
|
|
|
strcpy(replace, "L");
|
|
|
|
strcpy(suffix, name+1);
|
|
|
|
prefix[0]= 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(len > 5) {
|
|
|
|
/* hrms, why test for a separator? lets do the rule 'ultimate left or right' */
|
|
|
|
index = BLI_strcasestr(prefix, "right");
|
|
|
|
if (index==prefix || index==prefix+len-5) {
|
|
|
|
if(index[0]=='r')
|
|
|
|
strcpy (replace, "left");
|
|
|
|
else {
|
|
|
|
if(index[1]=='I')
|
|
|
|
strcpy (replace, "LEFT");
|
|
|
|
else
|
|
|
|
strcpy (replace, "Left");
|
|
|
|
}
|
|
|
|
*index= 0;
|
|
|
|
strcpy (suffix, index+5);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
index = BLI_strcasestr(prefix, "left");
|
|
|
|
if (index==prefix || index==prefix+len-4) {
|
|
|
|
if(index[0]=='l')
|
|
|
|
strcpy (replace, "right");
|
|
|
|
else {
|
|
|
|
if(index[1]=='E')
|
|
|
|
strcpy (replace, "RIGHT");
|
|
|
|
else
|
|
|
|
strcpy (replace, "Right");
|
|
|
|
}
|
|
|
|
*index= 0;
|
|
|
|
strcpy (suffix, index+4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef IS_SEPARATOR
|
|
|
|
|
2010-01-17 16:00:54 +00:00
|
|
|
sprintf (name, "%s%s%s%s", prefix, replace, suffix, number);
|
2010-01-15 17:28:00 +00:00
|
|
|
}
|
|
|
|
|
2010-12-31 11:51:00 +00:00
|
|
|
float defvert_find_weight(const struct MDeformVert *dvert, const int group_num)
|
2010-01-26 17:07:47 +00:00
|
|
|
{
|
|
|
|
MDeformWeight *dw= defvert_find_index(dvert, group_num);
|
2010-01-28 12:16:35 +00:00
|
|
|
return dw ? dw->weight : 0.0f;
|
2010-01-26 17:07:47 +00:00
|
|
|
}
|
2010-01-15 17:28:00 +00:00
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
float defvert_array_find_weight_safe(const struct MDeformVert *dvert, int index, int group_num)
|
|
|
|
{
|
|
|
|
if(group_num == -1 || dvert == NULL)
|
2010-01-30 03:47:13 +00:00
|
|
|
return 1.0f;
|
2010-01-15 17:28:00 +00:00
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
return defvert_find_weight(dvert+index, group_num);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-12-03 01:52:28 +00:00
|
|
|
MDeformWeight *defvert_find_index(const MDeformVert *dvert, const int defgroup)
|
2008-07-04 19:56:31 +00:00
|
|
|
{
|
2010-01-26 17:07:47 +00:00
|
|
|
if(dvert && defgroup >= 0) {
|
|
|
|
MDeformWeight *dw = dvert->dw;
|
2008-07-04 19:56:31 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
for(i=dvert->totweight; i>0; i--, dw++)
|
2010-01-26 17:07:47 +00:00
|
|
|
if(dw->def_nr == defgroup)
|
|
|
|
return dw;
|
2008-07-04 19:56:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
return NULL;
|
2008-07-04 19:56:31 +00:00
|
|
|
}
|
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
/* 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 */
|
2010-12-03 01:52:28 +00:00
|
|
|
MDeformWeight *defvert_verify_index(MDeformVert *dv, const int defgroup)
|
2008-07-04 19:56:31 +00:00
|
|
|
{
|
2010-01-26 17:07:47 +00:00
|
|
|
MDeformWeight *newdw;
|
2008-07-04 19:56:31 +00:00
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
/* do this check always, this function is used to check for it */
|
|
|
|
if(!dv || defgroup<0)
|
|
|
|
return NULL;
|
2008-07-04 19:56:31 +00:00
|
|
|
|
2010-01-26 17:07:47 +00:00
|
|
|
newdw = defvert_find_index(dv, defgroup);
|
|
|
|
if(newdw)
|
|
|
|
return newdw;
|
|
|
|
|
|
|
|
newdw = MEM_callocN(sizeof(MDeformWeight)*(dv->totweight+1), "deformWeight");
|
|
|
|
if(dv->dw) {
|
|
|
|
memcpy(newdw, dv->dw, sizeof(MDeformWeight)*dv->totweight);
|
|
|
|
MEM_freeN(dv->dw);
|
|
|
|
}
|
|
|
|
dv->dw=newdw;
|
|
|
|
|
|
|
|
dv->dw[dv->totweight].weight=0.0f;
|
|
|
|
dv->dw[dv->totweight].def_nr=defgroup;
|
|
|
|
/* Group index */
|
|
|
|
|
|
|
|
dv->totweight++;
|
|
|
|
|
|
|
|
return dv->dw+(dv->totweight-1);
|
|
|
|
}
|